客服朋友圈配置信息
This commit is contained in:
@@ -108,6 +108,17 @@ class WorkbenchMomentsJob
|
||||
public function execute2()
|
||||
{
|
||||
try {
|
||||
// 每日重置发送次数(允许10分钟误差)
|
||||
$now = time();
|
||||
$todayStart = strtotime(date('Y-m-d 00:00:00'));
|
||||
if ($now - $todayStart >= 0 && $now - $todayStart <= 600) {
|
||||
$cacheKey = 'moments_settings_reset_' . date('Ymd');
|
||||
if (!Cache::has($cacheKey)) {
|
||||
Db::table('ck_kf_moments_settings')->where('sendNum', '<>', 0)
|
||||
->update(['sendNum' => 0, 'updateTime' => $now]);
|
||||
Cache::set($cacheKey, 1, 7200); // 2小时缓存,防止重复重置
|
||||
}
|
||||
}
|
||||
// 获取所有工作台
|
||||
$kfMoments = KfMoments::where(['isSend' => 0, 'isDel' => 0])->where('sendTime', '<=', time() + 120)->order('id desc')->select();
|
||||
foreach ($kfMoments as $val) {
|
||||
@@ -144,6 +155,46 @@ class WorkbenchMomentsJob
|
||||
$moments = new Moments();
|
||||
$moments->addJob($sendData);
|
||||
KfMoments::where(['id' => $val['id']])->update(['isSend' => 1]);
|
||||
|
||||
// 统计发送次数(ck_kf_moments_settings)
|
||||
try {
|
||||
$nowTs = time();
|
||||
$companyId = (int)($val['companyId'] ?? 0);
|
||||
$userId = (int)($val['userId'] ?? 0);
|
||||
$items = $sendData['jobPublishWechatMomentsItems'] ?? [];
|
||||
foreach ($items as $it) {
|
||||
$wechatId = (int)($it['wechatAccountId'] ?? 0);
|
||||
if ($wechatId <= 0) { continue; }
|
||||
|
||||
$cond = [
|
||||
'companyId' => $companyId,
|
||||
'userId' => $userId,
|
||||
'wechatId' => $wechatId,
|
||||
];
|
||||
|
||||
$setting = Db::table('ck_kf_moments_settings')->where($cond)->find();
|
||||
if ($setting) {
|
||||
Db::table('ck_kf_moments_settings')
|
||||
->where('id', $setting['id'])
|
||||
->update([
|
||||
'sendNum' => Db::raw('sendNum + 1'),
|
||||
'updateTime' => $nowTs,
|
||||
]);
|
||||
} else {
|
||||
Db::table('ck_kf_moments_settings')->insert([
|
||||
'companyId' => $companyId,
|
||||
'userId' => $userId,
|
||||
'wechatId' => $wechatId,
|
||||
'max' => 5,
|
||||
'sendNum' => 1,
|
||||
'createTime' => $nowTs,
|
||||
'updateTime' => $nowTs,
|
||||
]);
|
||||
}
|
||||
}
|
||||
} catch (\Throwable $statE) {
|
||||
Log::error('朋友圈发送统计失败: ' . $statE->getMessage());
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error("朋友圈同步任务异常: " . $e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user