MoneyBuy.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  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] = 'batch_id';
  130. $moneyBuyMthOr[0][$key][1] = $value['batch_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', '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->batch_id == $value['batch_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. $moneyBuyMthOr = [];
  335. $allBatchId = array_unique($getMoneyBuyStr, SORT_REGULAR);
  336. if (!$allBatchId) {
  337. // 获取记录总数
  338. $result['total'] = 0;
  339. $result['list'] = [];
  340. // 总页数计算
  341. $result['countPage'] = 1;
  342. $result['currentPage'] = 1;
  343. return $result;
  344. }
  345. // foreach ($allBatchId as $key => $value) {
  346. // $moneyBuyMthOr[0][$key][0] = 'batch_id';
  347. // $moneyBuyMthOr[0][$key][1] = $value['batch_id'];
  348. // }
  349. foreach ($allBatchId as $key => $value) {
  350. $moneyBuyMthOr[0][$key][0] = 'order_id';
  351. $moneyBuyMthOr[0][$key][1] = $value['order_id'];
  352. }
  353. // 获取注单
  354. $moneyBuyMthWhere['bet_type'] = 2;
  355. $moneyBuyMthMdl = lm('Money_buy_match', "commons");
  356. $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'];
  357. $getMoneyBuyMth = $moneyBuyMthMdl -> moneyBuyMatch($moneyBuyMthSlt, $moneyBuyMthWhere, $moneyBuyMthOr, $begin, $pageSize);
  358. // 获取所有的比赛类型
  359. $stGameTypeMdl = lm('StGameType', "commons");
  360. $StGameTypeSlt = ['game_code'];
  361. $StGameTypeWhr['status'] = 1;
  362. $getStGameType = $stGameTypeMdl -> getGameType($StGameTypeSlt, $StGameTypeWhr);
  363. $allMatch = [];
  364. $allMatchInfo = [];
  365. foreach ($getStGameType as $value) {
  366. $allMatch[$value->game_code] = [];
  367. $allMatchInfo[$value->game_code] = [];
  368. }
  369. // 循环获取所有的赛事ID
  370. foreach ($getMoneyBuyMth as $value) {
  371. $allMatch[$value->game_code][] = $value->match_id;
  372. }
  373. $stCompetitionMdl = lm('St_competition', "commons");
  374. // 循环获取所有的赛事信息
  375. foreach ($allMatch as $key => $value) {
  376. $stCptWhrOr = array_unique($value);
  377. $allMatchInfo[$key] = $stCompetitionMdl -> getMatch($key, $stCptWhrOr);
  378. }
  379. // 循环添加赛事时间
  380. foreach ($getMoneyBuyMth as $k => $v) {
  381. foreach ($allMatchInfo[$v->game_code] as $key => $value) {
  382. if ($v->match_id == $value->id) {
  383. $getMoneyBuyMth[$k]->match_date = $value->match_date;
  384. $getMoneyBuyMth[$k]->match_time = $value->match_time;
  385. $getMoneyBuyMth[$k]->lg_name = $value->name_chinese;
  386. }
  387. }
  388. }
  389. // 获取可加注所需要的查询条件
  390. $commonFunction = C() -> get('commonFunction');
  391. $stOddsWheres = [];
  392. foreach ($getMoneyBuyMth as $key => $value) {
  393. $match_id = $value -> match_id;
  394. $odds_code = $value -> odds_code;
  395. $gameType = $value -> game_code;
  396. $where = [
  397. 'match_id' => $match_id,
  398. 'odds_code' => $odds_code,
  399. ];
  400. // 判断是否重复
  401. if (!$commonFunction -> judgeEqual($where, $stOddsWheres[$gameType])) {
  402. $stOddsWheres[$gameType][] = $where;
  403. }
  404. }
  405. // 查询数据下所有可加注的游戏
  406. $stOddsModel = lm('stOdds','commons');
  407. $stOddsSelect = ['match_id', 'odds_code'];
  408. $getSstOdds = [];
  409. // 循环查询每个运动的可加注游戏 注:由于查询不同表所以必须循环查询
  410. foreach ($stOddsWheres as $key => $value) {
  411. if ($value) {
  412. $getSstOdds[$key] = $stOddsModel -> stOdds($stOddsSelect, $value, $key);
  413. }
  414. }
  415. // 循环添加玩法和判断玩法是否可加注
  416. foreach ($getMoneyBuyMth as $key => $value) {
  417. $typeSstOdds = $getSstOdds[$value -> game_code];
  418. $thisSstOdds = [
  419. 'match_id' => $value -> match_id,
  420. 'odds_code' => $value -> odds_code,
  421. ];
  422. // 判断如果在数组中则为可加注
  423. if (!!$commonFunction->judgeEqual($thisSstOdds, $typeSstOdds)) {
  424. $getMoneyBuyMth[$key] -> addBet = 0;
  425. } else {
  426. $getMoneyBuyMth[$key] -> addBet = 1;
  427. }
  428. }
  429. foreach ($getMoneyBuyStr as $key => $value) {
  430. // 计算所赢金额.
  431. if ($value->gain_money) {
  432. $getMoneyBuyStr[$key]->winMoney = $value->gain_money - $value->money;
  433. } else {
  434. $getMoneyBuyStr[$key]->winMoney = 0;
  435. }
  436. foreach ($getMoneyBuyMth as $k => $v) {
  437. if ($value['order_id'] == $v['order_id']) {
  438. $getMoneyBuyStr[$key]['money_buy'][] = $v;
  439. }
  440. }
  441. $getMoneyBuyStr[$key]->use_mark = $value['use_mark'];//处理备注
  442. if($value['settle_status'] > 1 and $value['order_status'] == 1){
  443. $getMoneyBuyStr[$key]->settle_status = 2;//结算状态 已结算
  444. }else if($value['settle_status'] == 1 and $value['order_status'] == 1){
  445. $getMoneyBuyStr[$key]->settle_status = 1;//结算状态 未结算
  446. }else if($value['order_status'] > 1){
  447. $getMoneyBuyStr[$key]->settle_status = -1;//结算状态 无效
  448. }
  449. }
  450. // 获取记录总数
  451. $result['total'] = $allCount;
  452. $result['list'] = $getMoneyBuyStr;
  453. // 总页数计算
  454. $result['countPage'] = ceil($result['total'] / $pageSize);
  455. $result['currentPage'] = $currentPage;
  456. return $result;
  457. }
  458. /**
  459. * 盈亏记录
  460. *
  461. * @access public
  462. * @return String
  463. */
  464. public function moneyRecord()
  465. {
  466. // 获取用户信息
  467. $accountManagerClass = new AccountManager;
  468. $userInfo = $accountManagerClass -> getCurrentUser();
  469. if (empty($userInfo['identity'])) {
  470. Render([], '2001', lang('Common','Api') -> get('user does login'));
  471. }
  472. $moneyRecordWhere = array();
  473. // 用户ID
  474. $moneyRecordWhere['account_identity'] = $userInfo['identity'];
  475. $moneyRecordWhere['status'] = 1;
  476. $moneyRecordWhere['settle_status'] = 2;
  477. if (empty($_POST['result']) === false) {
  478. $moneyRecordWhere['game_status'] = empty($_POST['result']);
  479. }
  480. // 时间区间
  481. $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
  482. $endTime = isset($_POST['endTime'])? $_POST['endTime'] : '3000-12-12 00:00:00';
  483. $moneyRecordBetween = [$startTime, $endTime];
  484. // 当前页
  485. $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
  486. // 分页大小
  487. $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
  488. // 起始查询位置
  489. $begin = ($currentPage - 1) * $pageSize;
  490. $moneyRecord = lm('Money_buy_simplex', "commons");
  491. $moneyRecordSelect = ['info_identity', 'trade_id', 'account_identity', 'money', 'money_time', 'money_type'];
  492. // 获取盈亏记录
  493. $result['list'] = $moneyRecord -> winLoseRecord($moneyRecordWhere, $moneyRecordBetween, $begin, $pageSize);
  494. // 获取记录总数
  495. $result['total'] = $moneyRecord -> winLoseCount($moneyRecordWhere, $moneyRecordBetween);
  496. // 总页数计算
  497. $result['countPage'] = ceil($result['total'] / $pageSize);
  498. $result['currentPage'] = $currentPage;
  499. return $result;
  500. }
  501. /**
  502. * 统计记录
  503. *
  504. * @access public
  505. * @return String
  506. */
  507. public function monthRecord()
  508. {
  509. $accountManagerClass = new AccountManager;
  510. $userInfo = $accountManagerClass -> getCurrentUser();
  511. if (empty($userInfo['identity'])) {
  512. Render([], '2001', lang('Common','Api') -> get('user does login'));
  513. }
  514. // 用户ID
  515. // $moneyBuyWhere['account_identity'] = $userInfo['identity'];
  516. // 时间区间
  517. $endTime = date('Y-m-d H:i:s');
  518. if ($userInfo['statisticsTime']) {
  519. $startTime = $userInfo['statisticsTime'];
  520. } else {
  521. $startTime = '1900-01-01 00:00:00';
  522. }
  523. // $moneyBuyBetween = [$startTime, $endTime];
  524. $moneyRecordWhere['settle_status'] = 2;
  525. $moneyBuyWhere = [
  526. ['account_identity','=',$userInfo['identity']],
  527. ['money_time','>',$startTime],
  528. ['money_time','<',$endTime],
  529. ];
  530. // 获取单式投注订单
  531. $moneyBuySimplex = lm('money_buy_simplex', "commons");
  532. $mnyBuySpxData = $moneyBuySimplex
  533. ->select(['order_id', 'money', 'gain_money', 'batch_id'])
  534. ->where($moneyBuyWhere)
  535. // ->whereBetween('settlementTime', $moneyBuyBetween)
  536. ->get()
  537. ->toArray();
  538. // 获取全部订单id
  539. $moneyBuyMthOr = [];
  540. $allBatchId = array_unique($mnyBuySpxData, SORT_REGULAR);
  541. if ($allBatchId) {
  542. foreach ($allBatchId as $key => $value) {
  543. $moneyBuyMthOr[0][$key][0] = 'batch_id';
  544. $moneyBuyMthOr[0][$key][1] = $value['batch_id'];
  545. }
  546. $moneyBuyMthWhere['bet_type'] = 1;
  547. // 获取注单
  548. $moneyBuyMthMdl = lm('Money_buy_match', "commons");
  549. $moneyBuyMthSlt = ['bet_money', 'odds', 'result'];
  550. $getMoneyBuyMth = $moneyBuyMthMdl -> moneyBuyMatchAll($moneyBuyMthSlt, $moneyBuyMthWhere, $moneyBuyMthOr);
  551. } else {
  552. $getMoneyBuyMth = [];
  553. }
  554. // 获取串式投注订单
  555. $moneyBuyStr = lm('money_buy_str', "commons");
  556. $mnyBuyStrData = $moneyBuyStr
  557. ->select(['order_id', 'money', 'gain_money'])
  558. ->where($moneyBuyWhere)
  559. // ->whereBetween('settlementTime', $moneyBuyBetween)
  560. ->get();
  561. $winMoney = $userInfo['allWin'];
  562. $loseMoney = $userInfo['allLose'];
  563. // 单式盈利.
  564. foreach ($getMoneyBuyMth as $key => $value) {
  565. // 判断订单是否盈利
  566. if ($value->result == 1) {
  567. $winMoney += $value->bet_money * $value->odds;
  568. } else if ($value->result == 3) {
  569. $winMoney += $value->bet_money * $value->odds * 0.5;
  570. } else if ($value->result == 4) {
  571. $loseMoney += $value->bet_money * 0.5;
  572. } else if ($value->result == -1) {
  573. $loseMoney += $value->bet_money;
  574. }
  575. }
  576. // 串式盈利.
  577. foreach ($mnyBuyStrData as $key => $value) {
  578. // 判断订单是否盈利
  579. if ($value->money >= $value->gain_money) {
  580. $loseMoney += $value->money - $value->gain_money; //本钱减回款
  581. } else {
  582. $winMoney += $value->gain_money - $value->money; //回款减本钱
  583. }
  584. }
  585. // 修改用户统计
  586. $updateActDtd = [
  587. 'allWin' => $winMoney,
  588. 'allLose' => $loseMoney,
  589. 'statisticsTime' => date('Y-m-d H:i:s'),
  590. ];
  591. $accountDetailed = lm('account_detailed', "commons");
  592. $accountDetailed->where(['account_identity'=>$userInfo['identity']])->update($updateActDtd);
  593. $result = [
  594. 'winMoney' => $winMoney ?? 0,
  595. 'loseMoney' => $loseMoney ?? 0,
  596. 'allMoney' => $userInfo['available_cash'],
  597. ];
  598. return $result;
  599. }
  600. }