| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- <?php
- namespace App\Module\Shop\Repositorys;
- use App\Module\Shop\Models\ShopPurchaseLimit;
- use Dcat\Admin\Repositories\EloquentRepository;
- /**
- * 商店限购配置数据仓库
- *
- * 提供商店限购配置的数据访问和管理功能
- */
- class ShopPurchaseLimitRepository extends EloquentRepository
- {
- /**
- * 模型类名
- *
- * @var string
- */
- protected $eloquentClass = ShopPurchaseLimit::class;
- /**
- * 获取商品的限购配置列表
- *
- * @param int $shopItemId 商品ID
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function getByShopItem(int $shopItemId)
- {
- return ShopPurchaseLimit::where('shop_item_id', $shopItemId)
- ->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();
- }
- }
|