init: 项目初始代码
This commit is contained in:
145
app/api/controller/v1/SystemConfig.php
Normal file
145
app/api/controller/v1/SystemConfig.php
Normal file
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace app\api\controller\v1;
|
||||
|
||||
use app\api\model\SystemConfig as SystemConfigModel;
|
||||
use app\api\validate\SystemConfig as SystemConfigValidate;
|
||||
/**
|
||||
* 系统配置
|
||||
*/
|
||||
class SystemConfig extends Base
|
||||
{
|
||||
public function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
$this->model = new SystemConfigModel();
|
||||
$this->validate = new SystemConfigValidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 列表
|
||||
*/
|
||||
public function index():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->getIndexList($this->page,$this->size,$this->field, $this->simple, $this->focus,$this->order);
|
||||
if (isset($result['data']) && !empty($result['data'])) {
|
||||
foreach ($result['data'] as $key => $item) {
|
||||
if (!empty($item['image'])) {
|
||||
$result['data'][$key]['image'] = json_decode($item['image'],true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
public function read():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param(['id']);
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
$result = $this->model->getInfo($inputData);
|
||||
if ($result['type'] == 2 || $result['type'] == 4) {
|
||||
// 处理图片
|
||||
if (isset($result['image']) && !empty($result['image'])) {
|
||||
$result['image'] = json_decode($result['image'],true);
|
||||
} else {
|
||||
$result['image'] = [];
|
||||
}
|
||||
}
|
||||
|
||||
if ($result) {
|
||||
$result['language_id'] = $result['site_id'];
|
||||
return $this->msg(200,'获取列表成功',$result);
|
||||
} else {
|
||||
return $this->msg(200,'获取列表成功',[]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
public function create():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
//语言包
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
|
||||
if (isset($inputData['site_id']) || !empty($inputData['site_id']) || $inputData['site_id'] != 0) {
|
||||
$this->focus['site_id'] = $inputData['site_id'];
|
||||
} else {
|
||||
return $this->msg(504,'语言包/所属站点参数,不正确,请检查!');
|
||||
}
|
||||
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
// 处理图片
|
||||
if (isset($inputData['image']) && !empty($inputData['image'])) {
|
||||
$inputData['image'] = json_encode($inputData['image']);
|
||||
}
|
||||
|
||||
$result = $this->model->addData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'新增成功');
|
||||
} else {
|
||||
return $this->msg(504,'新增失败');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
public function update():\think\Response\Json
|
||||
{
|
||||
$inputData = $this->request->param();
|
||||
if (isset($inputData['language_id']) && $inputData['language_id'] != 0 && $inputData['language_id'] != '') {
|
||||
$this->focus['site_id'] = $inputData['site_id'] = $inputData['language_id'];
|
||||
unset($inputData['language_id']);
|
||||
}
|
||||
|
||||
$inputData['platform_id'] = $this->platformId;
|
||||
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
|
||||
return $this->msg(-1,$this->validate->getError());
|
||||
}
|
||||
|
||||
// 处理图片
|
||||
if (isset($inputData['image']) && !empty($inputData['image'])) {
|
||||
$inputData['image'] = json_encode($inputData['image']);
|
||||
}
|
||||
|
||||
$result = $this->model->editData($inputData);
|
||||
|
||||
if ($result) {
|
||||
return $this->msg(200,'更改成功');
|
||||
} else {
|
||||
return $this->msg(504,'更改失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user