SportsNoteList.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jonlin
  5. * Date: 2019/4/9
  6. * Time: 9:18
  7. */
  8. namespace App\Models;
  9. use Illuminate\Support\Facades\DB;
  10. use App\Models\MoneyBuyMatch;
  11. class SportsNoteList extends BaseModel
  12. {
  13. protected $table = "money_buy_simplex";
  14. public $timestamps = false;
  15. public function matchdatas()
  16. {
  17. return $this->hasMany(MoneyBuyMatch::class, 'order_id', 'order_id');
  18. }
  19. function getinfo($list = 10, $page, $where = '', $type)
  20. {
  21. $data = $this
  22. ->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')
  23. ->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')
  24. // ->join('st_'.$type.'_league','st_'.$type.'_competition.lg_id','=','st_'.$type.'_league.id')
  25. ->join('st_' . $type . '_league', 'money_buy_simplex.lg_id', '=', 'st_' . $type . '_league.id')
  26. ->select('money_buy_simplex.id', 'money_buy_simplex.account_name', 'money_buy_simplex.is_champion', 'money_buy_simplex.account_identity', 'money_buy_simplex.order_id', 'money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.status', 'money_buy_simplex.money_time', 'money_buy_simplex.settle_status', 'money_buy_simplex.gain_money', 'money_buy_simplex.game_code', 'money_buy_simplex.match_id', 'money_buy_simplex.game_status', 'st_' . $type . '_competition.home_team', 'st_' . $type . '_competition.guest_team', 'st_' . $type . '_competition.match_date', 'st_' . $type . '_competition.match_time', 'st_' . $type . '_competition.lg_id', 'st_' . $type . '_competition.status as match_status', 'money_details.money_cash', 'money_buy_simplex.batch_id', 'st_' . $type . '_league.name_chinese', 'st_' . $type . '_league.last_time')
  27. ->where($where)
  28. ->orderby('money_buy_simplex.money_time', 'desc')
  29. ->paginate($list);
  30. if (!$data < 0) {
  31. return -2021052003; //
  32. }
  33. //反水
  34. $water_return_money = \App\Models\Money_details::where('trade_type', '7')->get();
  35. //注单作废
  36. $invalid_money = \App\Models\Money_details::where('trade_type', '3')->get();
  37. //订单投注的玩法
  38. $content = \App\Models\MoneyBuyMatch::where('bet_type', '1')->get();
  39. for ($d = 0; $d < count($content); $d++) {
  40. if ($content[$d]->result == 0) {
  41. $content[$d]->result = '未处理';
  42. }
  43. if ($content[$d]->result == 1) {
  44. $content[$d]->result = '赢';
  45. }
  46. if ($content[$d]->result == -1) {
  47. $content[$d]->result = '输';
  48. }
  49. if ($content[$d]->result == 2) {
  50. $content[$d]->result = '平';
  51. }
  52. if ($content[$d]->result == 3) {
  53. $content[$d]->result = '赢半平半';
  54. }
  55. if ($content[$d]->result == 4) {
  56. $content[$d]->result = '输半平半';
  57. }
  58. }
  59. //玩法
  60. $result = \App\Models\Matchcode::where('game_code', $type)->get();
  61. //$result = \App\Model\Matchcode::get();
  62. for ($i = 0; $i < count($data); $i++) {
  63. // if($data[$i]->status==1 && $data[$i]->game_status==0){
  64. // $data[$i]->order_status = '投注'.'<br>;<a class="layui-btn layui-btn-sm invalid" lay-event="detail" pid="id" uri="/admin/SoccerNoteList/invalid/?id=" href="javascript:invalid(\'/admin/SoccerNoteList/invalid/?id='.$data[$i]->id.'\');"> 作废 </a>';
  65. // }else
  66. if ($data[$i]->status == 1 && $data[$i]->game_status == 0) {
  67. $data[$i]->order_status = '投注';
  68. } else if ($data[$i]->status == 2) {
  69. $data[$i]->order_status = '作废';//.'<br><a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 已作废 </a>';
  70. } else if ($data[$i]->status == 3) {
  71. $data[$i]->order_status = '撤单';//.'<br><a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 已撤单 </a>';
  72. }
  73. if ($data[$i]->settle_status == 1) {
  74. $data[$i]->settle_status = '未结算';
  75. } else if ($data[$i]->settle_status == 2) {
  76. $data[$i]->settle_status = '已结算';
  77. }
  78. if ($data[$i]->game_status == 0) {
  79. $data[$i]->game_status = '未处理';
  80. } else {
  81. $data[$i]->game_status = '已处理';
  82. }
  83. if ($data[$i]->game_code == 'zq') {
  84. $data[$i]->match_id_order = '<a href="/admin/sportsfoot/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  85. }
  86. if ($data[$i]->game_code == 'lq') {
  87. $data[$i]->match_id_order = '<a href="/admin/Sportsbk/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  88. }
  89. if ($data[$i]->game_code == 'wq') {
  90. $data[$i]->match_id_order = '<a href="/admin/Sportswq/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  91. }
  92. if ($data[$i]->game_code == 'bq') {
  93. $data[$i]->match_id_order = '<a href="/admin/Sportsbq/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  94. }
  95. $data[$i]->league = $data[$i]->name_chinese;
  96. if ($data[$i]->is_champion == 0) {
  97. $data[$i]->home_guest = $data[$i]->home_team . ' VS ' . $data[$i]->guest_team;
  98. $data[$i]->time = '开赛:' . $data[$i]->match_date . ' ' . $data[$i]->match_time;
  99. } else {
  100. $data[$i]->home_guest = '冠军联赛投注';
  101. $data[$i]->time = '结束:' . $data[$i]->last_time;
  102. }
  103. $data[$i]->money_match_time = '下注:' . $data[$i]->money_time . $data[$i]->time;
  104. //反水
  105. $data[$i]->water_return = -1;
  106. for ($a = 0; $a < count($water_return_money); $a++) {
  107. if ($data[$i]->order_id == $water_return_money[$a]->trade_id) {
  108. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  109. $data[$i]->water_return = 0;
  110. } else {
  111. $data[$i]->water_return = $water_return_money[$a]->money;
  112. }
  113. //用户投注后账户金额
  114. $data[$i]->frozen_cash = $water_return_money[$a]->money_cash;
  115. }
  116. }
  117. if ($data[$i]->water_return == -1) {
  118. $data[$i]->water_return = 0;
  119. //用户投注后账户金额
  120. $data[$i]->frozen_cash = $data[$i]->money_cash;
  121. }
  122. //此时结果金额
  123. $data[$i]->result = $data[$i]->water_return + $data[$i]->gain_money;
  124. //用户投注前账户金额
  125. $data[$i]->available_cash = $data[$i]->money_cash + $data[$i]->money;
  126. //投注前后账户金额
  127. $data[$i]->account_money = $data[$i]->available_cash . '<br><span>' . $data[$i]->money . '</span><br>' . $data[$i]->frozen_cash;
  128. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  129. for ($b = 0; $b < count($invalid_money); $b++) {
  130. if ($data[$i]->order_id == $invalid_money[$b]->trade_id) {
  131. $data[$i]->available_cash = $invalid_money[$b]->money_cash;
  132. $data[$i]->account_money = $data[$i]->available_cash;
  133. }
  134. }
  135. }
  136. $data[$i]->str = 0;
  137. for ($b = 0; $b < count($content); $b++) {
  138. $data[$i]->str1 = 0;
  139. $data[$i]->team = '';
  140. if (!empty($content[$b]->odds_code)) {
  141. if (!empty(stristr($content[$b]->odds_code, 'home'))) {
  142. $data[$i]->team = $data[$i]->home_team;
  143. }
  144. if (!empty(stristr($content[$b]->odds_code, 'guest'))) {
  145. $data[$i]->team = $data[$i]->guest_team;
  146. }
  147. if ($content[$b]->p_code == 'half_full') {
  148. $string = str_replace('home', $data[$i]->home_team, $content[$b]->odds_code);
  149. $string = str_replace('guest', $data[$i]->guest_team, $string);
  150. $string = str_replace('dogfall', '和局', $string);
  151. $string = explode('_', $string);
  152. $data[$i]->team = $string['2'] . '/' . $string['3'];
  153. }
  154. }
  155. //处理普通赛事玩法详情
  156. if ($data[$i]->match_id == $content[$b]->match_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 0) {
  157. if ($content[$b]->p_code == 'first_last_ball' || $content[$b]->p_code == 'half_full' || $content[$b]->p_code == 'capot' || $content[$b]->p_code == 'two_sides' || $content[$b]->p_code == 'total_goal') {
  158. $content[$b]->condition = '';
  159. }
  160. $data[$i]->game_status = $data[$i]->game_status;
  161. //投注详情
  162. if (!empty($data[$i]->match_time)) {
  163. $data[$i]->content1 = '[' . $data[$i]->match_time . ']';
  164. //$data[$i]->match_time = $data[$i]->match_time;
  165. } else {
  166. if (!empty($data[$i]->last_time)) {
  167. $datetime = explode(' ', $data[$i]->last_time);
  168. //$data[$i]->match_time = $datetime[1];
  169. $data[$i]->content1 = '[' . $datetime[1] . ']';
  170. }
  171. }
  172. for ($c = 0; $c < count($result); $c++) {
  173. if ($content[$b]->odds_code == $result[$c]->odds_code) {
  174. $data[$i]->str1 = 1;
  175. if ($content[$b]->result == '未处理') {
  176. $data[$i]->content = $data[$i]->content . $result[$c]->odds_name . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br>';
  177. } else {
  178. $data[$i]->content = $data[$i]->content . $result[$c]->odds_name . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br><span>' . $content[$b]->result . '</span>(' . $content[$b]->matchresult . ')<br>';
  179. }
  180. }
  181. }
  182. if ($data[$i]->str1 == 0) {
  183. if ($content[$b]->result == '未处理') {
  184. $data[$i]->content = $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br>';
  185. } else {
  186. $data[$i]->content = $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br><span>' . $content[$b]->result . '</span>(' . $content[$b]->matchresult . ')<br>';
  187. }
  188. }
  189. }
  190. //处理冠军联赛玩法详情
  191. if ($data[$i]->match_id == $content[$b]->lg_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 1) {
  192. $content[$b]->condition = '';
  193. if ($content[$b]->p_code == 'first_last_ball' || $content[$b]->p_code == 'half_full' || $content[$b]->p_code == 'capot' || $content[$b]->p_code == 'two_sides' || $content[$b]->p_code == 'total_goal') {
  194. $content[$b]->condition = '';
  195. }
  196. $data[$i]->game_status = $data[$i]->game_status;
  197. /*
  198. //投注详情
  199. if(!empty($data[$i]->match_time)){
  200. $data[$i]->content1 = '['.$data[$i]->match_time.']';
  201. //$data[$i]->match_time = $data[$i]->match_time;
  202. }
  203. else{
  204. if(!empty($data[$i]->last_time)){
  205. $datetime = explode(' ',$data[$i]->last_time);
  206. //$data[$i]->match_time = $datetime[1];
  207. $data[$i]->content1 = '['.$datetime[1].']';
  208. }
  209. }
  210. */
  211. /*
  212. for($c=0;$c<count($result);$c++){
  213. if($content[$b]->odds_code == $result[$c]->odds_code){
  214. $data[$i]->str1 = 1;
  215. if($content[$b]->result=='未处理'){
  216. $data[$i]->content = $content[$b]->home_team.'<br>'.$data[$i]->content.$result[$c]->odds_name.'<br>'.$content[$b]->condition.' '.$data[$i]->team.'@'.$content[$b]->odds.' ¥'.$content[$b]->bet_money.'<br>';
  217. }else{
  218. $data[$i]->content = $content[$b]->home_team.'<br>'.$data[$i]->content.$result[$c]->odds_name.'<br>'.$content[$b]->condition.' '.$data[$i]->team.'@'.$content[$b]->odds.' ¥'.$content[$b]->bet_money.'<br><span>'.$content[$b]->result.'</span>('.$content[$b]->matchresult.')<br>';
  219. }
  220. }
  221. }
  222. */
  223. if ($data[$i]->str1 == 0) {
  224. if ($content[$b]->result == '未处理') {
  225. $data[$i]->content = $content[$b]->home_team . '<br>' . $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br>';
  226. } else {
  227. $data[$i]->content = $content[$b]->home_team . '<br>' . $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br><span>' . $content[$b]->result . '</span>(' . $content[$b]->matchresult . ')<br>';
  228. }
  229. }
  230. }
  231. }
  232. // if($data[$i]->status == 1){
  233. // if($data[$i]->match_status == 0 || $data[$i]->match_status == 1){
  234. // $data[$i]->game_status = $data[$i]->settle_status.'<br><a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 结算 </a>';
  235. // }
  236. // if($data[$i]->match_status == 2 || $data[$i]->match_status == 3 || $data[$i]->match_status == 5){
  237. // if($data[$i]->settle_status == '已结算'){
  238. // $data[$i]->game_status = $data[$i]->settle_status.'<br><a class="layui-btn layui-btn-sm resettlement" lay-event="detail" pid="id" uri="/admin/SoccerNoteList/resettlement/?id=" href="javascript:resettlement(\'/admin/SoccerNoteList/resettlement/?id='.$data[$i]->id.'\');"> 重新结算 </a>';
  239. // }else{
  240. // $data[$i]->game_status = $data[$i]->settle_status.'<br><a class="layui-btn layui-btn-sm settlement" lay-event="detail" pid="id" uri="/admin/SoccerNoteList/settlement/?id=" href="javascript:settlement(\'/admin/SoccerNoteList/settlement/?id='.$data[$i]->id.'\');"> 结算 </a>';
  241. // }
  242. // }
  243. // }else{
  244. // $data[$i]->game_status = $data[$i]->settle_status.'<br><a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 结2算 </a>';
  245. // }
  246. $data[$i]->content = $data[$i]->content1 . $data[$i]->content;
  247. }
  248. return $data->toArray();
  249. }
  250. //投注金额汇总统计
  251. function MoneyCount($where = '', $type)
  252. {
  253. $data = array();
  254. // $data['all_money'] = $this->sum('money');
  255. // $data['all_prize_money'] = $this->sum('prize_money');
  256. // $data['alraedy_prize_money'] = $this->where('settle_status','2')->sum('gain_money');
  257. $data['all_money'] = 0;
  258. $data['all_prize_money'] = 0;
  259. $data['alraedy_prize_money'] = 0;
  260. $all_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where('money_buy_simplex.status', '1')->get();
  261. for ($a = 0; $a < count($all_money); $a++) {
  262. $data['all_money'] = $data['all_money'] + $all_money[$a]->money;
  263. }
  264. $all_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where('money_buy_simplex.status', '1')->get();
  265. for ($a = 0; $a < count($all_prize_money); $a++) {
  266. $data['all_prize_money'] = $data['all_money'] + $all_prize_money[$a]->prize_money;
  267. }
  268. $alraedy_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where('money_buy_simplex.settle_status', '2')->where('money_buy_simplex.status', '1')->get();
  269. for ($a = 0; $a < count($alraedy_prize_money); $a++) {
  270. $data['alraedy_prize_money'] = $data['all_money'] + $alraedy_prize_money[$a]->gain_money;
  271. }
  272. if (!empty($where) && is_array($where)) {
  273. $data['all_money'] = 0;
  274. $data['all_prize_money'] = 0;
  275. $data['alraedy_prize_money'] = 0;
  276. //$data['all_money'] = $this->where($where)->sum('money');
  277. // $data['all_prize_money'] = $this->where($where)->sum('prize_money');
  278. // $data['alraedy_prize_money'] = $this->where($where)->where('settle_status','2')->sum('gain_money');
  279. $all_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_zq_competition', 'st_zq_competition.id', '=', 'money_buy_simplex.match_id')->join('st_zq_league', 'st_zq_competition.lg_id', '=', 'st_zq_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where($where)->where('money_buy_simplex.status', '1')->get();
  280. for ($a = 0; $a < count($all_money); $a++) {
  281. $data['all_money'] = $data['all_money'] + $all_money[$a]->money;
  282. }
  283. $all_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where($where)->where('money_buy_simplex.status', '1')->get();
  284. for ($a = 0; $a < count($all_prize_money); $a++) {
  285. $data['all_prize_money'] = $data['all_prize_money'] + $all_prize_money[$a]->prize_money;
  286. }
  287. $alraedy_prize_money = $this->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')->join('st_' . $type . '_league', 'st_' . $type . '_competition.lg_id', '=', 'st_' . $type . '_league.id')->select('money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.gain_money')->where('money_buy_simplex.settle_status', '2')->where($where)->where('money_buy_simplex.status', '1')->get();
  288. for ($a = 0; $a < count($alraedy_prize_money); $a++) {
  289. $data['alraedy_prize_money'] = $data['alraedy_prize_money'] + $alraedy_prize_money[$a]->gain_money;
  290. }
  291. }
  292. return $data;
  293. }
  294. //修改赛事下的所有单式下注 3199308
  295. function updatesimplex($ssid, $code)
  296. {
  297. $newapp = new \App\Models\MoneyBuyMatch();
  298. $data = $newapp->allsimplexorder($ssid, $code);
  299. if ($data) {
  300. for ($i = 0; $i < count($data); $i++) {
  301. $the = array(
  302. 'status' => 2,
  303. 'game_status' => 3,
  304. 'game_code' => $code,
  305. );
  306. $res = $this->where('order_id', $data[$i]['order_id'])->update($the);
  307. }
  308. if ($res < 0) {
  309. return -7012000302; //操作失败
  310. }
  311. return $res;
  312. } else {
  313. return -111;
  314. }
  315. }
  316. function info($list = 10, $page, $where = '', $type)
  317. {
  318. $data = $this
  319. ->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')
  320. ->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')
  321. // ->join('st_'.$type.'_league','st_'.$type.'_competition.lg_id','=','st_'.$type.'_league.id')
  322. ->join('st_' . $type . '_league', 'money_buy_simplex.lg_id', '=', 'st_' . $type . '_league.id')
  323. ->select('money_buy_simplex.id', 'money_buy_simplex.account_name', 'money_buy_simplex.is_champion', 'money_buy_simplex.account_identity', 'money_buy_simplex.order_id', 'money_buy_simplex.money', 'money_buy_simplex.prize_money', 'money_buy_simplex.status', 'money_buy_simplex.money_time', 'money_buy_simplex.settle_status', 'money_buy_simplex.gain_money', 'money_buy_simplex.game_code', 'money_buy_simplex.match_id', 'money_buy_simplex.game_status', 'st_' . $type . '_competition.home_team', 'st_' . $type . '_competition.guest_team', 'st_' . $type . '_competition.match_date', 'st_' . $type . '_competition.match_time', 'st_' . $type . '_competition.lg_id', 'st_' . $type . '_competition.status as match_status', 'money_details.money_cash', 'money_buy_simplex.batch_id', 'st_' . $type . '_league.name_chinese', 'st_' . $type . '_league.last_time')
  324. ->where($where)
  325. ->orderby('money_buy_simplex.money_time', 'desc')
  326. ->paginate($list);
  327. if (!$data < 0) {
  328. return -2021052003; //
  329. }
  330. //反水
  331. $water_return_money = \App\Models\Money_details::where('trade_type', '7')->get();
  332. //注单作废
  333. $invalid_money = \App\Models\Money_details::where('trade_type', '3')->get();
  334. //订单投注的玩法
  335. $content = \App\Models\MoneyBuyMatch::where('bet_type', '1')->get();
  336. for ($d = 0; $d < count($content); $d++) {
  337. if ($content[$d]->result == 0) {
  338. $content[$d]->result = '未处理';
  339. }
  340. if ($content[$d]->result == 1) {
  341. $content[$d]->result = '赢';
  342. }
  343. if ($content[$d]->result == -1) {
  344. $content[$d]->result = '输';
  345. }
  346. if ($content[$d]->result == 2) {
  347. $content[$d]->result = '平';
  348. }
  349. if ($content[$d]->result == 3) {
  350. $content[$d]->result = '赢半平半';
  351. }
  352. if ($content[$d]->result == 4) {
  353. $content[$d]->result = '输半平半';
  354. }
  355. }
  356. //玩法
  357. $result = \App\Models\Matchcode::where('game_code', $type)->get();
  358. //$result = \App\Model\Matchcode::get();
  359. for ($i = 0; $i < count($data); $i++) {
  360. if ($data[$i]->status == 1 && $data[$i]->game_status == 0) {
  361. $data[$i]->order_status = '投注' . '<br><a class="layui-btn layui-btn-sm invalid" lay-event="detail" pid="id" uri="/admin/SoccerNoteList/invalid/?id=" href="javascript:invalid(\'/admin/SoccerNoteList/invalid/?id=' . $data[$i]->id . '\');"> 作废 </a>';
  362. } else if ($data[$i]->status == 1 && $data[$i]->game_status != 0) {
  363. $data[$i]->order_status = '投注';
  364. } else if ($data[$i]->status == 2) {
  365. $data[$i]->order_status = '作废';
  366. } else if ($data[$i]->status == 3) {
  367. $data[$i]->order_status = '撤单';
  368. }
  369. // if($data[$i]->settle_status==1){
  370. // $data[$i]->settle_status = '未结算';
  371. // }else if($data[$i]->settle_status==2){
  372. // $data[$i]->settle_status = '已结算';
  373. // }
  374. if ($data[$i]->game_status == 0) {
  375. $data[$i]->game_status = '未处理';
  376. } else {
  377. $data[$i]->game_status = '已处理';
  378. }
  379. if ($data[$i]->game_code == 'zq') {
  380. $data[$i]->match_id_order = '<a href="/admin/sportsfoot/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  381. }
  382. if ($data[$i]->game_code == 'lq') {
  383. $data[$i]->match_id_order = '<a href="/admin/Sportsbk/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  384. }
  385. if ($data[$i]->game_code == 'wq') {
  386. $data[$i]->match_id_order = '<a href="/admin/Sportswq/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  387. }
  388. if ($data[$i]->game_code == 'bq') {
  389. $data[$i]->match_id_order = '<a href="/admin/Sportsbq/outcome?home_team=' . $data[$i]->match_id . '">' . $data[$i]->match_id . '</a> (<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  390. }
  391. $data[$i]->league = $data[$i]->name_chinese;
  392. if ($data[$i]->is_champion == 0) {
  393. $data[$i]->home_guest = $data[$i]->home_team . ' VS ' . $data[$i]->guest_team;
  394. $data[$i]->time = '开赛:' . $data[$i]->match_date . ' ' . $data[$i]->match_time;
  395. } else {
  396. $data[$i]->home_guest = '冠军联赛投注';
  397. $data[$i]->time = '结束:' . $data[$i]->last_time;
  398. }
  399. $data[$i]->money_match_time = '下注:' . $data[$i]->money_time . $data[$i]->time;
  400. /*
  401. $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
  402. $data[$i]->time = '开赛:'.$data[$i]->match_date.' '.$data[$i]->match_time;
  403. $data[$i]->money_match_time = '下注:'.$data[$i]->money_time.'<br>'.$data[$i]->time;
  404. */
  405. //反水
  406. $data[$i]->water_return = -1;
  407. for ($a = 0; $a < count($water_return_money); $a++) {
  408. if ($data[$i]->order_id == $water_return_money[$a]->trade_id) {
  409. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  410. $data[$i]->water_return = 0;
  411. } else {
  412. $data[$i]->water_return = $water_return_money[$a]->money;
  413. }
  414. //用户投注后账户金额
  415. $data[$i]->frozen_cash = $water_return_money[$a]->money_cash;
  416. }
  417. }
  418. if ($data[$i]->water_return == -1) {
  419. $data[$i]->water_return = 0;
  420. //用户投注后账户金额
  421. $data[$i]->frozen_cash = $data[$i]->money_cash;
  422. }
  423. //此时结果金额
  424. $data[$i]->result = $data[$i]->water_return + $data[$i]->gain_money;
  425. //用户投注前账户金额
  426. $data[$i]->available_cash = $data[$i]->money_cash + $data[$i]->money;
  427. //投注前后账户金额
  428. $data[$i]->account_money = $data[$i]->available_cash . '<br><span>' . $data[$i]->money . '</span><br>' . $data[$i]->frozen_cash;
  429. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  430. for ($b = 0; $b < count($invalid_money); $b++) {
  431. if ($data[$i]->order_id == $invalid_money[$b]->trade_id) {
  432. $data[$i]->available_cash = $invalid_money[$b]->money_cash;
  433. $data[$i]->account_money = $data[$i]->available_cash;
  434. }
  435. }
  436. }
  437. $data[$i]->str = 0;
  438. for ($b = 0; $b < count($content); $b++) {
  439. $data[$i]->str1 = 0;
  440. $data[$i]->team = '';
  441. if (!empty($content[$b]->odds_code)) {
  442. if (!empty(stristr($content[$b]->odds_code, 'home'))) {
  443. $data[$i]->team = $data[$i]->home_team;
  444. }
  445. if (!empty(stristr($content[$b]->odds_code, 'guest'))) {
  446. $data[$i]->team = $data[$i]->guest_team;
  447. }
  448. if ($content[$b]->p_code == 'half_full') {
  449. $string = str_replace('home', $data[$i]->home_team, $content[$b]->odds_code);
  450. $string = str_replace('guest', $data[$i]->guest_team, $string);
  451. $string = str_replace('dogfall', '和局', $string);
  452. $string = explode('_', $string);
  453. $data[$i]->team = $string['2'] . '/' . $string['3'];
  454. }
  455. }
  456. //处理普通赛事
  457. if ($data[$i]->match_id == $content[$b]->match_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 0) {
  458. if ($content[$b]->p_code == 'first_last_ball' || $content[$b]->p_code == 'half_full' || $content[$b]->p_code == 'capot' || $content[$b]->p_code == 'two_sides' || $content[$b]->p_code == 'total_goal') {
  459. $content[$b]->condition = '';
  460. }
  461. $data[$i]->game_status = $data[$i]->game_status;
  462. //投注详情
  463. if (!empty($data[$i]->match_time)) {
  464. $data[$i]->content1 = '[' . $data[$i]->match_time . ']';
  465. //$data[$i]->match_time = $data[$i]->match_time;
  466. } else {
  467. if (!empty($data[$i]->last_time)) {
  468. $datetime = explode(' ', $data[$i]->last_time);
  469. //$data[$i]->match_time = $datetime[1];
  470. $data[$i]->content1 = '[' . $datetime[1] . ']';
  471. }
  472. }
  473. for ($c = 0; $c < count($result); $c++) {
  474. if ($content[$b]->odds_code == $result[$c]->odds_code) {
  475. $data[$i]->str1 = 1;
  476. if ($content[$b]->result == '未处理') {
  477. $data[$i]->content = $data[$i]->content . $result[$c]->odds_name . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br>';
  478. } else {
  479. $data[$i]->content = $data[$i]->content . $result[$c]->odds_name . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br><span>' . $content[$b]->result . '</span>(' . $content[$b]->matchresult . ')<br>';
  480. }
  481. }
  482. }
  483. if ($data[$i]->str1 == 0) {
  484. if ($content[$b]->result == '未处理') {
  485. $data[$i]->content = $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br>';
  486. } else {
  487. $data[$i]->content = $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br><span>' . $content[$b]->result . '</span>(' . $content[$b]->matchresult . ')<br>';
  488. }
  489. }
  490. }
  491. //处理冠军联赛玩法详情
  492. if ($data[$i]->match_id == $content[$b]->lg_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 1) {
  493. $content[$b]->condition = '';
  494. if ($content[$b]->p_code == 'first_last_ball' || $content[$b]->p_code == 'half_full' || $content[$b]->p_code == 'capot' || $content[$b]->p_code == 'two_sides' || $content[$b]->p_code == 'total_goal') {
  495. $content[$b]->condition = '';
  496. }
  497. $data[$i]->game_status = $data[$i]->game_status;
  498. /*
  499. //投注详情
  500. if(!empty($data[$i]->match_time)){
  501. $data[$i]->content1 = '['.$data[$i]->match_time.']';
  502. //$data[$i]->match_time = $data[$i]->match_time;
  503. }
  504. else{
  505. if(!empty($data[$i]->last_time)){
  506. $datetime = explode(' ',$data[$i]->last_time);
  507. //$data[$i]->match_time = $datetime[1];
  508. $data[$i]->content1 = '['.$datetime[1].']';
  509. }
  510. }
  511. */
  512. /*
  513. for($c=0;$c<count($result);$c++){
  514. if($content[$b]->odds_code == $result[$c]->odds_code){
  515. $data[$i]->str1 = 1;
  516. if($content[$b]->result=='未处理'){
  517. $data[$i]->content = $data[$i]->content.$result[$c]->odds_name.'<br>'.$content[$b]->condition.' '.$data[$i]->team.'@'.$content[$b]->odds.' ¥'.$content[$b]->bet_money.'<br>';
  518. }else{
  519. $data[$i]->content = $data[$i]->content.$result[$c]->odds_name.'<br>'.$content[$b]->condition.' '.$data[$i]->team.'@'.$content[$b]->odds.' ¥'.$content[$b]->bet_money.'<br><span>'.$content[$b]->result.'</span>('.$content[$b]->matchresult.')<br>';
  520. }
  521. }
  522. }
  523. */
  524. if ($data[$i]->str1 == 0) {
  525. if ($content[$b]->result == '未处理') {
  526. $data[$i]->content = $content[$b]->home_team . '<br>' . $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br>';
  527. } else {
  528. $data[$i]->content = $content[$b]->home_team . '<br>' . $data[$i]->content . $content[$b]->odds_code . '<br>' . $content[$b]->condition . ' ' . $data[$i]->team . '@' . $content[$b]->odds . ' ¥' . $content[$b]->bet_money . '<br><span>' . $content[$b]->result . '</span>(' . $content[$b]->matchresult . ')<br>';
  529. }
  530. }
  531. }
  532. }
  533. $data[$i]->game_status = $data[$i]->settle_status;
  534. $data[$i]->content = $data[$i]->content1 . $data[$i]->content;
  535. }
  536. return $data->toArray();
  537. }
  538. //查询单订单是否存在
  539. function onlyorder($orderid)
  540. {
  541. $order = $this->where('order_id', $orderid)->count();
  542. return $order;
  543. }
  544. //查询单订单是否存在
  545. function getorder($orderid)
  546. {
  547. $order = $this->with("matchdatas")->where('order_id', $orderid)->first();
  548. return $order;
  549. }
  550. }