50 lines
1.7 KiB
PHP
50 lines
1.7 KiB
PHP
<?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所有者身份类型不正确!");
|
||
}
|
||
}
|
||
} |