get(); $model = new AdminModel(); $model->setPage($input['page'] ?? 1); $model->setPageSize($input['pageSize'] ?? 10); if ($this->isAdmin()) { $where = []; } else { $where[] = ['a.status', '=', $model::NORMAL]; } if (!empty($input['name'])) { $where[] = ['a.name', 'like', "%{$input['name']}%"]; } if (!empty($input['mobile'])) { $where[] = ['a.mobile', 'like', "%{$input['mobile']}%"]; } $model->setWhere($where); $data = $model->getAdminList(); Until::output($data); } /** * @OA\Post(path="/api/Admin/save", * tags={"管理员管理"}, * summary="保存管理员信息", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="管理员名称", property="name", type="string", default="jack"), * @OA\Property(description="登入账号", property="account", type="string", default="admin01"), * @OA\Property(description="登入密码", property="password", type="string", default="123465"), * @OA\Property(description="手机号", property="mobile", type="string", default="12367897654"), * @OA\Property(description="角色id-单选", property="roleId", type="integer", default="1"), * @OA\Property(description="集团id-多选", property="groupIds", type="string", default="1,2"), * @OA\Property(description="门店id-多选", property="storeIds", type="string", default="1,2"), * @OA\Property(description="mac地址", property="macAdress", type="string", default="1,2"), * @OA\Property(description="管理员id", property="id", type="string", default="0"), * required={"name","account","mobile","roleId","groupIds","storeIds"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function save() { $input = Until::getInput(); $rule = [ 'name|管理员名称' => 'require', 'account|登入账号' => 'require', 'mobile|手机号' => 'require', 'roleId|角色id' => 'require', 'storeIds|门店id' => 'require', 'groupIds|集团id' => 'require', ]; Until::check($rule, $input); $model = new AdminModel(); if (!empty($input['id'])) { $id = (int)$input['id']; try { $model->startTrans(); $model::where(['id' => $id])->update([ 'name' => $input['name'], 'account' => $input['account'], 'role_id' => $input['roleId'], 'mobile' => $input['mobile'], 'status' => $input['status'] ?? 1, ]); $model->saveStoreRole($input['storeIds'], $id, true); $model->saveGroupRole($input['groupIds'], $id,true); }catch (\Exception $e){ $model->rollback(); throw new ApiException($e->getMessage()); } } else { if (empty($input['password'])) { throw new ApiException('密码不为空'); } try { $model->startTrans(); $id = $model->insertGetId([ 'name' => $input['name'], 'account' => $input['account'], 'role_id' => $input['roleId'], 'password' => md5($input['password'] . '-Bjx14Nb3Le9ghOmM'), 'mobile' => $input['mobile'], 'status' => $input['status'] ?? 1, 'mac_address' => $input['macAddress'] ?? '' ]); $model->saveStoreRole($input['storeIds'], (int)$id); $model->saveGroupRole($input['groupIds'], (int)$id); $model->commit(); } catch (Exception $e) { $model->rollback(); throw new ApiException($e->getMessage()); } } $where[] = ['a.id', '=', (int)$id]; $model->setWhere($where); $info = $model->getAdminInfo(); Until::output(['info' => $info]); } /** * @OA\Post(path="/api/Admin/login", * tags={"管理员管理"}, * summary="管理员登入", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\RequestBody( * @OA\MediaType( * mediaType="multipart/form-data", * @OA\Schema( * @OA\Property(description="登入账号", property="account", type="string", default="admin"), * @OA\Property(description="登入密码", property="password", type="string", default="123456"), * @OA\Property(description="登入密码", property="password", type="string", default="akjs"), * required={"account","password,code"}) * ) * ), * @OA\Response(response="200", description="请求成功") * ) */ public function login() { $input = Until::getInput(); $rule = [ 'account|用户名' => 'require', 'password|内容' => 'require', 'code|验证码' => 'require' ]; Until::check($rule, $input); if( !captcha_check($input['code'] )) { // 验证失败 throw new ApiException('验证码错误'); } $model = (new AdminModel()); $where[] = ['a.account', '=', $input['account']]; $where[] = ['a.password', '=', $input['password']]; $model->setWhere($where); $info = $model->getAdminInfo(); if (empty($info)) { throw new ApiException('账号或密码错误'); } $tokenService = new \app\common\until\Token(); $token = $tokenService->getToken($info['id'],'',true); Until::output(['token' => $token, 'info' => $info]); } public function logout() { Until::output(['name' => 'tom']); } /** * @OA\GET(path="/api/Admin/read", * tags={"管理员管理"}, * summary="查看管理员个人信息", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="id", in="query", description="管理员id", @OA\Schema(type="ineger")), * @OA\RequestBody( * ), * @OA\Response(response="200", description="请求成功") * ) */ public function read($id) { $model = new AdminModel(); $where[] = ['a.id', '=', (int)$id]; $model->setWhere($where); $info = $model->getAdminInfo(); Until::output(['info' => $info]); } /** * 保存更新的资源 * * @param \think\Request $request * @param int $id * @return \think\Response */ public function update(Request $request, $id) { // } /** * @OA\GET(path="/api/Admin/delete", * tags={"管理员管理"}, * summary="删除管理员信息", * @OA\Parameter(name="token", in="header", description="token", @OA\Schema(type="string")), * @OA\Parameter(name="id", in="query", description="管理员id", @OA\Schema(type="ineger",default="1")), * @OA\Parameter(name="status", in="query", description="1正常 2删除", @OA\Schema(type="ineger",default="1")), * @OA\RequestBody( * ), * @OA\Response(response="200", description="请求成功") * ) */ public function delete($id,$status) { $model = new AdminModel(); $where[] = ['id', '=', (int)$id]; $data = ['status' => (int)$status]; $isSuccess = $model::where($where)->update($data); Until::output(['isSuccess' => $isSuccess]); } /** * @OA\GET(path="/api/Admin/verifyImg", * tags={"管理员管理"}, * summary="生成二维码", * @OA\RequestBody( * ), * @OA\Response(response="200", description="请求成功") * ) */ public function verifyImg() { $captcha = new Captcha(); return $captcha->entry(); } }