SoccerNoteListController.php 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jonlin
  5. * Date: 2019/4/9
  6. * Time: 9:11
  7. */
  8. namespace App\Http\Controllers\Admin;
  9. use App\Http\Controllers\Controller;
  10. use Illuminate\Http\Request as Req;
  11. use Illuminate\Support\Facades\DB;
  12. Use App\Lib\Settlement\SettlementOrder;
  13. Use App\Lib\Settlement\SettlementWinFail;
  14. use App\Models;
  15. use App\Models\MoneyBuySimplex as MoneyBuySimplexModel;
  16. use Request;
  17. /**
  18. *1
  19. */
  20. class SoccerNoteListController extends Controller
  21. {
  22. public function notelist(Req $req)
  23. {
  24. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  25. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  26. $request['account'] = isset($req->account) ? trim($req->account) : null;
  27. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
  28. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
  29. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
  30. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : null;
  31. $request['lg_id'] = isset($req->lg_id) ? trim($req->lg_id) : null;//联赛id 用于冠军联赛投注
  32. $request['is_gj'] = isset($req->is_gj) ? trim($req->is_gj) : 0;//是否是冠军联赛投注 0否 1是
  33. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  34. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  35. $request['p_codes'] = isset($req->p_codes) ? trim($req->p_codes) : null;
  36. $request['game_status'] = isset($req->game_status) ? trim($req->game_status) : 0;
  37. $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
  38. $dt = \App\Lib\DataTable\DataTable::init();
  39. $dt->setDataSource('/admin/SoccerNoteList/getinfo');
  40. $dt->setLang('sportsnotelist');
  41. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  42. $dt->addColsFields('match_id_order', array('sort' => true, 'width' => 210, 'minWidth'=>200));
  43. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  44. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 260));
  45. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
  46. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  47. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  48. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  49. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  50. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  51. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  52. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
  53. // $dt->addColsFields('game_status', array('templet' => '#game_status', 'sort' => false, 'width' => 114));
  54. $dt->addColsFields('game_status', array('sort' => false, 'width' => 80));
  55. // $arr[] = 'view';1
  56. // if (checkRriv('/admin/SoccerNoteList/edit')) {
  57. // $arr[] = 'edit';
  58. // }
  59. // $dt->setToolBar($arr, array('width' => 70));
  60. $dt->enableCheckBox();//var_dump($request['type']);
  61. return view('sports/sports_notelist', $dt->render($request));
  62. }
  63. //冠军注单手工结算1
  64. public function championset(Req $req)
  65. {
  66. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  67. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  68. $request['account'] = isset($req->account) ? trim($req->account) : null;
  69. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
  70. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
  71. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
  72. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : null;
  73. $request['lg_id'] = isset($req->lg_id) ? trim($req->lg_id) : null;//联赛id 用于冠军联赛投注
  74. $request['is_gj'] = isset($req->is_gj) ? trim($req->is_gj) : 1;//是否是冠军联赛投注 0否 1是
  75. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  76. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  77. $request['p_codes'] = isset($req->p_codes) ? trim($req->p_codes) : null;
  78. $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
  79. $dt = \App\Lib\DataTable\DataTable::init();
  80. $dt->setDataSource('/admin/SoccerNoteList/championsetinfo');
  81. $dt->setLang('sportsnotelist');
  82. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  83. $dt->addColsFields('lg_id_order', array('sort' => true, 'width' => 210, 'minWidth' => 200));
  84. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  85. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 260));
  86. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
  87. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  88. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  89. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  90. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  91. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  92. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  93. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
  94. // $dt->addColsFields('game_status', array('templet' => '#game_status', 'sort' => false, 'width' => 114));
  95. $dt->addColsFields('game_status', array( 'sort' => false, 'width' => 114));
  96. //$arr[] = 'view';
  97. // if (checkRriv('/admin/SoccerNoteList/edit')) {
  98. // $arr[] = 'edit';
  99. // }
  100. // $dt->setToolBar($arr, array('width' => 70));
  101. $dt->enableCheckBox();//var_dump($request['type']);
  102. return view('sports/sports_notelist', $dt->render($request));
  103. }
  104. function championsetinfo()
  105. {
  106. $page = Request::has('page') ? Request::get('page') : '';
  107. $list = Request::has('limit') ? Request::get('limit') : 10;
  108. $account = Request::get('account') ? Request::get('account') : '';
  109. $star_time = Request::get('star_time') ? Request::get('star_time') . ' 00:00:00' : '';
  110. $end_time = Request::get('end_time') ? Request::get('end_time') . ' 23:59:59' : '';
  111. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  112. $match_id = Request::get('match_id') ? Request::get('match_id') : '';
  113. $lg_id = Request::get('lg_id') ? Request::get('lg_id') : '';
  114. $status = Request::has('status') ? Request::get('status') : '-1';
  115. $order_status = Request::has('order_status') ? Request::get('order_status') : '';
  116. $p_codes = Request::has('p_codes') ? Request::get('p_codes') : '';
  117. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  118. $type = Request::has('type') ? Request::get('type') : 'zq';
  119. $where = array();
  120. $where[] = array('money_buy_simplex.is_champion', 1);
  121. if (!empty($account)) {
  122. if (empty($sureblur) || $sureblur == 'off') {
  123. $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
  124. } else {
  125. $where[] = array('money_buy_simplex.account_name', '=', $account);
  126. }
  127. }
  128. if (!empty($star_time)) {
  129. if (!empty($end_time)) {
  130. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  131. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  132. } else {
  133. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  134. }
  135. } else if (empty($star_time)) {
  136. if (!empty($end_time)) {
  137. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  138. }
  139. }
  140. if (!empty($order_id)) {
  141. $where[] = array('money_buy_simplex.order_id', $order_id);
  142. }
  143. if (!empty($match_id)) {
  144. $where[] = array('money_buy_simplex.match_id', $match_id);
  145. }
  146. if (!empty($p_codes)) {
  147. $where[] = array('money_buy_match.p_code', $p_codes);
  148. }
  149. //调整状态查询 1,2,3为订单状态 1投注 2作废 3撤单
  150. if ($order_status == 1 || $order_status == 2 || $order_status == 3) {
  151. $where[] = array('money_buy_simplex.status', '=', $order_status);
  152. }
  153. //4 5为结算状态 4未结算 5已结算
  154. if ($order_status == 4) {
  155. $status = 1;
  156. $where[] = array('money_buy_simplex.status', '=',1);
  157. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  158. }
  159. if ($order_status == 5) {
  160. $status = 2;
  161. $where[] = array('money_buy_simplex.status', '=',1);
  162. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  163. }
  164. //10进球无效 11红卡无效
  165. if ($order_status == 10) {
  166. $use_mark = '进球无效';
  167. $where[] = array('money_buy_simplex.status', '=',1);
  168. $where[] = array('money_buy_simplex.use_mark', '=', $use_mark);
  169. }
  170. if ($order_status == 11) {
  171. $use_mark = '红卡无效';
  172. $where[] = array('money_buy_simplex.status', '=',1);
  173. $where[] = array('money_buy_simplex.use_mark', '=', $use_mark);
  174. }
  175. //6 7 8 9 12 为输赢 6赢 7输 8赢一半 9输一半 12和局
  176. if ($order_status == 6) {
  177. $result = 1;
  178. $where[] = array('money_buy_simplex.status', '=',1);
  179. $where[] = array('money_buy_match.result', '=', $result);
  180. }
  181. if ($order_status == 7) {
  182. $result = -1;
  183. $where[] = array('money_buy_simplex.status', '=',1);
  184. $where[] = array('money_buy_match.result', '=', $result);
  185. }
  186. if ($order_status == 8) {
  187. $result = 3;
  188. $where[] = array('money_buy_simplex.status', '=',1);
  189. $where[] = array('money_buy_match.result', '=', $result);
  190. }
  191. if ($order_status == 9) {
  192. $result = 4;
  193. $where[] = array('money_buy_simplex.status', '=',1);
  194. $where[] = array('money_buy_match.result', '=', $result);
  195. }
  196. if ($order_status == 12) {
  197. $result = 2;
  198. $where[] = array('money_buy_simplex.status', '=',1);
  199. $where[] = array('money_buy_match.result', '=', $result);
  200. }
  201. if(!empty($lg_id)){
  202. $where[] = array('money_buy_simplex.lg_id', $lg_id);
  203. }
  204. if ($status != -1) {
  205. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  206. }
  207. if ($order_status != -1) {
  208. $where[] = array('money_buy_simplex.status', '=', $order_status);
  209. }
  210. $where[] = array('money_buy_simplex.game_code', $type);
  211. $newapp = new \App\Models\SportsNoteList();
  212. $data = $newapp->getinfo($list, $page, $where, $type);
  213. //$alldata = Models\MoneyBuyMatch::where('bet_type',1)->where('is_rolling',1)->distinct('order_id')->count('order_id');
  214. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  215. }
  216. //修改冠军单订单结果
  217. function orderupgj(Req $req)
  218. {
  219. $id = $req->id;//37
  220. $orderid = $req->order;//S20190916094723915270970
  221. if (intval($id) < 1) {
  222. return -1;
  223. }
  224. $data = \App\Models\SoccerLeague::where('id', $id)->first();
  225. $odds_code = \App\Models\SoccerOdds::where('lg_id', $id)->where('type', 1)->where('odds_code', '!=', '')->select('odds_code')->distinct()->get()->toArray();//赔率表
  226. for ($i = 0; $i < count($odds_code); $i++) {
  227. $allteam[] = \App\Models\SoccerOdds::where('odds_code', $odds_code[$i]['odds_code'])->where('lg_id', $id)->where('type', 1)->select('team')->distinct()->get()->toArray();
  228. }
  229. $data = $data->toArray();
  230. $isdisplay = \App\Models\Stwqleagueresult::where(['lg_id' => $id, 'status' => 1])->select("game_name")->distinct()->get()->toArray();
  231. $idisplay = array_column($isdisplay, 'game_name');
  232. $displays = implode(",", $idisplay);//转换成字符串
  233. //新增纪录
  234. foreach ($odds_code as $k => $v) {
  235. foreach ($allteam[$k] as $kk => $vv) {
  236. $name = $v['odds_code'];
  237. $isteam = $allteam[$k][$kk]['team'];
  238. $res = \App\Models\Stwqleagueresult::where(['lg_id' => $id, 'game_name' => $name, 'result' => $isteam])->first();
  239. $addresult = [
  240. 'lg_id' => $id,
  241. 'game_name' => $name,
  242. 'result' => $isteam,
  243. 'ctime' => date('Y-m-d H:i:s', time()),
  244. 'status' => 0,
  245. 'updated_at' => date('Y-m-d H:i:s', time()),
  246. ];
  247. if (empty($res)) {
  248. \App\Models\Stwqleagueresult::insert($addresult);
  249. }
  250. }
  251. }
  252. $orderjg = \App\Models\SportsNoteList::where(['order_id' => $orderid])->select("single_result")->first();
  253. $orderjg = json_decode($orderjg['single_result'], true);
  254. $data['allteam'] = $allteam;
  255. $data['odds_code'] = $odds_code;
  256. $data['displays'] = $displays;
  257. $data['isdisplay'] = $isdisplay;
  258. $data['orderjg'] = $orderjg;
  259. $data['orderid'] = $orderid;
  260. $data['lg_id'] = $id;
  261. return view('sports/orderupgj', $data);
  262. }
  263. //修改冠军单订单结果提交
  264. function ajaxtj(Req $req)
  265. {
  266. $isstatus = $req->isstatus;//更新
  267. $order = $req->order;
  268. if ($isstatus) {
  269. $gjresult = array(
  270. 'lg_id' => $req->lg_id ? $req->lg_id : '',
  271. 'game_name' => $req->odds_code ? $req->odds_code : '',
  272. 'result' => $req->team ? $req->team : '',
  273. 'updatetime' => date("Y-m-d H:i:s", time()),
  274. );
  275. } else {
  276. $gjresult = array(
  277. 'lg_id' => '',
  278. 'game_name' => '',
  279. 'result' => '',
  280. );
  281. }
  282. \App\Models\SportsNoteList::where(['order_id' => $order])->update(['single_result' => json_encode($gjresult, JSON_UNESCAPED_UNICODE)]);
  283. return responseToJson(1);
  284. }
  285. function info()
  286. {
  287. $page = Request::has('page') ? Request::get('page') : '';
  288. $list = Request::has('limit') ? Request::get('limit') : 10;
  289. $account = Request::get('account') ? Request::get('account') : '';
  290. $star_time = Request::get('star_time') ? Request::get('star_time') . ' 00:00:00' : '';
  291. $end_time = Request::get('end_time') ? Request::get('end_time') . ' 23:59:59' : '';
  292. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  293. $match_id = Request::get('match_id') ? Request::get('match_id') : '';
  294. // $status = Request::has('status') ? Request::get('status') : '';
  295. $order_status = Request::has('order_status') ? Request::get('order_status') : '';
  296. $p_codes = Request::has('p_codes') ? Request::get('p_codes') : '';
  297. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  298. $type = Request::has('type') ? Request::get('type') : 'zq';
  299. $where = array();
  300. $where[] = array('money_buy_simplex.is_champion', '<>', 1);
  301. if (!empty($account)) {
  302. if (empty($sureblur) || $sureblur == 'off') {
  303. $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
  304. } else {
  305. $where[] = array('money_buy_simplex.account_name', '=', $account);
  306. }
  307. }
  308. if (!empty($star_time)) {
  309. if (!empty($end_time)) {
  310. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  311. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  312. } else {
  313. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  314. }
  315. } else if (empty($star_time)) {
  316. if (!empty($end_time)) {
  317. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  318. }
  319. }
  320. if (!empty($order_id)) {
  321. $where[] = array('money_buy_simplex.order_id', $order_id);
  322. }
  323. if (!empty($match_id)) {
  324. $where[] = array('money_buy_simplex.match_id', $match_id);
  325. }
  326. if (!empty($p_codes)) {
  327. $where[] = array('money_buy_match.p_code', $p_codes);
  328. }
  329. //调整状态查询 1,2,3为订单状态 1投注 2作废 3撤单
  330. if ($order_status == 1 || $order_status == 2 || $order_status == 3) {
  331. $where[] = array('money_buy_simplex.status', '=', $order_status);
  332. }
  333. //4 5为结算状态 4未结算 5已结算
  334. if ($order_status == 4) {
  335. $status = 1;
  336. $where[] = array('money_buy_simplex.status', '=',1);
  337. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  338. }
  339. if ($order_status == 5) {
  340. $status = 2;
  341. $where[] = array('money_buy_simplex.status', '=',1);
  342. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  343. }
  344. //10进球无效 11红卡无效
  345. if ($order_status == 10) {
  346. $use_mark = '进球无效';
  347. $where[] = array('money_buy_simplex.status', '=',1);
  348. $where[] = array('money_buy_simplex.use_mark', '=', $use_mark);
  349. }
  350. if ($order_status == 11) {
  351. $use_mark = '红卡无效';
  352. $where[] = array('money_buy_simplex.status', '=',1);
  353. $where[] = array('money_buy_simplex.use_mark', '=', $use_mark);
  354. }
  355. //6 7 8 9 12 为输赢 6赢 7输 8赢一半 9输一半 12和局
  356. if ($order_status == 6) {
  357. $result = 1;
  358. $where[] = array('money_buy_simplex.status', '=',1);
  359. $where[] = array('money_buy_match.result', '=', $result);
  360. }
  361. if ($order_status == 7) {
  362. $result = -1;
  363. $where[] = array('money_buy_simplex.status', '=',1);
  364. $where[] = array('money_buy_match.result', '=', $result);
  365. }
  366. if ($order_status == 8) {
  367. $result = 3;
  368. $where[] = array('money_buy_simplex.status', '=',1);
  369. $where[] = array('money_buy_match.result', '=', $result);
  370. }
  371. if ($order_status == 9) {
  372. $result = 4;
  373. $where[] = array('money_buy_simplex.status', '=',1);
  374. $where[] = array('money_buy_match.result', '=', $result);
  375. }
  376. if ($order_status == 12) {
  377. $result = 2;
  378. $where[] = array('money_buy_simplex.status', '=',1);
  379. $where[] = array('money_buy_match.result', '=', $result);
  380. }
  381. /*
  382. if ($status != -1) {
  383. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  384. }
  385. if ($order_status != -1) {
  386. $where[] = array('money_buy_simplex.status', '=', $order_status);
  387. }
  388. */
  389. $where[] = array('money_buy_simplex.game_code', $type);
  390. $newapp = new \App\Models\SportsNoteList();
  391. $data = $newapp->getinfo($list, $page, $where, $type);
  392. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  393. }
  394. public function search(Req $req)
  395. {
  396. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  397. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  398. $request['account'] = isset($req->account) ? trim($req->account) : null;
  399. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
  400. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
  401. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
  402. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : null;
  403. $request['lg_id'] = isset($req->lg_id) ? trim($req->lg_id) : null;//联赛id 用于冠军联赛投注
  404. $request['is_gj'] = isset($req->is_gj) ? trim($req->is_gj) : 0;//是否是冠军联赛投注 0否 1是
  405. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  406. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  407. $request['p_codes'] = isset($req->p_codes) ? trim($req->p_codes) : null;
  408. $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
  409. $dt = \App\Lib\DataTable\DataTable::init();
  410. $dt->setDataSource('/admin/SoccerNoteList/info');
  411. $dt->setLang('sportsnotelist');
  412. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  413. $dt->addColsFields('match_id_order', array('sort' => true, 'width' => 210, 'minWidth'=>200));
  414. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  415. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 260));
  416. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
  417. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  418. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  419. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  420. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  421. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  422. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  423. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
  424. // $dt->addColsFields('settle_status', array('sort' => false, 'width' => 90));
  425. //$arr[] = 'view';
  426. // if (checkRriv('/admin/SoccerNoteList/edit')) {
  427. // $arr[] = 'edit';
  428. // }
  429. // $dt->setToolBar($arr, array('width' => 70));
  430. $dt->enableCheckBox();
  431. return view('sports/sports_search', $dt->render($request));
  432. }
  433. //冠军注单
  434. public function champion(Req $req)
  435. {
  436. $request['name_chinese'] = isset($req->name_chinese) ? trim($req->name_chinese) : null;
  437. $request['sureblurs'] = isset($req->sureblurs) ? $req->sureblurs : 'on';
  438. $request['account'] = isset($req->account) ? trim($req->account) : null;
  439. $request['star_time'] = isset($req->star_time) ? trim($req->star_time) : null;
  440. $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : null;
  441. $request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
  442. $request['match_id'] = isset($req->match_id) ? trim($req->match_id) : null;
  443. $request['lg_id'] = isset($req->lg_id) ? trim($req->lg_id) : null;//联赛id 用于冠军联赛投注
  444. $request['is_gj'] = isset($req->is_gj) ? trim($req->is_gj) : 1;//是否是冠军联赛投注 0否 1是
  445. $request['status'] = isset($req->status) ? trim($req->status) : '-1';
  446. $request['order_status'] = isset($req->order_status) ? trim($req->order_status) : '-1';
  447. $request['p_codes'] = isset($req->p_codes) ? trim($req->p_codes) : null;
  448. $request['type'] = isset($req->type) ? trim($req->type) : 'zq';
  449. $dt = \App\Lib\DataTable\DataTable::init();
  450. $dt->setDataSource('/admin/SoccerNoteList/championinfo');
  451. $dt->setLang('sportsnotelist');
  452. //$dt->addColsFields('id', array('templet' => '#userdetail', 'sort' => true, 'width' => 80));
  453. $dt->addColsFields('lg_id_order', array('sort' => true, 'width' => 210, 'minWidth' => 200));
  454. $dt->addColsFields('league', array('templet' => '#userdetail', 'sort' => false, 'width' => 100));
  455. $dt->addColsFields('home_guest', array('templet' => '#userdetail', 'sort' => false, 'width' => 260));
  456. $dt->addColsFields('content', array('templet' => '#userdetail', 'sort' => false, 'width' => 250));
  457. $dt->addColsFields('money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  458. $dt->addColsFields('water_return', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  459. $dt->addColsFields('prize_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 80));
  460. $dt->addColsFields('result', array('templet' => '#userdetail', 'sort' => false, 'width' => 70));
  461. $dt->addColsFields('money_match_time', array('templet' => '#userdetail', 'sort' => false, 'width' => 200));
  462. $dt->addColsFields('order_status', array('sort' => false, 'width' => 80));
  463. $dt->addColsFields('account_money', array('templet' => '#userdetail', 'sort' => false, 'width' => 110));
  464. // $dt->addColsFields('game_status', array('sort' => false, 'width' => 90));
  465. //$arr[] = 'view';
  466. // if (checkRriv('/admin/SoccerNoteList/edit')) {
  467. // $arr[] = 'edit';
  468. // }
  469. // $dt->setToolBar($arr, array('width' => 70));
  470. $dt->enableCheckBox();
  471. return view('sports/sports_search', $dt->render($request));
  472. }
  473. function championinfo()
  474. {
  475. $page = Request::has('page') ? Request::get('page') : '';
  476. $list = Request::has('limit') ? Request::get('limit') : 10;
  477. $account = Request::get('account') ? Request::get('account') : '';
  478. $star_time = Request::get('star_time') ? Request::get('star_time') . ' 00:00:00' : '';
  479. $end_time = Request::get('end_time') ? Request::get('end_time') . ' 23:59:59' : '';
  480. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  481. $match_id = Request::get('match_id') ? Request::get('match_id') : '';
  482. $lg_id = Request::get('lg_id') ? Request::get('lg_id') : '';
  483. $status = Request::has('status') ? Request::get('status') : '';
  484. $order_status = Request::has('order_status') ? Request::get('order_status') : '';
  485. $p_codes = Request::has('p_codes') ? Request::get('p_codes') : '';
  486. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  487. $type = Request::has('type') ? Request::get('type') : 'zq';
  488. $where = array();
  489. $where[] = array('money_buy_simplex.is_champion', 1);
  490. if (!empty($account)) {
  491. if (empty($sureblur) || $sureblur == 'off') {
  492. $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
  493. } else {
  494. $where[] = array('money_buy_simplex.account_name', '=', $account);
  495. }
  496. }
  497. if (!empty($star_time)) {
  498. if (!empty($end_time)) {
  499. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  500. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  501. } else {
  502. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  503. }
  504. } else if (empty($star_time)) {
  505. if (!empty($end_time)) {
  506. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  507. }
  508. }
  509. if (!empty($order_id)) {
  510. $where[] = array('money_buy_simplex.order_id', $order_id);
  511. }
  512. if (!empty($match_id)) {
  513. $where[] = array('money_buy_simplex.match_id', $match_id);
  514. }
  515. if(!empty($lg_id)){
  516. $where[] = array('money_buy_simplex.lg_id', $lg_id);
  517. }
  518. if (!empty($p_codes)) {
  519. $where[] = array('money_buy_match.p_code', $p_codes);
  520. }
  521. //调整状态查询 1,2,3为订单状态 1投注 2作废 3撤单
  522. if ($order_status == 1 || $order_status == 2 || $order_status == 3) {
  523. $where[] = array('money_buy_simplex.status', '=', $order_status);
  524. }
  525. //4 5为结算状态 4未结算 5已结算
  526. if ($order_status == 4) {
  527. $status = 1;
  528. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  529. }
  530. if ($order_status == 5) {
  531. $status = 2;
  532. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  533. }
  534. //10进球无效 11红卡无效
  535. if ($order_status == 10) {
  536. $use_mark = '进球无效';
  537. $where[] = array('money_buy_simplex.status', '=',1);
  538. $where[] = array('money_buy_simplex.use_mark', '=', $use_mark);
  539. }
  540. if ($order_status == 11) {
  541. $use_mark = '红卡无效';
  542. $where[] = array('money_buy_simplex.status', '=',1);
  543. $where[] = array('money_buy_simplex.use_mark', '=', $use_mark);
  544. }
  545. //6 7 8 9 12 为输赢 6赢 7输 8赢一半 9输一半 12和局
  546. if ($order_status == 6) {
  547. $result = 1;
  548. $where[] = array('money_buy_simplex.status', '=',1);
  549. $where[] = array('money_buy_match.result', '=', $result);
  550. }
  551. if ($order_status == 7) {
  552. $result = -1;
  553. $where[] = array('money_buy_simplex.status', '=',1);
  554. $where[] = array('money_buy_match.result', '=', $result);
  555. }
  556. if ($order_status == 8) {
  557. $result = 3;
  558. $where[] = array('money_buy_simplex.status', '=',1);
  559. $where[] = array('money_buy_match.result', '=', $result);
  560. }
  561. if ($order_status == 9) {
  562. $result = 4;
  563. $where[] = array('money_buy_simplex.status', '=',1);
  564. $where[] = array('money_buy_match.result', '=', $result);
  565. }
  566. if ($order_status == 12) {
  567. $result = 2;
  568. $where[] = array('money_buy_simplex.status', '=',1);
  569. $where[] = array('money_buy_match.result', '=', $result);
  570. }
  571. /*
  572. if ($status != -1) {
  573. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  574. }
  575. if ($order_status != -1) {
  576. $where[] = array('money_buy_simplex.status', '=', $order_status);
  577. }
  578. */
  579. $where[] = array('money_buy_simplex.game_code', $type);
  580. $newapp = new \App\Models\SportsNoteList();
  581. $data = $newapp->getinfo($list, $page, $where, $type);
  582. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  583. }
  584. //查询赛事结果
  585. // function Sairesult(Req $req){
  586. // $did = $req->did;
  587. // $qlgame = $req->qlgame?$req->qlgame:'zq';
  588. // $newapp = \App\Models\SportsNoteList::where('id', $did)->first();
  589. // if($qlgame=='zq'){
  590. // if($newapp['match_id']){
  591. // $newre = new \App\Models\Stzqresult();
  592. // $teamname = $newre->matchjg($newapp['match_id']);
  593. // }else{
  594. // $teamname ='';
  595. // }
  596. // }elseif($qlgame=='lq'){
  597. // if($newapp['match_id']){
  598. // $newre = new \App\Models\Stlqresult();
  599. // $teamname = $newre->matchjg($newapp['match_id']);
  600. // }else{
  601. // $teamname ='';
  602. // }
  603. // }elseif($qlgame=='bq'){
  604. // if($newapp['match_id']){
  605. // $newre = new \App\Models\Stbqresult();
  606. // $teamname = $newre->matchjg($newapp['match_id']);
  607. // }else{
  608. // $teamname ='';
  609. // }
  610. // }elseif($qlgame=='wq'){
  611. // if($newapp['match_id']){
  612. // $newre = new \App\Models\Stwqresult();
  613. // $teamname = $newre->matchjg($newapp['match_id']);
  614. // }else{
  615. // $teamname ='';
  616. // }
  617. // }else{
  618. // $data = "参数错误";
  619. // }
  620. // $data =array(
  621. // 'singleresult' => json_decode($newapp['single_result'],true),
  622. // 'teamname' => $teamname,
  623. // );
  624. // return $data;
  625. // }
  626. // function Sairesult(Req $req){
  627. // $did = $req->did;
  628. // $model = \App\Models\SportsNoteList::where('id', $did)->first();
  629. // $pid = $model['match_id'];
  630. // $saisjg = \App\Models\Stzqresult::where('match_id',$pid)->first()->toArray();//赛事结果
  631. // $saisjg['corner_ball'] = json_decode($saisjg['corner_ball'],true);
  632. // $saisjg['first_score'] = json_decode($saisjg['first_score'],true);
  633. // $saisjg['penalty_card'] = json_decode($saisjg['penalty_card'],true);
  634. // $saisjg['warn_more'] = json_decode($saisjg['warn_more'],true);
  635. // }
  636. //结果添加
  637. function addend(Req $req)
  638. {
  639. $did = $req->did;//59;//
  640. $qlgame = $req->qlgame;//1;
  641. $model = \App\Models\SportsNoteList::where('id', $did)->first();
  642. $pid = $model['match_id'];
  643. if ($qlgame == 1) {
  644. if ($model['result_flag'] != 1) {
  645. $saisjg = \App\Models\Stzqresult::where('match_id', $pid)->first()->toArray();//赛事结果
  646. $saisjg['corner_ball'] = json_decode($saisjg['corner_ball'], true);
  647. $saisjg['first_score'] = json_decode($saisjg['first_score'], true);
  648. $saisjg['penalty_card'] = json_decode($saisjg['penalty_card'], true);
  649. $saisjg['warn_more'] = json_decode($saisjg['warn_more'], true);
  650. $model->single_result = json_encode([$saisjg], JSON_UNESCAPED_UNICODE);
  651. $model->save();
  652. }
  653. $newm = \App\Models\SportsNoteList::where('id', $did)->first();
  654. return $newm['single_result'];
  655. } else {
  656. $new = \App\Models\SportsNoteList::where('id', $did)->first();
  657. $newa = json_decode($new['single_result'], true);
  658. $newa[0]['home_score'] = $req->home_score;//主队进球
  659. $newa[0]['guest_score'] = $req->guest_score;//客队进球
  660. $newa[0]['all_goal'] = intval($req->guest_score) + intval($req->home_score);//总进球
  661. $newa[0]['last_score'] = $req->lastscore ? $req->lastscore : '';//最后进球球队
  662. $newa[0]['match_winer'] = $req->matchwiner ? $req->matchwiner : '';//赢球球队
  663. $newa[0]['update_time'] = time();//更新时间
  664. $newa[0]['u_guest_score'] = $req->u_guest_score;//上半场-主队进球数
  665. $newa[0]['u_home_score'] = $req->u_home_score;//上半场-客队进球数
  666. $newa[0]['penalty_card'] = array(
  667. 'home' => $req->homeallcard,
  668. 'guest' => $req->guestallcard,
  669. 'home_half' => $req->homehalfcard,
  670. 'guest_half' => $req->guesthalfcard,
  671. );
  672. $newa[0]['corner_ball'] = array(
  673. 'home' => $req->homeallcorner,
  674. 'guest' => $req->guestallcorner,
  675. 'home_half' => $req->homehalfcorner,
  676. 'guest_half' => $req->guesthalfcorner,
  677. );
  678. //最新进球
  679. $newa[0]['first_score'] = array(
  680. 'teamscore' => $req->firstscore ? $req->firstscore : 0,//最先进球球队
  681. 'scoretime' => $req->onescoretime ? $req->onescoretime : '',//进球时间
  682. 'scoretype' => $req->firststye ? $req->firststye : '',//进球方式
  683. );
  684. $model->single_result = json_encode($newa, JSON_UNESCAPED_UNICODE);
  685. $model->result_flag = 1;
  686. $model->save();
  687. return responseToJson(1);
  688. }
  689. }
  690. function getinfo()
  691. {
  692. $page = Request::has('page') ? Request::get('page') : '';
  693. $list = Request::has('limit') ? Request::get('limit') : 10;
  694. $account = Request::get('account') ? Request::get('account') : '';
  695. $star_time = Request::get('star_time') ? Request::get('star_time') . ' 00:00:00' : '';
  696. $end_time = Request::get('end_time') ? Request::get('end_time') . ' 23:59:59' : '';
  697. $order_id = Request::get('order_id') ? Request::get('order_id') : '';
  698. $match_id = Request::get('match_id') ? Request::get('match_id') : '';
  699. $status = Request::has('status') ? Request::get('status') : '-1';
  700. $order_status = Request::has('order_status') ? Request::get('order_status') : '';
  701. $p_codes = Request::has('p_codes') ? Request::get('p_codes') : '';
  702. $sureblur = Request::has('sureblurs') ? Request::get('sureblurs') : 'off';
  703. $type = Request::has('type') ? Request::get('type') : 'zq';
  704. $where = array();
  705. $where[] = array('money_buy_simplex.is_champion', '<>', 1);
  706. if (!empty($account)) {
  707. if (empty($sureblur) || $sureblur == 'off') {
  708. $where[] = array('money_buy_simplex.account_name', 'like', '%' . $account . '%');
  709. } else {
  710. $where[] = array('money_buy_simplex.account_name', '=', $account);
  711. }
  712. }
  713. if (!empty($star_time)) {
  714. if (!empty($end_time)) {
  715. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  716. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  717. } else {
  718. $where[] = array('money_buy_simplex.money_time', '>', $star_time);
  719. }
  720. } else if (empty($star_time)) {
  721. if (!empty($end_time)) {
  722. $where[] = array('money_buy_simplex.money_time', '<', $end_time);
  723. }
  724. }
  725. if (!empty($order_id)) {
  726. $where[] = array('money_buy_simplex.order_id', $order_id);
  727. }
  728. if (!empty($match_id)) {
  729. $where[] = array('money_buy_simplex.match_id', $match_id);
  730. }
  731. if (!empty($p_codes)) {
  732. $where[] = array('money_buy_match.p_code', $p_codes);
  733. }
  734. //调整状态查询 1,2,3为订单状态 1投注 2作废 3撤单
  735. if ($order_status == 1 || $order_status == 2 || $order_status == 3) {
  736. $where[] = array('money_buy_simplex.status', '=', $order_status);
  737. }
  738. //4 5为结算状态 4未结算 5已结算
  739. if ($order_status == 4) {
  740. $status = 1;
  741. $where[] = array('money_buy_simplex.status', '=',1);
  742. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  743. }
  744. if ($order_status == 5) {
  745. $status = 2;
  746. $where[] = array('money_buy_simplex.status', '=', 1);
  747. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  748. }
  749. //10进球无效 11红卡无效
  750. if ($order_status == 10) {
  751. $use_mark = '进球无效';
  752. $where[] = array('money_buy_simplex.status', '=',1);
  753. $where[] = array('money_buy_simplex.use_mark', '=', $use_mark);
  754. }
  755. if ($order_status == 11) {
  756. $use_mark = '红卡无效';
  757. $where[] = array('money_buy_simplex.status', '=',1);
  758. $where[] = array('money_buy_simplex.use_mark', '=', $use_mark);
  759. }
  760. //6 7 8 9 12 为输赢 6赢 7输 8赢一半 9输一半 12和局
  761. if ($order_status == 6) {
  762. $result = 1;
  763. $where[] = array('money_buy_simplex.status', '=',1);
  764. $where[] = array('money_buy_match.result', '=', $result);
  765. }
  766. if ($order_status == 7) {
  767. $result = -1;
  768. $where[] = array('money_buy_simplex.status', '=',1);
  769. $where[] = array('money_buy_match.result', '=', $result);
  770. }
  771. if ($order_status == 8) {
  772. $result = 3;
  773. $where[] = array('money_buy_simplex.status', '=',1);
  774. $where[] = array('money_buy_match.result', '=', $result);
  775. }
  776. if ($order_status == 9) {
  777. $result = 4;
  778. $where[] = array('money_buy_simplex.status', '=',1);
  779. $where[] = array('money_buy_match.result', '=', $result);
  780. }
  781. if ($order_status == 12) {
  782. $result = 2;
  783. $where[] = array('money_buy_simplex.status', '=',1);
  784. $where[] = array('money_buy_match.result', '=', $result);
  785. }
  786. /*
  787. if ($status != -1) {
  788. $where[] = array('money_buy_simplex.settle_status', '=', $status);
  789. }
  790. if ($order_status != -1) {
  791. $where[] = array('money_buy_simplex.status', '=', $order_status);
  792. }
  793. */
  794. $where[] = array('money_buy_simplex.game_code', $type);
  795. $newapp = new \App\Models\SportsNoteList();
  796. $data = $newapp->getinfo($list, $page, $where, $type);
  797. //$alldata = Models\MoneyBuyMatch::where('bet_type',1)->where('is_rolling',1)->distinct('order_id')->count('order_id');
  798. return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total'], 0, $where);
  799. }
  800. /**
  801. * 取消结算
  802. */
  803. public function no_cancel_end(Req $req){
  804. $order_id = $req->order_id;
  805. if(empty($order_id)){
  806. return responseToJson(-1, '参数错误');
  807. }
  808. try {
  809. //开启事务
  810. DB::beginTransaction();
  811. //处理注单数据
  812. $orderModel = new \App\Models\SportsNoteList();
  813. $ret = $orderModel->no_cancel_end($order_id);
  814. if($ret != 1) throw new \Exception('操作失败');
  815. //提交事务
  816. DB::commit();
  817. return responseToJson(1, '成功');
  818. } catch (\Exception $e) {
  819. //回滚事务
  820. DB::rollBack();
  821. return responseToJson(-1, $e->getMessage());
  822. }
  823. }
  824. /**
  825. * 取消作废
  826. */
  827. public function no_cancel_invalid(Req $req){
  828. $order_id = $req->order_id;
  829. return responseToJson(1, '成功', $order_id);
  830. dd('取消作废');
  831. }
  832. /**
  833. *单式注单作废
  834. */
  835. public function invalid(Req $req)
  836. {
  837. $id = $req->id;
  838. $reason = $_GET['reason'];
  839. if (intval($id) < 1) {
  840. return -1;
  841. }
  842. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  843. //用戶账户金额
  844. $account_money = \App\Models\Account_detailed::where('account_identity', $order->account_identity)->first();
  845. //反水
  846. $water_return_money = \App\Models\Money_details::where('trade_id', $order->order_id)->where('trade_type', '7')->first();
  847. if (!empty($water_return_money)) {
  848. $water_return = $water_return_money->money;
  849. } else {
  850. $water_return = 0;
  851. }
  852. //撤单后用户账户金额
  853. $available_cash = $account_money->available_cash;
  854. $new_available_cash = $available_cash + $order->money - $order->gain_money - $water_return;
  855. $model = new \App\Models\Money_details();
  856. $model->info_identity = UUID();
  857. $model->trade_id = $order->order_id;
  858. $model->account_name = $order->account_name;
  859. $model->account_identity = $order->account_identity;
  860. $model->money = abs($order->money - $order->gain_money - $water_return);
  861. $model->money_time = date("Y-m-d H:i:s", time());
  862. if ($new_available_cash > $available_cash) {
  863. $model->money_type = '1';
  864. } else {
  865. $model->money_type = '2';
  866. }
  867. $model->money_cash = $new_available_cash;
  868. $model->trade_type = '3';
  869. $model->trade_desc = '管理员作废单式注单';
  870. $model->status = '1';
  871. try {
  872. DB::beginTransaction();//开启事务
  873. \App\Models\SportsNoteList::where('id', $id)->update(['status' => '2', 'gain_money' => '0', 'use_mark' => $reason]);
  874. \App\Models\Account_detailed::where('account_identity', $order->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
  875. $model->save();
  876. DB::commit();//提交
  877. return 1;
  878. } catch (Exception $e) {
  879. DB::rollback();//回滚
  880. return -1;
  881. }
  882. }
  883. /**
  884. *单式注单首次结算
  885. */
  886. public function settlement(Req $req)
  887. {
  888. $id = $req->id;
  889. if (intval($id) < 1) {
  890. return -1;
  891. }
  892. $order = \App\Models\SportsNoteList::where('id', $id)->first();
  893. $order_id = $order->order_id;
  894. $order_ids = array($order->order_id);
  895. $match_id = $order->match_id;
  896. $game_code = $order->game_code;
  897. $bet_type = 1;//单式注单
  898. //return $match_id;
  899. //判断输赢
  900. $settlementWinFail = new SettlementWinFail();
  901. $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
  902. //结算
  903. $SettlementOrder = new SettlementOrder();
  904. $settype = 1; //首次结算
  905. $data = $SettlementOrder->reSettlement($order_ids, $bet_type, $settype, $game_code, $match_id, $match_status = 0);
  906. return $data;
  907. }
  908. /**
  909. *单式注单重新结算
  910. */
  911. // public function resettlement(Req $req) {
  912. // $id = $req->id;
  913. // if (intval($id) < 1) {
  914. // return -1;
  915. // }
  916. // $order = \App\Models\SportsNoteList::where('id',$id)->first();
  917. // $match_id = $order->match_id;
  918. // $game_code = $order->game_code;
  919. // $order_id = $order->order_id;
  920. // $order_ids = array($order->order_id);
  921. // //return $match_id;
  922. // $bet_type = 1;//单式注单
  923. // //重新判断输赢
  924. // $settlementWinFail = new SettlementWinFail();
  925. // $res = $settlementWinFail->ProcWinInfoByOneOrder($match_id, $order_id, $bet_type);
  926. // //结算
  927. // $SettlementOrder = new SettlementOrder();
  928. // $settype = 2; //重新结算
  929. // $data = $SettlementOrder->reSettlement($order_ids,$bet_type,$settype,$game_code,$match_id,$match_status=0);
  930. // return $data;
  931. // }
  932. public function resettlement(Req $req)
  933. {
  934. $order_id = $req->order_id;
  935. $type = $req->type;
  936. $match_id = $req->match_id;
  937. $jsurl = config('sconstant.url');//结算请求域名地址
  938. $token = session('adminInfo.token');
  939. //查询是否有订单
  940. $newapp = new \App\Models\SportsNoteList();
  941. $simplexnum = $newapp->onlyorder($order_id);
  942. if ($simplexnum == 1) {
  943. $requet = file_get_contents($jsurl . "/DoWinFailOneOrder?order_id=" . $order_id . "&token=" . $token);
  944. if (json_decode($requet, true)['status'] == 1) {
  945. $napp = new \App\Models\Stzqresult();
  946. $simplex = array(
  947. 'token' => $token,
  948. 'order_ids' => $order_id, //订单id字符串,用半角都好分隔
  949. 'bettype' => 1, //结算类型 1单式 2串式
  950. 'settype' => 2, //结算次数 1首次 2非首冷饮
  951. 'game_code' => $type, //赛事类型 zq lq wq bq
  952. 'match_id' => $match_id, // 赛事ID
  953. 'change_status' => 0 //是否改状态
  954. );
  955. $url = $jsurl . '/Settelement';
  956. $simplex_res = $napp->post_curls($url, $simplex);//返回json
  957. $huawei_res = json_decode($simplex_res, true);
  958. if ($huawei_res['status'] == 1) {
  959. return json_encode(['status' => 1, 'msg' => '结算成功']);
  960. } else {
  961. return json_encode(['status' => 4, 'msg' => '结算失败']);
  962. }
  963. } else {
  964. return json_encode(['status' => 3, 'msg' => '输赢判断错误']);
  965. }
  966. } else {
  967. return json_encode(['status' => 2, 'msg' => '订单不存在']);
  968. }
  969. }
  970. /**
  971. *单式注单批量结算
  972. */
  973. public function batchsettlement()
  974. {
  975. $orders = \App\Models\SportsNoteList::where('settle_status', '1')->get();
  976. $order_ids = array();
  977. for ($i = 0; $i < count($orders); $i++) {
  978. $result = \App\Models\MoneyBuyMatch::where('batch_id', $orders[$i]->batch_id)->where('match_id', $orders[$i]->match_id)->get();
  979. $res = array();
  980. for ($j = 0; $j < count($result); $j++) {
  981. $res[] = $result[$j]->result;
  982. }
  983. if (!in_array(0, $res)) {
  984. $order_ids[] = $orders[$i]->order_id;
  985. }
  986. }
  987. $SettlementOrder = new SettlementOrder();
  988. $bet_type = 1;//单式注单
  989. $data = $SettlementOrder->reSettlement($order_ids, $bet_type);
  990. return $data;
  991. }
  992. /**
  993. *删除订单
  994. */
  995. public function delete(Req $req)
  996. {
  997. $id = $req->input('id');
  998. if (empty($id)) {
  999. return responseToJson(-2001); //id
  1000. }
  1001. $ids = explode(',', $id);
  1002. if (!is_array($ids) && intval($ids) < 0) {
  1003. return responseToJson(-2002); //id
  1004. }
  1005. if (is_array($ids) && count($ids) > 0) {
  1006. foreach ($ids as $k => $v) {
  1007. if (intval($v) < 1) {
  1008. unset($ids[$k]);
  1009. }
  1010. }
  1011. }
  1012. $rows = \App\Models\SportsNoteList::whereIn('id', $ids)->delete();
  1013. if (!$rows) {
  1014. return responseToJson(-2003); //id
  1015. }
  1016. return responseToJson(1, trans('menu.delete_success')); //id
  1017. }
  1018. /**
  1019. * 投注金额统计
  1020. */
  1021. function moneycount()
  1022. {
  1023. $where = Request::has('where') ? Request::get('where') : '';
  1024. $type = Request::has('type') ? Request::get('type') : 'zq';
  1025. $db = new \App\Models\SportsNoteList;
  1026. $data = $db->MoneyCount($where, $type);
  1027. return responseToJson($data);
  1028. }
  1029. //单式订单数据
  1030. public function manualmatchget(Req $req)
  1031. {
  1032. $order_id = isset($req->order_id) ? $req->order_id : 0;
  1033. $model = new \App\Models\SportsNoteList();
  1034. $ret = $model->getorder($order_id);
  1035. if ($ret) {
  1036. // $league = db('st_'.$ret->game_code.'_league')->where('id',$ret->lg_id)->first();
  1037. // $ret->league = $league->name_chinese;
  1038. $modelcode = new \App\Models\StoddsCode();
  1039. $opcode_nameArr = $modelcode->getTypeDatas($ret->game_code);
  1040. $ret = $ret->toArray();
  1041. foreach ($ret['matchdatas'] as $key => $val) {
  1042. $tmp_pcode = $val['p_code'];
  1043. $tmp_code = $val['odds_code'];
  1044. $ret['matchdatas'][$key]['odds_name'] = isset($opcode_nameArr[$tmp_pcode][$tmp_code]['odds_name']) ? $opcode_nameArr[$tmp_pcode][$tmp_code]['odds_name'] : '';
  1045. }
  1046. return responseToJson(1, '成功', $ret);
  1047. } else {
  1048. return responseToJson(-1, 'false', $ret);
  1049. }
  1050. }
  1051. //单式订单直接手动更改输赢结果并结算
  1052. public function manualmatchpdate(Req $req)
  1053. {
  1054. $order_id = isset($req->order_id) ? $req->order_id : 0;
  1055. $datas = isset($req->matchdata) ? $req->matchdata : [];
  1056. $datas = json_decode($datas, true);
  1057. if (empty($order_id) || empty($datas)) {
  1058. return responseToJson(-1, '参数不能为空!');
  1059. }
  1060. $model = new \App\Models\SportsNoteList();
  1061. $modeldata = $model->getorder($order_id);
  1062. if (empty($modeldata)) {
  1063. return responseToJson(-1, 'false');
  1064. }
  1065. $sdataArr = [];
  1066. foreach ($datas as $val) {
  1067. $tmp_id = $val['id'];
  1068. $tmp_result = intval($val['result']);
  1069. $tmp_matchword = trim($val['matchresult']);
  1070. if (!in_array($tmp_result, [-1, 1, 2, 3, 4])) {
  1071. continue;
  1072. }
  1073. $sdataArr[$tmp_id] = ['result' => $tmp_result, 'matchresult' => $tmp_matchword];
  1074. }
  1075. if (empty($sdataArr)) {
  1076. return responseToJson(-2, '没有要更新的数据');
  1077. }
  1078. $chageNum = 0;
  1079. foreach ($modeldata->matchdatas as $key => $val) {
  1080. $id = $val->id;
  1081. if (isset($sdataArr[$id])) {
  1082. if ($val->result != $sdataArr[$id]['result'] || $val->matchwork != $sdataArr[$id]['matchresult']) {
  1083. $val->result = $sdataArr[$id]['result'];
  1084. $val->matchresult = $sdataArr[$id]['matchresult'];
  1085. $val->save();
  1086. $chageNum++;
  1087. }
  1088. }
  1089. }
  1090. if ($chageNum) {
  1091. $modeldata->is_manual = 1;
  1092. $modeldata->save();
  1093. } else {
  1094. return responseToJson(1, '没有更新操作数据!');
  1095. }
  1096. $data = [
  1097. 'token' => session('adminInfo.token'), //外网
  1098. 'order_ids' => $modeldata->order_id,
  1099. 'bettype' => 1,
  1100. 'settype' => 2,
  1101. 'game_code' => $modeldata->game_code,
  1102. 'match_id' => $modeldata->match_id,
  1103. 'change_status' => 0,
  1104. 'is_manual' => 1,
  1105. ];
  1106. $ret = $this->request_post(config('sconstant.url') . '/Settelement', $data);
  1107. $retjson = json_decode($ret, true);
  1108. if (isset($retjson['status']) && $retjson['status'] == 1) {
  1109. $model->where('order_id', $order_id)->update(['settle_status' => 2]);
  1110. }
  1111. return responseToJson(1, '更新成功');
  1112. }
  1113. //冠军注单直接手动设置比赛结果 --> 提交胜负判断处理以及 --> 提交结算
  1114. public function matchpdate_v2(Req $req)
  1115. {
  1116. $order_id = isset($req->order_id) ? $req->order_id : 0;
  1117. $game_code = isset($req->game_code) ? $req->game_code : 0;
  1118. $match_id = isset($req->match_id) ? $req->match_id : 0;
  1119. $pdatas = isset($req->matchdata) ? $req->matchdata : [];
  1120. $pdatas = json_decode($pdatas, true);
  1121. if (empty($order_id) || empty($game_code) || empty($match_id) || empty($pdatas)) {
  1122. return responseToJson(0, '参数错误');
  1123. }
  1124. $buyModel = (new MoneyBuySimplexModel())->where([['order_id', '=', $order_id]])->first();
  1125. if (empty($buyModel)) {
  1126. return responseToJson(0, '订单数据错误');
  1127. }
  1128. $game_name = $pdatas['odds_code'];
  1129. $result = $pdatas['result'];
  1130. $res = [];
  1131. $res['lg_id'] = $match_id;
  1132. $res['game_name'] = $game_name;
  1133. $res['result'] = $result;
  1134. $buyModel->single_result = json_encode([$res], 256);
  1135. //$buyModel->single_result = '{"lg_id":'.$match_id.',"game_name":'.$game_name.',"game_name":'.$result.',"game_name":'.time().'}';
  1136. $buyModel->result_flag = 1;
  1137. $buyModel->is_manual = 1;
  1138. $ret = $buyModel->save();
  1139. if ($ret) {
  1140. $ret2 = $this->do_win_set($order_id, $game_code, $match_id);
  1141. if ($ret2['status'] == 1) {
  1142. return responseToJson(1, '操作成功!');
  1143. } else {
  1144. return responseToJson(0, '操作失败2!--' . $ret2['data']);
  1145. }
  1146. }
  1147. return responseToJson(0, '未做更新', ['order_id' => $order_id, 'game_code' => $game_code, 'match_id' => $game_code, 'datas' => $pdatas]);
  1148. }
  1149. //单式订单直接手动设置比赛结果 --> 提交胜负判断处理以及 --> 提交结算
  1150. public function manualmatchpdate_v2(Req $req)
  1151. {
  1152. $order_id = isset($req->order_id) ? $req->order_id : 0;
  1153. $game_code = isset($req->game_code) ? $req->game_code : 0;
  1154. $match_id = isset($req->match_id) ? $req->match_id : 0;
  1155. $pdatas = isset($req->matchdata) ? $req->matchdata : [];
  1156. $pdatas = json_decode($pdatas, true);
  1157. if (empty($order_id) || empty($game_code) || empty($match_id) || empty($pdatas)) {
  1158. return responseToJson(0, '参数错误');
  1159. }
  1160. if(in_array(-1,$pdatas)){
  1161. return responseToJson(-1, '输入比分错误');
  1162. }
  1163. $buyModel = (new MoneyBuySimplexModel())->where([['order_id', '=', $order_id]])->first();
  1164. if (empty($buyModel)) {
  1165. return responseToJson(0, '订单数据错误');
  1166. }
  1167. $restModel = '';
  1168. switch ($game_code) {
  1169. case 'zq':
  1170. $restModel = DB::table('st_zq_result')->where([['match_id', '=', $match_id]])->first();
  1171. break;
  1172. case 'lq':
  1173. $restModel = DB::table('st_lq_result')->where([['match_id', '=', $match_id]])->first();
  1174. break;
  1175. case 'wq':
  1176. $restModel = DB::table('st_wq_result')->where([['match_id', '=', $match_id]])->first();
  1177. break;
  1178. case 'bq':
  1179. $restModel = DB::table('st_bq_result')->where([['match_id', '=', $match_id]])->first();
  1180. break;
  1181. }
  1182. if (empty($restModel)) {
  1183. return responseToJson(0, '赛事结果记录没有找到,数据错误');
  1184. }
  1185. if ($game_code == 'zq') {
  1186. $home = intval($pdatas['home']);
  1187. $guest = intval($pdatas['guest']);
  1188. $home_u = intval($pdatas['home_u']);
  1189. $guest_u = intval($pdatas['guest_u']);
  1190. $restModel->home_score = $home;
  1191. $restModel->guest_score = $guest;
  1192. $restModel->u_home_score = $home_u;
  1193. $restModel->u_guest_score = $guest_u;
  1194. $restModel->corner_ball = json_decode($restModel->corner_ball, 256);
  1195. $restModel->penalty_card = json_decode($restModel->penalty_card, 256);
  1196. $restModel->first_score = json_decode($restModel->first_score, 256);
  1197. $restModel->warn_more = json_decode($restModel->warn_more, 256);
  1198. $buyModel->single_result = json_encode([$restModel], 256);
  1199. $buyModel->result_flag = 1;
  1200. $buyModel->is_manual = 1;
  1201. $ret = $buyModel->save();
  1202. if ($ret) {
  1203. $ret2 = $this->do_win_set($order_id, $game_code, $match_id);
  1204. if ($ret2['status'] == 1) {
  1205. return responseToJson(1, '操作成功!');
  1206. } else {
  1207. return responseToJson(0, '操作失败2!--' . $ret2['data']);
  1208. }
  1209. }
  1210. return responseToJson(0, '更新失败1');
  1211. }
  1212. if ($game_code == 'lq') {
  1213. $home = $pdatas['home'];
  1214. $guest = $pdatas['guest'];
  1215. $restModel->home_score = ['1' => intval($home['0']), '2' => intval($home['1']), '3' => intval($home['2']), '4' => intval($home['3'])];
  1216. $restModel->guest_score = ['1' => intval($guest['0']), '2' => intval($guest['1']), '3' => intval($guest['2']), '4' => intval($guest['3'])];
  1217. $restModel->u_home_score = intval($home['0']) + intval($home['1']);
  1218. $restModel->u_guest_score = intval($guest['0']) + intval($guest['1']);
  1219. $all_home = intval($home['0']) + intval($home['1']) + intval($home['2']) + intval($home['3']);
  1220. $all_guest = intval($guest['0']) + intval($guest['1']) + intval($guest['2']) + intval($guest['3']);
  1221. $restModel->all_goal = $all_home + $all_guest;
  1222. $restModel->match_score = $all_home . ':' . $all_guest;
  1223. $restModel->match_winer = $all_home > $all_guest ? $restModel->home_team : $restModel->guest_team;
  1224. $restModel->warn_more = json_decode($restModel->warn_more, 256);
  1225. $buyModel->single_result = json_encode([$restModel], 256);
  1226. $buyModel->result_flag = 1;
  1227. $buyModel->is_manual = 1;
  1228. $ret = $buyModel->save();
  1229. if ($ret) {
  1230. $ret2 = $this->do_win_set($order_id, $game_code, $match_id);
  1231. if ($ret2['status'] == 1) {
  1232. return responseToJson(1, '操作成功!');
  1233. } else {
  1234. return responseToJson(0, '操作失败2!--' . $ret2['data']);
  1235. }
  1236. }
  1237. return responseToJson(0, '更新失败1');
  1238. }
  1239. if ($game_code == 'bq') {
  1240. $home = $pdatas['home'];
  1241. $guest = $pdatas['guest'];
  1242. $home_other = $pdatas['home_other'];
  1243. $guest_other = $pdatas['guest_other'];
  1244. $arrs = [];
  1245. for ($i = 0; $i <= 8; $i++) {
  1246. $j = $i + 1;
  1247. $arrs[$j] = [
  1248. 'home' => intval($home[$i]),
  1249. 'guest' => intval($guest[$i]),
  1250. ];
  1251. }
  1252. $arrs['other'] = [
  1253. 'home' => intval($home_other),
  1254. 'guest' => intval($guest_other),
  1255. ];
  1256. $restModel->match_score_t = $arrs;
  1257. $restModel->warn_more = json_decode($restModel->warn_more, 256);
  1258. $buyModel->single_result = json_encode([$restModel], 256);
  1259. $buyModel->result_flag = 1;
  1260. $buyModel->is_manual = 1;
  1261. $ret = $buyModel->save();
  1262. if ($ret) {
  1263. $ret2 = $this->do_win_set($order_id, $game_code, $match_id);
  1264. if ($ret2['status'] == 1) {
  1265. return responseToJson(1, '操作成功!');
  1266. } else {
  1267. return responseToJson(0, '操作失败2!--' . $ret2['data']);
  1268. }
  1269. }
  1270. return responseToJson(0, '更新失败1');
  1271. }
  1272. if ($game_code == 'wq') {
  1273. $home = $pdatas['home'];
  1274. $guest = $pdatas['guest'];
  1275. $arrs = [];
  1276. for ($i = 0; $i <= 4; $i++) {
  1277. $j = $i + 1;
  1278. $arrs[$j] = [
  1279. 'home' => intval($home[$i]),
  1280. 'guest' => intval($guest[$i]),
  1281. ];
  1282. }
  1283. $restModel->inning = $arrs;
  1284. $restModel->warn_more = json_decode($restModel->warn_more, 256);
  1285. $buyModel->single_result = json_encode([$restModel], 256);
  1286. $buyModel->result_flag = 1;
  1287. $buyModel->is_manual = 1;
  1288. $ret = $buyModel->save();
  1289. if ($ret) {
  1290. $ret2 = $this->do_win_set($order_id, $game_code, $match_id);
  1291. if ($ret2['status'] == 1) {
  1292. return responseToJson(1, '操作成功!');
  1293. } else {
  1294. return responseToJson(0, '操作失败2!--' . $ret2['data']);
  1295. }
  1296. }
  1297. return responseToJson(0, '更新失败1');
  1298. }
  1299. return responseToJson(0, '未做更新', ['order_id' => $order_id, 'game_code' => $game_code, 'match_id' => $game_code, 'datas' => $pdatas]);
  1300. }
  1301. //修复比分时用到订单信息及比赛结果数据
  1302. public function manualmatchget_v2(Req $req)
  1303. {
  1304. $order_id = isset($req->order_id) ? $req->order_id : 0;
  1305. $model = new MoneyBuySimplexModel();
  1306. $ret = $model->OrderinfoResult($order_id);
  1307. if ($ret && !empty($ret['result'])) {
  1308. return responseToJson(1, '成功', $ret);
  1309. } else {
  1310. return responseToJson(-1, 'false', $ret);
  1311. }
  1312. }
  1313. //先提交输赢,再结算
  1314. private function do_win_set($order_id, $game_code, $match_id)
  1315. {
  1316. $winret = $this->do_winfail($order_id, $game_code, $match_id);
  1317. if ($winret['status'] == 1) {
  1318. $setret = $this->do_settelement($order_id, $game_code, $match_id);
  1319. if ($setret['status'] == 1) {
  1320. return ['status' => 1, 'msg' => 'success', 'data' => []];
  1321. } else {
  1322. return ['status' => 0, 'msg' => 'failse', 'data' => $setret['msg']];
  1323. }
  1324. } else {
  1325. return ['status' => 0, 'msg' => 'failse', 'data' => $winret['msg']];
  1326. }
  1327. }
  1328. //单订单手动提交输赢计算
  1329. private function do_winfail($order_id, $game_code, $match_id)
  1330. {
  1331. $data = [
  1332. 'token' => session('adminInfo.token'), //外网
  1333. 'order_id' => $order_id,
  1334. ];
  1335. $ret = $this->request_post(config('sconstant.url') . '/DoWinFailOneOrder', $data);
  1336. return json_decode($ret, true);
  1337. }
  1338. //单订单手动提交结算
  1339. private function do_settelement($order_id, $game_code, $match_id)
  1340. {
  1341. $data = [
  1342. 'token' => session('adminInfo.token'), //外网
  1343. 'order_ids' => $order_id,
  1344. 'bettype' => 1,
  1345. 'settype' => 2,
  1346. 'game_code' => $game_code,
  1347. 'match_id' => $match_id,
  1348. 'change_status' => 0,
  1349. 'is_manual' => 1,
  1350. ];
  1351. $ret = $this->request_post(config('sconstant.url') . '/Settelement', $data);
  1352. return json_decode($ret, true);
  1353. }
  1354. private function request_post($url = '', $param = '')
  1355. {
  1356. if (empty($url) || empty($param)) {
  1357. return false;
  1358. }
  1359. $postUrl = $url;
  1360. $curlPost = $param;
  1361. $ch = curl_init();//初始化curl
  1362. curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
  1363. curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
  1364. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
  1365. curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
  1366. curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
  1367. $data = curl_exec($ch);//运行curl
  1368. curl_close($ch);
  1369. return $data;
  1370. }
  1371. public function getpcode(){
  1372. $game_type = $_GET["game_type"];
  1373. $p_code = \App\Models\StoddsCode::where('p_id',0)->where('game_code',$game_type)->get();
  1374. return json_encode($p_code);
  1375. }
  1376. }