From de80f6178cf9162711f617593d5ff77f2dcb96f9 Mon Sep 17 00:00:00 2001 From: Nick Zeng Date: Tue, 9 Dec 2025 15:45:40 +0800 Subject: [PATCH] add shopee queue push test --- .../app/Command/AppMessageQueuePushShopee.php | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 backend/app/Command/AppMessageQueuePushShopee.php diff --git a/backend/app/Command/AppMessageQueuePushShopee.php b/backend/app/Command/AppMessageQueuePushShopee.php new file mode 100644 index 0000000..f0bac0c --- /dev/null +++ b/backend/app/Command/AppMessageQueuePushShopee.php @@ -0,0 +1,123 @@ +setDescription('Test push message with Shopee Loop data'); + } + + public function handle(): void + { + try { + + // 尝试更新 store 信息 + + $store = Store::where('platform_id', '=', 25) + ->where('platform_store_id', '=', 931327381 ) + ->first(); + + if(!$store){ + $this->error('店铺不存在!'); + return; + } + + $_platform_meta = [ + 'partner_id' => 2006675, + 'app_id' => '', + 'merchant_id' => 3726273, + 'name' => 'Loop Earplugs.SG', + 'zone' => 'SG', + ]; + + $platform_meta = !$store->platform_meta ? $_platform_meta : array_merge($store->platform_meta, $_platform_meta); + $store->platform_meta = $platform_meta; + $store->save(); + + return; + + // 从 raw 数据库连接获取数据 + $orders = Db::connection('raw') + ->table('wpic_shopee_order') + ->where('store_id', '=', 931327381) + ->orderBy('id', 'desc') + ->limit(4)->get('order_raw')->lazy(); + + // dump($orders->first()); + // return; + + if ($orders->isEmpty()) { + $this->warn('No orders found in wpic_shopee_order table'); + return; + } + + $this->info(sprintf('Found %d orders, processing...', $orders->count())); + + // 获取 Producer 实例 + $producer = $this->container->get(Producer::class); + + // 每 2 条记录组成一条消息 - 实际生产环境需要增大这个值 + // $orders->chunk(2)->each(function($collection) use ($producer) { + + $messageCount = 0; + + $orders->chunk(2)->each(function (LazyCollection $collection) use ($producer, &$messageCount) { + + $order_data = $collection->pluck('order_raw')->map(function ($item) { + return json_decode($item, true); + })->toArray(); + + //@ATTENTION 生产环境需要注意, 暂时使用 Shopee Loop SG 进行测试 + $messageData = [ + 'company_id' => 171, + 'platform_id' => 25, + 'store_id' => 255, + 'platform_store_id' => 931327381, + 'unique_id' => uniqid() . '_' . time(), + 'raw_data' => $order_data, // 包含 2 条原始记录 + ]; + + // 创建并发送消息 + $message = new ShopeeOrderProducer($messageData); + $producer->produce($message); + + $messageCount++; + + $this->line(sprintf('Sent message %d with order IDs: %s', + $messageCount, + $messageData['unique_id'], + )); + }); + + + $this->info(sprintf('Successfully sent %d messages to RabbitMQ', $messageCount)); + return; + + } catch (Exception $e) { + $this->error('Error pushing messages: ' . $e->getMessage()); + $this->error($e->getTraceAsString()); + return; + } + } +}