TeamInviteReward.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace App\Module\Promotion\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 $user_id 获得奖励的用户ID
  11. * @property int $invited_user_id 被邀请的用户ID
  12. * @property string $reward_type 奖励类型:item=物品,coin=货币,exp=经验
  13. * @property int $reward_id 奖励ID(物品ID或货币类型ID)
  14. * @property int $reward_amount 奖励数量
  15. * @property string $reward_source 奖励来源:register=注册,upgrade=升级,task=任务
  16. * @property int $status 状态:0=未发放,1=已发放,2=已过期
  17. * @property string $remark 备注
  18. * @property \Carbon\Carbon $created_at 创建时间
  19. * @property \Carbon\Carbon $updated_at 更新时间
  20. * field end
  21. */
  22. class PromotionInviteReward extends ModelCore
  23. {
  24. /**
  25. * 与模型关联的表名
  26. *
  27. * @var string
  28. */
  29. protected $table = 'promotion_invite_rewards';
  30. /**
  31. * 奖励类型常量
  32. */
  33. const REWARD_TYPE_ITEM = 'item';
  34. const REWARD_TYPE_COIN = 'coin';
  35. const REWARD_TYPE_EXP = 'exp';
  36. /**
  37. * 奖励来源常量
  38. */
  39. const REWARD_SOURCE_REGISTER = 'register';
  40. const REWARD_SOURCE_UPGRADE = 'upgrade';
  41. const REWARD_SOURCE_TASK = 'task';
  42. /**
  43. * 状态常量
  44. */
  45. const STATUS_PENDING = 0;
  46. const STATUS_ISSUED = 1;
  47. const STATUS_EXPIRED = 2;
  48. // attrlist start
  49. protected $fillable = [
  50. 'id',
  51. 'user_id',
  52. 'invited_user_id',
  53. 'reward_type',
  54. 'reward_id',
  55. 'reward_amount',
  56. 'reward_source',
  57. 'status',
  58. 'remark',
  59. ];
  60. // attrlist end
  61. /**
  62. * 获取用户信息
  63. *
  64. * @return BelongsTo
  65. */
  66. public function user()
  67. {
  68. return $this->belongsTo('App\Models\User', 'user_id');
  69. }
  70. /**
  71. * 获取被邀请用户信息
  72. *
  73. * @return BelongsTo
  74. */
  75. public function invitedUser()
  76. {
  77. return $this->belongsTo('App\Models\User', 'invited_user_id');
  78. }
  79. /**
  80. * 获取物品信息(如果奖励类型为物品)
  81. *
  82. * @return BelongsTo|null
  83. */
  84. public function item()
  85. {
  86. if ($this->reward_type != self::REWARD_TYPE_ITEM) {
  87. return null;
  88. }
  89. return $this->belongsTo('App\Module\GameItems\Models\Item', 'reward_id');
  90. }
  91. /**
  92. * 判断奖励是否已发放
  93. *
  94. * @return bool
  95. */
  96. public function isIssued(): bool
  97. {
  98. return $this->status == self::STATUS_ISSUED;
  99. }
  100. /**
  101. * 判断奖励是否已过期
  102. *
  103. * @return bool
  104. */
  105. public function isExpired(): bool
  106. {
  107. return $this->status == self::STATUS_EXPIRED;
  108. }
  109. }