ItemRecipeMaterial.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Module\GameItems\Models;
  3. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  4. use UCore\ModelCore;
  5. /**
  6. * 合成配方材料
  7. *
  8. * field start
  9. * @property int $id 记录ID,主键
  10. * @property int $recipe_id 配方ID,外键关联kku_item_recipes表
  11. * @property int $item_id 材料物品ID,外键关联kku_item_items表
  12. * @property int $quantity 所需数量
  13. * @property int $is_consumed 是否消耗(0:不消耗, 1:消耗)
  14. * @property \Carbon\Carbon $created_at 创建时间
  15. * @property \Carbon\Carbon $updated_at 更新时间
  16. * field end
  17. */
  18. class ItemRecipeMaterial extends ModelCore
  19. {
  20. /**
  21. * 与模型关联的表名
  22. *
  23. * @var string
  24. */
  25. protected $table = 'item_recipe_materials';
  26. // attrlist start
  27. protected $fillable = [
  28. 'id',
  29. 'recipe_id',
  30. 'item_id',
  31. 'quantity',
  32. 'is_consumed',
  33. ];
  34. // attrlist end
  35. /**
  36. * 可批量赋值的属性
  37. *
  38. * @var array
  39. */
  40. protected $fillable = [
  41. 'recipe_id',
  42. 'item_id',
  43. 'quantity',
  44. 'is_consumed',
  45. ];
  46. /**
  47. * 应该被转换为原生类型的属性
  48. *
  49. * @var array
  50. */
  51. protected $casts = [
  52. 'quantity' => 'integer',
  53. 'is_consumed' => 'boolean',
  54. ];
  55. /**
  56. * 获取关联的配方
  57. *
  58. * @return BelongsTo
  59. */
  60. public function recipe(): BelongsTo
  61. {
  62. return $this->belongsTo(ItemRecipe::class, 'recipe_id');
  63. }
  64. /**
  65. * 获取关联的物品
  66. *
  67. * @return BelongsTo
  68. */
  69. public function item(): BelongsTo
  70. {
  71. return $this->belongsTo(ItemItem::class, 'item_id');
  72. }
  73. }