DataLogic.php 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/26
  6. * Time: 17:10
  7. */
  8. namespace App\Logic;
  9. use datainf\pplus\Instance;
  10. use App\Http\Response\Response;
  11. use App\Lib\ModelBase;
  12. use Illuminate\Database\Capsule\Manager as DB;
  13. use App\Lib\Biz\Sport\Common as commonFunction;
  14. use App\Http\Model\StBqResult as BqResultModel;
  15. use App\Http\Model\StBroadcast as broadcastModel;
  16. use App\Http\Model\StGameType as gameModel;
  17. use App\Http\Model\StLqResult as LqResultModel;
  18. use App\Http\Model\StWqResult as WqResultModel;
  19. use App\Http\Model\StZqLocalLeague as LeagueModel;
  20. use App\Http\Model\StZqLocalMatch as MatchModel;
  21. use App\Http\Model\StZqOdds as OddsModel;
  22. use App\Http\Model\StZqOddsRecord as OddsRecordModel;
  23. use App\Http\Model\StZqResult as ZqResultModel;
  24. use App\Http\Model\St_area_country as StAreaCountryModel;
  25. use App\Http\Model\St_set_sports_record as St_set_sports_recordModel;
  26. use App\Http\Model\St_team as StTeamModel;
  27. use App\Models\SportsNoteList as SportsNoteListModel;
  28. class DataLogic
  29. {
  30. use Instance;
  31. private $isRecord = 0;
  32. /*
  33. * 写 联赛 数据
  34. * 每个请求 包含 N个联赛
  35. */
  36. public function setLeague($data)
  37. {
  38. try {
  39. //开启事务
  40. DB::beginTransaction();
  41. $obt = $data['data'];
  42. //请求 数据 为空
  43. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  44. $getData = $this->getAddData($obt);
  45. //不是 联赛 数据
  46. if ($getData['title'] != 'league') throw new \Exception(Response::generate('不是联赛数据,', Response::ABNORMAL));
  47. /*
  48. //写请求数据 日志记录
  49. if($this->isRecord){
  50. commonFunction::SET_SPORTS_RECORD($obt,$getData['title']);
  51. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  52. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  53. }
  54. */
  55. //获取球类代码
  56. $game_code = $getData['game_code'];
  57. //获取数据源
  58. $source = $getData['source'];
  59. //获取球类名称
  60. $gameName = gameModel::getGameName($game_code);
  61. //获取 model
  62. $models = commonFunction::getModels($game_code, 1);
  63. //获取 联赛 数据
  64. $leagueData = $getData['data'];
  65. //获取 当前请求 所有 联赛 uuid
  66. $identity = [];
  67. foreach ($leagueData as $k => $v) {
  68. $identity[] = $v['uuid'];
  69. }
  70. $identity = array_unique($identity);
  71. sort($identity);
  72. //获取 本地 已存在 联赛
  73. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
  74. //二维数组去重
  75. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  76. //循环对比 请求identity->本地identity
  77. foreach ($l_lg_data as $k => $v) {
  78. foreach ($identity as $kk => $uuid) {
  79. if ($v['identity'] == $uuid) {
  80. unset($identity[$kk]);
  81. }
  82. }
  83. }
  84. //去除本地和请求里都存在的联赛,如果还有剩余联赛uuid,则将其写入
  85. if (!empty($identity)) {
  86. //没有 决赛时间 默认获取本年最后一天
  87. $last_time = date('Y-12-31 23:59:59');
  88. foreach ($leagueData as $k => $v) {
  89. foreach ($identity as $kk => $uuid) {
  90. if ($v['uuid'] == $uuid) {
  91. //如有 决赛时间
  92. if ($v['last_time']) {
  93. $last_time = $v['last_time'];
  94. }
  95. //获取联赛所属国家或地区
  96. $getArea = $this->getArea($v['name_chinese']);
  97. if ($getArea['pid'] == 0) {
  98. $area_id = $getArea['id'];
  99. $country_id = 0;
  100. } else {
  101. $area_id = $getArea['pid'];
  102. $country_id = $getArea['id'];
  103. }
  104. if (empty($v['uuid'])) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::LG__UUID_NULL));
  105. $set_lg['name_chinese'] = $v['name_chinese'];
  106. $set_lg['kind'] = $v['kind'];
  107. $set_lg['match_mode'] = $v['match_mode'];
  108. $set_lg['if_stop'] = $v['if_stop'];
  109. $set_lg['identity'] = $v['uuid'];
  110. $set_lg['last_time'] = $last_time;
  111. $set_lg['utime'] = date('Y-m-d H:i:s');
  112. $set_lg['area_id'] = $area_id ?: 247;
  113. $set_lg['country_id'] = $country_id ?: 0;
  114. //写入联赛
  115. $id = $models['model_league']::insertGetId($set_lg);
  116. $m_lg_id = $id;
  117. if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $v['lg_id'] . ';', Response::INSERT_ERROR));
  118. //写入 本地 联赛记录
  119. $set_local = [
  120. 'lg_id' => $id,
  121. 'others_lg_id' => $v['lg_id'],
  122. 'source' => $source,
  123. 'ctime' => date('Y-m-d H:i:s'),
  124. 'identity' => $v['uuid'],
  125. ];
  126. $ret = $models['model_local_league']::insertGetId($set_local);
  127. if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LOCAL_LEAGUE_ERROR));//Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
  128. }
  129. }
  130. }
  131. }
  132. $this->writeLog($data, Response::success());
  133. //提交事务
  134. DB::commit();
  135. return Response::success();
  136. } catch (\Exception $e) {
  137. //回滚事务
  138. DB::rollBack();
  139. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  140. return $e->getMessage();
  141. }
  142. }
  143. //写赛果接口
  144. public function setResultExpress($data)
  145. {
  146. $ret = $this->setResultExpress_v1($data);
  147. return $ret;
  148. }
  149. /**
  150. * 写赛果数据
  151. */
  152. public function setResultExpress_v1($data)
  153. {
  154. try {
  155. //开启事务
  156. DB::beginTransaction();
  157. $obt = $data['data'];
  158. //请求 数据 为空
  159. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  160. $getData = $this->getAddData($obt);
  161. //不是 赛事 结果 记录 数据
  162. if ($getData['title'] != 'result') throw new \Exception(Response::generate('不是赛果数据,', Response::ABNORMAL));
  163. //获取球类代码
  164. $game_code = $getData['game_code'];
  165. //获取数据源
  166. $source = $getData['source'];
  167. //获取球类名称
  168. $gameName = gameModel::getGameName($game_code);
  169. //获取 model
  170. $models = commonFunction::getModels($game_code, 1);
  171. //获取 赛事 数据
  172. $match_r_data = $getData['data'];
  173. if (!empty($match_r_data)) {
  174. foreach ($match_r_data as $k => $v) {
  175. $del = $models['model_result_express']::where('match_id', $v['match_id'])->delete();
  176. $v['c_time'] = date('Y-m-d H:i:s', time());
  177. $v['u_time'] = date('Y-m-d H:i:s', time());
  178. $v['source'] = $source;
  179. $v['play_data'] = json_encode($v['play_data'], JSON_UNESCAPED_UNICODE);
  180. $ret = $models['model_result_express']::insert($v);
  181. if ($ret != true) throw new \Exception(Response::generate($gameName . ';', Response::SET_MATCH_R_ERR));
  182. }
  183. //写 赛事 结果 记录
  184. }
  185. $this->writeLog($data, Response::success());
  186. //提交事务
  187. DB::commit();
  188. //写请求数据 日志记录
  189. return Response::success();
  190. } catch (\Exception $e) {
  191. //回滚事务
  192. DB::rollBack();
  193. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  194. return $e->getMessage();
  195. }
  196. }
  197. /*
  198. * 写 赛事 数据
  199. * 每个请求 包含 N个联赛 下 N个赛事
  200. */
  201. public function setMatch($data)
  202. {
  203. $logdata = $data;
  204. try {
  205. //开启事务
  206. DB::beginTransaction();
  207. $obt = $data['data'];
  208. //请求 数据 为空
  209. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  210. $getData = $this->getAddData($obt);
  211. //不是 赛事 数据
  212. if ($getData['title'] != 'match') throw new \Exception(Response::generate('不是赛事数据,', Response::ABNORMAL));
  213. /*
  214. //写请求数据 日志记录
  215. if($this->isRecord){
  216. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  217. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  218. }
  219. */
  220. //获取球类代码
  221. $game_code = $getData['game_code'];
  222. //获取数据源
  223. $source = $getData['source'];
  224. //获取球类名称
  225. $gameName = gameModel::getGameName($game_code);
  226. //获取 model
  227. $models = commonFunction::getModels($game_code, 1);
  228. //获取 赛事 数据
  229. $matchData = $getData['data'];
  230. //获取 当前请求 所有 uuid
  231. $identity = [];
  232. $s_match_ids = [];
  233. $match_uuids = [];
  234. foreach ($matchData as $k => $v) {
  235. $identity[] = $v['uuid'];
  236. $s_match_ids[] = $v['match_id'];
  237. }
  238. //====验证 赛事 所属 联赛 是否存在====
  239. $identity = array_unique($identity);
  240. sort($identity);
  241. //获取 本地 已存在 联赛
  242. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id', 'others_lg_id')->get()->toArray();
  243. //二维数组去重
  244. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  245. //如果获取不到本地联赛数据,则返回联赛不存在
  246. if (empty($l_lg_data)) throw new \Exception(Response::generate($gameName . '本次请求的所有赛事都没有联赛数据;', Response::LEAGUE_ERROR));
  247. //获取到本次请求,所有本地有联赛的赛事
  248. $mathData_before = $matchData;//接收原赛事
  249. $matchData = [];//获取新赛事
  250. foreach ($l_lg_data as $k => $v) {
  251. foreach ($mathData_before as $kk => $vv) {
  252. if ($v['identity'] == $vv['uuid']) {
  253. $matchData[] = $vv;
  254. }
  255. }
  256. }
  257. //获取当前请求有关联联赛的赛事 match_id
  258. $s_match_ids = [];
  259. foreach ($matchData as $k => $v) {
  260. $s_match_ids[] = $v['match_id'];
  261. //追加获取赛事uuid
  262. $match_uuids[] = $v['match_identity'];
  263. }
  264. //====获取 本地 已存在 赛事====
  265. $match_uuids = array_unique($match_uuids);
  266. sort($match_uuids);
  267. //$l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->where('source', $source)->select('match_id', 'identity')->get()->toArray();
  268. $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->select('match_id', 'identity')->get()->toArray();
  269. //二维数组去重
  270. $l_match_data = commonFunction::uniquArrV2($l_match_data, 'identity');
  271. //循环对比 请求match_id->本地others_match_id
  272. //如果本地有 赛事,则分别获取本地已存在/不存在赛事
  273. if (!empty($l_match_data)) {
  274. //本地已存在赛事,用于更新
  275. $matchData_y = [];
  276. foreach ($l_match_data as $k => $v) {
  277. foreach ($match_uuids as $kk => $match_identity) {
  278. if ($v['identity'] == $match_identity) {
  279. $matchData_y[$k]['match_identity'] = $match_identity;
  280. $matchData_y[$k]['match_id'] = $v['match_id'];
  281. unset($match_uuids[$kk]);
  282. }
  283. }
  284. }
  285. sort($match_uuids);
  286. }
  287. //如果 请求中 有本地赛事,则执行更新
  288. if (!empty($matchData_y)) {
  289. foreach ($matchData as $k => $v) {
  290. foreach ($matchData_y as $kk => $vv) {
  291. if ($v['match_identity'] == $vv['match_identity']) {
  292. $data = $v;
  293. $up_match = [];
  294. $up_match['utime'] = date('Y-m-d H:i:s');
  295. $up_match['status'] = $data['status'];
  296. //获取需更新字段
  297. if ($data['is_rollball'] == 1) {
  298. $up_match['is_rollball'] = $data['is_rollball'];
  299. }
  300. if ($data['is_today'] == 1) {
  301. $up_match['is_today'] = $data['is_today'];
  302. }
  303. if ($data['is_morningplate'] == 1) {
  304. $up_match['is_morningplate'] = $data['is_morningplate'];
  305. }
  306. if ($data['is_stringscene'] == 1) {
  307. $up_match['is_stringscene'] = $data['is_stringscene'];
  308. }
  309. //追加更新开赛日期/时间
  310. $up_match['match_date'] = $data['match_date'];
  311. $up_match['match_time'] = $data['match_time'];
  312. $up_match['us_time'] = $data['us_time'];
  313. //如果是网球 追加rule 字段
  314. if ($game_code == 'wq' and !empty($data['rule'])) {
  315. $up_match['rule'] = $data['rule'];
  316. }
  317. //更新赛事 返回成功数量
  318. $set = $models['model_match']::where(['id' => $vv['match_id']])
  319. ->update($up_match);
  320. if ($set < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPSTATUS_ERROR));
  321. }
  322. }
  323. }
  324. }
  325. //剩余 赛事 数据 写入
  326. if (!empty($match_uuids)) {
  327. foreach ($matchData as $k => $v) {
  328. foreach ($match_uuids as $kk => $match_identity) {
  329. if ($v['match_identity'] == $match_identity) {
  330. $data = $v;
  331. $half_match_id = $v['half_match_id'];
  332. //获取 本地 联赛 ID
  333. //验证本赛事是否有数据源lg_id
  334. if (empty($data['lg_id'])) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::S_LG_ID_NULL));
  335. $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
  336. //验证 本赛事是否获取到本地lg_id
  337. if (empty($lg_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::L_LG_ID_NULL));
  338. //如果赛事没有开始日期,则为冠军盘口赛事
  339. if (empty($data['match_date'])) {
  340. //冠军盘口赛事获取所属联赛结束时间
  341. $last_time = $models['model_league']::where(['id' => $lg_id])
  342. ->value('last_time');
  343. if (empty($last_time)) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LG_LASTTIME_ERROR));//Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
  344. //给冠军盘口赛事 赋值时间
  345. $time = strtotime($last_time);
  346. $data['match_date'] = date('Y-m-d', $time);
  347. $data['match_time'] = date('H:i:s', $time);
  348. }
  349. $set_match = [
  350. 'ctime' => date('Y-m-d H:i:s'),
  351. 'utime' => date('Y-m-d H:i:s'),
  352. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  353. 'home_team' => $data['home_team'] ?: '',
  354. 'guest_team' => $data['guest_team'] ?: 'no_team',
  355. 'lg_id' => $lg_id,
  356. 'status' => $data['status'],
  357. 'match_date' => $data['match_date'] ?: date('Y-m-d'),
  358. 'match_time' => $data['match_time'] ?: date('H:i:s'),
  359. 'is_rollball' => $data['is_rollball'] ?: 0,
  360. 'is_today' => $data['is_today'] ?: 0,
  361. 'is_morningplate' => $data['is_morningplate'] ?: 0,
  362. 'is_stringscene' => $data['is_stringscene'] ?: 0,
  363. 'is_horn' => $data['is_horn'] ?: 0,
  364. 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
  365. 'half_match_id' => $half_match_id ?: 0,
  366. 'identity' => $data['uuid'],
  367. 'match_identity' => $data['match_identity'],
  368. ];
  369. //如果是网球 追加rule 字段
  370. if ($game_code == 'wq') {
  371. $set_match['rule'] = $data['rule'];
  372. }
  373. //写入赛事 返回id
  374. $id = $models['model_match']::insertGetId($set_match);
  375. if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
  376. //写关联记录
  377. $set_local = [
  378. 'match_id' => $id,
  379. 'others_match_id' => $data['match_id'],
  380. 'source' => $source,
  381. 'identity' => $data['match_identity'],
  382. 'ctime' => date('Y-m-d H:i:s')
  383. ];
  384. $ret = $models['model_local_match']::insertGetId($set_local);
  385. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::LOCAL_MATCH_ERROR));
  386. //追加写球队名称
  387. $team = [
  388. 'team_h' => $data['home_team'],
  389. 'team_g' => $data['guest_team'],
  390. ];
  391. StTeamModel::setTeam($game_code, $team, $source);
  392. //追加写赛事结果
  393. $opt = [
  394. 'data' => $data,
  395. 'lg_id' => $lg_id,
  396. 'match_id' => $id,
  397. 'models' => $models,
  398. 'gameName' => $gameName,
  399. 'game_code' => $game_code,
  400. ];
  401. ZqResultModel::set_result($opt);
  402. }
  403. }
  404. }
  405. }
  406. $this->writeLog($logdata, Response::success());
  407. //提交事务
  408. DB::commit();
  409. return Response::success();
  410. } catch (\Exception $e) {
  411. //回滚事务
  412. DB::rollBack();
  413. $this->writeLog($logdata, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  414. return $e->getMessage();
  415. }
  416. }
  417. /*
  418. * 写 赛事 结果 记录 数据
  419. * 每个请求 包含 N个联赛 下 N个赛事 结果数据
  420. */
  421. public function setMatchResult($data)
  422. {
  423. $logdata = $data;
  424. try {
  425. //开启事务
  426. DB::beginTransaction();
  427. $obt = $data['data'];
  428. //请求 数据 为空
  429. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  430. $getData = $this->getAddData($obt);
  431. //不是 赛事 结果 记录 数据
  432. if ($getData['title'] != 'match_result_r') throw new \Exception(Response::generate('不是赛事结果记录数据,', Response::ABNORMAL));
  433. /*
  434. //写请求数据 日志记录
  435. if($this->isRecord){
  436. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  437. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  438. }
  439. */
  440. //获取球类代码
  441. $game_code = $getData['game_code'];
  442. //获取数据源
  443. $source = $getData['source'];
  444. //获取球类名称
  445. $gameName = gameModel::getGameName($game_code);
  446. //获取 model
  447. $models = commonFunction::getModels($game_code, 1);
  448. //获取 赛事 数据
  449. $match_r_data = $getData['data'];
  450. //获取 当前请求 所有 uuid /match_id
  451. $identity = [];
  452. $s_match_ids = [];
  453. $match_uuids = [];
  454. foreach ($match_r_data as $k => $v) {
  455. $identity[] = $v['uuid'];
  456. $s_match_ids[] = $v['match_id'];
  457. //追加获取赛事uuid
  458. $match_uuids[] = $v['match_identity'];
  459. }
  460. //====验证 赛事 所属 联赛 是否存在====
  461. $identity = array_unique($identity);
  462. sort($identity);
  463. //获取 本地 已存在 联赛
  464. $l_lg_data = $models['model_local_league']::whereIn('identity', $identity)->select('identity', 'lg_id')->get()->toArray();
  465. //二维数组去重
  466. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  467. //循环对比 请求uuid->本地identity
  468. foreach ($l_lg_data as $k => $v) {
  469. foreach ($identity as $kk => $uuid) {
  470. if ($v['identity'] == $uuid) {
  471. unset($identity[$kk]);
  472. }
  473. }
  474. }
  475. sort($identity);
  476. //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常
  477. if (!empty($identity)) throw new \Exception(Response::generate($gameName . '联赛:uuid-' . $identity[0] . ';', Response::LEAGUE_ERROR));
  478. //====end====
  479. //====验证 赛事结果记录 所属赛事 是否存在====
  480. $match_uuids = array_unique($match_uuids);
  481. sort($match_uuids);
  482. //获取 本地 已存在 赛事
  483. // $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->where('source', $source)->select('identity', 'match_id')->get()->toArray();
  484. $l_match_data = $models['model_local_match']::whereIn('identity', $match_uuids)->select('identity', 'match_id')->get()->toArray();
  485. //二维数组去重
  486. $l_match_data = commonFunction::uniquArrV2($l_match_data, 'identity');
  487. //循环对比 请求identity->本地identity
  488. foreach ($l_match_data as $k => $v) {
  489. foreach ($match_uuids as $kk => $match_identity) {
  490. if ($v['identity'] == $match_identity) {
  491. unset($match_uuids[$kk]);
  492. }
  493. }
  494. }
  495. sort($match_uuids);
  496. //去除本地和请求里都存在的赛事,如果还有剩余赛事id,则返回异常
  497. if (!empty($match_uuids)) throw new \Exception(Response::generate($gameName . '赛事-match_id' . $match_uuids[0] . ';', Response::MATCH_ERROR));
  498. //====end====
  499. //处理 赛事 结果记录 数据
  500. foreach ($match_r_data as $k => $v) {
  501. $data = $v;
  502. //获取 本地 联赛 ID
  503. $lg_id = commonFunction::searcharray($data['uuid'], 'identity', $l_lg_data, 'lg_id');
  504. //获取 本地 赛事 ID
  505. $match_id = commonFunction::searcharray($data['match_identity'], 'identity', $l_match_data, 'match_id');
  506. //根据球类 获取 赛事结果记录字段
  507. $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
  508. //写 赛事 结果 记录
  509. $ret = $models['model_result_record']::insert($set_match_r);
  510. if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));
  511. }
  512. $this->writeLog($logdata, Response::success());
  513. //提交事务
  514. DB::commit();
  515. return Response::success();
  516. } catch (\Exception $e) {
  517. //回滚事务
  518. DB::rollBack();
  519. $this->writeLog($logdata, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  520. return $e->getMessage();
  521. }
  522. }
  523. //将数组按按指定健名,重新生成新的数组,key在存在并且 值不能重复
  524. private function ArrayKeySet(Array $array, $key)
  525. {
  526. $ret = [];
  527. foreach ($array as $val) {
  528. $ret[$val[$key]] = $val;
  529. }
  530. return $ret;
  531. }
  532. /*
  533. * 写 普通 赔率 数据
  534. * 每个请求 只包含 一场赛事下 N条赔率
  535. */
  536. public function setOdds($data)
  537. {
  538. try {
  539. //开启事务
  540. DB::beginTransaction();
  541. $obt = $data['data'];
  542. //请求 数据 为空
  543. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  544. $getData = $this->getAddData($obt);
  545. //不是 赔率 数据
  546. if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
  547. //获取球类代码
  548. $game_code = $getData['game_code'];
  549. //获取数据源
  550. $source = $getData['source'];
  551. //获取源数据联赛ID
  552. $uuid = $getData['uuid'];
  553. //获取源数据赛事ID
  554. $s_match_id = $getData['match_id'];
  555. //获取赔率所属赛事 tag 值 玩法数量
  556. $tag = $getData['tag'] ?: 99;
  557. //获取赔率是否是串场
  558. $is_stringscene = $getData['is_stringscene'];
  559. //获取数据源赛事uuid
  560. $match_identity = $getData['match_identity'];
  561. //获取球类名称
  562. $gameName = gameModel::getGameName($game_code);
  563. //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
  564. $models = commonFunction::getModels($game_code, 1);
  565. $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
  566. $match_id = $this->matchVerify_v2($models, $match_identity, $source, $gameName);
  567. //更新赛事 tag 值
  568. //如果未获取到本地赛事id,则返回异常
  569. if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
  570. $upMatch = $models['model_match']::where(['id' => $match_id])
  571. ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
  572. if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
  573. //获取 赔率数据
  574. $oddsData = $getData['data'];
  575. //===追加处理赔率过滤===
  576. //获取当前赛事 在本地的所有赔率
  577. $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id, 'is_stringscene' => $is_stringscene])->get()->toArray();
  578. //获取请求待写入数据
  579. $setOddsData = [];
  580. //获取本地待删除数据
  581. $delOddsData = [];
  582. //本地没有该赛事赔率,则直接全部写入
  583. if (empty($l_odds_data)) {
  584. $setOddsData = $oddsData;
  585. } //本地有该赛事赔率,则分别获取需写入/删除的数据
  586. else {
  587. $newodds_t = $this->ArrayKeySet($oddsData, 'odds_only');
  588. $oldodds_t = $this->ArrayKeySet($l_odds_data, 'odds_only');
  589. foreach ($newodds_t as $key => $val) {
  590. if (isset($oldodds_t[$key])) {
  591. unset($newodds_t[$key]);
  592. unset($oldodds_t[$key]);
  593. }
  594. }
  595. $oddsData = $newodds_t;
  596. $l_odds_data = $oldodds_t;
  597. /*
  598. foreach ($oddsData as $k => $v) {
  599. foreach ($l_odds_data as $kk => $vv) {
  600. if ($v['odds_only'] == $vv['odds_only']) {
  601. unset($oddsData[$k]);
  602. unset($l_odds_data[$kk]);
  603. }
  604. }
  605. }
  606. */
  607. sort($oddsData);
  608. sort($l_odds_data);
  609. //需写入请求数据
  610. $setOddsData = $oddsData;
  611. //需删除本地数据
  612. $delOddsData = $l_odds_data;
  613. }
  614. //===end===
  615. //删除本地不在请求中的数据
  616. if (!empty($delOddsData)) {
  617. //所有需删除数据odds_only
  618. $odds_onlys = [];
  619. foreach ($delOddsData as $k => $v) {
  620. $odds_onlys[] = $v['odds_only'];
  621. }
  622. $del = $models['model_odds']::whereIn('odds_only', $odds_onlys)->delete();
  623. if ($del != count($odds_onlys)) throw new \Exception(Response::generate($gameName, Response::DEL_ODDS_ERR));
  624. }
  625. //写入请求中本地不存在的数据
  626. if (!empty($setOddsData)) {
  627. //处理待写入 赔率记录数据
  628. foreach ($setOddsData as $k => $v) {
  629. //组装数据
  630. $set_odds_r[] = [
  631. 'match_id' => $match_id ?: 0,
  632. 'others_match_id' => $v['match_id'] ?: 0,
  633. 'odds_code' => $v['odds_code'] ?: '',
  634. 'status' => $v['status'] ?: 0,
  635. 'sort' => $v['sort'] ?: 0,
  636. 'p_code' => $v['p_code'] ?: '',
  637. 'odds' => $v['odds'] ?: 0,
  638. 'condition' => $v['condition'],
  639. 'odds_only' => $v['odds_only'] ?: '',
  640. 'source' => $v['source'] ?: '',
  641. 'type' => $v['type'] ?: 0,
  642. 'team' => $v['team'] ?: '',
  643. 'lg_id' => $lg_id,
  644. 'is_stringscene' => $is_stringscene,
  645. 'others_lg_id' => $v['lg_id'],
  646. 'ctime' => date('Y-m-d H:i:s'),
  647. 'utime' => date('Y-m-d H:i:s'),
  648. ];
  649. }
  650. //处理待写入 赔率数据
  651. foreach ($oddsData as $k => $v) {
  652. //组装数据
  653. $set_odds[] = [
  654. 'match_id' => $match_id ?: 0,
  655. 'others_match_id' => $v['match_id'] ?: 0,
  656. 'odds_code' => $v['odds_code'] ?: '',
  657. 'status' => $v['status'] ?: 0,
  658. 'sort' => $v['sort'] ?: 0,
  659. 'p_code' => $v['p_code'] ?: '',
  660. 'odds' => $v['odds'] ?: 0,
  661. 'condition' => $v['condition'],
  662. 'odds_only' => $v['odds_only'] ?: '',
  663. 'source' => $v['source'] ?: '',
  664. 'type' => $v['type'] ?: 0,
  665. 'team' => $v['team'] ?: '',
  666. 'lg_id' => $lg_id,
  667. 'is_stringscene' => $is_stringscene,
  668. 'others_lg_id' => $v['lg_id'],
  669. 'ctime' => date('Y-m-d H:i:s'),
  670. 'utime' => date('Y-m-d H:i:s'),
  671. 'sole' => $v['sole'],
  672. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  673. ];
  674. }
  675. //写赔率记录数据
  676. $ret = $models['model_odds_record']::insert($set_odds_r);
  677. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  678. //写赔率 数据
  679. $ret = $models['model_odds']::insert($set_odds);
  680. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  681. }
  682. $this->writeLog($data, Response::success());
  683. //提交事务
  684. DB::commit();
  685. return Response::success();
  686. } catch (\Exception $e) {
  687. //回滚事务
  688. DB::rollBack();
  689. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  690. return $e->getMessage();
  691. }
  692. }
  693. /*
  694. * 写 普通 赔率 数据
  695. * 每个请求 只包含 一场赛事下 N条赔率
  696. */
  697. public function setOdds_old($data)
  698. {
  699. try {
  700. //开启事务
  701. DB::beginTransaction();
  702. $obt = $data['data'];
  703. //请求 数据 为空
  704. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  705. $getData = $this->getAddData($obt);
  706. //不是 赔率 数据
  707. if ($getData['title'] != 'odds') throw new \Exception(Response::generate('不是赔率数据,', Response::ABNORMAL));
  708. /*
  709. //写请求数据 日志记录
  710. if($this->isRecord){
  711. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  712. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  713. }
  714. */
  715. //获取球类代码
  716. $game_code = $getData['game_code'];
  717. //获取数据源
  718. $source = $getData['source'];
  719. //获取源数据联赛ID
  720. $uuid = $getData['uuid'];
  721. //获取源数据赛事ID
  722. $s_match_id = $getData['match_id'];
  723. //获取赔率所属赛事 tag 值 玩法数量
  724. $tag = $getData['tag'] ?: 99;
  725. //获取赔率是否是串场
  726. $is_stringscene = $getData['is_stringscene'];
  727. //获取球类名称
  728. $gameName = gameModel::getGameName($game_code);
  729. //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
  730. $models = commonFunction::getModels($game_code, 1);
  731. $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
  732. $match_id = $this->matchVerify($models, $s_match_id, $source, $gameName);
  733. //更新赛事 tag 值
  734. //如果未获取到本地赛事id,则返回异常
  735. if (empty($match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::L_MATCH_ID_ERR));
  736. $upMatch = $models['model_match']::where(['id' => $match_id])
  737. ->update(['tag' => $tag, 'utime' => date('Y-m-d H:i:s')]);
  738. if ($upMatch < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $s_match_id . ';', Response::UPMATCHTAG_ERROR));
  739. //获取 赔率数据
  740. $oddsData = $getData['data'];
  741. //获取 当前 所有 可用 赔率 sole
  742. $odds_only = $getData['odds_only'];
  743. //更新赛事下所有 不在本次请求的赔率 状态
  744. $ret = OddsModel::upOddsStatus($models, $s_match_id, '', $source, $odds_only, $is_stringscene);
  745. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  746. //获取当前赛事 在本地的所有赔率
  747. $l_odds_data = $models['model_odds']::select('odds_only')->where(['match_id' => $match_id])->get()->toArray();
  748. $set_odds_r = [];
  749. $set_odds = [];
  750. if (!empty($oddsData)) {
  751. //去除本地已有的赔率
  752. if (!empty($l_odds_data)) {
  753. foreach ($oddsData as $k => $v) {
  754. foreach ($l_odds_data as $kk => $vv) {
  755. if ($v['odds_only'] == $vv['odds_only']) {
  756. unset($oddsData[$k]);
  757. }
  758. }
  759. }
  760. sort($oddsData);
  761. }
  762. //处理待写入 赔率记录数据
  763. foreach ($oddsData as $k => $v) {
  764. //组装数据
  765. $set_odds_r[] = [
  766. 'match_id' => $match_id ?: 0,
  767. 'others_match_id' => $v['match_id'] ?: 0,
  768. 'odds_code' => $v['odds_code'] ?: '',
  769. 'status' => $v['status'] ?: 0,
  770. 'sort' => $v['sort'] ?: 0,
  771. 'p_code' => $v['p_code'] ?: '',
  772. 'odds' => $v['odds'] ?: 0,
  773. 'condition' => $v['condition'],
  774. 'odds_only' => $v['odds_only'] ?: '',
  775. 'source' => $v['source'] ?: '',
  776. 'type' => $v['type'] ?: 0,
  777. 'team' => $v['team'] ?: '',
  778. 'lg_id' => $lg_id,
  779. 'is_stringscene' => $is_stringscene,
  780. 'others_lg_id' => $v['lg_id'],
  781. 'ctime' => date('Y-m-d H:i:s'),
  782. 'utime' => date('Y-m-d H:i:s'),
  783. ];
  784. }
  785. //处理待写入 赔率数据
  786. foreach ($oddsData as $k => $v) {
  787. //组装数据
  788. $set_odds[] = [
  789. 'match_id' => $match_id ?: 0,
  790. 'others_match_id' => $v['match_id'] ?: 0,
  791. 'odds_code' => $v['odds_code'] ?: '',
  792. 'status' => $v['status'] ?: 0,
  793. 'sort' => $v['sort'] ?: 0,
  794. 'p_code' => $v['p_code'] ?: '',
  795. 'odds' => $v['odds'] ?: 0,
  796. 'condition' => $v['condition'],
  797. 'odds_only' => $v['odds_only'] ?: '',
  798. 'source' => $v['source'] ?: '',
  799. 'type' => $v['type'] ?: 0,
  800. 'team' => $v['team'] ?: '',
  801. 'lg_id' => $lg_id,
  802. 'is_stringscene' => $is_stringscene,
  803. 'others_lg_id' => $v['lg_id'],
  804. 'ctime' => date('Y-m-d H:i:s'),
  805. 'utime' => date('Y-m-d H:i:s'),
  806. 'sole' => $v['sole'],
  807. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  808. ];
  809. }
  810. //写赔率记录数据
  811. $ret = $models['model_odds_record']::insert($set_odds_r);
  812. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  813. //写赔率 数据
  814. $ret = $models['model_odds']::insert($set_odds);
  815. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  816. }
  817. $this->writeLog($data, Response::success());
  818. //提交事务
  819. DB::commit();
  820. return Response::success();
  821. } catch (\Exception $e) {
  822. //回滚事务
  823. DB::rollBack();
  824. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  825. return $e->getMessage();
  826. }
  827. }
  828. /**
  829. * @param Req $data
  830. * @return string
  831. * @throws \App\Lib\Biz\Sport\Exception
  832. * 更新赛事状态
  833. */
  834. public function upMatch($data)
  835. {
  836. $sdata = $data;
  837. try {
  838. //开启事务
  839. DB::beginTransaction();
  840. //获取待更新赛事
  841. $obt = $data['data'];
  842. //请求 数据 为空
  843. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  844. $data = $this->getAddData($obt);
  845. //不是更新赛事状态数据
  846. if ($data['title'] != 'match_status') throw new \Exception(Response::generate('不是更新赛事状态数据', Response::ABNORMAL));
  847. /*
  848. //写请求数据 日志记录
  849. if($this->isRecord){
  850. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  851. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  852. }
  853. */
  854. //获取 球类代码
  855. $game_code = $data['game_code'];
  856. //获取球类 名称
  857. $gameName = gameModel::getGameName($game_code);
  858. //获取 数据源
  859. $source = $data['source'];
  860. //获取 当前请求 所有 uuid /match_id
  861. $others_match_ids = [];
  862. $match_uuids = [];
  863. foreach ($data['data'] as $k => $v) {
  864. $others_match_ids[] = $v['match_id'];
  865. //追加获取赛事uuid
  866. $match_uuids[] = $v['match_identity'];
  867. }
  868. //根据球类代码 获取model
  869. $model = commonFunction::getModels($game_code, 1);
  870. //获取所有赛事 match_id
  871. $local_match = $model['model_local_match']::SELECT('others_match_id', 'match_id')
  872. ->where(['source' => $source])
  873. ->whereIn('identity', $match_uuids)
  874. ->get()->toArray();
  875. if (empty($local_match)) throw new \Exception(Response::generate('', Response::MATCHID_NULL));
  876. //设置各球类 判断结束时间
  877. if ($game_code == 'zq') {
  878. //足球 60分钟
  879. $handle_time = 60 * 60;
  880. }
  881. if ($game_code == 'lq') {
  882. //篮球 40分钟
  883. $handle_time = 60 * 40;
  884. }
  885. if ($game_code == 'wq') {
  886. //网球 2小时
  887. $handle_time = 60 * 60 * 2;
  888. }
  889. if ($game_code == 'bq') {
  890. //棒球 2小时
  891. $handle_time = 60 * 60 * 2;
  892. }
  893. //取值 更新字段
  894. foreach ($local_match as $k => $v) {
  895. foreach ($data['data'] as $kk => $vv) {
  896. if ($v['others_match_id'] == $vv['match_id']) {
  897. $set_status = [
  898. 'status' => $vv['status'],
  899. 'is_rollball' => $vv['is_rollball'],
  900. 'is_today' => $vv['is_today'],
  901. 'is_morningplate' => $vv['is_morningplate'],
  902. 'is_stringscene' => $vv['is_stringscene'],
  903. 'utime' => date('Y-m-d H:i:s'),
  904. ];
  905. //如果是足球 追加角球状态
  906. if ($game_code == 'zq') {
  907. $set_status['is_horn'] = $vv['is_horn'];
  908. }
  909. $ret = $model['model_match']::where(['id' => $v['match_id']])
  910. ->update($set_status);
  911. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $v['others_match_id'], Response::UPSTATUS_ERROR));
  912. //获取赛事开始时间
  913. $game_start_time = $model['model_result']::where(['match_id' => $v['match_id']])->first()->start_time;
  914. //开赛时间 时间戳
  915. $game_start_time_unx = strtotime($game_start_time);
  916. //===如果赛事已结束 并且 开赛时间< 当前时间-各球类处理时间 ===
  917. if ($vv['status'] == 2 and $game_start_time_unx < (time() - $handle_time)) {
  918. // 新增 更新 赛事结果
  919. $this->match_result($game_code, $v['match_id']);
  920. // 写入结算通知表 用于自动结算
  921. $Comendnotice = new \App\Models\Comendnotice();
  922. $ret_add = $Comendnotice->addcomendnotice($v['match_id'], $game_code, 0, $game_start_time);
  923. if ($ret_add != 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $v['others_match_id'], Response::ADD_NOTICE_ERR));
  924. }
  925. //===end===
  926. }
  927. }
  928. }
  929. $this->writeLog($sdata, Response::success());
  930. //提交事务
  931. DB::commit();
  932. return Response::success();
  933. } catch (\Exception $e) {
  934. //回滚事务
  935. DB::rollBack();
  936. $this->writeLog($sdata, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  937. return $e->getMessage();
  938. }
  939. }
  940. /*
  941. *写 冠军联赛 赔率 数据
  942. *每个请求 包含 N个联赛 下 N条赔率
  943. */
  944. public function setOddsCH_v1($data)
  945. {
  946. try {
  947. //开启事务
  948. DB::beginTransaction();
  949. $obt = $data['data'];
  950. //请求 数据 为空
  951. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  952. $getData = $this->getAddData($obt);
  953. //不是 冠军 赔率 数据
  954. if ($getData['title'] != 'odds_ch') throw new \Exception(Response::generate('不是冠军赔率数据,', Response::ABNORMAL));
  955. //写请求数据 日志记录
  956. if ($this->isRecord) {
  957. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'], $obt, $getData);
  958. if ($setSportsRecord < 1) throw new \Exception(Response::generate('', Response::SPORTS_RECORD_ERR));
  959. }
  960. //获取球类代码
  961. $game_code = $getData['game_code'];
  962. //获取数据源
  963. $source = $getData['source'];
  964. //获取球类名称
  965. $gameName = gameModel::getGameName($game_code);
  966. //获取 model
  967. $models = commonFunction::getModels($game_code, 1);
  968. //获取 赔率数据
  969. $oddsData = $getData['data'];
  970. //获取 当前 所有 可用 赔率 sole
  971. $odds_only = $getData['odds_only'];
  972. //====验证 请求里 所有赔率 所属联赛 是否存在 ====
  973. //获取 当前请求 所有 联赛 uuid
  974. $uuids = [];
  975. $s_lg_ids = [];
  976. foreach ($oddsData as $k => $v) {
  977. $uuids[] = $v['uuid'];
  978. $s_lg_ids[] = $v['lg_id'];
  979. }
  980. $s_lg_ids = array_unique($s_lg_ids);
  981. $uuids = array_unique($uuids);
  982. sort($uuids);
  983. sort($s_lg_ids);
  984. //更新联赛下所有 不在本次请求的赔率 状态
  985. $ret = OddsModel::upOddsStatus($models, '', $s_lg_ids, $source, $odds_only);
  986. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  987. //获取 本地 已存在 联赛
  988. $l_lg_data = $models['model_local_league']::whereIn('identity', $uuids)->select('identity', 'lg_id')->get()->toArray();
  989. //二维数组去重
  990. $l_lg_data = commonFunction::uniquArrV2($l_lg_data, 'identity');
  991. //循环对比 请求uuid->本地uuid
  992. foreach ($l_lg_data as $k => $v) {
  993. foreach ($uuids as $kk => $uuid) {
  994. if ($v['identity'] == $uuid) {
  995. unset($uuids[$kk]);
  996. }
  997. }
  998. }
  999. //去除本地和请求里都存在的联赛,如果还有剩余联赛id,则返回异常;
  1000. if (!empty($uuids)) throw new \Exception(Response::generate($gameName . '冠军联赛:uuid-' . $uuids[0] . ';', Response::LEAGUE_ERROR));
  1001. //====end====
  1002. //赔率记录数据
  1003. $set_odds_r = [];
  1004. //赔率数据
  1005. $set_odds = [];
  1006. if (!empty($oddsData)) {
  1007. foreach ($oddsData as $k => $v) {
  1008. //获取 本地 联赛 ID
  1009. $lg_id = commonFunction::searcharray($v['uuid'], 'identity', $l_lg_data, 'lg_id');
  1010. //组装赔率记录数据
  1011. $set_odds_r[] = [
  1012. 'match_id' => 0,
  1013. 'others_match_id' => $v['match_id'] ?: 0,
  1014. 'odds_code' => $v['odds_code'] ?: '',
  1015. 'status' => $v['status'] ?: 0,
  1016. 'sort' => $v['sort'] ?: 0,
  1017. 'p_code' => $v['p_code'] ?: '',
  1018. 'odds' => $v['odds'] ?: 0,
  1019. 'condition' => $v['condition'],
  1020. 'odds_only' => $v['odds_only'] ?: '',
  1021. 'source' => $v['source'] ?: '',
  1022. 'type' => $v['type'] ?: 1,
  1023. 'team' => $v['team'] ?: '',
  1024. 'lg_id' => $lg_id,
  1025. 'others_lg_id' => $v['lg_id'],
  1026. 'ctime' => date('Y-m-d H:i:s'),
  1027. 'utime' => date('Y-m-d H:i:s'),
  1028. ];
  1029. }
  1030. foreach ($oddsData as $k => $v) {
  1031. //获取 本地 联赛 ID
  1032. $lg_id = commonFunction::searcharray($v['uuid'], 'identity', $l_lg_data, 'lg_id');
  1033. //组装赔率数据
  1034. $set_odds[] = [
  1035. 'match_id' => 0,
  1036. 'others_match_id' => $v['match_id'] ?: 0,
  1037. 'odds_code' => $v['odds_code'] ?: '',
  1038. 'status' => $v['status'] ?: 0,
  1039. 'sort' => $v['sort'] ?: 0,
  1040. 'p_code' => $v['p_code'] ?: '',
  1041. 'odds' => $v['odds'] ?: 0,
  1042. 'condition' => $v['condition'],
  1043. 'odds_only' => $v['odds_only'] ?: '',
  1044. 'source' => $v['source'] ?: '',
  1045. 'type' => $v['type'] ?: 1,
  1046. 'team' => $v['team'] ?: '',
  1047. 'lg_id' => $lg_id,
  1048. 'others_lg_id' => $v['lg_id'],
  1049. 'ctime' => date('Y-m-d H:i:s'),
  1050. 'utime' => date('Y-m-d H:i:s'),
  1051. 'sole' => $v['sole'],
  1052. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  1053. ];
  1054. }
  1055. //写赔率记录数据
  1056. $ret = $models['model_odds_record']::insert($set_odds_r);
  1057. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  1058. //写赔率 数据
  1059. $ret = $models['model_odds']::insert($set_odds);
  1060. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  1061. }
  1062. $this->writeLog($data, Response::success());
  1063. //提交事务
  1064. DB::commit();
  1065. return Response::success();
  1066. } catch (\Exception $e) {
  1067. //回滚事务
  1068. DB::rollBack();
  1069. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  1070. return $e->getMessage();
  1071. }
  1072. }
  1073. /*
  1074. *写 冠军联赛 赔率 数据
  1075. *每个请求 包含 1个联赛 下 N条赔率
  1076. *追加赔率过滤
  1077. */
  1078. public function setOddsCH($data)
  1079. {
  1080. try {
  1081. //开启事务
  1082. DB::beginTransaction();
  1083. $obt = $data['data'];
  1084. //请求 数据 为空
  1085. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1086. $getData = $this->getAddData($obt);
  1087. //不是 冠军 赔率 数据
  1088. if ($getData['title'] != 'odds_ch') throw new \Exception(Response::generate('不是冠军赔率数据,', Response::ABNORMAL));
  1089. /*
  1090. //写请求数据 日志记录
  1091. if($this->isRecord){
  1092. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'],$obt,$getData);
  1093. if($setSportsRecord < 1) throw new \Exception(Response::generate('',Response::SPORTS_RECORD_ERR));
  1094. }
  1095. */
  1096. //获取球类代码
  1097. $game_code = $getData['game_code'];
  1098. //获取数据源
  1099. $source = $getData['source'];
  1100. //获取球类名称
  1101. $gameName = gameModel::getGameName($game_code);
  1102. //获取数据源联赛ID
  1103. $s_lg_id = $getData['lg_id'];
  1104. //获取源数据联赛UUID
  1105. $uuid = $getData['uuid'];
  1106. //获取 model
  1107. $models = commonFunction::getModels($game_code, 1);
  1108. //获取 赔率数据
  1109. $oddsData = $getData['data'];
  1110. //验证本次请求所属联赛/赛事是否存在 返回本地联赛/赛事ID
  1111. $lg_id = $this->leagueVerify($models, $uuid, $source, $gameName);
  1112. //===追加处理赔率过滤===
  1113. //获取当前联赛 在本地的所有赔率
  1114. $l_odds_data = $models['model_odds']::select('odds_only')->where(['lg_id' => $lg_id, 'type' => 1])->get()->toArray();
  1115. //获取请求待写入数据
  1116. $setOddsData = [];
  1117. //获取本地待删除数据
  1118. $delOddsData = [];
  1119. //本地没有该赛事赔率,则直接全部写入
  1120. if (empty($l_odds_data)) {
  1121. $setOddsData = $oddsData;
  1122. } //本地有该赛事赔率,则分别获取需写入/删除的数据
  1123. else {
  1124. $newodds_t = $this->ArrayKeySet($oddsData, 'odds_only');
  1125. $oldodds_t = $this->ArrayKeySet($l_odds_data, 'odds_only');
  1126. foreach ($newodds_t as $key => $val) {
  1127. if (isset($oldodds_t[$key])) {
  1128. unset($newodds_t[$key]);
  1129. unset($oldodds_t[$key]);
  1130. }
  1131. }
  1132. $oddsData = $newodds_t;
  1133. $l_odds_data = $oldodds_t;
  1134. sort($oddsData);
  1135. sort($l_odds_data);
  1136. //需写入请求数据
  1137. $setOddsData = $oddsData;
  1138. //需删除本地数据
  1139. $delOddsData = $l_odds_data;
  1140. }
  1141. //===end===
  1142. //删除本地不在请求中的数据
  1143. if (!empty($delOddsData)) {
  1144. //所有需删除数据odds_only
  1145. $odds_onlys = [];
  1146. foreach ($delOddsData as $k => $v) {
  1147. $odds_onlys[] = $v['odds_only'];
  1148. }
  1149. $del = $models['model_odds']::whereIn('odds_only', $odds_onlys)->delete();
  1150. if ($del != count($odds_onlys)) throw new \Exception(Response::generate($gameName, Response::DEL_ODDS_ERR));
  1151. }
  1152. //写入请求中本地不存在的数据
  1153. if (!empty($setOddsData)) {
  1154. foreach ($setOddsData as $k => $v) {
  1155. //组装赔率记录数据
  1156. $set_odds_r[] = [
  1157. 'match_id' => 0,
  1158. 'others_match_id' => $v['match_id'] ?: 0,
  1159. 'odds_code' => $v['odds_code'] ?: '',
  1160. 'status' => $v['status'] ?: 0,
  1161. 'sort' => $v['sort'] ?: 0,
  1162. 'p_code' => $v['p_code'] ?: '',
  1163. 'odds' => $v['odds'] ?: 0,
  1164. 'condition' => $v['condition'],
  1165. 'odds_only' => $v['odds_only'] ?: '',
  1166. 'source' => $v['source'] ?: '',
  1167. 'type' => $v['type'] ?: 1,
  1168. 'team' => $v['team'] ?: '',
  1169. 'lg_id' => $lg_id,
  1170. 'others_lg_id' => $v['lg_id'],
  1171. 'ctime' => date('Y-m-d H:i:s'),
  1172. 'utime' => date('Y-m-d H:i:s'),
  1173. ];
  1174. }
  1175. foreach ($oddsData as $k => $v) {
  1176. //组装赔率数据
  1177. $set_odds[] = [
  1178. 'match_id' => 0,
  1179. 'others_match_id' => $v['match_id'] ?: 0,
  1180. 'odds_code' => $v['odds_code'] ?: '',
  1181. 'status' => $v['status'] ?: 0,
  1182. 'sort' => $v['sort'] ?: 0,
  1183. 'p_code' => $v['p_code'] ?: '',
  1184. 'odds' => $v['odds'] ?: 0,
  1185. 'condition' => $v['condition'],
  1186. 'odds_only' => $v['odds_only'] ?: '',
  1187. 'source' => $v['source'] ?: '',
  1188. 'type' => $v['type'] ?: 1,
  1189. 'team' => $v['team'] ?: '',
  1190. 'lg_id' => $lg_id,
  1191. 'others_lg_id' => $v['lg_id'],
  1192. 'ctime' => date('Y-m-d H:i:s'),
  1193. 'utime' => date('Y-m-d H:i:s'),
  1194. 'sole' => $v['sole'],
  1195. 'expire_time' => date('Y-m-d H:i:s', time() + 60)
  1196. ];
  1197. }
  1198. //写赔率记录数据
  1199. $ret = $models['model_odds_record']::insert($set_odds_r);
  1200. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录;', Response::ADD_ODDS_R_ERROR));
  1201. //写赔率 数据
  1202. $ret = $models['model_odds']::insert($set_odds);
  1203. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率;', Response::ADD_ODDS_ERROR));
  1204. }
  1205. $this->writeLog($data, Response::success());
  1206. //提交事务
  1207. DB::commit();
  1208. return Response::success();
  1209. } catch (\Exception $e) {
  1210. //回滚事务
  1211. DB::rollBack();
  1212. $this->writeLog($data, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  1213. return $e->getMessage();
  1214. }
  1215. }
  1216. /*
  1217. * 写入直播 数据
  1218. */
  1219. public function setBroadCast($data)
  1220. {
  1221. $data_s = $data['data'];
  1222. try {
  1223. //开启事务
  1224. DB::beginTransaction();
  1225. $obt = $data['data'];
  1226. //请求 数据 为空
  1227. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1228. $getData = $this->getAddData($obt);
  1229. //不是 直播 数据
  1230. if ($getData['title'] != 'broad_cast') throw new \Exception(Response::generate('不是直播数据,', Response::ABNORMAL));
  1231. //写请求数据 日志记录
  1232. if ($this->isRecord) {
  1233. $setSportsRecord = St_set_sports_recordModel::setSportsRecord($getData['title'], $obt, $getData);
  1234. if ($setSportsRecord < 1) throw new \Exception(Response::generate('', Response::SPORTS_RECORD_ERR));
  1235. }
  1236. //获取 球类
  1237. $game_code = $getData['game_code'];
  1238. //删除当前球类已存在的直播数据
  1239. $del = broadcastModel::where('game_code', $game_code)->delete();
  1240. if ($del != true) throw new \Exception(Response::generate('', Response::DEL_PAST_BROADCAST_ERR));
  1241. //获取 直播 数据
  1242. $BroadCast = $getData['data'];
  1243. $set_broadcast = [];
  1244. foreach ($BroadCast as $k => $data) {
  1245. //组装数据
  1246. $set_broadcast[] = [
  1247. "doing" => $data['doing'],
  1248. "game_type" => $data['game_type'],
  1249. "game_code" => $game_code,
  1250. "guest_team" => $data['guest_team'],
  1251. "host_team" => $data['host_team'],
  1252. "league_name" => $data['league_name'],
  1253. "shower" => $data['shower'],
  1254. "showid" => (int)$data['showid'],
  1255. "start_time" => $data['start_time'],
  1256. "ctime" => date('Y-m-d H:i:s'),
  1257. "utime" => date('Y-m-d H:i:s'),
  1258. ];
  1259. }
  1260. //写入 直播 数据
  1261. $ret = broadcastModel::insert($set_broadcast);
  1262. if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
  1263. $this->writeLog($data_s, Response::success());
  1264. //提交事务
  1265. DB::commit();
  1266. return Response::success();
  1267. } catch (\Exception $e) {
  1268. //回滚事务
  1269. DB::rollBack();
  1270. $this->writeLog($data_s, ['file' => $e->getFile(), 'line' => $e->getLine(), 'msg' => $e->getMessage()]);
  1271. return $e->getMessage();
  1272. }
  1273. }
  1274. /**
  1275. * 写赛事危险球数据
  1276. */
  1277. public function setMatchWarn($data)
  1278. {
  1279. try {
  1280. //开启事务
  1281. DB::beginTransaction();
  1282. $obt = $data['data'];
  1283. //请求 数据 为空
  1284. if (empty($obt)) throw new \Exception(Response::generate('请求数据为空,', Response::ABNORMAL));
  1285. $getData = $this->getAddData($obt);
  1286. //不是 赛事 危险球 数据
  1287. if ($getData['title'] != 'match_warn') throw new \Exception(Response::generate('不是危险球数据,', Response::ABNORMAL));
  1288. //获取球类代码
  1289. $game_code = $getData['game_code'];
  1290. //获取数据源
  1291. $source = $getData['source'];
  1292. //获取数据源赛事id
  1293. $others_match_id = $getData['match_id'];
  1294. //获取数据源赛事uuid
  1295. $match_identity = $getData['match_identity'];
  1296. //获取球类名称
  1297. $gameName = gameModel::getGameName($game_code);
  1298. //获取 model
  1299. $models = commonFunction::getModels($game_code, 1);
  1300. //获取 赛事 数据
  1301. $warn_data = $getData['data'];
  1302. //获取赛事 match_id
  1303. $match_id = $models['model_local_match']::SELECT('others_match_id', 'match_id')
  1304. //->where(['source' => $source, 'identity' => $match_identity])
  1305. ->where(['identity' => $match_identity])
  1306. ->first()->match_id;
  1307. if (!empty($match_id)) {
  1308. //更新 危险球
  1309. $ret = ZqResultModel::set_result_warn($match_id, $warn_data);
  1310. if ($ret < 1) throw new \Exception(Response::generate('', Response::SET_WARN_ERR));
  1311. //追加 滚球投注 危险球审核
  1312. SportsNoteListModel::WarnHandle($match_id, $warn_data);
  1313. }
  1314. //提交事务
  1315. DB::commit();
  1316. //写请求数据 日志记录
  1317. $this->writeLog($data, Response::success());
  1318. return Response::success();
  1319. } catch (\Exception $e) {
  1320. //回滚事务
  1321. DB::rollBack();
  1322. //写请求数据 日志记录
  1323. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD($game_code, $getData, $getData['title'], $e->getMessage());
  1324. return $e->getMessage();
  1325. }
  1326. }
  1327. /**
  1328. * 定时执行 滚球投注危险球审核
  1329. */
  1330. public function HandleOrder()
  1331. {
  1332. try {
  1333. //开启事务
  1334. DB::beginTransaction();
  1335. $time = 60;
  1336. //处理指定时间内的滚球待审核订单
  1337. SportsNoteListModel::getOrderData($time);
  1338. //提交事务
  1339. DB::commit();
  1340. //写请求数据 日志记录
  1341. $this->writeLog(['HandleOrder' => 'ok'], Response::success());
  1342. return Response::success();
  1343. } catch (\Exception $e) {
  1344. //回滚事务
  1345. DB::rollBack();
  1346. //写请求数据 日志记录
  1347. $this->writeLog(['HandleOrder' => 'no', 'msg' => $e->getMessage()], Response::success());
  1348. return $e->getMessage();
  1349. }
  1350. }
  1351. /*
  1352. * 验证所属 联赛 是否存在
  1353. */
  1354. public function leagueVerify($models = [], $uuid = '', $source = '', $gameName = '')
  1355. {
  1356. if (empty($models) || empty($uuid)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1357. $l_lg_id = $models['model_local_league']::where(['identity' => $uuid])->value('lg_id');
  1358. if ($l_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛:lg_id-' . $uuid, Response::LEAGUE_ERROR));
  1359. return $l_lg_id;
  1360. }
  1361. /*
  1362. * 验证所属 赛事 是否存在
  1363. */
  1364. public function matchVerify($models = [], $s_match_id = '', $source = '', $gameName = '')
  1365. {
  1366. if (empty($models) || empty($s_match_id)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1367. $l_match_id = $models['model_local_match']::where(['others_match_id' => $s_match_id, 'source' => $source])->value('match_id');
  1368. if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . '赛事:match_id-' . $s_match_id, Response::MATCH_ERROR));
  1369. return $l_match_id;
  1370. }
  1371. /*
  1372. * 验证所属 赛事 是否存在
  1373. */
  1374. public function matchVerify_v2($models = [], $match_identity = '', $source = '', $gameName = '')
  1375. {
  1376. if (empty($models) || empty($match_identity)) throw new \Exception(Response::generate('', Response::ABNORMAL));
  1377. //$l_match_id = $models['model_local_match']::where(['identity' => $match_identity, 'source' => $source])->value('match_id');
  1378. $l_match_id = $models['model_local_match']::where(['identity' => $match_identity])->value('match_id');
  1379. if ($l_match_id < 1) throw new \Exception(Response::generate($gameName . 'match_identity-' . $match_identity, Response::MATCH_ERROR));
  1380. return $l_match_id;
  1381. }
  1382. /*
  1383. * 写入直播 数据
  1384. */
  1385. public function broadcast($opt = [], $game_code = '')
  1386. {
  1387. $data = $opt['data'];
  1388. $set_broadcast = [
  1389. "doing" => $data['doing'],
  1390. "game_type" => $data['game_type'],
  1391. "game_code" => $game_code,
  1392. "guest_team" => $data['guest_team'],
  1393. "host_team" => $data['host_team'],
  1394. "league_name" => $data['league_name'],
  1395. "shower" => $data['shower'],
  1396. "showid" => (int)$data['showid'],
  1397. "start_time" => $data['start_time'],
  1398. "ctime" => date('Y-m-d H:i:s'),
  1399. "utime" => date('Y-m-d H:i:s'),
  1400. ];
  1401. $ret = broadcastModel::insert($set_broadcast);
  1402. if ($ret == false) throw new \Exception(Response::generate('', Response::BROADCAST_ERROR));
  1403. }
  1404. /*
  1405. * 写入 赛事 初始 结果
  1406. */
  1407. public function match_result($game_code = '', $match_id = 0)
  1408. {
  1409. $model = commonFunction::getModels($game_code, 1);
  1410. if ($game_code == 'zq') ZqResultModel::ZQresult_v2($model, $match_id);
  1411. if ($game_code == 'lq') LqResultModel::LQresult_v2($model, $match_id);
  1412. if ($game_code == 'wq') WqResultModel::WQresult_v2($model, $match_id);
  1413. if ($game_code == 'bq') BqResultModel::BQresult_v2($model, $match_id);
  1414. }
  1415. /*
  1416. * 写入联赛数据
  1417. */
  1418. public function league($opt = [], $gameName = '')
  1419. {
  1420. $game_code = $opt['game_code'];
  1421. //根据球类代码获取相关model
  1422. $model = commonFunction::getModels($game_code, 1);
  1423. $data = $opt['data'];
  1424. //查询联赛是否已存在
  1425. $id = $model['model_league']::where('name_chinese', '=', $data['name_chinese'])
  1426. ->value('id');
  1427. //默认获取本年最后一天
  1428. $last_time = date('Y-12-31 23:59:59');
  1429. //决赛时间
  1430. if ($data['last_time']) {
  1431. $last_time = $data['last_time'];
  1432. }
  1433. $set_lg['name_chinese'] = $data['name_chinese'];
  1434. $set_lg['kind'] = $data['kind'];
  1435. $set_lg['match_mode'] = $data['match_mode'];
  1436. $set_lg['if_stop'] = $data['if_stop'];
  1437. $set_lg['identity'] = $data['uuid'] ?: '';
  1438. $set_lg['last_time'] = $last_time;
  1439. $set_lg['utime'] = date('Y-m-d H:i:s');
  1440. if (empty($id)) {
  1441. //写入联赛
  1442. $id = $model['model_league']::insertGetId($set_lg);
  1443. $m_lg_id = $id;
  1444. if ($m_lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::INSERT_ERROR));
  1445. } else {
  1446. //更新联赛
  1447. $ret = $model['model_league']::where(['id' => $id])
  1448. ->update($set_lg);
  1449. if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::UPDATE_ERROR));
  1450. }
  1451. $set_local = [
  1452. 'lg_id' => $id,
  1453. 'others_lg_id' => $data['lg_id'],
  1454. 'source' => $data['source'],
  1455. 'ctime' => date('Y-m-d H:i:s')
  1456. ];
  1457. $ret = $model['model_local_league']::insertGetId($set_local);
  1458. if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LOCAL_LEAGUE_ERROR));//Render([], '10017', lang('Tips','Sports')->get('local_league_error'));
  1459. //执行成功返回源数据 联赛ID
  1460. $data = ['others_lg_id' => $data['lg_id'], 'lg_id' => $id];
  1461. return $data;
  1462. }
  1463. /*
  1464. * 写入赛事数据
  1465. */
  1466. public function competition($opt = [], $gameName = '', $lg_id = '')
  1467. {
  1468. $game_code = $opt['game_code'];
  1469. //根据球类代码获取相关model
  1470. $model = commonFunction::getModels($game_code, 1);
  1471. $data = $opt['data'];
  1472. if (empty($data['lg_id'])) throw new \Exception(Response::generate('', Response::LEAGUE_ERROR));//Render([], '10015', lang('Tips','Sports')->get('league_error'));
  1473. //查询赛事是否存在
  1474. $id = $model['model_match']::where(['home_team' => $data['home_team'], 'guest_team' => $data['guest_team'], 'match_date' => $data['match_date'], 'match_time' => $data['match_time']])
  1475. ->value('id');
  1476. $half_match_id = 0;
  1477. //如果有上半场赛事id 获取上半场赛事是否存在
  1478. if (!empty($data['half_match_id'])) {
  1479. $half_match_id = $match_id = $model['model_local_match']::where(['others_match_id' => $data['half_match_id'], 'source' => $data['source']])
  1480. ->value('match_id');
  1481. if (empty($half_match_id)) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::HALF_MATCH_ERROR));//Render([], '10024', lang('Tips','Sports')->get('half_match_error'));
  1482. }
  1483. //如果赛事没有开始日期,则为冠军盘口赛事
  1484. if (empty($data['match_date'])) {
  1485. //冠军盘口赛事获取所属联赛结束时间
  1486. $last_time = $model['model_league']::where(['id' => $lg_id])
  1487. ->value('last_time');
  1488. if (empty($last_time)) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LG_LASTTIME_ERROR));//Render([], '10023', lang('Tips','Sports')->get('lg_lastTime_error'));
  1489. //给冠军盘口赛事 赋值时间
  1490. $time = strtotime($last_time);
  1491. $data['match_date'] = date('Y-m-d', $time);
  1492. $data['match_time'] = date('H:i:s', $time);
  1493. }
  1494. $set_match = [
  1495. 'ctime' => date('Y-m-d H:i:s'),
  1496. 'utime' => date('Y-m-d H:i:s'),
  1497. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  1498. 'home_team' => $data['home_team'] ?: '',
  1499. 'guest_team' => $data['guest_team'] ?: 'no_team',
  1500. 'lg_id' => $lg_id,
  1501. 'status' => $data['status'],
  1502. 'match_date' => $data['match_date'] ?: date('Y-m-d'),
  1503. 'match_time' => $data['match_time'] ?: date('H:i:s'),
  1504. 'tag' => $data['tag'] ?: 0,
  1505. 'is_rollball' => $data['is_rollball'] ?: 0,
  1506. 'is_today' => $data['is_today'] ?: 0,
  1507. 'is_morningplate' => $data['is_morningplate'] ?: 0,
  1508. 'is_stringscene' => $data['is_stringscene'] ?: 0,
  1509. 'us_time' => $data['us_time'] ?: commonFunction::qgmdate('Y-m-d H:i:s', '', -4),
  1510. 'half_match_id' => $half_match_id ?: 0,
  1511. 'identity' => $data['uuid'],
  1512. ];
  1513. //写入赛事
  1514. if (empty($id)) {
  1515. //写入赛事 返回id
  1516. $id = $model['model_match']::insertGetId($set_match);
  1517. if ($id < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::INSERT_ERROR));
  1518. } else {
  1519. //更新赛事
  1520. $ret = $model['model_match']::where(['id' => $id])->update($set_match);
  1521. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::UPDATE_ERROR));
  1522. }
  1523. //写关联记录
  1524. $set_local = [
  1525. 'match_id' => $id,
  1526. 'others_match_id' => $data['match_id'],
  1527. 'source' => $data['source'],
  1528. 'ctime' => date('Y-m-d H:i:s')
  1529. ];
  1530. $ret = $model['model_local_match']::insertGetId($set_local);
  1531. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::LOCAL_MATCH_ERROR));//Render([], '10018', lang('Tips','Sports')->get('local_match_error'));
  1532. //返回 源数据 赛事ID
  1533. $data = ['others_match_id' => $data['match_id'], 'match_id' => $id];
  1534. return $data;
  1535. }
  1536. /*
  1537. * 写入赔率/赔率记录数据
  1538. */
  1539. public function odds($opt = [], $gameName = '', $lg_id = 0, $match_id = 0, $oddsID = '', $oddsRecordID = '')
  1540. {
  1541. $game_code = $opt['game_code'];
  1542. //根据球类代码获取相关model
  1543. $model = commonFunction::getModels($game_code, 1);
  1544. $data = $opt['data'];
  1545. //获取赛事 本地/源ID
  1546. $others_match_id = $data['match_id'];
  1547. //获取联赛 本地/源ID
  1548. $others_lg_id = $data['lg_id'];
  1549. //===写赔率记录===
  1550. $set_odds_r = [
  1551. 'match_id' => $match_id ?: 0,
  1552. 'others_match_id' => $others_match_id ?: 0,
  1553. 'odds_code' => $data['odds_code'] ?: '',
  1554. 'status' => $data['status'] ?: 0,
  1555. 'sort' => $data['sort'] ?: 0,
  1556. 'p_code' => $data['p_code'] ?: '',
  1557. 'odds' => $data['odds'] ?: 0,
  1558. 'condition' => $data['condition'],
  1559. 'odds_only' => $data['odds_only'] ?: '',
  1560. 'source' => $data['source'] ?: '',
  1561. 'type' => $data['type'] ?: 0,
  1562. 'team' => $data['team'] ?: '',
  1563. 'lg_id' => $lg_id,
  1564. 'others_lg_id' => $others_lg_id,
  1565. 'ctime' => date('Y-m-d H:i:s'),
  1566. ];
  1567. //更新或写入赔率记录
  1568. if ($oddsRecordID != false) {
  1569. $ret = $model['model_odds_record']::where(['id' => $oddsRecordID])
  1570. ->update($set_odds_r);
  1571. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赔率记录-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_R_ERROR));//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
  1572. } else {
  1573. $ret = $model['model_odds_record']::insert($set_odds_r);
  1574. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率记录-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_R_ERROR));//Render([], '10020', lang('Tips','Sports')->get('add_odds_r_error'));
  1575. }
  1576. //===写赔率===
  1577. $set_odds = [
  1578. 'match_id' => $match_id ?: 0,
  1579. 'others_match_id' => $others_match_id ?: 0,
  1580. 'odds_code' => $data['odds_code'] ?: '',
  1581. 'status' => $data['status'] ?: 0,
  1582. 'sort' => $data['sort'] ?: 0,
  1583. 'p_code' => $data['p_code'] ?: '',
  1584. 'odds' => $data['odds'] ?: 0,
  1585. 'condition' => $data['condition'],
  1586. 'odds_only' => $data['odds_only'] ?: '',
  1587. 'sole' => $data['sole'] ?: '',
  1588. 'source' => $data['source'] ?: '',
  1589. 'type' => $data['type'] ?: 0,
  1590. 'team' => $data['team'] ?: '',
  1591. 'lg_id' => $lg_id,
  1592. 'others_lg_id' => $others_lg_id,
  1593. 'ctime' => date('Y-m-d H:i:s'),
  1594. 'utime' => date('Y-m-d H:i:s'),
  1595. 'expire_time' => date('Y-m-d H:i:s', time() + 60),
  1596. ];
  1597. //更新或写入赔率数据
  1598. if ($oddsID != false) {
  1599. $ret = $model['model_odds']::where(['id' => $oddsID])
  1600. ->update($set_odds);
  1601. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赔率-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_ERROR));//Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
  1602. } else {
  1603. $ret = $model['model_odds']::insert($set_odds);
  1604. if ($ret != true) throw new \Exception(Response::generate($gameName . '赔率-odds_only:' . $data['odds_only'] . ';', Response::ADD_ODDS_ERROR));//Render([], '10019', lang('Tips','Sports')->get('add_odds_error'));
  1605. }
  1606. //===end===
  1607. }
  1608. /*
  1609. * 更新 赛事下 所有不在本次请求的 赔率状态
  1610. */
  1611. public function upOddsStatus($opt = [], $gameName = '')
  1612. {
  1613. //获取球类代码
  1614. $game_code = $opt['game_code'];
  1615. //获取球类model
  1616. $model = commonFunction::getModels($game_code, 1);
  1617. //赛事下 所有 赔率sole
  1618. $odds_sole = $opt['data'];
  1619. //数据源 赛事 id
  1620. $others_match_id = $opt['match_id'];
  1621. //数据源
  1622. $source = $opt['source'];
  1623. //更新赛事下所有 不在本次请求的赔率 状态
  1624. $ret = OddsModel::getMatchSole($model, $others_match_id, '', $source, $odds_sole);
  1625. if ($ret != true) throw new \Exception(Response::generate($gameName, Response::ODDS_SOLE_ERR));
  1626. }
  1627. /*
  1628. * 写入联赛结果
  1629. */
  1630. public function league_result($opt, $gameName)
  1631. {
  1632. $game_code = $opt['game_code'];
  1633. //根据球类代码获取相关model
  1634. $model = commonFunction::getModels($game_code, 1);
  1635. $data = $opt['data'];
  1636. //验证结果所属联赛
  1637. $lg_id = $model['model_local_league']::where(['others_lg_id' => $data['lg_id'], 'source' => $data['source']])
  1638. ->value('lg_id');
  1639. if ($lg_id < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::LEAGUE_ERROR));
  1640. $lg_result_id = $model['model_league_result']::where(['lg_id' => $lg_id, 'game_name' => $data['game_name']])
  1641. ->value('id');
  1642. $set_lg_result = [
  1643. 'lg_id' => $lg_id,
  1644. 'game_name' => $data['game_name'],
  1645. 'result' => json_encode($data['result'], JSON_UNESCAPED_UNICODE),
  1646. 'status' => $data['status'],
  1647. 'ctime' => date('Y-m-d H:i:s'),
  1648. 'utime' => date('Y-m-d H:i:s'),
  1649. ];
  1650. //联赛结果数据处理
  1651. if (!empty($lg_result_id)) {
  1652. $ret = $model['model_league_result']::where(['id' => $lg_result_id])
  1653. ->update($set_lg_result);
  1654. if ($ret < 1) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::ADD_LG_R_ERROR));//Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
  1655. } else {
  1656. $ret = $model['model_league_result']::insert($set_lg_result);
  1657. if ($ret != true) throw new \Exception(Response::generate($gameName . '联赛-lg_id:' . $data['lg_id'] . ';', Response::ADD_LG_R_ERROR));//Render([], '10021', lang('Tips','Sports')->get('add_lg_r_error'));
  1658. }
  1659. }
  1660. /*
  1661. * 写入赛事结果
  1662. */
  1663. public function com_result($opt = [], $gameName = '', $lg_id = '', $match_id = '')
  1664. {
  1665. $game_code = $opt['game_code'];
  1666. //根据球类代码获取相关model
  1667. $model = commonFunction::getModels($game_code, 1);
  1668. $data = $opt['data'];
  1669. //查询结果是否存在
  1670. $match_r_id = $model['model_result']::where(['match_id' => $match_id])
  1671. ->value('id');
  1672. $set_match_r = [
  1673. "home_team" => $data['home_team'],
  1674. "guest_team" => $data['guest_team'],
  1675. "lg_id" => $lg_id,
  1676. "home_rate" => $data['home_rate'],
  1677. "guest_rate" => $data['guest_rate'],
  1678. "home_score" => $data['home_score'],
  1679. "guest_score" => $data['guest_score'],
  1680. "all_goal" => $data['all_goal'],
  1681. "status" => $data['status'],
  1682. "first_score" => $data['first_score'],
  1683. "last_score" => $data['last_score'],
  1684. "match_score" => $data['match_score'],
  1685. "match_winer" => $data['match_winer'],
  1686. "match_time" => $data['match_time'],
  1687. "match_process" => $data['match_process'],
  1688. "tag" => $data['tag'],
  1689. "match_id" => $match_id,
  1690. "u_home_score" => $data['u_home_score'],
  1691. "u_guest_score" => $data['u_guest_score'],
  1692. "p_code" => $data['p_code'],
  1693. "update_time" => date('Y-m-d H:i:s')
  1694. ];
  1695. //赛事结果数据处理
  1696. if (!empty($match_r_id)) {
  1697. $ret = $model['model_result']::where(['id' => $match_r_id])
  1698. ->update($set_match_r);
  1699. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
  1700. } else {
  1701. $ret = $model['model_result']::insert($set_match_r);
  1702. if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_error'));
  1703. }
  1704. // return Response::success();
  1705. }
  1706. //写入赛事结果记录
  1707. public function com_result_record($opt = [], $gameName = '', $lg_id = '', $match_id = '')
  1708. {
  1709. $game_code = $opt['game_code'];
  1710. //根据球类代码获取相关model
  1711. $model = commonFunction::getModels($game_code, 1);
  1712. $data = $opt['data'];
  1713. $match_r_id = $model['model_result_record']::where(['match_id' => $match_id, 'match_time' => $data['match_time']])
  1714. ->value('id');
  1715. //根据球类 获取 赛事结果记录字段
  1716. $set_match_r = $this->get_match_r($game_code, $lg_id, $match_id, $data);
  1717. //赛事结果记录处理
  1718. if ($match_r_id > 0) {
  1719. $ret = $model['model_result_record']::where(['id' => $match_r_id])
  1720. ->update($set_match_r);
  1721. if ($ret < 1) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
  1722. } else {
  1723. $ret = $model['model_result_record']::insert($set_match_r);
  1724. if ($ret != true) throw new \Exception(Response::generate($gameName . '赛事-match_id:' . $data['match_id'] . ';', Response::ADD_MATCH_R_R_ERROR));//Render([], '10022', lang('Tips','Sports')->get('add_match_r_r_error'));
  1725. }
  1726. }
  1727. /**
  1728. * @param $data
  1729. * @return mixed
  1730. * json转数组
  1731. */
  1732. public function getAddData($data)
  1733. {
  1734. $data = json_decode($data, true);
  1735. return $data;
  1736. }
  1737. /*
  1738. * 根据球类获取 赛事结果记录字段
  1739. */
  1740. public function get_match_r($game_code, $lg_id, $match_id, $data)
  1741. {
  1742. $set_match_r = [];
  1743. if ($game_code == 'zq') {
  1744. $set_match_r = [
  1745. "home_team" => $data['home_team'] ?: '',
  1746. "guest_team" => $data['guest_team'] ?: '',
  1747. "lg_id" => $lg_id,
  1748. "all_goal" => $data['all_goal'] ?: 0,
  1749. "home_rate" => $data['home_rate'] ?: 0,
  1750. "guest_rate" => $data['guest_rate'] ?: 0,
  1751. "home_score" => $data['home_score'] ?: 0,
  1752. "guest_score" => $data['guest_score'] ?: 0,
  1753. "status" => $data['status'] ?: 0,
  1754. "first_score" => $data['first_score'] ?: 0,
  1755. "last_score" => $data['last_score'] ?: 0,
  1756. "match_score" => $data['match_score'] ?: 0,
  1757. "match_winer" => $data['match_winer'] ?: '',
  1758. "match_time" => $data['match_time'] ?: 0,
  1759. "match_process" => $data['match_process'] ?: '',
  1760. // "tag"=> $data['tag']?:0,
  1761. "match_id" => $match_id,
  1762. "update_time" => date('Y-m-d H:i:s')
  1763. ];
  1764. };
  1765. if ($game_code == 'lq') {
  1766. $set_match_r = [
  1767. "home_team" => $data['home_team'] ?: '',
  1768. "guest_team" => $data['guest_team'] ?: '',
  1769. "lg_id" => $lg_id,
  1770. "home_rate" => $data['home_rate'] ?: 0,
  1771. "guest_rate" => $data['guest_rate'] ?: 0,
  1772. "home_score" => $data['home_score'] ?: 0,
  1773. "guest_score" => $data['guest_score'] ?: 0,
  1774. "status" => $data['status'] ?: 0,
  1775. "first_score" => $data['first_score'] ?: 0,
  1776. "last_score" => $data['last_score'] ?: 0,
  1777. "match_score" => $data['match_score'] ?: 0,
  1778. "match_winer" => $data['match_winer'] ?: '',
  1779. "match_time" => $data['match_time'] ?: 0,
  1780. "match_process" => $data['match_process'] ?: '',
  1781. // "tag"=> $data['tag']?:0,
  1782. "match_id" => $match_id,
  1783. "update_time" => date('Y-m-d H:i:s'),
  1784. "result_mark" => json_encode($data['result_mark']) ?: '',
  1785. ];
  1786. }
  1787. if ($game_code == 'wq') {
  1788. $set_match_r = [
  1789. "home_player_name" => $data['home_player_name'] ?: '',
  1790. "guest_player_name" => $data['guest_player_name'] ?: '',
  1791. "lg_id" => $lg_id,
  1792. "home_player_let_plate" => $data['home_player_let_plate'] ?: 0,
  1793. "guest_player_let_plate" => $data['guest_player_let_plate'] ?: 0,
  1794. "home_player_let_inning" => $data['home_player_let_inning'] ?: 0,
  1795. "guest_player_let_inning" => $data['guest_player_let_inning'] ?: 0,
  1796. "all_inning" => $data['all_inning'] ?: 0,
  1797. "home_player_score" => $data['home_player_score'] ?: 0,
  1798. "guest_player_score" => $data['guest_player_score'] ?: 0,
  1799. "status" => $data['status'] ?: 0,
  1800. "first_score_player" => $data['first_score_player'] ?: '',
  1801. "last_score_player" => $data['last_score_player'] ?: '',
  1802. "first_inning_score" => $data['first_inning_score'] ?: 0,
  1803. "second_inning_score" => $data['second_inning_score'] ?: 0,
  1804. "third_inning_score" => $data['third_inning_score'] ?: 0,
  1805. "match_winer_player" => $data['match_winer_player'] ?: '',
  1806. "update_time" => date('Y-m-d H:i:s'),
  1807. "match_time" => $data['match_time'] ?: 0,
  1808. "match_process" => $data['match_process'] ?: '',
  1809. // "tag"=>$data['tag']?:0,
  1810. "match_id" => $match_id,
  1811. "result_mark" => json_encode($data['result_mark']) ?: '',
  1812. ];
  1813. }
  1814. if ($game_code == 'bq') {
  1815. $set_match_r = [
  1816. "home_team" => $data['home_team'] ?: '',
  1817. "guest_team" => $data['guest_team'] ?: '',
  1818. "lg_id" => $lg_id,
  1819. "home_rate" => $data['home_rate'] ?: 0,
  1820. "guest_rate" => $data['guest_rate'] ?: 0,
  1821. "home_score" => $data['home_score'] ?: 0,
  1822. "guest_score" => $data['guest_score'] ?: 0,
  1823. "status" => $data['status'] ?: 0,
  1824. "first_score" => $data['first_score'] ?: 0,
  1825. "last_score" => $data['last_score'] ?: 0,
  1826. "match_score" => $data['match_score'] ?: 0,
  1827. "match_winer" => $data['match_winer'] ?: '',
  1828. "match_time" => $data['match_time'] ?: 0,
  1829. "match_process" => $data['match_process'] ?: '',
  1830. // "tag"=> $data['tag']?:0,
  1831. "match_id" => $match_id,
  1832. "all_inning" => $data['all_inning'] ?: 9,
  1833. "update_time" => date('Y-m-d H:i:s'),
  1834. "result_mark" => json_encode($data['result_mark']) ?: '',
  1835. ];
  1836. }
  1837. return $set_match_r;
  1838. }
  1839. /**
  1840. * 根据联赛名称 获取 国家 地区
  1841. */
  1842. public function getArea($leagueName = '')
  1843. {
  1844. //如果联赛名称有括号,去除
  1845. $leagueName = preg_replace('/\(.*?\)/', '', $leagueName);
  1846. //获取所有国家/地区
  1847. $areaData = StAreaCountryModel::select('id', 'pid', 'name')->get()->toArray();
  1848. //获取当前联赛所属国家
  1849. if (strpos($leagueName, 'NBA') !== false) {
  1850. $data = [
  1851. 'id' => 247,
  1852. 'pid' => 0,
  1853. 'name' => '世界'
  1854. ];
  1855. return $data;
  1856. }
  1857. //识别本地 国家地区数据
  1858. foreach ($areaData as $v => $k) {
  1859. if (strpos($leagueName, $k['name']) !== false) {
  1860. return $k;
  1861. }
  1862. }
  1863. //如果不能识别,则返回未知
  1864. $data = [
  1865. 'id' => 0,
  1866. 'pid' => 0,
  1867. 'name' => '未知国家或地区'
  1868. ];
  1869. return $data;
  1870. }
  1871. //写文本日志
  1872. private function writeLog($body, $ret)
  1873. {
  1874. go(function () use ($body, $ret) {
  1875. $json_data = json_encode($body, JSON_UNESCAPED_UNICODE);
  1876. $data = json_decode($body['data'], true);
  1877. $game_code = isset($data['game_code']) ? $data['game_code'] : '';
  1878. $title = isset($data['title']) ? $data['title'] : '';
  1879. $msg = is_string($ret) ? $ret : json_encode($ret, 256);
  1880. $now = explode(" ", microtime());
  1881. $wdata = date("Y-m-d", $now[1]);
  1882. $path = LOG_PATH . DS . $wdata . DS . $game_code . DS;
  1883. if (!file_exists($path)) {
  1884. $ret = mkdir($path, '0755', true);
  1885. if (!$ret) {
  1886. echo "$path --- Log File Create false \n";
  1887. return;
  1888. }
  1889. }
  1890. $lasttxt = date('Y-m-d H:i:s', $now[1]) . substr($now[0], 1, 5) . ' - ' . $msg . ' - ' . $json_data . "\n\n";
  1891. $file = $path . DS . $game_code . '_' . $title . '.log';
  1892. file_put_contents($file, $lasttxt, FILE_APPEND | LOCK_EX);
  1893. return;
  1894. });
  1895. return;
  1896. }
  1897. private function writeLog_db($body, $ret)
  1898. {
  1899. if (!is_string($body)) {
  1900. $body = json_encode([$body], 256);
  1901. }
  1902. if (!is_string($ret)) {
  1903. $ret = json_encode([$ret], 256);
  1904. }
  1905. $data = ['ctime' => date("Y-m-d H:i:s"), 'body' => $body, 'ret' => $ret];
  1906. $return = DB::table('datainf_log')->insert($data);
  1907. return $return;
  1908. }
  1909. }