MoneyBuy.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552
  1. <?php
  2. /**
  3. *------Create thems Model------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2017-06-12 05:08:18------
  7. */
  8. namespace App\Api\Model;
  9. use \System\Model;
  10. use Biz\Account\AccountManager;
  11. class MoneyBuy extends Model {
  12. protected $table = 'money_buy';
  13. //晋级流水统计
  14. function getstreamAmount($params=array(),$startime='',$endtime='')
  15. {
  16. if (empty($params['account_identity'])) {
  17. return -51005;
  18. }
  19. $gradeinfo = lm('UserGrade', 'Api')->select('name', 'rule', 'rule_details')->where('grade', '=', 0)->first();
  20. if (empty($gradeinfo)) {
  21. return -5002;
  22. }
  23. $gradeinfo = $gradeinfo->toArray();
  24. $gradeinfo['rule_details'] = explode(',', $gradeinfo['rule_details']);
  25. $bet = lm('MoneyBuy', 'Api')->where('account_identity', $params['account_identity'])->where('status', '<', 4)->where('game_status', '>', 0);
  26. $uservip = lm('User_vip', 'Api')->select('audittime')->where('account_identity', $params['account_identity'])->first();
  27. if ($gradeinfo['rule_details'][0] == 'year') {
  28. $startime = date('Y-01-01', time()) . ' 00:00:00';
  29. $endtime = date('Y-12-31', time()) . ' 23:59:59';
  30. $bet = $bet->where('money_time', '>=', $startime)->where('money_time', '<=', $endtime);
  31. } elseif ($gradeinfo['rule_details'][0] == 'month') {
  32. $startime = date('Y-m-01', strtotime(date('Y', time()) . '-' . (date('m', time()) - 1) . '-01')) . ' 00:00:00';
  33. $endtime = date('Y-m-d', strtotime("$startime +1 month -1 day")) . ' 23:59:59';
  34. $bet = $bet->where('money_time', '>=', $startime)->where('money_time', '<=', $endtime);
  35. } elseif ($gradeinfo['rule_details'][0] == 'week') {
  36. $now_day = date('W', time()) - 1;
  37. $sunday_str = time() - $now_day * 60 * 60 * 24;
  38. $sunday = date('Y-m-d 00:00:00', $sunday_str);
  39. $strday_str = time() + (6 - $now_day) * 60 * 60 * 24;
  40. $strday = date('Y-m-d 23:59:59', $strday_str);
  41. $bet = $bet->where('money_time', '>=', $sunday)->where('money_time', '<=', $strday);
  42. } elseif ($gradeinfo['rule_details'][0] == 'day') {
  43. $firstday = date('Y-m-d 00:00:00', strtotime("-" . $gradeinfo['rule_details'][3] . " day"));
  44. $bet = $bet->where('money_time', '>=', $firstday)->where('money_time', '<=', date('Y-m-d 23:59:59', strtotime('-1 day')));
  45. } elseif ($gradeinfo['rule_details'][0] == 'ymd') {
  46. $firstday = $gradeinfo['rule_details'][3] . ' 00:00:00';
  47. $bet = $bet->where('money_time', '>=', $firstday);
  48. }
  49. if(!empty($uservip)){
  50. $bet = $uservip->audittime?$bet->where ('money_time', '>=', $uservip->audittime):$bet;
  51. }
  52. $bet=$startime?$bet->where ('money_time', '>=', $startime):$bet;
  53. $bet=$endtime?$bet->where ('money_time', '<', $endtime):$bet;
  54. $bet = $bet->sum('money');
  55. return $bet;
  56. }
  57. /**
  58. * 单式投注记录
  59. *
  60. * @access public
  61. * @return String
  62. */
  63. public function singleBetRecord()
  64. {
  65. // 获取用户信息
  66. $accountManagerClass = new AccountManager;
  67. $userInfo = $accountManagerClass -> getCurrentUser();
  68. if (empty($userInfo['identity'])) {
  69. Render([], '2001', lang('Common','Api') -> get('user does login'));
  70. }
  71. // 用户ID
  72. $moneyBuySpxWhere['account_identity'] = $userInfo['identity'];
  73. // 时间区间
  74. $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
  75. $endTime = isset($_POST['endTime'])? $_POST['endTime'] : '3000-12-12 00:00:00';
  76. $moneyBuySpxBetween = ['money_time' => [$startTime, $endTime]];
  77. $moneyBuySpxMdl = lm('money_buy_simplex', "commons");
  78. //===追加状态字段 Tank.peng 2019/10/22===
  79. /*
  80. 状态:1 投注 2作废 3撤单
  81. */
  82. $status = $_POST['status']?$_POST['status']:1;
  83. $moneyBuySpxWhere['status'] = $status;
  84. //===end===
  85. // 获取订单记录
  86. $moneyBuySpxSlt = ['batch_id', 'order_id','use_mark','status as order_status','roll_ratify'];
  87. $getMoneyBuySpx = $moneyBuySpxMdl -> moneyBuySimplex($moneyBuySpxSlt, $moneyBuySpxWhere, $moneyBuySpxBetween, '', '', 1);
  88. // 获取全部订单id
  89. $moneyBuyMthOr = [];
  90. $allBatchId = array_unique($getMoneyBuySpx, SORT_REGULAR);
  91. if (!$allBatchId) {
  92. // 获取记录总数
  93. $result['total'] = 0;
  94. $result['list'] = [];
  95. // 总页数计算
  96. $result['countPage'] = 1;
  97. $result['currentPage'] = 1;
  98. return $result;
  99. }
  100. foreach ($allBatchId as $key => $value) {
  101. $moneyBuyMthOr[0][$key][0] = 'batch_id';
  102. $moneyBuyMthOr[0][$key][1] = $value['batch_id'];
  103. }
  104. $moneyBuyMthWhere['bet_type'] = 1;
  105. // 输赢
  106. if (!empty($_POST['result']) && $_POST['result'] == 1) {
  107. $moneyBuyMthOr[1][0][0] = 'result';
  108. $moneyBuyMthOr[1][0][1] = 1;
  109. $moneyBuyMthOr[1][1][0] = 'result';
  110. $moneyBuyMthOr[1][1][1] = 3;
  111. $moneyBuyMthOr[1][2][0] = 'result';
  112. $moneyBuyMthOr[1][2][1] = 2;
  113. } elseif (!empty($_POST['result']) && $_POST['result'] == 2) {
  114. $moneyBuyMthOr[1][0][0] = 'result';
  115. $moneyBuyMthOr[1][0][1] = -1;
  116. $moneyBuyMthOr[1][1][0] = 'result';
  117. $moneyBuyMthOr[1][1][1] = 4;
  118. } elseif ($_POST['result'] === '0') {
  119. $moneyBuyMthOr[1][0][0] = 'result';
  120. $moneyBuyMthOr[1][0][1] = 0;
  121. }
  122. // 当前页
  123. $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
  124. // 分页大小
  125. $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
  126. // 起始查询位置
  127. $begin = ($currentPage - 1) * $pageSize;
  128. // 获取注单
  129. $moneyBuyMthMdl = lm('Money_buy_match', "commons");
  130. $moneyBuyMthSlt = ['status', 'bet_money', 'matchresult', 'result', 'home_team', 'batch_id', 'guest_team', 'condition', 'ctime', 'odds', 'odds_name', 'match_id', 'money_buy_match.game_code', 'money_buy_match.odds_code'];
  131. $getMoneyBuyMth = $moneyBuyMthMdl -> moneyBuyMatch($moneyBuyMthSlt, $moneyBuyMthWhere, $moneyBuyMthOr, $begin, $pageSize);
  132. $allCount = $moneyBuyMthMdl -> moneyBuyMatchTotal($moneyBuyMthWhere, $moneyBuyMthOr);
  133. // 获取所有的比赛类型
  134. $stGameTypeMdl = lm('StGameType', "commons");
  135. $StGameTypeSlt = ['game_code'];
  136. $StGameTypeWhr['status'] = 1;
  137. $getStGameType = $stGameTypeMdl -> getGameType($StGameTypeSlt, $StGameTypeWhr);
  138. $allMatch = [];
  139. $allMatchInfo = [];
  140. foreach ($getStGameType as $value) {
  141. $allMatch[$value->game_code] = [];
  142. $allMatchInfo[$value->game_code] = [];
  143. }
  144. // 循环获取所有的赛事ID
  145. foreach ($getMoneyBuyMth as $value) {
  146. $allMatch[$value->game_code][] = $value->match_id;
  147. }
  148. $stCompetitionMdl = lm('St_competition', "commons");
  149. // 循环获取所有的赛事信息
  150. foreach ($allMatch as $key => $value) {
  151. $stCptWhrOr = array_unique($value);
  152. $allMatchInfo[$key] = $stCompetitionMdl -> getMatch($key, $stCptWhrOr);
  153. }
  154. // 循环添加赛事时间
  155. foreach ($getMoneyBuyMth as $k => $v) {
  156. foreach ($allMatchInfo[$v->game_code] as $key => $value) {
  157. if ($v->match_id == $value->id) {
  158. $getMoneyBuyMth[$k]->match_date = $value->match_date;
  159. $getMoneyBuyMth[$k]->match_time = $value->match_time;
  160. $getMoneyBuyMth[$k]->lg_name = $value->name_chinese;
  161. }
  162. }
  163. foreach ($getMoneyBuySpx as $key => $value) {
  164. if ($v->batch_id == $value['batch_id']) {
  165. $getMoneyBuyMth[$k]->order_id = $value['order_id'];//订单id
  166. $getMoneyBuyMth[$k]->order_status = $value['order_status'];//订单状态
  167. $getMoneyBuyMth[$k]->roll_ratify = $value['roll_ratify'];//滚球投注审核状态
  168. $getMoneyBuyMth[$k]->use_mark = $value['use_mark'];//处理备注
  169. }
  170. }
  171. }
  172. // 获取可加注所需要的查询条件
  173. $commonFunction = C() -> get('commonFunction');
  174. $stOddsWheres = [];
  175. foreach ($getMoneyBuyMth as $key => $value) {
  176. $match_id = $value -> match_id;
  177. $odds_code = $value -> odds_code;
  178. $gameType = $value -> game_code;
  179. $where = [
  180. 'match_id' => $match_id,
  181. 'odds_code' => $odds_code,
  182. ];
  183. // 判断是否重复
  184. if (!$commonFunction -> judgeEqual($where, $stOddsWheres[$gameType])) {
  185. $stOddsWheres[$gameType][] = $where;
  186. }
  187. }
  188. // 查询数据下所有可加注的游戏
  189. $stOddsModel = lm('stOdds','commons');
  190. $stOddsSelect = ['match_id', 'odds_code'];
  191. $getSstOdds = [];
  192. // 循环查询每个运动的可加注游戏 注:由于查询不同表所以必须循环查询
  193. foreach ($stOddsWheres as $key => $value) {
  194. if ($value) {
  195. $getSstOdds[$key] = $stOddsModel -> stOdds($stOddsSelect, $value, $key);
  196. }
  197. }
  198. // 循环添加玩法和判断玩法是否可加注
  199. foreach ($getMoneyBuyMth as $key => $value) {
  200. $getMoneyBuyMth[$key]->willMoney = $value->bet_money * $value->odds;
  201. if ($value->result) {
  202. switch (intval($value->result)) {
  203. case 1:
  204. $oddsDiscount = 1 + $value->odds;
  205. break;
  206. case 2:
  207. $oddsDiscount = 1;
  208. break;
  209. case 3:
  210. $oddsDiscount = 1 + $value->odds * 0.5;
  211. break;
  212. case 4:
  213. $oddsDiscount = 0.5;
  214. break;
  215. default:
  216. $oddsDiscount = 0;
  217. }
  218. $getMoneyBuyMth[$key]->winMoney = $value->bet_money * ($oddsDiscount - 1);
  219. } else {
  220. $getMoneyBuyMth[$key]->winMoney = 0;
  221. }
  222. $typeSstOdds = $getSstOdds[$value -> game_code];
  223. $thisSstOdds = [
  224. 'match_id' => $value -> match_id,
  225. 'odds_code' => $value -> odds_code,
  226. ];
  227. // 判断如果在数组中则为可加注
  228. if (!!$commonFunction->judgeEqual($thisSstOdds, $typeSstOdds)) {
  229. $getMoneyBuyMth[$key] -> addBet = 0;
  230. } else {
  231. $getMoneyBuyMth[$key] -> addBet = 1;
  232. }
  233. }
  234. // 获取记录总数
  235. $result['total'] = $allCount;
  236. $result['list'] = $getMoneyBuyMth;
  237. // 总页数计算
  238. $result['countPage'] = ceil($result['total'] / $pageSize);
  239. $result['currentPage'] = $currentPage;
  240. return $result;
  241. }
  242. /**
  243. * 串式投注记录
  244. *
  245. * @access public
  246. * @return String
  247. */
  248. public function stringBetRecord()
  249. {
  250. // 获取用户信息
  251. $accountManagerClass = new AccountManager;
  252. $userInfo = $accountManagerClass -> getCurrentUser();
  253. if (empty($userInfo['identity'])) {
  254. Render([], '2001', lang('Common','Api') -> get('user does login'));
  255. }
  256. // 用户ID
  257. $moneyBuyStrWhere['account_identity'] = $userInfo['identity'];
  258. // 输赢
  259. if (!empty($_POST['result'])) {
  260. $moneyBuyStrWhere['game_status'] = $_POST['result'];
  261. }
  262. // 时间区间
  263. $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
  264. $endTime = isset($_POST['endTime'])? $_POST['endTime'] : '3000-12-12 00:00:00';
  265. $moneyBuyStrBetween = ['money_time' => [$startTime, $endTime]];
  266. $moneyBuyStrMdl = lm('money_buy_str', "commons");
  267. // 当前页
  268. $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
  269. // 分页大小
  270. $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
  271. // 起始查询位置
  272. $begin = ($currentPage - 1) * $pageSize;
  273. // 获取订单记录
  274. $moneyBuyStrSlt = ['order_id', 'batch_id', 'gain_money', 'game_status', 'money', 'prize_money', 'money_time'];
  275. $getMoneyBuyStr = $moneyBuyStrMdl -> moneyBuyStr($moneyBuyStrSlt, $moneyBuyStrWhere, $moneyBuyStrBetween, $begin, $pageSize, 1);
  276. $allCount = $moneyBuyStrMdl -> moneyBuyStrTotal($moneyBuyStrWhere, $moneyBuyStrBetween);
  277. // 获取全部订单id
  278. $moneyBuyMthOr = [];
  279. $allBatchId = array_unique($getMoneyBuyStr, SORT_REGULAR);
  280. if (!$allBatchId) {
  281. // 获取记录总数
  282. $result['total'] = 0;
  283. $result['list'] = [];
  284. // 总页数计算
  285. $result['countPage'] = 1;
  286. $result['currentPage'] = 1;
  287. return $result;
  288. }
  289. foreach ($allBatchId as $key => $value) {
  290. $moneyBuyMthOr[0][$key][0] = 'batch_id';
  291. $moneyBuyMthOr[0][$key][1] = $value['batch_id'];
  292. }
  293. $moneyBuyMthWhere['bet_type'] = 2;
  294. // 获取注单
  295. $moneyBuyMthMdl = lm('Money_buy_match', "commons");
  296. $moneyBuyMthSlt = ['status', 'matchResult', 'bet_money', 'home_team', 'guest_team', 'condition', 'odds', 'odds_name', 'match_id', 'batch_id', 'money_buy_match.game_code', 'money_buy_match.odds_code'];
  297. $getMoneyBuyMth = $moneyBuyMthMdl -> moneyBuyMatch($moneyBuyMthSlt, $moneyBuyMthWhere, $moneyBuyMthOr, $begin, $pageSize);
  298. // 获取所有的比赛类型
  299. $stGameTypeMdl = lm('StGameType', "commons");
  300. $StGameTypeSlt = ['game_code'];
  301. $StGameTypeWhr['status'] = 1;
  302. $getStGameType = $stGameTypeMdl -> getGameType($StGameTypeSlt, $StGameTypeWhr);
  303. $allMatch = [];
  304. $allMatchInfo = [];
  305. foreach ($getStGameType as $value) {
  306. $allMatch[$value->game_code] = [];
  307. $allMatchInfo[$value->game_code] = [];
  308. }
  309. // 循环获取所有的赛事ID
  310. foreach ($getMoneyBuyMth as $value) {
  311. $allMatch[$value->game_code][] = $value->match_id;
  312. }
  313. $stCompetitionMdl = lm('St_competition', "commons");
  314. // 循环获取所有的赛事信息
  315. foreach ($allMatch as $key => $value) {
  316. $stCptWhrOr = array_unique($value);
  317. $allMatchInfo[$key] = $stCompetitionMdl -> getMatch($key, $stCptWhrOr);
  318. }
  319. // 循环添加赛事时间
  320. foreach ($getMoneyBuyMth as $k => $v) {
  321. foreach ($allMatchInfo[$v->game_code] as $key => $value) {
  322. if ($v->match_id == $value->id) {
  323. $getMoneyBuyMth[$k]->match_date = $value->match_date;
  324. $getMoneyBuyMth[$k]->match_time = $value->match_time;
  325. $getMoneyBuyMth[$k]->lg_name = $value->name_chinese;
  326. }
  327. }
  328. }
  329. // 获取可加注所需要的查询条件
  330. $commonFunction = C() -> get('commonFunction');
  331. $stOddsWheres = [];
  332. foreach ($getMoneyBuyMth as $key => $value) {
  333. $match_id = $value -> match_id;
  334. $odds_code = $value -> odds_code;
  335. $gameType = $value -> game_code;
  336. $where = [
  337. 'match_id' => $match_id,
  338. 'odds_code' => $odds_code,
  339. ];
  340. // 判断是否重复
  341. if (!$commonFunction -> judgeEqual($where, $stOddsWheres[$gameType])) {
  342. $stOddsWheres[$gameType][] = $where;
  343. }
  344. }
  345. // 查询数据下所有可加注的游戏
  346. $stOddsModel = lm('stOdds','commons');
  347. $stOddsSelect = ['match_id', 'odds_code'];
  348. $getSstOdds = [];
  349. // 循环查询每个运动的可加注游戏 注:由于查询不同表所以必须循环查询
  350. foreach ($stOddsWheres as $key => $value) {
  351. if ($value) {
  352. $getSstOdds[$key] = $stOddsModel -> stOdds($stOddsSelect, $value, $key);
  353. }
  354. }
  355. // 循环添加玩法和判断玩法是否可加注
  356. foreach ($getMoneyBuyMth as $key => $value) {
  357. $typeSstOdds = $getSstOdds[$value -> game_code];
  358. $thisSstOdds = [
  359. 'match_id' => $value -> match_id,
  360. 'odds_code' => $value -> odds_code,
  361. ];
  362. // 判断如果在数组中则为可加注
  363. if (!!$commonFunction->judgeEqual($thisSstOdds, $typeSstOdds)) {
  364. $getMoneyBuyMth[$key] -> addBet = 0;
  365. } else {
  366. $getMoneyBuyMth[$key] -> addBet = 1;
  367. }
  368. }
  369. foreach ($getMoneyBuyStr as $key => $value) {
  370. // 计算所赢金额.
  371. if ($value->gain_money) {
  372. $getMoneyBuyStr[$key]->winMoney = $value->gain_money - $value->money;
  373. } else {
  374. $getMoneyBuyStr[$key]->winMoney = 0;
  375. }
  376. foreach ($getMoneyBuyMth as $k => $v) {
  377. if ($value['batch_id'] == $v['batch_id']) {
  378. $getMoneyBuyStr[$key]['money_buy'][] = $v;
  379. }
  380. }
  381. }
  382. // 获取记录总数
  383. $result['total'] = $allCount;
  384. $result['list'] = $getMoneyBuyStr;
  385. // 总页数计算
  386. $result['countPage'] = ceil($result['total'] / $pageSize);
  387. $result['currentPage'] = $currentPage;
  388. return $result;
  389. }
  390. /**
  391. * 盈亏记录
  392. *
  393. * @access public
  394. * @return String
  395. */
  396. public function moneyRecord()
  397. {
  398. // 获取用户信息
  399. $accountManagerClass = new AccountManager;
  400. $userInfo = $accountManagerClass -> getCurrentUser();
  401. if (empty($userInfo['identity'])) {
  402. Render([], '2001', lang('Common','Api') -> get('user does login'));
  403. }
  404. $moneyRecordWhere = array();
  405. // 用户ID
  406. $moneyRecordWhere['account_identity'] = $userInfo['identity'];
  407. $moneyRecordWhere['status'] = 1;
  408. $moneyRecordWhere['settle_status'] = 2;
  409. if (empty($_POST['result']) === false) {
  410. $moneyRecordWhere['game_status'] = empty($_POST['result']);
  411. }
  412. // 时间区间
  413. $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
  414. $endTime = isset($_POST['endTime'])? $_POST['endTime'] : '3000-12-12 00:00:00';
  415. $moneyRecordBetween = [$startTime, $endTime];
  416. // 当前页
  417. $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
  418. // 分页大小
  419. $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
  420. // 起始查询位置
  421. $begin = ($currentPage - 1) * $pageSize;
  422. $moneyRecord = lm('Money_buy_simplex', "commons");
  423. $moneyRecordSelect = ['info_identity', 'trade_id', 'account_identity', 'money', 'money_time', 'money_type'];
  424. // 获取盈亏记录
  425. $result['list'] = $moneyRecord -> winLoseRecord($moneyRecordWhere, $moneyRecordBetween, $begin, $pageSize);
  426. // 获取记录总数
  427. $result['total'] = $moneyRecord -> winLoseCount($moneyRecordWhere, $moneyRecordBetween);
  428. // 总页数计算
  429. $result['countPage'] = ceil($result['total'] / $pageSize);
  430. $result['currentPage'] = $currentPage;
  431. return $result;
  432. }
  433. /**
  434. * 统计记录
  435. *
  436. * @access public
  437. * @return String
  438. */
  439. public function monthRecord()
  440. {
  441. $accountManagerClass = new AccountManager;
  442. $userInfo = $accountManagerClass -> getCurrentUser();
  443. if (empty($userInfo['identity'])) {
  444. Render([], '2001', lang('Common','Api') -> get('user does login'));
  445. }
  446. // 用户ID
  447. $moneyBuyWhere['account_identity'] = $userInfo['identity'];
  448. // 时间区间
  449. $endTime = date('Y-m-d H:i:s');
  450. if ($userInfo['statisticsTime']) {
  451. $startTime = $userInfo['statisticsTime'];
  452. } else {
  453. $startTime = '1900-01-01 00:00:00';
  454. }
  455. $moneyBuyBetween = [$startTime, $endTime];
  456. $moneyRecordWhere['settle_status'] = 2;
  457. // 获取单式投注订单
  458. $moneyBuySimplex = lm('money_buy_simplex', "commons");
  459. $mnyBuySpxData = $moneyBuySimplex
  460. ->select(['order_id', 'money', 'gain_money', 'batch_id'])
  461. ->where($moneyBuyWhere)
  462. ->whereBetween('settlementTime', $moneyBuyBetween)
  463. ->get()
  464. ->toArray();
  465. // 获取全部订单id
  466. $moneyBuyMthOr = [];
  467. $allBatchId = array_unique($mnyBuySpxData, SORT_REGULAR);
  468. if ($allBatchId) {
  469. foreach ($allBatchId as $key => $value) {
  470. $moneyBuyMthOr[0][$key][0] = 'batch_id';
  471. $moneyBuyMthOr[0][$key][1] = $value['batch_id'];
  472. }
  473. $moneyBuyMthWhere['bet_type'] = 1;
  474. // 获取注单
  475. $moneyBuyMthMdl = lm('Money_buy_match', "commons");
  476. $moneyBuyMthSlt = ['bet_money', 'odds', 'result'];
  477. $getMoneyBuyMth = $moneyBuyMthMdl -> moneyBuyMatchAll($moneyBuyMthSlt, $moneyBuyMthWhere, $moneyBuyMthOr);
  478. } else {
  479. $getMoneyBuyMth = [];
  480. }
  481. // 获取串式投注订单
  482. $moneyBuyStr = lm('money_buy_str', "commons");
  483. $mnyBuyStrData = $moneyBuyStr
  484. ->select(['order_id', 'money', 'gain_money'])
  485. ->where($moneyBuyWhere)
  486. ->whereBetween('settlementTime', $moneyBuyBetween)
  487. ->get();
  488. $winMoney = $userInfo['allWin'];
  489. $loseMoney = $userInfo['allLose'];
  490. // 单式盈利.
  491. foreach ($getMoneyBuyMth as $key => $value) {
  492. // 判断订单是否盈利
  493. if ($value->result == 1) {
  494. $winMoney += $value->bet_money * $value->odds;
  495. } else if ($value->result == 3) {
  496. $winMoney += $value->bet_money * $value->odds * 0.5;
  497. } else if ($value->result == 4) {
  498. $loseMoney += $value->bet_money * 0.5;
  499. } else if ($value->result == -1) {
  500. $loseMoney += $value->bet_money;
  501. }
  502. }
  503. // 串式盈利.
  504. foreach ($mnyBuyStrData as $key => $value) {
  505. // 判断订单是否盈利
  506. if ($value->money >= $value->gain_money) {
  507. $loseMoney += $value->money - $value->gain_money; //本钱减回款
  508. } else {
  509. $winMoney += $value->gain_money - $value->money; //回款减本钱
  510. }
  511. }
  512. // 修改用户统计
  513. $updateActDtd = [
  514. 'allWin' => $winMoney,
  515. 'allLose' => $loseMoney,
  516. 'statisticsTime' => date('Y-m-d H:i:s'),
  517. ];
  518. $accountDetailed = lm('account_detailed', "commons");
  519. $accountDetailed->where(['account_identity'=>$userInfo['identity']])->update($updateActDtd);
  520. $result = [
  521. 'winMoney' => $winMoney ?? 0,
  522. 'loseMoney' => $loseMoney ?? 0,
  523. 'allMoney' => $userInfo['available_cash'],
  524. ];
  525. return $result;
  526. }
  527. }