add mq test
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Command;
|
||||
|
||||
use App\Model\User;
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use App\Platform\Tmall\Producer\OrderProducer as TmallOrderProducer;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\Amqp\Producer;
|
||||
|
||||
#[Command]
|
||||
class AppMqInit extends HyperfCommand
|
||||
{
|
||||
|
||||
#[Inject]
|
||||
private Producer $producerService;
|
||||
public function __construct(protected ContainerInterface $container)
|
||||
{
|
||||
parent::__construct('app:mq:init');
|
||||
}
|
||||
|
||||
public function configure()
|
||||
{
|
||||
parent::configure();
|
||||
$this->setDescription('Insert mq test feeds');
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->line('Insert MQ test feeds now...', 'info');
|
||||
|
||||
// shopee
|
||||
// $company_id = 171;
|
||||
// $platform_id = 25;
|
||||
// $store_id = 255;
|
||||
|
||||
// Tmall
|
||||
$company_id = 188;
|
||||
$platform_id = 2;
|
||||
$store_id = 292;
|
||||
|
||||
for ($i=0; $i < 2; $i++) {
|
||||
|
||||
|
||||
$unique_id = \uniqid();
|
||||
|
||||
// 构建 $message_id 格式为 {prefix}#{app_id}#{company_id}#{platform_id}#{store_id}#{entity_type}#{unique_id}
|
||||
|
||||
$data = Db::connection('raw')->table('wpic_taobao_order')
|
||||
->select(['id', 'order_raw'])->orderBy('t_created', 'asc')
|
||||
->limit(20)->offset($i * 20)
|
||||
->get()->toArray();
|
||||
|
||||
$data = [
|
||||
'platform_id' => $platform_id,
|
||||
'company_id' => $company_id,
|
||||
'store_id' => $store_id,
|
||||
'unique_id' => $unique_id,
|
||||
'raw_data' => $data,
|
||||
];
|
||||
|
||||
|
||||
$message = new TmallOrderProducer($data);
|
||||
$result = $this->producerService->produce($message, true);
|
||||
|
||||
|
||||
$log = \sprintf('%s %s %s %s %s',
|
||||
$company_id,
|
||||
$platform_id,
|
||||
$store_id,
|
||||
$unique_id,
|
||||
$result
|
||||
);
|
||||
|
||||
dump($log);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user