Browse Source

钱包迁移,api,异步回调

lizhen_gitee 2 years ago
parent
commit
3d01decf95

+ 1 - 1
application/api/controller/Money.php

@@ -1603,7 +1603,7 @@ class Money extends Common
             $rechargelogModel = new \app\common\model\UserRechargeLog();
             $rechargelogModel = new \app\common\model\UserRechargeLog();
             $orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
             $orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
             $userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
             $userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
-            $userwallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
+            $userwallet = Db::name('user_wallet')->where('user_id',$orderInfo["user_id"])->find();
             // 修改订单状态
             // 修改订单状态
             $res1 = $orderModel->update(["status" => 1, 'platform' => 2], ["order_no" => $out_trade_no]);
             $res1 = $orderModel->update(["status" => 1, 'platform' => 2], ["order_no" => $out_trade_no]);
             // 修改用户钻石余额
             // 修改用户钻石余额

+ 14 - 5
application/api/controller/Notify.php

@@ -119,7 +119,7 @@ class Notify extends Api
         $rechargelogModel = new \app\common\model\UserRechargeLog();
         $rechargelogModel = new \app\common\model\UserRechargeLog();
         $orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
         $orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
         $userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
         $userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
-        $userwallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
+        $userwallet = Db::name('user_wallet')->where('user_id',$orderInfo["user_id"])->find();
         $time = time();
         $time = time();
         // 修改订单状态
         // 修改订单状态
         $res1 = $orderModel->update(["status" => 1,'transaction_id' => $trade_no,'paytime'=>$time], ["order_no" => $out_trade_no]);
         $res1 = $orderModel->update(["status" => 1,'transaction_id' => $trade_no,'paytime'=>$time], ["order_no" => $out_trade_no]);
@@ -208,18 +208,27 @@ class Notify extends Api
                     $rechargelogModel = new \app\common\model\UserRechargeLog();
                     $rechargelogModel = new \app\common\model\UserRechargeLog();
                     $orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
                     $orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
                     $userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
                     $userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
+                    $userwallet = Db::name('user_wallet')->where('user_id',$orderInfo["user_id"])->find();
                     // 修改订单状态
                     // 修改订单状态
                     $res1 = $orderModel->update(["status" => 1], ["order_no" => $out_trade_no]);
                     $res1 = $orderModel->update(["status" => 1], ["order_no" => $out_trade_no]);
                     // 修改用户钻石余额
                     // 修改用户钻石余额
-                    $res2 = $userModel->where(["id" => $orderInfo["user_id"]])->setInc("jewel", $orderInfo["jewel"]);
+                    $res2 = true;
                     // 添加钻石流水记录
                     // 添加钻石流水记录
-                    $detail = "砖石充值";
-                    $res3 = $jewellogModel->addUserJewelLog($userInfo["id"], $orderInfo["jewel"], "+", $userInfo["jewel"], $detail, 1);
+                    $detail = "钻石充值";
+                    $res3 = true;
+
+                    //增加用户钻石余额
+                    $rs_wallet = model('wallet')->lockChangeAccountRemain($userInfo["id"], $orderInfo["jewel"], "+", 0, $detail, 1,'jewel');
+                    if($rs_wallet['status'] == false){
+                        Db::rollback();
+                        $this->error($rs_wallet['msg']);
+                    }
+
                     // 添加充值记录
                     // 添加充值记录
                     $rechargeCount = $rechargelogModel->where('user_id',$orderInfo["user_id"])->count();
                     $rechargeCount = $rechargelogModel->where('user_id',$orderInfo["user_id"])->count();
                     $isFirstRecharge = $rechargeCount > 0 ? 0 : 1;
                     $isFirstRecharge = $rechargeCount > 0 ? 0 : 1;
                     $platformArr = ["wx_app_pay" => 1, "ali_wap_pay" => 2, "wx_public_pay" => 3];
                     $platformArr = ["wx_app_pay" => 1, "ali_wap_pay" => 2, "wx_public_pay" => 3];
-                    $res4 = $rechargelogModel->addRecord($userInfo["id"], $orderInfo["jewel"], $payamount, bcadd($userInfo["jewel"], $orderInfo["jewel"], 2), $userInfo["money"], $orderInfo["platform"], $platformArr[$pay_channel], $isFirstRecharge, $userInfo["pre_userid"]);
+                    $res4 = $rechargelogModel->addRecord($userInfo["id"], $orderInfo["jewel"], $payamount, bcadd($userwallet["jewel"], $orderInfo["jewel"], 2), $userwallet["money"], $orderInfo["platform"], $platformArr[$pay_channel], $isFirstRecharge, $userInfo["pre_userid"]);
                     if ($res1 && $res2 && $res3 && $res4) {
                     if ($res1 && $res2 && $res3 && $res4) {
                         // 添加统计
                         // 添加统计
                         $time = time();
                         $time = time();

+ 2 - 2
application/api/controller/Usersign.php

@@ -169,7 +169,7 @@ class Usersign extends Api
 
 
     //第七天赠送vip
     //第七天赠送vip
     //找出最近七天的次数
     //找出最近七天的次数
-    private function gift_vip($user_sign_gift_vipdays){
+    /*private function gift_vip($user_sign_gift_vipdays){
         $start = strtotime(date('Y-m-d')) - 518400;
         $start = strtotime(date('Y-m-d')) - 518400;
         $map = [
         $map = [
             'uid' => $this->auth->id,
             'uid' => $this->auth->id,
@@ -197,5 +197,5 @@ class Usersign extends Api
             return true;
             return true;
         }
         }
         return false;
         return false;
-    }
+    }*/
 }
 }