From 07d82d25da57ef45d9dfccb81a65a51baa29239a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8F=82=E7=8F=82?= Date: Fri, 15 Nov 2024 16:08:47 +0800 Subject: [PATCH] init --- .../bydauto/src/Commands/BYDAutoCommand.php | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packages/bydauto/src/Commands/BYDAutoCommand.php b/packages/bydauto/src/Commands/BYDAutoCommand.php index 67ef0b7..7c90c84 100644 --- a/packages/bydauto/src/Commands/BYDAutoCommand.php +++ b/packages/bydauto/src/Commands/BYDAutoCommand.php @@ -4,8 +4,10 @@ use App\Mail\HelloMail; use App\Notifications\HelloNotification; +use BYDAuto\Models\Activity; use BYDAuto\Models\Contact; use BYDAuto\Models\Testdrive; +use BYDAuto\Notifications\TestdirveNotification; use Illuminate\Console\Command; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Support\Facades\Mail; @@ -42,6 +44,35 @@ public function action_init() $this->call('migrate'); } + // 同步试驾数据给到经销商联系人 按顺序每个联系人分配一个试驾数据 + public function action_push2contact() + { + $items = Testdrive::query() + ->whereNotNull('source') + ->where('status', Testdrive::STATUS_DRAFT) + ->get(); + + $contacts = Contact::query()->where('status', Contact::STATUS_PUBLISHED)->get(); + $count = $contacts->count(); + $offset = cache()->get('push2contact:offset', 0); + foreach ($items as $item) { + $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 + ]); + $this->info("分配试驾数据 {$item->id} 给联系人 {$contact->id}"); + $offset = ($offset + 1) % $count; + } + cache()->forever('push2contact:offset', $offset); + + return Command::SUCCESS; + } + public function action_testdrive() { $items = Testdrive::query()->orderBy('id', 'desc')->get();