PromotionInviteReward.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * field end
  10. */
  11. class PromotionInviteReward extends ModelCore
  12. {
  13. /**
  14. * 与模型关联的表名
  15. *
  16. * @var string
  17. */
  18. protected $table = 'promotion_invite_rewards';
  19. /**
  20. * 奖励类型常量
  21. */
  22. const REWARD_TYPE_ITEM = 'item';
  23. const REWARD_TYPE_COIN = 'coin';
  24. const REWARD_TYPE_EXP = 'exp';
  25. /**
  26. * 奖励来源常量
  27. */
  28. const REWARD_SOURCE_REGISTER = 'register';
  29. const REWARD_SOURCE_UPGRADE = 'upgrade';
  30. const REWARD_SOURCE_TASK = 'task';
  31. /**
  32. * 状态常量
  33. */
  34. const STATUS_PENDING = 0;
  35. const STATUS_ISSUED = 1;
  36. const STATUS_EXPIRED = 2;
  37. // attrlist start
  38. protected $fillable = [
  39. ];
  40. // attrlist end
  41. /**
  42. * 获取用户信息
  43. *
  44. * @return BelongsTo
  45. */
  46. public function user()
  47. {
  48. return $this->belongsTo('App\Models\User', 'user_id');
  49. }
  50. /**
  51. * 获取被邀请用户信息
  52. *
  53. * @return BelongsTo
  54. */
  55. public function invitedUser()
  56. {
  57. return $this->belongsTo('App\Models\User', 'invited_user_id');
  58. }
  59. /**
  60. * 获取物品信息(如果奖励类型为物品)
  61. *
  62. * @return BelongsTo|null
  63. */
  64. public function item()
  65. {
  66. if ($this->reward_type != self::REWARD_TYPE_ITEM) {
  67. return null;
  68. }
  69. return $this->belongsTo('App\Module\GameItems\Models\Item', 'reward_id');
  70. }
  71. /**
  72. * 判断奖励是否已发放
  73. *
  74. * @return bool
  75. */
  76. public function isIssued(): bool
  77. {
  78. return $this->status == self::STATUS_ISSUED;
  79. }
  80. /**
  81. * 判断奖励是否已过期
  82. *
  83. * @return bool
  84. */
  85. public function isExpired(): bool
  86. {
  87. return $this->status == self::STATUS_EXPIRED;
  88. }
  89. }