<?php


namespace app\Admin\controller;
use think\Db;

class User extends Base
{
    public function __construct()
    {
        parent::__construct();
    }


    /**
     *
     */
    public function ResetInfo(){
       $pasword = isset($this->post['password']) && $this->post['password']!="" ? $this->post['password'] :"";
       $data=[];
       if($pasword!=""){
        $data['salt']=makeSalt();
        $data['password']=sha1($pasword.$data['salt']);
       }
       $nickname = isset($this->post['nickname'])&& $this->post['nickname']!="" ? trim($this->post['nickname']):"";
       if($nickname!=""){
           $data['nickname']=$nickname;
       }
        $mobile = isset($this->post['mobile'])&& $this->post['mobile']!="" ? trim($this->post['mobile']):"";
        if($mobile!=""){
            $data['mobile']=$mobile;
        }
        $data['updatetime'] = date("Y-m-d H:i:s");
        $result=Db::name('admin')->where(['id'=>$this->userinfo['id']])->update($data);

        $msg =isset($data['password'])? "修改密码为：{$pasword}":"";
        $msg .=isset($data['nickname'])? "修改昵称为：{$nickname}":"";
        $msg .=isset($data['mobile'])? "修改手机号为：{$mobile}":"";
      if($result){
            write_log("管理员{$this->userinfo['nickname']}修改个人信息成功{$msg}",$this->userinfo,"user","edit");
            return app_show(0,"信息修改成功");
        }else{
            return error_show(1003,"信息修改失败");
        }
    }
    //获取用户信息
    public function UserInfo(){
        return app_show(0,"获取成功",$this->userinfo);
    }
}