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['money'])) { $origin = $row->getOriginData(); if($origin['money']-$changedata['money']>0){ $money=$origin['money']-$changedata['money']; }else{ $money=$changedata['money']-$origin['money']; } MoneyLog::create(['user_id' => $row['id'], 'money' =>$money , 'before' => $origin['money'], 'after' => $changedata['money'], 'memo' => '管理员变更金额']); } if (isset($changedata['score'])) { $origin = $row->getOriginData(); if($origin['score']-$changedata['score']>0){ $score=$origin['score']-$changedata['score']; }else{ $score=$changedata['score']-$origin['score']; } ScoreLog::create(['user_id' => $row['id'], 'score' => $score, 'before' => $origin['score'], 'after' => $changedata['score'], 'memo' => '管理员变更积分']); } }); } public function getGenderList() { return ['1' => __('Male'), '0' => __('Female')]; } public function getStatusList() { return ['normal' => __('Normal'), 'hidden' => __('Hidden')]; } 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; } public function group() { return $this->belongsTo('UserGroup', 'group_id', 'id', [], 'LEFT')->setEagerlyType(0); } // public function address() // { // return $this->belongsTo('UserUsdtAddress', 'uid')->setEagerlyType(0); // } }