From c3a8f6b5084b86f57d996e4b8e2f0c72039d195e Mon Sep 17 00:00:00 2001
From: tpingzhang <635929049@qq.com>
Date: Sun, 29 Sep 2019 15:51:27 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=85=88=E6=89=A3=E9=99=A4=E7=BB=91?=
=?UTF-8?q?=E5=B8=81=E3=80=81=E5=B9=B3=E5=8F=B0=E5=B8=81=20=E8=B6=85?=
=?UTF-8?q?=E7=BA=A7=E7=AD=BE=20=E5=85=BC=E5=AE=B9=E5=BA=94=E7=94=A8?=
=?UTF-8?q?=E5=86=85=E5=BA=94=E7=94=A8=E5=A4=96=E8=B7=B3=E8=BD=AC?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Controller/BaseController.class.php | 210 ++++++++
.../Controller/NotifyController.class.php | 8 +-
Application/Sdk/Conf/config.php | 1 +
.../Sdk/Controller/AppleController.class.php | 131 ++++-
.../Sdk/Controller/Ipa365Controller.class.php | 64 ++-
.../Sdk/Controller/PayController.class.php | 94 +++-
.../Sdk/Controller/SpendController.class.php | 32 +-
.../Sdk/Controller/WapPayController.class.php | 34 +-
Application/Sdk/View/default/Ipa365/pay.html | 8 +-
.../Sdk/View/default/Ipa365/paytip.html | 12 +-
.../Sdk/View/default/Spend/pay_success.html | 96 +++-
.../Sdk/View/default/Spend/pay_success2.html | 61 ++-
.../Sdk/View/default/Spend/pay_way.html | 481 +++++++++---------
Public/Sdk/css/weui.min.css | 5 +
Public/Sdk/images/alipay.png | Bin 0 -> 6187 bytes
Public/Sdk/images/cardpay.png | Bin 0 -> 18909 bytes
Public/Sdk/images/onlinepay.png | Bin 0 -> 4081 bytes
Public/Sdk/images/wxpay.png | Bin 0 -> 10164 bytes
Public/Sdk/js/flex.min.js | 1 +
ThinkPHP/Library/Think/Pay.class.php | 10 +-
20 files changed, 923 insertions(+), 325 deletions(-)
create mode 100644 Public/Sdk/css/weui.min.css
create mode 100644 Public/Sdk/images/alipay.png
create mode 100644 Public/Sdk/images/cardpay.png
create mode 100644 Public/Sdk/images/onlinepay.png
create mode 100644 Public/Sdk/images/wxpay.png
create mode 100644 Public/Sdk/js/flex.min.js
diff --git a/Application/Callback/Controller/BaseController.class.php b/Application/Callback/Controller/BaseController.class.php
index 65b29bbda..6aa04e2cf 100644
--- a/Application/Callback/Controller/BaseController.class.php
+++ b/Application/Callback/Controller/BaseController.class.php
@@ -4,6 +4,7 @@ namespace Callback\Controller;
use Think\Controller;
use Common\Api\GameApi;
use Org\UcenterSDK\Ucservice;
+use Think\Log;
/**
* 支付回调控制器
* @author 小纯洁
@@ -54,6 +55,7 @@ class BaseController extends Controller {
$spend = M('Spend',"tab_");
$map['pay_order_number'] = $data['out_trade_no'];
$d = $spend->where($map)->find();
+
if(empty($d)){$this->record_logs("数据异常");return false;}
// 支付金额判断 by zgc
if ($d['pay_amount'] != $data['money']) {
@@ -61,6 +63,63 @@ class BaseController extends Controller {
}
if($d['pay_status'] == 0){
+ // 处理绑币平台币优先处理
+ if ($d['deduction_amount'] > 0) {
+ $out_trade_no = "PF_" . date('Ymd') . date('His') . sp_random_string(4);
+
+ $bind_balance = M('user_play', 'tab_')->where(array(
+ 'user_id' => $d['user_id'],
+ 'game_id' => $d['game_id']
+ ))->getField('bind_balance');
+ $request = $d;
+ $request['pay_order_number'] = $out_trade_no;
+ $request['price'] = $bind_balance;
+ $request['deduction_amount'] = 0;
+ $request['pay_way'] = -1;
+ $request['pay_status'] = 1;
+
+ if ($d['deduction_amount'] > $bind_balance)
+ $bb = 0;
+ else
+ $bb = $bind_balance - $d['deduction_amount'];
+
+ if ($bind_balance > 0) {
+ M('user_play', 'tab_')->where(array(
+ 'user_id' => $d['user_id'],
+ 'game_id' => $d['game_id']
+ ))->save(array(
+ 'bind_balance' => $bb
+ ));
+
+ $result = $this->add_spend($request);
+ $this->set_ratio($request['pay_order_number'], 2); // 游戏返利
+ }
+
+ if ($bb == 0) {
+ $mbalance = $d['deduction_amount'] - $bind_balance;
+ if ($mbalance > 0) {
+ $request['pay_way'] = 0;
+ $request['pay_order_number'] = $request['pay_order_number']."_1";
+ $request['price'] = $mbalance;
+ $balance = M('user', 'tab_')->where(array(
+ 'id' => $d['user_id'],
+ ))->getField('balance');
+
+ if ($balance < $mbalance) { // 异常
+ $this->record_logs($mbalance."平台币余额不足".$balance);return false;
+ }
+ M('user', 'tab_')->where(array(
+ 'id' => $d['user_id']
+ ))->save(array(
+ 'balance' => $balance - $mbalance,
+ ));
+ $result = $this->add_spend($request);
+ $this->set_ratio($request['pay_order_number'], 2); // 游戏返利
+ }
+ }
+
+ }
+
$data_save['pay_status'] = 1;
$data_save['order_number'] = $data['trade_no'];
$map_s['pay_order_number'] = $data['out_trade_no'];
@@ -464,4 +523,155 @@ class BaseController extends Controller {
fwrite($myfile, $txt);
fclose($myfile);
}
+
+ /**
+ *消费表添加数据
+ */
+ public function add_spend($data,$type=0){
+ $spend = M("spend","tab_");
+ $spend_data = $this->spend_param($data);
+ $ordercheck = $spend->where(array('pay_order_number'=>$spend_data["pay_order_number"]))->find();
+ if($ordercheck)
+ {
+ if($type==1){
+ redirect(U('Spend/notice',array('user_id'=>$ordercheck['user_id'],'game_id'=>$ordercheck['game_id'],'msg'=>'订单已经存在,请刷新充值页面重新下单!')));exit;
+ }else{
+ $this->set_message(0,'fail',"订单已经存在,请刷新充值页面重新下单!");
+ }
+ }
+ // if(!is_check_apply_promote($spend_data['game_id'],$spend_data['promote_id'])){
+ // $spend_data['promote_id']=0;
+ // $spend_data['promote_account']="自然注册";
+ // }
+ $result = $spend->add($spend_data);
+ return $result;
+ }
+
+ /**
+ *消费记录表 参数
+ */
+ private function spend_param($param=array()){
+ $user_entity = get_user_entity($param['user_id']);
+ $data_spned['user_id'] = $param["user_id"];
+ $data_spned['user_account'] = $user_entity["account"];
+ $data_spned['user_nickname'] = $user_entity["nickname"];
+ $data_spned['game_id'] = $param["game_id"];
+ $data_spned['game_appid'] = $param["game_appid"];
+ $data_spned['game_name'] = get_game_name($param["game_id"]);
+ $data_spned['selle_ratio'] = get_game_selle_ratio($param["game_id"]);
+ $data_spned['server_id'] = $param["server_id"];
+ $data_spned['server_name'] = $param["server_name"];
+ $data_spned['game_player_name'] = $param["game_player_name"];
+ $data_spned['promote_id'] = $user_entity["promote_id"];
+ $data_spned['promote_account'] = $user_entity["promote_account"];
+ $data_spned['order_number'] = $param["order_number"];
+ $data_spned['pay_order_number'] = $param["pay_order_number"];
+ $data_spned['props_name'] = $param["title"];
+ $data_spned['cost'] = $param["price"];//原价
+ $data_spned['deduction_amount'] = $param["deduction_amount"];// 抵扣价格
+ $data_spned['discount_amount'] = $param["discount_amount"];// 折扣价格
+ $data_spned['pay_time'] = NOW_TIME;
+ $data_spned['pay_status'] = $param["pay_status"];
+ $data_spned['pay_game_status'] = 0;
+ $data_spned['extend'] = $param['extend'];
+ $data_spned['pay_way'] = $param["pay_way"];
+ if($data_spned['pay_way'] != 7){
+ $discount = $this->get_discount($param['game_id'],$user_entity['promote_id'],$param['user_id']);
+ $data_spned['pay_amount'] = $param["price"] * $discount['discount']/10;//实付金额
+ $data_spned['discount_type'] = $discount['discount_type'];
+ }else{//苹果支付不计入折扣
+ $data_spned['pay_amount'] = $param["price"];
+ $data_spned['discount_type'] = 0;
+ }
+ if (isset($param['actual_amount']) && $param['actual_amount'])
+ $data_spned['pay_amount'] = $param['actual_amount']; // 实际支付价格
+ $data_spned['spend_ip'] = $param["spend_ip"];
+ $data_spned['sdk_version'] = $param["sdk_version"];
+ if($param['small_user_id'] != $param['user_id']) {
+ $data_spned['small_id'] = $param["small_user_id"];
+ $data_spned['small_account'] = get_user_account_by_id($param['small_user_id']);
+ }
+ return $data_spned;
+ }
+
+ /**
+ * 获取用户折扣
+ * @param $game_id 游戏ID
+ * @param $promote_id 渠道ID
+ * @param $user_id 用户ID
+ * @return mixed
+ */
+ protected function get_discount($game_id,$promote_id,$user_id){
+ //获取折扣
+ $map['game_id'] = $game_id;
+ $map['promote_id'] =-1;
+ $map['status'] = 2;
+ $discount = M('Promote_welfare','tab_')->where($map)->find();
+ if(null==$discount){
+ $map['game_id'] = $game_id;
+ $map['promote_id'] = $promote_id == 0 ? 0 : -2;
+ $map['status'] = 2;
+ $discount = M('Promote_welfare','tab_')->where($map)->find();
+ }
+ $discount = discount_data($discount);
+ if(empty($discount)){
+ $res['discount'] = 10;
+ $res['discount_type'] = 0;//无折扣
+ return $res;
+ }
+
+ //判断用户是否为首冲
+ $where['game_id'] = $game_id;
+ $where['user_id'] = $user_id;
+ $where['pay_status'] = 1;
+ $data = M('bind_spend','tab_')->where($where)->find();
+ if(!empty($data) || !empty(M('spend','tab_')->where($where)->find())){
+ $res['discount'] = $discount['continue_discount'];//续冲
+ $res['discount_type'] = 2;
+ }else{
+ $res['discount'] = $discount['first_discount'];//首冲
+ $res['discount_type'] = 1;
+ }
+ return $res;
+ }
+
+ /**
+ *游戏返利
+ *$type 类型 1 非绑定平台币 2绑定平台币
+ */
+ /* public function set_ratio($data,$type = 1){
+ $map['pay_order_number']=$data;
+ $map['pay_way'] = ($type==2) ? -1 : 0; // 判断支付类型
+ $spend=M("Spend","tab_")->where($map)->find();
+ $reb_map['game_id']=$spend['game_id'];
+ $time = time();
+ $reb_map['starttime'] = ['lt',$time];
+ $reb_map_str = "endtime > {$time} or endtime = 0";
+ switch ($spend['promote_id']) {
+ case 0:
+ $reb_map['promote_id'] = array('in','0,-1');
+ break;
+ default:
+ $reb_map['promote_id'] = array('in','1,-1');
+ break;
+ }
+
+
+ //如果是绑币则判断是否开启绑币返利
+ if($type == 2){$reb_map['bind_status'] = 1;}
+ $rebate=M("Rebate","tab_")->where($reb_map)->where($reb_map_str)->find();//
+ if (!empty($rebate)) {
+ if($rebate['money']>0 && $rebate['status']==1){
+ if($spend['pay_amount']>=$rebate['money']){
+ $this->compute($spend,$rebate);
+ }else{
+ return false;
+ }
+ }else{
+ $this->compute($spend,$rebate);
+ }
+ }else{
+ return false;
+ }
+ } */
}
\ No newline at end of file
diff --git a/Application/Callback/Controller/NotifyController.class.php b/Application/Callback/Controller/NotifyController.class.php
index ee8fdda34..e0612e4d9 100644
--- a/Application/Callback/Controller/NotifyController.class.php
+++ b/Application/Callback/Controller/NotifyController.class.php
@@ -15,15 +15,12 @@ use Sdk\Controller\Ipa365Controller;
*/
class NotifyController extends BaseController
{
-
/**
*通知方法
*/
public function notify()
-
{
-
C(api('Config/lists'));
$apitype = I('get.apitype');#获取支付api类型
@@ -61,14 +58,13 @@ class NotifyController extends BaseController
if ($apitype == "swiftpass") {
$apitype = "weixin";
}
-
$pay = new \Think\Pay($pay_way, C($apitype));
if ($pay->verifyNotify($notify)) {
//获取回调订单信息
$order_info = $pay->getInfo();
-
+Log::write(serialize($order_info), Log::DEBUG);
if ($order_info['status']) {
$pay_where = substr($order_info['out_trade_no'], 0, 2);
@@ -96,7 +92,7 @@ class NotifyController extends BaseController
case 'TB':
$result = $this->set_balance($order_info);
- $to_balance = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/Home/PromoteCoin/lists';
+ $to_balance = 'http://' . $_SERVER['HTTP_HOST'] . '/index.php/Home/PromoteCoin/lists';
break;
case 'BR':
diff --git a/Application/Sdk/Conf/config.php b/Application/Sdk/Conf/config.php
index 1683c2f10..6ca9ed729 100644
--- a/Application/Sdk/Conf/config.php
+++ b/Application/Sdk/Conf/config.php
@@ -110,4 +110,5 @@ return array(
'SQ_UNION' => 10,
'SQ_SHORTCUT' => 15
),
+ 'WX_PAY_LIMIT' => 3000, // 微信支付限额
);
diff --git a/Application/Sdk/Controller/AppleController.class.php b/Application/Sdk/Controller/AppleController.class.php
index 3455d74fc..448552daa 100644
--- a/Application/Sdk/Controller/AppleController.class.php
+++ b/Application/Sdk/Controller/AppleController.class.php
@@ -92,7 +92,14 @@ class AppleController extends BaseController{
$request = json_decode(think_decrypt($file),true);
C(api('Config/lists'));
-
+ /*$request['user_id'] = 1;
+ $request['game_id'] = 1;
+ $request['price'] = 1.01;
+ $request['extend'] = 21111183;
+ $request['pay_order_number'] = 21111183;
+ $request['sdk_version'] = 2;
+ $request['code'] =1;
+ */
if (empty($request)) {
echo json_encode(['code'=>0,'msg'=>'登录数据不能为空']);exit;
}
@@ -114,6 +121,8 @@ class AppleController extends BaseController{
if($extend_data){
echo json_encode(['code'=>0,'msg'=>'订单号重复,请关闭支付页面重新支付']);exit;
}
+
+ $this->other_price($request);
if(get_zfb_type()==0){ // 支付宝官方
if(C('alipay.way')==1 || ($request['is_create_ordernumer']==1 && C('alipay.way')==0)){/* wap */
@@ -126,8 +135,8 @@ class AppleController extends BaseController{
$request['payway'] = 1;
$request['title']=$request['price'];
$request['body']=$request['price'];
- $request['callback'] = 'http://'.$_SERVER['HTTP_HOST']. "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
- $request['notifyurl'] = 'http://'.$_SERVER['HTTP_HOST']. "/callback.php/Notify/notify/apitype/alipay/method/notify";
+ //$request['callback'] = 'http://'.$_SERVER['HTTP_HOST']. "/sdk.php/Spend/pay_success/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
+ //$request['notifyurl'] = 'http://'.$_SERVER['HTTP_HOST']. "/callback.php/Notify/notify/apitype/alipay/method/notify";
$pay_url=$this->pay($request);
//echo $pay_url['url'];die;
//redirect($pay_url['url']);
@@ -333,7 +342,7 @@ class AppleController extends BaseController{
if($param['is_uc']==1){
return $pay->buildRequestForm($vo,1);
}else{
- $pay_['url']= $pay->buildRequestForm($vo);
+ $pay_['url']= $pay->buildRequestForm($vo, 0, $param);
$pay_['out_trade_no']= $out_trade_no;
return $pay_;
}
@@ -347,10 +356,10 @@ class AppleController extends BaseController{
$request = json_decode(think_decrypt($file),true);
/*$request['user_id'] = 1;
$request['game_id'] = 1;
- $request['price'] = 0.01;
- $request['extend'] = 21111177;
- $request['pay_order_number'] = 21111177;
-
+ $request['price'] = 157.01;
+ $request['extend'] = 21111178;
+ $request['pay_order_number'] = 21111178;
+ $request['sdk_version'] = 2;
$request['code'] =1;
*/
if (empty($request)) {
@@ -358,7 +367,7 @@ class AppleController extends BaseController{
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'登录数据不能为空')));exit;
}
// 支付验证 是否让支付
- $payCheck = pay_check($request['user_id']);
+ $payCheck = pay_check($user_id);
if (!$payCheck['code']) {
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=> $payCheck['msg'])));exit;
}
@@ -367,10 +376,9 @@ class AppleController extends BaseController{
if($game['pay_status'] == 0){
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'该游戏暂时无法充值,请联系客服!')));exit;
}
- if($request['price']*1<=0){
+ if($request['price']*1<=0 || $request['price'] > C('WX_PAY_LIMIT')) {
// $this->set_message(0,"fail","充值金额有误");
redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误')));exit;
-
}
$extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'game_id'=>$request['game_id'],'game_status'=>1))->find();
if($extend_data){
@@ -387,7 +395,10 @@ class AppleController extends BaseController{
$discount = $this->get_discount($request['game_id'],$user['promote_id'],$request['user_id']);
$discount = $discount['discount'];
$pay_amount = $discount * $request['price'] / 10;
- file_put_contents(dirname(__FILE__).'/1222222.txt',get_wx_pay_type());
+ file_put_contents(dirname(__FILE__).'/1222222.txt',get_wx_pay_type());
+ // 绑币平台币优先处理
+ $this->other_price($request, $discountAmount);
+
//0 官方 1威富通 2俊付通
if (get_wx_pay_type() == 0) {
$weixn = new Weixin();
@@ -747,6 +758,102 @@ class AppleController extends BaseController{
}
+
+
+ /*
+ * 平台币抵扣
+ * 优先抵扣绑币 平台币 调这个接口说明 不走第三方支付通道
+ */
+ public function platform_coin_deduction($user_id, $game_id) {
+ $file=file_get_contents("./Application/Sdk/OrderNo/".$user_id."-".$game_id.".txt");
+ $request = json_decode(think_decrypt($file),true);
+
+ if (empty($request)) {
+ redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'参数错误')));exit;
+ }
+ // 支付验证 是否让支付
+ $payCheck = pay_check($request['user_id']);
+ if (!$payCheck['code']) {
+ redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=> $payCheck['msg'])));exit;
+ }
+
+ if ($request['price'] *1<=0) {
+ redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'充值金额有误')));exit;
+ }
+ $request['price'] = abs($request['price']);
+ $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find();
+ if($extend_data){
+ redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'订单号重复,请关闭支付页面重新支付')));exit;
+ }
+ $user_info = get_user_entity($request['user_id']);
+ if($user_info['lock_status'] == 0 || $user_info['check_status'] == 0){
+ redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'账号被禁用,无法充值,请联..系客服!')));exit;
+ }
+ $game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
+ if($game['pay_status'] == 0){
+ redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'该游戏暂时无法充值,请联系客服!')));exit;
+ }
+ $out_trade_no = "PF_" . date('Ymd') . date('His') . sp_random_string(4);
+ $request['order_number'] = $out_trade_no;
+ $request['pay_order_number'] = $out_trade_no;
+ $request['out_trade_no'] = $out_trade_no;
+ $request['title'] = $request['title'];
+ $request['pay_status'] = 1;
+ $request['pay_way'] = 0;
+ $request['spend_ip'] = get_client_ip();
+ $user_entity = get_user_entity($request['user_id']);
+ $discount_arr = $this->get_discount($request['game_id'], $user_entity['promote_id'], $request['user_id']);
+ $discount = $discount_arr['discount'];
+ $user = M("user", "tab_");
+ //添加黑名单
+ $check_deposit_money = $this->check_deposit_money($user_entity);
+ $check_bind_money = $this->check_bind_money($user_entity);
+ if($check_deposit_money === false || $check_bind_money === false || (C('BRUSH_MONEY') && (abs($check_deposit_money)>=C('BRUSH_MONEY') || abs($check_bind_money)>=C('BRUSH_MONEY'))) || (!C('BRUSH_MONEY') && (abs($check_deposit_money) != 0 || abs($check_bind_money) != 0))){
+ if(C('BRUSH_SMS_STATUS') && C('BRUSH_PHONE')&& C('BRUSH_SMS_ID')){
+ $result = $this-> send_block(C('BRUSH_PHONE'),$user_entity['account']);
+ }
+ $block_data['check_status'] = 0;
+ $block_data['block_time'] = time();
+ $user->where(['id'=>$user_entity['id']])->save($block_data);
+ redirect(U('Spend/notice',array('user_id'=>$user_id,'game_id'=>$game_id,'msg'=>'您的账号暂时无法充值,请联系客服处理.')));exit;
+ }
+ $result = false;
+ // 先扣绑币
+ $request['pay_way'] = -1;
+ $user_play = M("UserPlay", "tab_");
+ $user_play_map['user_id'] = $request['user_id'];
+ $user_play_map['game_id'] = $request['game_id'];
+ $user_play_data = $user_play->where($user_play_map)->find();
+
+ if ($user_play_data['bind_balance'] < $request['price']) {
+ $price = $request['price'];
+ if ($user_play_data['bind_balance'] > 0) {
+ $user_play->where($user_play_map)->save(array('bind_balance' => 0)); // 扣绑定币
+ $request['price'] = $user_play_data['bind_balance'];
+ $result = $this->add_spend($request);
+ $this->set_ratio($request['pay_order_number'], 2); // 游戏返利
+ }
+ $request['pay_way'] = 0; // 扣平台币
+ $real_price = $price - $user_play_data['bind_balance'];
+ $user->where(array('id' => $request["user_id"]))->setDec("balance", $real_price);
+ //$this->set_message(0,"fail", $request['pay_order_number']);
+
+ $request['pay_order_number'] = $request['pay_order_number']."_1";
+ $request['price'] = $real_price;
+ $result = $this->add_spend($request);
+ $this->set_ratio($request['pay_order_number'], 1); // 游戏返利
+ } else { // 绑定币足够扣
+ $user_play->where($user_play_map)->setDec('bind_balance', $request['price']); // 扣绑定币
+ $result = $this->add_spend($request);
+ $this->set_ratio($request['pay_order_number'], 2); // 游戏返利
+ }
+
+ $game = new GameApi();
+ $game->game_pay_notify($request, $request['code']);
+ $url = 'http://' . $_SERVER ['HTTP_HOST'] . "/sdk.php/Spend/pay_success3/orderno/".$request['pay_order_number'].'/game_id/'.$request['game_id'];
+
+ redirect($url);
+ }
/**
diff --git a/Application/Sdk/Controller/Ipa365Controller.class.php b/Application/Sdk/Controller/Ipa365Controller.class.php
index a4a7453fc..b32278965 100644
--- a/Application/Sdk/Controller/Ipa365Controller.class.php
+++ b/Application/Sdk/Controller/Ipa365Controller.class.php
@@ -68,7 +68,24 @@ class Ipa365Controller extends BaseController{
));
}
-
+ public function pay_order_check() {
+
+ $orderId = I('order_id');
+ $order = M('game_supersign', 'tab_')->where(array(
+ 'order_id' => $orderId
+ ))->find();
+ if (!$order) {
+ echo "订单不存在!";
+ }
+ if ($order['pay_status'] == 1) {
+ redirect(U("Ipa365/install_show", [
+ 'game_id' => $order['game_id'],
+ 'order_id' => $order['order_id']
+ ]));
+ }
+ echo "订单正在处理中.请稍后再试!";
+ exit();
+ }
/*
* 发起支付
*/
@@ -132,9 +149,6 @@ class Ipa365Controller extends BaseController{
$param['notifyurl'] = "https://api.wmtxkj.com/callback.php/Notify/notify/apitype/alipay";
$ret = $this->alipay($param);
- $_SESSION['paytip_price']=self::signprice;
- $_SESSION['paytip_order_id']=$orderId;
- $_SESSION['paytip_url']=$ret['url'];
$this->assign("price", self::signprice);
$this->assign("url", $ret['url']);
@@ -144,11 +158,47 @@ class Ipa365Controller extends BaseController{
$this->display();
}
+
+
public function paytip(){
- $this->assign("price", $_SESSION['paytip_price']);
- $this->assign("url", $_SESSION['paytip_url']);
- $this->assign("order_id", $_SESSION['paytip_order_id']);
+ $orderId = I('order_id');
+
+ $payLog = M('game_supersign', 'tab_')->where(array(
+ 'order_id' => $orderId,
+ ))->find();
+
+ $this->assign('url', U('Ipa365/install', array(
+ 'order_id' => $payLog['order_id'],
+ 'user_id' => $payLog['user_id'],
+ 'game_id' => $payLog['game_id'],
+ )));
+
+ $price = $payLog['pay_price'];
+ $userId = $payLog['user_id'];
+ $gameId = $payLog['game_id'];
+
+ $param['price'] = $price;
+ $param['sdk_version'] = '2';
+ $param['user_id'] = $userId;
+ $param['game_id'] = $gameId;
+ $param['order_id'] = $orderId;
+ $param['apitype'] = "alipay";
+ $param['config'] = "alipay";
+ $param['signtype']= "MD5";
+ $param['server'] = "alipay.wap.create.direct.pay.by.user";
+ $param['payway'] = 1;
+ $param['title'] = $price;
+ $param['body'] = $price;
+ $param['callback'] = "https://api.wmtxkj.com/sdk.php/Ipa365/install_show/user_id/{$userId}/game_id/{$gameId}/order_id/{$orderId}";
+ $param['notifyurl'] = "https://api.wmtxkj.com/callback.php/Notify/notify/apitype/alipay";
+
+ $ret = $this->alipay($param);
+
+ $this->assign("url", $ret['url']);
+ $this->assign("price", $price);
+ $this->assign("order_id", $payLog['order_id']);
+ $this->assign("game_id", $payLog['game_id']);
//$this->assign("jump_url",$jump_url);
$this->display();
}
diff --git a/Application/Sdk/Controller/PayController.class.php b/Application/Sdk/Controller/PayController.class.php
index 9c91bc31d..6b5132487 100644
--- a/Application/Sdk/Controller/PayController.class.php
+++ b/Application/Sdk/Controller/PayController.class.php
@@ -328,6 +328,98 @@ class PayController extends BaseController
echo base64_encode(json_encode($data));
}
+ /*
+ * 平台币抵扣
+ * 优先抵扣绑币 平台币 调这个接口说明 不走第三方支付通道
+ */
+ public function platform_coin_deduction() {
+
+ #获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
+ $request = json_decode(base64_decode(file_get_contents("php://input")), true);
+ #记录信息
+ if ($request['price'] *1<=0) {
+ $this->set_message(1011, "fail", "充值金额有误");
+ }
+ $request['price'] = abs($request['price']);
+ $extend_data = M('spend','tab_')->where(array('extend'=>$request['extend'],'pay_status'=>1,'game_id'=>$request['game_id']))->find();
+ if($extend_data){
+ $this->set_message(1089,"fail","订单号重复,请关闭支付页面重新支付");
+ }
+ $user_info = get_user_entity($request['user_id']);
+ if($user_info['lock_status'] == 0 || $user_info['check_status'] == 0){
+ $this->set_message(0,"fail","账号被禁用,无法充值,请联..系客服!");
+ }
+ $game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
+ if($game['pay_status'] == 0){
+ $this->set_message(0,"fail","该游戏暂时无法充值,请联系客服!");
+ }
+ $out_trade_no = "PF_" . date('Ymd') . date('His') . sp_random_string(4);
+ $request['order_number'] = $out_trade_no;
+ $request['pay_order_number'] = $out_trade_no;
+ $request['out_trade_no'] = $out_trade_no;
+ $request['title'] = $request['title'];
+ $request['pay_status'] = 1;
+ $request['pay_way'] = 0;
+ $request['spend_ip'] = get_client_ip();
+ $user_entity = get_user_entity($request['user_id']);
+ $discount_arr = $this->get_discount($request['game_id'], $user_entity['promote_id'], $request['user_id']);
+ $discount = $discount_arr['discount'];
+ $user = M("user", "tab_");
+ //添加黑名单
+ $check_deposit_money = $this->check_deposit_money($user_entity);
+ $check_bind_money = $this->check_bind_money($user_entity);
+ if($check_deposit_money === false || $check_bind_money === false || (C('BRUSH_MONEY') && (abs($check_deposit_money)>=C('BRUSH_MONEY') || abs($check_bind_money)>=C('BRUSH_MONEY'))) || (!C('BRUSH_MONEY') && (abs($check_deposit_money) != 0 || abs($check_bind_money) != 0))){
+ if(C('BRUSH_SMS_STATUS') && C('BRUSH_PHONE')&& C('BRUSH_SMS_ID')){
+ $result = $this-> send_block(C('BRUSH_PHONE'),$user_entity['account']);
+ }
+ $block_data['check_status'] = 0;
+ $block_data['block_time'] = time();
+ $user->where(['id'=>$user_entity['id']])->save($block_data);
+ echo base64_encode(json_encode(array("status" => 1076,"return_code" => "fail", "return_msg" => C('BRUSH_MONEY')."您的账号暂时无法充值,请联系客服处理.".$check_deposit_money)));
+ exit();
+ }
+
+ $result = false;
+ // 先扣绑币
+ $request['pay_way'] = -1;
+ $user_play = M("UserPlay", "tab_");
+ $user_play_map['user_id'] = $request['user_id'];
+ $user_play_map['game_id'] = $request['game_id'];
+ $user_play_data = $user_play->where($user_play_map)->find();
+
+ if ($user_play_data['bind_balance'] < $request['price']) {
+ $price = $request['price'];
+ if ($user_play_data['bind_balance'] > 0) {
+ $user_play->where($user_play_map)->save(array('bind_balance' => 0)); // 扣绑定币
+ $request['price'] = $user_play_data['bind_balance'];
+ $result = $this->add_spend($request);
+ $this->set_ratio($request['pay_order_number'], 2); // 游戏返利
+ }
+ $request['pay_way'] = 0; // 扣平台币
+ $real_price = $price - $user_play_data['bind_balance'];
+ $user->where(array('id' => $request["user_id"]))->setDec("balance", $real_price);
+//$this->set_message(0,"fail", $request['pay_order_number']);
+
+ $request['pay_order_number'] = $request['pay_order_number']."_1";
+ $request['price'] = $real_price;
+ $result = $this->add_spend($request);
+ $this->set_ratio($request['pay_order_number'], 1); // 游戏返利
+ } else { // 绑定币足够扣
+ $user_play->where($user_play_map)->setDec('bind_balance', $request['price']); // 扣绑定币
+ $result = $this->add_spend($request);
+ $this->set_ratio($request['pay_order_number'], 2); // 游戏返利
+ }
+
+ $game = new GameApi();
+ $game->game_pay_notify($request, $request['code']);
+ if ($result) {
+ echo base64_encode(json_encode(array("status" => 200, "return_code" => "success", "return_msg" => "支付成功", "out_trade_no" => $out_trade_no)));
+ } else {
+ echo base64_encode(json_encode(array("status" => 1078, "return_code" => "fail", "return_msg" => "支付失败")));
+ }
+
+
+ }
/**
*平台币支付
@@ -347,7 +439,7 @@ class PayController extends BaseController
}
$user_info = get_user_entity($request['user_id']);
if($user_info['lock_status'] == 0 || $user_info['check_status'] == 0){
- $this->set_message(0,"fail","账号被禁用,无法充值,请联系客服!");
+ $this->set_message(0,"fail","账号被禁用,无法充值,请联系客服...!");
}
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
if($game['pay_status'] == 0){
diff --git a/Application/Sdk/Controller/SpendController.class.php b/Application/Sdk/Controller/SpendController.class.php
index f01a3f0a0..b99ccb966 100644
--- a/Application/Sdk/Controller/SpendController.class.php
+++ b/Application/Sdk/Controller/SpendController.class.php
@@ -43,37 +43,35 @@ class SpendController extends Controller {
* @return [type] [description]
*/
public function pay_way() {
- $user_id = I ( 'user_id' );
-
- $game_id = I ( 'game_id' );
+ $user_id = I ('user_id');
+ $game_id = I ('game_id');
$file = file_get_contents ( "./Application/Sdk/OrderNo/" . $user_id . "-" . $game_id . ".txt" );
$request = json_decode ( think_decrypt ( $file ), true );
$data = array(
- 'coin' => $request ['body'],
- 'price' => $request ['price'],
- 'game_name' => $request ['game_name'],
- 'code' => $request ['code']
+ 'coin' => $request ['body'],
+ 'price' => $request ['price'],
+ 'game_name' => $request ['game_name'],
+ 'code' => $request ['code']
);
$balance = M ( 'user', 'tab_' )->where ( array (
- 'id' => $user_id
+ 'id' => $user_id
) )->getField ( 'balance' );
$bind_balance = M ( 'user_play', 'tab_' )->where ( array (
- 'user_id' => $user_id,
- 'game_id' => $game_id
+ 'user_id' => $user_id,
+ 'game_id' => $game_id
) )->getField ( 'bind_balance' );
+ $data['price'] = 1;
- /* $sqpay = new Sqpay();
- $prefix = $request['code'] == 1 ? "SP_" : "PF_"; // SP 0 充值 1消费
- $order_no = $prefix.date('Ymd').date('His').sp_random_string(4);
- $ret = $sqpay->sq_pay($order_no,$request ['price'],$merno="168885",$ip=0,$returnurl="");
- $ret = json_decode($ret, true); */
-
$this->assign ( 'balance', $balance );
$this->assign ( 'bind_balance', $bind_balance );
$this->assign ( 'data', $data );
$this->assign ( 'btncolor', $request ['btncolor'] );
+ if ($balance + $bind_balance > $data['price'])
+ $this->assign ('pay_price', 0); // 是否第三方支付
+ else
+ $this->assign ('pay_price', $data['price'] - $balance - $bind_balance);
/* $this->assign ( 'alipayurl', $ret[0]['payURL']);
header("Access-Control-Allow-Origin: *"); */
@@ -87,6 +85,7 @@ class SpendController extends Controller {
$orderno = $_GET ['jinzhue'];
}
$pay_where = substr ( $orderno, 0, 2 );
+ $Scheme = file_get_contents ( "./Application/Sdk/Scheme/" . $_GET ['game_id'] . ".txt" );
$map ['pay_order_number'] = $orderno;
switch ($pay_where) {
case 'SP' :
@@ -104,6 +103,7 @@ class SpendController extends Controller {
$result = M ( 'bind_recharge', 'tab_' )->field ( 'pay_status' )->where ( $map )->find ();
break;
}
+ $this->assign ( 'Scheme', $Scheme );
$this->assign ( 'paystatus', $result ['pay_status'] );
$this->display ();
}
diff --git a/Application/Sdk/Controller/WapPayController.class.php b/Application/Sdk/Controller/WapPayController.class.php
index e1591e516..50600d2a8 100644
--- a/Application/Sdk/Controller/WapPayController.class.php
+++ b/Application/Sdk/Controller/WapPayController.class.php
@@ -57,35 +57,6 @@ class WapPayController extends BaseController{
return $pay->buildRequestForm($vo, 0, $param);
}
- /**
- * 优先扣除绑币 和平台 处理
- * $request $discountAmount 折扣价格
- */
- public function other_price(&$request, $discountAmount=0) {
- // 优先扣除绑定币平台币
- $deductionAmount = 0;
- $user_id = $request['user_id'];
- $game_id = $request['game_id'];
- $balance = M ('user', 'tab_')->where (array(
- 'id' => $user_id
- ))->getField('balance');
- $bind_balance = M('user_play', 'tab_')->where(array(
- 'user_id' => $user_id,
- 'game_id' => $game_id
- ))->getField('bind_balance');
- // 够抵扣的情况 不走这个接口
- $deductionAmount = $bind_balance + $balance;
- if ($deductionAmount > $request['price']) {
- $this->set_message(1089,"fail",$deductionAmount."平台币足够,请关闭支付页面重新支付".$pay_amount);
- }
- // 实际支付金额 = 支付总金额 - 折扣抵扣价格 - 绑币和平台币抵扣金额
- $request['actual_amount'] = round($request['price'] - $discountAmount - $deductionAmount, 2).'';
- $request['discount_amount'] = round($discountAmount, 2).'';
- $request['deduction_amount'] = round($deductionAmount, 2).'';
- $request['price'] = round($request['actual_amount'], 2).'';
- return $request;
- //$this->set_message(1089,"fail",$request['price']."新支付".$pay_amount);
- }
/**
*支付宝移动支付
@@ -120,7 +91,7 @@ class WapPayController extends BaseController{
$out_trade_no = $prefix.date('Ymd').date('His').sp_random_string(4);
$request = $this->other_price($request);
-Log::write(serialize($request), Log::DEBUG);
+//Log::write(serialize($request), Log::DEBUG);
if(get_zfb_type()==0){
$game_set_data = get_game_set_info($request['game_id']);
@@ -133,6 +104,7 @@ Log::write(serialize($request), Log::DEBUG);
$request['title']=$request['price'];
$request['body']=$request['price'];
$request['out_trade_no'] = $out_trade_no;
+//$this->set_message(1011,"fail", $request['code']);
$pay_url=$this->pay($request);
@@ -594,7 +566,7 @@ Log::write(serialize($request), Log::DEBUG);
$this->set_message(1088, "fail", $payCheck['msg']);
}
C(api('Config/lists'));
- if($request['price']*1<=0){
+ if($request['price']*1<=0 || $request['price'] > C('WX_PAY_LIMIT')){
$this->set_message(1011,"fail","充值金额有误");
}
$game = M('Game','tab_')->where(['id'=>$request['game_id']])->field('pay_status')->find();
diff --git a/Application/Sdk/View/default/Ipa365/pay.html b/Application/Sdk/View/default/Ipa365/pay.html
index 5cc44ed23..1bb04584d 100644
--- a/Application/Sdk/View/default/Ipa365/pay.html
+++ b/Application/Sdk/View/default/Ipa365/pay.html
@@ -69,7 +69,7 @@
{$price}元
@@ -86,11 +86,11 @@