Skip to content

Commit 6ef363e

Browse files
author
peter
committed
update
1 parent 4a5368a commit 6ef363e

File tree

5 files changed

+15
-33
lines changed

5 files changed

+15
-33
lines changed

app/Command/Amazon/Finance/ListFinancialEventGroups.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function configure(): void
4545
parent::configure();
4646
$this->addArgument('merchant_id', InputArgument::REQUIRED, '商户id')
4747
->addArgument('merchant_store_id', InputArgument::REQUIRED, '店铺id')
48+
->addArgument('region', InputArgument::REQUIRED, '地区')
4849
->setDescription('Amazon Finance List Financial Event Groups Command');
4950
}
5051

@@ -57,8 +58,9 @@ public function handle(): void
5758
{
5859
$merchant_id = (int) $this->input->getArgument('merchant_id');
5960
$merchant_store_id = (int) $this->input->getArgument('merchant_store_id');
61+
$region = $this->input->getArgument('region');
6062

61-
AmazonApp::tok($merchant_id, $merchant_store_id, static function (AmazonSDK $amazonSDK, int $merchant_id, int $merchant_store_id, SellingPartnerSDK $sdk, AccessToken $accessToken, string $region, array $marketplace_ids) {
63+
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) {
6264
$console = ApplicationContext::getContainer()->get(StdoutLoggerInterface::class);
6365
$logger = ApplicationContext::getContainer()->get(AmazonFinanceLog::class);
6466

app/Command/Amazon/Finance/ListFinancialEvents.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function configure(): void
4242
parent::configure();
4343
$this->addArgument('merchant_id', InputArgument::REQUIRED, '商户id')
4444
->addArgument('merchant_store_id', InputArgument::REQUIRED, '店铺id')
45+
->addArgument('region', InputArgument::REQUIRED, '地区')
4546
->addArgument('posted_after', InputArgument::REQUIRED, '指定时间之后(或在指定时间)发布的财务事件的日期')
4647
->addArgument('posted_before', InputArgument::OPTIONAL, '指定时间之前(但不是在指定时间)发布的财务事件的日期')
4748
->setDescription('Amazon Finance List Financial Events Command');
@@ -56,10 +57,11 @@ public function handle(): void
5657
{
5758
$merchant_id = (int) $this->input->getArgument('merchant_id');
5859
$merchant_store_id = (int) $this->input->getArgument('merchant_store_id');
60+
$region = $this->input->getArgument('region');
5961
$posted_after = $this->input->getArgument('posted_after');
6062
$posted_before = $this->input->getArgument('posted_before');
6163

62-
AmazonApp::tok($merchant_id, $merchant_store_id, static function (AmazonSDK $amazonSDK, int $merchant_id, int $merchant_store_id, SellingPartnerSDK $sdk, AccessToken $accessToken, string $region, array $marketplace_ids) use ($posted_after, $posted_before) {
64+
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 ($posted_after, $posted_before) {
6365
$console = ApplicationContext::getContainer()->get(StdoutLoggerInterface::class);
6466
$logger = ApplicationContext::getContainer()->get(AmazonFinanceLog::class);
6567

app/Command/Crontab/Amazon/CommonCacheRefresh.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@
1111
namespace App\Command\Crontab\Amazon;
1212

1313
use App\Model\AmazonAppModel;
14-
use App\Model\AmazonInventoryModel;
1514
use App\Util\AmazonApp;
16-
use App\Util\RedisHash\AmazonInventoryFnSkuToSkuMapHash;
1715
use Hyperf\Command\Annotation\Command;
1816
use Hyperf\Command\Command as HyperfCommand;
1917
use Psr\Container\ContainerInterface;
2018

21-
use function Hyperf\Support\make;
22-
2319
#[Command]
2420
class CommonCacheRefresh extends HyperfCommand
2521
{
@@ -36,26 +32,6 @@ public function handle(): void
3632
$merchant_id = $amazonAppCollection->merchant_id;
3733
$merchant_store_id = $amazonAppCollection->merchant_store_id;
3834

39-
/**
40-
* @var AmazonInventoryFnSkuToSkuMapHash $hash
41-
*/
42-
$hash = make(AmazonInventoryFnSkuToSkuMapHash::class, [$merchant_id, $merchant_store_id]);
43-
44-
$fnSkuMapCollections = AmazonInventoryModel::query()
45-
->where('merchant_id', $merchant_id)
46-
->where('merchant_store_id', 1)
47-
->pluck('seller_sku', 'fn_sku');
48-
49-
if ($fnSkuMapCollections->isEmpty()) {
50-
return true;
51-
}
52-
foreach ($fnSkuMapCollections as $fn_sku => $seller_sku) {
53-
try {
54-
$hash->setSellerSkuByFnSku($fn_sku, $seller_sku);
55-
} catch (\JsonException|\RedisException $e) {
56-
}
57-
}
58-
5935
return true;
6036
});
6137
}

app/Util/AmazonApp.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static function tick(int $merchant_id, int $merchant_store_id, callable $
6666
try {
6767
$amazonAppCollection = AmazonAppModel::query()->where('merchant_id', $merchant_id)->where('merchant_store_id', $merchant_store_id)->firstOrFail();
6868
} catch (ModelNotFoundException $exception) {
69-
throw new AmazonAppException(sprintf('AmazonAppException ModelNotFound. %s', $exception->getMessage()), 201);
69+
throw new AmazonAppException(sprintf('AmazonAppException ModelNotFound. 错误信息:%s', $exception->getMessage()), 201);
7070
}
7171
$appHash->load($amazonAppCollection->toArray());
7272
$appHash->ttl(3600);
@@ -158,21 +158,22 @@ public static function tok2(int $merchant_id, int $merchant_store_id, string $re
158158
// 验证region知否为合法
159159
try {
160160
self::region($region);
161-
} catch (BusinessException $businessException) {
162-
$log = sprintf('Amazon App SDK构建失败,region值非法. region:%s ', $region);
161+
} catch (AmazonAppException $amazonAppException) {
162+
$log = sprintf('Amazon App SDK构建失败,region值非法. region:%s, 请检查. ', $region);
163163
$console = ApplicationContext::getContainer()->get(StdoutLoggerInterface::class);
164164
$console->error($log);
165165
return true;
166166
}
167167

168+
//TODO 缓存AmazonAppRegionModel数据
168169
try {
169170
$amazonAppRegionCollection = AmazonAppRegionModel::query()
170171
->where('merchant_id', $merchant_id)
171172
->where('merchant_store_id', $merchant_store_id)
172173
->where('region', $region)
173174
->firstOrFail();
174175
} catch (ModelNotFoundException $modelNotFoundException) {
175-
$log = sprintf('Amazon App SDK构建失败,AmazonAppRegion查询失败. %s merchant_id:%s merchant_store_id:%s region:%s ', $modelNotFoundException->getMessage(), $merchant_id, $merchant_store_id, $region);
176+
$log = sprintf('Amazon App SDK构建失败,AmazonAppRegion查询失败. 错误信息:%s merchant_id:%s merchant_store_id:%s region:%s ', $modelNotFoundException->getMessage(), $merchant_id, $merchant_store_id, $region);
176177
$console = ApplicationContext::getContainer()->get(StdoutLoggerInterface::class);
177178
$console->error($log);
178179
return true;
@@ -220,6 +221,7 @@ public static function tok2(int $merchant_id, int $merchant_store_id, string $re
220221
*/
221222
public static function single(callable $func): bool
222223
{
224+
//TODO 缓存AmazonAppModel数据
223225
$amazonAppCollections = AmazonAppModel::query()->where('status', Constants::STATUS_ACTIVE)->get();
224226
if ($amazonAppCollections->isEmpty()) {
225227
return false;
@@ -266,7 +268,7 @@ public static function regions(array $regions): void
266268
public static function region(string $region): void
267269
{
268270
if (! Regions::isValid($region)) {
269-
throw new BusinessException('Invalid Region', 1);
271+
throw new AmazonAppException('Invalid Region', 1);
270272
}
271273
}
272274
}

app/Util/AmazonSDK.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function __construct(AmazonAppModel $amazonAppModel)
9595
$marketplace_ids[] = $country->id();
9696
$this->marketplace_id_country_map[$country->id()] = $countryId;
9797
} catch (InvalidArgumentException $exception) {
98+
// $exception->getMessage();
9899
}
99100
}
100101
$this->marketplace_ids = $marketplace_ids;
@@ -302,8 +303,7 @@ public function getSdk(string $region, bool $force_refresh = false): SellingPart
302303
$hash->accessKeyId = $assumeRole->accessKeyId();
303304
$hash->secretAccessKey = $assumeRole->secretAccessKey();
304305
$hash->sessionToken = $assumeRole->sessionToken();
305-
$expiration = $assumeRole->expiration();
306-
$hash->expiration = $expiration;
306+
$hash->expiration = $assumeRole->expiration();
307307
$hash->ttl(50 * 60);
308308
}
309309

0 commit comments

Comments
 (0)