GameConsumeItem.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace App\Module\Game\Models;
  3. use App\Module\Game\Enums\CONSUME_TYPE;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use UCore\ModelCore;
  6. /**
  7. * 消耗项
  8. *
  9. * field start
  10. * @property int $id 主键
  11. * @property int $group_id 消耗组ID,外键关联game_consume_groups表
  12. * @property int $consume_type 消耗类型(1:物品, 2:货币)
  13. * @property int $target_id 目标ID(物品ID、货币ID等,根据consume_type解释)
  14. * @property int $param1 参数1(根据consume_type不同含义,如物品的品质、货币的来源等)
  15. * @property int $param2 参数2(根据consume_type不同含义,如物品的绑定状态、货币的类型等)
  16. * @property int $quantity 数量
  17. * @property array $extra_data 额外数据(JSON格式,可存储特定消耗类型的额外参数)
  18. * @property \Carbon\Carbon $created_at 创建时间
  19. * @property \Carbon\Carbon $updated_at 更新时间
  20. * field end
  21. */
  22. class GameConsumeItem extends ModelCore
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'game_consume_items';
  30. // attrlist start
  31. protected $fillable = [
  32. 'id',
  33. 'group_id',
  34. 'consume_type',
  35. 'target_id',
  36. 'param1',
  37. 'param2',
  38. 'quantity',
  39. 'extra_data',
  40. ];
  41. // attrlist end
  42. /**
  43. * 应该被转换为原生类型的属性
  44. *
  45. * @var array
  46. */
  47. protected $casts = [
  48. 'consume_type' => 'integer',
  49. 'target_id' => 'integer',
  50. 'param1' => 'integer',
  51. 'param2' => 'integer',
  52. 'quantity' => 'integer',
  53. 'extra_data' => 'json',
  54. ];
  55. /**
  56. * 获取消耗项所属的消耗组
  57. *
  58. * @return BelongsTo
  59. */
  60. public function consumeGroup(): BelongsTo
  61. {
  62. return $this->belongsTo(GameConsumeGroup::class, 'group_id', 'id');
  63. }
  64. }