fix:前台客户新增/编辑类目接口完善

This commit is contained in:
xjh 2023-08-10 11:10:33 +08:00
parent 438fc02b89
commit 96f39e6c52
2 changed files with 38 additions and 35 deletions

View File

@ -42,12 +42,8 @@ class CodeModuleCategory extends BaseController
'code_module_category_parent_guid|上级类目guid' => 'require', 'code_module_category_parent_guid|上级类目guid' => 'require',
'code_module_category_name|类目名' => 'require', 'code_module_category_name|类目名' => 'require',
'code_module_category_sort|排序' => 'require', 'code_module_category_sort|排序' => 'require',
'code_module_category_global_mode|全局模式' => 'require',
'code_module_category_library_type|库类型' => 'require',
]); ]);
$params['customer_guid'] = ModelToken::getCurrentCustomer()->customer_guid; LogicCodeModuleCategory::handleAddEditCodeModuleCategory($params, 'add');
$params['code_module_category_audit'] = LogicCodeModuleCategory::buildCodeModuleCategoryAudit($params['code_module_category_library_type']);
LogicCodeModuleCategory::validateAddCodeModuleCategory($params);
$category_create = ModelCodeModuleCategory::create($params, [ $category_create = ModelCodeModuleCategory::create($params, [
'code_module_category_name', 'code_module_category_name',
'code_module_category_parent_guid', 'code_module_category_parent_guid',
@ -89,20 +85,16 @@ class CodeModuleCategory extends BaseController
try { try {
$params = $request->param(); $params = $request->param();
$this->validate($params, [ $this->validate($params, [
'code_module_category_parent_guid|上级类目guid' => 'require',
'code_module_category_guid|类目' => 'require',
'code_module_category_name|类目名' => 'require', 'code_module_category_name|类目名' => 'require',
'code_module_category_sort|排序' => 'require', 'code_module_category_sort|排序' => 'require',
'code_module_category_global_mode|全局模式' => 'require',
'code_module_category_library_type|库类型' => 'require',
'code_module_category_guid|类目' => 'require',
'code_module_category_parent_guid|上级类目guid' => 'require',
]); ]);
$model = ModelCodeModuleCategory::where('code_module_category_guid', $params['code_module_category_guid'])->find(); $model = ModelCodeModuleCategory::where('code_module_category_guid', $params['code_module_category_guid'])->find();
if (!$model) { if (!$model) {
throwErrorMsg("该代码块类目不存在", 1); throwErrorMsg("该代码块类目不存在", 1);
} }
LogicCodeModuleCategory::validateEditCodeModuleCategory($params); LogicCodeModuleCategory::handleAddEditCodeModuleCategory($params, 'edit');
$params['code_module_category_audit'] = LogicCodeModuleCategory::buildCodeModuleCategoryAudit($params['code_module_category_library_type']);
$model->allowField([ $model->allowField([
'code_module_category_name', 'code_module_category_name',
'code_module_category_parent_guid', 'code_module_category_parent_guid',

View File

@ -88,39 +88,50 @@ class CodeModuleCategory
} }
/** /**
* 代码类目新增验证 * 代码类目新增/编辑处理
* *
* @param array $params 新增代码类目的参数 * @param array &$params 新增代码类目的参数
* @param string $op 操作类型(add:新增 edit编辑)
* @return void * @return void
* @date 2023-07-14 * @date 2023-07-14
* @author xjh * @author xjh
* @since 1.0.0 * @since 1.0.0
*/ */
public static function validateAddCodeModuleCategory(array $params): void public static function handleAddEditCodeModuleCategory(array &$params, string $op): void
{ {
if ($params['code_module_category_parent_guid'] != ModelCodeModuleCategory::MASTER_DEFAULT) { //编辑操作时附加当前类目验证
self::validateOpCodeModuleCategoryParent($params['code_module_category_parent_guid']); if ($op == "edit") {
self::validateOpCodeModuleCategory($params['code_module_category_guid']);
} }
//当前操作类目为父级类目(相关值验证)
if ($params['code_module_category_parent_guid'] == ModelCodeModuleCategory::MASTER_DEFAULT) {
//父级类目客户guid获取并填充
$params['customer_guid'] = ModelToken::getCurrentCustomer()->customer_guid;
//全局模式验证
if (!isset($params['code_module_category_global_mode']) || !$params['code_module_category_global_mode']) {
throwErrorMsg("当前新增为父级类目,缺少类目全局模式值");
}
//库类型
if (isset($params['code_module_category_library_type']) && $params['code_module_category_library_type']) {
if (!in_array($params['code_module_category_library_type'], [ModelCodeModuleCategory::LIBRARY_COMMON, ModelCodeModuleCategory::LIBRARY_PRIVATE])) { if (!in_array($params['code_module_category_library_type'], [ModelCodeModuleCategory::LIBRARY_COMMON, ModelCodeModuleCategory::LIBRARY_PRIVATE])) {
throwErrorMsg("客户只可新增私有/公有待审核的代码类目!"); throwErrorMsg("客户只可新增私有/公有待审核的代码类目!");
} }
} else {
throwErrorMsg("当前新增为父级类目,缺少类目库类型值");
}
}
//当前操作类目为子级类目(父子类目共用信息自动填充)
else {
self::validateOpCodeModuleCategoryParent($params['code_module_category_parent_guid']);
$parent = ModelCodeModuleCategory::find($params['code_module_category_parent_guid']);
foreach (ModelCodeModuleCategory::COMMON_INFO_FIELDS as $field) {
$params[$field] = $parent->$field;
}
} }
/** //类目审核状态填充
* 代码类目编辑验证 $params['code_module_category_audit'] = self::buildCodeModuleCategoryAudit($params['code_module_category_library_type']);
*
* @param array $params 编辑代码类目的参数
* @return void
* @date 2023-07-14
* @author xjh
* @since 1.0.0
*/
public static function validateEditCodeModuleCategory(array $params): void
{
if ($params['code_module_category_parent_guid'] != ModelCodeModuleCategory::MASTER_DEFAULT) {
self::validateOpCodeModuleCategoryParent($params['code_module_category_parent_guid']);
}
self::validateOpCodeModuleCategory($params['code_module_category_guid']);
} }
/** /**