fix:代码块接口取消排序处理 feat:代码块及其类目模块新增对应删除接口、新增上传公有类目接口
This commit is contained in:
parent
067f22cec5
commit
3ea5bcaca4
@ -52,37 +52,27 @@ class CodeModule extends BaseController
|
||||
*/
|
||||
public function addCodeModule(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite(['code_module', 'dictionary', 'code_module_category']);
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_guid|类目' => 'require',
|
||||
'code_module_name|代码块名称' => 'require',
|
||||
'code_module_html|html内容' => 'require',
|
||||
]);
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_guid|类目' => 'require',
|
||||
'code_module_name|代码块名称' => 'require',
|
||||
'code_module_html|html内容' => 'require',
|
||||
]);
|
||||
|
||||
$params['code_module_audit'] = ModelCodeModule::AUDIT_PASS;
|
||||
$model = ModelCodeModule::create($params, [
|
||||
'code_module_category_guid',
|
||||
'code_module_name',
|
||||
'code_module_html',
|
||||
'code_module_style',
|
||||
'code_module_script',
|
||||
'code_module_sort',
|
||||
'code_module_audit',
|
||||
'code_module_guid',
|
||||
'code_module_create_user_guid',
|
||||
'code_module_update_user_guid'
|
||||
]);
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('添加成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
$params['code_module_audit'] = ModelCodeModule::AUDIT_PASS;
|
||||
$model = ModelCodeModule::create($params, [
|
||||
'code_module_category_guid',
|
||||
'code_module_name',
|
||||
'code_module_html',
|
||||
'code_module_style',
|
||||
'code_module_script',
|
||||
'code_module_sort',
|
||||
'code_module_audit',
|
||||
'code_module_guid',
|
||||
'code_module_create_user_guid',
|
||||
'code_module_update_user_guid'
|
||||
]);
|
||||
return msg('添加成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,40 +80,30 @@ class CodeModule extends BaseController
|
||||
*/
|
||||
public function editCodeModule(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite(['code_module', 'dictionary', 'code_module_category']);
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_guid|类目' => 'require',
|
||||
'code_module_name|代码块名称' => 'require',
|
||||
'code_module_html|html内容' => 'require',
|
||||
'code_module_sort|排序' => 'require',
|
||||
'code_module_audit|审核状态' => 'require',
|
||||
'code_module_guid|代码块' => 'require'
|
||||
]);
|
||||
$model = ModelCodeModule::where('code_module_guid', $params['code_module_guid'])->find();
|
||||
if (!$model) {
|
||||
throwErrorMsg("该代码块不存在", 1);
|
||||
}
|
||||
$model->allowField([
|
||||
'code_module_category_guid',
|
||||
'code_module_name',
|
||||
'code_module_html',
|
||||
'code_module_style',
|
||||
'code_module_script',
|
||||
'code_module_sort',
|
||||
'code_module_audit',
|
||||
'code_module_update_user_guid'
|
||||
])->save($params);
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('编辑成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_guid|类目' => 'require',
|
||||
'code_module_name|代码块名称' => 'require',
|
||||
'code_module_html|html内容' => 'require',
|
||||
'code_module_sort|排序' => 'require',
|
||||
'code_module_audit|审核状态' => 'require',
|
||||
'code_module_guid|代码块' => 'require'
|
||||
]);
|
||||
$model = ModelCodeModule::where('code_module_guid', $params['code_module_guid'])->find();
|
||||
if (!$model) {
|
||||
throwErrorMsg("该代码块不存在", 1);
|
||||
}
|
||||
$model->allowField([
|
||||
'code_module_category_guid',
|
||||
'code_module_name',
|
||||
'code_module_html',
|
||||
'code_module_style',
|
||||
'code_module_script',
|
||||
'code_module_sort',
|
||||
'code_module_audit',
|
||||
'code_module_update_user_guid'
|
||||
])->save($params);
|
||||
return msg('编辑成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,25 +111,15 @@ class CodeModule extends BaseController
|
||||
*/
|
||||
public function deleteCodeModule(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite(['code_module', 'dictionary', 'code_module_category']);
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_guid' => 'require',
|
||||
]);
|
||||
$code_module = ModelCodeModule::where([
|
||||
'code_module_guid' => explode(',', $params['code_module_guid'])
|
||||
])->select();
|
||||
$code_module->delete();
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('删除成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_guid' => 'require',
|
||||
]);
|
||||
$code_module = ModelCodeModule::where([
|
||||
'code_module_guid' => explode(',', $params['code_module_guid'])
|
||||
])->select();
|
||||
$code_module->delete();
|
||||
return msg('删除成功!');
|
||||
}
|
||||
|
||||
|
||||
|
@ -31,6 +31,7 @@ class CodeModule extends BaseController
|
||||
*/
|
||||
public function addCodeModule(Request $request): array
|
||||
{
|
||||
BaseModel::setUserGuid(false);
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_guid|类目' => 'require',
|
||||
@ -39,32 +40,21 @@ class CodeModule extends BaseController
|
||||
]);
|
||||
LogicCodeModule::validateAddCodeModule($params);
|
||||
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite(['code_module', 'code_module_category']);
|
||||
BaseModel::setUserGuid(false);
|
||||
try {
|
||||
$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',
|
||||
'code_module_html',
|
||||
'code_module_style',
|
||||
'code_module_script',
|
||||
'code_module_sort',
|
||||
'code_module_audit',
|
||||
'code_module_guid',
|
||||
'code_module_create_user_guid',
|
||||
'code_module_update_user_guid'
|
||||
]);
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('添加代码块成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
$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',
|
||||
'code_module_html',
|
||||
'code_module_style',
|
||||
'code_module_script',
|
||||
'code_module_sort',
|
||||
'code_module_audit',
|
||||
'code_module_guid',
|
||||
'code_module_create_user_guid',
|
||||
'code_module_update_user_guid'
|
||||
]);
|
||||
return msg('添加代码块成功!');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,6 +68,7 @@ class CodeModule extends BaseController
|
||||
*/
|
||||
public function editCodeModule(Request $request): array
|
||||
{
|
||||
BaseModel::setUserGuid(false);
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_guid|类目' => 'require',
|
||||
@ -92,27 +83,45 @@ class CodeModule extends BaseController
|
||||
}
|
||||
LogicCodeModule::validateEditCodeModule($params['code_module_guid']);
|
||||
|
||||
$params['code_module_audit'] = LogicCodeModule::buildCodeModuleAudit($params['code_module_category_guid']);
|
||||
$model->allowField([
|
||||
'code_module_category_guid',
|
||||
'code_module_name',
|
||||
'code_module_html',
|
||||
'code_module_style',
|
||||
'code_module_script',
|
||||
'code_module_sort',
|
||||
'code_module_audit',
|
||||
'code_module_update_user_guid'
|
||||
])->save($params);
|
||||
return msg('编辑代码块成功!');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除代码块接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-07-20
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function deleteCodeModule(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite(['code_module', 'dictionary', 'code_module_category']);
|
||||
BaseModel::setUserGuid(false);
|
||||
try {
|
||||
$params['code_module_audit'] = LogicCodeModule::buildCodeModuleAudit($params['code_module_category_guid']);
|
||||
$model->allowField([
|
||||
'code_module_category_guid',
|
||||
'code_module_name',
|
||||
'code_module_html',
|
||||
'code_module_style',
|
||||
'code_module_script',
|
||||
'code_module_sort',
|
||||
'code_module_audit',
|
||||
'code_module_update_user_guid'
|
||||
])->save($params);
|
||||
$params = $request->param();
|
||||
$this->validate($params, ['code_module_guid|代码块guid' => 'require',]);
|
||||
foreach (explode(',', $params['code_module_guid']) as $code_module_guid) {
|
||||
LogicCodeModule::validateDeleteCodeModule($code_module_guid);
|
||||
ModelCodeModule::find($code_module_guid)->delete();
|
||||
}
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return msg('编辑代码块成功!');
|
||||
return msg('删除代码块成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ use app\BaseModel;
|
||||
class CodeModuleCategory extends BaseController
|
||||
{
|
||||
/**
|
||||
* 添加类目接口
|
||||
* 添加代码类目接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
@ -33,6 +33,7 @@ class CodeModuleCategory extends BaseController
|
||||
*/
|
||||
public function addCodeModuleCategory(Request $request): array
|
||||
{
|
||||
BaseModel::setUserGuid(false);
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_parent_guid|上级类目guid' => 'require',
|
||||
@ -41,7 +42,6 @@ class CodeModuleCategory extends BaseController
|
||||
'code_module_category_global_mode|全局模式' => 'require',
|
||||
'code_module_category_library_type|库类型' => 'require',
|
||||
]);
|
||||
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);
|
||||
@ -62,7 +62,7 @@ class CodeModuleCategory extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑类目接口
|
||||
* 编辑代码类目接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
@ -72,24 +72,24 @@ class CodeModuleCategory extends BaseController
|
||||
*/
|
||||
public function editCodeModuleCategory(Request $request): array
|
||||
{
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_name|类目名' => 'require',
|
||||
'code_module_category_sort|排序' => 'require',
|
||||
'code_module_category_global_mode|全局模式' => 'require',
|
||||
'code_module_category_library_type|库类型' => 'require',
|
||||
'code_module_category_guid|类目' => 'require',
|
||||
'code_module_category_parent_guid|上级类目guid' => 'require',
|
||||
]);
|
||||
$model = ModelCodeModuleCategory::where('code_module_category_guid', $params['code_module_category_guid'])->find();
|
||||
if (!$model) {
|
||||
throwErrorMsg("该代码块类目不存在", 1);
|
||||
}
|
||||
LogicCodeModuleCategory::validateEditCodeModuleCategory($params['code_module_category_guid']);
|
||||
|
||||
Db::startTrans();
|
||||
BaseModel::setUserGuid(false);
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_name|类目名' => 'require',
|
||||
'code_module_category_sort|排序' => 'require',
|
||||
'code_module_category_global_mode|全局模式' => 'require',
|
||||
'code_module_category_library_type|库类型' => 'require',
|
||||
'code_module_category_guid|类目' => 'require',
|
||||
'code_module_category_parent_guid|上级类目guid' => 'require',
|
||||
]);
|
||||
$model = ModelCodeModuleCategory::where('code_module_category_guid', $params['code_module_category_guid'])->find();
|
||||
if (!$model) {
|
||||
throwErrorMsg("该代码块类目不存在", 1);
|
||||
}
|
||||
LogicCodeModuleCategory::validateEditCodeModuleCategory($params);
|
||||
|
||||
$params['code_module_category_audit'] = LogicCodeModuleCategory::buildCodeModuleCategoryAudit($params['code_module_category_library_type']);
|
||||
$model->allowField([
|
||||
'code_module_category_name',
|
||||
@ -110,4 +110,59 @@ class CodeModuleCategory extends BaseController
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除代码类目接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-07-20
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function deleteCodeModuleCategory(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
BaseModel::setUserGuid(false);
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, ['code_module_category_guid|类目guid' => 'require',]);
|
||||
foreach (explode(',', $params['code_module_category_guid']) as $code_module_category_guid) {
|
||||
LogicCodeModuleCategory::validateDeleteCodeModuleCategory($code_module_category_guid);
|
||||
ModelCodeModuleCategory::find($code_module_category_guid)->delete();
|
||||
}
|
||||
Db::commit();
|
||||
return msg('删除代码类目成功!');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传公共类目接口
|
||||
*
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @date 2023-07-20
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function uploadCommonCodeModuleCategory(Request $request): array
|
||||
{
|
||||
Db::startTrans();
|
||||
BaseModel::setUserGuid(false);
|
||||
try {
|
||||
$params = $request->param();
|
||||
$this->validate($params, [
|
||||
'code_module_category_guid|主级类目guid' => 'require',
|
||||
]);
|
||||
LogicCodeModuleCategory::handleUploadCommonCodeModuleCategory($params['code_module_category_guid']);
|
||||
Db::commit();
|
||||
return msg('上传公共类目成功!请耐心等待审核...');
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
throw $th;
|
||||
}
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ class CodeModule
|
||||
/**
|
||||
* 代码块新增验证
|
||||
*
|
||||
* @param array $params 新增代码的参数
|
||||
* @param array $params 新增代码块的参数
|
||||
* @return void
|
||||
* @date 2023-07-12
|
||||
* @author xjh
|
||||
@ -40,35 +40,55 @@ class CodeModule
|
||||
*/
|
||||
public static function validateAddCodeModule(array $params): void
|
||||
{
|
||||
if ($params['code_module_category_guid'] != ModelCodeModuleCategory::MASTER_DEFAULT) {
|
||||
$category = ModelCodeModuleCategory::find($params['code_module_category_guid']);
|
||||
if ($category) {
|
||||
if ($category->customer_guid != ModelToken::getCurrentCustomer()->customer_guid) {
|
||||
throwErrorMsg("所选的上级类目不属于当前客户!");
|
||||
}
|
||||
} else {
|
||||
throwErrorMsg("所选的上级类目不存在!");
|
||||
}
|
||||
}
|
||||
LogicCodeModuleCategory::validateOpCodeModuleCategoryParent($params['code_module_category_guid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码块编辑验证
|
||||
*
|
||||
* @param string $code_module_guid 代码块guid
|
||||
* @return array
|
||||
* @param array $params 编辑代码块的参数
|
||||
* @return void
|
||||
* @date 2023-07-14
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function validateEditCodeModule(string $code_module_guid): void
|
||||
public static function validateEditCodeModule(array $params): void
|
||||
{
|
||||
LogicCodeModuleCategory::validateOpCodeModuleCategoryParent($params['code_module_category_guid']);
|
||||
self::validateOpCodeModule($params['code_module_guid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码块删除验证
|
||||
*
|
||||
* @param string $code_module_guid 代码块guid
|
||||
* @return void
|
||||
* @date 2023-07-14
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function validateDeleteCodeModule(string $code_module_guid): void
|
||||
{
|
||||
self::validateOpCodeModule($code_module_guid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码块操作验证
|
||||
*
|
||||
* @param string $code_module_guid 代码块guid
|
||||
* @return void
|
||||
* @date 2023-07-20
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function validateOpCodeModule(string $code_module_guid): void
|
||||
{
|
||||
$module = ModelCodeModule::find($code_module_guid);
|
||||
if (!$module) {
|
||||
throwErrorMsg("所编辑的代码块不存在!");
|
||||
throwErrorMsg("所操作的代码块不存在!");
|
||||
}
|
||||
if ($module->customer_guid != ModelToken::getCurrentCustomer()->customer_guid) {
|
||||
throwErrorMsg("所编辑的代码块不属于当前客户!");
|
||||
throwErrorMsg("所操作的代码块不属于当前客户!");
|
||||
}
|
||||
}
|
||||
}
|
@ -3,12 +3,67 @@
|
||||
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;
|
||||
|
||||
|
||||
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);
|
||||
//子级类目拷贝送审
|
||||
$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);
|
||||
//各个子级类目的代码块送审
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建客户代码类目初始审核状态
|
||||
*
|
||||
@ -23,7 +78,7 @@ class CodeModuleCategory
|
||||
if ($library_type == ModelCodeModuleCategory::LIBRARY_PRIVATE) {
|
||||
return ModelCodeModuleCategory::AUDIT_PASS;
|
||||
} else {
|
||||
return ModelCodeModuleCategory::AUDIT_FAILED;
|
||||
return ModelCodeModuleCategory::AUDIT_UNAUDITED;
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +86,7 @@ class CodeModuleCategory
|
||||
* 代码类目新增验证
|
||||
*
|
||||
* @param array $params 新增代码类目的参数
|
||||
* @return array
|
||||
* @return void
|
||||
* @date 2023-07-14
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
@ -39,37 +94,105 @@ class CodeModuleCategory
|
||||
public static function validateAddCodeModuleCategory(array $params): void
|
||||
{
|
||||
if ($params['code_module_category_parent_guid'] != ModelCodeModuleCategory::MASTER_DEFAULT) {
|
||||
$category = ModelCodeModuleCategory::find($params['code_module_category_parent_guid']);
|
||||
if ($category) {
|
||||
if ($category->customer_guid != ModelToken::getCurrentCustomer()->customer_guid) {
|
||||
throwErrorMsg("所选的上级类目不属于当前客户!");
|
||||
}
|
||||
} else {
|
||||
throwErrorMsg("所选的上级类目不存在!");
|
||||
}
|
||||
self::validateOpCodeModuleCategoryParent($params['code_module_category_parent_guid']);
|
||||
}
|
||||
if (!in_array($params['code_module_category_library_type'], [ModelCodeModuleCategory::LIBRARY_COMMON, ModelCodeModuleCategory::LIBRARY_PRIVATE])) {
|
||||
throwErrorMsg("新增类目的所属库类型异常!");
|
||||
throwErrorMsg("客户只可新增私有/公有待审核的代码类目!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码类目编辑验证
|
||||
*
|
||||
* @param string $code_module_category_guid 类目guid
|
||||
* @return array
|
||||
* @param array $params 编辑代码类目的参数
|
||||
* @return void
|
||||
* @date 2023-07-14
|
||||
* @author xjh
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public static function validateEditCodeModuleCategory(string $code_module_category_guid): void
|
||||
public static function validateEditCodeModuleCategory(array $params): void
|
||||
{
|
||||
if ($params['code_module_category_parent_guid'] != ModelCodeModuleCategory::MASTER_DEFAULT) {
|
||||
self::validateOpCodeModuleCategoryParent($params['code_module_category_parent_guid']);
|
||||
}
|
||||
self::validateOpCodeModuleCategory($params['code_module_category_guid']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 代码类目删除验证
|
||||
*
|
||||
* @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("所编辑的类目不存在!");
|
||||
throwErrorMsg("所操作的类目不存在!");
|
||||
}
|
||||
if ($category->customer_guid != ModelToken::getCurrentCustomer()->customer_guid) {
|
||||
throwErrorMsg("所编辑的类目不属于当前客户!");
|
||||
throwErrorMsg("所操作的类目不属于当前客户!");
|
||||
}
|
||||
}
|
||||
}
|
@ -32,6 +32,7 @@ class CodeModule extends BaseModel
|
||||
'code_module_script' => '',
|
||||
'code_module_sort' => 'int',
|
||||
'code_module_audit' => 'int',
|
||||
'customer_guid' => 'int',
|
||||
'code_module_create_time' => 'datetime',
|
||||
'code_module_create_user_guid' => 'string',
|
||||
'code_module_update_time' => 'datetime',
|
||||
@ -81,7 +82,7 @@ class CodeModule extends BaseModel
|
||||
*/
|
||||
public static function onBeforeInsert(self $model): void
|
||||
{
|
||||
Tool::dataAddSortProc($model, ['code_module_category_guid' => $model->code_module_category_guid]);
|
||||
// Tool::dataAddSortProc($model, ['code_module_category_guid' => $model->code_module_category_guid]);
|
||||
$model->completeCreateField();
|
||||
}
|
||||
|
||||
@ -90,7 +91,7 @@ class CodeModule extends BaseModel
|
||||
*/
|
||||
public static function onBeforeUpdate(self $model): void
|
||||
{
|
||||
Tool::dataEditSortProc($model, ['code_module_category_guid' => $model->code_module_category_guid]);
|
||||
// Tool::dataEditSortProc($model, ['code_module_category_guid' => $model->code_module_category_guid]);
|
||||
$model->completeUpdateField();
|
||||
}
|
||||
|
||||
@ -99,7 +100,7 @@ class CodeModule extends BaseModel
|
||||
*/
|
||||
public static function onBeforeDelete(self $model): void
|
||||
{
|
||||
Tool::dataDeleteSortProc($model);
|
||||
// Tool::dataDeleteSortProc($model);
|
||||
$model->completeDeleteField();
|
||||
}
|
||||
|
||||
@ -125,20 +126,22 @@ class CodeModule extends BaseModel
|
||||
*/
|
||||
public static function exportExcel(array $select): void
|
||||
{
|
||||
$data = [[
|
||||
'类目',
|
||||
'代码块名称',
|
||||
'html内容',
|
||||
'style内容',
|
||||
'script内容',
|
||||
'排序',
|
||||
'审核状态'
|
||||
]];
|
||||
$data = [
|
||||
[
|
||||
'类目',
|
||||
'代码块名称',
|
||||
'html内容',
|
||||
'style内容',
|
||||
'script内容',
|
||||
'排序',
|
||||
'审核状态'
|
||||
]
|
||||
];
|
||||
foreach ($select as $key => $val) {
|
||||
|
||||
// 根据字典值获取审核状态名称
|
||||
$audit_status = ModelDictionary::getDictionaryData('audit_status');
|
||||
$val['code_module_audit'] = ModelDictionary::getDataDictionaryName($audit_status, $val['code_module_audit']);
|
||||
$val['code_module_audit'] = ModelDictionary::getDataDictionaryName($audit_status, $val['code_module_audit']);
|
||||
|
||||
$data[] = [
|
||||
$val['code_module_category_name'],
|
||||
@ -164,32 +167,23 @@ class CodeModule extends BaseModel
|
||||
{
|
||||
$msg = [];
|
||||
|
||||
Db::startTrans();
|
||||
Tool::adminLockTableWrite(['code_module', 'dictionary', 'code_module_category']);
|
||||
try {
|
||||
$excel = new Excel($file);
|
||||
$data = $excel->parseExcel(
|
||||
Tool::getExcelRule(self::EXCELFIELD),
|
||||
['titleLine' => [1]]
|
||||
);
|
||||
if (!$data) throwErrorMsg('excel无数据', 1);
|
||||
$msg = [];
|
||||
foreach ($data as $line => $value) {
|
||||
try {
|
||||
$model = self::importExcelInit($value);
|
||||
$msg[] = "{$line} <span style='color:#27af49'>代码库:【{$value['code_module_name']}】新增成功!</span><br>";
|
||||
} catch (\Throwable $th) {
|
||||
$msg[] = "{$line} <span style='color:red'>{$th->getMessage()}</span><br>";
|
||||
}
|
||||
$excel = new Excel($file);
|
||||
$data = $excel->parseExcel(
|
||||
Tool::getExcelRule(self::EXCELFIELD),
|
||||
['titleLine' => [1]]
|
||||
);
|
||||
if (!$data)
|
||||
throwErrorMsg('excel无数据', 1);
|
||||
$msg = [];
|
||||
foreach ($data as $line => $value) {
|
||||
try {
|
||||
$model = self::importExcelInit($value);
|
||||
$msg[] = "{$line} <span style='color:#27af49'>代码库:【{$value['code_module_name']}】新增成功!</span><br>";
|
||||
} catch (\Throwable $th) {
|
||||
$msg[] = "{$line} <span style='color:red'>{$th->getMessage()}</span><br>";
|
||||
}
|
||||
Db::commit();
|
||||
Tool::unlockTable();
|
||||
return implode(', ', $msg);
|
||||
} catch (\Throwable $th) {
|
||||
Db::rollback();
|
||||
Tool::unlockTable();
|
||||
throw $th;
|
||||
}
|
||||
return implode(', ', $msg);
|
||||
}
|
||||
|
||||
|
||||
@ -209,7 +203,8 @@ class CodeModule extends BaseModel
|
||||
// $code_module_audit = $value['code_module_audit'];
|
||||
|
||||
$code_module_catetory = ModelCodeModuleCategory::where('code_module_category_name', $code_module_category_guid)->find();
|
||||
if (!$code_module_catetory) throwErrorMsg($code_module_category_guid . "不存在,请重新确认!");
|
||||
if (!$code_module_catetory)
|
||||
throwErrorMsg($code_module_category_guid . "不存在,请重新确认!");
|
||||
$code_module_category_guid = $code_module_catetory->code_module_category_guid;
|
||||
|
||||
// $audit_status = ModelDictionary::getDictionaryData('audit_status');
|
||||
@ -275,16 +270,19 @@ class CodeModule extends BaseModel
|
||||
public static function audit($value, $params)
|
||||
{
|
||||
$model = self::where('code_module_guid', $value)->find();
|
||||
if (!$model) throwErrorMsg("该代码块不存在", 1);
|
||||
if (!$model)
|
||||
throwErrorMsg("该代码块不存在", 1);
|
||||
|
||||
$audit_status = $model->code_module_audit;
|
||||
$code_module_name = $model->code_module_name;
|
||||
|
||||
if ($audit_status == 2) throwErrorMsg("{$code_module_name} 代码块已通过审核!");
|
||||
if ($audit_status == 3) throwErrorMsg("{$code_module_name} 代码块已驳回审核!");
|
||||
if ($audit_status == 2)
|
||||
throwErrorMsg("{$code_module_name} 代码块已通过审核!");
|
||||
if ($audit_status == 3)
|
||||
throwErrorMsg("{$code_module_name} 代码块已驳回审核!");
|
||||
|
||||
$model->allowField([
|
||||
'code_module_audit',
|
||||
])->save($params);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user