朋友圈推送优化

This commit is contained in:
wong
2025-07-16 11:25:36 +08:00
parent c08b9b0b26
commit 342b239d76
2 changed files with 111 additions and 30 deletions

View File

@@ -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;