客服端 内容管理功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace app\job;
|
||||
|
||||
use app\api\controller\WebSocketController;
|
||||
@@ -13,6 +14,7 @@ use think\queue\Job;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Config;
|
||||
use app\api\controller\MomentsController as Moments;
|
||||
use app\chukebao\model\KfMoments;
|
||||
|
||||
/**
|
||||
* 工作台朋友圈同步任务
|
||||
@@ -52,6 +54,7 @@ class WorkbenchMomentsJob
|
||||
$queueLockKey = $data['queueLockKey'] ?? '';
|
||||
try {
|
||||
$this->logJobStart($jobId, $queueLockKey);
|
||||
$this->execute2();
|
||||
$this->execute();
|
||||
$this->handleJobSuccess($job, $queueLockKey);
|
||||
return true;
|
||||
@@ -75,13 +78,13 @@ class WorkbenchMomentsJob
|
||||
if (!$config) {
|
||||
continue;
|
||||
}
|
||||
$startTime = strtotime(date('Y-m-d '. $config['startTime']));
|
||||
$endTime = strtotime(date('Y-m-d '. $config['endTime']));
|
||||
$startTime = strtotime(date('Y-m-d ' . $config['startTime']));
|
||||
$endTime = strtotime(date('Y-m-d ' . $config['endTime']));
|
||||
// 如果时间不符,则跳过
|
||||
if($startTime > time() || $endTime < time()){
|
||||
if ($startTime > time() || $endTime < time()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// 获取设备
|
||||
$devices = $this->getDevice($workbench, $config);
|
||||
if (empty($devices)) {
|
||||
@@ -102,6 +105,53 @@ class WorkbenchMomentsJob
|
||||
}
|
||||
}
|
||||
|
||||
public function execute2()
|
||||
{
|
||||
try {
|
||||
// 获取所有工作台
|
||||
$kfMoments = KfMoments::where(['isSend' => 0, 'isDel' => 0])->where('sendTime', '<=', time() + 120)->order('id desc')->select();
|
||||
foreach ($kfMoments as $val) {
|
||||
$sendData = json_decode($val->sendData,true);
|
||||
$endTime = strtotime($sendData['endTime']);
|
||||
if ($endTime <= time() + 1800){
|
||||
$endTime = time() + 3600;
|
||||
$sendData['endTime'] = date('Y-m-d H:i:s', $endTime);
|
||||
}
|
||||
switch ($sendData['momentContentType']) {
|
||||
case 1:
|
||||
$sendData['link'] = ['image' => ''];
|
||||
$sendData['picUrlList'] = [];
|
||||
$sendData['videoUrl'] = '';
|
||||
break;
|
||||
case 2:
|
||||
$sendData['link'] = ['image' => ''];
|
||||
$sendData['videoUrl'] = '';
|
||||
break;
|
||||
case 3:
|
||||
$sendData['link'] = ['image' => ''];
|
||||
$sendData['picUrlList'] = [];
|
||||
break;
|
||||
case 4:
|
||||
$sendData['picUrlList'] = [];
|
||||
$sendData['videoUrl'] = '';
|
||||
break;
|
||||
default:
|
||||
$sendData['link'] = ['image' => ''];
|
||||
$sendData['picUrlList'] = [];
|
||||
$sendData['videoUrl'] = '';
|
||||
break;
|
||||
}
|
||||
$moments = new Moments();
|
||||
$moments->addJob($sendData);
|
||||
KfMoments::where(['id' => $val['id']])->update(['isSend' => 1]);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error("朋友圈同步任务异常: " . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理内容发送
|
||||
* @param Workbench $workbench
|
||||
@@ -132,30 +182,30 @@ class WorkbenchMomentsJob
|
||||
$sendTime = !empty($contentLibrary['sendTime']) ? $contentLibrary['sendTime'] : time();
|
||||
|
||||
// 图片url
|
||||
if($momentContentType == 2){
|
||||
if ($momentContentType == 2) {
|
||||
$picUrlList = json_decode($contentLibrary['resUrls'], true);
|
||||
}else{
|
||||
} else {
|
||||
$picUrlList = [];
|
||||
}
|
||||
|
||||
// 视频url
|
||||
if($momentContentType == 3){
|
||||
if ($momentContentType == 3) {
|
||||
$videoUrl = json_decode($contentLibrary['urls'], true);
|
||||
$videoUrl = $videoUrl[0] ?? '';
|
||||
}else{
|
||||
} else {
|
||||
$videoUrl = '';
|
||||
}
|
||||
|
||||
// 链接url
|
||||
if($momentContentType == 4){
|
||||
$urls = json_decode($contentLibrary['urls'],true);
|
||||
if ($momentContentType == 4) {
|
||||
$urls = json_decode($contentLibrary['urls'], true);
|
||||
$url = $urls[0] ?? [];
|
||||
$link = [
|
||||
'desc' => $url['desc'] ?? '',
|
||||
'image' => $url['image'] ?? '',
|
||||
'url' => $url['url'] ?? ''
|
||||
];
|
||||
}else{
|
||||
} else {
|
||||
$link = ['image' => ''];
|
||||
}
|
||||
|
||||
@@ -208,7 +258,7 @@ class WorkbenchMomentsJob
|
||||
];
|
||||
Db::name('workbench_moments_sync_item')->insert($data);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,7 +353,7 @@ class WorkbenchMomentsJob
|
||||
'ci.comment',
|
||||
'ci.sendTime'
|
||||
]);
|
||||
// 复制 query
|
||||
// 复制 query
|
||||
$query2 = clone $query;
|
||||
$query3 = clone $query;
|
||||
// 根据accountType处理不同的发送逻辑
|
||||
@@ -322,7 +372,7 @@ class WorkbenchMomentsJob
|
||||
|
||||
// 获取下一个要发送的内容(从内容库中查询,排除isLoop为0的数据)
|
||||
$isPushIds = Db::name('workbench_moments_sync_item')
|
||||
->where(['workbenchId' => $workbench->id,'isLoop' => 0])
|
||||
->where(['workbenchId' => $workbench->id, 'isLoop' => 0])
|
||||
->column('contentId');
|
||||
|
||||
if (empty($isPushIds)) {
|
||||
@@ -342,7 +392,7 @@ class WorkbenchMomentsJob
|
||||
->update(['isLoop' => 1]);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return $sentContent;
|
||||
} else {
|
||||
// 不能循环发送,只获取未发送的内容
|
||||
@@ -362,9 +412,9 @@ class WorkbenchMomentsJob
|
||||
protected function logJobStart($jobId, $queueLockKey)
|
||||
{
|
||||
Log::info('开始处理工作台朋友圈同步任务: ' . json_encode([
|
||||
'jobId' => $jobId,
|
||||
'queueLockKey' => $queueLockKey
|
||||
]));
|
||||
'jobId' => $jobId,
|
||||
'queueLockKey' => $queueLockKey
|
||||
]));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -389,18 +439,18 @@ class WorkbenchMomentsJob
|
||||
protected function handleJobError(\Exception $e, $job, $queueLockKey)
|
||||
{
|
||||
Log::error('工作台朋友圈同步任务异常:' . $e->getMessage());
|
||||
|
||||
|
||||
if (!empty($queueLockKey)) {
|
||||
Cache::rm($queueLockKey);
|
||||
Log::info("由于异常释放队列锁: {$queueLockKey}");
|
||||
}
|
||||
|
||||
|
||||
if ($job->attempts() > self::MAX_RETRY_ATTEMPTS) {
|
||||
$job->delete();
|
||||
} else {
|
||||
$job->release(Config::get('queue.failed_delay', 10));
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user