MoneyBuy.php 25 KB

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