From bd594cb81d1fcb0c9ddb4d3094255828182e9d30 Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 4 Aug 2025 15:17:07 +0800 Subject: [PATCH 1/8] ts --- app/queue/redis/EmailMessage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/queue/redis/EmailMessage.php b/app/queue/redis/EmailMessage.php index 8fbeb22..d0ec89a 100644 --- a/app/queue/redis/EmailMessage.php +++ b/app/queue/redis/EmailMessage.php @@ -22,7 +22,7 @@ class EmailMessage implements Consumer $inquiryLogService = new InquiryLogService(); $data = $inquiryLogService->getContent($data['id']); - MailSend::send($data['email'], '【XYH】新的客户线索', replaceTpl($data)); + // MailSend::send($data['email'], '【XYH】新的客户线索', replaceTpl($data)); } catch (\Throwable $th) { throw $th; } From 2f6609dab46d5d64e40f3c77a8b144939e85e33d Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 4 Aug 2025 15:20:12 +0800 Subject: [PATCH 2/8] ts --- app/queue/redis/InquiryToCrm.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/queue/redis/InquiryToCrm.php b/app/queue/redis/InquiryToCrm.php index 966d4a3..77429cd 100644 --- a/app/queue/redis/InquiryToCrm.php +++ b/app/queue/redis/InquiryToCrm.php @@ -44,6 +44,7 @@ class InquiryToCrm implements Consumer // $scene = 'inquiry-group-send'; // $receiveType = 'group'; } + var_dump($uinfo); // 同步客户数据 $crmCustomer = new CrmCustomer(); $crmCustomer->sn = $info->order_no; @@ -75,6 +76,7 @@ class InquiryToCrm implements Consumer // 'scene' => $scene, // 'receive_type' => $receiveType ]; + var_dump($options); \Webman\RedisQueue\Redis::send('email-message', $options); } } From 9d6364ca932a5f922febd30c5f3599f2dc75934e Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 4 Aug 2025 15:24:25 +0800 Subject: [PATCH 3/8] ts --- app/queue/redis/InquiryToCrm.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/app/queue/redis/InquiryToCrm.php b/app/queue/redis/InquiryToCrm.php index 77429cd..26202f3 100644 --- a/app/queue/redis/InquiryToCrm.php +++ b/app/queue/redis/InquiryToCrm.php @@ -9,6 +9,7 @@ use Webman\RedisQueue\Consumer; use app\common\model\User; use app\common\utils\FeishuMessage; use support\exception\BusinessException; +use support\Log; class InquiryToCrm implements Consumer { @@ -44,7 +45,6 @@ class InquiryToCrm implements Consumer // $scene = 'inquiry-group-send'; // $receiveType = 'group'; } - var_dump($uinfo); // 同步客户数据 $crmCustomer = new CrmCustomer(); $crmCustomer->sn = $info->order_no; @@ -71,12 +71,9 @@ class InquiryToCrm implements Consumer if ($uinfo && $uinfo->email) { $options = [ 'id' => $info->id, - 'email' => $uinfo->email, - // 'category' => 'inquiry', - // 'scene' => $scene, - // 'receive_type' => $receiveType + 'email' => $uinfo->email ]; - var_dump($options); + Log::info('发送邮件消息:' . json_encode($options)); \Webman\RedisQueue\Redis::send('email-message', $options); } } From be212317eb4a56d33eb74c79b170c1b66e144781 Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 4 Aug 2025 15:30:28 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E9=82=AE=E4=BB=B6?= =?UTF-8?q?=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/queue/redis/EmailMessage.php | 4 ++-- app/queue/redis/InquiryToCrm.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/queue/redis/EmailMessage.php b/app/queue/redis/EmailMessage.php index d0ec89a..7291868 100644 --- a/app/queue/redis/EmailMessage.php +++ b/app/queue/redis/EmailMessage.php @@ -20,9 +20,9 @@ class EmailMessage implements Consumer try { // 询单信息 $inquiryLogService = new InquiryLogService(); - $data = $inquiryLogService->getContent($data['id']); + $content = $inquiryLogService->getContent($data['id']); - // MailSend::send($data['email'], '【XYH】新的客户线索', replaceTpl($data)); + MailSend::send($data['email'], '【XYH】新的客户线索', replaceTpl($content)); } catch (\Throwable $th) { throw $th; } diff --git a/app/queue/redis/InquiryToCrm.php b/app/queue/redis/InquiryToCrm.php index 26202f3..8eb88c5 100644 --- a/app/queue/redis/InquiryToCrm.php +++ b/app/queue/redis/InquiryToCrm.php @@ -73,7 +73,7 @@ class InquiryToCrm implements Consumer 'id' => $info->id, 'email' => $uinfo->email ]; - Log::info('发送邮件消息:' . json_encode($options)); + // Log::info('发送邮件消息:' . json_encode($options)); \Webman\RedisQueue\Redis::send('email-message', $options); } } From a315ad33f145ed0d00053da71008e1301f4f88dc Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 4 Aug 2025 18:11:44 +0800 Subject: [PATCH 5/8] Merge branch 'feature/mzl_dev' # Conflicts: # app/command/TbCommand.php # app/common/utils/email/Emails.php # app/controller/IndexController.php # app/functions.php --- app/command/TbCommand.php | 2 +- app/common/logic/AuthLogic.php | 2 +- app/common/model/EmailParsedResult.php | 49 +++++++ app/common/utils/UidRotator.php | 178 +++++++++++++++++++++++++ app/common/utils/email/Emails.php | 150 +++++++++++++++++++++ app/controller/IndexController.php | 4 +- app/functions.php | 26 ++++ app/queue/redis/InquiryToCrm.php | 2 +- 8 files changed, 408 insertions(+), 5 deletions(-) create mode 100644 app/common/model/EmailParsedResult.php create mode 100644 app/common/utils/UidRotator.php diff --git a/app/command/TbCommand.php b/app/command/TbCommand.php index fa0a33a..265d24c 100644 --- a/app/command/TbCommand.php +++ b/app/command/TbCommand.php @@ -29,7 +29,7 @@ class TbCommand extends Command // } $m = new Emails(); - $m->process(); + $m->fenpai(); return self::SUCCESS; } diff --git a/app/common/logic/AuthLogic.php b/app/common/logic/AuthLogic.php index b2a74fc..59155dc 100644 --- a/app/common/logic/AuthLogic.php +++ b/app/common/logic/AuthLogic.php @@ -93,7 +93,7 @@ class AuthLogic ->orWhere('email', $email); }) ->first(); - + $user->isLogin = true; if (!$user) { // 获取编号 $userSn = $this->getAvailableUserSn(); diff --git a/app/common/model/EmailParsedResult.php b/app/common/model/EmailParsedResult.php new file mode 100644 index 0000000..de1a1be --- /dev/null +++ b/app/common/model/EmailParsedResult.php @@ -0,0 +1,49 @@ +first(); + + // 固定渠道 + $channel = 8; + $channelInfo = InquiryChannel::where('id', $channel)->first(); + + // 初始化 UID 轮询器 + \app\common\utils\UidRotator::initialize([64, 63, 83, 93, 108, 118, 131, 132, 145, 150, 143, 156, 157, 158]); + + EmailParsedResult::where('status', 0) + ->chunkById($batchSize, function ($records) use ($delaySeconds, $throttleAfter, $throttleSeconds, $enterUser, $channelInfo) { + $count = 0; + + foreach ($records as $record) { + try { + // Mail::to($record->mailto)->send(new CustomEmail($record)); + + // 获取国家信息 + $countryName = removeParentheses($record->iplocation); + $countryInfo = Country::where('cn_addr', $countryName)->first(); +// var_dump($countryName); +// var_dump($countryInfo); +// var_dump('====== ====== ====== ====== ====== ====== '); + // 获取下一个分配的UID + $assignedUid = \app\common\utils\UidRotator::next(); +// var_dump($assignedUid); +// var_dump('====== ====== ====== ====== ====== ====== '); + // 获取分配的用户信息 + $recipientInfo = User::where('id', $assignedUid)->first(); +// var_dump($recipientInfo); +// var_dump('====== ====== ====== ====== ====== ====== '); + // 生成录单 + $log = [ + 'order_no' => orderNum(), + 'enter_user_id' => $enterUser->id, + 'recipient' => $assignedUid, + 'quality' => 2, + 'channel' => $channelInfo->id, + 'email' => $record->email, + 'tel' => $record->tel, + 'whatsapp' => '', + 'country' => $countryInfo->id, + 'contacts' => $record->name, + 'content' => $record->message, + 'r_time' => time(), + 't_time' => time(), + 'status' => 2, + 'sync_crm' => 1 + ]; +// var_dump($log); +// var_dump('====== ====== ====== ====== ====== ====== '); + $inquiryLogResult = InquiryLog::create($log); + if (!$inquiryLogResult) { + throw new BusinessException('录单失败~'); + } + + // 同步客户 + $crmCustomer = new CrmCustomer(); + $crmCustomer->sn = $inquiryLogResult->order_no; + $crmCustomer->corp_abbr = $recipientInfo->corp_id; + $crmCustomer->user_id = $assignedUid; + $crmCustomer->type = 1; + $crmCustomer->channel_id = $inquiryLogResult->channel; + $crmCustomer->country_id = $inquiryLogResult->country; + $crmCustomer->magnitude = $inquiryLogResult->quality; + $crmCustomer->email = $inquiryLogResult->email; + $crmCustomer->phone = $inquiryLogResult->tel; + $crmCustomer->WhatsApp = $inquiryLogResult->whatsapp; + $crmCustomer->contacts = $inquiryLogResult->contacts; + $crmCustomer->desc_collect = $inquiryLogResult->content; + $crmCustomer->enter_user_id = $inquiryLogResult->enter_user_id; +// var_dump($crmCustomer); +// var_dump('====== ====== ====== ====== ====== ====== '); + if (!$crmCustomer->save()) { + throw new BusinessException('同步失败~'); + } + + // 邮件模板 + $data = [ + 'order_no' => $inquiryLogResult->order_no, + 'enter_user_id' => $enterUser->name, + 'recipient' => $recipientInfo->name, + 'quality' => (new \app\inquiry\service\InquiryLogService())->qualityName($inquiryLogResult->quality), + 'channel' => $channelInfo->name, + 'email' => $inquiryLogResult->email && $inquiryLogResult->email != '' ? $inquiryLogResult->email : ' - ', + 'tel' => $inquiryLogResult->tel && $inquiryLogResult->tel != '' ? $inquiryLogResult->tel : ' - ', + 'whatsapp' => $inquiryLogResult->whatsapp && $inquiryLogResult->whatsapp != '' ? $inquiryLogResult->whatsapp : ' - ', + 'country' => $countryName, + 'contacts' => $inquiryLogResult->contacts && $inquiryLogResult->contacts != '' ? $inquiryLogResult->contacts : ' - ', + 'content' => $inquiryLogResult->content && $inquiryLogResult->content != '' ? $inquiryLogResult->content : ' - ', + 'r_time' => $inquiryLogResult->r_time ? date('Y-m-d H:i:s', $inquiryLogResult->r_time) : ' - ', + 't_time' => $inquiryLogResult->t_time ? date('Y-m-d H:i:s', $inquiryLogResult->t_time) : ' - ' + ]; + \app\common\utils\email\MailSend::send($recipientInfo->email, '【XYH】新的客户线索', replaceTpl($data)); +// var_dump($data); +// var_dump('====== ====== ====== ====== ====== ====== '); + // 更新状态 + $record->update(['status' => 1]); + + // 每封邮件后延迟 + if ($delaySeconds > 0) { + sleep($delaySeconds); + } + + // 每发送一定数量后额外休息 + if (++$count % $throttleAfter === 0) { + sleep($throttleSeconds); + Log::info("已发送 {$count} 封邮件,休息 {$throttleSeconds} 秒"); + } + + } catch (\Exception $e) { + Log::error("邮件发送失败 ID:{$record->id} - " . $e->getMessage()); + // 更新状态 + $record->update(['status' => 3]); + // 失败后也加入延迟,避免快速连续失败 + sleep($delaySeconds); + } + } + }); + } catch (\Throwable $th) { + flg(dpr($th)); + return false; + } + } } \ No newline at end of file diff --git a/app/controller/IndexController.php b/app/controller/IndexController.php index d9ac96c..6dc874b 100644 --- a/app/controller/IndexController.php +++ b/app/controller/IndexController.php @@ -80,7 +80,7 @@ class IndexController // ], 'model' => [ 'module' => 'common', - 'name' => 'inquiry_channel' + 'name' => 'email_parsed_result' ], // 'service' => [ // 'module' => 'inquiry', @@ -94,7 +94,7 @@ class IndexController // 'module' => 'inquiry', // 'name' => 'country' // ], - 'table' => 'inquiry_channel' + 'table' => 'email_parsed_result' ]; $result = (new Generate($options))->doGenerate(); diff --git a/app/functions.php b/app/functions.php index 45af92c..f69f082 100644 --- a/app/functions.php +++ b/app/functions.php @@ -194,4 +194,30 @@ if (!function_exists('InquiryFormat')) { $content .= '内容:'.$data['content']; return $content; } +} + +/** + * 移除字符串中的括号及其内部内容(仅移除第一个匹配项) + * + * @param string $str 要处理的字符串 + * @return string 处理后的字符串 + */ +if (!function_exists('removeParentheses')) { + function removeParentheses(string $str): string + { + // 匹配模式:半角括号或全角括号及其内部内容 + $pattern = '/ + (?: # 非捕获分组开始 + \( # 匹配半角左括号 + [^)]* # 匹配除半角右括号外的任意字符 + \) # 匹配半角右括号 + )|(?: # 或 + \( # 匹配全角左括号 + [^)]* # 匹配除全角右括号外的任意字符 + \) # 匹配全角右括号 + ) # 非捕获分组结束 + /xu'; // x: 忽略空白 u: Unicode模式 + + return trim(preg_replace($pattern, '', $str, 1)); + } } \ No newline at end of file diff --git a/app/queue/redis/InquiryToCrm.php b/app/queue/redis/InquiryToCrm.php index 8eb88c5..8e1ae51 100644 --- a/app/queue/redis/InquiryToCrm.php +++ b/app/queue/redis/InquiryToCrm.php @@ -53,7 +53,7 @@ class InquiryToCrm implements Consumer $crmCustomer->type = 1; $crmCustomer->channel_id = $info->channel; $crmCustomer->country_id = $info->country; - $crmCustomer->magnitude = $info->quality - 1; + $crmCustomer->magnitude = $info->quality; $crmCustomer->email = $info->email; $crmCustomer->phone = $info->tel; $crmCustomer->WhatsApp = $info->whatsapp; From 3177e3552406747af267fb4a75ab8033907e22d9 Mon Sep 17 00:00:00 2001 From: mzl Date: Tue, 5 Aug 2025 09:00:36 +0800 Subject: [PATCH 6/8] edit email config --- app/common/utils/email/Emails.php | 37 +++++++++---------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/app/common/utils/email/Emails.php b/app/common/utils/email/Emails.php index f7cfb90..8a3db68 100644 --- a/app/common/utils/email/Emails.php +++ b/app/common/utils/email/Emails.php @@ -419,15 +419,10 @@ class Emails public function fenpai() { - try { - // $uids = [ - // 64, 63, 83, 93, 108, 118, 131, 132, 145, 150, 143, 156, 157, 158 - // ]; - - + try { // 配置参数 $batchSize = 100; // 每批处理量 - $delaySeconds = 1; // 每封邮件间隔秒数 + $delaySeconds = 2; // 每封邮件间隔秒数 $throttleAfter = 50; // 每发送多少封后增加休息 $throttleSeconds = 5; // 批量休息秒数 @@ -448,22 +443,16 @@ class Emails foreach ($records as $record) { try { - // Mail::to($record->mailto)->send(new CustomEmail($record)); - // 获取国家信息 - $countryName = removeParentheses($record->iplocation); + $countryName = $record->iplocation ? removeParentheses($record->iplocation) : '未知'; $countryInfo = Country::where('cn_addr', $countryName)->first(); -// var_dump($countryName); -// var_dump($countryInfo); -// var_dump('====== ====== ====== ====== ====== ====== '); + // 获取下一个分配的UID $assignedUid = \app\common\utils\UidRotator::next(); -// var_dump($assignedUid); -// var_dump('====== ====== ====== ====== ====== ====== '); + // 获取分配的用户信息 $recipientInfo = User::where('id', $assignedUid)->first(); -// var_dump($recipientInfo); -// var_dump('====== ====== ====== ====== ====== ====== '); + // 生成录单 $log = [ 'order_no' => orderNum(), @@ -482,8 +471,6 @@ class Emails 'status' => 2, 'sync_crm' => 1 ]; -// var_dump($log); -// var_dump('====== ====== ====== ====== ====== ====== '); $inquiryLogResult = InquiryLog::create($log); if (!$inquiryLogResult) { throw new BusinessException('录单失败~'); @@ -504,8 +491,6 @@ class Emails $crmCustomer->contacts = $inquiryLogResult->contacts; $crmCustomer->desc_collect = $inquiryLogResult->content; $crmCustomer->enter_user_id = $inquiryLogResult->enter_user_id; -// var_dump($crmCustomer); -// var_dump('====== ====== ====== ====== ====== ====== '); if (!$crmCustomer->save()) { throw new BusinessException('同步失败~'); } @@ -527,11 +512,11 @@ class Emails 't_time' => $inquiryLogResult->t_time ? date('Y-m-d H:i:s', $inquiryLogResult->t_time) : ' - ' ]; \app\common\utils\email\MailSend::send($recipientInfo->email, '【XYH】新的客户线索', replaceTpl($data)); -// var_dump($data); -// var_dump('====== ====== ====== ====== ====== ====== '); + // 更新状态 $record->update(['status' => 1]); - + flg('====== 编号:'.$inquiryLogResult->order_no.' 分配给:'.$recipientInfo->name.' email:'.$recipientInfo->email, false); + // 每封邮件后延迟 if ($delaySeconds > 0) { sleep($delaySeconds); @@ -540,11 +525,11 @@ class Emails // 每发送一定数量后额外休息 if (++$count % $throttleAfter === 0) { sleep($throttleSeconds); - Log::info("已发送 {$count} 封邮件,休息 {$throttleSeconds} 秒"); + flg("已发送 {$count} 封邮件,休息 {$throttleSeconds} 秒", false); } } catch (\Exception $e) { - Log::error("邮件发送失败 ID:{$record->id} - " . $e->getMessage()); + flg("邮件发送失败 ID:{$record->id} - " . $e->getMessage()); // 更新状态 $record->update(['status' => 3]); // 失败后也加入延迟,避免快速连续失败 From f39b0ee63f261468bcd3522f84f57df15c9e98fb Mon Sep 17 00:00:00 2001 From: mzl Date: Tue, 5 Aug 2025 10:05:16 +0800 Subject: [PATCH 7/8] Merge branch 'feature/mzl_dev' # Conflicts: # app/common/utils/email/Emails.php --- app/common/utils/RedisUidRotator.php | 161 +++++++++++++++++++++++++++ app/common/utils/email/Emails.php | 7 +- 2 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 app/common/utils/RedisUidRotator.php diff --git a/app/common/utils/RedisUidRotator.php b/app/common/utils/RedisUidRotator.php new file mode 100644 index 0000000..44d4265 --- /dev/null +++ b/app/common/utils/RedisUidRotator.php @@ -0,0 +1,161 @@ +key = "uid_rotator:{$rotatorName}:index"; + $this->setKey = "uid_rotator:{$rotatorName}:uids"; + $this->lockKey = "uid_rotator:{$rotatorName}:lock"; + $this->expireSeconds = $expireSeconds; + } + + public function setUids(array $uids, bool $resetIndex = true): bool + { + // 删除旧数据 + Redis::del($this->setKey); + + if (!empty($uids)) { + // 添加新UID集合 + foreach ($uids as $uid) { + Redis::sAdd($this->setKey, $uid); + } + + // 重置索引 + if ($resetIndex) { + Redis::set($this->key, 0); + } + } + + $this->touchExpire(); + return true; + } + + public function next(): ?int + { + $lockAcquired = false; + try { + // 获取锁(改用原生命令) + $lockAcquired = $this->acquireLock(5); + if (!$lockAcquired) { + throw new \RuntimeException("获取锁失败"); + } + + // 获取当前索引 + $currentIndex = (int)Redis::get($this->key); + + // 获取所有UID + $uids = Redis::sMembers($this->setKey); + if (empty($uids)) { + return null; + } + + // 计算位置 + $uid = $uids[$currentIndex % count($uids)]; + $nextIndex = $currentIndex + 1; + + // 更新索引 + Redis::set($this->key, $nextIndex); + $this->touchExpire(); + + return is_numeric($uid) ? (int)$uid : $uid; + } catch (\Throwable $e) { + Log::info("UID分配错误: " . $e->getMessage()); + return null; + } finally { + if ($lockAcquired) { + Redis::del($this->lockKey); + } + } + } + + private function acquireLock(int $timeout = 5): bool + { + $start = time(); + $lockTimeout = $timeout + 1; // 锁过期时间比等待时间长 + + while (time() - $start < $timeout) { + // 使用SETNX实现锁(分两步) + if (Redis::setNx($this->lockKey, 1)) { + // 设置过期时间 + Redis::expire($this->lockKey, $lockTimeout); + return true; + } + + // 检查锁是否已过期但未被删除(处理死锁) + if (Redis::ttl($this->lockKey) < 0) { + Redis::del($this->lockKey); + } + + usleep(100000); // 100ms重试间隔 + } + + return false; + } + + private function touchExpire(): void + { + Redis::expire($this->key, $this->expireSeconds); + Redis::expire($this->setKey, $this->expireSeconds); + } + + public function getPosition(): int + { + return (int)Redis::get($this->key); + } + + public function resetIndex(int $position = 0): bool + { + return (bool)Redis::set($this->key, max(0, $position)); + } + + public function getUids(): array + { + return Redis::sMembers($this->setKey) ?: []; + } + + public function addUids($uids): int + { + $added = 0; + $uids = is_array($uids) ? $uids : [$uids]; + + foreach ($uids as $uid) { + $added += Redis::sAdd($this->setKey, $uid); + } + + $this->touchExpire(); + return $added; + } + + public function removeUids($uids): int + { + $removed = 0; + $uids = is_array($uids) ? $uids : [$uids]; + + foreach ($uids as $uid) { + $removed += Redis::sRem($this->setKey, $uid); + } + + return $removed; + } + + public function count(): int + { + return (int)Redis::sCard($this->setKey); + } + + public function destroy(): void + { + Redis::del([$this->key, $this->setKey, $this->lockKey]); + } +} \ No newline at end of file diff --git a/app/common/utils/email/Emails.php b/app/common/utils/email/Emails.php index 8a3db68..0bb8376 100644 --- a/app/common/utils/email/Emails.php +++ b/app/common/utils/email/Emails.php @@ -435,10 +435,11 @@ class Emails $channelInfo = InquiryChannel::where('id', $channel)->first(); // 初始化 UID 轮询器 - \app\common\utils\UidRotator::initialize([64, 63, 83, 93, 108, 118, 131, 132, 145, 150, 143, 156, 157, 158]); + $uidRotator = new \app\common\utils\RedisUidRotator('email_parsed_result_20250804'); + $uidRotator->setUids([64, 63, 83, 93, 108, 118, 131, 132, 145, 150, 143, 156, 157, 158]); EmailParsedResult::where('status', 0) - ->chunkById($batchSize, function ($records) use ($delaySeconds, $throttleAfter, $throttleSeconds, $enterUser, $channelInfo) { + ->chunkById($batchSize, function ($records) use ($delaySeconds, $throttleAfter, $throttleSeconds, $enterUser, $channelInfo, $uidRotator) { $count = 0; foreach ($records as $record) { @@ -448,7 +449,7 @@ class Emails $countryInfo = Country::where('cn_addr', $countryName)->first(); // 获取下一个分配的UID - $assignedUid = \app\common\utils\UidRotator::next(); + $assignedUid = $uidRotator->next(); // 获取分配的用户信息 $recipientInfo = User::where('id', $assignedUid)->first(); From 459a6d36c053fa86c7a13fb8ac25801768c71df4 Mon Sep 17 00:00:00 2001 From: mzl Date: Tue, 5 Aug 2025 10:19:57 +0800 Subject: [PATCH 8/8] Merge branch 'feature/mzl_dev' # Conflicts: # app/process/Emails.php --- app/process/Emails.php | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/app/process/Emails.php b/app/process/Emails.php index 7886fff..f9641ea 100644 --- a/app/process/Emails.php +++ b/app/process/Emails.php @@ -2,8 +2,6 @@ namespace app\process; -use app\crm\model\Customer; -use support\Log; use Workerman\Crontab\Crontab; use app\common\utils\email\Emails as EmailsUtils; @@ -12,23 +10,47 @@ class Emails public function onWorkerStart() { - // 拉取新邮件 - new Crontab('0 */30 * * * *', function(){ + // // 拉取新邮件 + // new Crontab('0 */30 * * * *', function(){ + // $email = new EmailsUtils(); + // $email->uids(); + // }); + + // // 邮件详情 + // new Crontab('0 */35 * * * *', function(){ + // $email = new EmailsUtils(); + // $email->details(); + // }); + + // // 邮件处理 + // new Crontab('0 */40 * * * *', function(){ + // $email = new EmailsUtils(); + // $email->process(); + // }); + + // 拉取新邮件 - 每3小时的第0分钟0秒执行 + new Crontab('0 0 */3 * * *', function(){ $email = new EmailsUtils(); $email->uids(); }); - // 邮件详情 - new Crontab('0 */35 * * * *', function(){ + // 邮件详情 - 每3小时的第10分钟0秒执行 + new Crontab('0 10 */3 * * *', function(){ $email = new EmailsUtils(); $email->details(); }); - // 邮件处理 - new Crontab('0 */40 * * * *', function(){ + // 邮件处理 - 每3小时的第20分钟0秒执行 + new Crontab('0 20 */3 * * *', function(){ $email = new EmailsUtils(); $email->process(); }); + + // 邮件分派 - 每3小时的第30分钟0秒执行 + new Crontab('0 30 */3 * * *', function(){ + $email = new EmailsUtils(); + $email->fenpai(); + }); } } \ No newline at end of file