| // +------------------------------------------------+ 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(); }); } /** * 格式化 最后登录时间 * @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); } /** * 用户资料 */ protected function info() { return $this->hasOne('MemberInfo', 'uid', 'id'); } /** * 关联 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(); } }