validate([ 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1'], 'button' => ['nullable', 'string'], 'language' => ['nullable', 'string', 'in:zh,vi,en'], 'explain' => ['nullable', 'string'], 'group_id' => ['nullable', 'integer', 'in:0,1'], ]); $result = KeyboardService::paginate($search); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (Exception $e) { return $this->error($e->getCode(), $e->getMessage()); } return $this->success($result); } /** * @api {post} /admin/keyboard/submit 修改回复 * @apiGroup 回复管理 * * @apiUse result * @apiUse header * @apiVersion 1.0.0 * * @apiParam {int} id 回复ID * @apiParam {string} button 关键字 * @apiParam {string} reply 回复内容 * @apiParam {array} buttons 操作按钮组 */ public function store(): JsonResponse { try { $id = request()->input('id'); $validator = [ 'id' => ['required', 'integer'], 'reply' => ['required', 'string'], 'explain' => ['nullable', 'string', 'max:28'], 'language' => ['required', 'string', 'in:zh,vi,en'], 'image' => ['nullable', 'url'], 'button' => ['nullable', 'string', 'max:100'], 'buttons' => ['array'], 'buttons.*' => ['array', 'min:1'], 'buttons.*.*.text' => ['required', 'string', 'min:1'], 'buttons.*.*.url' => ['required', 'string', 'min:1'], ]; if (empty($id)) { unset($validator['id']); $validator['button'] = ['required', 'string', 'min:1', 'max:100']; } $params = request()->validate($validator); $ret = KeyboardService::submit($params); if ($ret['code'] == BaseService::NOT) { throw new Exception($ret['msg'], HttpStatus::CUSTOM_ERROR); } } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (Exception $e) { if ($e->getCode() == HttpStatus::CUSTOM_ERROR) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage()); } return $this->error(intval($e->getCode())); } return $this->success([], $ret['msg']); } /** * @api {post} /admin/keyboard/delete 删除回复 * @apiGroup 回复管理 * * @apiUse result * @apiUse header * @apiVersion 1.0.0 * * @apiParam {int} id 回复ID */ public function destroy(): JsonResponse { $id = request()->post('id'); // 示例:通过 ID 删除回复 $info = KeyboardService::findOne(['id' => $id]); if (!$info) { return $this->error(HttpStatus::CUSTOM_ERROR, '数据不存在'); } if ($info->group_id != 1) return $this->error(HttpStatus::CUSTOM_ERROR, '系统配置禁止删除'); $info->delete(); return $this->success([], '删除成功'); } }