-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGetOrder.php
77 lines (65 loc) · 2.59 KB
/
GetOrder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
declare(strict_types=1);
/**
*
* @author xiaoguo0426
* @contact [email protected]
* @license MIT
*/
namespace App\Command\Amazon\Order;
use AmazonPHP\SellingPartner\AccessToken;
use AmazonPHP\SellingPartner\SellingPartnerSDK;
use App\Util\Amazon\Creator\OrderCreator;
use App\Util\Amazon\Engine\OrderEngine;
use App\Util\AmazonApp;
use App\Util\AmazonSDK;
use Hyperf\Command\Annotation\Command;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Di\Exception\NotFoundException;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Symfony\Component\Console\Input\InputArgument;
use function Hyperf\Support\make;
#[Command]
class GetOrder extends HyperfCommand
{
public function __construct(protected ContainerInterface $container)
{
parent::__construct('amazon:order:get-order');
}
public function configure(): void
{
parent::configure();
// 指令配置
$this->addArgument('merchant_id', InputArgument::REQUIRED, '商户id')
->addArgument('merchant_store_id', InputArgument::REQUIRED, '店铺id')
->addArgument('region', InputArgument::REQUIRED, '地区')
->addArgument('order_id', InputArgument::REQUIRED, 'order_id')
->setDescription('Amazon Order API Get Order Command');
}
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws \RedisException
* @throws NotFoundException
*/
public function handle(): void
{
$merchant_id = (int) $this->input->getArgument('merchant_id');
$merchant_store_id = (int) $this->input->getArgument('merchant_store_id');
$region = $this->input->getArgument('region');
$amazon_order_id = $this->input->getArgument('order_id');
AmazonApp::tok2($merchant_id, $merchant_store_id, $region, static function (AmazonSDK $amazonSDK, int $merchant_id, int $merchant_store_id, SellingPartnerSDK $sdk, AccessToken $accessToken, string $region, array $marketplace_ids) use ($amazon_order_id) {
$nextToken = null;
$max_results_per_page = 100;
$orderCreator = new OrderCreator();
$orderCreator->setMarketplaceIds($marketplace_ids);
$orderCreator->setMaxResultsPerPage($max_results_per_page);
$orderCreator->setNextToken($nextToken);
$orderCreator->setAmazonOrderIds([$amazon_order_id]);
make(OrderEngine::class, [$amazonSDK, $sdk, $accessToken])->launch($orderCreator);
return true;
});
}
}