From c003c3f4b8644732e9e9ddec3578482a84706b97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8F=82=E7=8F=82?= Date: Fri, 22 Nov 2024 15:21:11 +0800 Subject: [PATCH] dev --- packages/bydauto/routes/api.php | 4 --- .../bydauto/src/Commands/BYDAutoCommand.php | 29 +++++++++++++++++-- packages/bydauto/src/Models/Activity.php | 5 ++++ packages/bydauto/src/Models/Testdrive.php | 19 +++++++++--- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/packages/bydauto/routes/api.php b/packages/bydauto/routes/api.php index 967c1bf..f592c60 100644 --- a/packages/bydauto/routes/api.php +++ b/packages/bydauto/routes/api.php @@ -6,10 +6,6 @@ $prefix = '/pkg/bydauto'; Route::group(['prefix' => $prefix, 'middleware' => ['api']], function () { - Route::get('vehicle', [BYDAutoController::class, 'vehicle']); - Route::get('dealer', [BYDAutoController::class, 'dealer']); - Route::get('province', [BYDAutoController::class, 'province']); - Route::get('city', [BYDAutoController::class, 'city']); Route::post('testdrive', [BYDAutoController::class, 'testdrive']); Route::post('isaas', [BYDAutoController::class, 'isaas']); Route::post('cluepackage', [BYDAutoController::class, 'cluepackage']); diff --git a/packages/bydauto/src/Commands/BYDAutoCommand.php b/packages/bydauto/src/Commands/BYDAutoCommand.php index a31a651..ff8c198 100644 --- a/packages/bydauto/src/Commands/BYDAutoCommand.php +++ b/packages/bydauto/src/Commands/BYDAutoCommand.php @@ -27,6 +27,9 @@ public function handle() } } + // public function action_contact() + // {} + public function action_mail_test() { $users = Contact::query()->get(); @@ -112,11 +115,33 @@ 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; } + public function action_map_activity_testdirve() + { + $activities = Activity::query() + ->orderBy('id') + ->get(); + + foreach ($activities as $activity) { + $testdriveId = $activity->content['testdrive'] ?? null; + if ($testdriveId) { + $testdrive = Testdrive::query()->find($testdriveId); + if ($testdrive) { + $testdrive->update([ + 'contact_id' => $activity->related_id, + 'contact_info' => $activity->related->toArray(), + ]); + } + } + } + $this->info('Map activity testdrive done'); + return Command::SUCCESS; + } + public function action_testdrive() { $items = Testdrive::query()->orderBy('id', 'desc')->get(); @@ -127,7 +152,7 @@ public function action_testdrive() public function action_contact() { - $items = Contact::all(); + $items = Contact::query()->orderBy('id')->get(); $this->table(['id', 'email', 'remark', 'status'], $items->map(function (Contact $v) { return [$v->id, $v->email, $v->remark, $v->status]; })); diff --git a/packages/bydauto/src/Models/Activity.php b/packages/bydauto/src/Models/Activity.php index 8242025..c6a9bdb 100644 --- a/packages/bydauto/src/Models/Activity.php +++ b/packages/bydauto/src/Models/Activity.php @@ -22,4 +22,9 @@ class Activity extends Model protected $fillable = ['name', 'content', 'related_id', 'related_type']; protected $casts = ['content' => 'json']; + + public function related() + { + return $this->morphTo('related'); + } } diff --git a/packages/bydauto/src/Models/Testdrive.php b/packages/bydauto/src/Models/Testdrive.php index 4a89614..f146468 100644 --- a/packages/bydauto/src/Models/Testdrive.php +++ b/packages/bydauto/src/Models/Testdrive.php @@ -6,6 +6,7 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Attributes\ObservedBy; use Illuminate\Database\Eloquent\Model; +use Illuminate\Validation\ValidationException; /** * 销售线索. @@ -34,8 +35,17 @@ class Testdrive extends Model protected $table = 'bydauto_testdrive'; protected $fillable = [ - 'status', 'name', 'mobile', 'platform', 'source', 'meta', - 'rawdata', 'request_id', 'external_id', 'contact_id', 'contact_info' + 'status', + 'name', + 'mobile', + 'platform', + 'source', + 'meta', + 'rawdata', + 'request_id', + 'external_id', + 'contact_id', + 'contact_info' ]; protected $casts = ['meta' => 'json', 'rawdata' => 'json', 'contact_info' => 'json']; @@ -109,8 +119,9 @@ public static function cluepackage($data) // "utc_timestamp": "1724681530", // "user_mobile_no": "15318418738" // } - - // $externalId = $data['id']; + info('===== Testdrive:cluepackage', $data); + $externalId = $data['id'] ?? null; + throw_if($externalId === null, ValidationException::withMessages(['id' => 'MISSING_ID'])); // $model = static::query()->where('external_id', $externalId)->first(); // if ($model) { // info('===== cluepackage exists', $data);