Files
huangjingfen/pro_v3.5.1/app/controller/admin/v1/system/config/SystemGroup.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

206 lines
6.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\controller\admin\v1\system\config;
use app\services\system\config\SystemGroupDataServices;
use think\annotation\Inject;
use app\controller\admin\AuthController;
use app\services\system\config\SystemGroupServices;
/**
* 组合数据
* Class SystemGroup
* @package app\controller\admin\v1\setting
*/
class SystemGroup extends AuthController
{
/**
* @var SystemGroupServices
*/
#[Inject]
protected SystemGroupServices $services;
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
$where = $this->request->getMore([
['title', '']
]);
return $this->success($this->services->getGroupList($where));
}
/**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
}
/**
* 保存新建的资源
*
* @return \think\Response
*/
public function save()
{
$params = $this->request->postMore([
['name', ''],
['config_name', ''],
[['cate_id', 'd'], 0],
['info', ''],
['typelist', []],
]);
//数据组名称判断
if (!$params['name']) {
return $this->fail('请输入数据组名称!');
}
if (!$params['config_name']) {
return $this->fail('请输入配置名称!');
}
$data["name"] = $params['name'];
$data["config_name"] = $params['config_name'];
$data["info"] = $params['info'];
$data["cate_id"] = $params['cate_id'];
//字段信息判断
if (!count($params['typelist']))
return $this->fail('字段至少存在一个!');
else {
$validate = ["name", "type", "title", "description"];
foreach ($params["typelist"] as $key => $value) {
foreach ($value as $name => $field) {
if (empty($field["value"]) && in_array($name, $validate))
return $this->fail("字段" . ($key + 1) . "" . $field["placeholder"] . "不能为空!");
else
$data["fields"][$key][$name] = $field["value"];
}
}
}
$data["fields"] = json_encode($data["fields"]);
$this->services->save($data);
\crmeb\services\GroupDataService::clear();
return $this->success('添加数据组成功!');
}
/**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
$info = $this->services->get($id);
$fields = json_decode($info['fields'], true);
$type_list = [];
foreach ($fields as $key => $v) {
$type_list[$key]['name']['value'] = $v['name'];
$type_list[$key]['title']['value'] = $v['title'];
$type_list[$key]['type']['value'] = $v['type'];
$type_list[$key]['param']['value'] = $v['param'];
}
$info['typelist'] = $type_list;
unset($info['fields']);
return $this->success(compact('info'));
}
/**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
}
/**
* 保存更新的资源
*
* @param int $id
* @return \think\Response
*/
public function update($id)
{
$params = $this->request->postMore([
['name', ''],
['config_name', ''],
[['cate_id', 'd'], 0],
['info', ''],
['typelist', []],
]);
//数据组名称判断
if (!$params['name']) return $this->fail('请输入数据组名称!');
if (!$params['config_name']) return $this->fail('请输入配置名称!');
//判断ID是否存在存在就是编辑不存在就是添加
if (!$id) {
if ($this->services->count(['config_name' => $params['config_name']])) {
return $this->fail('数据关键字已存在!');
}
}
$data["name"] = $params['name'];
$data["config_name"] = $params['config_name'];
$data["info"] = $params['info'];
$data["cate_id"] = $params['cate_id'];
//字段信息判断
if (!count($params['typelist']))
return $this->fail('字段至少存在一个!');
else {
$validate = ["name", "type", "title", "description"];
foreach ($params["typelist"] as $key => $value) {
foreach ($value as $name => $field) {
if (empty($field["value"]) && in_array($name, $validate))
return $this->fail("字段" . ($key + 1) . "" . $field["placeholder"] . "不能为空!");
else
$data["fields"][$key][$name] = $field["value"];
}
}
}
$data["fields"] = json_encode($data["fields"]);
$this->services->update($id, $data);
\crmeb\services\GroupDataService::clear();
return $this->success('编辑数据组成功!');
}
/**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id, SystemGroupDataServices $services)
{
if (!$this->services->delete($id))
return $this->fail('删除失败,请稍候再试!');
else {
$services->delete($id, 'gid');
return $this->success('删除成功!');
}
}
/**
* 获取组合数据
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function getGroup()
{
return $this->success($this->services->getGroupList(['cate_id' => 1], ['id', 'name', 'config_name'])['list']);
}
}