request->param('flag', 1); $list = ConfigModel::where('flag', $flag)->select(); $select = ConfigModel::getSelect(); foreach ($list as &$item) { if (isset($select[$item['field']])) { $item['select'] = $select[$item['field']]; } } return $this->success(['count' => count($list), 'list' => $list]); } /** * @api {post} /config/update 更新系统配置 */ function update() { DB::startTrans(); try { $id = $this->request->post('id'); if ($id) { $params = (new ConfigValidate())->post()->goCheck('edit'); } else { $params = (new ConfigValidate())->post()->goCheck('add'); } $params['language_code'] = $params['language_code'] ?? 'zh'; // $params['val'] = json_encode($params['val'], JSON_UNESCAPED_UNICODE); if (!empty($id)) { $exist = ConfigModel::where('id', $id)->find(); if (!$exist) { return $this->error('配置不存在'); } ConfigModel::where('id', $id)->update($params); } else { ConfigModel::create($params); } DB::commit(); } catch (Exception $e) { DB::rollBack(); return $this->error($e->getMessage()); } return $this->success(); } }