diff --git a/Application/Sdk/Model/PayLimitConfModel.class.php b/Application/Sdk/Model/PayLimitConfModel.class.php new file mode 100644 index 00000000..0c320ca8 --- /dev/null +++ b/Application/Sdk/Model/PayLimitConfModel.class.php @@ -0,0 +1,183 @@ +tablePrefix ='tab_'; + /* 执行构造方法 */ + parent::__construct($name, $tablePrefix, $connection); + } + + // 累加充值金额 + 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(), + )); + } + } +} diff --git a/Application/Sdk/Model/ValueDetailLogModel.class.php b/Application/Sdk/Model/ValueDetailLogModel.class.php new file mode 100644 index 00000000..7fe94deb --- /dev/null +++ b/Application/Sdk/Model/ValueDetailLogModel.class.php @@ -0,0 +1,45 @@ +tablePrefix ='tab_'; + /* 执行构造方法 */ + parent::__construct($name, $tablePrefix, $connection); + } + + // 新增数值变动记录 + public function add($uid, $before, $value, $after, $type, $remark='', $payType=1) { + $this->add(array( + 'user_id' => $uid, + 'before_value' => $before, + 'value' => $value, + 'after_value' => $after, + 'create_time' => time(), + 'type' => $type, + 'remark' => $remark, + 'pay_type' => $payType + )); + } +}