code_module_category_parent_guid == ModelCodeModuleCategory::MASTER_DEFAULT) { self::handleMainCategory($module_category, $code_module_category_audit); } //子类目审核处理 else { self::handleSonCategory($module_category, $code_module_category_audit); } } } /** * 代码块主类目审核处理 * * @param ModelCodeModuleCategory $module_category 模型实例 * @param int $code_module_category_audit 审核状态 * @return void * @date 2023-07-05 * @author xjh * @since 1.0.0 */ public static function handleMainCategory(ModelCodeModuleCategory $module_category, int $code_module_category_audit): void { //主类目的审核将会直接将所属的子类目们审核状态连带修改 //(例: 主类目审核通过则子类目将会全员审核状态为通过) //【主类目更新】 $module_category->code_module_category_audit = $code_module_category_audit; $module_category->save(); //【所属子类目们的更新】 ModelCodeModuleCategory::where('code_module_category_parent_guid', $module_category->code_module_category_guid)->select()->update([ 'code_module_category_audit' => $code_module_category_audit ]); } /** * 代码块子类目审核处理 * * @param ModelCodeModuleCategory $module_category 模型实例 * @param int $code_module_category_audit 审核状态 * @return void * @date 2023-07-05 * @author xjh * @since 1.0.0 */ public static function handleSonCategory(ModelCodeModuleCategory $module_category, int $code_module_category_audit): void { //【当前子类目更新】 $module_category->code_module_category_audit = $code_module_category_audit; $module_category->save(); //【所属主类目更新】 $module_category_parent_guid = $module_category->code_module_category_parent_guid; //当前主类目含未审核子类目的数量 $count = ModelCodeModuleCategory::scope('auditUnaudited')->where([ ['code_module_category_parent_guid', '=', $module_category_parent_guid], ['code_module_category_guid', '<>', $module_category->code_module_category_guid], ])->count(); //当未审核子类目的数量为0的时候 //【场景一】若此时所有的已审核子类目状态都为不通过,则自动将所属的主类目审核状态设置为不通过 //【场景二】若此时所有的已审核子类目状态包含着通过与不通过的状态,则自动将所属的主类目审核状态设置为通过 if ($count == 0) { $son_category_audits = ModelCodeModuleCategory::scope('auditPass')->where('code_module_category_parent_guid', $module_category_parent_guid) ->column('code_module_category_audit'); $is_all_not_failed = true; foreach ($son_category_audits as $son_category_audit) { if ($son_category_audit != ModelCodeModuleCategory::AUDIT_FAILED) { $is_all_not_failed = false; break; } } if ($is_all_not_failed) { ModelCodeModuleCategory::update([ 'code_module_category_guid' => $module_category_parent_guid, 'code_module_category_audit' => ModelCodeModuleCategory::AUDIT_FAILED, ]); } else { ModelCodeModuleCategory::update([ 'code_module_category_guid' => $module_category_parent_guid, 'code_module_category_audit' => ModelCodeModuleCategory::AUDIT_PASS, ]); } } } }