Quellcode durchsuchen

核销用户卡券

lizhen_gitee vor 1 Jahr
Ursprung
Commit
1818c34cda

+ 50 - 0
application/api/controller/company/Coupon.php

@@ -79,6 +79,56 @@ class Coupon extends Apic
         $this->success('删除成功');
     }
 
+    //核销用户一张卡券
+    public function hexiao(){
+        $user_coupon_id = input('user_coupon_id',0);
+
+        $map = [
+            'company_id' => $this->auth->company_id,
+            'id'         => $user_coupon_id,
+        ];
+
+        Db::startTrans();
+        $check = Db::name('user_coupons')->where($map)->find();
+        if(empty($check)){
+            Db::rollback();
+            $this->error('不存在的卡券');
+        }
+        if($check['remain'] <= 0){
+            Db::rollback();
+            $this->error('卡券数量不足');
+        }
+        if($check['endtime'] <= time()){
+            Db::rollback();
+            $this->error('卡券已过期');
+        }
+
+        //核销日志
+        $log = [
+            'user_id' => $check['user_id'],
+            'company_id' => $check['company_id'],
+            'coupons_id' => $check['coupons_id'],
+            'coupon_name' => $check['coupon_name'],
+            'user_coupon_id' => $check['id'],
+            'createtime' => time(),
+        ];
+        $log_id = Db::name('user_coupons_log')->insertGetId($log);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('核销失败');
+        }
+
+        //数量减一
+        $rs = Db::name('user_coupons')->where($map)->update(['remain'=>$check['remain']-1]);
+        if($rs === false){
+            Db::rollback();
+            $this->error('核销失败');
+        }
+
+        Db::commit();
+        $this->success('核销完成');
+    }
+
 
 
 

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

@@ -27,6 +27,7 @@ class Index extends Apic
             'position'  => 1
         ];
         $list = Db::name('platform_banner')->where($where)->order('weigh asc,id asc')->select();
+        $list = list_domain_image($list,['image']);
         $this->success(1,$list);
     }