| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- namespace App\Module\Promotion\Models;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 邀请奖励记录
- *
- * field start
- * @property int $id 主键ID
- * @property int $user_id 获得奖励的用户ID
- * @property int $invited_user_id 被邀请的用户ID
- * @property string $reward_type 奖励类型:item=物品,coin=货币,exp=经验
- * @property int $reward_id 奖励ID(物品ID或货币类型ID)
- * @property int $reward_amount 奖励数量
- * @property string $reward_source 奖励来源:register=注册,upgrade=升级,task=任务
- * @property int $status 状态:0=未发放,1=已发放,2=已过期
- * @property string $remark 备注
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * 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 = [
- 'id',
- 'user_id',
- 'invited_user_id',
- 'reward_type',
- 'reward_id',
- 'reward_amount',
- 'reward_source',
- 'status',
- 'remark',
- ];
- // 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;
- }
- }
|