Browse Source

套餐订单完成,商家得钱

lizhen_gitee 1 year ago
parent
commit
4ca2066adb
1 changed files with 15 additions and 3 deletions
  1. 15 3
      application/api/controller/company/Order.php

+ 15 - 3
application/api/controller/company/Order.php

@@ -113,18 +113,30 @@ class Order extends Apic
     public function finish(){
         $id = input('id',0);
 
-        $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->company_id)->find();
-        if($info['status'] == 2){
+        Db::startTrans();
+        $info = Db::name('order')->where('id',$id)->where('company_id',$this->auth->company_id)->lock(true)->find();
+        if($info['status'] != 2){
+            Db::rollback();
             $this->error('当前订单不能完成');
         }
 
         //完成
         $rs = Db::name('order')->where('id',$id)->update(['status'=>3,'finish_time'=>time(),'staff_id'=>$this->auth->id]);
-
         if($rs === false){
+            Db::rollback();
             $this->error('操作失败');
         }
 
+        //给门店加钱
+        if($info['ordertype'] == 3 && $info['pay_fee'] > 0){
+            $wallet_rs = model('walletcompany')->lockChangeAccountRemain($this->auth->company_id,'money',$info['pay_fee'],203,$remark='套餐订单完成服务','order',$id);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+        }
+
+        //是否弹出保养
         $baoyang_switch = Db::name('servicetype')->where('id',$info['servicetype_id'])->value('baoyang_switch');
 
         $this->success('操作成功',$baoyang_switch);