drag-create-api/app/common/logic/CustomerMessage/Audit/CodeModuleCategory.php

145 lines
5.3 KiB
PHP

<?php
namespace app\common\logic\CustomerMessage\Audit;
use app\common\model\Code\CodeModuleCategory as ModelCodeModuleCategory;
use app\common\model\Customer\CustomerMessage as ModelCustomerMessage;
use app\common\model\Token as ModelToken;
/**
* 客户消息-代码块类目审核
*/
class CodeModuleCategory
{
/**
* 发送客户类目审核消息(依据审核状态来进行对应消息发送)
*
* @param string $code_module_category_guid 代码块类目guid
* @param int $audit 审核状态
* @return void
* @date 2023-08-01
* @author xjh
* @since 1.0.0
*/
public static function sendAuditMessage(string $code_module_category_guid, int $audit, string $ps = "无附言"): void
{
switch ($audit) {
case ModelCodeModuleCategory::AUDIT_UNAUDITED:
self::unaudited($code_module_category_guid, $ps);
break;
case ModelCodeModuleCategory::AUDIT_PASS:
self::passAudit($code_module_category_guid, $ps);
break;
case ModelCodeModuleCategory::AUDIT_FAILED:
self::rejectAudit($code_module_category_guid, $ps);
break;
default:
throwErrorMsg('审核状态不正确!');
}
}
/**
* 待审核消息
*
* @param string $code_module_category_guid 代码块类目guid
* @param string $ps 附言
* @return void
* @date 2023-08-01
* @author xjh
* @since 1.0.0
*/
public static function unaudited(string $code_module_category_guid, string $ps = "无附言"): void
{
$title = "【公共代码块类目审核中】";
$content_info = self::bulidContentInfo($code_module_category_guid, '正在认真审核中,请耐心等待...');
ModelCustomerMessage::create([
'customer_message_title' => $title,
'customer_message_content' => $content_info['content'],
'customer_message_postscript' => $ps,
'customer_guid' => $content_info['customer_guid'],
]);
}
/**
* 审核通过消息
*
* @param string $code_module_category_guid 代码块类目guid
* @param string $ps 附言
* @return void
* @date 2023-08-01
* @author xjh
* @since 1.0.0
*/
public static function passAudit(string $code_module_category_guid, string $ps = "无附言"): void
{
$title = "【公共代码块类目审核结果】";
$content_info = self::bulidContentInfo($code_module_category_guid, '审核结果:通过!');
ModelCustomerMessage::create([
'customer_message_title' => $title,
'customer_message_content' => $content_info['content'],
'customer_message_postscript' => $ps,
'customer_guid' => $content_info['customer_guid'],
]);
}
/**
* 审核驳回消息
*
* @param string $code_module_category_guid 代码块类目guid
* @param string $ps 附言
* @return void
* @date 2023-08-01
* @author xjh
* @since 1.0.0
*/
public static function rejectAudit(string $code_module_category_guid, string $ps = "无附言"): void
{
$title = "【公共代码块类目审核结果】";
$content_info = self::bulidContentInfo($code_module_category_guid, '审核结果:驳回!');
ModelCustomerMessage::create([
'customer_message_title' => $title,
'customer_message_content' => $content_info['content'],
'customer_message_postscript' => $ps,
'customer_guid' => $content_info['customer_guid'],
]);
}
/**
* 获取审核消息所需信息
*
* @param string $code_module_category_guid 代码块类目guid
* @param string $type 审核结果类型
* @return array ['content' => 审核消息内容 , 'customer_guid' => 客户guid]
* @date 2023-08-01
* @author xjh
* @since 1.0.0
*/
public static function bulidContentInfo(string $code_module_category_guid, string $main_content): array
{
$category = ModelCodeModuleCategory::find($code_module_category_guid);
if (!$category) {
throwErrorMsg("客户消息-代码块类目审核信息构建异常(类目不存在!)");
}
//类目提交审核的时间
$start_datetime = date('Y-m-d H:i:s');
//主子级类目区分处理
if ($category->code_module_category_parent_guid == ModelCodeModuleCategory::MASTER_DEFAULT) {
$category_name = "主级类目:{$category->code_module_category_name}";
} else {
$parent_category = ModelCodeModuleCategory::find($category->code_module_category_parent_guid);
if (!$parent_category) {
throwErrorMsg("客户消息-代码模块类目审核信息构建异常(所属父级类目不存在!)");
}
$category_name = "(所属主级类目:{$parent_category->code_module_category_name})子级类目:{$category->code_module_category_name}";
}
//整体消息内容
$content = "您在 {$start_datetime} 提交的公共类目【{$category_name}" . $main_content;
return [
'content' => $content,
'customer_guid' => $category->customer_guid,
];
}
}