MoneyBuy.php 28 KB

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