qifengquan 1 year ago
parent
commit
bcd7df8200
2 changed files with 29 additions and 12 deletions
  1. 8 2
      addons/epay/controller/Api.php
  2. 21 10
      application/api/controller/User.php

+ 8 - 2
addons/epay/controller/Api.php

@@ -7,6 +7,7 @@ use addons\epay\library\Wechat;
 use addons\third\model\Third;
 use app\common\library\Auth;
 use app\common\model\Order;
+use app\common\model\User;
 use think\addons\Controller;
 use think\Response;
 use think\Session;
@@ -194,8 +195,13 @@ class Api extends Controller
             return;
         }
         $data = $pay->verify();
-        Order::update(['status'=>1],['orderid'=>$orderid]);
-
+        $order = Order::get(['orderid'=>$orderid]);
+        $order->save(['status'=>1]);
+        if($order['type']==1){
+            User::money($order['money'],$order['uid'],'狗粮充值');
+        }elseif ($order['type']==1){
+            User::money($order['money'],$order['uid'],'喜欢额度充值');
+        }
         //你可以在这里你的业务处理逻辑,比如处理你的订单状态、给会员加余额等等功能
         //下面这句必须要执行,且在此之前不能有任何输出
         return $pay->success()->send();

+ 21 - 10
application/api/controller/User.php

@@ -800,11 +800,7 @@ class User extends Api
         ];
         Order::create($order);
         $notifyurl = $this->request->root(true) . '/addons/epay/api/notifyx/type/' . $type.'/orderid/'.$orderId;
-        $returnurl = $this->request->root(true) . '/addons/epay/api/returnx/type/' . $type . '/out_trade_no/' . $orderId;
-
-//        print_r($notifyurl);
-//        print_r($returnurl);
-//        exit;
+        $returnurl = $this->request->root(true) . '/addons/epay/api/notifyx/type/' . $type.'/orderid/'.$orderId;
         $params = [
             'amount'=>$money,
             'orderid'=>$orderId,
@@ -824,24 +820,39 @@ class User extends Api
      * @ApiParams (name='openid',description='openid')
      */
     public function addScore(){
+        $uid = $this->auth->id;
         $money = $this->request->post('score');
         $openid = $this->request->post('openid');
+        $num = \config('site.score')[$money];
         if(!$money && !$openid){
             $this->error('参数缺失');
         }
+        if(!$uid && !$num){
+            $this->error('系统错误');
+        }
+        $type = 'wechat';
         $orderId = (new \app\api\controller\Common())->getOrderId();
+        $order = [
+            'uid'=>$uid,
+            'title'=>'喜欢额度充值',
+            'recharge_amount'=>$money,
+            'money'=>$num,
+            'type'=>2,
+            'orderid'=>$orderId
+        ];
+        Order::create($order);
+        $notifyurl = $this->request->root(true) . '/addons/epay/api/notifyx/type/' . $type.'/orderid/'.$orderId;
+        $returnurl = $this->request->root(true) . '/addons/epay/api/notifyx/type/' . $type.'/orderid/'.$orderId;
         $params = [
             'amount'=>$money,
             'orderid'=>$orderId,
             'type'=>'wechat',
-            'title'=>'狗粮充值',
-            'notifyurl'=>1,
-            'returnurl'=>1,
+            'title'=>'喜欢额度充值',
+            'notifyurl'=>$notifyurl,
+            'returnurl'=>$returnurl,
             'method'=>"mp",
             'openid'=>$openid
         ];
-//        echo \addons\epay\library\Service::submitOrder("99.9", "订单号", "wechat", "订单标题", "回调地址", "返回地址", "支付方法");
-//        echo \addons\epay\library\Service::submitOrder($params);
         $this->success('',\addons\epay\library\Service::submitOrder($params));
     }