From f2c25927ebb9f46f64da6e7a71144b6b46a22c5e Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Mon, 13 Oct 2025 17:00:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=9C=8D=E6=9C=8B=E5=8F=8B=E5=9C=88?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/CustomerServiceController.php | 6 +++ .../application/job/WorkbenchMomentsJob.php | 51 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/Server/application/chukebao/controller/CustomerServiceController.php b/Server/application/chukebao/controller/CustomerServiceController.php index 93892fe5..deb955bc 100644 --- a/Server/application/chukebao/controller/CustomerServiceController.php +++ b/Server/application/chukebao/controller/CustomerServiceController.php @@ -10,6 +10,8 @@ class CustomerServiceController extends BaseController public function getList(){ $accountId = $this->getUserInfo('s2_accountId'); + $userId = $this->getUserInfo('id'); + $companyId = $this->getUserInfo('companyId'); if (empty($accountId)){ return ResponseHelper::error('请先登录'); } @@ -28,6 +30,10 @@ class CustomerServiceController extends BaseController $v['createTime'] = !empty($v['createTime']) ? date('Y-m-d H:i:s',$v['createTime']) : ''; $v['updateTime'] = !empty($v['updateTime']) ? date('Y-m-d H:i:s',$v['updateTime']) : ''; $v['labels'] = json_decode($v['labels'],true); + $momentsSetting = Db::name('kf_moments_settings')->where(['userId' => $userId,'companyId' => $companyId,'wechatId' =>$v['id']])->find(); + $v['momentsMax'] = !empty($momentsSetting['max']) ? $momentsSetting['max'] : 5; + $v['momentsNum'] = !empty($momentsSetting['sendNum']) ? $momentsSetting['sendNum'] : 0; + unset( $v['accountUserName'], $v['accountRealName'], diff --git a/Server/application/job/WorkbenchMomentsJob.php b/Server/application/job/WorkbenchMomentsJob.php index d8c008ac..4d82739c 100644 --- a/Server/application/job/WorkbenchMomentsJob.php +++ b/Server/application/job/WorkbenchMomentsJob.php @@ -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());