MoneyBuy.php 27 KB

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