214 lines
9.1 KiB
PHP
214 lines
9.1 KiB
PHP
<?php
|
||
|
||
namespace app\api\logic\Code;
|
||
|
||
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
|
||
use app\common\model\Code\CodeModule as ModelCodeModule;
|
||
use app\common\model\Token as ModelToken;
|
||
use app\common\arw\adjfut\src\Exception\ErrorMsg;
|
||
use app\common\exception\Tool;
|
||
use app\common\logic\CustomerMessage\Audit\CodeModuleCategory as CustomerMessageAuditCodeModuleCategory;
|
||
use app\common\logic\CustomerMessage\Audit\CodeModule as CustomerMessageAuditCodeModule;
|
||
|
||
|
||
class CodeModuleCategory
|
||
{
|
||
/**
|
||
* 上传公共类目处理
|
||
*
|
||
* @param string $code_module_category_guid 主级代码类目guid
|
||
* @return void
|
||
* @date 2023-07-20
|
||
* @author xjh
|
||
* @since 1.0.0
|
||
*/
|
||
public static function handleUploadCommonCodeModuleCategory(string $code_module_category_guid): void
|
||
{
|
||
//匿名函数-新增代码类目(用于拷贝送审类目时的值修改及其新增操作)
|
||
$addCategory = function (ModelCodeModuleCategory &$model_category, string $code_module_category_parent_guid = null): ModelCodeModuleCategory {
|
||
return ModelCodeModuleCategory::create([
|
||
'code_module_category_parent_guid' => $code_module_category_parent_guid ?? $model_category->code_module_category_parent_guid,
|
||
'code_module_category_name' => $model_category->code_module_category_name,
|
||
'code_module_category_sort' => 0,
|
||
'code_module_category_global_mode' => $model_category->code_module_category_global_mode,
|
||
'code_module_category_library_type' => ModelCodeModuleCategory::LIBRARY_COMMON,
|
||
'code_module_category_audit' => ModelCodeModuleCategory::AUDIT_UNAUDITED,
|
||
'customer_guid' => $model_category->customer_guid,
|
||
]);
|
||
};
|
||
//匿名函数-新增代码块(用于拷贝送审代码块时的值修改及其新增操作)
|
||
$addModule = function (ModelCodeModule &$model_module, string $code_module_category_guid): void {
|
||
ModelCodeModule::create([
|
||
'code_module_category_guid' => $code_module_category_guid,
|
||
'code_module_audit' => ModelCodeModule::AUDIT_UNAUDITED,
|
||
'code_module_name' => $model_module->code_module_name,
|
||
'code_module_html' => $model_module->code_module_html,
|
||
'code_module_style' => $model_module->code_module_style,
|
||
'code_module_script' => $model_module->code_module_script,
|
||
'code_module_sort' => $model_module->code_module_sort,
|
||
'customer_guid' => $model_module->customer_guid,
|
||
]);
|
||
};
|
||
//主级类目验证
|
||
$category = self::validateMasterCodeModuleCategory($code_module_category_guid, true);
|
||
//主级类目拷贝送审
|
||
$master_category_add = $addCategory($category);
|
||
CustomerMessageAuditCodeModuleCategory::unaudited($master_category_add->code_module_category_guid);
|
||
//子级类目拷贝送审
|
||
$category_sons = ModelCodeModuleCategory::where('code_module_category_parent_guid', $code_module_category_guid)->select();
|
||
foreach ($category_sons as $category_son) {
|
||
$son_category_add = $addCategory($category_son, $master_category_add->code_module_category_guid);
|
||
CustomerMessageAuditCodeModuleCategory::unaudited($son_category_add->code_module_category_guid);
|
||
//各个子级类目的代码块送审
|
||
$code_modules = ModelCodeModule::where('code_module_category_guid', $category_son->code_module_category_guid)->select();
|
||
foreach ($code_modules as $code_module) {
|
||
$addModule($code_module, $son_category_add->code_module_category_guid);
|
||
CustomerMessageAuditCodeModule::unaudited($code_module->code_module_guid);
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
/**
|
||
* 构建客户代码类目初始审核状态
|
||
*
|
||
* @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_UNAUDITED;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 代码类目新增/编辑处理
|
||
*
|
||
* @param array &$params 新增代码类目的参数
|
||
* @param string $op 操作类型(add:新增 edit:编辑)
|
||
* @return void
|
||
* @date 2023-07-14
|
||
* @author xjh
|
||
* @since 1.0.0
|
||
*/
|
||
public static function handleAddEditCodeModuleCategory(array &$params, string $op): void
|
||
{
|
||
//编辑操作时附加当前类目验证
|
||
if ($op == "edit") {
|
||
self::validateOpCodeModuleCategory($params['code_module_category_guid']);
|
||
}
|
||
|
||
//当前操作类目为父级类目(相关值验证)
|
||
if ($params['code_module_category_parent_guid'] == ModelCodeModuleCategory::MASTER_DEFAULT) {
|
||
//父级类目客户guid获取并填充
|
||
$params['customer_guid'] = ModelToken::getCurrentCustomer()->customer_guid;
|
||
//全局模式验证
|
||
if (!isset($params['code_module_category_global_mode']) || !$params['code_module_category_global_mode']) {
|
||
throwErrorMsg("当前新增为父级类目,缺少类目全局模式值");
|
||
}
|
||
//库类型
|
||
if (isset($params['code_module_category_library_type']) && $params['code_module_category_library_type']) {
|
||
if (!in_array($params['code_module_category_library_type'], [ModelCodeModuleCategory::LIBRARY_COMMON, ModelCodeModuleCategory::LIBRARY_PRIVATE])) {
|
||
throwErrorMsg("客户只可新增私有/公有待审核的代码类目!");
|
||
}
|
||
} else {
|
||
throwErrorMsg("当前新增为父级类目,缺少类目库类型值");
|
||
}
|
||
}
|
||
//当前操作类目为子级类目(父子类目共用信息自动填充)
|
||
else {
|
||
self::validateOpCodeModuleCategoryParent($params['code_module_category_parent_guid']);
|
||
$parent = ModelCodeModuleCategory::find($params['code_module_category_parent_guid']);
|
||
foreach (ModelCodeModuleCategory::COMMON_INFO_FIELDS as $field) {
|
||
$params[$field] = $parent->$field;
|
||
}
|
||
}
|
||
|
||
//类目审核状态填充
|
||
$params['code_module_category_audit'] = self::buildCodeModuleCategoryAudit($params['code_module_category_library_type']);
|
||
}
|
||
|
||
/**
|
||
* 代码类目删除验证
|
||
*
|
||
* @param string $code_module_category_guid 代码类目guid
|
||
* @return void
|
||
* @date 2023-07-14
|
||
* @author xjh
|
||
* @since 1.0.0
|
||
*/
|
||
public static function validateDeleteCodeModuleCategory(string $code_module_category_guid): void
|
||
{
|
||
self::validateOpCodeModuleCategory($code_module_category_guid);
|
||
}
|
||
|
||
/**
|
||
* 主级类目操作验证
|
||
*
|
||
* @param string $code_module_category_guid 主级代码类目guid
|
||
* @param bool $is_return_obj 是否返回主级类目模型实例
|
||
* @return void|ModelCodeModuleCategory
|
||
* @date 2023-07-20
|
||
* @author xjh
|
||
* @since 1.0.0
|
||
*/
|
||
public static function validateMasterCodeModuleCategory(string $code_module_category_guid, bool $is_return_obj = false)
|
||
{
|
||
$category = ModelCodeModuleCategory::scope('master')->find($code_module_category_guid);
|
||
if (!$category) {
|
||
throwErrorMsg("所操作的主级类目不存在!");
|
||
}
|
||
if ($category->customer_guid != ModelToken::getCurrentCustomer()->customer_guid) {
|
||
throwErrorMsg("所操作的主级类目不属于当前客户!");
|
||
}
|
||
if ($is_return_obj) {
|
||
return $category;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 上级代码类目操作验证
|
||
*
|
||
* @param string $code_module_category_parent_guid 上级代码类目guid
|
||
* @return void
|
||
* @date 2023-07-20
|
||
* @author xjh
|
||
* @since 1.0.0
|
||
*/
|
||
public static function validateOpCodeModuleCategoryParent(string $code_module_category_parent_guid): void
|
||
{
|
||
$category = ModelCodeModuleCategory::find($code_module_category_parent_guid);
|
||
if (!$category) {
|
||
throwErrorMsg("所操作的上级类目不存在!");
|
||
}
|
||
if ($category->customer_guid != ModelToken::getCurrentCustomer()->customer_guid) {
|
||
throwErrorMsg("所操作的上级类目不属于当前客户!");
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 代码类目操作验证
|
||
*
|
||
* @param string $code_module_category_guid 代码类目guid
|
||
* @return void
|
||
* @date 2023-07-20
|
||
* @author xjh
|
||
* @since 1.0.0
|
||
*/
|
||
public static function validateOpCodeModuleCategory(string $code_module_category_guid): void
|
||
{
|
||
$category = ModelCodeModuleCategory::find($code_module_category_guid);
|
||
if (!$category) {
|
||
throwErrorMsg("所操作的类目不存在!");
|
||
}
|
||
if ($category->customer_guid != ModelToken::getCurrentCustomer()->customer_guid) {
|
||
throwErrorMsg("所操作的类目不属于当前客户!");
|
||
}
|
||
}
|
||
} |