fix:审核模块修改

This commit is contained in:
xjh 2023-07-19 22:09:06 +08:00
parent 9683b9b55f
commit 067f22cec5
10 changed files with 46 additions and 93 deletions

View File

@ -62,6 +62,7 @@ class CodeModule extends BaseController
'code_module_html|html内容' => 'require',
]);
$params['code_module_audit'] = ModelCodeModule::AUDIT_PASS;
$model = ModelCodeModule::create($params, [
'code_module_category_guid',
'code_module_name',

View File

@ -57,7 +57,7 @@ class CodeModuleCategory extends BaseController
'code_module_category_global_mode|全局模式' => 'require',
'code_module_category_library_type|库类型' => 'require',
]);
$params['code_module_category_audit'] = ModelCodeModuleCategory::AUDIT_PASS;
ModelCodeModuleCategory::create($params, [
'code_module_category_name',
'code_module_category_parent_guid',

View File

@ -6,7 +6,6 @@ use app\BaseController;
use app\common\model\Code\CodeModule as ModelCodeModule;
use app\api\logic\Code\CodeModule as LogicCodeModule;
use app\common\model\Token as ModelToken;
use app\common\logic\Code\CodeModuleCategory as CommonLogicCodeModuleCategory;
use app\Request;
use think\Validate;
use think\exception\ValidateException;
@ -42,9 +41,10 @@ class CodeModule extends BaseController
Db::startTrans();
Tool::adminLockTableWrite(['code_module', 'code_module_category']);
BaseModel::setUserGuid(false);
try {
BaseModel::setUserGuid(false);
$params['customer_guid'] = ModelToken::getCurrentCustomer()->customer_guid;
$params['code_module_audit'] = LogicCodeModule::buildCodeModuleAudit($params['code_module_category_guid']);
ModelCodeModule::create($params, [
'code_module_category_guid',
'code_module_name',
@ -94,8 +94,9 @@ class CodeModule extends BaseController
Db::startTrans();
Tool::adminLockTableWrite(['code_module', 'dictionary', 'code_module_category']);
BaseModel::setUserGuid(false);
try {
BaseModel::setUserGuid(false);
$params['code_module_audit'] = LogicCodeModule::buildCodeModuleAudit($params['code_module_category_guid']);
$model->allowField([
'code_module_category_guid',
'code_module_name',

View File

@ -43,6 +43,7 @@ class CodeModuleCategory extends BaseController
]);
BaseModel::setUserGuid(false);
$params['customer_guid'] = ModelToken::getCurrentCustomer()->customer_guid;
$params['code_module_category_audit'] = LogicCodeModuleCategory::buildCodeModuleCategoryAudit($params['code_module_category_library_type']);
LogicCodeModuleCategory::validateAddCodeModuleCategory($params);
ModelCodeModuleCategory::create($params, [
'code_module_category_name',
@ -87,8 +88,9 @@ class CodeModuleCategory extends BaseController
LogicCodeModuleCategory::validateEditCodeModuleCategory($params['code_module_category_guid']);
Db::startTrans();
BaseModel::setUserGuid(false);
try {
BaseModel::setUserGuid(false);
$params['code_module_category_audit'] = LogicCodeModuleCategory::buildCodeModuleCategoryAudit($params['code_module_category_library_type']);
$model->allowField([
'code_module_category_name',
'code_module_category_parent_guid',

View File

@ -3,6 +3,7 @@
namespace app\api\logic\Code;
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
use app\api\logic\Code\CodeModuleCategory as LogicCodeModuleCategory;
use app\common\model\Code\CodeModule as ModelCodeModule;
use app\common\model\Token as ModelToken;
use app\common\exception\Tool;
@ -10,6 +11,24 @@ use app\common\exception\Tool;
class CodeModule
{
/**
* 构建客户代码块初始审核状态
*
* @param string $code_module_category_guid 所属类目guid
* @return int 审核状态
* @date 2023-07-19
* @author xjh
* @since 1.0.0
*/
public static function buildCodeModuleAudit(string $code_module_category_guid): int
{
$category = ModelCodeModuleCategory::find($code_module_category_guid);
if (!$category) {
throwErrorMsg("代码块所属类目不存在!");
}
return LogicCodeModuleCategory::buildCodeModuleCategoryAudit($category->code_module_category_library_type);
}
/**
* 代码块新增验证
*

View File

@ -9,6 +9,24 @@ use app\common\exception\Tool;
class CodeModuleCategory
{
/**
* 构建客户代码类目初始审核状态
*
* @param int $library_type 库类型
* @return int 审核状态
* @date 2023-07-19
* @author xjh
* @since 1.0.0
*/
public static function buildCodeModuleCategoryAudit(int $library_type): int
{
if ($library_type == ModelCodeModuleCategory::LIBRARY_PRIVATE) {
return ModelCodeModuleCategory::AUDIT_PASS;
} else {
return ModelCodeModuleCategory::AUDIT_FAILED;
}
}
/**
* 代码类目新增验证
*

View File

@ -1,50 +0,0 @@
<?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 模型实例
* @param string $op 操作类型 ( add新增 edit编辑 )
* @param int $ibrary_type 库类型
* @return void
* @date 2023-07-12
* @author xjh
* @since 1.0.0
*/
public static function handleOpAudit(BaseModel &$model, string $op, int $ibrary_type = 0): void
{
$model_class = get_class($model);
$table_name = $model->db()->getTable();
$audit_field = "{$table_name}_audit";
if ($ibrary_type == 0) {
$ibrary_type = $model->code_module_category_library_type;
}
switch (ModelToken::getCurrent()->token_type) {
case ModelToken::USER_TYPE: //用户
if ($op == "add") {
//保证用户新增的任意代码类目审核状态为已审核
$model->$audit_field = $model_class::AUDIT_PASS;
}
break;
case ModelToken::CUSTOMER_TYPE: //客户
//客户新增/编辑代码类目时只有库类为私用的权限时,才可默认审核状态为已审核,其余都为待审核
if ($ibrary_type == ModelCodeModuleCategory::LIBRARY_PRIVATE) {
$model->$audit_field = $model_class::AUDIT_PASS;
} else {
$model->$audit_field = $model_class::AUDIT_UNAUDITED;
}
break;
default:
throwErrorMsg("token所有者身份类型不正确!");
}
}
}

View File

@ -1,32 +0,0 @@
<?php
namespace app\common\logic\Code;
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
use app\common\model\Code\CodeModule as ModelCodeModule;
use app\common\exception\Tool;
use app\common\logic\Code\CodeCommon as CommonLogicCodeCommon;
use app\BaseModel;
class CodeModule
{
/**
* 操作时审核状态处理
*
* @param BaseModel &$model 模型实例
* @param string $op 操作类型 ( add新增 edit编辑 )
* @param int $ibrary_type 库类型
* @return void
* @date 2023-07-12
* @author xjh
* @since 1.0.0
*/
public static function handleOpAudit(BaseModel &$model, string $op): void
{
$category = ModelCodeModuleCategory::find($model->code_module_category_guid);
if (!$category) {
throwErrorMsg("类目不存在!");
}
CommonLogicCodeCommon::handleOpAudit($model, $op, $category->code_module_category_library_type);
}
}

View File

@ -11,7 +11,6 @@ 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\CodeModule as CommonLogicCodeModule;
class CodeModule extends BaseModel
{
@ -83,7 +82,6 @@ class CodeModule extends BaseModel
public static function onBeforeInsert(self $model): void
{
Tool::dataAddSortProc($model, ['code_module_category_guid' => $model->code_module_category_guid]);
CommonLogicCodeModule::handleOpAudit($model, 'add');
$model->completeCreateField();
}
@ -93,7 +91,6 @@ class CodeModule extends BaseModel
public static function onBeforeUpdate(self $model): void
{
Tool::dataEditSortProc($model, ['code_module_category_guid' => $model->code_module_category_guid]);
CommonLogicCodeModule::handleOpAudit($model, 'edit');
$model->completeUpdateField();
}

View File

@ -12,7 +12,6 @@ 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
{
@ -93,7 +92,6 @@ class CodeModuleCategory extends BaseModel
public static function onBeforeInsert(self $model): void
{
CommonLogicCodeModuleCategory::onBeforeOpParentGuid($model);
CommonLogicCodeCommon::handleOpAudit($model, 'add');
CommonLogicCodeModuleCategory::validateCategoryInfo($model);
$model->completeCreateField();
}
@ -104,7 +102,6 @@ class CodeModuleCategory extends BaseModel
public static function onBeforeUpdate(self $model): void
{
CommonLogicCodeModuleCategory::onBeforeOpParentGuid($model);
CommonLogicCodeCommon::handleOpAudit($model, 'edit');
CommonLogicCodeModuleCategory::validateCategoryInfo($model);
$model->completeUpdateField();
}