fix:代码模块新增前审核状态统一处理

This commit is contained in:
xjh 2023-07-12 09:19:15 +08:00
parent 55c74b0f6f
commit 7bc8cc0d9a
5 changed files with 47 additions and 33 deletions

View File

@ -62,9 +62,6 @@ class CodeModule extends BaseController
'code_module_html|html内容' => 'require',
]);
// 后台添加默认通过审核
$params['code_module_audit'] = "2";
$model = ModelCodeModule::create($params, [
'code_module_category_guid',
'code_module_name',

View File

@ -0,0 +1,43 @@
<?php
namespace app\common\logic\Code;
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
use app\common\model\Token as ModelToken;
use app\BaseModel;
class CodeCommon
{
/**
* 新增前审核状态处理
*
* @param BaseModel &$model 模型实例
* @return void
* @date 2023-07-12
* @author xjh
* @since 1.0.0
*/
public static function onBeforeInsertAudit(BaseModel &$model): void
{
$model_class = get_class($model);
$table_name = $model->db()->getTable();
$audit_field = "{$table_name}_audit";
switch (ModelToken::getCurrent()->token_type) {
case ModelToken::USER_TYPE: //用户
//保证用户新增的任意代码类目审核状态为已审核
$model->$audit_field = $model_class::AUDIT_PASS;
break;
case ModelToken::CUSTOMER_TYPE: //客户
//客户新增代码类目时只有库类为私用的权限时,才可默认审核状态为已审核,其余都为待审核
if ($model->code_module_category_library_type == $model_class::LIBRARY_PRIVATE) {
$model->$audit_field = $model_class::AUDIT_PASS;
} else {
$model->$audit_field = $model_class::AUDIT_UNAUDITED;
}
break;
default:
throwErrorMsg("token所有者身份类型不正确!");
}
}
}

View File

@ -34,35 +34,6 @@ class CodeModuleCategory
}
}
/**
* 新增前审核状态处理
*
* @param ModelCodeModuleCategory &$model
* @return void
* @date 2023-06-28
* @author xjh
* @since 1.0.0
*/
public static function onBeforeInsertAudit(ModelCodeModuleCategory &$model): void
{
switch (ModelToken::getCurrent()->token_type) {
case ModelToken::USER_TYPE: //用户
//保证用户新增的任意代码类目审核状态为已审核
$model->code_module_category_audit = ModelCodeModuleCategory::AUDIT_PASS;
break;
case ModelToken::CUSTOMER_TYPE: //客户
//客户新增代码类目时只有库类为私用的权限时,才可默认审核状态为已审核,其余都为待审核
if ($model->code_module_category_library_type == ModelCodeModuleCategory::LIBRARY_PRIVATE) {
$model->code_module_category_audit = ModelCodeModuleCategory::AUDIT_PASS;
} else {
$model->code_module_category_audit = ModelCodeModuleCategory::AUDIT_UNAUDITED;
}
break;
default:
throwErrorMsg("token所有者身份类型不正确!");
}
}
/**
* 新增/编辑前父级(上级类目)guid处理
*

View File

@ -11,6 +11,7 @@ use app\common\exception\Tool;
use think\facade\Db;
use app\common\model\Dictionary\Dictionary as ModelDictionary;
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
use app\common\logic\Code\CodeCommon as CommonLogicCodeCommon;
class CodeModule extends BaseModel
{
@ -82,6 +83,7 @@ class CodeModule extends BaseModel
public static function onBeforeInsert(self $model): void
{
Tool::dataAddSortProc($model);
CommonLogicCodeCommon::onBeforeInsertAudit($model);
$model->completeCreateField();
}

View File

@ -12,6 +12,7 @@ use think\facade\Db;
use app\common\model\Token as ModelToken;
use app\common\model\Dictionary\Dictionary as ModelDictionary;
use app\common\logic\Code\CodeModuleCategory as CommonLogicCodeModuleCategory;
use app\common\logic\Code\CodeCommon as CommonLogicCodeCommon;
class CodeModuleCategory extends BaseModel
{
@ -92,7 +93,7 @@ class CodeModuleCategory extends BaseModel
public static function onBeforeInsert(self $model): void
{
CommonLogicCodeModuleCategory::onBeforeOpParentGuid($model);
CommonLogicCodeModuleCategory::onBeforeInsertAudit($model);
CommonLogicCodeCommon::onBeforeInsertAudit($model);
CommonLogicCodeModuleCategory::validateCategoryInfo($model);
$model->completeCreateField();
}