MoneyBuy.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. // 用户ID
  72. $moneyBuySpxWhere['account_identity'] = $userInfo['identity'];
  73. // 时间区间
  74. $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
  75. $endTime = isset($_POST['endTime'])? $_POST['endTime'] : '3000-12-12 00:00:00';
  76. $moneyBuySpxBetween = ['money_time' => [$startTime, $endTime]];
  77. $moneyBuySpxMdl = lm('money_buy_simplex', "commons");
  78. // 获取订单记录
  79. $moneyBuySpxSlt = ['batch_id'];
  80. $getMoneyBuySpx = $moneyBuySpxMdl -> moneyBuySimplex($moneyBuySpxSlt, $moneyBuySpxWhere, $moneyBuySpxBetween, '', '', 1);
  81. // 获取全部订单id
  82. $moneyBuyMthOr = [];
  83. $allBatchId = array_unique($getMoneyBuySpx, SORT_REGULAR);
  84. foreach ($allBatchId as $key => $value) {
  85. $moneyBuyMthOr[0][$key][0] = 'batch_id';
  86. $moneyBuyMthOr[0][$key][1] = $value['batch_id'];
  87. }
  88. $moneyBuyMthWhere['bet_type'] = 1;
  89. // 输赢
  90. if (!empty($_POST['result']) && $_POST['result'] == 1) {
  91. $moneyBuyMthOr[1][0][0] = 'result';
  92. $moneyBuyMthOr[1][0][1] = 1;
  93. $moneyBuyMthOr[1][1][0] = 'result';
  94. $moneyBuyMthOr[1][1][1] = 3;
  95. $moneyBuyMthOr[1][2][0] = 'result';
  96. $moneyBuyMthOr[1][2][1] = 2;
  97. } elseif (!empty($_POST['result']) && $_POST['result'] == 2) {
  98. $moneyBuyMthOr[1][0][0] = 'result';
  99. $moneyBuyMthOr[1][0][1] = -1;
  100. $moneyBuyMthOr[1][1][0] = 'result';
  101. $moneyBuyMthOr[1][1][1] = 4;
  102. }
  103. // 当前页
  104. $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
  105. // 分页大小
  106. $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
  107. // 起始查询位置
  108. $begin = ($currentPage - 1) * $pageSize;
  109. // 获取注单
  110. $moneyBuyMthMdl = lm('Money_buy_match', "commons");
  111. $moneyBuyMthSlt = ['status', 'bet_money', 'home_team', 'guest_team', 'condition', 'odds', 'odds_name', 'match_id', 'game_type', 'money_buy_match.odds_code'];
  112. $getMoneyBuyMth = $moneyBuyMthMdl -> moneyBuyMatch($moneyBuyMthSlt, $moneyBuyMthWhere, $moneyBuyMthOr, $begin, $pageSize);
  113. $allCount = $moneyBuyMthMdl -> moneyBuyMatchTotal($moneyBuyMthWhere, $moneyBuyMthOr);
  114. // 获取可加注所需要的查询条件
  115. $commonFunction = C() -> get('commonFunction');
  116. $stOddsWheres = [];
  117. foreach ($getMoneyBuyMth as $key => $value) {
  118. $match_id = $value -> match_id;
  119. $odds_code = $value -> odds_code;
  120. $gameType = $value -> game_type;
  121. $where = [
  122. 'match_id' => $match_id,
  123. 'odds_code' => $odds_code,
  124. ];
  125. // 判断是否重复
  126. if (!$commonFunction -> judgeEqual($where, $stOddsWheres[$gameType])) {
  127. $stOddsWheres[$gameType][] = $where;
  128. }
  129. }
  130. // 查询数据下所有可加注的游戏
  131. $stOddsModel = lm('stOdds','commons');
  132. $stOddsSelect = ['match_id', 'odds_code'];
  133. $getSstOdds = [];
  134. // 循环查询每个运动的可加注游戏 注:由于查询不同表所以必须循环查询
  135. foreach ($stOddsWheres as $key => $value) {
  136. if ($value) {
  137. $getSstOdds[$key] = $stOddsModel -> stOdds($stOddsSelect, $value, $key);
  138. }
  139. }
  140. // 循环添加玩法和判断玩法是否可加注
  141. foreach ($getMoneyBuyMth as $key => $value) {
  142. $typeSstOdds = $getSstOdds[$value -> game_type];
  143. $thisSstOdds = [
  144. 'match_id' => $value -> match_id,
  145. 'odds_code' => $value -> odds_code,
  146. ];
  147. // 判断如果在数组中则为可加注
  148. if (!!$commonFunction->judgeEqual($thisSstOdds, $typeSstOdds)) {
  149. $getMoneyBuyMth[$key] -> addBet = 0;
  150. } else {
  151. $getMoneyBuyMth[$key] -> addBet = 1;
  152. }
  153. }
  154. // 获取记录总数
  155. $result['total'] = $allCount;
  156. $result['list'] = $getMoneyBuyMth;
  157. // 总页数计算
  158. $result['countPage'] = ceil($result['total'] / $pageSize);
  159. $result['currentPage'] = $currentPage;
  160. return $result;
  161. }
  162. /**
  163. * 串式投注记录
  164. *
  165. * @access public
  166. * @return String
  167. */
  168. public function stringBetRecord()
  169. {
  170. // 获取用户信息
  171. $accountManagerClass = new AccountManager;
  172. $userInfo = $accountManagerClass -> getCurrentUser();
  173. if (empty($userInfo['identity'])) {
  174. Render([], '2001', lang('Common','Api') -> get('user does login'));
  175. }
  176. // 用户ID
  177. $moneyBuyStrWhere['account_identity'] = $userInfo['identity'];
  178. // 输赢
  179. if (!empty($_POST['result'])) {
  180. $moneyBuyStrWhere['game_status'] = $_POST['result'];
  181. }
  182. // 时间区间
  183. $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
  184. $endTime = isset($_POST['endTime'])? $_POST['endTime'] : '3000-12-12 00:00:00';
  185. $moneyBuyStrBetween = ['money_time' => [$startTime, $endTime]];
  186. $moneyBuyStrMdl = lm('money_buy_str', "commons");
  187. // 当前页
  188. $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
  189. // 分页大小
  190. $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
  191. // 起始查询位置
  192. $begin = ($currentPage - 1) * $pageSize;
  193. // 获取订单记录
  194. $moneyBuyStrSlt = ['batch_id', 'money'];
  195. $getMoneyBuyStr = $moneyBuyStrMdl -> moneyBuyStr($moneyBuyStrSlt, $moneyBuyStrWhere, $moneyBuyStrBetween, $begin, $pageSize, 1);
  196. $allCount = $moneyBuyStrMdl -> moneyBuyStrTotal($moneyBuyStrWhere, $moneyBuyStrBetween);
  197. // 获取全部订单id
  198. $moneyBuyMthOr = [];
  199. $allBatchId = array_unique($getMoneyBuyStr, SORT_REGULAR);
  200. foreach ($allBatchId as $key => $value) {
  201. $moneyBuyMthOr[0][$key][0] = 'batch_id';
  202. $moneyBuyMthOr[0][$key][1] = $value['batch_id'];
  203. }
  204. $moneyBuyMthWhere['bet_type'] = 2;
  205. // 获取注单
  206. $moneyBuyMthMdl = lm('Money_buy_match', "commons");
  207. $moneyBuyMthSlt = ['status', 'bet_money', 'home_team', 'guest_team', 'condition', 'odds', 'odds_name', 'match_id', 'batch_id', 'game_type', 'money_buy_match.odds_code'];
  208. $getMoneyBuyMth = $moneyBuyMthMdl -> moneyBuyMatch($moneyBuyMthSlt, $moneyBuyMthWhere, $moneyBuyMthOr, $begin, $pageSize);
  209. // 获取可加注所需要的查询条件
  210. $commonFunction = C() -> get('commonFunction');
  211. $stOddsWheres = [];
  212. foreach ($getMoneyBuyMth as $key => $value) {
  213. $match_id = $value -> match_id;
  214. $odds_code = $value -> odds_code;
  215. $gameType = $value -> game_type;
  216. $where = [
  217. 'match_id' => $match_id,
  218. 'odds_code' => $odds_code,
  219. ];
  220. // 判断是否重复
  221. if (!$commonFunction -> judgeEqual($where, $stOddsWheres[$gameType])) {
  222. $stOddsWheres[$gameType][] = $where;
  223. }
  224. }
  225. // 查询数据下所有可加注的游戏
  226. $stOddsModel = lm('stOdds','commons');
  227. $stOddsSelect = ['match_id', 'odds_code'];
  228. $getSstOdds = [];
  229. // 循环查询每个运动的可加注游戏 注:由于查询不同表所以必须循环查询
  230. foreach ($stOddsWheres as $key => $value) {
  231. if ($value) {
  232. $getSstOdds[$key] = $stOddsModel -> stOdds($stOddsSelect, $value, $key);
  233. }
  234. }
  235. // 循环添加玩法和判断玩法是否可加注
  236. foreach ($getMoneyBuyMth as $key => $value) {
  237. $typeSstOdds = $getSstOdds[$value -> game_type];
  238. $thisSstOdds = [
  239. 'match_id' => $value -> match_id,
  240. 'odds_code' => $value -> odds_code,
  241. ];
  242. // 判断如果在数组中则为可加注
  243. if (!!$commonFunction->judgeEqual($thisSstOdds, $typeSstOdds)) {
  244. $getMoneyBuyMth[$key] -> addBet = 0;
  245. } else {
  246. $getMoneyBuyMth[$key] -> addBet = 1;
  247. }
  248. }
  249. foreach ($getMoneyBuyStr as $key => $value) {
  250. foreach ($getMoneyBuyMth as $k => $v) {
  251. if ($value['batch_id'] == $v['batch_id']) {
  252. $getMoneyBuyStr[$key]['money_buy'][$k] = $v;
  253. }
  254. }
  255. }
  256. // 获取记录总数
  257. $result['total'] = $allCount;
  258. $result['list'] = $getMoneyBuyStr;
  259. // 总页数计算
  260. $result['countPage'] = ceil($result['total'] / $pageSize);
  261. $result['currentPage'] = $currentPage;
  262. return $result;
  263. }
  264. /**
  265. * 盈亏记录
  266. *
  267. * @access public
  268. * @return String
  269. */
  270. public function moneyRecord()
  271. {
  272. // 获取用户信息
  273. $accountManagerClass = new AccountManager;
  274. $userInfo = $accountManagerClass -> getCurrentUser();
  275. if (empty($userInfo['identity'])) {
  276. Render([], '2001', lang('Common','Api') -> get('user does login'));
  277. }
  278. $moneyRecordWhere = array();
  279. // 用户ID
  280. $moneyRecordWhere['account_identity'] = $userInfo['identity'];
  281. $moneyRecordWhere['status'] = 1;
  282. // 时间区间
  283. $startTime = isset($_POST['startTime'])? $_POST['startTime'] : '1900-01-01 00:00:00';
  284. $endTime = isset($_POST['endTime'])? $_POST['endTime'] : '3000-12-12 00:00:00';
  285. $moneyRecordBetween = [$startTime, $endTime];
  286. // 当前页
  287. $currentPage = isset($_POST['currentPage']) ? $_POST['currentPage'] : "1";
  288. // 分页大小
  289. $pageSize = isset($_POST['pageSize']) ? $_POST['pageSize'] : "10";
  290. // 起始查询位置
  291. $begin = ($currentPage - 1) * $pageSize;
  292. $moneyRecord = lm('money_record', "commons");
  293. $moneyRecordSelect = ['info_identity', 'trade_id', 'account_identity', 'money', 'money_time', 'money_type'];
  294. // 获取盈亏记录
  295. $result['list'] = $moneyRecord -> moneyRecord($moneyRecordSelect, $moneyRecordWhere, $moneyRecordBetween, $begin, $pageSize);
  296. // 获取记录总数
  297. $result['total'] = $moneyRecord -> moneyRecordTotal($moneyRecordWhere, $moneyRecordBetween);
  298. // 总页数计算
  299. $result['countPage'] = ceil($result['total'] / $pageSize);
  300. $result['currentPage'] = $currentPage;
  301. return $result;
  302. }
  303. }