| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Module\GameItems\Repositorys;
- use App\Module\GameItems\Models\ItemChestOpenCost;
- use UCore\DcatAdmin\Repository\EloquentRepository;
- /**
- * 宝箱开启消耗配置数据仓库
- */
- class ItemChestOpenCostRepository extends EloquentRepository
- {
- /**
- * 关联的Eloquent模型类
- *
- * @var string
- */
- protected $eloquentClass = ItemChestOpenCost::class;
- /**
- * 获取指定宝箱的所有激活消耗配置
- *
- * @param int $chestId 宝箱ID
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public function getActiveByChestId(int $chestId)
- {
- return $this->eloquentClass::where('chest_id', $chestId)
- ->where('is_active', true)
- ->get();
- }
- /**
- * 批量更新消耗配置的激活状态
- *
- * @param array $ids 消耗配置ID数组
- * @param bool $isActive 是否激活
- * @return int 更新的记录数
- */
- public function batchUpdateActiveStatus(array $ids, bool $isActive): int
- {
- return $this->eloquentClass::whereIn('id', $ids)
- ->update(['is_active' => $isActive]);
- }
- /**
- * 复制消耗配置到另一个宝箱
- *
- * @param int $sourceChestId 源宝箱ID
- * @param int $targetChestId 目标宝箱ID
- * @return int 复制的记录数
- */
- public function copyToAnotherChest(int $sourceChestId, int $targetChestId): int
- {
- $sourceCosts = $this->eloquentClass::where('chest_id', $sourceChestId)->get();
- $count = 0;
- foreach ($sourceCosts as $cost) {
- $newCost = $cost->replicate();
- $newCost->chest_id = $targetChestId;
- $newCost->save();
- $count++;
- }
- return $count;
- }
- }
|