群推送
This commit is contained in:
@@ -39,16 +39,19 @@ class Workbench extends Validate
|
||||
// 群消息推送特有参数
|
||||
'pushType' => 'requireIf:type,3|in:0,1', // 推送方式 0定时 1立即
|
||||
'targetType' => 'requireIf:type,3|in:1,2', // 推送目标类型:1=群推送,2=好友推送
|
||||
'startTime' => 'requireIf:type,3|dateFormat:H:i',
|
||||
'endTime' => 'requireIf:type,3|dateFormat:H:i',
|
||||
'groupPushSubType' => 'checkGroupPushSubType|in:1,2', // 群推送子类型:1=群群发,2=群公告(仅当targetType=1时有效)
|
||||
'maxPerDay' => 'requireIf:type,3|number|min:1',
|
||||
'pushOrder' => 'requireIf:type,3|in:1,2', // 1最早 2最新
|
||||
'isLoop' => 'requireIf:type,3|in:0,1',
|
||||
'status' => 'requireIf:type,3|in:0,1',
|
||||
'wechatGroups' => 'checkGroupPushTarget|array|min:1', // 当targetType=1时必填
|
||||
'wechatFriends' => 'checkFriendPushTarget|array', // 当targetType=2时可选(可以为空)
|
||||
'deviceGroups' => 'checkFriendPushDevice|array|min:1', // 当targetType=2时必填
|
||||
'ownerWechatId' => 'checkFriendPushService', // 当targetType=2且未选择好友/流量池时必填
|
||||
'contentGroups' => 'requireIf:type,3|array|min:1',
|
||||
// 群公告特有参数
|
||||
'announcementContent' => 'checkAnnouncementContent|max:5000', // 群公告内容(当groupPushSubType=2时必填)
|
||||
'enableAiRewrite' => 'checkEnableAiRewrite|in:0,1', // 是否启用AI智能话术改写
|
||||
'aiRewritePrompt' => 'checkAiRewritePrompt|max:500', // AI改写提示词(当enableAiRewrite=1时必填)
|
||||
// 自动建群特有参数
|
||||
'groupNameTemplate' => 'requireIf:type,4|max:50',
|
||||
'maxGroupsPerDay' => 'requireIf:type,4|number|min:1',
|
||||
@@ -61,6 +64,7 @@ class Workbench extends Validate
|
||||
'accountGroups' => 'requireIf:type,5|array|min:1',
|
||||
// 通用参数
|
||||
'deviceGroups' => 'requireIf:type,1,2,5|array',
|
||||
'trafficPools' => 'checkFriendPushPools',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -123,13 +127,20 @@ class Workbench extends Validate
|
||||
'wechatGroups.checkGroupPushTarget' => '群推送时必须选择推送群组',
|
||||
'wechatGroups.array' => '推送群组格式错误',
|
||||
'wechatGroups.min' => '至少选择一个推送群组',
|
||||
'groupPushSubType.checkGroupPushSubType' => '群推送子类型错误',
|
||||
'groupPushSubType.in' => '群推送子类型只能是群群发或群公告',
|
||||
'announcementContent.checkAnnouncementContent' => '群公告必须输入公告内容',
|
||||
'announcementContent.max' => '公告内容最多5000个字符',
|
||||
'enableAiRewrite.checkEnableAiRewrite' => 'AI智能话术改写参数错误',
|
||||
'enableAiRewrite.in' => 'AI智能话术改写参数只能是0或1',
|
||||
'aiRewritePrompt.checkAiRewritePrompt' => '启用AI智能话术改写时,必须输入改写提示词',
|
||||
'aiRewritePrompt.max' => '改写提示词最多500个字符',
|
||||
'wechatFriends.requireIf' => '请选择推送好友',
|
||||
'wechatFriends.checkFriendPushTarget' => '好友推送时必须选择推送好友',
|
||||
'wechatFriends.array' => '推送好友格式错误',
|
||||
'deviceGroups.requireIf' => '请选择设备',
|
||||
'deviceGroups.checkFriendPushDevice' => '好友推送时必须选择设备',
|
||||
'deviceGroups.array' => '设备格式错误',
|
||||
'deviceGroups.min' => '至少选择一个设备',
|
||||
'ownerWechatId.checkFriendPushService' => '好友推送需选择客服或提供好友/流量池',
|
||||
// 自动建群相关提示
|
||||
'groupNameTemplate.requireIf' => '请设置群名称前缀',
|
||||
'groupNameTemplate.max' => '群名称前缀最多50个字符',
|
||||
@@ -160,6 +171,7 @@ class Workbench extends Validate
|
||||
'accountGroups.requireIf' => '流量分发时必须选择分发账号',
|
||||
'accountGroups.array' => '分发账号格式错误',
|
||||
'accountGroups.min' => '至少选择一个分发账号',
|
||||
'trafficPools.checkFriendPushPools' => '好友推送时请选择好友或流量池',
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -169,7 +181,8 @@ class Workbench extends Validate
|
||||
'create' => ['name', 'type', 'autoStart', 'deviceGroups', 'targetGroups',
|
||||
'interval', 'maxLikes', 'startTime', 'endTime', 'contentTypes',
|
||||
'syncCount', 'syncType', 'accountGroups',
|
||||
'pushType', 'targetType', 'startTime', 'endTime', 'maxPerDay', 'pushOrder', 'isLoop', 'status', 'wechatGroups', 'wechatFriends', 'contentGroups',
|
||||
'pushType', 'targetType', 'groupPushSubType', 'startTime', 'endTime', 'maxPerDay', 'pushOrder', 'isLoop', 'status', 'wechatGroups', 'wechatFriends', 'trafficPools', 'ownerWechatId', 'contentGroups',
|
||||
'announcementContent', 'enableAiRewrite', 'aiRewritePrompt',
|
||||
'groupNameTemplate', 'maxGroupsPerDay', 'groupSizeMin', 'groupSizeMax',
|
||||
'distributeType', 'timeType', 'accountGroups',
|
||||
],
|
||||
@@ -177,7 +190,8 @@ class Workbench extends Validate
|
||||
'update' => ['name', 'type', 'autoStart', 'deviceGroups', 'targetGroups',
|
||||
'interval', 'maxLikes', 'startTime', 'endTime', 'contentTypes',
|
||||
'syncCount', 'syncType', 'accountGroups',
|
||||
'pushType', 'targetType', 'startTime', 'endTime', 'maxPerDay', 'pushOrder', 'isLoop', 'status', 'wechatGroups', 'wechatFriends', 'deviceGroups', 'contentGroups',
|
||||
'pushType', 'targetType', 'groupPushSubType', 'startTime', 'endTime', 'maxPerDay', 'pushOrder', 'isLoop', 'status', 'wechatGroups', 'wechatFriends', 'trafficPools', 'ownerWechatId', 'contentGroups',
|
||||
'announcementContent', 'enableAiRewrite', 'aiRewritePrompt',
|
||||
'groupNameTemplate', 'maxGroupsPerDay', 'groupSizeMin', 'groupSizeMax',
|
||||
'distributeType', 'timeType', 'accountGroups',
|
||||
]
|
||||
@@ -243,18 +257,126 @@ class Workbench extends Validate
|
||||
/**
|
||||
* 验证好友推送时设备必填(当targetType=2时,deviceGroups必填)
|
||||
*/
|
||||
protected function checkFriendPushDevice($value, $rule, $data)
|
||||
protected function checkFriendPushService($value, $rule, $data)
|
||||
{
|
||||
if (isset($data['type']) && $data['type'] == self::TYPE_GROUP_PUSH) {
|
||||
$targetType = isset($data['targetType']) ? intval($data['targetType']) : 1; // 默认1
|
||||
if ($targetType == 2) {
|
||||
if ($value !== null && $value !== '' && !is_array($value)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$hasFriends = isset($data['wechatFriends']) && is_array($data['wechatFriends']) && count($data['wechatFriends']) > 0;
|
||||
$hasPools = isset($data['trafficPools']) && is_array($data['trafficPools']) && count($data['trafficPools']) > 0;
|
||||
$hasServices = is_array($value) && count(array_filter($value, function ($item) {
|
||||
if (is_array($item)) {
|
||||
return !empty($item['ownerWechatId'] ?? $item['wechatId'] ?? $item['id']);
|
||||
}
|
||||
return $item !== null && $item !== '';
|
||||
})) > 0;
|
||||
|
||||
if (!$hasFriends && !$hasPools && !$hasServices) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证好友推送时是否选择好友或流量池(至少其一)
|
||||
*/
|
||||
protected function checkFriendPushPools($value, $rule, $data)
|
||||
{
|
||||
if (isset($data['type']) && $data['type'] == self::TYPE_GROUP_PUSH) {
|
||||
$targetType = isset($data['targetType']) ? intval($data['targetType']) : 1; // 默认1
|
||||
if ($targetType == 2) {
|
||||
$hasFriends = isset($data['wechatFriends']) && !empty($data['wechatFriends']);
|
||||
$hasPools = isset($value) && $value !== null && $value !== '' && is_array($value) && count($value) > 0;
|
||||
if (!$hasFriends && !$hasPools) {
|
||||
return false;
|
||||
}
|
||||
if (isset($value) && $value !== null && $value !== '') {
|
||||
if (!is_array($value)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证群推送子类型(当targetType=1时,groupPushSubType必填且只能是1或2)
|
||||
*/
|
||||
protected function checkGroupPushSubType($value, $rule, $data)
|
||||
{
|
||||
// 如果是群消息推送类型
|
||||
if (isset($data['type']) && $data['type'] == self::TYPE_GROUP_PUSH) {
|
||||
// 如果targetType=2(好友推送),则deviceGroups必填
|
||||
// 如果targetType=1(群推送),则groupPushSubType必填
|
||||
$targetType = isset($data['targetType']) ? intval($data['targetType']) : 1; // 默认1
|
||||
if ($targetType == 2) {
|
||||
if ($targetType == 1) {
|
||||
// 检查值是否存在且有效
|
||||
if (!isset($value) || $value === null || $value === '') {
|
||||
if (!isset($value) || !in_array(intval($value), [1, 2])) {
|
||||
return false;
|
||||
}
|
||||
if (!is_array($value) || count($value) < 1) {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证群公告内容(当groupPushSubType=2时,announcementContent必填)
|
||||
*/
|
||||
protected function checkAnnouncementContent($value, $rule, $data)
|
||||
{
|
||||
// 如果是群消息推送类型
|
||||
if (isset($data['type']) && $data['type'] == self::TYPE_GROUP_PUSH) {
|
||||
// 如果targetType=1且groupPushSubType=2(群公告),则announcementContent必填
|
||||
$targetType = isset($data['targetType']) ? intval($data['targetType']) : 1; // 默认1
|
||||
$groupPushSubType = isset($data['groupPushSubType']) ? intval($data['groupPushSubType']) : 1; // 默认1
|
||||
if ($targetType == 1 && $groupPushSubType == 2) {
|
||||
// 检查值是否存在且有效
|
||||
if (!isset($value) || $value === null || trim($value) === '') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证AI智能话术改写(当enableAiRewrite=1时,aiRewritePrompt必填)
|
||||
*/
|
||||
protected function checkEnableAiRewrite($value, $rule, $data)
|
||||
{
|
||||
// 如果是群消息推送类型且是群公告
|
||||
if (isset($data['type']) && $data['type'] == self::TYPE_GROUP_PUSH) {
|
||||
$targetType = isset($data['targetType']) ? intval($data['targetType']) : 1; // 默认1
|
||||
$groupPushSubType = isset($data['groupPushSubType']) ? intval($data['groupPushSubType']) : 1; // 默认1
|
||||
if ($targetType == 1 && $groupPushSubType == 2) {
|
||||
// 检查值是否存在且有效
|
||||
if (!isset($value) || !in_array(intval($value), [0, 1])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证AI改写提示词(当enableAiRewrite=1时,aiRewritePrompt必填)
|
||||
*/
|
||||
protected function checkAiRewritePrompt($value, $rule, $data)
|
||||
{
|
||||
// 如果是群消息推送类型且是群公告
|
||||
if (isset($data['type']) && $data['type'] == self::TYPE_GROUP_PUSH) {
|
||||
$targetType = isset($data['targetType']) ? intval($data['targetType']) : 1; // 默认1
|
||||
$groupPushSubType = isset($data['groupPushSubType']) ? intval($data['groupPushSubType']) : 1; // 默认1
|
||||
$enableAiRewrite = isset($data['enableAiRewrite']) ? intval($data['enableAiRewrite']) : 0; // 默认0
|
||||
if ($targetType == 1 && $groupPushSubType == 2 && $enableAiRewrite == 1) {
|
||||
// 如果启用AI改写,提示词必填
|
||||
if (!isset($value) || $value === null || trim($value) === '') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user