From 54f77de5cf136da9ec1542d65e6cd5f4bcc3c9b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8F=82=E7=8F=82?= Date: Fri, 15 Nov 2024 17:06:19 +0800 Subject: [PATCH] init --- .../bydauto/src/Commands/BYDAutoCommand.php | 28 +++++++++++-------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/bydauto/src/Commands/BYDAutoCommand.php b/packages/bydauto/src/Commands/BYDAutoCommand.php index 0d18618..4e7b7dd 100644 --- a/packages/bydauto/src/Commands/BYDAutoCommand.php +++ b/packages/bydauto/src/Commands/BYDAutoCommand.php @@ -71,6 +71,10 @@ public function action_push2contact() $count = $contacts->count(); $offset = cache()->get('push2contact:offset', 0); + + $sendList = []; + + // 分配数据 foreach ($items as $item) { if (mb_strlen($item->name) > 6) { info("试驾数据 {$item->id} 姓名异常 {$item->name}"); @@ -79,22 +83,22 @@ public function action_push2contact() continue; } $contact = $contacts[$offset]; - // $contact->notify(new TestdirveNotification($item)); - $item->update(['status' => Testdrive::STATUS_PUBLISHED]); - Activity::create([ - 'name' => '试驾通知', - 'content' => ['testdrive' => $item->id, 'contact' => $contact->id], - 'related_id' => $contact->id, - 'related_type' => Contact::class, - ]); - - info("分配试驾数据 {$item->id} 给联系人 {$contact->id}"); - $this->info("分配试驾数据 {$item->id} 给联系人 {$contact->id}"); - + if (!isset($sendList[$contact->id])) { + $sendList[$contact->id] = [$item]; + } else { + $sendList[$contact->id][] = $item; + } + // info("分配试驾数据 {$item->id} 给联系人 {$contact->id}"); + // $this->info("分配试驾数据 {$item->id} 给联系人 {$contact->id}"); $offset = ($offset + 1) % $count; } cache()->forever('push2contact:offset', $offset); + // 开始发送 + foreach ($sendList as $contactId => $items) { + $contact = $contacts->find($contactId); + $this->info("发送试驾数据给联系人 {$contact->id} 总数 " . count($items)); + } return Command::SUCCESS; }