浏览代码

首页可领的优惠券

lizhen_gitee 7 月之前
父节点
当前提交
f5b9ed1c47
共有 1 个文件被更改,包括 17 次插入0 次删除
  1. 17 0
      application/api/controller/Index.php

+ 17 - 0
application/api/controller/Index.php

@@ -44,11 +44,28 @@ class Index extends Api
         $buttom_category = Db::name('unishop_category')->field('id, name, image')->where(['status' => 'normal','is_top' => 0])->order('weigh', 'asc')->select();
         $buttom_category = list_domain_image($buttom_category, ['image']);
 
+        //未领取的优惠券
+        $coupon = (object)[];
+        if($this->auth->isLogin()){
+            //我拥有的
+            $user_coupon = Db::name('unishop_coupon_user')->where('user_id',$this->auth->id)->column('coupon_id');
+            //我没有的,可领取的
+            $coupon = Db::name('unishop_coupon')->field('id,title,least,value')
+                ->where('id','NOTIN',$user_coupon)
+                ->where('deletetime',NULL)
+                ->where('switch',1)
+                ->where('starttime','<',time())
+                ->where('endtime','>',time())
+                ->order('id asc')->find();
+
+            if(empty($coupon)){ $coupon = (object)[];}
+        }
         //
         $result = [
             'banner' => $banner,
             'top_category' => $top_category,
             'buttom_category' => $buttom_category,
+            'coupon' => $coupon,
         ];
         $this->success(1,$result);
     }