Browse Source

商品优惠券

lizhen_gitee 6 months ago
parent
commit
a370126efb
1 changed files with 18 additions and 3 deletions
  1. 18 3
      addons/unishop/controller/Product.php

+ 18 - 3
addons/unishop/controller/Product.php

@@ -9,6 +9,7 @@ use addons\unishop\model\Favorite;
 use addons\unishop\model\Product as productModel;
 use addons\unishop\model\Coupon;
 use think\Exception;
+use think\Db;
 
 /**
  * 商品
@@ -87,10 +88,24 @@ class Product extends Base
                 ->find();*/
 
             //优惠券
-            $data->coupon = (new Coupon)->where('endtime', '>', time())
-                ->where(['switch' => Coupon::SWITCH_ON])->order('weigh DESC')->select();
+            /*$data->coupon = (new Coupon)->where('endtime', '>', time())
+                ->where(['switch' => Coupon::SWITCH_ON])->order('weigh DESC')->select();*/
 
-            // 是否已收藏
+            $data->coupon = [];
+            if($this->auth->isLogin()){
+                $data->coupon = Db::name('unishop_coupon_user')->alias('cu')
+                    ->field(['c.id','c.title','c.least','c.value','c.starttime','c.endtime'])
+                    ->join('unishop_coupon c','cu.coupon_id = c.id','LEFT')
+                    ->where('cu.user_id',$this->auth->id)
+                    ->where('cu.status',0)
+                    ->where('c.deletetime',NULL)
+                    ->where('c.switch',Coupon::SWITCH_ON)
+                    ->where('c.endtime','>',time())
+                    ->select();
+            }
+
+
+                // 是否已收藏
             /*if ($this->auth->id) {
                 $data->favorite = (new Favorite)->where(['user_id' => $this->auth->id, 'product_id' => $productId])->count();
             }*/