ItemDismantleLog.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Module\GameItems\Models;
  3. use App\Module\GameItems\Casts\TransactionDetailsCast;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use UCore\ModelCore;
  6. /**
  7. * 物品分解记录
  8. *
  9. * field start
  10. * @property int $id 记录ID,主键
  11. * @property int $user_id 用户ID
  12. * @property int $item_id 被分解的物品ID,外键关联kku_item_items表
  13. * @property int $instance_id 被分解的单独属性物品ID,外键关联kku_item_instances表(可为空)
  14. * @property int $quantity 分解数量
  15. * @property int $rule_id 使用的分解规则ID,外键关联kku_item_dismantle_rules表
  16. * @property object|array $results 分解结果,包含获得的物品ID、数量等信息
  17. * @property string $dismantle_time 分解时间
  18. * @property string $ip_address 操作的IP地址
  19. * @property string $device_info 设备信息
  20. * @property \Carbon\Carbon $created_at 创建时间
  21. * field end
  22. */
  23. class ItemDismantleLog extends ModelCore
  24. {
  25. /**
  26. * 与模型关联的表名
  27. *
  28. * @var string
  29. */
  30. protected $table = 'item_dismantle_logs';
  31. // attrlist start
  32. protected $fillable = [
  33. 'id',
  34. 'user_id',
  35. 'item_id',
  36. 'instance_id',
  37. 'quantity',
  38. 'rule_id',
  39. 'results',
  40. 'dismantle_time',
  41. 'ip_address',
  42. 'device_info',
  43. ];
  44. // attrlist end
  45. /**
  46. * 可批量赋值的属性
  47. *
  48. * @var array
  49. */
  50. protected $fillable = [
  51. 'user_id',
  52. 'item_id',
  53. 'instance_id',
  54. 'quantity',
  55. 'rule_id',
  56. 'results',
  57. 'coin_returned',
  58. 'dismantle_time',
  59. 'ip_address',
  60. 'device_info',
  61. ];
  62. /**
  63. * 应该被转换为日期的属性
  64. *
  65. * @var array
  66. */
  67. protected $dates = [
  68. 'dismantle_time',
  69. 'created_at',
  70. ];
  71. /**
  72. * 应该被转换为原生类型的属性
  73. *
  74. * @var array
  75. */
  76. protected $casts = [
  77. 'quantity' => 'integer',
  78. 'results' => TransactionDetailsCast::class,
  79. 'coin_returned' => 'integer',
  80. ];
  81. /**
  82. * 获取关联的物品
  83. *
  84. * @return BelongsTo
  85. */
  86. public function item(): BelongsTo
  87. {
  88. return $this->belongsTo(ItemItem::class, 'item_id');
  89. }
  90. /**
  91. * 获取关联的物品实例(如果有)
  92. *
  93. * @return BelongsTo
  94. */
  95. public function instance(): BelongsTo
  96. {
  97. return $this->belongsTo(ItemInstance::class, 'instance_id');
  98. }
  99. /**
  100. * 获取关联的分解规则
  101. *
  102. * @return BelongsTo
  103. */
  104. public function rule(): BelongsTo
  105. {
  106. return $this->belongsTo(ItemDismantleRule::class, 'rule_id');
  107. }
  108. }