validate([ 'title' => ['nullable', 'string'], 'permission_name' => ['nullable', 'string'], ]); $search = request()->all(); $result = KeyboardService::paginate($search); } catch (ValidationException $e) { return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors()); } catch (Exception $e) { return $this->error(intval($e->getCode())); } 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 操作按钮组 * @apiExample {js} button 示例 * //button 的数据格式如下 * [ * [ //第一行 * { //第一行按钮 的第一个按钮 * "text": "百度", //按钮文字 * "url": "https://baidu.com" //按钮跳转的链接 * }, * { //第一行按钮 的第二个按钮 * "text": "百度", * "url": "https://baidu.com" * } * //更多按钮... * ], * [ //第二行 * { * "text": "百度", * "url": "https://baidu.com" * } * ] * //更多行... * ] */ public function store() { // try { $params = request()->all(); $validator = [ // 'name' => 'required|string|max:50|alpha_dash', // 'name' => 'required|string|max:50|alpha_dash|unique:keyboards,name', 'button' => 'required|nullable|string|max:100', 'reply' => 'required|nullable|string', ]; request()->validate($validator); $ret = KeyboardService::submit($params); if ($ret['code'] == KeyboardService::NOT) { return $this->error($ret['code'], $ret['msg']); } // } catch (ValidationException $e) { // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors()); // } catch (Exception $e) { // 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() { $id = request()->post('id'); // 示例:通过 ID 删除回复 $info = KeyboardService::findOne(['id' => $id]); if (!$info) { return $this->error(0, '数据不存在'); } $info->delete(); return $this->success([], '删除成功'); } }