朋友圈内容库优化
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');
|
$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) : '--';
|
$item->lastSyncTime = !empty($lastTime) ? date('Y-m-d H:i',$lastTime) : '--';
|
||||||
|
|
||||||
|
|
||||||
// 获取内容库名称
|
// 获取内容库名称
|
||||||
if (!empty($item->config->contentLibraries)) {
|
if (!empty($item->config->contentLibraries)) {
|
||||||
$libraryNames = ContentLibrary::where('id', 'in', $item->config->contentLibraries)
|
$libraryNames = ContentLibrary::whereIn('id', $item->config->contentLibraries)
|
||||||
->column('name');
|
->column('name');
|
||||||
$item->config->contentLibraryNames = $libraryNames;
|
$item->config->contentLibraryNames = $libraryNames;
|
||||||
} else {
|
} else {
|
||||||
@@ -678,6 +679,18 @@ class WorkbenchController extends Controller
|
|||||||
case self::TYPE_MOMENTS_SYNC:
|
case self::TYPE_MOMENTS_SYNC:
|
||||||
$config = WorkbenchMomentsSync::where('workbenchId', $param['id'])->find();
|
$config = WorkbenchMomentsSync::where('workbenchId', $param['id'])->find();
|
||||||
if ($config) {
|
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->syncInterval = $param['syncInterval'];
|
||||||
$config->syncCount = $param['syncCount'];
|
$config->syncCount = $param['syncCount'];
|
||||||
$config->syncType = $param['syncType'];
|
$config->syncType = $param['syncType'];
|
||||||
@@ -685,7 +698,7 @@ class WorkbenchController extends Controller
|
|||||||
$config->endTime = $param['endTime'];
|
$config->endTime = $param['endTime'];
|
||||||
$config->accountType = $param['accountType'];
|
$config->accountType = $param['accountType'];
|
||||||
$config->devices = json_encode($param['devices']);
|
$config->devices = json_encode($param['devices']);
|
||||||
$config->contentLibraries = json_encode($param['contentLibraries'] ?? []);
|
$config->contentLibraries = json_encode($contentLibraries);
|
||||||
$config->updateTime = time();
|
$config->updateTime = time();
|
||||||
$config->save();
|
$config->save();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ class WorkbenchMomentsJob
|
|||||||
|
|
||||||
// 获取设备
|
// 获取设备
|
||||||
$devices = $this->getDevice($workbench, $config);
|
$devices = $this->getDevice($workbench, $config);
|
||||||
|
|
||||||
if (empty($devices)) {
|
if (empty($devices)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -94,7 +95,6 @@ class WorkbenchMomentsJob
|
|||||||
if (empty($contentLibrary)) {
|
if (empty($contentLibrary)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理内容发送
|
// 处理内容发送
|
||||||
$this->handleContentSend($workbench, $config, $devices, $contentLibrary);
|
$this->handleContentSend($workbench, $config, $devices, $contentLibrary);
|
||||||
}
|
}
|
||||||
@@ -234,27 +234,30 @@ class WorkbenchMomentsJob
|
|||||||
|
|
||||||
$newList = [];
|
$newList = [];
|
||||||
foreach ($list as $val) {
|
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')
|
$count = Db::name('workbench_moments_sync_item')
|
||||||
->where('workbenchId', $workbench->id)
|
->where('workbenchId', $workbench->id)
|
||||||
->where('deviceId', $val['deviceId'])
|
->where('deviceId', $val['deviceId'])
|
||||||
->whereTime('createTime', 'between', [
|
->whereTime('createTime', 'between', [$startTimestamp, $endTimestamp])
|
||||||
strtotime(date('Y-m-d') . '00:00:00'),
|
->count();
|
||||||
strtotime(date('Y-m-d') . '23:59:59')
|
|
||||||
])->count();
|
|
||||||
|
|
||||||
if ($count >= $config['syncCount']) {
|
if ($count >= $config['syncCount']) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查发送间隔
|
// 计算本次同步的最早允许时间
|
||||||
$prevSend = Db::name('workbench_moments_sync_item')
|
$nextSyncTime = $startTimestamp + $count * $interval;
|
||||||
->where('workbenchId', $workbench->id)
|
if (time() < $nextSyncTime) {
|
||||||
->where('deviceId', $val['deviceId'])
|
|
||||||
->order('createTime DESC')
|
|
||||||
->find();
|
|
||||||
|
|
||||||
if (!empty($prevSend) && ($prevSend['createTime'] + $config['syncInterval'] * 60) > time()) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user