param()); $tree_data = LogicCodeModuleCategory::buildTreeData($paging_info['guids']); return msg(0, "获取代码块类目列表成功!", [ 'count' => $paging_info['count'], 'data' => $tree_data, ]); } /** * 添加代码块类目接口 * * @param Request $request * @return array * @date 2023-06-28 * @author xjh * @since 1.0.0 */ public function addCodeModuleCategory(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', ]); 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_guid', 'code_module_category_create_user_guid', 'code_module_category_update_user_guid' ]); return msg('添加成功!'); } /** * 编辑代码块类目接口 * * @param Request $request * @return array * @date 2023-06-28 * @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', ]); $model = ModelCodeModuleCategory::where('code_module_category_guid', $params['code_module_category_guid'])->find(); if (!$model) { throwErrorMsg("该代码块类目不存在", 1); } Db::startTrans(); try { $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_update_user_guid' ])->save($params); CommonLogicCodeModuleCategory::hanldCommonInfoFieldsDataSync($params['code_module_category_guid']); Db::commit(); return msg('编辑成功!'); } catch (\Throwable $th) { Db::rollback(); throw $th; } } /** * 删除代码块类目接口 * * @param Request $request * @return array * @date 2023-06-28 * @author xjh * @since 1.0.0 */ public function deleteCodeModuleCategory(Request $request): array { $params = $request->param(); $this->validate($params, [ 'code_module_category_guid|类目guid' => 'require', ]); $code_module_category = ModelCodeModuleCategory::where([ 'code_module_category_guid' => explode(',', $params['code_module_category_guid']) ])->select(); $code_module_category->delete(); return msg('删除成功!'); } /** * 获取父子类目共用信息返回接口 * * @param Request $request * @return array * @date 2023-06-29 * @author xjh * @since 1.0.0 */ public function getCodeModuleCategoryInfo(Request $request): array { $params = $request->param(); $this->validate($params, [ 'code_module_category_guid|类目guid' => 'require', ]); $find = ModelCodeModuleCategory::field(ModelCodeModuleCategory::COMMON_INFO_FIELDS)->find($params['code_module_category_guid']); if (!$find) { throwErrorMsg("该类目不存在!"); } return msg(0, '', ['data' => $find]); } /** * 审核代码类目接口 * * @param Request $request * @return array * @date 2023-07-05 * @author xjh * @since 1.0.0 */ public function auditCodeModuleCategory(Request $request): array { $params = $request->param(); $this->validate($params, [ 'code_module_category_guid|类目guid' => 'require', 'code_module_category_audit|审核状态' => 'require|in:1,2,3', ]); Db::startTrans(); try { LogicCodeModuleCategoryAudit::handleAudit(explode(',', $params['code_module_category_guid']), $params['code_module_category_audit']); Db::commit(); return msg('审核成功!'); } catch (\Throwable $th) { Db::rollback(); throw $th; } } }