|
|
|
@ -44,14 +44,21 @@ class Config extends Base |
|
|
|
{ |
|
|
|
try { |
|
|
|
$postData = $this->request->post(); |
|
|
|
$id = $postData['id'] ?? ''; |
|
|
|
$id = $postData['id'] ?? ''; |
|
|
|
validate(ConfigValidate::class)->scene($id ? 'edit' : 'add')->check($postData); |
|
|
|
$data = [ |
|
|
|
'title' => $postData['title'], |
|
|
|
'name' => $postData['name'], |
|
|
|
'status' => $postData['status'], |
|
|
|
'content' => json_encode($postData['content']), |
|
|
|
]; |
|
|
|
$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]); |
|
|
|
@ -74,9 +81,11 @@ class Config extends Base |
|
|
|
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(); |
|
|
|
$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); |
|
|
|
return $this->buildSuccess([ |
|
|
|
'data' => $data |
|
|
|
]); |
|
|
|
} catch (\Exception $e) { |
|
|
|
return $this->buildFailed(ReturnCode::NOT_EXISTS, $e->getMessage()); |
|
|
|
} |
|
|
|
|