Browse Source

pc支付,支付宝

lizhen_gitee 3 years ago
parent
commit
5dc066713e
1 changed files with 84 additions and 1 deletions
  1. 84 1
      application/api/controller/Recharge.php

+ 84 - 1
application/api/controller/Recharge.php

@@ -46,7 +46,7 @@ class Recharge extends Api
         $this->success('success',$user_info);
     }
 
-    //创建订单
+    //创建订单,公众号
     public function recharge(){
 
         $rc_id = input('rc_id',0);
@@ -103,7 +103,65 @@ class Recharge extends Api
 
         $this->success('success',$return);
     }
+    //创建订单
+    public function recharge_pc(){
+
+        $rc_id = input('rc_id',0);
+        $pay_type  = input('pay_type','wechat');
+        $username = input('username',0);
+
+
+        if(!$rc_id){
+            $this->error('请选择充值金额');
+        }
+
+        if(!$username){
+            $this->error('请输入用户手机号并选择');
+        }
+
+        //查找用户
+        $user_info = Db::name('user')->field('id')->where('username',$username)->find();
+        if (empty($user_info)) {
+            $this->error('用户信息不存在');
+        }
+
+        //赋值money
+        $recharge_config = Db::name('paygold_webcon')->where('id',$rc_id)->find();
+        $money = $recharge_config['money'];
+        $gold = $recharge_config['gold'];
+
+        //创建订单
+        $data = [];
+        $data['status'] = 0;
+        $pay_no = createUniqueNo('P',$user_info['id']);
+        $data['pay_no'] = $pay_no;
+        $data['money'] = $money;
+        $data['payment_class'] = $pay_type;
+        $data['user_id'] = $user_info['id'];
+        $data['ext_info'] =  json_encode(['subject'=>'充值金币支付']);
+        $data['memo'] =  '充值金币支付';
+        $data['createtime'] = time();
+        $data['payment'] = $pay_type == 'alipay' ? 'web' : 'scan';
+        $orderid = Db::name('pay_order')->insertGetId($data);
+
+        //创建回调
+        $data = [];
+        $data['event'] = 'success';
+        $data['class'] = 'app\common\model\Recharge';
+        $data['method'] = 'rechargepaysucc';
+        $data['args'] = json_encode(['user_id'=>$user_info['id'],'gold'=>$gold,'money'=>$money,'pg_id'=>$rc_id]);
+        $data['pay_no'] = $pay_no;
+        Db::name('pay_event')->insertGetId($data);
+
+        $return = [
+            'pay_no'=>$pay_no,
+            'title' => '充值金币支付',
+        ];
+
+        $this->success('success',$return);
+    }
 
+    //公众号
     public function topay(){
 
         $openid = input('openid');
@@ -125,7 +183,32 @@ class Recharge extends Api
         $res = Service::submitOrder($params);
         $this->success('请求成功',json_decode($res,true));
     }
+    //pc支付
+    public function topay_pc(){
 
+        $openid = input('openid');
+        $pay_no = input('pay_no');
+        $pay_type  = input_post('pay_type','wechat');
+        $orderInfo = Db::name('pay_order')->where('pay_no',$pay_no)->find();
+        //下单
+        $params = [
+            'type'         => $pay_type,
+            'orderid'      => $pay_no,
+            'title'        => $orderInfo['memo'],
+            'amount'       => $orderInfo['money'],
+            // 'amount'       => 0.01,
+            'method'       => $pay_type == 'alipay' ? 'web' : 'scan',
+            'openid'       => $openid,
+            'notifyurl' => $this->request->root(true) . '/notify.php/paytype/'.$pay_type,
+//            'returnurl' => $this->request->root(true) . '/index/index/paysuccess',
+        ];
+        $res = Service::submitOrder($params);
 
+        if($pay_type == 'wechat'){
+            exit;
+        }else{
+            return $res;
+        }
+    }
 
 }