SportsNoteList.php 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  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('money_buy_match','money_buy_match.order_id','=','money_buy_simplex.order_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. ->whereIn('money_buy_simplex.roll_ratify',array(0,1))
  28. ->where($where)
  29. //->distinct('money_buy_match.order_id')
  30. ->orderby('money_buy_simplex.money_time', 'desc')
  31. ->paginate($list);
  32. if (!$data < 0) {
  33. return -2021052003; //
  34. }
  35. //反水
  36. $water_return_money = \App\Models\Money_details::where('trade_type', '7')->get();
  37. //注单作废
  38. $invalid_money = \App\Models\Money_details::where('trade_type', '3')->get();
  39. //订单投注的玩法
  40. $content = \App\Models\MoneyBuyMatch::where('bet_type', '1')->get();
  41. for ($d = 0; $d < count($content); $d++) {
  42. if ($content[$d]->result == 0) {
  43. $content[$d]->result = '未处理';
  44. }
  45. if ($content[$d]->result == 1) {
  46. $content[$d]->result = '赢';
  47. }
  48. if ($content[$d]->result == -1) {
  49. $content[$d]->result = '输';
  50. }
  51. if ($content[$d]->result == 2) {
  52. $content[$d]->result = '平';
  53. }
  54. if ($content[$d]->result == 3) {
  55. $content[$d]->result = '赢半平半';
  56. }
  57. if ($content[$d]->result == 4) {
  58. $content[$d]->result = '输半平半';
  59. }
  60. }
  61. //玩法
  62. $result = \App\Models\Matchcode::where('game_code', $type)->get();
  63. //$result = \App\Model\Matchcode::get();
  64. for ($i = 0; $i < count($data); $i++) {
  65. if($data[$i]->status==1 && $data[$i]->settle_status == 1){
  66. $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 . '\',\''.$data[$i]->order_id.'\',\''.$data[$i]->name_chinese.'\');"> 作废 </a>';
  67. }
  68. else if ($data[$i]->status == 1 && $data[$i]->settle_status != 1) {
  69. $data[$i]->order_status = '投注';
  70. } else if ($data[$i]->status == 2) {
  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. } else if ($data[$i]->status == 3) {
  73. $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>';
  74. }
  75. if ($data[$i]->settle_status == 1) {
  76. $data[$i]->settle_status = '未结算';
  77. } else{
  78. $data[$i]->settle_status = '已结算';
  79. }
  80. if ($data[$i]->game_status == 0) {
  81. $data[$i]->game_status = '未处理';
  82. } else {
  83. $data[$i]->game_status = '已处理';
  84. }
  85. $data[$i]->league = $data[$i]->name_chinese;
  86. if ($data[$i]->is_champion == 0) {
  87. if ($data[$i]->game_code == 'zq') {
  88. $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;
  89. }
  90. if ($data[$i]->game_code == 'lq') {
  91. $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;
  92. }
  93. if ($data[$i]->game_code == 'wq') {
  94. $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;
  95. }
  96. if ($data[$i]->game_code == 'bq') {
  97. $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;
  98. }
  99. $data[$i]->home_guest = $data[$i]->home_team . ' VS ' . $data[$i]->guest_team;
  100. $data[$i]->time = '开赛:' . $data[$i]->match_date . ' ' . $data[$i]->match_time;
  101. } else {
  102. $data[$i]->lg_id_order = $data[$i]->match_id . '(<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  103. $data[$i]->home_guest = '冠军联赛投注';
  104. $data[$i]->time = '结束:' . $data[$i]->last_time;
  105. }
  106. $data[$i]->money_match_time = '下注:' . $data[$i]->money_time . $data[$i]->time;
  107. //反水
  108. $data[$i]->water_return = -1;
  109. for ($a = 0; $a < count($water_return_money); $a++) {
  110. if ($data[$i]->order_id == $water_return_money[$a]->trade_id) {
  111. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  112. $data[$i]->water_return = 0;
  113. } else {
  114. $data[$i]->water_return = $water_return_money[$a]->money;
  115. }
  116. //用户投注后账户金额
  117. $data[$i]->frozen_cash = $water_return_money[$a]->money_cash;
  118. }
  119. }
  120. if ($data[$i]->water_return == -1) {
  121. $data[$i]->water_return = 0;
  122. //用户投注后账户金额
  123. $data[$i]->frozen_cash = $data[$i]->money_cash;
  124. }
  125. //此时结果金额
  126. $data[$i]->result = $data[$i]->water_return + $data[$i]->gain_money;
  127. //用户投注前账户金额
  128. $data[$i]->available_cash = $data[$i]->money_cash + $data[$i]->money;
  129. //投注前后账户金额
  130. $data[$i]->account_money = $data[$i]->available_cash . '<br><span>' . $data[$i]->money . '</span><br>' . $data[$i]->frozen_cash;
  131. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  132. // for ($b = 0; $b < count($invalid_money); $b++) {
  133. // if ($data[$i]->order_id == $invalid_money[$b]->trade_id) {
  134. // $data[$i]->available_cash = $invalid_money[$b]->money_cash;
  135. // $data[$i]->account_money = $data[$i]->available_cash;
  136. // }
  137. // }
  138. $data[$i]->account_money = $data[$i]->available_cash;
  139. }
  140. $data[$i]->str = 0;
  141. for ($b = 0; $b < count($content); $b++) {
  142. $data[$i]->str1 = 0;
  143. $data[$i]->team = '';
  144. if (!empty($content[$b]->odds_code)) {
  145. if (!empty(stristr($content[$b]->odds_code, 'home'))) {
  146. $data[$i]->team = $data[$i]->home_team;
  147. }
  148. if (!empty(stristr($content[$b]->odds_code, 'guest'))) {
  149. $data[$i]->team = $data[$i]->guest_team;
  150. }
  151. if ($content[$b]->p_code == 'half_full') {
  152. $string = str_replace('home', $data[$i]->home_team, $content[$b]->odds_code);
  153. $string = str_replace('guest', $data[$i]->guest_team, $string);
  154. $string = str_replace('dogfall', '和局', $string);
  155. $string = explode('_', $string);
  156. $data[$i]->team = $string['2'] . '/' . $string['3'];
  157. }
  158. }
  159. //处理普通赛事玩法详情
  160. if ($data[$i]->match_id == $content[$b]->match_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 0) {
  161. 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') {
  162. $content[$b]->condition = '';
  163. }
  164. $data[$i]->game_status = $data[$i]->game_status;
  165. //投注详情
  166. if (!empty($data[$i]->match_time)) {
  167. $data[$i]->content1 = '[' . $data[$i]->match_time . ']';
  168. //$data[$i]->match_time = $data[$i]->match_time;
  169. } else {
  170. if (!empty($data[$i]->last_time)) {
  171. $datetime = explode(' ', $data[$i]->last_time);
  172. //$data[$i]->match_time = $datetime[1];
  173. $data[$i]->content1 = '[' . $datetime[1] . ']';
  174. }
  175. }
  176. for ($c = 0; $c < count($result); $c++) {
  177. if ($content[$b]->odds_code == $result[$c]->odds_code) {
  178. $data[$i]->str1 = 1;
  179. if ($content[$b]->result == '未处理') {
  180. $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>';
  181. } else {
  182. $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>';
  183. }
  184. }
  185. }
  186. if ($data[$i]->str1 == 0) {
  187. if ($content[$b]->result == '未处理') {
  188. $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>';
  189. } else {
  190. $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>';
  191. }
  192. }
  193. }
  194. //处理冠军联赛玩法详情
  195. if ($data[$i]->match_id == $content[$b]->lg_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 1) {
  196. $content[$b]->condition = '';
  197. 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') {
  198. $content[$b]->condition = '';
  199. }
  200. $data[$i]->game_status = $data[$i]->game_status;
  201. /*
  202. //投注详情
  203. if(!empty($data[$i]->match_time)){
  204. $data[$i]->content1 = '['.$data[$i]->match_time.']';
  205. //$data[$i]->match_time = $data[$i]->match_time;
  206. }
  207. else{
  208. if(!empty($data[$i]->last_time)){
  209. $datetime = explode(' ',$data[$i]->last_time);
  210. //$data[$i]->match_time = $datetime[1];
  211. $data[$i]->content1 = '['.$datetime[1].']';
  212. }
  213. }
  214. */
  215. /*
  216. for($c=0;$c<count($result);$c++){
  217. if($content[$b]->odds_code == $result[$c]->odds_code){
  218. $data[$i]->str1 = 1;
  219. if($content[$b]->result=='未处理'){
  220. $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>';
  221. }else{
  222. $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>';
  223. }
  224. }
  225. }
  226. */
  227. if ($data[$i]->str1 == 0) {
  228. if ($content[$b]->result == '未处理') {
  229. $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>';
  230. } else {
  231. $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>';
  232. }
  233. }
  234. }
  235. }
  236. // if($data[$i]->status == 1){
  237. // if($data[$i]->match_status == 0 || $data[$i]->match_status == 1){
  238. // $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>';
  239. // }
  240. // if($data[$i]->match_status == 2 || $data[$i]->match_status == 3 || $data[$i]->match_status == 5){
  241. // if($data[$i]->settle_status == '已结算'){
  242. // $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>';
  243. // }else{
  244. // $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>';
  245. // }
  246. // }
  247. // }else{
  248. // $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>';
  249. // }
  250. $data[$i]->content = $data[$i]->content1 . $data[$i]->content;
  251. }
  252. return $data->toArray();
  253. }
  254. //投注金额汇总统计
  255. function MoneyCount($where = '', $type)
  256. {
  257. $data = array();
  258. // $data['all_money'] = $this->sum('money');
  259. // $data['all_prize_money'] = $this->sum('prize_money');
  260. // $data['alraedy_prize_money'] = $this->where('settle_status','2')->sum('gain_money');
  261. $data['all_money'] = 0;
  262. $data['all_prize_money'] = 0;
  263. $data['alraedy_prize_money'] = 0;
  264. $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')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where('money_buy_simplex.status', '1')->get();
  265. for ($a = 0; $a < count($all_money); $a++) {
  266. $data['all_money'] = $data['all_money'] + $all_money[$a]->money;
  267. }
  268. $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')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where('money_buy_simplex.status', '1')->get();
  269. for ($a = 0; $a < count($all_prize_money); $a++) {
  270. $data['all_prize_money'] = $data['all_money'] + $all_prize_money[$a]->prize_money;
  271. }
  272. $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')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where('money_buy_simplex.status', '1')->get();
  273. for ($a = 0; $a < count($alraedy_prize_money); $a++) {
  274. $data['alraedy_prize_money'] = $data['all_money'] + $alraedy_prize_money[$a]->gain_money;
  275. }
  276. if (!empty($where) && is_array($where)) {
  277. $data['all_money'] = 0;
  278. $data['all_prize_money'] = 0;
  279. $data['alraedy_prize_money'] = 0;
  280. //$data['all_money'] = $this->where($where)->sum('money');
  281. // $data['all_prize_money'] = $this->where($where)->sum('prize_money');
  282. // $data['alraedy_prize_money'] = $this->where($where)->where('settle_status','2')->sum('gain_money');
  283. $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')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where($where)->where('money_buy_simplex.status', '1')->get();
  284. for ($a = 0; $a < count($all_money); $a++) {
  285. $data['all_money'] = $data['all_money'] + $all_money[$a]->money;
  286. }
  287. $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')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where($where)->where('money_buy_simplex.status', '1')->get();
  288. for ($a = 0; $a < count($all_prize_money); $a++) {
  289. $data['all_prize_money'] = $data['all_prize_money'] + $all_prize_money[$a]->prize_money;
  290. }
  291. $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')->whereIn('money_buy_simplex.roll_ratify',array(0,1))->where('money_buy_simplex.settle_status', '2')->where($where)->where('money_buy_simplex.status', '1')->get();
  292. for ($a = 0; $a < count($alraedy_prize_money); $a++) {
  293. $data['alraedy_prize_money'] = $data['alraedy_prize_money'] + $alraedy_prize_money[$a]->gain_money;
  294. }
  295. }
  296. return $data;
  297. }
  298. //修改赛事下的所有单式下注 3199308
  299. function updatesimplex($ssid, $code)
  300. {
  301. $newapp = new \App\Models\MoneyBuyMatch();
  302. $data = $newapp->allsimplexorder($ssid, $code);
  303. if ($data) {
  304. for ($i = 0; $i < count($data); $i++) {
  305. $the = array(
  306. 'status' => 2,
  307. 'game_status' => 3,
  308. 'game_code' => $code,
  309. );
  310. $res = $this->where('order_id', $data[$i]['order_id'])->update($the);
  311. }
  312. if ($res < 0) {
  313. return -7012000302; //操作失败
  314. }
  315. return $res;
  316. } else {
  317. return -111;
  318. }
  319. }
  320. function info($list = 10, $page, $where = '', $type)
  321. {
  322. $data = $this
  323. ->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')
  324. ->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')
  325. // ->join('st_'.$type.'_league','st_'.$type.'_competition.lg_id','=','st_'.$type.'_league.id')
  326. ->join('st_' . $type . '_league', 'money_buy_simplex.lg_id', '=', 'st_' . $type . '_league.id')
  327. ->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')
  328. ->whereIn('money_buy_simplex.roll_ratify',array(0,1))
  329. ->where($where)
  330. ->orderby('money_buy_simplex.money_time', 'desc')
  331. ->paginate($list);
  332. if (!$data < 0) {
  333. return -2021052003; //
  334. }
  335. //反水
  336. $water_return_money = \App\Models\Money_details::where('trade_type', '7')->get();
  337. //注单作废
  338. $invalid_money = \App\Models\Money_details::where('trade_type', '3')->get();
  339. //订单投注的玩法
  340. $content = \App\Models\MoneyBuyMatch::where('bet_type', '1')->get();
  341. for ($d = 0; $d < count($content); $d++) {
  342. if ($content[$d]->result == 0) {
  343. $content[$d]->result = '未处理';
  344. }
  345. if ($content[$d]->result == 1) {
  346. $content[$d]->result = '赢';
  347. }
  348. if ($content[$d]->result == -1) {
  349. $content[$d]->result = '输';
  350. }
  351. if ($content[$d]->result == 2) {
  352. $content[$d]->result = '平';
  353. }
  354. if ($content[$d]->result == 3) {
  355. $content[$d]->result = '赢半平半';
  356. }
  357. if ($content[$d]->result == 4) {
  358. $content[$d]->result = '输半平半';
  359. }
  360. }
  361. //玩法
  362. $result = \App\Models\Matchcode::where('game_code', $type)->get();
  363. //$result = \App\Model\Matchcode::get();
  364. for ($i = 0; $i < count($data); $i++) {
  365. if ($data[$i]->status == 1 && $data[$i]->settle_status == 1) {
  366. $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 . '\',\''.$data[$i]->order_id.'\',\''.$data[$i]->name_chinese.'\');"> 作废 </a>';
  367. } else if ($data[$i]->status == 1 && $data[$i]->settle_status != 1) {
  368. $data[$i]->order_status = '投注';
  369. } else if ($data[$i]->status == 2) {
  370. $data[$i]->order_status = '作废';
  371. } else if ($data[$i]->status == 3) {
  372. $data[$i]->order_status = '撤单';
  373. }
  374. // if($data[$i]->settle_status==1){
  375. // $data[$i]->settle_status = '未结算';
  376. // }else if($data[$i]->settle_status==2){
  377. // $data[$i]->settle_status = '已结算';
  378. // }
  379. if ($data[$i]->game_status == 0) {
  380. $data[$i]->game_status = '未处理';
  381. } else {
  382. $data[$i]->game_status = '已处理';
  383. }
  384. $data[$i]->league = $data[$i]->name_chinese;
  385. if ($data[$i]->is_champion == 0) {
  386. if ($data[$i]->game_code == 'zq') {
  387. $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;
  388. }
  389. if ($data[$i]->game_code == 'lq') {
  390. $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;
  391. }
  392. if ($data[$i]->game_code == 'wq') {
  393. $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;
  394. }
  395. if ($data[$i]->game_code == 'bq') {
  396. $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;
  397. }
  398. $data[$i]->home_guest = $data[$i]->home_team . ' VS ' . $data[$i]->guest_team;
  399. $data[$i]->time = '开赛:' . $data[$i]->match_date . ' ' . $data[$i]->match_time;
  400. } else {
  401. $data[$i]->lg_id_order = $data[$i]->match_id . '(<span>' . $data[$i]->account_name . '</span>)<br>' . $data[$i]->order_id;
  402. $data[$i]->home_guest = '冠军联赛投注';
  403. $data[$i]->time = '结束:' . $data[$i]->last_time;
  404. }
  405. $data[$i]->money_match_time = '下注:' . $data[$i]->money_time . $data[$i]->time;
  406. /*
  407. $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
  408. $data[$i]->time = '开赛:'.$data[$i]->match_date.' '.$data[$i]->match_time;
  409. $data[$i]->money_match_time = '下注:'.$data[$i]->money_time.'<br>'.$data[$i]->time;
  410. */
  411. //反水
  412. $data[$i]->water_return = -1;
  413. for ($a = 0; $a < count($water_return_money); $a++) {
  414. if ($data[$i]->order_id == $water_return_money[$a]->trade_id) {
  415. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  416. $data[$i]->water_return = 0;
  417. } else {
  418. $data[$i]->water_return = $water_return_money[$a]->money;
  419. }
  420. //用户投注后账户金额
  421. $data[$i]->frozen_cash = $water_return_money[$a]->money_cash;
  422. }
  423. }
  424. if ($data[$i]->water_return == -1) {
  425. $data[$i]->water_return = 0;
  426. //用户投注后账户金额
  427. $data[$i]->frozen_cash = $data[$i]->money_cash;
  428. }
  429. //此时结果金额
  430. $data[$i]->result = $data[$i]->water_return + $data[$i]->gain_money;
  431. //用户投注前账户金额
  432. $data[$i]->available_cash = $data[$i]->money_cash + $data[$i]->money;
  433. //投注前后账户金额
  434. $data[$i]->account_money = $data[$i]->available_cash . '<br><span>' . $data[$i]->money . '</span><br>' . $data[$i]->frozen_cash;
  435. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  436. // for ($b = 0; $b < count($invalid_money); $b++) {
  437. // if ($data[$i]->order_id == $invalid_money[$b]->trade_id) {
  438. // $data[$i]->available_cash = $invalid_money[$b]->money_cash;
  439. // $data[$i]->account_money = $data[$i]->available_cash;
  440. // }
  441. // }
  442. $data[$i]->account_money = $data[$i]->available_cash;
  443. }
  444. $data[$i]->str = 0;
  445. for ($b = 0; $b < count($content); $b++) {
  446. $data[$i]->str1 = 0;
  447. $data[$i]->team = '';
  448. if (!empty($content[$b]->odds_code)) {
  449. if (!empty(stristr($content[$b]->odds_code, 'home'))) {
  450. $data[$i]->team = $data[$i]->home_team;
  451. }
  452. if (!empty(stristr($content[$b]->odds_code, 'guest'))) {
  453. $data[$i]->team = $data[$i]->guest_team;
  454. }
  455. if ($content[$b]->p_code == 'half_full') {
  456. $string = str_replace('home', $data[$i]->home_team, $content[$b]->odds_code);
  457. $string = str_replace('guest', $data[$i]->guest_team, $string);
  458. $string = str_replace('dogfall', '和局', $string);
  459. $string = explode('_', $string);
  460. $data[$i]->team = $string['2'] . '/' . $string['3'];
  461. }
  462. }
  463. //处理普通赛事
  464. if ($data[$i]->match_id == $content[$b]->match_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 0) {
  465. 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') {
  466. $content[$b]->condition = '';
  467. }
  468. $data[$i]->game_status = $data[$i]->game_status;
  469. //投注详情
  470. if (!empty($data[$i]->match_time)) {
  471. $data[$i]->content1 = '[' . $data[$i]->match_time . ']';
  472. //$data[$i]->match_time = $data[$i]->match_time;
  473. } else {
  474. if (!empty($data[$i]->last_time)) {
  475. $datetime = explode(' ', $data[$i]->last_time);
  476. //$data[$i]->match_time = $datetime[1];
  477. $data[$i]->content1 = '[' . $datetime[1] . ']';
  478. }
  479. }
  480. for ($c = 0; $c < count($result); $c++) {
  481. if ($content[$b]->odds_code == $result[$c]->odds_code) {
  482. $data[$i]->str1 = 1;
  483. if ($content[$b]->result == '未处理') {
  484. $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>';
  485. } else {
  486. $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>';
  487. }
  488. }
  489. }
  490. if ($data[$i]->str1 == 0) {
  491. if ($content[$b]->result == '未处理') {
  492. $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>';
  493. } else {
  494. $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>';
  495. }
  496. }
  497. }
  498. //处理冠军联赛玩法详情
  499. if ($data[$i]->match_id == $content[$b]->lg_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 1) {
  500. $content[$b]->condition = '';
  501. 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') {
  502. $content[$b]->condition = '';
  503. }
  504. $data[$i]->game_status = $data[$i]->game_status;
  505. /*
  506. //投注详情
  507. if(!empty($data[$i]->match_time)){
  508. $data[$i]->content1 = '['.$data[$i]->match_time.']';
  509. //$data[$i]->match_time = $data[$i]->match_time;
  510. }
  511. else{
  512. if(!empty($data[$i]->last_time)){
  513. $datetime = explode(' ',$data[$i]->last_time);
  514. //$data[$i]->match_time = $datetime[1];
  515. $data[$i]->content1 = '['.$datetime[1].']';
  516. }
  517. }
  518. */
  519. /*
  520. for($c=0;$c<count($result);$c++){
  521. if($content[$b]->odds_code == $result[$c]->odds_code){
  522. $data[$i]->str1 = 1;
  523. if($content[$b]->result=='未处理'){
  524. $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>';
  525. }else{
  526. $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>';
  527. }
  528. }
  529. }
  530. */
  531. if ($data[$i]->str1 == 0) {
  532. if ($content[$b]->result == '未处理') {
  533. $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>';
  534. } else {
  535. $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>';
  536. }
  537. }
  538. }
  539. }
  540. $data[$i]->game_status = $data[$i]->settle_status;
  541. $data[$i]->content = $data[$i]->content1 . $data[$i]->content;
  542. }
  543. return $data->toArray();
  544. }
  545. //查询单订单是否存在
  546. function onlyorder($orderid)
  547. {
  548. $order = $this->where('order_id', $orderid)->count();
  549. return $order;
  550. }
  551. //查询单订单是否存在
  552. function getorder($orderid)
  553. {
  554. $order = $this->with("matchdatas")->where('order_id', $orderid)->first();
  555. return $order;
  556. }
  557. function checkinfo($list = 10, $page, $where = '', $type)
  558. {
  559. $data = $this
  560. ->join('money_details', 'money_details.info_identity', '=', 'money_buy_simplex.info_identity')
  561. ->join('st_' . $type . '_competition', 'st_' . $type . '_competition.id', '=', 'money_buy_simplex.match_id')
  562. //->join('money_buy_match','money_buy_match.order_id','=','money_buy_simplex.order_id')
  563. ->join('st_' . $type . '_league', 'money_buy_simplex.lg_id', '=', 'st_' . $type . '_league.id')
  564. ->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', 'money_buy_simplex.roll_ratify', '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')
  565. ->whereIn('money_buy_simplex.roll_ratify',array(-1,2))
  566. ->where($where)
  567. //->distinct('money_buy_match.order_id')
  568. ->orderby('money_buy_simplex.money_time', 'desc')
  569. ->paginate($list);
  570. if (!$data < 0) {
  571. return -2021052003; //
  572. }
  573. //反水
  574. $water_return_money = \App\Models\Money_details::where('trade_type', '7')->get();
  575. //注单作废
  576. $invalid_money = \App\Models\Money_details::where('trade_type', '3')->get();
  577. //订单投注的玩法
  578. $content = \App\Models\MoneyBuyMatch::where('bet_type', '1')->get();
  579. for ($d = 0; $d < count($content); $d++) {
  580. if ($content[$d]->result == 0) {
  581. $content[$d]->result = '未处理';
  582. }
  583. if ($content[$d]->result == 1) {
  584. $content[$d]->result = '赢';
  585. }
  586. if ($content[$d]->result == -1) {
  587. $content[$d]->result = '输';
  588. }
  589. if ($content[$d]->result == 2) {
  590. $content[$d]->result = '平';
  591. }
  592. if ($content[$d]->result == 3) {
  593. $content[$d]->result = '赢半平半';
  594. }
  595. if ($content[$d]->result == 4) {
  596. $content[$d]->result = '输半平半';
  597. }
  598. }
  599. //玩法
  600. $result = \App\Models\Matchcode::where('game_code', $type)->get();
  601. //$result = \App\Model\Matchcode::get();
  602. for ($i = 0; $i < count($data); $i++) {
  603. if($data[$i]->status==1 && $data[$i]->settle_status == 1){
  604. $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 . '\',\''.$data[$i]->order_id.'\',\''.$data[$i]->name_chinese.'\');"> 作废 </a>';
  605. }
  606. if ($data[$i]->status == 1 && $data[$i]->settle_status != 1) {
  607. $data[$i]->order_status = '投注';
  608. } else if ($data[$i]->status == 2) {
  609. $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>';
  610. } else if ($data[$i]->status == 3) {
  611. $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>';
  612. }
  613. if ($data[$i]->settle_status == 1) {
  614. $data[$i]->settle_status = '未结算';
  615. } else if ($data[$i]->settle_status == 2) {
  616. $data[$i]->settle_status = '已结算';
  617. }
  618. if ($data[$i]->game_status == 0) {
  619. $data[$i]->game_status = '未处理';
  620. } else {
  621. $data[$i]->game_status = '已处理';
  622. }
  623. if ($data[$i]->roll_ratify == 2) {
  624. $data[$i]->roll_ratify = '<a class="layui-btn layui-btn-sm lay-btn-diy" lay-event="detail" pid="id" uri="/admin/CheckRolling/check/?id=" href="javascript:check(\'/admin/CheckRolling/check/?id=' . $data[$i]->id . '\');"> 通过 </a><br><a class="layui-btn layui-btn-sm invalid" lay-event="detail" pid="id" style="margin-top:5px;" uri="/admin/CheckRolling/nocheck/?id=" href="javascript:nocheck(\'/admin/CheckRolling/nocheck/?id=' . $data[$i]->id . '\');"> 拒绝 </a>';
  625. }
  626. if ($data[$i]->roll_ratify == -1) {
  627. $data[$i]->roll_ratify = '未通过审核';
  628. }
  629. if ($data[$i]->game_code == 'zq') {
  630. $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;
  631. }
  632. if ($data[$i]->game_code == 'lq') {
  633. $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;
  634. }
  635. if ($data[$i]->game_code == 'wq') {
  636. $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;
  637. }
  638. if ($data[$i]->game_code == 'bq') {
  639. $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;
  640. }
  641. $data[$i]->league = $data[$i]->name_chinese;
  642. if ($data[$i]->is_champion == 0) {
  643. $data[$i]->home_guest = $data[$i]->home_team . ' VS ' . $data[$i]->guest_team;
  644. $data[$i]->time = '开赛:' . $data[$i]->match_date . ' ' . $data[$i]->match_time;
  645. } else {
  646. $data[$i]->home_guest = '冠军联赛投注';
  647. $data[$i]->time = '结束:' . $data[$i]->last_time;
  648. }
  649. $data[$i]->money_match_time = '下注:' . $data[$i]->money_time . $data[$i]->time;
  650. //反水
  651. $data[$i]->water_return = -1;
  652. for ($a = 0; $a < count($water_return_money); $a++) {
  653. if ($data[$i]->order_id == $water_return_money[$a]->trade_id) {
  654. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  655. $data[$i]->water_return = 0;
  656. } else {
  657. $data[$i]->water_return = $water_return_money[$a]->money;
  658. }
  659. //用户投注后账户金额
  660. $data[$i]->frozen_cash = $water_return_money[$a]->money_cash;
  661. }
  662. }
  663. if ($data[$i]->water_return == -1) {
  664. $data[$i]->water_return = 0;
  665. //用户投注后账户金额
  666. $data[$i]->frozen_cash = $data[$i]->money_cash;
  667. }
  668. //此时结果金额
  669. $data[$i]->result = $data[$i]->water_return + $data[$i]->gain_money;
  670. //用户投注前账户金额
  671. $data[$i]->available_cash = $data[$i]->money_cash + $data[$i]->money;
  672. //投注前后账户金额
  673. $data[$i]->account_money = $data[$i]->available_cash . '<br><span>' . $data[$i]->money . '</span><br>' . $data[$i]->frozen_cash;
  674. if ($data[$i]->status == 2 || $data[$i]->status == 3) {
  675. // for ($b = 0; $b < count($invalid_money); $b++) {
  676. // if ($data[$i]->order_id == $invalid_money[$b]->trade_id) {
  677. // $data[$i]->available_cash = $invalid_money[$b]->money_cash;
  678. // $data[$i]->account_money = $data[$i]->available_cash;
  679. // }
  680. // }
  681. $data[$i]->account_money = $data[$i]->available_cash;
  682. }
  683. $data[$i]->str = 0;
  684. for ($b = 0; $b < count($content); $b++) {
  685. $data[$i]->str1 = 0;
  686. $data[$i]->team = '';
  687. if (!empty($content[$b]->odds_code)) {
  688. if (!empty(stristr($content[$b]->odds_code, 'home'))) {
  689. $data[$i]->team = $data[$i]->home_team;
  690. }
  691. if (!empty(stristr($content[$b]->odds_code, 'guest'))) {
  692. $data[$i]->team = $data[$i]->guest_team;
  693. }
  694. if ($content[$b]->p_code == 'half_full') {
  695. $string = str_replace('home', $data[$i]->home_team, $content[$b]->odds_code);
  696. $string = str_replace('guest', $data[$i]->guest_team, $string);
  697. $string = str_replace('dogfall', '和局', $string);
  698. $string = explode('_', $string);
  699. $data[$i]->team = $string['2'] . '/' . $string['3'];
  700. }
  701. }
  702. //处理普通赛事玩法详情
  703. if ($data[$i]->match_id == $content[$b]->match_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 0) {
  704. 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') {
  705. $content[$b]->condition = '';
  706. }
  707. $data[$i]->game_status = $data[$i]->game_status;
  708. //投注详情
  709. if (!empty($data[$i]->match_time)) {
  710. $data[$i]->content1 = '[' . $data[$i]->match_time . ']';
  711. //$data[$i]->match_time = $data[$i]->match_time;
  712. } else {
  713. if (!empty($data[$i]->last_time)) {
  714. $datetime = explode(' ', $data[$i]->last_time);
  715. //$data[$i]->match_time = $datetime[1];
  716. $data[$i]->content1 = '[' . $datetime[1] . ']';
  717. }
  718. }
  719. for ($c = 0; $c < count($result); $c++) {
  720. if ($content[$b]->odds_code == $result[$c]->odds_code) {
  721. $data[$i]->str1 = 1;
  722. if ($content[$b]->result == '未处理') {
  723. $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>';
  724. } else {
  725. $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>';
  726. }
  727. }
  728. }
  729. if ($data[$i]->str1 == 0) {
  730. if ($content[$b]->result == '未处理') {
  731. $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>';
  732. } else {
  733. $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>';
  734. }
  735. }
  736. }
  737. //处理冠军联赛玩法详情
  738. if ($data[$i]->match_id == $content[$b]->lg_id && $data[$i]->batch_id == $content[$b]->batch_id && $data[$i]->is_champion == 1) {
  739. $content[$b]->condition = '';
  740. 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') {
  741. $content[$b]->condition = '';
  742. }
  743. $data[$i]->game_status = $data[$i]->game_status;
  744. /*
  745. //投注详情
  746. if(!empty($data[$i]->match_time)){
  747. $data[$i]->content1 = '['.$data[$i]->match_time.']';
  748. //$data[$i]->match_time = $data[$i]->match_time;
  749. }
  750. else{
  751. if(!empty($data[$i]->last_time)){
  752. $datetime = explode(' ',$data[$i]->last_time);
  753. //$data[$i]->match_time = $datetime[1];
  754. $data[$i]->content1 = '['.$datetime[1].']';
  755. }
  756. }
  757. */
  758. /*
  759. for($c=0;$c<count($result);$c++){
  760. if($content[$b]->odds_code == $result[$c]->odds_code){
  761. $data[$i]->str1 = 1;
  762. if($content[$b]->result=='未处理'){
  763. $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>';
  764. }else{
  765. $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>';
  766. }
  767. }
  768. }
  769. */
  770. if ($data[$i]->str1 == 0) {
  771. if ($content[$b]->result == '未处理') {
  772. $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>';
  773. } else {
  774. $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>';
  775. }
  776. }
  777. }
  778. }
  779. // if($data[$i]->status == 1){
  780. // if($data[$i]->match_status == 0 || $data[$i]->match_status == 1){
  781. // $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>';
  782. // }
  783. // if($data[$i]->match_status == 2 || $data[$i]->match_status == 3 || $data[$i]->match_status == 5){
  784. // if($data[$i]->settle_status == '已结算'){
  785. // $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>';
  786. // }else{
  787. // $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>';
  788. // }
  789. // }
  790. // }else{
  791. // $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>';
  792. // }
  793. $data[$i]->content = $data[$i]->content1 . $data[$i]->content;
  794. }
  795. return $data->toArray();
  796. }
  797. //作废赛事下注单处理
  798. function delorder($matchid,$type){
  799. //该赛事的单式注单
  800. $account_identitys = array();
  801. $order_ids = array();
  802. $orders = $this->where('match_id',$matchid)->get();
  803. if(!empty($orders)){
  804. for ($c=0; $c < count($orders); $c++){
  805. $account_identitys[] = $orders[$c]['account_identitys'];
  806. $order_ids[] = $orders[$c]['order_id'];
  807. }
  808. //用戶账户金额
  809. $account_money = \App\Models\Account_detailed::wherein('account_identity',$account_identitys)->get();
  810. //反水
  811. $water_return_money = \App\Models\Money_details::wherein('trade_id',$order_ids)->where('trade_type', '7')->get();
  812. for($i=0;$i<count($orders);$i++){
  813. $available_cash = '';
  814. for($a=0;$a<count($account_money);$a++){
  815. if($orders[$i]['account_identity'] == $account_money[$a]['account_identity']){
  816. $available_cash = $account_money[$a]['available_cash'];
  817. }
  818. }
  819. $water_return = '';
  820. for($b=0;$b<count($water_return_money);$b++){
  821. if($orders[$i]['order_id'] == $water_return_money[$b]['trade_id']){
  822. $water_return = $water_return_money[$b]['money'];
  823. } else {
  824. $water_return = 0;
  825. }
  826. }
  827. $new_available_cash = $available_cash + $orders[$i]->money - $orders[$i]->gain_money - $water_return;
  828. $models = new \App\Models\Money_details();
  829. $models->info_identity = UUID();
  830. $models->trade_id = $orders[$i]->order_id;
  831. $models->account_name = $orders[$i]->account_name;
  832. $models->account_identity = $orders[$i]->account_identity;
  833. $models->money = abs($orders[$i]->money - $orders[$i]->gain_money - $water_return);
  834. $models->money_time = date("Y-m-d H:i:s", time());
  835. if ($new_available_cash > $available_cash) {
  836. $models->money_type = '1';
  837. } else {
  838. $models->money_type = '2';
  839. }
  840. $models->money_cash = $new_available_cash;
  841. $models->trade_type = '3';
  842. $models->trade_desc = '赛事作废单式注单回款';
  843. $models->status = '1';
  844. try {
  845. DB::beginTransaction();//开启事务
  846. $this->where('id', $orders[$i]['id'])->update(['status' => '2']);
  847. \App\Models\Account_detailed::where('account_identity', $orders[$i]->account_identity)->update(['available_cash' => $new_available_cash, 'cash' => $new_available_cash]);
  848. $models->save();
  849. DB::commit();//提交
  850. } catch (Exception $e) {
  851. DB::rollback();//回滚
  852. }
  853. }
  854. }
  855. //该赛事相关的的串关注单做平局处理
  856. \App\Models\MoneyBuyMatch::where('match_id',$matchid)->where('game_code',$type)->where('bet_type',2)->update(['result'=>2]);
  857. }
  858. }