lizhen_gitee 1 vuosi sitten
vanhempi
commit
fb4f2268ac

+ 64 - 3
application/api/controller/company/Coupon.php

@@ -86,6 +86,45 @@ class Coupon extends Apic
     }
 
     //统一核销
+    public function gethexiao(){
+        $code = input('code','');
+        $code = explode('_',$code);
+        $action = $code[0];
+        $id = $code[1];
+
+        if($action != 'hexiaocoupon' && $action != 'hexiaoorder'){
+            $this->error('错误的核销码');
+        }
+
+        if($action == 'hexiaocoupon'){
+            $map = [
+                'company_id' => $this->auth->company_id,
+                'id'         => $id,
+                'remain'     => ['gt',0],
+            ];
+            $check = Db::name('user_coupons')->field('id,coupon_name,coupon_info,endtime,getfrom')->where($map)->find();
+            if(!empty($check)){
+                $check['action'] = 'hexiaocoupon';
+            }
+        }else{
+            $map = [
+                'company_id' => $this->auth->company_id,
+                'id'         => $id,
+                'ordertype'  => 3,
+                'status'     => 2, //2=已支付,待处理
+            ];
+            $check = Db::name('order')->field('id,package_info,package_price')->where($map)->find();
+            if(!empty($check)){
+                $check['action'] = 'hexiaoorder';
+            }
+        }
+
+        $this->success(1,$check);
+
+        //$this->$action($id);
+    }
+
+    //统一核销
     public function hexiao(){
         $code = input('code','');
         $code = explode('_',$code);
@@ -108,7 +147,7 @@ class Coupon extends Apic
         ];
 
         Db::startTrans();
-        $check = Db::name('user_coupons')->where($map)->find();
+        $check = Db::name('user_coupons')->where($map)->lock(true)->find();
         if(empty($check)){
             Db::rollback();
             $this->error('不存在的卡券');
@@ -151,8 +190,30 @@ class Coupon extends Apic
 
 
     //核销用户的套餐订单
-    public function hexiaoorder(){
-        $this->error('接口暂未完成');
+    public function hexiaoorder($order_id){
+        $map = [
+            'company_id' => $this->auth->company_id,
+            'id'         => $order_id,
+            'ordertype'  => 3,
+            'status'     => 2, //2=已支付,待处理
+        ];
+
+        Db::startTrans();
+        $check = Db::name('order')->where($map)->lock(true)->find();
+        if(empty($check)){
+            Db::rollback();
+            $this->error('不存在的订单');
+        }
+
+        //数量减一
+        $rs = Db::name('order')->where($map)->update(['status'=>3,'hexiaotime'=>time()]);
+        if($rs === false){
+            Db::rollback();
+            $this->error('核销失败');
+        }
+
+        Db::commit();
+        $this->success('订单核销完成');
     }
 
 }

+ 1 - 0
application/api/controller/company/Preorder.php

@@ -99,6 +99,7 @@ class Preorder extends Apic
         $data['company_id'] = $this->auth->company_id;
         $data['staff_id'] = $this->auth->id;
 
+        $data['status'] = 2; //2=已支付,待处理
         $data['createtime'] = time();
 
         $order_id = Db::name('order')->insertGetId($data);