where('is_active', true) ->orderBy('sort_order') ->get(); } /** * 批量获取多个商品的限购配置 * * @param array $shopItemIds 商品ID数组 * @return \Illuminate\Database\Eloquent\Collection */ public function getByShopItems(array $shopItemIds) { return ShopPurchaseLimit::whereIn('shop_item_id', $shopItemIds) ->where('is_active', true) ->orderBy('sort_order') ->get() ->groupBy('shop_item_id'); } /** * 创建限购配置 * * @param array $data 限购配置数据 * @return ShopPurchaseLimit */ public function createLimit(array $data): ShopPurchaseLimit { return ShopPurchaseLimit::create($data); } /** * 更新限购配置 * * @param int $id 限购配置ID * @param array $data 更新数据 * @return bool */ public function updateLimit(int $id, array $data): bool { return ShopPurchaseLimit::where('id', $id)->update($data) > 0; } /** * 删除限购配置 * * @param int $id 限购配置ID * @return bool */ public function deleteLimit(int $id): bool { return ShopPurchaseLimit::where('id', $id)->delete() > 0; } /** * 切换限购配置状态 * * @param int $id 限购配置ID * @return bool */ public function toggleStatus(int $id): bool { $limit = ShopPurchaseLimit::find($id); if (!$limit) { return false; } $limit->is_active = !$limit->is_active; return $limit->save(); } }