CommonFunction.php 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316
  1. <?php
  2. namespace Biz\Common;
  3. class CommonFunction {
  4. function checkDebug()
  5. {
  6. return (isset($_GET['debug']) && intval($_GET['debug'])==-99999) || APP_DEBUG==1?1:0;
  7. }
  8. function View($Path = "") {
  9. if (!$Path) {
  10. global $ViewPath;
  11. $ViewPath = explode("\\", $ViewPath);
  12. $ViewPath[3] = explode("Controller", $ViewPath[3]);
  13. $ViewPath[3] = $ViewPath[3][0];
  14. return APP_PATH . "/" . $ViewPath[1] . "/View/" . $ViewPath[3] . "/" . $ViewPath[4] . ".blade.php";
  15. } else {
  16. return APP_PATH . "/" . $Path . ".blade.php";
  17. }
  18. }
  19. function arrayToOptions($data, $key, $val)
  20. {
  21. $options = array();
  22. if (is_array($data) && count($data)) {
  23. foreach ($data as $k => $value) {
  24. $options[$value[$key]] = $value[$val];
  25. }
  26. }
  27. return $options;
  28. }
  29. function M($TABLE_NAME = "") {
  30. return new DB($TABLE_NAME);
  31. }
  32. function checkClose() {
  33. if (file_exists(ROOT_PATH . '/Cache/system.lock')) {
  34. if (is_mobile()) {
  35. return appExec("Mobile", "Weihu", "index");
  36. } else {
  37. return appExec("home", "weihu", "index");
  38. }
  39. }
  40. }
  41. /**
  42. * 发布消息
  43. *
  44. * @param integer $status
  45. * @param string $msg
  46. * @param string $data
  47. * @return void
  48. */
  49. function publishNotify($channel, $status = 1, $data = '') {
  50. // toLog('publishNotify-'.$channel.'+++'.$data);
  51. C()->get('msg')->publish($channel, $data);
  52. }
  53. /**
  54. * 数组分类排序
  55. * @param [array] $columnsArr [需要进行排序的数组]
  56. * @param [int] $plmid [所属分类ID]
  57. */
  58. function getColumns($columnsArr, $plmid) {
  59. $menu = array();
  60. foreach ($columnsArr as $v) {
  61. if ($v['plmid'] == $plmid) {
  62. $menu[] = $v;
  63. $a = getColumns($columnsArr, $v['lmid']);
  64. foreach ($a as $vv) {
  65. $menu[] = $vv;
  66. }
  67. }
  68. }
  69. return $menu;
  70. }
  71. /**
  72. * 获取客户端真实IP
  73. */
  74. function GETIP() {
  75. global $ip;
  76. if (getenv("HTTP_CLIENT_IP")) {
  77. $ip = getenv("HTTP_CLIENT_IP");
  78. } else if (getenv("HTTP_X_FORWARDED_FOR")) {
  79. $ip = getenv("HTTP_X_FORWARDED_FOR");
  80. } else if (getenv("REMOTE_ADDR")) {
  81. $ip = getenv("REMOTE_ADDR");
  82. } else {
  83. $ip = "Unknow";
  84. }
  85. return $ip;
  86. }
  87. function dump($data, $exit = 1) {
  88. echo "<pre>";
  89. print_r($data);
  90. echo "</pre>";
  91. if ($exit) {
  92. exit;
  93. }
  94. }
  95. function OrderID($prefix = '') {
  96. $num = mt_rand(100, 999);
  97. list($s, $m) = explode(' ', microtime());
  98. $order = date("YmdHis") . ($s * 1000000) . $num;
  99. return $prefix . $order;
  100. }
  101. /**
  102. * 容器
  103. */
  104. function C() {
  105. static $c = array();
  106. if (!isset($c['container'])) {
  107. $c['container'] = new \System\Di();
  108. }
  109. return $c['container'];
  110. }
  111. /**
  112. * 全局变量快捷操作
  113. * @param [type] $key [description]
  114. * @param [type] $value [description]
  115. */
  116. function S($key, $value = null) {
  117. if ($value != null) {
  118. $GLOBALS[$key] = $value;
  119. }
  120. if (isset($GLOBALS[$key])) {
  121. return $GLOBALS[$key];
  122. }
  123. }
  124. /**
  125. * 载入模型
  126. * @param [type] $name [description]
  127. * @param string $proj [description]
  128. * @return [type] [description]
  129. */
  130. function lm($name, $proj = '') {
  131. $proj = empty($proj) ? S('CUR_PROJECT') : $proj;
  132. if (empty($proj)) {
  133. throw new \Exception("项目{$proj}不存在", 1);
  134. }
  135. $cls = "\\App\\" . ucfirst($proj) . "\\Model\\" . ucfirst($name);
  136. if(!class_exists($cls)){
  137. return;
  138. }
  139. $key = 'model_' . $name . $proj;
  140. C()->shared($key, $cls);
  141. return C()->get($key);
  142. }
  143. /**
  144. * 载入语言包
  145. * @param string $key 语言项
  146. * @param string $file 语言文件名
  147. * @param string $proj 项目名称
  148. * @return [type] [description]
  149. */
  150. function lang($file = '', $proj = '') {
  151. $proj = empty($proj) ? S('CUR_PROJECT') : $proj;
  152. $file = empty($file) ? S('CUR_CONTROLLER') : $file;
  153. $ckey = "Lang_{$proj}_{$file}";
  154. if (C()->has($ckey)) {
  155. return C()->get($ckey);
  156. } else {
  157. C()->shared($ckey, function () use ($proj, $file) {
  158. $file = ucfirst($file);
  159. $proj = ucfirst($proj);
  160. $lang = new \System\Lang();
  161. $lang_files = array();
  162. if (S('CUR_PROJECT') == $proj && S('CUR_CONTROLLER') == $file) {
  163. $lang_files[] = ROOT_PATH . "/Application/Commons/Lang/Common.php";
  164. $lang_files[] = ROOT_PATH . "/Application/{$proj}/Lang/Common.php";
  165. }
  166. $lang_files[] = ROOT_PATH . "/Application/{$proj}/Lang/{$file}.php";
  167. $data = array();
  168. foreach ($lang_files as $v) {
  169. if (file_exists($v)) {
  170. $data2 = include $v;
  171. if (is_array($data2)) {
  172. $data = array_merge($data, $data2);
  173. }
  174. }
  175. }
  176. $lang->load($data);
  177. return $lang;
  178. });
  179. return C()->get($ckey);
  180. }
  181. }
  182. /**
  183. * 标签替换
  184. *
  185. * @param [type] $message
  186. * @param array $data
  187. * @param string $tag
  188. * @return void
  189. */
  190. function parseTag($message,$data=array(),$tag='#'){
  191. if(is_array($data) && count($data)>0){
  192. foreach ($data as $k => $v) {
  193. $message = str_replace($tag . $k . $tag, $v, $message);
  194. }
  195. }
  196. return $message;
  197. }
  198. function appExec($proj, $ctrl, $method, $exec = 0) {
  199. $proj = ucfirst($proj);
  200. $ctrl = ucfirst($ctrl);
  201. $method = ucfirst($method);
  202. S('CUR_PROJECT', $proj);
  203. S('CUR_CONTROLLER', $ctrl);
  204. S('CUR_METHOD', $method);
  205. checkPlatform();
  206. toDomain();
  207. //设置REMOTE_KEY
  208. lm('setinfo','commons')->setKey();
  209. $cls = "\\App\\{$proj}\\Controller\\{$ctrl}";
  210. C()->set($ctrl, $cls);
  211. $cls = C()->get($ctrl);
  212. if (!$cls) {
  213. exit("404 NOT FOUND");
  214. }
  215. if ($exec) {
  216. $result = $cls->$method();
  217. if (!empty($result)) {
  218. Render($result);
  219. }
  220. }
  221. if (method_exists($cls, $method)) {
  222. $result = $cls->$method();
  223. if (!empty($result)) {
  224. Render($result);
  225. }
  226. } else {
  227. exit("404 METHOD NOT FOUND");
  228. }
  229. }
  230. /**
  231. * UUID 生成
  232. */
  233. function UUID() {
  234. $prefix = '';
  235. $uuid = '';
  236. $str = md5(uniqid(mt_rand(), true));
  237. $uuid = substr($str, 0, 8) . '-';
  238. $uuid .= substr($str, 8, 4) . '-';
  239. $uuid .= substr($str, 12, 4) . '-';
  240. $uuid .= substr($str, 16, 4) . '-';
  241. $uuid .= substr($str, 20, 12);
  242. return $prefix . $uuid;
  243. }
  244. /**
  245. *密码加密码
  246. */
  247. function GenEncryption() {
  248. srand((double) microtime() * 1000000); //create a random number feed.
  249. $ychar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
  250. $list = explode(",", $ychar);
  251. $authnum = "";
  252. for ($i = 0; $i < 6; $i++) {
  253. $randnum = rand(0, 61); // 10+26;
  254. $authnum .= $list[$randnum];
  255. }
  256. return $authnum;
  257. }
  258. //密码加密
  259. function GenPassword($password) {
  260. $Enc = GenEncryption();
  261. $Pwd = md5(md5($Enc . $password));
  262. return array("encryption" => $Enc, "password" => $Pwd);
  263. }
  264. //密码验证
  265. function VerPassword($identity, $password) {
  266. $account = M("account_password")->where("account_identity = '$identity' and", "status = ", '1')->select("encryption,account_password")->find();
  267. $VerPwd = md5(md5($account["encryption"] . $password));
  268. if ($VerPwd == $account["account_password"]) {
  269. unset($account);
  270. unset($VerPwd);
  271. return true;
  272. } else {
  273. unset($account);
  274. unset($VerPwd);
  275. return false;
  276. }
  277. }
  278. /**
  279. * Json return
  280. * @param string $data [description]
  281. * @param string $status [description]
  282. * @param string $msg [description]
  283. * @param string $method [description]
  284. */
  285. function JsonReturn($data = "", $status = "200", $msg = "", $method = "") {
  286. // header("Content-type:application/json;charset:utf-8");
  287. // header('content-type:text/html; charset=utf-8');
  288. if(isset($_REQUEST['crossdomain']) && !empty($_REQUEST['crossdomain'])){
  289. header("Access-Control-Allow-Origin:{$_REQUEST['crossdomain']}");
  290. }else{
  291. header("Access-Control-Allow-Origin:*");
  292. }
  293. header('Access-Control-Allow-Methods:POST,GET,PUT,DELETE,OPTIONS');
  294. header('Access-Control-Allow-Credentials:true');
  295. $retdata=array("status" => $status, "msg" => $msg, "data" =>$data);
  296. $devicetype=isset($_REQUEST['devicetype'])?trim($_REQUEST['devicetype']):'';
  297. if(!empty($devicetype) && in_array($devicetype,array('ios','android'))){
  298. $path=S('CUR_PROJECT').'/'.S('CUR_CONTROLLER').'/'. S('CUR_METHOD');
  299. $retdata=C()->get($devicetype."Result")->update($path,$retdata);
  300. }
  301. if ($method == '') {
  302. //dump($devicetype);
  303. echo (json_encode($retdata,JSON_UNESCAPED_UNICODE));
  304. } else {
  305. echo ($method . "(" . json_encode($retdata,JSON_UNESCAPED_UNICODE) . ")");
  306. }
  307. }
  308. function XmlReturn($data = "", $status = 200, $msg = '') {
  309. // header("Content-type:text/xml;charset:utf-8");
  310. $xml = '<?xml version="1.0" encoding="utf-8"?>';
  311. $xml .= "<root>";
  312. $xml .= '<status>' . $status . '</status>';
  313. $xml .= '<msg>' . $msg . '</msg>';
  314. $xml .= "<rows>";
  315. $xml .= toXml($data);
  316. $xml .= "</rows>";
  317. $xml .= "</root>";
  318. echo($xml);
  319. }
  320. function toXml($data) {
  321. // print_r($data);
  322. $xml = '';
  323. if (is_array($data) && count($data) > 0) {
  324. foreach ($data as $k => $v) {
  325. $key = $k;
  326. if (is_numeric($k)) {
  327. $key = 'data';
  328. }
  329. if (is_array($v)) {
  330. $xml .= "<{$key}>" . toXml($v) . "</{$key}>";
  331. continue;
  332. }
  333. if (is_string($v)) {
  334. $xml .= "<{$key}>{$v}</{$key}>";
  335. }
  336. }
  337. }
  338. return $xml;
  339. }
  340. function WriteLog($Log) {
  341. $logger = new Logger('LOGGS');
  342. $logURI = "Cache/log/" . date("Y-m-d-H-i") . ".log";
  343. $logger->pushHandler(new StreamHandler($logURI, Logger::DEBUG));
  344. $logger->pushHandler(new FirePHPHandler());
  345. $logger->addInfo(var_export($Log,1));
  346. }
  347. /**
  348. * 计算当前用时
  349. *
  350. * @param string $runName
  351. * @param integer $return
  352. * @return void
  353. */
  354. function computeTime($runName='',$return=0,$start=1){
  355. $curTime= get_millisecond();
  356. $numTime=$curTime-(intval($GLOBALS['startTime'])*1000);
  357. if($return){
  358. return array('curTime'=>$curTime,'numTime'=>$numTime,'runName'=>$runName);
  359. }else{
  360. echo "<pre>执行{$runName} 功能,当前时间为:{$curTime},累积用时: {$numTime}</pre>";
  361. return;
  362. }
  363. }
  364. function get_millisecond()
  365. {
  366. list($usec, $sec) = explode(" ", microtime());
  367. $msec = round($usec * 1000);
  368. return $sec . $msec;
  369. }
  370. function toLog($text, $rewrite = 0) {
  371. $data = "=============" . date("Y-m-d H:i", time()) . "==========================================" . chr(13);
  372. $data .= var_export($text, 1) . chr(13);
  373. $data .= "======================================================================================" . chr(13);
  374. $data = iconv('utf-8', 'gb2312', $data);
  375. if ($rewrite) {
  376. file_put_contents(ROOT_PATH . '/logs.txt', $data);
  377. } else {
  378. file_put_contents(ROOT_PATH . '/logs.txt', $data, FILE_APPEND);
  379. }
  380. }
  381. /**
  382. * 发送数据到前台,根据请求的数据格式返回相应的数据
  383. * @param [type] $data [description]
  384. * @param string $status [description]
  385. * @param string $msg [description]
  386. */
  387. function Render($data, $status = "1", $msg = "", $method = '') {
  388. $format = S('CUR_RETURN_FORMAT');
  389. $msg = empty($msg) ? lang('errors', 'api')->get('error' . $status) : $msg;
  390. if (empty($format) || $format == 'json') {
  391. JsonReturn($data, $status, $msg);
  392. }
  393. if ($format == 'xml') {
  394. XmlReturn($data, $status, $msg);
  395. }
  396. exit;
  397. }
  398. function _beginTransaction() {
  399. S('DB')->beginTransaction();
  400. }
  401. function _rollBack() {
  402. S('DB')->rollBack();
  403. }
  404. function _commit() {
  405. S('DB')->commit();
  406. }
  407. /**
  408. * 服务
  409. *
  410. * @param string 服务名称
  411. * @param array $params
  412. * @return void
  413. */
  414. function SRV($name, $params = array()) {
  415. return C()->get($name)->update($params);
  416. }
  417. /**
  418. * 是否验证token过期
  419. *
  420. * @return bool
  421. */
  422. function isCheckToken() {
  423. $result = true;
  424. $allowMethod = include ROOT_PATH . "/Config/AllowMethod.php";
  425. $key = S('CUR_PROJECT') . '/' . S('CUR_CONTROLLER') . '/' . S('CUR_METHOD');
  426. if ($allowMethod[$key] == 1) {
  427. $result = false;
  428. }
  429. return $result;
  430. }
  431. function checkPlatform(){
  432. if(isset($_GET['platform'])){
  433. $_SESSION['platform']=$_GET['platform']=='wap'?1:0;
  434. }
  435. if(isset($_GET['clearPlatform']) && intval($_GET['clearPlatform'])==1){
  436. $_SESSION['platform']=null;
  437. }
  438. }
  439. function is_mobile() {
  440. if(isset($_SESSION['platform']) && $mobile=intval($_SESSION['platform'])>0 ){
  441. return $mobile==1?true:false;
  442. }
  443. $user_agent = $_SERVER['HTTP_USER_AGENT'];
  444. $mobile_agents = Array("240x320", "acer", "acoon", "acs-", "abacho", "ahong", "airness", "alcatel", "amoi", "android", "anywhereyougo.com", "applewebkit/525", "applewebkit/532", "asus", "audio", "au-mic", "avantogo", "becker", "benq", "bilbo", "bird", "blackberry", "blazer", "bleu", "cdm-", "compal", "coolpad", "danger", "dbtel", "dopod", "elaine", "eric", "etouch", "fly ", "fly_", "fly-", "go.web", "goodaccess", "gradiente", "grundig", "haier", "hedy", "hitachi", "htc", "huawei", "hutchison", "inno", "ipad", "ipaq", "ipod", "jbrowser", "kddi", "kgt", "kwc", "lenovo", "lg ", "lg2", "lg3", "lg4", "lg5", "lg7", "lg8", "lg9", "lg-", "lge-", "lge9", "longcos", "maemo", "mercator", "meridian", "micromax", "midp", "mini", "mitsu", "mmm", "mmp", "mobi", "mot-", "moto", "nec-", "netfront", "newgen", "nexian", "nf-browser", "nintendo", "nitro", "nokia", "nook", "novarra", "obigo", "palm", "panasonic", "pantech", "philips", "phone", "pg-", "playstation", "pocket", "pt-", "qc-", "qtek", "rover", "sagem", "sama", "samu", "sanyo", "samsung", "sch-", "scooter", "sec-", "sendo", "sgh-", "sharp", "siemens", "sie-", "softbank", "sony", "spice", "sprint", "spv", "symbian", "tablet", "talkabout", "tcl-", "teleca", "telit", "tianyu", "tim-", "toshiba", "tsm", "up.browser", "utec", "utstar", "verykool", "virgin", "vk-", "voda", "voxtel", "vx", "wap", "wellco", "wig browser", "wii", "windows ce", "wireless", "xda", "xde", "zte");
  445. $is_mobile = false;
  446. foreach ($mobile_agents as $device) {
  447. if (stristr($user_agent, $device)) {
  448. $is_mobile = true;
  449. break;
  450. }
  451. }
  452. return $is_mobile;
  453. }
  454. function toDomain() {
  455. $domain = $_SERVER['HTTP_HOST'];
  456. $config = include ROOT_PATH . '/Config/Domain.php';
  457. $is_mobile = is_mobile();
  458. $curDomain = $old_domain = $domain;
  459. if (is_array($config) && count($config) > 0) {
  460. $domains = array();
  461. $domains[] = $domain;
  462. if ($is_mobile) {
  463. $domains[] = str_replace('www.', 'm.', $domain);
  464. $domains[] = 'm.' . $domain;
  465. } else {
  466. $domains[] = str_replace('m.', '', $domain);
  467. $domains[] = str_replace('m.', 'www.', $domain);
  468. }
  469. foreach ($domains as $key => $value) {
  470. if (isset($config[$value])) {
  471. $v = $config[$value];
  472. if ($v == 'pay') {
  473. return;
  474. }
  475. if ($is_mobile) {
  476. if ($v == 'pc') {
  477. continue;
  478. }
  479. } else {
  480. if ($v != 'pc') {
  481. continue;
  482. }
  483. }
  484. $curDomain = $value;
  485. // $_SESSION['domain']=$value;
  486. }
  487. }
  488. }
  489. // echo $curDomain;
  490. if ($is_mobile) {
  491. if (S('CUR_PROJECT') == 'Home') {
  492. header("Location:http://" . $curDomain . "/m");
  493. //header("Location:http://" . $curDomain . "/mobile-index/index");
  494. }
  495. } else {
  496. if (S('CUR_PROJECT') == 'Mobile') {
  497. header("Location:http://" . $curDomain . "/home-index/index");
  498. }
  499. }
  500. /**
  501. * 数据签名认证
  502. * @param array $data 被认证的数据
  503. * @return string 签名
  504. */
  505. function data_auth_sign($data) {
  506. //数据类型检测
  507. if (!is_array($data)) {
  508. $data = (array) $data;
  509. }
  510. ksort($data); //排序
  511. $code = http_build_query($data); //url编码并生成query字符串
  512. $sign = sha1($code); //生成签名
  513. return $sign;
  514. }
  515. /*
  516. * 判断用户是否登录
  517. * */
  518. function isLogin($str = '',$type='agent') {
  519. $session = $_SESSION[$type.'Info'];
  520. if(empty($session)){
  521. return null;
  522. }
  523. if($type=='agent'){
  524. if($str=='name'){
  525. return $session['agent_user'];
  526. }
  527. if($str=='uid'){
  528. return $session['user_identity'];
  529. }
  530. }
  531. }
  532. }
  533. function jump($url){
  534. header('Location:'.$url);
  535. }
  536. //手机中间星号
  537. function phoneHide($phone)
  538. {
  539. if (!empty($phone)) {
  540. $phone = substr_replace($phone, '****', 3, 4);
  541. }
  542. return $phone;
  543. }
  544. /**
  545. * @param $game_code 球类代码
  546. * @param int $isJoin 是否用于join
  547. * @return array
  548. * @throws Exception
  549. * 根据球类代码 定义相关model
  550. */
  551. function getModels($game_code,$isJoin=1){
  552. $game_type = lm('GameType', 'Sports')->where('game_code',$game_code)->select('game_code')->first();
  553. // 获取不同球类model
  554. if($isJoin == 1){
  555. switch ($game_type->game_code){
  556. case 'zq':
  557. $model_league = 'st_zq_league';
  558. $model_match = 'st_zq_competition';
  559. $model_odds = 'st_zq_odds';
  560. $model_odds_record = 'st_zq_odds_record';
  561. $model_result = 'st_zq_result';
  562. $model_result_record = 'st_zq_result_record';
  563. $model_league_result = 'st_zq_league_result';
  564. $model_local_league = 'st_zq_local_league';
  565. $model_local_match = 'st_zq_local_match';
  566. break;
  567. case 'lq':
  568. $model_league = 'st_lq_league';
  569. $model_match = 'st_lq_competition';
  570. $model_odds = 'st_lq_odds';
  571. $model_odds_record = 'st_lq_odds_record';
  572. $model_result = 'st_lq_result';
  573. $model_result_record = 'st_lq_result_record';
  574. $model_league_result = 'st_lq_league_result';
  575. $model_local_league = 'st_lq_local_league';
  576. $model_local_match = 'st_lq_local_match';
  577. break;
  578. case 'wq':
  579. $model_league = 'st_wq_league';
  580. $model_match = 'st_wq_competition';
  581. $model_odds = 'st_wq_odds';
  582. $model_odds_record = 'st_wq_odds_record';
  583. $model_result = 'st_wq_result';
  584. $model_result_record = 'st_wq_result_record';
  585. $model_league_result = 'st_wq_league_result';
  586. $model_local_league = 'st_wq_local_league';
  587. $model_local_match = 'st_wq_local_match';
  588. break;
  589. case 'bq':
  590. $model_league = 'st_bq_league';
  591. $model_match = 'st_bq_competition';
  592. $model_odds = 'st_bq_odds';
  593. $model_odds_record = 'st_bq_odds_record';
  594. $model_result = 'st_bq_result';
  595. $model_result_record = 'st_bq_result_record';
  596. $model_league_result = 'st_bq_league_result';
  597. $model_local_league = 'st_bq_local_league';
  598. $model_local_match = 'st_bq_local_match';
  599. break;
  600. case 'gj':
  601. $model_league = 'st_zq_league';
  602. $model_match = 'st_zq_competition';
  603. $model_odds = 'st_zq_odds';
  604. $model_result = 'st_zq_result';
  605. break;
  606. default:
  607. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  608. }
  609. }else{
  610. switch ($game_type->game_code){
  611. case 'zq':
  612. $model_league = 'st_zq_league';
  613. $model_match = 'st_zq_competition';
  614. $model_odds = 'st_zq_odds';
  615. $model_result = 'SoccerResult';
  616. break;
  617. case 'lq':
  618. $model_league = 'st_lq_league';
  619. $model_match = 'st_lq_competition';
  620. $model_odds = 'st_lq_odds';
  621. $model_result = 'BasketballResult';
  622. break;
  623. case 'wq':
  624. $model_league = 'st_wq_league';
  625. $model_match = 'st_wq_competition';
  626. $model_odds = 'st_wq_odds';
  627. $model_result = 'TennisResult';
  628. break;
  629. case 'bq':
  630. $model_league = 'st_bq_league';
  631. $model_match = 'st_bq_competition';
  632. $model_odds = 'st_bq_odds';
  633. $model_result = 'BaseballResult';
  634. break;
  635. case 'gj':
  636. $model_league = 'st_zq_league';
  637. $model_match = 'st_zq_competition';
  638. $model_odds = 'st_zq_odds';
  639. $model_result = 'SoccerResult';
  640. break;
  641. default:
  642. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  643. }
  644. }
  645. $data = [
  646. 'model_league'=>$model_league,//联赛
  647. 'model_match'=>$model_match,//赛事
  648. 'model_odds'=>$model_odds,//赔率
  649. 'model_result' =>$model_result,//赛事结果
  650. 'model_odds_record' => $model_odds_record,//赔率记录
  651. 'model_result_record' =>$model_result_record,//赛事结果记录
  652. 'model_league_result'=>$model_league_result,//联赛结果
  653. 'model_local_league'=>$model_local_league,//本地关联联赛
  654. 'model_local_match'=>$model_local_match,//本地关联赛事
  655. ];
  656. return $data;
  657. }
  658. /**
  659. * @param $type_code 状态码
  660. * @param $model_match 赛事表名
  661. * @param $game_code 球类代码
  662. * @return array
  663. * @throws \Exception
  664. * 获取不同状态下的 查询条件
  665. */
  666. function getState($type_code,$model_match = '',$game_code){
  667. if($model_match == ''){
  668. switch ($type_code){
  669. case 'StRollBall'://滚球 正在进行
  670. //追加不同球类的滚球时间
  671. if($game_code == 'zq' || $game_code == 'gj'){
  672. $where = [
  673. // ['is_rollball','=',1],
  674. ['status','<','2'],
  675. ['match_date','=',date("Y-m-d")],
  676. ['match_time','>',date("H:i:s", time()-(120*60))],
  677. ['match_time','<',date("H:i:s", time())]
  678. ];
  679. }
  680. if($game_code == 'lq'){
  681. $where = [
  682. // ['is_rollball','=',1],
  683. ['status','<','2'],
  684. ['match_date','=',date("Y-m-d")],
  685. ['match_time','>',date("H:i:s", time()-(90*60))],
  686. ['match_time','<',date("H:i:s", time())]
  687. ];
  688. }
  689. if($game_code == 'wq'){
  690. $where = [
  691. // ['is_rollball','=',1],
  692. ['status','<','2'],
  693. ['match_date','=',date("Y-m-d")],
  694. ['match_time','>',date("H:i:s", time()-(300*60))],
  695. ['match_time','<',date("H:i:s", time())]
  696. ];
  697. }
  698. if($game_code == 'bq'){
  699. $where = [
  700. // ['is_rollball','=',1],
  701. ['status','<','2'],
  702. ['match_date','=',date("Y-m-d")],
  703. ['match_time','>',date("H:i:s", time()-(300*60))],
  704. ['match_time','<',date("H:i:s", time())]
  705. ];
  706. }
  707. break;
  708. case 'StSoon'://即将 今日两小时内开始
  709. $where = [
  710. ['status','=','0'],
  711. ['match_date','=',date("Y-m-d")],
  712. ['match_time','<',date("H:i:s", strtotime("+2 hour"))],
  713. ['match_time','>',date("H:i:s", time())]
  714. /*
  715. ['utime','>',date("Y-m-d").' 00:00:00']
  716. */
  717. ];
  718. break;
  719. case 'StToday'://今日 今日未开始未结束
  720. $where = [
  721. ['status', '<', '2'],
  722. ['match_date','=',date("Y-m-d")],
  723. ['match_time','>',date("H:i:s", time())],
  724. /*
  725. ['is_today', '=', 1],
  726. ['type', '=', '1'],
  727. ['utime','>',date("Y-m-d").' 00:00:00']
  728. */
  729. ];
  730. break;
  731. case 'StMorningPlate'://早盘
  732. //获取当天结束时间戳
  733. $endTime = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  734. $where = [
  735. ['status', '<', '2'],
  736. // ['is_morningplate', '=', 1],
  737. ['us_time','>',$this->qgmdate('Y-m-d H:i:s', $endTime, -4)],
  738. /*
  739. ['match_date','>',date("Y-m-d",time())],
  740. ['match_time','>',date("H:i:s", time())],
  741. ['type', '=', '2'],
  742. ['utime','>',date("Y-m-d").' 00:00:00']
  743. */
  744. ];
  745. break;
  746. case 'StStringScene'://串场
  747. $where = [
  748. ['status', '<', '2'],
  749. ['is_stringscene', '=', 1],
  750. ['us_time','>',$this->qgmdate('Y-m-d H:i:s', '', -4)],
  751. /*
  752. ['match_date','>',date("Y-m-d",time())],
  753. ['match_time','>',date("H:i:s", time())],
  754. ['type', '=', '3'],
  755. ['utime','>',date("Y-m-d").' 00:00:00']
  756. */
  757. ];
  758. break;
  759. case 'StChampion'://冠军
  760. $where = [
  761. 'type'=>1
  762. ];
  763. break;
  764. default:
  765. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  766. }
  767. }else{
  768. switch ($type_code){
  769. case 'StRollBall'://滚球 正在进行
  770. //追加不同球类的滚球时间
  771. if($game_code == 'zq' || $game_code == 'gj'){
  772. $where = [
  773. // [$model_match.'.is_rollball','=',1],
  774. [$model_match.'.status','<','2'],
  775. [$model_match.'.match_date','=',date("Y-m-d")],
  776. [$model_match.'.match_time','>',date("H:i:s", time()-(120*60))],
  777. [$model_match.'.match_time','<',date("H:i:s", time())]
  778. ];
  779. }
  780. if($game_code == 'lq'){
  781. $where = [
  782. // [$model_match.'.is_rollball','=',1],
  783. [$model_match.'.status','<','2'],
  784. [$model_match.'.match_date','=',date("Y-m-d")],
  785. [$model_match.'.match_time','>',date("H:i:s", time()-(90*60))],
  786. [$model_match.'.match_time','<',date("H:i:s", time())]
  787. ];
  788. }
  789. if($game_code == 'wq'){
  790. $where = [
  791. // [$model_match.'.is_rollball','=',1],
  792. [$model_match.'.status','<','2'],
  793. [$model_match.'.match_date','=',date("Y-m-d")],
  794. [$model_match.'.match_time','>',date("H:i:s", time()-(300*60))],
  795. [$model_match.'.match_time','<',date("H:i:s", time())]
  796. ];
  797. }
  798. if($game_code == 'bq'){
  799. $where = [
  800. // [$model_match.'.is_rollball','=',1],
  801. [$model_match.'.status','<','2'],
  802. [$model_match.'.match_date','=',date("Y-m-d")],
  803. [$model_match.'.match_time','>',date("H:i:s", time()-(300*60))],
  804. [$model_match.'.match_time','<',date("H:i:s", time())]
  805. ];
  806. }
  807. break;
  808. case 'StSoon'://即将 今日两小时内开始
  809. $where = [
  810. [$model_match.'.status','=','0'],
  811. [$model_match.'.match_date','=',date("Y-m-d")],
  812. [$model_match.'.match_time','<',date("H:i:s", strtotime("+2 hour"))],
  813. [$model_match.'.match_time','>',date("H:i:s", time())]
  814. /*
  815. [$model_match.'.utime','>',date("Y-m-d").' 00:00:00']
  816. */
  817. ];
  818. break;
  819. case 'StToday'://今日 今日未开始未结束
  820. $where = [
  821. [$model_match.'.status', '<', '2'],
  822. [$model_match.'.match_date','=',date("Y-m-d")],
  823. [$model_match.'.match_time','>',date("H:i:s", time())],
  824. /*
  825. [$model_match.'.utime','>',date("Y-m-d").' 00:00:00'],
  826. [$model_match.'.is_today','=',1],
  827. [$model_match.'.type', '=', '1'],
  828. */
  829. ];
  830. break;
  831. case 'all'://所有赛事
  832. $where = [
  833. [$model_match.'.status', '<', '2'],
  834. ];
  835. break;
  836. case 'StMorningPlate'://早盘
  837. //获取当天结束的时间戳
  838. $endTime = mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
  839. $where = [
  840. [$model_match.'.status', '<', '2'],
  841. // [$model_match.'.is_morningplate','=',1],
  842. [$model_match.'.us_time','>',$this->qgmdate('Y-m-d H:i:s',$endTime , -4)],
  843. /*
  844. [$model_match.'.match_date','>',date("Y-m-d",time())],
  845. [$model_match.'.match_time','>',date("H:i:s", time())],
  846. [$model_match.'.type', '=', '2'],
  847. [$model_match.'.utime','>',date("Y-m-d").' 00:00:00']
  848. */
  849. ];
  850. break;
  851. case 'StStringScene'://串场 查询串场状态为1 开赛时间大于当前时间
  852. $where = [
  853. [$model_match.'.is_stringscene','=',1],
  854. [$model_match.'.us_time','>',$this->qgmdate('Y-m-d H:i:s', '', -4)],
  855. [$model_match.'.status', '<', '2'],
  856. /*
  857. [$model_match.'.match_date','>',date("Y-m-d",time())],
  858. [$model_match.'.match_time','>',date("H:i:s", time())],
  859. [$model_match.'.type', '=', '3'],
  860. [$model_match.'.utime','>',date("Y-m-d").' 00:00:00']
  861. */
  862. ];
  863. break;
  864. case 'StChampion'://冠军
  865. $where = [
  866. 'type'=>1
  867. ];
  868. break;
  869. default:
  870. throw new \Exception(Render([], '10002', lang('Tips','Sports')->get('PARAM_ERROR')));
  871. }
  872. }
  873. return $where;
  874. }
  875. /**
  876. * @param $data
  877. * @return array
  878. * 处理当国家下无联赛数据 删除该数组
  879. */
  880. function handleArr($data){
  881. $hData = [];
  882. foreach ($data as $key =>$v){
  883. if(empty($v['league_count'])){
  884. $v = [];
  885. }
  886. $hData[]=$v;
  887. }
  888. foreach($hData as $k=>$v){
  889. if(empty($v)){
  890. unset($hData[$k]);
  891. }
  892. }
  893. foreach ($hData as $k=>$v){
  894. $v['league_count'] = array_values($v['league_count']);
  895. $hData[$k]=$v;
  896. }
  897. return array_values($hData);
  898. }
  899. /**
  900. * @param $arr
  901. * @param $key
  902. * @return array
  903. * 去除二维数组重复项
  904. */
  905. function array_unset_tt($arr,$key){
  906. //建立一个目标数组
  907. $res = array();
  908. foreach ($arr as $value) {
  909. //查看有没有重复项
  910. if(isset($res[$value[$key]])){
  911. unset($value[$key]); //有:销毁
  912. }else{
  913. $res[$value[$key]] = $value;
  914. }
  915. }
  916. return $res;
  917. }
  918. /**
  919. * 处理冠军盘口 数组结构
  920. */
  921. function array_gj_tt($data,$oddsData){
  922. foreach ($data as $k=>&$v){
  923. foreach ($v['league_count'] as $kk=>&$vv){
  924. foreach ($oddsData as $kkk=>$vvv){
  925. if($vv['lg_id'] == $vvv['lg_id']){
  926. $vv['oddsData'][]=$vvv;
  927. }
  928. }
  929. if($vv['oddsData']){
  930. $vv['oddsData'] = $this->array_unset_tt($vv['oddsData'],'p_code');
  931. $vv['count'] = count($vv['oddsData']);
  932. unset($vv['oddsData']);
  933. }
  934. if(count($vv) != 5){
  935. unset($v['league_count'][$kk]);
  936. }
  937. }
  938. $v['league_count'] = array_values($v['league_count']);
  939. if(empty($v['league_count'])){
  940. unset($data[$k]);
  941. }
  942. }
  943. return array_values($data);
  944. }
  945. /**
  946. * 处理冠军以外 数组结构
  947. */
  948. function array_other_tt($data,$matchData){
  949. foreach ($data as $k=>&$v){
  950. foreach ($v['league_count'] as $kk=>&$vv){
  951. foreach ($matchData as $kkk=>$vvv){
  952. if($vv['lg_id'] == $vvv['lg_id']){
  953. $vv['matchData'][]=$vvv;
  954. }
  955. }
  956. if($vv['matchData']){
  957. $vv['matchData'] = $this->array_unset_tt($vv['matchData'],'match_id');
  958. $vv['count'] = count($vv['matchData']);
  959. unset($vv['matchData']);
  960. }
  961. if(empty($vv['count'])){
  962. unset($v['league_count'][$kk]);
  963. }
  964. }
  965. $v['league_count'] = array_values($v['league_count']);
  966. if(empty($v['league_count'])){
  967. unset($data[$k]);
  968. }
  969. }
  970. return array_values($data);
  971. }
  972. /**
  973. * 时间格式化
  974. * @param string $dateformat 时间格式
  975. * @param int $timestamp 时间戳
  976. * @param int $timeoffset 时区偏差 默认8 北京时间 -4美东时间
  977. * @return string
  978. */
  979. function qgmdate($dateformat = 'Y-m-d H:i:s', $timestamp = '', $timeoffset = 8,$type = '') {
  980. if(empty($timestamp)) {
  981. $timestamp = time();
  982. }
  983. $result = gmdate($dateformat, $timestamp + $timeoffset * 3600);
  984. return $result;
  985. }
  986. /**
  987. * 判断二维数组是否包含一维数组
  988. * @param mixed $arr 查询条件
  989. * @param mixed $arrs 运动类型
  990. * @return string
  991. */
  992. function judgeEqual($arr, $arrs){
  993. foreach ($arrs as $value) {
  994. if (count($value) === count($arr)) {
  995. $a = 0;
  996. foreach ($value as $key => $v) {
  997. $a++;
  998. if ($v != $arr[$key]) {
  999. break;
  1000. }
  1001. if ($a == count($key)) { // 到最后一个元素都没有出现不相等,就说明这两个数组相等。
  1002. return true;
  1003. }
  1004. }
  1005. }
  1006. }
  1007. return false;
  1008. }
  1009. // 排列
  1010. function arrangement($a, $m) {
  1011. $r = array();
  1012. $n = count($a);
  1013. if ($m <= 0 || $m > $n) {
  1014. return $r;
  1015. }
  1016. for ($i=0; $i<$n; $i++) {
  1017. $b = $a;
  1018. $t = array_splice($b, $i, 1);
  1019. if ($m == 1) {
  1020. $r[] = $t;
  1021. } else {
  1022. $c = $this->arrangement($b, $m-1);
  1023. foreach ($c as $v) {
  1024. $r[] = array_merge($t, $v);
  1025. }
  1026. }
  1027. }
  1028. return $r;
  1029. }
  1030. // 组合
  1031. function combination($a, $m) {
  1032. $r = array();
  1033. $n = count($a);
  1034. if ($m <= 0 || $m > $n) {
  1035. return $r;
  1036. }
  1037. for ($i=0; $i<$n; $i++) {
  1038. $t = array($a[$i]);
  1039. if ($m == 1) {
  1040. $r[] = $t;
  1041. } else {
  1042. $b = array_slice($a, $i+1);
  1043. $c = $this->combination($b, $m-1);
  1044. foreach ($c as $v) {
  1045. $r[] = array_merge($t, $v);
  1046. }
  1047. }
  1048. }
  1049. return $r;
  1050. }
  1051. // 阶乘
  1052. function factorial($n) {
  1053. return array_product(range(1, $n));
  1054. }
  1055. // 排列数
  1056. function A1($n, $m) {
  1057. return factorial($n)/factorial($n-$m);
  1058. }
  1059. // 组合数
  1060. function C1($n, $m) {
  1061. return A1($n, $m)/factorial($m);
  1062. }
  1063. //处理空赔率赛事
  1064. function Handle_Odds_Null($matchData=[],$models=[],$oddsTypeWhere=[]){
  1065. //===获取当前赛事是否有赔率,如果没有则去除===
  1066. //获取当前match_id
  1067. $match_ids = [];
  1068. foreach($matchData as $k=>$v){
  1069. $match_ids[] = $v['match_id'];
  1070. }
  1071. //获取下赛事赔率
  1072. $oddsData = lm($models['model_odds'],'Sports')
  1073. ->select('match_id')
  1074. ->whereIn('match_id',$match_ids)
  1075. ->where($oddsTypeWhere)
  1076. ->distinct('match_id')
  1077. ->get()
  1078. ->toArray();
  1079. //如果赔率为空,则返回空
  1080. if(empty($oddsData)) return $oddsData;
  1081. $matchData_new = [];
  1082. foreach($matchData as $k=>$v){
  1083. foreach($oddsData as $kk=>$vv){
  1084. if($v['match_id'] == $vv['match_id']){
  1085. $matchData_new[] = $matchData[$k];
  1086. }
  1087. }
  1088. }
  1089. return $matchData_new;
  1090. //===赛事空赔率 处理end ===
  1091. }
  1092. //处理空赔率联赛
  1093. function Handle_Odds_Null_lg($matchData=[],$models=[]){
  1094. //===获取当前联赛是否有赔率,如果没有则去除===
  1095. //获取当前lg_id
  1096. $lg_ids = [];
  1097. foreach($matchData as $k=>$v){
  1098. $lg_ids[] = $v['lg_id'];
  1099. }
  1100. //获取下赛事赔率
  1101. $oddsData = lm($models['model_odds'],'Sports')
  1102. ->select('lg_id')
  1103. ->whereIn('lg_id',$lg_ids)
  1104. ->where('type',1)
  1105. ->distinct('lg_id')
  1106. ->get()
  1107. ->toArray();
  1108. //如果赔率为空,则返回空
  1109. if(empty($oddsData)) return $oddsData;
  1110. $matchData_new = [];
  1111. foreach($matchData as $k=>$v){
  1112. foreach($oddsData as $kk=>$vv){
  1113. if($v['lg_id'] == $vv['lg_id']){
  1114. $matchData_new[] = $matchData[$k];
  1115. }
  1116. }
  1117. }
  1118. return $matchData_new;
  1119. //===联赛空赔率 处理end ===
  1120. }
  1121. /**
  1122. * 处理各球类投注: 可赢金额计算
  1123. * $game_code 球类代码
  1124. * $p_code 父级玩法代码
  1125. * $odds 赔率
  1126. * $bet_amount 投注金额
  1127. * $type 投注类型 1单式
  1128. */
  1129. function getEarnMoney($game_code='',$p_code='',$odds=0,$bet_amount=0,$type=0){
  1130. /*
  1131. 可赢额直接乘以赔率的父级玩法有
  1132. 足球:球队进球数:大/小 进球:大/小 让球
  1133. 篮球:让球 总分:大/小 球队得分大小
  1134. 网球:让盘 让局 总局数:大/小
  1135. 棒球:让球 总得分:大/小
  1136. */
  1137. //单式投注
  1138. if($type == 1){
  1139. //足球 可赢金额 计算规则
  1140. if($game_code == 'zq'){
  1141. //球队进球数:大/小;进球:大/小;让球;
  1142. if($p_code == 'tema_ball' || $p_code == 'goal_size' || $p_code == 'concede'){
  1143. //可赢金额 = 赔率*投注金额
  1144. $prize_money = $odds*$bet_amount;
  1145. }else{
  1146. //可赢金额 = (赔率-1)*投注金额
  1147. $prize_money = ($odds-1)*$bet_amount;
  1148. }
  1149. }
  1150. //篮球 可赢金额 计算规则
  1151. if($game_code == 'lq'){
  1152. //让球 总分:大/小 球队得分大小
  1153. if($p_code == 'total_size' || $p_code == 'team_score' || $p_code == 'concede'){
  1154. //可赢金额 = 赔率*投注金额
  1155. $prize_money = $odds*$bet_amount;
  1156. }else{
  1157. //可赢金额 = (赔率-1)*投注金额
  1158. $prize_money = ($odds-1)*$bet_amount;
  1159. }
  1160. }
  1161. //网球 可赢金额 计算规则
  1162. if($game_code == 'wq'){
  1163. //让盘 让局 总局数:大/小
  1164. if($p_code == 'dishes' || $p_code == 'bureau' || $p_code == 'total_number'){
  1165. //可赢金额 = 赔率*投注金额
  1166. $prize_money = $odds*$bet_amount;
  1167. }else{
  1168. //可赢金额 = (赔率-1)*投注金额
  1169. $prize_money = ($odds-1)*$bet_amount;
  1170. }
  1171. }
  1172. //棒球
  1173. if($game_code == 'bq'){
  1174. //让球 总得分:大/小
  1175. if($p_code == 'concede' || $p_code == 'total_size'){
  1176. //可赢金额 = 赔率*投注金额
  1177. $prize_money = $odds*$bet_amount;
  1178. }else{
  1179. //可赢金额 = (赔率-1)*投注金额
  1180. $prize_money = ($odds-1)*$bet_amount;
  1181. }
  1182. }
  1183. }
  1184. return $prize_money;
  1185. }
  1186. //计算赛事当前进行时间
  1187. function getMatchTime($match_date,$match_time){
  1188. $time = time() - strtotime($match_date.' '.$match_time);
  1189. //如果需要时刻格式
  1190. // $time = $this->dataformat($time);
  1191. return floor($time/60);
  1192. }
  1193. //将秒 转换为 时 分 秒
  1194. function dataformat($num=0) {
  1195. $hour = floor($num/3600);
  1196. $minute = floor(($num-3600*$hour)/60);
  1197. $second = floor((($num-3600*$hour)-60*$minute)%60);
  1198. return $hour.':'.$minute.':'.$second;
  1199. }
  1200. //根据赛事进行 时间 获取进程
  1201. function getMatchProcess($time=0,$game_code){
  1202. if($game_code == 'zq'){
  1203. if($time < 45) return '上半场';
  1204. return '下半场';
  1205. }
  1206. if($game_code == 'lq'){
  1207. if($time < 10) return '第一节';
  1208. if(($time > 10) and ($time < 20)) return '第二节';
  1209. if(($time > 20) and ($time < 30)) return '第三节';
  1210. if(($time > 30) and ($time < 40)) return '第四节';
  1211. }
  1212. if($game_code == 'wq'){
  1213. return '';
  1214. }
  1215. if($game_code == 'bq'){
  1216. return '';
  1217. }
  1218. }
  1219. }
  1220. ?>