You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
user_center/app/Http/Controllers/Api/SystemSettingController.php

194 lines
5.8 KiB

<?php
namespace App\Http\Controllers\Api;
use App\Http\Resources\SystemSetting;
use App\Http\Resources\SystemSettingCollection;
use App\Models\SystemSettingT;
use Illuminate\Http\Request;
/**
* @title 系统设置
* @description 系统设置
* @package App\Http\Controllers\Api
* @author zcstatham
* @time 2021/1/28
*/
class SystemSettingController extends BaseController
{
protected $rules = [
'store' => [
'rules' => [
'title' => 'required|max:20',
'name' => 'bail|required|unique:App\Models\SystemSettingT|max:20',
'data_type' => 'required',
'prop' => 'required',
'content' => 'required',
'sort' => 'integer',
'status' => 'integer',
],
'messages' => [],
],
'show' => [
'rules' => [
'id' => 'bail|inter|min:1',
],
'messages' => [],
'custom' => 'exists,App\Models\SystemSettingT,id'
],
'update' => [
'rules' => [
'id' => 'bail|inter|min:1',
'title' => 'required|max:20',
'name' => 'bail|required|max:20',
'data_type' => 'required',
'prop' => 'required',
'content' => 'required',
'sort' => 'integer',
'status' => 'integer',
],
'messages' => [],
'custom' => [
'exists,App\Models\SystemSettingT,id',
'unique,App\Models\SystemSettingT,name,id'
]
],
'destroy' => [
'rules' => [
'id' => 'bail|inter|min:1',
],
'messages' => [],
'custom' => [
'exists,App\Models\SystemSettingT,id',
]
]
];
public function __construct(Request $request)
{
$this->model = new SystemSettingT();
parent::__construct($request);
}
/**
* @title 配置列表
* @description 配置列表
* @return \Illuminate\Http\JsonResponse
* @author zcstatham
* @time 2021/1/28
*/
public function index()
{
$query = SystemSettingT::query();
if(isset($this->params['prop']) && $this->params['prop'] != ''){
$query->where('prop', $this->params['prop']);
}
if(isset($this->params['group']) && $this->params['group'] != ''){
$query->where('group', $this->params['group']);
}
if(isset($this->params['name']) && $this->params['name'] != ''){
$query->where('name', $this->params['name']);
}
if(isset($this->params['status']) && $this->params['status'] >= 0){
$query->where('status', $this->params['status']);
} else {
$query->where('status', 1);
}
if(isset($this->params['title']) && $this->params['title'] != ''){
$query->where('title', 'like', '%'. $this->params['title'] .'%');
}
$data = $query->paginate();
return $this->success(new SystemSettingCollection($data));
}
/**
* @title 配置新增
* @description 配置新增
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @author zcstatham
* @time 2021/1/28
*/
public function store(Request $request)
{
$setting = new SystemSettingT();
$setting->name = $this->params['name'];
$setting->title = $this->params['title'];
$setting->data_type = $this->params['data_type'];
$setting->prop = $this->params['prop'];
$setting->group = $this->params['group'] ?? '';
$setting->content = $this->params['content'];
$setting->remark = $this->params['remark'] ?? '';
$setting->sort = $this->params['sort'] ?? 1;
$setting->status = $this->params['status'] ?? 1;
if($setting->save()){
return $this->success($setting);
} else {
return $this->error(500, '配置信息保存失败');
}
}
/**
* @title 配置详情
* @description 配置详情
* @param $id
* @return mixed
* @author zcstatham
* @time 2021/1/28
*/
public function show($id)
{
$setting = SystemSettingT::find($id);
return $this->success(new SystemSetting($setting));
}
/**
* @title 配置更新
* @description 配置更新
* @param Request $request
* @param $id
* @return \Illuminate\Http\JsonResponse
* @author zcstatham
* @time 2021/1/28
*/
public function update(Request $request, $id)
{
$setting = SystemSettingT::find($id);
$setting->name = $this->params['name'];
$setting->title = $this->params['title'];
$setting->data_type = $this->params['data_type'];
$setting->prop = $this->params['prop'];
$setting->group = $this->params['group'] ?? $setting->group;
$setting->content = $this->params['content'];
$setting->remark = $this->params['remark'] ?? $setting->remark;
$setting->sort = $this->params['sort'] ?? $setting->sort;
$setting->status = $this->params['status'] ?? $setting->status;
if($setting->save()){
return $this->success(new SystemSetting($setting));
} else {
return $this->error(500, '配置信息保存失败');
}
}
/**
* @title 配置删除
* @description 软删除
* @param $id
* @return \Illuminate\Http\JsonResponse
* @author zcstatham
* @time 2021/1/28
*/
public function destroy($id)
{
$setting = SystemSettingT::find($id);
$setting->status = 0;
if($setting->save()){
return $this->success();
} else {
return $this->error(500, '配置信息保存失败');
}
}
}