DataLogic.php 91 KB

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