朋友圈推送优化
This commit is contained in:
@@ -47,28 +47,28 @@ class AutomaticAssign extends BaseController
|
||||
}
|
||||
|
||||
$params = [
|
||||
'accountKeyword' => '',
|
||||
'addFrom' => [],
|
||||
'allotAccountId' => '',
|
||||
'containAllLabel' => false,
|
||||
'containSubDepartment' => false,
|
||||
'departmentId' => '',
|
||||
'extendFields' => [],
|
||||
'friendKeyword' => '',
|
||||
'friendPhoneKeyword' => '',
|
||||
'friendPinYinKeyword' => '',
|
||||
'friendRegionKeyword' => '',
|
||||
'friendRemarkKeyword' => '',
|
||||
'gender' => '',
|
||||
'groupId' => null,
|
||||
'isByRule' => false,
|
||||
'accountKeyword' => !empty($data['accountKeyword']) ? $data['accountKeyword'] : '',
|
||||
'addFrom' => !empty($data['addFrom']) ? $data['addFrom'] : [],
|
||||
'allotAccountId' => !empty($data['allotAccountId']) ? $data['allotAccountId'] : '',
|
||||
'containAllLabel' => !empty($data['containAllLabel']) ? $data['containAllLabel'] : false,
|
||||
'containSubDepartment' => !empty($data['containSubDepartment']) ? $data['containSubDepartment'] : false,
|
||||
'departmentId' => !empty($data['departmentId']) ? $data['departmentId'] : '',
|
||||
'extendFields' => !empty($data['extendFields']) ? $data['extendFields'] : [],
|
||||
'friendKeyword' => !empty($data['friendKeyword']) ? $data['friendKeyword'] : '',
|
||||
'friendPhoneKeyword' => !empty($data['friendPhoneKeyword']) ? $data['friendPhoneKeyword'] : '',
|
||||
'friendPinYinKeyword' => !empty($data['friendPinYinKeyword']) ? $data['friendPinYinKeyword'] : '',
|
||||
'friendRegionKeyword' => !empty($data['friendRegionKeyword']) ? $data['friendRegionKeyword'] : '',
|
||||
'friendRemarkKeyword' => !empty($data['friendRemarkKeyword']) ? $data['friendRemarkKeyword'] : '',
|
||||
'gender' => !empty($data['gender']) ? $data['gender'] : '',
|
||||
'groupId' => !empty($data['groupId']) ? $data['groupId'] : null,
|
||||
'isByRule' => !empty($data['isByRule']) ? $data['isByRule'] : false,
|
||||
'isDeleted' => $isDeleted,
|
||||
'isPass' => true,
|
||||
'keyword' => '',
|
||||
'labels' => [],
|
||||
'pageIndex' => 0,
|
||||
'pageSize' => 100,
|
||||
'preFriendId' => '',
|
||||
'isPass' => !empty($data['isPass']) ? $data['isPass'] : true,
|
||||
'keyword' => !empty($data['keyword']) ? $data['keyword'] : '',
|
||||
'labels' => !empty($data['labels']) ? $data['labels'] : [],
|
||||
'pageIndex' => !empty($data['pageIndex']) ? $data['pageIndex'] : 0,
|
||||
'pageSize' => !empty($data['pageSize']) ? $data['pageSize'] : 100,
|
||||
'preFriendId' => !empty($data['preFriendId']) ? $data['preFriendId'] : '',
|
||||
'toAccountId' => $toAccountId,
|
||||
'wechatAccountKeyword' => $wechatAccountKeyword
|
||||
];
|
||||
@@ -283,4 +283,64 @@ class AutomaticAssign extends BaseController
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分配搜索结果
|
||||
* @param array $data 请求参数
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function allotSearchResult($data = [])
|
||||
{
|
||||
// 获取授权token
|
||||
$authorization = trim($this->request->header('authorization', $this->authorization));
|
||||
if (empty($authorization)) {
|
||||
return json_encode(['code'=>500,'msg'=>'缺少授权信息']);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
$params = [
|
||||
'accountKeyword' => !empty($data['accountKeyword']) ? $data['accountKeyword'] : '',
|
||||
'addFrom' => !empty($data['addFrom']) ? $data['addFrom'] : [],
|
||||
'allotAccountId' => !empty($data['allotAccountId']) ? $data['allotAccountId'] : '',
|
||||
'containAllLabel' => !empty($data['containAllLabel']) ? $data['containAllLabel'] : false,
|
||||
'containSubDepartment' => !empty($data['containSubDepartment']) ? $data['containSubDepartment'] : false,
|
||||
'departmentId' => !empty($data['departmentId']) ? $data['departmentId'] : '',
|
||||
'extendFields' => !empty($data['extendFields']) ? json_encode($data['extendFields']) : json_encode([]),
|
||||
'friendKeyword' => !empty($data['friendKeyword']) ? $data['friendKeyword'] : '',
|
||||
'friendPhoneKeyword' => !empty($data['friendPhoneKeyword']) ? $data['friendPhoneKeyword'] : '',
|
||||
'friendPinYinKeyword' => !empty($data['friendPinYinKeyword']) ? $data['friendPinYinKeyword'] : '',
|
||||
'friendRegionKeyword' => !empty($data['friendRegionKeyword']) ? $data['friendRegionKeyword'] : '',
|
||||
'friendRemarkKeyword' => !empty($data['friendRemarkKeyword']) ? $data['friendRemarkKeyword'] : '',
|
||||
'gender' => !empty($data['gender']) ? $data['gender'] : '',
|
||||
'groupId' => !empty($data['groupId']) ? $data['groupId'] : null,
|
||||
'isByRule' => !empty($data['isByRule']) ? $data['isByRule'] : false,
|
||||
'isDeleted' => !empty($data['isDeleted']) ? $data['isDeleted'] : false,
|
||||
'isPass' => !empty($data['isPass']) ? $data['isPass'] : true,
|
||||
'keyword' => !empty($data['keyword']) ? $data['keyword'] : '',
|
||||
'labels' => !empty($data['labels']) ? $data['labels'] : [],
|
||||
'pageIndex' => !empty($data['pageIndex']) ? $data['pageIndex'] : 0,
|
||||
'pageSize' => !empty($data['pageSize']) ? $data['pageSize'] : 20,
|
||||
'preFriendId' => !empty($data['preFriendId']) ? $data['preFriendId'] : '',
|
||||
'toAccountId' => !empty($data['toAccountId']) ? $data['toAccountId'] : '',
|
||||
'wechatAccountKeyword' => !empty($data['wechatAccountKeyword']) ? $data['wechatAccountKeyword'] : ''
|
||||
];
|
||||
|
||||
// 设置请求头
|
||||
$headerData = ['client:system'];
|
||||
$header = setHeader($headerData, $authorization, 'json');
|
||||
|
||||
// 发送请求
|
||||
$result = requestCurl($this->baseUrl . 'api/WechatFriend/allotSearchResult', $params, 'POST', $header, 'json');
|
||||
$response = handleApiResponse($result);
|
||||
if($response){
|
||||
return json_encode(['code'=>200,'msg'=>'分配成功']);
|
||||
}else{
|
||||
return json_encode(['code'=>500,'msg'=>$response]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
return json_encode(['code'=>500,'msg'=>'微信好友分配失败:' . $e->getMessage()]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -69,7 +69,6 @@ class WorkbenchMomentsJob
|
||||
try {
|
||||
// 获取所有工作台
|
||||
$workbenches = Workbench::where(['status' => 1, 'type' => 2, 'isDel' => 0])->order('id desc')->select();
|
||||
|
||||
foreach ($workbenches as $workbench) {
|
||||
// 获取工作台配置
|
||||
$config = WorkbenchMoments::where('workbenchId', $workbench->id)->find();
|
||||
@@ -85,7 +84,6 @@ class WorkbenchMomentsJob
|
||||
|
||||
// 获取设备
|
||||
$devices = $this->getDevice($workbench, $config);
|
||||
|
||||
if (empty($devices)) {
|
||||
continue;
|
||||
}
|
||||
@@ -95,6 +93,7 @@ class WorkbenchMomentsJob
|
||||
if (empty($contentLibrary)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 处理内容发送
|
||||
$this->handleContentSend($workbench, $config, $devices, $contentLibrary);
|
||||
}
|
||||
@@ -279,11 +278,9 @@ class WorkbenchMomentsJob
|
||||
if (empty($contentids)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 基础查询
|
||||
$query = Db::name('content_library')->alias('cl')
|
||||
->join('content_item ci', 'ci.libraryId = cl.id')
|
||||
->join('workbench_moments_sync_item wmsi', 'wmsi.contentId = ci.id and wmsi.workbenchId = ' . $workbench->id, 'left')
|
||||
->where(['cl.isDel' => 0, 'ci.isDel' => 0])
|
||||
->where('ci.sendTime <= ' . (time() + 60))
|
||||
->whereIn('cl.id', $contentids)
|
||||
@@ -303,23 +300,47 @@ class WorkbenchMomentsJob
|
||||
if ($config['accountType'] == 1) {
|
||||
// 可以循环发送
|
||||
// 1. 优先获取未发送的内容
|
||||
$unsentContent = $query->where('wmsi.id', 'null')
|
||||
$unsentContent = $query->join('workbench_moments_sync_item wmsi', 'wmsi.contentId = ci.id and wmsi.workbenchId = ' . $workbench->id, 'left')
|
||||
->where('wmsi.id', 'null')
|
||||
->order('ci.sendTime desc, ci.id desc')
|
||||
->find();
|
||||
|
||||
if (!empty($unsentContent)) {
|
||||
return $unsentContent;
|
||||
}
|
||||
$lastSendData = Db::name('workbench_moments_sync_item')->order('id desc')->find();
|
||||
$fastSendData = Db::name('workbench_moments_sync_item')->order('id asc')->find();
|
||||
|
||||
|
||||
// 2. 如果没有未发送的内容,则获取已发送的内容中最早发送的
|
||||
$sentContent = $query->where('wmsi.id', 'not null')
|
||||
->order('wmsi.createTime asc, ci.sendTime desc, ci.id desc')
|
||||
->find();
|
||||
$sentContent = Db::name('content_library')->alias('cl')
|
||||
->join('content_item ci', 'ci.libraryId = cl.id')
|
||||
->join('workbench_moments_sync_item wmsi', 'wmsi.contentId = ci.id and wmsi.workbenchId = ' . $workbench->id, 'left')
|
||||
->where(['cl.isDel' => 0, 'ci.isDel' => 0])
|
||||
->where('ci.sendTime <= ' . (time() + 60))
|
||||
->whereIn('cl.id', $contentids)
|
||||
->field([
|
||||
'ci.id',
|
||||
'ci.libraryId',
|
||||
'ci.contentType',
|
||||
'ci.title',
|
||||
'ci.content',
|
||||
'ci.resUrls',
|
||||
'ci.urls',
|
||||
'ci.comment',
|
||||
'ci.sendTime'
|
||||
]);
|
||||
|
||||
if ($lastSendData['contentId'] >= $fastSendData['contentId']){
|
||||
$sentContent = $sentContent->where('wmsi.contentId','<' ,$lastSendData['contentId'])->order('wmsi.id ASC')->group('wmsi.contentId')->find();
|
||||
}else{
|
||||
$sentContent = $sentContent->where('wmsi.contentId','>' ,$lastSendData['contentId'])->order('wmsi.id ASC')->group('wmsi.contentId')->find();
|
||||
}
|
||||
return $sentContent;
|
||||
} else {
|
||||
// 不能循环发送,只获取未发送的内容
|
||||
$list = $query->where('wmsi.id', 'null')
|
||||
$list = $query->join('workbench_moments_sync_item wmsi', 'wmsi.contentId = ci.id and wmsi.workbenchId = ' . $workbench->id, 'left')
|
||||
->where('wmsi.id', 'null')
|
||||
->order('ci.sendTime desc, ci.id desc')
|
||||
->find();
|
||||
return $list;
|
||||
|
||||
Reference in New Issue
Block a user