fix;完善代码块及类目新增/编辑审核状态统一处理、Token模型层客户角色信息属性方法完善

This commit is contained in:
xjh 2023-07-13 14:56:23 +08:00
parent 0b69fba715
commit 8d6f430d79
5 changed files with 64 additions and 12 deletions

View File

@ -10,30 +10,33 @@ 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 onBeforeInsertAudit(BaseModel &$model, int $ibrary_type = 0): void
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) {
if ($ibrary_type == 0) {
$ibrary_type = $model->code_module_category_library_type;
}
switch (ModelToken::getCurrent()->token_type) {
case ModelToken::USER_TYPE: //用户
//保证用户新增的任意代码类目审核状态为已审核
$model->$audit_field = $model_class::AUDIT_PASS;
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 {

View File

@ -11,21 +11,22 @@ 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 onBeforeInsertAudit(BaseModel &$model): void
public static function handleOpAudit(BaseModel &$model, string $op): void
{
$category = ModelCodeModuleCategory::find($model->code_module_category_guid);
if (!$category) {
throwErrorMsg("类目不存在!");
}
CommonLogicCodeCommon::onBeforeInsertAudit($model, $category->code_module_category_library_type);
CommonLogicCodeCommon::handleOpAudit($model, $op, $category->code_module_category_library_type);
}
}

View File

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

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

View File

@ -6,6 +6,7 @@ use app\BaseModel;
use app\common\arw\adjfut\src\Exception\ErrorMsg;
use app\common\exception\LoginTimeOut;
use app\common\model\User\User;
use app\common\model\Customer\Customer;
use think\facade\Request;
use think\helper\Arr;
use think\model\relation\HasOne;
@ -57,6 +58,12 @@ class Token extends BaseModel
* @var User
*/
private static $user = null;
/**
* 当前客户
*
* @var Customer
*/
private static $customer = null;
/**
* 当前model
*
@ -77,6 +84,19 @@ class Token extends BaseModel
return $this->hasOne(User::class, 'user_guid', 'user_guid');
}
/**
* 客户
*
* @date 2023-07-12
* @example
* @author xjh
* @since 1.0.0
*/
public function customer(): hasOne
{
return $this->hasOne(Customer::class, 'customer_guid', 'user_guid');
}
/**
* 设置过期时间
*
@ -249,6 +269,9 @@ class Token extends BaseModel
{
if (!self::$user) {
$model = self::getCurrent();
if ($model->token_type != self::USER_TYPE) {
throw new ErrorMsg("当前token不是用户", 1);
}
self::$user = $model->user;
if (!self::$user) {
throw new ErrorMsg("用户不存在", 1);
@ -257,6 +280,29 @@ class Token extends BaseModel
return self::$user;
}
/**
* 获取当前客户信息
*
* @date 2023-07-12
* @example
* @author xjh
* @since 1.0.0
*/
public static function getCurrentCustomer(): Customer
{
if (!self::$customer) {
$model = self::getCurrent();
if ($model->token_type != self::CUSTOMER_TYPE) {
throw new ErrorMsg("当前token不是客户", 1);
}
self::$customer = $model->customer;
if (!self::$customer) {
throw new ErrorMsg("客户不存在", 1);
}
}
return self::$customer;
}
/**
* 获取当前有效token
*
@ -343,4 +389,4 @@ class Token extends BaseModel
$this->token_type,
]) . time());
}
}
}