fix:代码块类目模型层父子类目共用信息字段常量名更替、新增编辑后的父子数据共用信息处理逻辑
This commit is contained in:
parent
71f2e376b7
commit
a2f352ac6f
@ -86,7 +86,6 @@ class CodeModuleCategory extends BaseController
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_name|类目名' => 'require',
|
||||
'code_module_category_parent_guid|父级guid' => 'require',
|
||||
'code_module_category_sort|排序' => 'require',
|
||||
'code_module_category_global_mode|全局模式' => 'require',
|
||||
'code_module_category_library_type|库类型' => 'require',
|
||||
@ -95,17 +94,24 @@ class CodeModuleCategory extends BaseController
|
||||
if (!$model) {
|
||||
throwErrorMsg("该代码块类目不存在", 1);
|
||||
}
|
||||
$model->allowField([
|
||||
'code_module_category_name',
|
||||
'code_module_category_parent_guid',
|
||||
'code_module_category_sort',
|
||||
'code_module_category_global_mode',
|
||||
'code_module_category_library_type',
|
||||
'customer_guid',
|
||||
'code_module_category_audit',
|
||||
'code_module_category_update_user_guid'
|
||||
])->save($params);
|
||||
return msg('编辑成功!');
|
||||
Db::startTrans();
|
||||
try {
|
||||
$model->allowField([
|
||||
'code_module_category_name',
|
||||
'code_module_category_parent_guid',
|
||||
'code_module_category_sort',
|
||||
'code_module_category_global_mode',
|
||||
'code_module_category_library_type',
|
||||
'customer_guid',
|
||||
'code_module_category_audit',
|
||||
'code_module_category_update_user_guid'
|
||||
])->save($params);
|
||||
Db::commit();
|
||||
return msg('编辑成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,7 +151,7 @@ class CodeModuleCategory extends BaseController
|
||||
$this->validate($params, [
|
||||
'code_module_category_guid|类目guid' => 'require',
|
||||
]);
|
||||
$find = ModelCodeModuleCategory::field(ModelCodeModuleCategory::Common_INFO_FIELDS)->find($params['code_module_category_guid']);
|
||||
$find = ModelCodeModuleCategory::field(ModelCodeModuleCategory::COMMON_INFO_FIELDS)->find($params['code_module_category_guid']);
|
||||
if (!$find) {
|
||||
throwErrorMsg("该类目不存在!");
|
||||
}
|
||||
|
@ -8,6 +8,28 @@ use app\common\model\Token as ModelToken;
|
||||
|
||||
class CodeModuleCategory
|
||||
{
|
||||
/**
|
||||
* 编辑后父子数据共用信息处理
|
||||
*
|
||||
* @param ModelCodeModuleCategory &$model
|
||||
* @return void
|
||||
* @date 2023-07-07
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function onAfterUpdateCommonInfoFields(ModelCodeModuleCategory &$model): void
|
||||
{
|
||||
//为主级类目时才执行
|
||||
//该方法目的是保持父子类目的共用信息一致
|
||||
if ($model->code_module_category_parent_guid == ModelCodeModuleCategory::MASTER_DEFAULT) {
|
||||
$update_data = [];
|
||||
foreach (ModelCodeModuleCategory::COMMON_INFO_FIELDS as $field) {
|
||||
$update_data[$field] = $model->$field;
|
||||
}
|
||||
ModelCodeModuleCategory::where('code_module_category_parent_guid', $model->code_module_category_guid)->select()->update($update_data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增前审核状态处理
|
||||
*
|
||||
@ -19,7 +41,7 @@ class CodeModuleCategory
|
||||
*/
|
||||
public static function onBeforeInsertAudit(ModelCodeModuleCategory &$model): void
|
||||
{
|
||||
switch (ModelToken::getCurrent()->token_type == ModelToken::USER_TYPE) {
|
||||
switch (ModelToken::getCurrent()->token_type) {
|
||||
case ModelToken::USER_TYPE: //用户
|
||||
//保证用户新增的任意代码类目审核状态为已审核
|
||||
$model->code_module_category_audit = ModelCodeModuleCategory::AUDIT_PASS;
|
||||
@ -38,7 +60,7 @@ class CodeModuleCategory
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增前父级(上级类目)guid处理
|
||||
* 新增/编辑前父级(上级类目)guid处理
|
||||
*
|
||||
* @param ModelCodeModuleCategory $model
|
||||
* @return void
|
||||
@ -46,7 +68,7 @@ class CodeModuleCategory
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function onBeforeInsertParentGuid(ModelCodeModuleCategory $model): void
|
||||
public static function onBeforeOpParentGuid(ModelCodeModuleCategory $model): void
|
||||
{
|
||||
if (isset($model->code_module_category_parent_guid) && $model->code_module_category_parent_guid) {
|
||||
if ($model->code_module_category_parent_guid == $model->code_module_category_guid) {
|
||||
@ -83,12 +105,11 @@ class CodeModuleCategory
|
||||
if (!$parent_category) {
|
||||
throwErrorMsg("上级类目不存在!");
|
||||
}
|
||||
foreach (ModelCodeModuleCategory::Common_INFO_FIELDS as $field) {
|
||||
foreach (ModelCodeModuleCategory::COMMON_INFO_FIELDS as $field) {
|
||||
if ($model->$field != $parent_category->$field) {
|
||||
throwErrorMsg("父子类目共用信息{$field}未完全相同! ");
|
||||
}
|
||||
}
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,7 +80,7 @@ class CodeModuleCategory extends BaseModel
|
||||
//父级主键字段
|
||||
public $parent_guid_field = 'code_module_category_parent_guid';
|
||||
//父子类目共用信息字段
|
||||
const Common_INFO_FIELDS = [
|
||||
const COMMON_INFO_FIELDS = [
|
||||
'code_module_category_global_mode',
|
||||
'code_module_category_library_type',
|
||||
'customer_guid'
|
||||
@ -91,7 +91,7 @@ class CodeModuleCategory extends BaseModel
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
CommonLogicCodeModuleCategory::onBeforeInsertParentGuid($model);
|
||||
CommonLogicCodeModuleCategory::onBeforeOpParentGuid($model);
|
||||
CommonLogicCodeModuleCategory::onBeforeInsertAudit($model);
|
||||
CommonLogicCodeModuleCategory::validateCategoryInfo($model);
|
||||
$model->completeCreateField();
|
||||
@ -102,11 +102,20 @@ class CodeModuleCategory extends BaseModel
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
CommonLogicCodeModuleCategory::onBeforeInsertParentGuid($model);
|
||||
CommonLogicCodeModuleCategory::onBeforeOpParentGuid($model);
|
||||
CommonLogicCodeModuleCategory::validateCategoryInfo($model);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新后
|
||||
*/
|
||||
public static function onAfterUpdate(self $model): void
|
||||
{
|
||||
CommonLogicCodeModuleCategory::onAfterUpdateCommonInfoFields($model);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除前
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user