xieruidong il y a 2 ans
Parent
commit
c0cce273b2

+ 3 - 0
application/api/controller/mall/GoodsFav.php

@@ -4,7 +4,9 @@ namespace app\api\controller\mall;
 
 use app\admin\model\GoodsViewFavCart;
 use app\common\controller\Api;
+use app\common\model\Favourite;
 use app\common\model\GoodsSku;
+use think\Db;
 
 /**
  * 商城收藏接口
@@ -23,6 +25,7 @@ class GoodsFav extends Api
      */
     public function index(){
         $user=$this->auth->getUser();
+        Favourite::delNotExists();
         $list=$user->favourite()
             ->order('id','desc')
             ->with(['goods'])

+ 5 - 0
application/common/model/Favourite.php

@@ -2,6 +2,7 @@
 
 namespace app\common\model;
 
+use think\Db;
 use think\Model;
 
 
@@ -17,4 +18,8 @@ class Favourite extends Model
     public function goods(){
         return $this->belongsTo(Goods::class,'fav_id');
     }
+
+    public static function delNotExists(){
+        self::whereNotExists(GoodsSku::where('id',Db::raw('favourite.goods_sku_id'))->buildSql())->delete();
+    }
 }

+ 1 - 0
thinkphp/library/think/Model.php

@@ -31,6 +31,7 @@ use think\model\relation\MorphTo;
  * @package think
  * @method static Query|static where($field, $op = null, $condition = null)
  * @method static Query|static whereExists($condition, $logic = 'AND')
+ * @method static Query|static whereNotExists($condition, $logic = 'AND')
  * @method static Query whereIn($field, $condition, $logic = 'AND')
  * @method static Query|static alias($alias)
  * @method static static find($data = null)