| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- <?php
- namespace App\Module\Game\Repositorys;
- use App\Module\Game\Enums\CONDITION_TYPE;
- use App\Module\Game\Models\GameConditionItem;
- use Dcat\Admin\Repositories\EloquentRepository;
- /**
- * 条件项数据仓库
- */
- class GameConditionItemRepository extends EloquentRepository
- {
- /**
- * 模型类名
- *
- * @var string
- */
- protected $eloquentClass = GameConditionItem::class;
- /**
- * 保存数据前的处理
- *
- * @param array $data
- * @return array
- */
- public function beforeStore(array $data): array
- {
- // 处理房屋等级条件的特殊情况
- if (isset($data['condition_type']) && $data['condition_type'] == CONDITION_TYPE::HOUSE_LEVEL->value) {
- $data['target_id'] = 0; // 房屋等级条件的target_id固定为0
- }
- return $data;
- }
- /**
- * 更新数据前的处理
- *
- * @param array $data
- * @return array
- */
- public function beforeUpdate(array $data): array
- {
- // 处理房屋等级条件的特殊情况
- if (isset($data['condition_type']) && $data['condition_type'] == CONDITION_TYPE::HOUSE_LEVEL->value) {
- $data['target_id'] = 0; // 房屋等级条件的target_id固定为0
- }
- return $data;
- }
- }
|