瀏覽代碼

用户优惠券

lizhen_gitee 6 月之前
父節點
當前提交
3b038b0736
共有 1 個文件被更改,包括 35 次插入1 次删除
  1. 35 1
      application/api/controller/Usercoupon.php

+ 35 - 1
application/api/controller/Usercoupon.php

@@ -4,7 +4,6 @@ namespace app\api\controller;
 
 use app\common\controller\Api;
 use think\Db;
-use app\common\library\Sms;
 
 /**
  *  用户优惠券
@@ -17,6 +16,41 @@ class Usercoupon extends Api
 
     //优惠券里列表
     public function lists(){
+        $status = input('status',0);
+
+        $where = [
+            'cu.user_id' => $this->auth->id,
+        ];
+
+        if($status == 0){
+            //待使用
+            $where['c.deletetime'] = NULL;
+            $where['c.switch']     = 1;
+            $where['c.starttime']  = ['<',time()];
+            $where['c.endtime']    = ['>',time()];
+            $where['cu.status']    = 0;
+        }
+        if($status == 1){
+            //已使用
+            $where['cu.status'] = 1;
+        }
+        if($status == 2){
+            //已失效
+            $where['c.deletetime'] = NULL;
+            $where['c.switch']     = 1;
+            $where['c.starttime']  = ['<',time()];
+            $where['c.endtime']    = ['<',time()];
+            $where['cu.status']    = 0;
+        }
+
+        $list = Db::name('unishop_coupon_user')->alias('cu')
+            ->field(['c.id','c.title','c.least','c.value','c.starttime','c.endtime','cu.status'])
+            ->join('unishop_coupon c','cu.coupon_id = c.id','LEFT')
+            ->where($where)
+            ->autopage()
+            ->select();
+
+        $this->success(1,$list);
 
     }