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]); // 失败后也加入延迟,避免快速连续失败