|
@@ -0,0 +1,143 @@
|
|
|
|
|
+<?php
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+namespace App\Http\Controllers\admin;
|
|
|
|
|
+
|
|
|
|
|
+use App\Constants\HttpStatus;
|
|
|
|
|
+use App\Http\Controllers\Controller;
|
|
|
|
|
+use App\Services\KeyboardService;
|
|
|
|
|
+use Exception;
|
|
|
|
|
+
|
|
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
|
+use Illuminate\Validation\ValidationException;
|
|
|
|
|
+
|
|
|
|
|
+class Keyboard extends Controller
|
|
|
|
|
+{
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @api {get} /admin/keyboard 回复列表
|
|
|
|
|
+ * @apiGroup 回复管理
|
|
|
|
|
+ *
|
|
|
|
|
+ * @apiUse result
|
|
|
|
|
+ * @apiUse header
|
|
|
|
|
+ * @apiVersion 1.0.0
|
|
|
|
|
+ *
|
|
|
|
|
+ * @apiParam {int} [page=1]
|
|
|
|
|
+ * @apiParam {int} [limit=10]
|
|
|
|
|
+ * @apiParam {string} [button] 关键字
|
|
|
|
|
+ *
|
|
|
|
|
+ * @apiSuccess (data) {Object} data
|
|
|
|
|
+ * @apiSuccess (data) {int} data.total 数量
|
|
|
|
|
+ * @apiSuccess (data) {Object[]} data.data 列表
|
|
|
|
|
+ * @apiSuccess (data) {int} data.data.id
|
|
|
|
|
+ * @apiSuccess (data) {string} data.data.button 回复关键字
|
|
|
|
|
+ * @apiSuccess (data) {string} data.data.replay 回复内容
|
|
|
|
|
+ * @apiSuccess (data) {string} data.data.updated_at
|
|
|
|
|
+ * @apiSuccess (data) {string} data.data.created_at
|
|
|
|
|
+ */
|
|
|
|
|
+ public function index()
|
|
|
|
|
+ {
|
|
|
|
|
+ try {
|
|
|
|
|
+ request()->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([], '删除成功');
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|