124 lines
2.9 KiB
PHP
124 lines
2.9 KiB
PHP
<?php
|
||
// +------------------------------------------------+
|
||
// |http://www.cjango.com |
|
||
// +------------------------------------------------+
|
||
// | 修复BUG不是一朝一夕的事情,等我喝醉了再说吧! |
|
||
// +------------------------------------------------+
|
||
// | Author: 小陈叔叔 <Jason.Chen> |
|
||
// +------------------------------------------------+
|
||
namespace app\common\model;
|
||
|
||
use think\Config as Conf;
|
||
use think\Request;
|
||
use tools\Crypt;
|
||
|
||
class Member extends _Init
|
||
{
|
||
protected $readonly = [''];
|
||
|
||
/**
|
||
* 模型初始化【事件注册】
|
||
*/
|
||
protected static function init()
|
||
{
|
||
self::beforeInsert(function ($data) {
|
||
$data->reg_ip = Request::instance()->ip();
|
||
$data->status = 1;
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 格式化 最后登录时间
|
||
* @param [type] $value 最后登录时间 时间戳
|
||
*/
|
||
protected function getLastTimeAttr($value)
|
||
{
|
||
return date(Conf::get('database.datetime_format'), $value);
|
||
}
|
||
|
||
/**
|
||
* 加密密码
|
||
* @param [type] $value [description]
|
||
*/
|
||
protected function setPasswordAttr($value)
|
||
{
|
||
return Crypt::uMd5($value);
|
||
}
|
||
|
||
/**
|
||
* 用户资料
|
||
*/
|
||
public function info()
|
||
{
|
||
return $this->hasOne('MemberInfo', 'uid', 'id');
|
||
}
|
||
|
||
public function account()
|
||
{
|
||
return $this->hasOne('Account', 'uid', 'id');
|
||
}
|
||
|
||
public function logs($type = '')
|
||
{
|
||
if ($type) {
|
||
return $this->belongsTo('AccountLogs', 'id', 'uid')->where('type', $type);
|
||
} else {
|
||
return $this->belongsTo('AccountLogs', 'id', 'uid');
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 关联 AuthUser 表
|
||
* @return [type] [description]
|
||
*/
|
||
public function authUser()
|
||
{
|
||
return $this->hasOne('AuthUser', 'uid', 'id');
|
||
}
|
||
|
||
public function getJuniorAttr($value, $data)
|
||
{
|
||
return MemberList::where('uid', $data['id'])->count();
|
||
}
|
||
|
||
public function getVipIsEmptyAttr($value, $data)
|
||
{
|
||
switch ($data['empty_vip']) {
|
||
case '0':
|
||
return "";
|
||
break;
|
||
case '1':
|
||
return "<span style='color:red' > 是 </span>";
|
||
break;
|
||
default:
|
||
return "";
|
||
break;
|
||
}
|
||
}
|
||
|
||
public function getAgentIsEmptyAttr($value, $data)
|
||
{
|
||
switch ($data['empty_agent']) {
|
||
case '0':
|
||
return "";
|
||
break;
|
||
case '1':
|
||
return "<span style='color:red' > 是 </span>";
|
||
break;
|
||
default:
|
||
return "";
|
||
break;
|
||
}
|
||
}
|
||
|
||
public function puser()
|
||
{
|
||
return $this->hasOne('Member', 'id', 'pid');
|
||
}
|
||
|
||
public function childs()
|
||
{
|
||
return $this->hasMany('Member', 'pid', 'id');
|
||
}
|
||
}
|