xieruidong 2 年之前
父节点
当前提交
2cc6c932de
共有 2 个文件被更改,包括 17 次插入2 次删除
  1. 2 2
      application/api/controller/mall/Index.php
  2. 15 0
      application/common/model/Goods.php

+ 2 - 2
application/api/controller/mall/Index.php

@@ -51,7 +51,7 @@ class Index extends Api
     public function kill_goods(){
         $config=KillService::getConfig();
         if($config['open']){
-            $goods= Goods::where('is_kill',1)->order('kill_at','desc')->limit(3)->select();
+            $goods= Goods::filterKill()->order('kill_at','desc')->limit(3)->select();
             $config['goods']=$goods;
         }
         $this->success('',$config);
@@ -60,7 +60,7 @@ class Index extends Api
      * 热销爆款
      */
     public function hot_goods(){
-        $info['goods']= Goods::where('is_hot',1)->order('hot_at','desc')->limit(3)->select();
+        $info['goods']= Goods::filterHot()->order('hot_at','desc')->limit(3)->select();
         $this->success('',$info);
     }
 }

+ 15 - 0
application/common/model/Goods.php

@@ -3,10 +3,14 @@
 namespace app\common\model;
 
 use app\common\validate\KillService;
+use think\db\Query;
 use think\Model;
 
 /**
  * 邮箱验证码
+ * @method $this|static|Query filterNormal()
+ * @method $this|static|Query filterKill()
+ * @method $this|static|Query filterHot()
  */
 class Goods Extends Model
 {
@@ -139,6 +143,17 @@ class Goods Extends Model
     }
 
 
+    public function scopeFilterNormal(Query $query){
+        $query->where('is_kill',0)->where('is_hot',0);
+    }
+    public function scopeFilterKill(Query $query){
+        $query->where('is_kill',1);
+    }
+    public function scopeFilterHot(Query $query){
+        $query->where('is_hot',1);
+    }
+
+
     public function getDetailUrlAttr($_,$model){
         return sprintf('%s/goodsDetail?id=%d',request()->domain(),$model['id']??0);
     }