where(["is_del" => CommonModel::$del_normal, "username" => $data['username']]) ->findOrEmpty(); if ($res->isEmpty()) return json_show(CommonModel::$error_token, '该账户不存在'); if ($res->status == CommonModel::$status_disable) return json_show(CommonModel::$error_token, '该账户已禁用'); if (get_password($data['password'], $res->salt) != $res->password) return json_show(CommonModel::$error_token, '账户密码错误'); $token = make_token($res->id, $data['username'], $res->salt); $userinfo = [ "username" => $res->username, "nickname" => $res->nickname, "mobile" => $res->mobile, "role_id" => $res->role_id, 'token' => $token ]; // write_log("账户{$account['username']}登录系统","","login","",0); return json_show(0, "登录成功", $userinfo); } //登出 public static function logout(string $token = ''): Json { $info = AdminTokenModel::where(['token' => $token])->save(['token' => '', 'expiretime' => date('Y-m-d H:i:s')]); return $info ? json_show(CommonModel::$success, '登出成功') : json_show(CommonModel::$error_param, '登出失败'); } //上传图片 public static function upload($files): Json { $list = upload_img($files); return (is_array($list) && !empty($list)) ? json_show(CommonModel::$success, '上传成功', $list) : json_show(CommonModel::$error_default, '上传失败'); } //获取全部商品单位 public static function unitAll(string $keyword = ''): Json { $where = [['is_del', '=', CommonModel::$del_normal]]; if ($keyword != '') $where[] = ['unit', 'like', $keyword . '%']; $list = Db::name('unit') ->field('id unit_id,unit unit_title') ->where($where) ->order('id', 'desc') ->select() ->toArray(); return json_show(CommonModel::$success, '获取全部商品单位成功', $list); } //获取省市区地址 public static function getAddr(string $parent_code = ''): Json { $rs = Db::name('area') ->field('id,name,code,level') ->where('parent_code', $parent_code) ->select() ->toArray(); return json_show(CommonModel::$success, '获取省市区地址成功', $rs); } }