111 lines
4.0 KiB
PHP
111 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller\CodeCustomer;
|
|
|
|
use app\BaseController;
|
|
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
|
|
use app\common\arw\adjfut\src\Traverse;
|
|
use app\Request;
|
|
use think\Validate;
|
|
use think\exception\ValidateException;
|
|
use think\facade\Filesystem;
|
|
use app\common\arw\adjfut\src\Excel;
|
|
use app\common\arw\adjfut\src\UploadFile;
|
|
use think\facade\Db;
|
|
use app\common\exception\Tool;
|
|
use app\common\model\Token as ModelToken;
|
|
use think\facade\Env;
|
|
use app\api\logic\Code\CodeModuleCategory as LogicCodeModuleCategory;
|
|
use app\common\logic\Code\CodeModuleCategory as CommonLogicCodeModuleCategory;
|
|
use app\BaseModel;
|
|
|
|
|
|
class CodeModuleCategory extends BaseController
|
|
{
|
|
/**
|
|
* 添加类目接口
|
|
*
|
|
* @param Request $request
|
|
* @return array
|
|
* @date 2023-07-12
|
|
* @author xjh
|
|
* @since 1.0.0
|
|
*/
|
|
public function addCodeModuleCategory(Request $request): array
|
|
{
|
|
$params = $request->param();
|
|
$this->validate($params, [
|
|
'code_module_category_parent_guid|上级类目guid' => 'require',
|
|
'code_module_category_name|类目名' => 'require',
|
|
'code_module_category_sort|排序' => 'require',
|
|
'code_module_category_global_mode|全局模式' => 'require',
|
|
'code_module_category_library_type|库类型' => 'require',
|
|
]);
|
|
BaseModel::setUserGuid(false);
|
|
$params['customer_guid'] = ModelToken::getCurrentCustomer()->customer_guid;
|
|
LogicCodeModuleCategory::validateAddCodeModuleCategory($params);
|
|
ModelCodeModuleCategory::create($params, [
|
|
'code_module_category_name',
|
|
'code_module_category_parent_guid',
|
|
'code_module_category_sort',
|
|
'code_module_category_global_mode',
|
|
'code_module_category_library_type',
|
|
'customer_guid',
|
|
'code_module_category_audit',
|
|
'code_module_category_ps',
|
|
'code_module_category_guid',
|
|
'code_module_category_create_user_guid',
|
|
'code_module_category_update_user_guid'
|
|
]);
|
|
return msg('添加类目成功!');
|
|
}
|
|
|
|
/**
|
|
* 编辑类目接口
|
|
*
|
|
* @param Request $request
|
|
* @return array
|
|
* @date 2023-07-12
|
|
* @author xjh
|
|
* @since 1.0.0
|
|
*/
|
|
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();
|
|
try {
|
|
BaseModel::setUserGuid(false);
|
|
$model->allowField([
|
|
'code_module_category_name',
|
|
'code_module_category_parent_guid',
|
|
'code_module_category_sort',
|
|
'code_module_category_global_mode',
|
|
'code_module_category_library_type',
|
|
'customer_guid',
|
|
'code_module_category_audit',
|
|
'code_module_category_ps',
|
|
'code_module_category_update_user_guid'
|
|
])->save($params);
|
|
CommonLogicCodeModuleCategory::hanldCommonInfoFieldsDataSync($params['code_module_category_guid']);
|
|
Db::commit();
|
|
return msg('编辑类目成功!');
|
|
} catch (\Throwable $th) {
|
|
Db::rollback();
|
|
throw $th;
|
|
}
|
|
}
|
|
} |