DataLogic.php 92 KB

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