MoneyBuy.php 23 KB

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