朋友圈内容库优化
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user