MoneyBuy.php 26 KB

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