代码提交
This commit is contained in:
@@ -337,7 +337,6 @@ class WorkbenchGroupPushJob
|
|||||||
->order($order)
|
->order($order)
|
||||||
->limit(0, $limit)
|
->limit(0, $limit)
|
||||||
->select();
|
->select();
|
||||||
exit_data($unsentContent);
|
|
||||||
if (!empty($unsentContent)) {
|
if (!empty($unsentContent)) {
|
||||||
return $unsentContent;
|
return $unsentContent;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -186,6 +186,7 @@ class WorkbenchMomentsJob
|
|||||||
$this->recordSendHistory($workbench, $devices, $contentLibrary);
|
$this->recordSendHistory($workbench, $devices, $contentLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记录发送历史
|
* 记录发送历史
|
||||||
* @param Workbench $workbench
|
* @param Workbench $workbench
|
||||||
@@ -202,6 +203,7 @@ class WorkbenchMomentsJob
|
|||||||
'deviceId' => $device['deviceId'],
|
'deviceId' => $device['deviceId'],
|
||||||
'contentId' => $contentLibrary['id'],
|
'contentId' => $contentLibrary['id'],
|
||||||
'wechatAccountId' => $device['wechatAccountId'],
|
'wechatAccountId' => $device['wechatAccountId'],
|
||||||
|
'isLoop' => 0, // 初始状态为未完成循环
|
||||||
'createTime' => $now,
|
'createTime' => $now,
|
||||||
];
|
];
|
||||||
Db::name('workbench_moments_sync_item')->insert($data);
|
Db::name('workbench_moments_sync_item')->insert($data);
|
||||||
@@ -274,15 +276,21 @@ class WorkbenchMomentsJob
|
|||||||
protected function getContentLibrary($workbench, $config)
|
protected function getContentLibrary($workbench, $config)
|
||||||
{
|
{
|
||||||
$contentids = json_decode($config['contentLibraries'], true);
|
$contentids = json_decode($config['contentLibraries'], true);
|
||||||
if (empty($contentids)) {
|
// 清洗 contentids:去除 null/空字符串,并去重,保持原顺序
|
||||||
|
if (is_array($contentids)) {
|
||||||
|
$contentids = array_values(array_unique(array_filter($contentids, function ($v) {
|
||||||
|
return $v !== null && $v !== '';
|
||||||
|
})));
|
||||||
|
} else {
|
||||||
|
$contentids = [];
|
||||||
|
}
|
||||||
|
if (empty($contentids)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// 基础查询
|
// 基础查询
|
||||||
$query = Db::name('content_library')->alias('cl')
|
$query = Db::name('content_library')->alias('cl')
|
||||||
->join('content_item ci', 'ci.libraryId = cl.id')
|
->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(['cl.isDel' => 0, 'ci.isDel' => 0])
|
||||||
->where('ci.sendTime <= ' . (time() + 60))
|
|
||||||
->whereIn('cl.id', $contentids)
|
->whereIn('cl.id', $contentids)
|
||||||
->field([
|
->field([
|
||||||
'ci.id',
|
'ci.id',
|
||||||
@@ -302,24 +310,44 @@ class WorkbenchMomentsJob
|
|||||||
if ($config['accountType'] == 1) {
|
if ($config['accountType'] == 1) {
|
||||||
// 可以循环发送
|
// 可以循环发送
|
||||||
// 1. 优先获取未发送的内容
|
// 1. 优先获取未发送的内容
|
||||||
$unsentContent = $query->where('wmsi.id', 'null')
|
$unsentContent = $query2->join('workbench_moments_sync_item wmsi', 'wmsi.contentId = ci.id and wmsi.workbenchId = ' . $workbench->id, 'left')
|
||||||
|
->where('wmsi.id', 'null')
|
||||||
|
->where('ci.sendTime <= ' . (time() + 60))
|
||||||
->order('ci.sendTime desc, ci.id desc')
|
->order('ci.sendTime desc, ci.id desc')
|
||||||
->find();
|
->find();
|
||||||
|
|
||||||
if (!empty($unsentContent)) {
|
if (!empty($unsentContent)) {
|
||||||
return $unsentContent;
|
return $unsentContent;
|
||||||
}
|
}
|
||||||
$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();
|
// 获取下一个要发送的内容(从内容库中查询,排除isLoop为0的数据)
|
||||||
|
$isPushIds = Db::name('workbench_moments_sync_item')
|
||||||
|
->where(['workbenchId' => $workbench->id,'isLoop' => 0])
|
||||||
|
->column('contentId');
|
||||||
|
|
||||||
if (empty($sentContent)) {
|
if (empty($isPushIds)) {
|
||||||
$sentContent = $query3->where('wmsi.contentId','=' ,$fastSendData['contentId'])->order('wmsi.id ASC')->group('wmsi.contentId')->find();
|
$isPushIds = [0];
|
||||||
}
|
}
|
||||||
|
$sentContent = $query3
|
||||||
|
->whereNotIn('ci.id', $isPushIds)
|
||||||
|
->group('ci.id')
|
||||||
|
->order('ci.id asc')
|
||||||
|
->find();
|
||||||
|
// 4. 如果仍然没有内容,说明内容库为空,将所有记录的isLoop标记为1
|
||||||
|
if (empty($sentContent)) {
|
||||||
|
// 将所有该工作台的记录标记为循环完成
|
||||||
|
Db::name('workbench_moments_sync_item')
|
||||||
|
->where('workbenchId', $workbench->id)
|
||||||
|
->where('isLoop', 0)
|
||||||
|
->update(['isLoop' => 1]);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return $sentContent;
|
return $sentContent;
|
||||||
} else {
|
} else {
|
||||||
// 不能循环发送,只获取未发送的内容
|
// 不能循环发送,只获取未发送的内容
|
||||||
$list = $query->where('wmsi.id', 'null')
|
$list = $query2->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')
|
->order('ci.sendTime desc, ci.id desc')
|
||||||
->find();
|
->find();
|
||||||
return $list;
|
return $list;
|
||||||
|
|||||||
Reference in New Issue
Block a user