| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace App\Module\Promotion\Models;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use UCore\ModelCore;
- /**
- * 邀请码使用记录
- *
- * field start
- * @property int $id 主键ID
- * @property string $code 使用的邀请码
- * @property int $code_owner_id 邀请码所有者用户ID
- * @property int $user_id 使用邀请码的用户ID
- * @property string $ip_address 使用时的IP地址
- * @property string $user_agent 使用时的用户代理
- * @property int $status 状态:0=失败,1=成功,2=已撤销
- * @property string $result 使用结果描述
- * @property string $remark 备注
- * @property \Carbon\Carbon $created_at 创建时间
- * @property \Carbon\Carbon $updated_at 更新时间
- * field end
- */
- class PromotionReferralCodeUsage extends ModelCore
- {
- /**
- * 与模型关联的表名
- *
- * @var string
- */
- protected $table = 'promotion_referral_code_usages';
- /**
- * 状态常量
- */
- const STATUS_FAILED = 0;
- const STATUS_SUCCESS = 1;
- const STATUS_REVOKED = 2;
- // attrlist start
- protected $fillable = [
- 'id',
- 'code',
- 'code_owner_id',
- 'user_id',
- 'ip_address',
- 'user_agent',
- 'status',
- 'result',
- 'remark',
- ];
- // attrlist end
- /**
- * 获取邀请码信息
- *
- * @return BelongsTo
- */
- public function referralCode()
- {
- return $this->belongsTo(PromotionReferralCode::class, 'code', 'code');
- }
- /**
- * 获取邀请码所有者信息
- *
- * @return BelongsTo
- */
- public function codeOwner()
- {
- return $this->belongsTo('App\Models\User', 'code_owner_id');
- }
- /**
- * 获取使用者信息
- *
- * @return BelongsTo
- */
- public function user()
- {
- return $this->belongsTo('App\Models\User', 'user_id');
- }
- /**
- * 判断使用是否成功
- *
- * @return bool
- */
- public function isSuccess(): bool
- {
- return $this->status == self::STATUS_SUCCESS;
- }
- /**
- * 判断使用是否已撤销
- *
- * @return bool
- */
- public function isRevoked(): bool
- {
- return $this->status == self::STATUS_REVOKED;
- }
- }
|