From 40f2366c9dd0a52393787c1c8e91b76a07bd1108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8F=82=E7=8F=82?= Date: Fri, 29 Nov 2024 14:36:32 +0800 Subject: [PATCH] add push_missing --- .../bydauto/src/Commands/BYDAutoCommand.php | 45 ++++++++++++++++++- packages/bydauto/src/Models/Activity.php | 4 +- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/packages/bydauto/src/Commands/BYDAutoCommand.php b/packages/bydauto/src/Commands/BYDAutoCommand.php index ff8c198..76b3b90 100644 --- a/packages/bydauto/src/Commands/BYDAutoCommand.php +++ b/packages/bydauto/src/Commands/BYDAutoCommand.php @@ -45,6 +45,49 @@ public function action_init() $this->call('migrate'); } + // 漏发试驾数据 + public function action_push_missing() + { + $items = Testdrive::query() + ->where('date_updated', '>', '2024-11-21 09:06:00') + ->get(); + + $contacts = Contact::query() + ->where('status', Contact::STATUS_PUBLISHED) + ->orderBy('id') + ->get(); + + $count = $contacts->count(); + $offset = cache()->get('push2contact:offset', 0); + $sendList = []; + + foreach ($items as $item) { + if ($this->isDirtyName($item->name)) { + info("试驾数据 {$item->id} 姓名异常 {$item->name}"); + $this->info("试驾数据 {$item->id} 姓名异常 {$item->name}"); + $item->update(['status' => Testdrive::STATUS_REJECTED]); + continue; + } + $contact = $contacts[$offset]; + // $item->update(['status' => Testdrive::STATUS_PUBLISHED, 'contact_id' => $contact->id, 'contact_info' => $contact->toArray()]); + if (!isset($sendList[$contact->id])) { + $sendList[$contact->id] = [$item]; + } else { + $sendList[$contact->id][] = $item; + } + $offset = ($offset + 1) % $count; + } + cache()->forever('push2contact:offset', $offset); + // 开始发送 + foreach ($sendList as $contactId => $items) { + $contact = $contacts->firstWhere('id', $contactId); + $this->info("发送试驾数据给联系人 {$contact->id} 总数 " . count($items)); + info("发送试驾数据给联系人 {$contact->id} 总数 " . count($items)); + // $contact->notify(new TestdirveNotification($items)); + } + return Command::SUCCESS; + } + // 同步试驾数据给到经销商联系人 按顺序每个联系人分配一个试驾数据 public function action_push2contact() { @@ -115,7 +158,7 @@ public function action_push2contact() $contact = $contacts->firstWhere('id', $contactId); $this->info("发送试驾数据给联系人 {$contact->id} 总数 " . count($items)); info("发送试驾数据给联系人 {$contact->id} 总数 " . count($items)); - // $contact->notify(new TestdirveNotification($items)); + $contact->notify(new TestdirveNotification($items)); } return Command::SUCCESS; } diff --git a/packages/bydauto/src/Models/Activity.php b/packages/bydauto/src/Models/Activity.php index c6a9bdb..9697948 100644 --- a/packages/bydauto/src/Models/Activity.php +++ b/packages/bydauto/src/Models/Activity.php @@ -15,7 +15,9 @@ */ class Activity extends Model { - public $timestamps = false; + public const CREATED_AT = 'date_created'; + + public const UPDATED_AT = 'date_updated'; protected $table = 'bydauto_activity';