代码提交
This commit is contained in:
@@ -109,13 +109,26 @@ class WorkbenchController extends Controller
|
||||
$config = new WorkbenchGroupPush;
|
||||
$config->workbenchId = $workbench->id;
|
||||
$config->pushType = !empty($param['pushType']) ? 1 : 0; // 推送方式:定时/立即
|
||||
$config->targetType = !empty($param['targetType']) ? intval($param['targetType']) : 1; // 推送目标类型:1=群推送,2=好友推送
|
||||
$config->startTime = $param['startTime'];
|
||||
$config->endTime = $param['endTime'];
|
||||
$config->maxPerDay = intval($param['maxPerDay']); // 每日推送数
|
||||
$config->pushOrder = $param['pushOrder']; // 推送顺序
|
||||
$config->isLoop = !empty($param['isLoop']) ? 1 : 0; // 是否循环
|
||||
// 根据targetType存储不同的数据
|
||||
if ($config->targetType == 1) {
|
||||
// 群推送
|
||||
$config->isLoop = !empty($param['isLoop']) ? 1 : 0; // 是否循环
|
||||
$config->groups = json_encode($param['wechatGroups'] ?? [], JSON_UNESCAPED_UNICODE); // 群组信息
|
||||
$config->friends = json_encode([], JSON_UNESCAPED_UNICODE); // 好友信息为空数组
|
||||
$config->devices = json_encode([], JSON_UNESCAPED_UNICODE); // 群推送不需要设备
|
||||
} else {
|
||||
// 好友推送:isLoop必须为0,设备必填
|
||||
$config->isLoop = 0; // 好友推送时强制为0
|
||||
$config->friends = json_encode($param['wechatFriends'] ?? [], JSON_UNESCAPED_UNICODE); // 好友信息(可以为空数组)
|
||||
$config->groups = json_encode([], JSON_UNESCAPED_UNICODE); // 群组信息为空数组
|
||||
$config->devices = json_encode($param['deviceGroups'] ?? [], JSON_UNESCAPED_UNICODE); // 设备信息(必填)
|
||||
}
|
||||
$config->status = !empty($param['status']) ? 1 : 0; // 是否启用
|
||||
$config->groups = json_encode($param['wechatGroups'], JSON_UNESCAPED_UNICODE); // 群组信息
|
||||
$config->contentLibraries = json_encode($param['contentGroups'], JSON_UNESCAPED_UNICODE); // 内容库信息
|
||||
$config->socialMediaId = !empty($param['socialMediaId']) ? $param['socialMediaId'] : '';
|
||||
$config->promotionSiteId = !empty($param['promotionSiteId']) ? $param['promotionSiteId'] : '';
|
||||
@@ -216,7 +229,7 @@ class WorkbenchController extends Controller
|
||||
$query->field('workbenchId,distributeType,maxPerDay,timeType,startTime,endTime,devices,pools,account');
|
||||
},
|
||||
'groupPush' => function ($query) {
|
||||
$query->field('workbenchId,pushType,startTime,endTime,maxPerDay,pushOrder,isLoop,status,groups,contentLibraries');
|
||||
$query->field('workbenchId,pushType,targetType,startTime,endTime,maxPerDay,pushOrder,isLoop,status,groups,friends,devices,contentLibraries');
|
||||
},
|
||||
'groupCreate' => function($query) {
|
||||
$query->field('workbenchId,devices,startTime,endTime,groupSizeMin,groupSizeMax,maxGroupsPerDay,groupNameTemplate,groupDescription,poolGroups,wechatGroups');
|
||||
@@ -289,13 +302,25 @@ class WorkbenchController extends Controller
|
||||
if (!empty($item->groupPush)) {
|
||||
$item->config = $item->groupPush;
|
||||
$item->config->pushType = $item->config->pushType;
|
||||
$item->config->targetType = isset($item->config->targetType) ? intval($item->config->targetType) : 1; // 默认1=群推送
|
||||
$item->config->startTime = $item->config->startTime;
|
||||
$item->config->endTime = $item->config->endTime;
|
||||
$item->config->maxPerDay = $item->config->maxPerDay;
|
||||
$item->config->pushOrder = $item->config->pushOrder;
|
||||
$item->config->isLoop = $item->config->isLoop;
|
||||
$item->config->status = $item->config->status;
|
||||
$item->config->groups = json_decode($item->config->groups, true);
|
||||
// 根据targetType解析不同的数据
|
||||
if ($item->config->targetType == 1) {
|
||||
// 群推送
|
||||
$item->config->wechatGroups = json_decode($item->config->groups, true) ?: [];
|
||||
$item->config->wechatFriends = [];
|
||||
$item->config->deviceGroups = [];
|
||||
} else {
|
||||
// 好友推送
|
||||
$item->config->wechatFriends = json_decode($item->config->friends, true) ?: [];
|
||||
$item->config->wechatGroups = [];
|
||||
$item->config->deviceGroups = json_decode($item->config->devices ?? '[]', true) ?: [];
|
||||
}
|
||||
$item->config->contentLibraries = json_decode($item->config->contentLibraries, true);
|
||||
$item->config->lastPushTime = '';
|
||||
}
|
||||
@@ -413,7 +438,7 @@ class WorkbenchController extends Controller
|
||||
$query->field('workbenchId,distributeType,maxPerDay,timeType,startTime,endTime,devices,pools,account');
|
||||
},
|
||||
'groupPush' => function ($query) {
|
||||
$query->field('workbenchId,pushType,startTime,endTime,maxPerDay,pushOrder,isLoop,status,groups,contentLibraries');
|
||||
$query->field('workbenchId,pushType,targetType,startTime,endTime,maxPerDay,pushOrder,isLoop,status,groups,friends,devices,contentLibraries');
|
||||
},
|
||||
'groupCreate' => function($query) {
|
||||
$query->field('workbenchId,devices,startTime,endTime,groupSizeMin,groupSizeMax,maxGroupsPerDay,groupNameTemplate,groupDescription,poolGroups,wechatGroups');
|
||||
@@ -484,7 +509,19 @@ class WorkbenchController extends Controller
|
||||
case self::TYPE_GROUP_PUSH:
|
||||
if (!empty($workbench->groupPush)) {
|
||||
$workbench->config = $workbench->groupPush;
|
||||
$workbench->config->wechatGroups = json_decode($workbench->config->groups, true);
|
||||
$workbench->config->targetType = isset($workbench->config->targetType) ? intval($workbench->config->targetType) : 1; // 默认1=群推送
|
||||
// 根据targetType解析不同的数据
|
||||
if ($workbench->config->targetType == 1) {
|
||||
// 群推送
|
||||
$workbench->config->wechatGroups = json_decode($workbench->config->groups, true) ?: [];
|
||||
$workbench->config->wechatFriends = [];
|
||||
$workbench->config->deviceGroups = [];
|
||||
} else {
|
||||
// 好友推送
|
||||
$workbench->config->wechatFriends = json_decode($workbench->config->friends, true) ?: [];
|
||||
$workbench->config->wechatGroups = [];
|
||||
$workbench->config->deviceGroups = json_decode($workbench->config->devices ?? '[]', true) ?: [];
|
||||
}
|
||||
$workbench->config->contentLibraries = json_decode($workbench->config->contentLibraries, true);
|
||||
unset($workbench->groupPush, $workbench->group_push);
|
||||
}
|
||||
@@ -603,11 +640,11 @@ class WorkbenchController extends Controller
|
||||
}
|
||||
|
||||
|
||||
// 获取群
|
||||
if (!empty($workbench->config->wechatGroups)){
|
||||
// 获取群(当targetType=1时)
|
||||
if (!empty($workbench->config->wechatGroups) && isset($workbench->config->targetType) && $workbench->config->targetType == 1){
|
||||
$groupList = Db::name('wechat_group')->alias('wg')
|
||||
->join('wechat_account wa', 'wa.wechatId = wg.ownerWechatId')
|
||||
->where('wg.id', 'in', $workbench->config->groups)
|
||||
->where('wg.id', 'in', $workbench->config->wechatGroups)
|
||||
->order('wg.id', 'desc')
|
||||
->field('wg.id,wg.name as groupName,wg.ownerWechatId,wa.nickName,wa.avatar,wa.alias,wg.avatar as groupAvatar')
|
||||
->select();
|
||||
@@ -616,6 +653,19 @@ class WorkbenchController extends Controller
|
||||
$workbench->config->wechatGroupsOptions = [];
|
||||
}
|
||||
|
||||
// 获取好友(当targetType=2时)
|
||||
if (!empty($workbench->config->wechatFriends) && isset($workbench->config->targetType) && $workbench->config->targetType == 2){
|
||||
$friendList = Db::table('s2_wechat_friend')->alias('wf')
|
||||
->join('s2_wechat_account wa', 'wa.id = wf.wechatAccountId', 'left')
|
||||
->where('wf.id', 'in', $workbench->config->wechatFriends)
|
||||
->order('wf.id', 'desc')
|
||||
->field('wf.id,wf.wechatId,wf.nickname as friendName,wf.avatar as friendAvatar,wf.conRemark,wf.ownerWechatId,wa.nickName as accountName,wa.avatar as accountAvatar')
|
||||
->select();
|
||||
$workbench->config->wechatFriendsOptions = $friendList;
|
||||
}else{
|
||||
$workbench->config->wechatFriendsOptions = [];
|
||||
}
|
||||
|
||||
// 获取内容库名称
|
||||
if (!empty($workbench->config->contentGroups)) {
|
||||
$libraryNames = ContentLibrary::where('id', 'in', $workbench->config->contentGroups)->select();
|
||||
@@ -748,13 +798,26 @@ class WorkbenchController extends Controller
|
||||
$config = WorkbenchGroupPush::where('workbenchId', $param['id'])->find();
|
||||
if ($config) {
|
||||
$config->pushType = !empty($param['pushType']) ? 1 : 0; // 推送方式:定时/立即
|
||||
$config->targetType = !empty($param['targetType']) ? intval($param['targetType']) : 1; // 推送目标类型:1=群推送,2=好友推送
|
||||
$config->startTime = $param['startTime'];
|
||||
$config->endTime = $param['endTime'];
|
||||
$config->maxPerDay = intval($param['maxPerDay']); // 每日推送数
|
||||
$config->pushOrder = $param['pushOrder']; // 推送顺序
|
||||
$config->isLoop = !empty($param['isLoop']) ? 1 : 0; // 是否循环
|
||||
// 根据targetType存储不同的数据
|
||||
if ($config->targetType == 1) {
|
||||
// 群推送
|
||||
$config->isLoop = !empty($param['isLoop']) ? 1 : 0; // 是否循环
|
||||
$config->groups = json_encode($param['wechatGroups'] ?? [], JSON_UNESCAPED_UNICODE); // 群组信息
|
||||
$config->friends = json_encode([], JSON_UNESCAPED_UNICODE); // 好友信息为空数组
|
||||
$config->devices = json_encode([], JSON_UNESCAPED_UNICODE); // 群推送不需要设备
|
||||
} else {
|
||||
// 好友推送:isLoop必须为0,设备必填
|
||||
$config->isLoop = 0; // 好友推送时强制为0
|
||||
$config->friends = json_encode($param['wechatFriends'] ?? [], JSON_UNESCAPED_UNICODE); // 好友信息(可以为空数组)
|
||||
$config->groups = json_encode([], JSON_UNESCAPED_UNICODE); // 群组信息为空数组
|
||||
$config->devices = json_encode($param['deviceGroups'] ?? [], JSON_UNESCAPED_UNICODE); // 设备信息(必填)
|
||||
}
|
||||
$config->status = !empty($param['status']) ? 1 : 0; // 是否启用
|
||||
$config->groups = json_encode($param['wechatGroups'], JSON_UNESCAPED_UNICODE); // 群组信息
|
||||
$config->contentLibraries = json_encode($param['contentGroups'], JSON_UNESCAPED_UNICODE); // 内容库信息
|
||||
$config->socialMediaId = !empty($param['socialMediaId']) ? $param['socialMediaId'] : '';
|
||||
$config->promotionSiteId = !empty($param['promotionSiteId']) ? $param['promotionSiteId'] : '';
|
||||
@@ -957,6 +1020,7 @@ class WorkbenchController extends Controller
|
||||
$newConfig = new WorkbenchGroupPush;
|
||||
$newConfig->workbenchId = $newWorkbench->id;
|
||||
$newConfig->pushType = $config->pushType;
|
||||
$newConfig->targetType = isset($config->targetType) ? $config->targetType : 1; // 默认1=群推送
|
||||
$newConfig->startTime = $config->startTime;
|
||||
$newConfig->endTime = $config->endTime;
|
||||
$newConfig->maxPerDay = $config->maxPerDay;
|
||||
@@ -964,7 +1028,11 @@ class WorkbenchController extends Controller
|
||||
$newConfig->isLoop = $config->isLoop;
|
||||
$newConfig->status = $config->status;
|
||||
$newConfig->groups = $config->groups;
|
||||
$newConfig->friends = $config->friends;
|
||||
$newConfig->devices = $config->devices;
|
||||
$newConfig->contentLibraries = $config->contentLibraries;
|
||||
$newConfig->socialMediaId = $config->socialMediaId;
|
||||
$newConfig->promotionSiteId = $config->promotionSiteId;
|
||||
$newConfig->createTime = time();
|
||||
$newConfig->updateTime = time();
|
||||
$newConfig->save();
|
||||
|
||||
Reference in New Issue
Block a user