ItemDismantleLog.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 $dates = [
  51. 'dismantle_time',
  52. 'created_at',
  53. ];
  54. /**
  55. * 应该被转换为原生类型的属性
  56. *
  57. * @var array
  58. */
  59. protected $casts = [
  60. 'quantity' => 'integer',
  61. 'results' => TransactionDetailsCast::class,
  62. 'coin_returned' => 'integer',
  63. ];
  64. /**
  65. * 获取关联的物品
  66. *
  67. * @return BelongsTo
  68. */
  69. public function item(): BelongsTo
  70. {
  71. return $this->belongsTo(Item::class, 'item_id');
  72. }
  73. /**
  74. * 获取关联的物品实例(如果有)
  75. *
  76. * @return BelongsTo
  77. */
  78. public function instance(): BelongsTo
  79. {
  80. return $this->belongsTo(ItemInstance::class, 'instance_id');
  81. }
  82. /**
  83. * 获取关联的分解规则
  84. *
  85. * @return BelongsTo
  86. */
  87. public function rule(): BelongsTo
  88. {
  89. return $this->belongsTo(ItemDismantleRule::class, 'rule_id');
  90. }
  91. }