GameConditionItemRepository.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Module\Game\Repositorys;
  3. use App\Module\Game\Enums\CONDITION_TYPE;
  4. use App\Module\Game\Models\GameConditionItem;
  5. use Dcat\Admin\Repositories\EloquentRepository;
  6. /**
  7. * 条件项数据仓库
  8. */
  9. class GameConditionItemRepository extends EloquentRepository
  10. {
  11. /**
  12. * 模型类名
  13. *
  14. * @var string
  15. */
  16. protected $eloquentClass = GameConditionItem::class;
  17. /**
  18. * 保存数据前的处理
  19. *
  20. * @param array $data
  21. * @return array
  22. */
  23. public function beforeStore(array $data): array
  24. {
  25. // 处理房屋等级条件的特殊情况
  26. if (isset($data['condition_type']) && $data['condition_type'] == CONDITION_TYPE::HOUSE_LEVEL->value) {
  27. $data['target_id'] = 0; // 房屋等级条件的target_id固定为0
  28. }
  29. return $data;
  30. }
  31. /**
  32. * 更新数据前的处理
  33. *
  34. * @param array $data
  35. * @return array
  36. */
  37. public function beforeUpdate(array $data): array
  38. {
  39. // 处理房屋等级条件的特殊情况
  40. if (isset($data['condition_type']) && $data['condition_type'] == CONDITION_TYPE::HOUSE_LEVEL->value) {
  41. $data['target_id'] = 0; // 房屋等级条件的target_id固定为0
  42. }
  43. return $data;
  44. }
  45. }