| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 | <?phpnamespace app\admin\controller;use app\admin\AdminBaseController;use app\common\model\UserFollowModel;use app\common\model\UserModel;use app\admin\validate\UserValidate;use think\exception\ValidateException;class User extends AdminBaseController{    /**     * 用户列表     */    public function index()    {        $gender_list    = UserModel::GENDER;        $gender_list[0] = '全部';        return view('', [            'status_list' => UserModel::STATUS,            'gender_list' => $gender_list,        ]);    }    public function listUser()    {        $map   = $this->dealEqualInput(['gender', 'status'], $this->dealLikeInput(['keywords' => 'account|nickname|realname', 'mobile']));        $list  = UserModel::where($map)            ->order('id', 'desc')            ->limit(input('limit'))            ->page(input('page'))            ->append(['status_text', 'gender_text'])->select();        $count = UserModel::where($map)->count();        if ($count == 0) {            ajax_return(1, '未查询到数据');        }        list_return($list, $count);    }    /**     * 用户跟进记录     */    public function follow()    {        $id   = input('id/d');        $user = UserModel::find($id);        $list = UserFollowModel::where('user_id', $id)->order('id', 'desc')->limit(100)->select();        return view('', [            'user'      => $user,            'list'      => $list,            'type_list' => UserFollowModel::TYPE,        ]);    }    public function editFollow()    {        $id   = input('id/d', 0);        $user = UserModel::find($id);        if (empty($user)) {            ajax_return(1, '用户信息不存在。');        }        UserFollowModel::create([            'user_id' => $id,            'type'    => input('type/d', 1),            'remark'  => input('remark/s', ""),        ]);        ajax_return();    }    /**     * 编辑用户     */    public function userForm()    {        $id   = input('id/d', 0);        $info = UserModel::find($id);        return view('', [            'info'        => $info,            'gender_list' => UserModel::GENDER,            'status_list' => UserModel::STATUS,        ]);    }    public function editUser()    {        $data = input('post.');        try {            validate(UserValidate::class)->check($data);        } catch (ValidateException $e) {            ajax_return(1, $e->getError());        }        //用户名        $check_account_where = [['account', '=', $data['account']]];        if (!empty($data['id'])) {            $check_account_where[] = ['id', '<>', $data['id']];        }        $check_account = UserModel::where($check_account_where)->find();        if (!empty($check_account)) {            ajax_return(1, '用户名已存在');        }        //手机号        $check_mobile_where = [['mobile', '=', $data['mobile']]];        if (!empty($data['id'])) {            $check_mobile_where[] = ['id', '<>', $data['id']];        }        $check_mobile = UserModel::where($check_mobile_where)->find();        if (!empty($check_mobile)) {            ajax_return(1, '手机号已存在');        }        //密码        if (empty($data['id']) && empty($data['password'])) {            ajax_return(1, '请输入一个初始密码');        }        if (empty($data['password'])) {            unset($data['password']);        } else {            $data['salt']     = rand_str();            $data['password'] = md5(md5($data['salt']) . $data['password']);        }        if (empty($data['id'])) {            UserModel::create($data);        } else {            UserModel::update($data, ['id' => $data['id']]);        }        ajax_return();    }}
 |