ItemCraftLog.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 $recipe_id 配方ID,外键关联kku_item_recipes表
  13. * @property \App\Module\GameItems\Casts\TransactionDetailsCast $materials 消耗的材料,以JSON格式存储
  14. * @property int $result_item_id 获得的物品ID,外键关联kku_item_items表
  15. * @property int $result_instance_id 获得的单独属性物品ID,外键关联kku_item_instances表(可为空)
  16. * @property int $result_quantity 获得的物品数量
  17. * @property bool $is_success 是否成功(0:失败, 1:成功)
  18. * @property \Carbon\Carbon $craft_time 合成时间
  19. * @property string $ip_address 操作的IP地址
  20. * @property string $device_info 设备信息
  21. * @property \Carbon\Carbon $created_at 创建时间
  22. * field end
  23. */
  24. class ItemCraftLog extends ModelCore
  25. {
  26. /**
  27. * 与模型关联的表名
  28. *
  29. * @var string
  30. */
  31. protected $table = 'item_craft_logs';
  32. /**
  33. * 指示模型是否应该被打上时间戳
  34. * 由于这是日志表,只需要创建时间,不需要更新时间
  35. *
  36. * @var bool
  37. */
  38. public $timestamps = true;
  39. /**
  40. * 更新时间戳字段名
  41. * 设置为null表示不使用updated_at字段
  42. *
  43. * @var string|null
  44. */
  45. const UPDATED_AT = null;
  46. // attrlist start
  47. protected $fillable = [
  48. 'id',
  49. 'user_id',
  50. 'recipe_id',
  51. 'materials',
  52. 'result_item_id',
  53. 'result_instance_id',
  54. 'result_quantity',
  55. 'is_success',
  56. 'craft_time',
  57. 'ip_address',
  58. 'device_info',
  59. ];
  60. // attrlist end
  61. /**
  62. * 应该被转换为原生类型的属性
  63. *
  64. * @var array
  65. */
  66. protected $casts = [
  67. 'is_success' => 'boolean',
  68. 'materials' => TransactionDetailsCast::class,
  69. 'result_quantity' => 'integer',
  70. 'craft_time' => 'datetime',
  71. 'created_at' => 'datetime',
  72. ];
  73. /**
  74. * 获取关联的配方
  75. *
  76. * @return BelongsTo
  77. */
  78. public function recipe(): BelongsTo
  79. {
  80. return $this->belongsTo(ItemRecipe::class, 'recipe_id');
  81. }
  82. /**
  83. * 获取关联的结果物品
  84. *
  85. * @return BelongsTo
  86. */
  87. public function resultItem(): BelongsTo
  88. {
  89. return $this->belongsTo(Item::class, 'result_item_id');
  90. }
  91. /**
  92. * 获取关联的结果物品实例(如果有)
  93. *
  94. * @return BelongsTo
  95. */
  96. public function resultInstance(): BelongsTo
  97. {
  98. return $this->belongsTo(ItemInstance::class, 'result_instance_id');
  99. }
  100. }