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; }