Przeglądaj źródła

总共三处退诊

lizhen_gitee 10 miesięcy temu
rodzic
commit
f48abd9688

+ 10 - 3
application/api/controller/Wenzhen.php

@@ -456,6 +456,7 @@ class Wenzhen extends Api
     }
 
     //用户发起退珍
+    //因为存在第三方,悲观锁
     public function tuizhen(){
         $apilimit = $this->apiLimit();
         if(!$apilimit){
@@ -464,23 +465,29 @@ class Wenzhen extends Api
 
         //订单详情
         $order_id = input('order_id',0);
-        $wenzhen_order = Db::name('wenzhen_order')->where('user_id',$this->auth->id)->where('id',$order_id)->find();
+        Db::startTrans();
+
+        $wenzhen_order = Db::name('wenzhen_order')->where('user_id',$this->auth->id)->where('id',$order_id)->lock(true)->find();
         if(empty($wenzhen_order)){
+            Db::rollback();
             $this->error('不存在的订单');
         }
 
         //仅限视频订单
         if($wenzhen_order['ordertype'] == 1){
+            Db::rollback();
             $this->error('图文问诊不能退诊');
         }
 
         //状态限制
         if(!in_array($wenzhen_order['status'],[10,20])){
+            Db::rollback();
             $this->error('当前订单不能退诊');
         }
 
         //超过支付时间一小时不能退
         if( time() - $wenzhen_order['pay_time'] > 3600){
+            Db::rollback();
             $this->error('支付超过一小时,不能退诊');
         }
 
@@ -492,7 +499,7 @@ class Wenzhen extends Api
             'cancel_reason' => '用户付款后退诊',
             'finish_time'   => $nowtime,
         ];
-        Db::startTrans();
+
 
         //退款要打折扣
         $wenzhen_refund_bili = config('site.payorder_userrefund_bili') ?: 70;
@@ -526,7 +533,7 @@ class Wenzhen extends Api
 
         }
 
-        $update_rs = Db::name('wenzhen_order')->where('id',$order_id)->where('status',$wenzhen_order['status'])->update($update);
+        $update_rs = Db::name('wenzhen_order')->where('id',$order_id)->update($update);
         if(!$update_rs){
             Db::rollback();
             $this->error('退诊失败');

+ 9 - 5
application/api/controller/doctor/Wenzhen.php

@@ -146,6 +146,7 @@ class Wenzhen extends Apic
     }
 
     //退珍
+    //因为存在第三方,悲观锁
     public function tuizhen(){
         $apilimit = $this->apiLimit();
         if(!$apilimit){
@@ -154,12 +155,17 @@ class Wenzhen extends Apic
 
         //订单详情
         $order_id = input('order_id',0);
-        $wenzhen_order = Db::name('wenzhen_order')->where('doctor_id',$this->auth->id)->where('id',$order_id)->find();
+
+        Db::startTrans();
+
+        $wenzhen_order = Db::name('wenzhen_order')->where('doctor_id',$this->auth->id)->where('id',$order_id)->lock(true)->find();
         if(empty($wenzhen_order)){
+            Db::rollback();
             $this->error('不存在的订单');
         }
 
         if($wenzhen_order['status'] != 10){
+            Db::rollback();
             $this->error('待接诊订单才能退诊');
         }
 
@@ -171,7 +177,7 @@ class Wenzhen extends Apic
             'cancel_reason' => input('cancel_reason','医生主动退珍'),
             'finish_time' => $nowtime,
         ];
-        Db::startTrans();
+
 
         //余额支付的直接退款
         if($wenzhen_order['pay_type'] == 'wallet'){
@@ -198,7 +204,7 @@ class Wenzhen extends Apic
             }
         }
 
-        $update_rs = Db::name('wenzhen_order')->where('id',$order_id)->where('status',10)->update($update);
+        $update_rs = Db::name('wenzhen_order')->where('id',$order_id)->update($update);
         if(!$update_rs){
             Db::rollback();
             $this->error('退珍失败');
@@ -235,11 +241,9 @@ class Wenzhen extends Apic
 
         $update_rs = Db::name('wenzhen_order')->where('id',$order_id)->where('status',10)->update($update);
         if(!$update_rs){
-            Db::rollback();
             $this->error('接诊失败');
         }
 
-        Db::commit();
         $this->success(1,'接珍成功');
     }
 

+ 1 - 0
application/index/controller/Plantask.php

@@ -5,6 +5,7 @@ namespace app\index\controller;
 use think\Controller;
 use think\Db;
 use think\Cache;
+use app\common\model\Wenzhenorder;
 
 class Plantask extends Controller
 {