| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace App\Module\Promotion\Models;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 邀请奖励记录
- *
- * field start
- * field end
- */
- class PromotionInviteReward extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'promotion_invite_rewards';
- /**
- * 奖励类型常量
- */
- const REWARD_TYPE_ITEM = 'item';
- const REWARD_TYPE_COIN = 'coin';
- const REWARD_TYPE_EXP = 'exp';
- /**
- * 奖励来源常量
- */
- const REWARD_SOURCE_REGISTER = 'register';
- const REWARD_SOURCE_UPGRADE = 'upgrade';
- const REWARD_SOURCE_TASK = 'task';
- /**
- * 状态常量
- */
- const STATUS_PENDING = 0;
- const STATUS_ISSUED = 1;
- const STATUS_EXPIRED = 2;
- // attrlist start
- protected $fillable = [
- ];
- // attrlist end
- /**
- * 获取用户信息
- *
- * @return BelongsTo
- */
- public function user()
- {
- return $this->belongsTo('App\Models\User', 'user_id');
- }
- /**
- * 获取被邀请用户信息
- *
- * @return BelongsTo
- */
- public function invitedUser()
- {
- return $this->belongsTo('App\Models\User', 'invited_user_id');
- }
- /**
- * 获取物品信息(如果奖励类型为物品)
- *
- * @return BelongsTo|null
- */
- public function item()
- {
- if ($this->reward_type != self::REWARD_TYPE_ITEM) {
- return null;
- }
- return $this->belongsTo('App\Module\GameItems\Models\Item', 'reward_id');
- }
- /**
- * 判断奖励是否已发放
- *
- * @return bool
- */
- public function isIssued(): bool
- {
- return $this->status == self::STATUS_ISSUED;
- }
- /**
- * 判断奖励是否已过期
- *
- * @return bool
- */
- public function isExpired(): bool
- {
- return $this->status == self::STATUS_EXPIRED;
- }
- }
|