Browse Source

钱包迁移,api,异步回调

lizhen_gitee 2 years ago
parent
commit
e2f19ff6ec
1 changed files with 12 additions and 3 deletions
  1. 12 3
      application/api/controller/Notify.php

+ 12 - 3
application/api/controller/Notify.php

@@ -119,11 +119,12 @@ class Notify extends Api
         $rechargelogModel = new \app\common\model\UserRechargeLog();
         $orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
         $userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
+        $userwallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
         $time = time();
         // 修改订单状态
         $res1 = $orderModel->update(["status" => 1,'transaction_id' => $trade_no,'paytime'=>$time], ["order_no" => $out_trade_no]);
         // 修改用户钻石余额
-        $res2 = $userModel->where(["id" => $orderInfo["user_id"]])->setInc("jewel", $orderInfo["jewel"]);
+        $res2 = true;
         //判断是否首充
         $jewellogWhere['user_id'] = $orderInfo["user_id"];
         $jewellogWhere['type'] = 1;
@@ -135,9 +136,17 @@ class Notify extends Api
         $preUserId = $userInfo['pre_userid'];
         // 添加钻石流水记录
         $detail = "钻石充值";
-        $res3 = $jewellogModel->addUserJewelLog($userInfo["id"], $orderInfo["jewel"], "+", $userInfo["jewel"], $detail, 1);
+        $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']);
+        }
+
         // 添加充值记录
-        $res4 = $rechargelogModel->addRecord($userInfo["id"], $orderInfo["jewel"], $payamount, bcadd($userInfo["jewel"], $orderInfo["jewel"], 2), $userInfo["money"], $orderInfo["platform"], 2,$isFirst,$preUserId);
+        $res4 = $rechargelogModel->addRecord($userInfo["id"], $orderInfo["jewel"], $payamount, bcadd($userwallet["jewel"], $orderInfo["jewel"], 2), $userwallet["money"], $orderInfo["platform"], 2,$isFirst,$preUserId);
         if ($res1 && $res2 && $res3 && $res4) {
             // 添加统计
             $userInfo->chargecount = $userInfo->chargecount + $payamount;