mirror of
https://github.com/crmeb/CRMEB.git
synced 2026-10-28 21:40:50 +00:00
【程序目录】refactor(adminapi/setting): 重构系统配置相关接口逻辑
1. 重构控制器构造函数参数命名,统一服务层依赖注入 2. 拆分表单构建方法,将createFormRule改为addFieldForm和editFieldForm 3. 重构表单验证规则处理逻辑,将必填、正则、数字范围合并为JSON存储 4. 新增参数合法性校验,包括最小值不大于最大值、参数ID合法性检查 5. 优化表单字段校验规则,统一新增、编辑接口的字段处理逻辑 6. 更新部分服务层调用方法名,调整表单默认参数 7. 新增文档配置项,补充项目规则说明
This commit is contained in:
parent
7797336273
commit
50ac735ac3
@ -1,3 +1,7 @@
|
||||
---
|
||||
alwaysApply: false
|
||||
description:
|
||||
---
|
||||
# CRMEB 项目专属 Chat 规则
|
||||
|
||||
## 1. 项目概述
|
||||
|
||||
@ -26,16 +26,18 @@ use think\facade\App;
|
||||
*/
|
||||
class SystemConfig extends AuthController
|
||||
{
|
||||
/** @var SystemConfigServices */
|
||||
protected $services;
|
||||
|
||||
/**
|
||||
* SystemConfig constructor.
|
||||
* @param App $app
|
||||
* @param SystemConfigServices $services
|
||||
* @param SystemConfigServices $configServices
|
||||
*/
|
||||
public function __construct(App $app, SystemConfigServices $services)
|
||||
public function __construct(App $app, SystemConfigServices $configServices)
|
||||
{
|
||||
parent::__construct($app);
|
||||
$this->services = $services;
|
||||
$this->services = $configServices;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -75,7 +77,7 @@ class SystemConfig extends AuthController
|
||||
[['type', 'd'], ''],
|
||||
[['tab_id', 'd'], 1]
|
||||
], true);
|
||||
return app('json')->success($this->services->createFormRule($type, $tabId));
|
||||
return app('json')->success($this->services->addFieldForm($type, $tabId));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -91,7 +93,10 @@ class SystemConfig extends AuthController
|
||||
['config_tab_id', 0],
|
||||
['parameter', ''],
|
||||
['upload_type', 1],
|
||||
['required', ''],
|
||||
['required', 0],
|
||||
['rule', ''], // 输入框验证
|
||||
['min', null], // 数字最小值
|
||||
['max', null], // 数字最大值
|
||||
['width', 0],
|
||||
['high', 0],
|
||||
['value', ''],
|
||||
@ -109,10 +114,7 @@ class SystemConfig extends AuthController
|
||||
if ($data['sort'] < 0) {
|
||||
$data['sort'] = 0;
|
||||
}
|
||||
if ($data['type'] == 'text') {
|
||||
if (!$data['width']) return app('json')->fail('请输入文本框的宽度');
|
||||
if ($data['width'] <= 0) return app('json')->fail('请输入正确的文本框的宽度');
|
||||
}
|
||||
|
||||
if ($data['type'] == 'textarea') {
|
||||
if (!$data['width']) return app('json')->fail('请输入多行文本框的宽度');
|
||||
if (!$data['high']) return app('json')->fail('请输入多行文本框的高度');
|
||||
@ -123,11 +125,36 @@ class SystemConfig extends AuthController
|
||||
if (!$data['parameter']) return app('json')->fail('请输入配置参数');
|
||||
$this->services->valiDateRadioAndCheckbox($data);
|
||||
}
|
||||
// 关联顶级选项
|
||||
if ($data['level'] == 1) {
|
||||
if (!$data['link_data']) return app('json')->fail('请选择关联顶级选项');
|
||||
$data['link_id'] = $data['link_data'][0];
|
||||
$data['link_value'] = $data['link_data'][1];
|
||||
}
|
||||
// 合并必填、格式规则和数字范围为 JSON 格式
|
||||
$requiredRules = [];
|
||||
if ($data['required']) {
|
||||
$requiredRules['required'] = true;
|
||||
} else {
|
||||
$requiredRules['required'] = false;
|
||||
}
|
||||
if ($data['rule']) {
|
||||
$requiredRules['regex'] = $data['rule'];
|
||||
}
|
||||
if ($data['type'] == 'text' && $data['input_type'] == 'number') {
|
||||
if ($data['min'] !== null) {
|
||||
$requiredRules['min'] = (int)$data['min'];
|
||||
}
|
||||
if ($data['max'] !== null) {
|
||||
$requiredRules['max'] = (int)$data['max'];
|
||||
}
|
||||
}
|
||||
// min不能大于max
|
||||
if ($data['min'] !== null && $data['max'] !== null && $data['min'] > $data['max']) {
|
||||
return app('json')->fail('最小值不能大于最大值');
|
||||
}
|
||||
$data['required'] = json_encode($requiredRules);
|
||||
unset($data['rule'], $data['min'], $data['max']);
|
||||
$data['value'] = json_encode($data['value']);
|
||||
$config = $this->services->getOne(['menu_name' => $data['menu_name']]);
|
||||
if ($config) {
|
||||
@ -162,7 +189,10 @@ class SystemConfig extends AuthController
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return app('json')->success($this->services->editConfigForm((int)$id));
|
||||
if (!$id) {
|
||||
return app('json')->fail('参数错误');
|
||||
}
|
||||
return app('json')->success($this->services->editFieldForm((int)$id));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -187,7 +217,10 @@ class SystemConfig extends AuthController
|
||||
['config_tab_id', 0],
|
||||
['parameter', ''],
|
||||
['upload_type', 1],
|
||||
['required', ''],
|
||||
['required', 0],
|
||||
['regex', ''], // 输入框验证
|
||||
['min', ''], // 数字最小值
|
||||
['max', ''], // 数字最大值
|
||||
['width', 0],
|
||||
['high', 0],
|
||||
['value', $value],
|
||||
@ -202,6 +235,33 @@ class SystemConfig extends AuthController
|
||||
if (!$this->services->get($id)) {
|
||||
return app('json')->fail('数据不存在');
|
||||
}
|
||||
// 合并必填、格式规则和数字范围为 JSON 格式
|
||||
$requiredRules = [];
|
||||
if ($data['required']) {
|
||||
$requiredRules['required'] = true;
|
||||
} else {
|
||||
$requiredRules['required'] = false;
|
||||
}
|
||||
// 正则表达式验证
|
||||
if ($data['regex']) {
|
||||
$requiredRules['regex'] = $data['regex'];
|
||||
}
|
||||
// 数字类型额外保存 min 和 max
|
||||
if ($data['type'] == 'text' && $data['input_type'] == 'number') {
|
||||
if ($data['min'] !== '') {
|
||||
$requiredRules['min'] = (int)$data['min'];
|
||||
}
|
||||
if ($data['max'] !== '') {
|
||||
$requiredRules['max'] = (int)$data['max'];
|
||||
}
|
||||
}
|
||||
// min不能大于max
|
||||
if ($data['min'] !== '' && $data['max'] !== '' && $data['min'] > $data['max']) {
|
||||
return app('json')->fail('最小值不能大于最大值');
|
||||
}
|
||||
$data['required'] = json_encode($requiredRules);
|
||||
unset($data['regex'], $data['min'], $data['max']);
|
||||
// 关联选项
|
||||
if ($data['level'] == 1) {
|
||||
if (!$data['link_data']) return app('json')->fail('请选择关联顶级选项');
|
||||
$data['link_id'] = $data['link_data'][0];
|
||||
@ -282,9 +342,11 @@ class SystemConfig extends AuthController
|
||||
if (isset($post['extract_type']) && !count($post['extract_type'])) {
|
||||
return app('json')->fail('提现方式最少选一种');
|
||||
}
|
||||
// 检查佣金绑定状态
|
||||
if (isset($post['store_brokerage_binding_status'])) {
|
||||
$this->services->checkBrokerageBinding($post);
|
||||
}
|
||||
// 检查一级返佣比例和二级返佣比例是否大于100%
|
||||
if (isset($post['store_brokerage_ratio']) && isset($post['store_brokerage_two'])) {
|
||||
$num = $post['store_brokerage_ratio'] + $post['store_brokerage_two'];
|
||||
if ($num > 100) {
|
||||
@ -526,7 +588,7 @@ class SystemConfig extends AuthController
|
||||
*/
|
||||
public function get_config_list($tabId)
|
||||
{
|
||||
$list = $this->services->getConfigTabAllList($tabId);
|
||||
$list = $this->services->getReadList($tabId);
|
||||
$data = [];
|
||||
foreach ($list as $item) {
|
||||
$data[$item['menu_name']] = json_decode($item['value']);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user