|
@@ -47,8 +47,6 @@ class User extends Model
|
|
self::STATUS_UNPASS => '已被封'
|
|
self::STATUS_UNPASS => '已被封'
|
|
];
|
|
];
|
|
|
|
|
|
- const GRADE = ["非会员", "月度会员", "季度会员", "年度会员"];
|
|
|
|
-
|
|
|
|
|
|
|
|
const SEX_UNKNOW = 0;
|
|
const SEX_UNKNOW = 0;
|
|
const SEX_MAN = 1;
|
|
const SEX_MAN = 1;
|
|
@@ -67,75 +65,12 @@ class User extends Model
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
|
- * 是否为会员
|
|
|
|
- * @return bool
|
|
|
|
- */
|
|
|
|
- public function isVip()
|
|
|
|
- {
|
|
|
|
- return !empty($this->level) && !$this->isVipExpire();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 是否过期,如果stop_time为空不算过期
|
|
|
|
- * @return bool
|
|
|
|
- */
|
|
|
|
- public function isVipExpire()
|
|
|
|
- {
|
|
|
|
- if (empty($this->stop_time))
|
|
|
|
- return false;
|
|
|
|
- return $this->stop_time < time();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 是否为代理
|
|
|
|
- * @return bool
|
|
|
|
- */
|
|
|
|
- public function isAgent()
|
|
|
|
- {
|
|
|
|
- return $this->user_cate == self::CATE_AGENT;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 是否为管理
|
|
|
|
- * @return bool
|
|
|
|
- */
|
|
|
|
- public function isManage()
|
|
|
|
- {
|
|
|
|
- return $this->user_cate == self::CATE_MANAGE;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * 计算会员到期时间
|
|
|
|
- * @param $vipId
|
|
|
|
- * @return false|int|mixed
|
|
|
|
- */
|
|
|
|
- public function createStopTime($vipId)
|
|
|
|
- {
|
|
|
|
- $starttime = $this->isVip() ? $this->stop_time : time();
|
|
|
|
- switch ($vipId) {
|
|
|
|
- case 1: //月
|
|
|
|
- return $starttime + 31 * 24 * 3600;
|
|
|
|
- case 2: //季度
|
|
|
|
- return $starttime + 93 * 24 * 3600;
|
|
|
|
- case 3: //年
|
|
|
|
- return strtotime('+1 year', $starttime);
|
|
|
|
- default:
|
|
|
|
- return $starttime;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//nickname
|
|
//nickname
|
|
public function getNicknameAttr($value, $data)
|
|
public function getNicknameAttr($value, $data)
|
|
{
|
|
{
|
|
return htmlspecialchars($value);
|
|
return htmlspecialchars($value);
|
|
}
|
|
}
|
|
|
|
|
|
- //level_text
|
|
|
|
- public function getLevelTextAttr($value, $data)
|
|
|
|
- {
|
|
|
|
- return self::GRADE[$data['level']]??'';
|
|
|
|
- }
|
|
|
|
|
|
|
|
//status_text
|
|
//status_text
|
|
public function getStatusTextAttr($value, $data)
|
|
public function getStatusTextAttr($value, $data)
|
|
@@ -143,20 +78,6 @@ class User extends Model
|
|
return self::STATUS[$data['status']]??'';
|
|
return self::STATUS[$data['status']]??'';
|
|
}
|
|
}
|
|
|
|
|
|
- //stop_time_text
|
|
|
|
- public function getStopTimeTextAttr($value, $data)
|
|
|
|
- {
|
|
|
|
- if (empty($this->level)) {
|
|
|
|
- return '';
|
|
|
|
- }
|
|
|
|
- if (empty($this->stop_time)) {
|
|
|
|
- return '永久';
|
|
|
|
- }
|
|
|
|
- if ($this->stop_time < time()) {
|
|
|
|
- return '已过期';
|
|
|
|
- }
|
|
|
|
- return $this->stop_time ? date('Y-m-d H:i:s', $this->stop_time) : '';
|
|
|
|
- }
|
|
|
|
|
|
|
|
//register_time
|
|
//register_time
|
|
public function getRegisterTimeAttr($value, $data)
|
|
public function getRegisterTimeAttr($value, $data)
|
|
@@ -181,22 +102,4 @@ class User extends Model
|
|
{
|
|
{
|
|
return self::USER_CATES[$data['user_cate']]??"";
|
|
return self::USER_CATES[$data['user_cate']]??"";
|
|
}
|
|
}
|
|
-
|
|
|
|
- //invite_code 邀请码
|
|
|
|
- public function getInviteCodeAttr($value, $data)
|
|
|
|
- {
|
|
|
|
- return inviteEncode($this->id);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //child_count 邀请人数
|
|
|
|
- public function getChildCountAttr()
|
|
|
|
- {
|
|
|
|
- return $this->hasMany('User', 'pid')->where('status', self::STATUS_PASS)->count();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- //推荐人
|
|
|
|
- public function parent()
|
|
|
|
- {
|
|
|
|
- return $this->belongsTo('User', 'pid');
|
|
|
|
- }
|
|
|
|
}
|
|
}
|