ItemCraftLog.php 2.6 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 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. /**
  53. * 应该被转换为日期的属性
  54. *
  55. * @var array
  56. */
  57. protected $dates = [
  58. 'craft_time',
  59. 'created_at',
  60. ];
  61. /**
  62. * 应该被转换为原生类型的属性
  63. *
  64. * @var array
  65. */
  66. protected $casts = [
  67. 'is_success' => 'boolean',
  68. 'materials_used' => TransactionDetailsCast::class,
  69. 'result_quantity' => 'integer',
  70. ];
  71. /**
  72. * 获取关联的配方
  73. *
  74. * @return BelongsTo
  75. */
  76. public function recipe(): BelongsTo
  77. {
  78. return $this->belongsTo(ItemRecipe::class, 'recipe_id');
  79. }
  80. /**
  81. * 获取关联的结果物品
  82. *
  83. * @return BelongsTo
  84. */
  85. public function resultItem(): BelongsTo
  86. {
  87. return $this->belongsTo(Item::class, 'result_item_id');
  88. }
  89. /**
  90. * 获取关联的结果物品实例(如果有)
  91. *
  92. * @return BelongsTo
  93. */
  94. public function resultInstance(): BelongsTo
  95. {
  96. return $this->belongsTo(ItemInstance::class, 'result_instance_id');
  97. }
  98. }