where('enable', 1)->where('user_id', $userId)->where('type', $type); # 根据主键id搜索 if($interestIds) { $collectModel->whereIn('id', $interestIds); } $count = $collectModel->count(); $list = $collectModel->select([ 'id', 'item_id', 'item_short_title', 'item_title', 'item_price', 'item_end_price', 'shop_type', 'coupon_money', 'item_pic', 'pid', 'updated_at' ])->orderBy('updated_at', 'desc')->offset(($page-1)*$pageSize)->limit($pageSize)->get(); return [$list, $count]; } /** * 批量移除商品收藏/浏览历史 * */ public static function removeInterest($userId, $ids, $type) { $result = self::where('user_id', $userId)->where('enable', 1)->where('is_del', 0) ->where('type', $type)->whereIn('item_id', $ids)->update(['is_del' => 1]); return $result ? 0 : 1005; } /** * 判断是否已收藏该商品 * */ public static function hadInterest($userId, $itemId) { return self::where('user_id', $userId) ->where('item_id', $itemId) ->where('enable', 1)->where('is_del', 0) ->where('type', 1) ->exists(); } }