朋友圈业务号发布优化
This commit is contained in:
@@ -93,7 +93,6 @@ class WorkbenchMomentsJob
|
||||
if (empty($contentLibrary)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 处理内容发送
|
||||
$this->handleContentSend($workbench, $config, $devices, $contentLibrary);
|
||||
}
|
||||
@@ -281,6 +280,7 @@ class WorkbenchMomentsJob
|
||||
// 基础查询
|
||||
$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)
|
||||
@@ -295,52 +295,31 @@ class WorkbenchMomentsJob
|
||||
'ci.comment',
|
||||
'ci.sendTime'
|
||||
]);
|
||||
|
||||
// 复制 query
|
||||
$query2 = clone $query;
|
||||
$query3 = clone $query;
|
||||
// 根据accountType处理不同的发送逻辑
|
||||
if ($config['accountType'] == 1) {
|
||||
// 可以循环发送
|
||||
// 1. 优先获取未发送的内容
|
||||
$unsentContent = $query->join('workbench_moments_sync_item wmsi', 'wmsi.contentId = ci.id and wmsi.workbenchId = ' . $workbench->id, 'left')
|
||||
->where('wmsi.id', 'null')
|
||||
$unsentContent = $query->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();
|
||||
$lastSendData = Db::name('workbench_moments_sync_item')->where('workbenchId' ,$workbench->id)->order('id desc')->find();
|
||||
$fastSendData = Db::name('workbench_moments_sync_item')->where('workbenchId' ,$workbench->id)->order('id asc')->find();
|
||||
|
||||
$sentContent = $query2->where('wmsi.contentId','<' ,$lastSendData['contentId'])->order('wmsi.id ASC')->group('wmsi.contentId')->find();
|
||||
|
||||
// 2. 如果没有未发送的内容,则获取已发送的内容中最早发送的
|
||||
$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();
|
||||
if (empty($sentContent)) {
|
||||
$sentContent = $query3->where('wmsi.contentId','=' ,$fastSendData['contentId'])->order('wmsi.id ASC')->group('wmsi.contentId')->find();
|
||||
}
|
||||
return $sentContent;
|
||||
} else {
|
||||
// 不能循环发送,只获取未发送的内容
|
||||
$list = $query->join('workbench_moments_sync_item wmsi', 'wmsi.contentId = ci.id and wmsi.workbenchId = ' . $workbench->id, 'left')
|
||||
->where('wmsi.id', 'null')
|
||||
$list = $query->where('wmsi.id', 'null')
|
||||
->order('ci.sendTime desc, ci.id desc')
|
||||
->find();
|
||||
return $list;
|
||||
|
||||
Reference in New Issue
Block a user