fix:代码块新增前审核状态值完善、代码块排序处理完善

This commit is contained in:
xjh 2023-07-12 12:49:05 +08:00
parent 7bc8cc0d9a
commit 0b69fba715
3 changed files with 41 additions and 6 deletions

View File

@ -13,16 +13,20 @@ class CodeCommon
* 新增前审核状态处理
*
* @param BaseModel &$model 模型实例
* @param int $ibrary_type 库类型
* @return void
* @date 2023-07-12
* @author xjh
* @since 1.0.0
*/
public static function onBeforeInsertAudit(BaseModel &$model): void
public static function onBeforeInsertAudit(BaseModel &$model, int $ibrary_type = 0): void
{
$model_class = get_class($model);
$table_name = $model->db()->getTable();
$audit_field = "{$table_name}_audit";
if (!$ibrary_type) {
$ibrary_type = $model->code_module_category_library_type;
}
switch (ModelToken::getCurrent()->token_type) {
case ModelToken::USER_TYPE: //用户
//保证用户新增的任意代码类目审核状态为已审核
@ -30,7 +34,7 @@ class CodeCommon
break;
case ModelToken::CUSTOMER_TYPE: //客户
//客户新增代码类目时只有库类为私用的权限时,才可默认审核状态为已审核,其余都为待审核
if ($model->code_module_category_library_type == $model_class::LIBRARY_PRIVATE) {
if ($ibrary_type == ModelCodeModuleCategory::LIBRARY_PRIVATE) {
$model->$audit_field = $model_class::AUDIT_PASS;
} else {
$model->$audit_field = $model_class::AUDIT_UNAUDITED;

View File

@ -0,0 +1,31 @@
<?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 int $ibrary_type 库类型
* @return void
* @date 2023-07-12
* @author xjh
* @since 1.0.0
*/
public static function onBeforeInsertAudit(BaseModel &$model): void
{
$category = ModelCodeModuleCategory::find($model->code_module_category_guid);
if (!$category) {
throwErrorMsg("类目不存在!");
}
CommonLogicCodeCommon::onBeforeInsertAudit($model, $category->code_module_category_library_type);
}
}

View File

@ -11,7 +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;
use app\common\logic\Code\CodeModule as CommonLogicCodeModule;
class CodeModule extends BaseModel
{
@ -82,8 +82,8 @@ class CodeModule extends BaseModel
*/
public static function onBeforeInsert(self $model): void
{
Tool::dataAddSortProc($model);
CommonLogicCodeCommon::onBeforeInsertAudit($model);
Tool::dataAddSortProc($model, ['code_module_category_guid' => $model->code_module_category_guid]);
CommonLogicCodeModule::onBeforeInsertAudit($model);
$model->completeCreateField();
}
@ -92,7 +92,7 @@ class CodeModule extends BaseModel
*/
public static function onBeforeUpdate(self $model): void
{
Tool::dataEditSortProc($model);
Tool::dataEditSortProc($model, ['code_module_category_guid' => $model->code_module_category_guid]);
$model->completeUpdateField();
}