From bd5e06182dc8e1e7ae9f4cbc59630105c48473b3 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Fri, 11 Jul 2025 11:09:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8B=E5=8F=8B=E5=9C=88=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E5=BA=93=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WorkbenchController.php | 17 ++++++++-- .../application/job/WorkbenchMomentsJob.php | 31 ++++++++++--------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/Server/application/cunkebao/controller/WorkbenchController.php b/Server/application/cunkebao/controller/WorkbenchController.php index 67eb0b9b..5bf682a6 100644 --- a/Server/application/cunkebao/controller/WorkbenchController.php +++ b/Server/application/cunkebao/controller/WorkbenchController.php @@ -244,9 +244,10 @@ class WorkbenchController extends Controller $lastTime = Db::name('workbench_moments_sync_item')->where(['workbenchId' => $item->id])->order('id DESC')->value('createTime'); $item->lastSyncTime = !empty($lastTime) ? date('Y-m-d H:i',$lastTime) : '--'; + // 获取内容库名称 if (!empty($item->config->contentLibraries)) { - $libraryNames = ContentLibrary::where('id', 'in', $item->config->contentLibraries) + $libraryNames = ContentLibrary::whereIn('id', $item->config->contentLibraries) ->column('name'); $item->config->contentLibraryNames = $libraryNames; } else { @@ -678,6 +679,18 @@ class WorkbenchController extends Controller case self::TYPE_MOMENTS_SYNC: $config = WorkbenchMomentsSync::where('workbenchId', $param['id'])->find(); if ($config) { + if (!empty($param['contentLibraries'])){ + foreach ($param['contentLibraries'] as $library){ + if(isset($library['id']) && !empty($library['id'])){ + $contentLibraries[] = $library['id']; + }else{ + $contentLibraries[] = $library; + } + } + }else{ + $contentLibraries = []; + } + $config->syncInterval = $param['syncInterval']; $config->syncCount = $param['syncCount']; $config->syncType = $param['syncType']; @@ -685,7 +698,7 @@ class WorkbenchController extends Controller $config->endTime = $param['endTime']; $config->accountType = $param['accountType']; $config->devices = json_encode($param['devices']); - $config->contentLibraries = json_encode($param['contentLibraries'] ?? []); + $config->contentLibraries = json_encode($contentLibraries); $config->updateTime = time(); $config->save(); } diff --git a/Server/application/job/WorkbenchMomentsJob.php b/Server/application/job/WorkbenchMomentsJob.php index a24baf8a..a62ca783 100644 --- a/Server/application/job/WorkbenchMomentsJob.php +++ b/Server/application/job/WorkbenchMomentsJob.php @@ -85,6 +85,7 @@ class WorkbenchMomentsJob // 获取设备 $devices = $this->getDevice($workbench, $config); + if (empty($devices)) { continue; } @@ -94,7 +95,6 @@ class WorkbenchMomentsJob if (empty($contentLibrary)) { continue; } - // 处理内容发送 $this->handleContentSend($workbench, $config, $devices, $contentLibrary); } @@ -234,27 +234,30 @@ class WorkbenchMomentsJob $newList = []; foreach ($list as $val) { - // 检查今日发送次数 + // 检查发送间隔(新逻辑:根据startTime、endTime、syncCount动态计算) + $today = date('Y-m-d'); + $startTimestamp = strtotime($today . ' ' . $config['startTime'] . ':00'); + $endTimestamp = strtotime($today . ' ' . $config['endTime'] . ':00'); + $totalSeconds = $endTimestamp - $startTimestamp; + if ($totalSeconds <= 0 || empty($config['syncCount'])) { + continue; + } + $interval = floor($totalSeconds / $config['syncCount']); + + // 查询今日已同步次数 $count = Db::name('workbench_moments_sync_item') ->where('workbenchId', $workbench->id) ->where('deviceId', $val['deviceId']) - ->whereTime('createTime', 'between', [ - strtotime(date('Y-m-d') . '00:00:00'), - strtotime(date('Y-m-d') . '23:59:59') - ])->count(); + ->whereTime('createTime', 'between', [$startTimestamp, $endTimestamp]) + ->count(); if ($count >= $config['syncCount']) { continue; } - // 检查发送间隔 - $prevSend = Db::name('workbench_moments_sync_item') - ->where('workbenchId', $workbench->id) - ->where('deviceId', $val['deviceId']) - ->order('createTime DESC') - ->find(); - - if (!empty($prevSend) && ($prevSend['createTime'] + $config['syncInterval'] * 60) > time()) { + // 计算本次同步的最早允许时间 + $nextSyncTime = $startTimestamp + $count * $interval; + if (time() < $nextSyncTime) { continue; }