MoneyBuy.php 26 KB

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