GameRewardItem.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Module\Game\Models;
  3. use App\Module\Game\Enums\REWARD_TYPE;
  4. use Illuminate\Database\Eloquent\Relations\BelongsTo;
  5. use UCore\ModelCore;
  6. /**
  7. * 奖励项
  8. *
  9. * field start
  10. * @property int $id 主键
  11. * @property int $group_id 奖励组ID,外键关联game_reward_groups表
  12. * @property int $reward_type 奖励类型(1:物品, 2:货币, 3:宠物经验, 4:宠物体力, 5:其他)
  13. * @property int $target_id 目标ID(物品ID、货币ID等,根据reward_type解释)
  14. * @property int $param1 参数1(根据reward_type不同含义,如物品的品质、货币的来源等)
  15. * @property int $param2 参数2(根据reward_type不同含义,如物品的绑定状态、货币的类型等)
  16. * @property int $quantity 数量
  17. * @property int $min_quantity 最小数量(NULL表示使用quantity字段)
  18. * @property int $max_quantity 最大数量(NULL表示使用quantity字段)
  19. * @property float $weight 权重(随机发放时使用)
  20. * @property float $probability 获得概率(百分比,0-100,NULL表示使用权重机制)
  21. * @property bool $is_guaranteed 是否必中(0:非必中, 1:必中)
  22. * @property array $extra_data 额外数据(JSON格式,可存储特定奖励类型的额外参数)
  23. * @property \Carbon\Carbon $created_at 创建时间
  24. * @property \Carbon\Carbon $updated_at 更新时间
  25. * field end
  26. */
  27. class GameRewardItem extends ModelCore
  28. {
  29. /**
  30. * 与模型关联的表名
  31. *
  32. * @var string
  33. */
  34. protected $table = 'game_reward_items';
  35. // attrlist start
  36. protected $fillable = [
  37. 'id',
  38. 'group_id',
  39. 'reward_type',
  40. 'target_id',
  41. 'param1',
  42. 'param2',
  43. 'quantity',
  44. 'min_quantity',
  45. 'max_quantity',
  46. 'weight',
  47. 'probability',
  48. 'is_guaranteed',
  49. 'extra_data',
  50. ];
  51. // attrlist end
  52. /**
  53. * 应该被转换为原生类型的属性
  54. *
  55. * @var array
  56. */
  57. protected $casts = [
  58. 'reward_type' => 'integer',
  59. 'target_id' => 'integer',
  60. 'param1' => 'integer',
  61. 'param2' => 'integer',
  62. 'quantity' => 'integer',
  63. 'weight' => 'float',
  64. 'probability' => 'float',
  65. 'min_quantity' => 'integer',
  66. 'max_quantity' => 'integer',
  67. 'is_guaranteed' => 'boolean',
  68. 'extra_data' => 'json',
  69. ];
  70. /**
  71. * 获取奖励项所属的奖励组
  72. *
  73. * @return BelongsTo
  74. */
  75. public function rewardGroup(): BelongsTo
  76. {
  77. return $this->belongsTo(GameRewardGroup::class, 'group_id', 'id');
  78. }
  79. }