request->get('size', config('apiadmin.ADMIN_LIST_DEFAULT')); $start = $this->request->get('page', 1); $listObj = (new ConfigModel())->where('delete_time', 0) ->withoutField('delete_time, content') ->paginate(['page' => $start, 'list_rows' => $limit]) ->toArray(); return $this->buildSuccess([ 'list' => $listObj['data'], 'count' => $listObj['total'], ]); } catch (\Exception $e) { return $this->buildFailed(ReturnCode::RECORD_NOT_FOUND, $e->getMessage()); } } /** * 新增字段 * @return Response * @author zhaoxiang */ public function add(): Response { try { $postData = $this->request->post(); $id = $postData['id'] ?? ''; validate(ConfigValidate::class)->scene($id ? 'edit' : 'add')->check($postData); $data = []; if (isset($postData['title'])) { $data['title'] = $postData['title']; } if (isset($postData['name'])) { $data['name'] = $postData['name']; } if (isset($postData['status'])) { $data['status'] = $postData['status']; } if (isset($postData['content'])) { $data['content'] = json_encode($postData['content']); } if ($id) { $data['update_time'] = time(); ConfigModel::update($data, ['id' => $id]); } else { $data['create_time'] = time(); ConfigModel::create($data); } return $this->buildSuccess(); } catch (\Exception $e) { return $this->buildFailed(ReturnCode::CACHE_SAVE_ERROR, $e->getMessage()); } } /** * 编辑添加数据 * @return Response */ public function editIndex(): Response { try { $id = $this->request->get('id', ''); if (!$id) throw new \Exception('缺少必填参数'); $data = (new ConfigModel())->withoutField('delete_time, update_time')->where('id', $id)->where('delete_time', 0)->find()->toArray(); $data['content'] = $data['content'] ? json_decode($data['content'], true) : $data['content']; return $this->buildSuccess([ 'data' => $data ]); } catch (\Exception $e) { return $this->buildFailed(ReturnCode::NOT_EXISTS, $e->getMessage()); } } }