72 lines
1.9 KiB
PHP
72 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace Modules\EcommerceFinance\Repositories;
|
|
|
|
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQuery;
|
|
use Modules\EcommerceFinance\Services\UpstreamReadOnlyQueryFactory;
|
|
|
|
class StoreReportUpstreamRepository
|
|
{
|
|
private const SOURCE = 'jiansun';
|
|
|
|
private ?UpstreamReadOnlyQuery $query = null;
|
|
|
|
public function __construct(private readonly UpstreamReadOnlyQueryFactory $queries)
|
|
{
|
|
}
|
|
|
|
/** @return array<int,array<string,mixed>> */
|
|
public function billBatch(int $afterId, int $limit): array
|
|
{
|
|
$limit = min(max($limit, 1), 10000);
|
|
|
|
return $this->query()->select(<<<SQL
|
|
SELECT TOP {$limit}
|
|
bill.Id AS source_id,
|
|
bill.shop_id,
|
|
bill.channel,
|
|
bill.fee_time,
|
|
bill.del_flag,
|
|
bill.primary_key,
|
|
bill.updateTime AS source_updated_at,
|
|
bill.fee_name,
|
|
bill.inout_type,
|
|
bill.amount,
|
|
shop.shop_name
|
|
FROM dbo.jst_originalBillInfo AS bill
|
|
LEFT JOIN dbo.jst_shopInfo AS shop ON shop.shop_id = bill.shop_id
|
|
WHERE bill.Id > ?
|
|
ORDER BY bill.Id
|
|
SQL, [$afterId]);
|
|
}
|
|
|
|
/** @return array<int,array<string,mixed>> */
|
|
public function lifecycleBatch(int $afterId, int $limit): array
|
|
{
|
|
$limit = min(max($limit, 1), 5000);
|
|
|
|
return $this->query()->select(<<<SQL
|
|
SELECT TOP {$limit}
|
|
flow.Id AS source_id,
|
|
flow.erpShopName AS erp_store_name,
|
|
flow.unifiedSocialCreditCode AS unified_social_credit_code,
|
|
flow.applyTime AS effective_at,
|
|
company.businessLicenseName AS company_name
|
|
FROM dbo.fys_shopInfo_flow AS flow
|
|
OUTER APPLY (
|
|
SELECT TOP 1 info.businessLicenseName
|
|
FROM dbo.fys_companyInfo AS info
|
|
WHERE info.unifiedSocialCreditCode = NULLIF(flow.unifiedSocialCreditCode, '')
|
|
ORDER BY info.Id DESC
|
|
) AS company
|
|
WHERE flow.Id > ?
|
|
ORDER BY flow.Id
|
|
SQL, [$afterId]);
|
|
}
|
|
|
|
private function query(): UpstreamReadOnlyQuery
|
|
{
|
|
return $this->query ??= $this->queries->forSource(self::SOURCE);
|
|
}
|
|
}
|