123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- <?php
- namespace app\admin\model;
- use app\common\model\ScoreLog;
- use fast\Random;
- use think\Model;
- class User extends Model
- {
- // 表名
- protected $name = 'user';
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- // 追加属性
- protected $append = [
- 'logintime_text',
- 'is_cool_text',
- 'is_manager_text',
- 'is_stealth_text',
- 'need_check_text',
- ];
- public function getOriginData()
- {
- return $this->origin;
- }
- protected static function init()
- {
- /*self::beforeUpdate(function ($row) {
- $changed = $row->getChangedData();
- //如果有修改密码
- if (isset($changed['password'])) {
- if ($changed['password']) {
- $salt = \fast\Random::alnum();
- $row->password = \app\common\library\Auth::instance()->getEncryptPassword($changed['password'], $salt);
- $row->salt = $salt;
- } else {
- unset($row->password);
- }
- }
- });*/
- /*self::beforeUpdate(function ($row) {
- $changedata = $row->getChangedData();
- if (isset($changedata['score'])) {
- $origin = $row->getOriginData();
- ScoreLog::create(['user_id' => $row['id'], 'score' => $changedata['score'] - $origin['score'], 'before' => $origin['score'], 'after' => $changedata['score'], 'memo' => '管理员变更积分']);
- }
- });*/
- }
- public function getGenderList()
- {
- return ['1' => __('Male'), '0' => __('Female')];
- }
- public function getStatusList()
- {
- return ['normal' => __('Normal'), 'hidden' => __('Hidden'), 'cancel' => __('Cancel')];
- }
- public function getNeedCheckList()
- {
- return [0 => __('Need_check 0'), 1 => __('Need_check 1')];
- }
- public function getNeedCheckTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['need_check']) ? $data['need_check'] : '');
- $list = $this->getNeedCheckList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getPrevtimeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['prevtime'];
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getLogintimeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['logintime'];
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- public function getJointimeTextAttr($value, $data)
- {
- $value = $value ? $value : $data['jointime'];
- return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
- }
- protected function setPrevtimeAttr($value)
- {
- return $value && !is_numeric($value) ? strtotime($value) : $value;
- }
- protected function setLogintimeAttr($value)
- {
- return $value && !is_numeric($value) ? strtotime($value) : $value;
- }
- protected function setJointimeAttr($value)
- {
- return $value && !is_numeric($value) ? strtotime($value) : $value;
- }
- protected function setBirthdayAttr($value)
- {
- return $value ? $value : null;
- }
- public function getIsCoolList()
- {
- return ['0' =>__('Is_cool 0'), '1' =>__('Is_cool 1')];
- }
- public function getIsCoolTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_cool']) ? $data['is_cool'] : '');
- $list = $this->getIsCoolList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getIsManagerList()
- {
- return ['0' =>__('Is_manager 0'), '1' =>__('Is_manager 1')];
- }
- public function getIsManagerTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_manager']) ? $data['is_manager'] : '');
- $list = $this->getIsManagerList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function getIsStealthList()
- {
- return ['0' =>__('Is_stealth 0'), '1' =>__('Is_stealth 1')];
- }
- public function getIsStealthTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['is_stealth']) ? $data['is_stealth'] : '');
- $list = $this->getIsStealthList();
- return isset($list[$value]) ? $list[$value] : '';
- }
- public function noble()
- {
- return $this->belongsTo('app\admin\model\noble\Level', 'noble', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function preuser()
- {
- return $this->belongsTo('app\admin\model\User', 'pre_userid', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function auth()
- {
- return $this->belongsTo('app\admin\model\user\Auth', 'id', 'user_id', [], 'LEFT')->setEagerlyType(0);
- }
- public function age()
- {
- return $this->belongsTo('app\admin\model\Age', 'age_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function constellation()
- {
- return $this->belongsTo('app\admin\model\Constellation', 'constellation_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function getUinqueId($length = 8, $ids = [])
- {
- $newid = Random::build("nozero", $length);
- if (in_array($newid, $ids)) {
- $newid = $this->getUinqueId($length, $ids);
- }
- return $newid;
- }
- /**
- * 生成不重复的随机数字字母组合
- */
- function getUinqueNo($length = 8, $nos = [])
- {
- $newid = Random::build("alnum", $length);
- if (in_array($newid, $nos)) {
- $newid = $this->getUinqueNo($length, $nos);
- }
- return $newid;
- }
- }
|