setWebsite(__NAMESPACE__); $this->isLoginJson(); } public function showList() { $request = Request::instance(); $category_type = $request->post('category_type'); $listObj = DB::table($this->table)->orderBy('created_at'); if ($category_type) { $listObj->where('category_type', $category_type); } $list = $listObj->get(); $list = array_map('get_object_vars', $list->toArray()); return responseMessage(1002, '', $list); } /** * @return JsonResponse */ public function save() { $request = Request::instance(); $id = $request->post('id'); $category_type = $request->post('category_type'); //1 关系数据库 2 非关系数据库 $type = $request->post('type'); // // sqlite mysql pgsql sqlsrv tidb file redis elasticsearch mongodb $title = $request->post('title'); $config_json = $request->post('config_json'); $requestData = [ 'category_type' => $category_type, 'type' => $type, 'title' => $title, 'config_json' => $config_json ]; if ($id) { // 判断是否已经存在 $isExist = ES::table($this->table) ->where('title', $title) ->where('type', $type) ->mustNot(function ($query) use ($id){ $query->where('id', $id); }) ->count(); if ($isExist) { return responseMessage(2001, '该标题已经存在,不允许重复添加!'); } $isSuccess = ES::table($this->table)->updateEntityById($id, $requestData); } else { // 判断是否已经存在 $isExist = ES::table($this->table)->where('title', $title)->where('type', $type)->count(); if ($isExist) { return responseMessage(2002, '该标题已经存在,不允许重复添加!'); } $isSuccess = ES::table($this->table)->insertGetId($requestData); } if ($isSuccess) { return responseMessage(1001, '添加成功!'); } else { return responseMessage(2003, '添加失败,请重试!'); } } }