ItemCraftLog.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 object|array $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 int $is_success 是否成功(0:失败, 1:成功)
  18. * @property string $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. // attrlist start
  33. protected $fillable = [
  34. 'id',
  35. 'user_id',
  36. 'recipe_id',
  37. 'materials',
  38. 'result_item_id',
  39. 'result_instance_id',
  40. 'result_quantity',
  41. 'is_success',
  42. 'craft_time',
  43. 'ip_address',
  44. 'device_info',
  45. ];
  46. // attrlist end
  47. /**
  48. * 可批量赋值的属性
  49. *
  50. * @var array
  51. */
  52. protected $fillable = [
  53. 'user_id',
  54. 'recipe_id',
  55. 'is_success',
  56. 'materials_used',
  57. 'result_item_id',
  58. 'result_instance_id',
  59. 'result_quantity',
  60. 'craft_time',
  61. 'ip_address',
  62. 'device_info',
  63. ];
  64. /**
  65. * 应该被转换为日期的属性
  66. *
  67. * @var array
  68. */
  69. protected $dates = [
  70. 'craft_time',
  71. 'created_at',
  72. ];
  73. /**
  74. * 应该被转换为原生类型的属性
  75. *
  76. * @var array
  77. */
  78. protected $casts = [
  79. 'is_success' => 'boolean',
  80. 'materials_used' => TransactionDetailsCast::class,
  81. 'result_quantity' => 'integer',
  82. ];
  83. /**
  84. * 获取关联的配方
  85. *
  86. * @return BelongsTo
  87. */
  88. public function recipe(): BelongsTo
  89. {
  90. return $this->belongsTo(ItemRecipe::class, 'recipe_id');
  91. }
  92. /**
  93. * 获取关联的结果物品
  94. *
  95. * @return BelongsTo
  96. */
  97. public function resultItem(): BelongsTo
  98. {
  99. return $this->belongsTo(ItemItem::class, 'result_item_id');
  100. }
  101. /**
  102. * 获取关联的结果物品实例(如果有)
  103. *
  104. * @return BelongsTo
  105. */
  106. public function resultInstance(): BelongsTo
  107. {
  108. return $this->belongsTo(ItemInstance::class, 'result_instance_id');
  109. }
  110. }