diff --git a/Application/Common/Common/extend.php b/Application/Common/Common/extend.php index c397db41..50fc456e 100644 --- a/Application/Common/Common/extend.php +++ b/Application/Common/Common/extend.php @@ -1995,8 +1995,40 @@ function get_default_payment_config($way=1) { return ['code' => 0, 'msg' => '', 'data' => $merchant]; } +function getMasterPaymentMerchant($way) +{ + $conditions = []; + $conditions['_string'] = 'ways&' . $way . '=' . $way; + $conditions['status'] = 1; + $conditions['is_master'] = 1; + return M('payment_merchant', 'tab_')->where($conditions)->select(); +} + +function checkIsUserMasterMerchant($baseGame, $userId, $payAmount) +{ + $rule = M('game_master_merchant_rule', 'tab_')->where(['base_game_id' => $baseGame['id']])->find(); + if (empty($rule)) { + return false; + } + $count = M('spend', 'tab_')->where([ + 'game_id' => ['in', [$baseGame['android_game_id'], $baseGame['ios_game_id']]], + 'pay_status' => 1, + 'user_id' => $userId + ])->count(); + if ($rule['is_first_pay'] == 1 && $count == 0) { + return true; + } + if ($count <= $rule['max_times'] + ($rule['is_first_pay'] == 1 ? 1 : 0)) { + return true; + } + if ($payAmount <= $rule['max_pay_amount']) { + return true; + } + return false; +} + // 获取支付配置 way 1 支付宝 2微信 3快捷 -function get_payment_config($way=1, $game=0, $user_id=0) { +function get_payment_config($way=1, $game=0, $user_id=0, $payAmount = 0) { $time = time(); $company = get_promote_company($user_id); @@ -2009,13 +2041,21 @@ function get_payment_config($way=1, $game=0, $user_id=0) { $map['end_time'] = 0; $map['_logic'] = 'or'; - $baseGameId = M('base_game', 'tab_')->where([ + $baseGame = M('base_game', 'tab_')->where([ 'android_game_id|ios_game_id' => $game['id'] - ])->getField('id'); - if (!$baseGameId) { + ])->find(); + if (!$baseGame) { return ['code' => -3, 'msg' => '找不到游戏ID'.$game['id'], 'data' => []]; } + + if (checkIsUserMasterMerchant($baseGame, $user_id, $payAmount)) { + $payConf = getMasterPaymentMerchant($way); + if (!empty($payConf)) { + return ['code' => 0, 'msg' => '', 'data' => $payConf]; + } + } + $baseGameId = $baseGame['id']; $payment_rule = M('payment_rule', 'tab_')->where($map)->select(); $find_rule = false; $rule = array(); diff --git a/Application/Sdk/Controller/PayH5Controller.class.php b/Application/Sdk/Controller/PayH5Controller.class.php index 863fe0e3..54bbab65 100644 --- a/Application/Sdk/Controller/PayH5Controller.class.php +++ b/Application/Sdk/Controller/PayH5Controller.class.php @@ -68,7 +68,7 @@ class PayH5Controller extends BaseController{ } $game = M('game', 'tab_')->where(['id' => $game_id])->find(); - $pay_info = get_payment_config(self::ALI_PAY, $game, $request['user_id']); + $pay_info = get_payment_config(self::ALI_PAY, $game, $request['user_id'], $request['price']); if ($pay_info['code'] != 0) { echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]); exit; @@ -373,7 +373,7 @@ class PayH5Controller extends BaseController{ } $this->other_price($request, $discountAmount); - $pay_info = get_payment_config(self::ALI_PAY, $game, $request['user_id']); + $pay_info = get_payment_config(self::ALI_PAY, $game, $request['user_id'], $request['price']); if ($pay_info['code'] != 0) { echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]); exit; @@ -747,7 +747,7 @@ class PayH5Controller extends BaseController{ } $game = M('game', 'tab_')->where(['id' => $game_id])->find(); - $pay_info = get_payment_config(self::WX_PAY, $game, $request['user_id']); + $pay_info = get_payment_config(self::WX_PAY, $game, $request['user_id'], $request['price']); if ($pay_info['code'] != 0) { echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]); exit; @@ -1504,7 +1504,7 @@ class PayH5Controller extends BaseController{ $this->other_price($request, $discountAmount); $pay_amount = $request['price']; - $pay_info = get_payment_config(self::WX_PAY, $game, $request['user_id']); + $pay_info = get_payment_config(self::WX_PAY, $game, $request['user_id'], $request['price']); if ($pay_info['code'] != 0) { echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]); exit; diff --git a/Application/Sdk/Controller/ShortcutController.class.php b/Application/Sdk/Controller/ShortcutController.class.php index 38d42734..71654471 100644 --- a/Application/Sdk/Controller/ShortcutController.class.php +++ b/Application/Sdk/Controller/ShortcutController.class.php @@ -591,7 +591,7 @@ class ShortcutController extends BaseController{ } } - $pay_info = get_payment_config(PayH5Controller::EXPRESS_PAY, $game, I('request.user_id')); + $pay_info = get_payment_config(PayH5Controller::EXPRESS_PAY, $game, I('request.user_id'), $request['price']); if ($pay_info['code'] != 0) { echo json_encode(['code'=>1010,'msg'=> $pay_info['msg']]); exit;