From c6aab288ea9f38dd0cf6a70247b4355893c5a342 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Wed, 16 Jul 2025 17:08:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8B=E5=8F=8B=E5=9C=88=E4=B8=9A=E5=8A=A1?= =?UTF-8?q?=E5=8F=B7=E5=8F=91=E5=B8=83=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/job/WorkbenchMomentsJob.php | 43 +++++-------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/Server/application/job/WorkbenchMomentsJob.php b/Server/application/job/WorkbenchMomentsJob.php index 54c19c01..41ed4701 100644 --- a/Server/application/job/WorkbenchMomentsJob.php +++ b/Server/application/job/WorkbenchMomentsJob.php @@ -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;