Browse Source

余额支付,付费旁听

lizhen_gitee 1 month ago
parent
commit
5dbcf626d8
2 changed files with 37 additions and 5 deletions
  1. 35 3
      app/Http/Controllers/Api/AskController.php
  2. 2 2
      app/Wen/Utils/UserUtils.php

+ 35 - 3
app/Http/Controllers/Api/AskController.php

@@ -189,14 +189,14 @@ class AskController extends BaseController
 
             //检查余额
             $balance = UserUtils::user_balance($uid);
-            if($balance <= $order['ask_price']){
+            if($balance <= $order->ask_price]){
                 return $this->fail(200012);
             }
 
             DB::beginTransaction();
 
             //余额支付
-            $pay_res = UserUtils::update_user_financial($uid, 11, $order['price'], '您花费了¥'.$order['price'].'余额开通了'.$order['days'].'天会员');
+            $pay_res = UserUtils::update_user_financial($uid, 101, $order->ask_price, '您花费了¥'.$order->ask_price.'余额,付费咨询');
             if(!$pay_res){
                 DB::rollBack();
                 return $this->fail(200012);
@@ -256,7 +256,39 @@ class AskController extends BaseController
             return $this->fail(200016,[],'该旁听已经支付过了');
         }
 
-        //
+        //使用余额支付
+        if($request->pay_type == 'balance'){
+
+            //检查支付密码
+            $this->check_paycode($uid,$request->paycode);
+
+            //检查余额
+            $balance = UserUtils::user_balance($uid);
+            if($balance <= $order->sit_price]){
+                return $this->fail(200012);
+            }
+
+            DB::beginTransaction();
+
+            //余额支付
+            $pay_res = UserUtils::update_user_financial($uid, 102, $order->sit_price, '您花费了¥'.$order->sit_price.'余额,付费旁听');
+            if(!$pay_res){
+                DB::rollBack();
+                return $this->fail(200012);
+            }
+            //直接修改订单状态,支付完成
+            $rs1 = DB::table('ask_order')->where('id',$order_id)->update(['status'=>10,'paytime'=>time()]);
+            if(!$rs1){
+                DB::rollBack();
+                return $this->fail([],200,'支付失败');
+            }
+
+            DB::commit();
+
+            return $this->success();
+        }
+
+        //拉起三方支付
         $body = '付费旁听';
         $data['body'] = '付费旁听';
         $total_fee = $order->sit_price;

+ 2 - 2
app/Wen/Utils/UserUtils.php

@@ -2255,7 +2255,7 @@ class UserUtils{
                 ->update(['bank_name' => $bank_name, 'bank_card' => $bank_card, 'balance' => $balance, 'withdrawal_price' => $withdrawalPrice]);
         }
 
-        if(in_array($type, [7, 8, 9, 10, 11, 13, 19, 21, 22, 27, 30, 32, 10001])){
+        if(in_array($type, [7, 8, 9, 10, 11, 13, 19, 21, 22, 27, 30, 32, 101, 102, 10001])){
             // 购买付费
             $wd = WxUserFinancial::where('user_id', $user_id)->first();
             if(_empty_($wd)){
@@ -2272,7 +2272,7 @@ class UserUtils{
 
         $record = new WxUserFinancialRecord();
         $record->user_id = $user_id;
-        if(in_array($type, [2, 7, 8, 9, 10, 11, 13, 19, 21, 22, 27, 30, 32, 10001])){
+        if(in_array($type, [2, 7, 8, 9, 10, 11, 13, 19, 21, 22, 27, 30, 32, 101, 102, 10001])){
             $record->num = -$nums;
         }else{
             $record->num = $nums;