tablePrefix ='tab_'; /* 执行构造方法 */ parent::__construct($name, $tablePrefix, $connection); } // 获取平台总流水 public function allTotal() { $total = M('game_data', 'tab_')->sum('pay_amount'); // var_dump("total:".$total); return $total ? $total : 0; } // 获取游戏总流水 public function gameTotal($gameId) { if (!$gameId) return 0; $gameTotal = M('game_data', 'tab_')->where(array('game_id' => $gameId))->sum('pay_amount'); // var_dump("game:".$gameTotal); return $gameTotal ? $gameTotal : 0; } // 获取玩家总流水 public function userTotal($userId) { if (!$userId) return 0; $userTotal = M('user_data', 'tab_')->where(array('user_id' => $userId))->getField('pay_amount'); // var_dump("userTotal:".$userTotal); return $userTotal ? $userTotal : 0; } /* // 累加充值金额 public function sum($userId, $price, $payType) { $now = date("His"); $nowDate = date('Ymd'); // 找出所有匹配的规则 时间范围满足的所有总流水限额 $limits = $this->where(array( 'start_time' => array('egt', $now), 'end_time' => array('lt', $now), 'pay_type' => $payType ))->select(); foreach ($limits as $k => $v) { $this->updateClearTime($v, $userId); // 清零 时间、限额 if ($v['limit_type'] == 'all_total' // 总流水 || ($v['limit_type'] == 'user_total' && $v['user_id'] == $userId) // 单玩家总流水 ) { $this->where(array( 'id' => $v['id'] ))->save(array( 'now_value' => $v['now_value'] + $price, 'update_time' => time(), )); } if ($v['limit_type'] == 'user_one' && $v['user_id'] == $userId) { // 单玩家单笔 } if ($v['limit_type'] == 'user_total' && $v['user_id'] == $userId) { // 单玩家总流水 } } } // 检查限额 如果超出返回false public function check($userId, $price, $payType) { $now = date("His"); $nowDate = date('Ymd'); // 找出所有匹配的规则 时间范围满足的所有总流水限额 $limits = $this->where(array( 'start_time' => array('egt', $now), 'end_time' => array('lt', $now), 'pay_type' => $payType ))->select(); foreach ($limits as $k => $v) { $this->updateClearTIme($v, $userId); if ($v['limit_type'] == 'all_total') { // 总流水 // 每日 每周 每月 if ($v['limit_time_type'] == "day" || $v['limit_time_type'] == "week" || $v['limit_time_type'] == "month") { if ($v['now_value'] + $price > $v['limit_value']) { return false; } } // 固定日期 if ($v['limit_time_type'] == 'fix') { if ($v['fix_date'] == $nowDate) { if ($v['now_value'] + $price > $v['limit_value']) { return false; } } } } if ($v['limit_type'] == 'user_one' && $v['user_id'] == $userId) { // 单玩家单笔 // 每日 每周 每月 if ($v['limit_time_type'] == "day" || $v['limit_time_type'] == "week" || $v['limit_time_type'] == "month") { if ($price > $v['limit_value']) { return false; } } // 固定日期 if ($v['limit_time_type'] == 'fix') { if ($v['fix_date'] == $nowDate) { if ($price > $v['limit_value']) { return false; } } } } if ($v['limit_type'] == 'user_total' && $v['user_id'] == $userId) { // 单玩家总流水 // 每日 每周 每月 if ($v['limit_time_type'] == "day" || $v['limit_time_type'] == "week" || $v['limit_time_type'] == "month") { if ($v['now_value'] + $price > $v['limit_value']) { return false; } } // 固定日期 if ($v['limit_time_type'] == 'fix') { if ($v['fix_date'] == $nowDate) { if ($v['now_value'] + $price > $v['limit_value']) { return false; } } } } } } // 更新清零时间 private function updateClearTIme($conf, $userId) { if (!$conf) return; $data = array(); $startTime = substr($conf['start_time'], 0, 2) * 3600; $startTime += substr($conf['start_time'], 2, 2) * 60; $startTime += substr($conf['start_time'], 4, 2); $isClear = false; if ($conf['limit_time_type'] == 'day') { $startTime += strtotime(date('Ymd')); // 清零时间小于开始时间 需要清零 if ($conf['clear_time'] < $startTime) { $isClear = true; } } if ($conf['limit_time_type'] == 'week') { $week_now = date("w")-1; $week_start= strtotime("-{$week_now} days",time()); $startTime += $week_start; // 清零时间小于开始时间 需要清零 if ($conf['clear_time'] < $startTime) { $isClear = true; } } if ($conf['limit_time_type'] == 'month') { $startTime += strtotime(date('Ym')); // 清零时间小于开始时间 需要清零 if ($conf['clear_time'] < $startTime) { $isClear = true; } } if ($isClear) { $this->where(array( 'id' => $conf['id'] ))->save(array( 'now_value' => 0, 'clear_time' => time(), )); } } */ /** * return 0 通过 1障碍 2限制 3参数有误 * {@inheritDoc} * @see \Think\Model::check() */ public function check($userId, $price, $payType, $orderId, $gameId=0) { if (!$userId || !$price || !$payType || !$orderId) { return 3; } // 如果是白名单的用户 不走限制 $userPayWhitelist = new UserPayWhitelistModel(); if ($userPayWhitelist->verify($userId)) { return 0; } $now = date("His"); $nowDate = date('Ymd'); $nowWeekNum = date('w'); $nowDateNum = (int)substr($nowDate, -2); // 找出所有匹配的规则 时间范围满足的所有总流水限额 $limits = $this->where(array( 'start_time' => array('elt', $now), 'end_time' => array('gt', $now), 'pay_type' => $payType ))->select(); if (!$limits) return 0; $result = 0; // 处理在这个时间段内的限制 foreach ($limits as $k => $v) { // 每日 每周 每月 固定时间 if ($v['limit_time_type'] == "day" || $v['limit_time_type'] == "week" || $v['limit_time_type'] == "month" || ($v['limit_time_type'] == 'fix' && $v['fix_date'] == $nowDate)) { if ($v['limit_time_type'] == "week" && $nowWeekNum != $v['limit_time_type_remark']) { continue; } if ($v['limit_time_type'] == "month" && $nowDateNum != $v['limit_time_type_remark']) { continue; } // 总流水 if ($v['total_limit'] > 0 && $this->allTotal() > $v['total_limit']) { if ($v['limit_type'] == "force") return 2; if ($v['limit_type'] == "obstacles") { // 障碍 第二次就可以支付 if (/* $this->enterCount($payType, $orderId) >= 2 && */$this->paySubmitCount($payType, $orderId) >= 1) { $result = 0; } else { return 1; } } } // 单玩家总流水 if ($v['user_total_limit'] > 0 && $this->userTotal($userId) > $v['user_total_limit']) { if ($v['limit_type'] == "force") return 2; if ($v['limit_type'] == "obstacles") { // 障碍 第二次就可以支付 if (/* $this->enterCount($payType, $orderId) >= 2 && */$this->paySubmitCount($payType, $orderId) >= 1) { $result = 0; } else { return 1; // 障碍 } } } // 单笔限额 if ($v['user_one_limit'] > 0 && $price >= $v['user_one_limit']) { if ($v['limit_type'] == "force") return 2; if ($v['limit_type'] == "obstacles") { // 障碍 第二次就可以支付 if (/* $this->enterCount($payType, $orderId) >= 2 && */$this->paySubmitCount($payType, $orderId) >= 1) { $result = 0; } else { return 1; // 障碍 } } } } } return $result; } // 支付方式 进入次数 private function enterCount($payType, $orderId) { $cnt = M('pay_channel_intention', 'tab_')->where(array( 'pay_way' => $payType, 'pay_order_number' => $orderId, ))->count(); return $cnt ? $cnt : 0; } // 提交支付次数 private function paySubmitCount($payType, $orderId) { $cnt = M('pay_channel_intention', 'tab_')->where(array( 'pay_way' => $payType, 'pay_order_number' => $orderId, 'is_submit' => 1 ))->count(); return $cnt ? $cnt : 0; } }