diff --git a/modules/EcommerceFinance/Repositories/ProductPriceRepository.php b/modules/EcommerceFinance/Repositories/ProductPriceRepository.php index 387da59a..adba2572 100644 --- a/modules/EcommerceFinance/Repositories/ProductPriceRepository.php +++ b/modules/EcommerceFinance/Repositories/ProductPriceRepository.php @@ -11,16 +11,16 @@ use Modules\EcommerceFinance\Services\UpstreamReadOnlyQueryFactory; class ProductPriceRepository { private const SOURCE = 'jiansun'; - private const TABLE = '[dbo].[aaronprice]'; + private const TABLE = '[dbo].[pm_priceAdjustment_log]'; private const PRICE_TYPES = [ - 'pricing' => '定价', - 'repricing' => '变价', + 'pricing' => '0', + 'repricing' => '1', ]; private const COST_REDUCTION = [ - 'yes' => '是', - 'no' => '否', + 'yes' => '1', + 'no' => '0', ]; private readonly UpstreamReadOnlyQuery $query; @@ -39,31 +39,31 @@ class ProductPriceRepository $bindings = []; if (($filters['barcode'] ?? '') !== '') { - $where[] = "[条形码] LIKE ? ESCAPE '\\'"; + $where[] = "[skucode] LIKE ? ESCAPE '\\'"; $bindings[] = $this->contains((string) $filters['barcode']); } $priceType = self::PRICE_TYPES[(string) ($filters['price_type'] ?? '')] ?? null; if ($priceType !== null) { - $where[] = '[价格类型] = ?'; + $where[] = '[priceType] = ?'; $bindings[] = $priceType; } $costReduction = self::COST_REDUCTION[(string) ($filters['cost_reduction'] ?? '')] ?? null; if ($costReduction !== null) { - $where[] = '[是否采购降本] = ?'; + $where[] = '[isCostReduction] = ?'; $bindings[] = $costReduction; } if (($filters['effective_from'] ?? '') !== '') { - $where[] = 'TRY_CONVERT(date, [生效开始时间]) >= ?'; + $where[] = '[effectStartTime] >= CAST(? AS date)'; $bindings[] = (string) $filters['effective_from']; } if (($filters['effective_to'] ?? '') !== '') { - $where[] = 'TRY_CONVERT(date, [生效开始时间]) <= ?'; + $where[] = '[effectStartTime] < DATEADD(day, 1, CAST(? AS date))'; $bindings[] = (string) $filters['effective_to']; } @@ -71,21 +71,22 @@ class ProductPriceRepository $offset = ($page - 1) * $limit; $fetch = $limit + 1; $sql = 'SELECT ' - . '[条形码] AS barcode, ' - . '[价格类型] AS price_type, ' - . '[变价类型] AS change_type, ' - . '[是否采购降本] AS cost_reduction, ' - . 'TRY_CONVERT(decimal(18,2), NULLIF([变价前价格], \'\')) AS price_before, ' - . 'TRY_CONVERT(decimal(18,2), NULLIF([变价后价格], \'\')) AS price_after, ' - . 'TRY_CONVERT(decimal(18,2), NULLIF([差价], \'\')) AS price_diff, ' - . '[申请人] AS applicant, ' - . '[备注] AS remark, ' - . 'CONVERT(varchar(19), TRY_CONVERT(datetime2, [生效开始时间]), 120) AS effective_start, ' - . 'CONVERT(varchar(19), TRY_CONVERT(datetime2, [生效结束时间]), 120) AS effective_end, ' - . 'CONVERT(varchar(19), TRY_CONVERT(datetime2, [流程完成时间]), 120) AS completed_at ' + . '[skucode] AS barcode, ' + . "CASE [priceType] WHEN '0' THEN N'定价' WHEN '1' THEN N'变价' ELSE NULLIF([priceType], '') END AS price_type, " + . "CASE [priceChangeType] WHEN '0' THEN N'普通变价' WHEN '1' THEN N'清货变价' " + . "WHEN '2' THEN N'阶段变价' WHEN '4' THEN N'打折入库' ELSE NULLIF([priceChangeType], '') END AS change_type, " + . "CASE [isCostReduction] WHEN '1' THEN N'是' WHEN '0' THEN N'否' ELSE NULL END AS cost_reduction, " + . '[originalPrice] AS price_before, ' + . '[afterPrice] AS price_after, ' + . '[diffPrice] AS price_diff, ' + . '[applyUser] AS applicant, ' + . '[remark] AS remark, ' + . 'CONVERT(varchar(19), [effectStartTime], 120) AS effective_start, ' + . 'CONVERT(varchar(19), [effectEndTime], 120) AS effective_end, ' + . 'CONVERT(varchar(19), COALESCE([updateTime], [createTime]), 120) AS completed_at ' . 'FROM ' . self::TABLE . $whereSql - . ' ORDER BY TRY_CONVERT(datetime2, [流程完成时间]) DESC, [条形码] ASC' + . ' ORDER BY COALESCE([updateTime], [createTime]) DESC, [Id] DESC, [skucode] ASC' . " OFFSET {$offset} ROWS FETCH NEXT {$fetch} ROWS ONLY"; return ['rows' => array_map([$this, 'normalize'], $this->query->select($sql, $bindings))]; diff --git a/tests/Unit/EcommerceFinance/ProductPriceRepositoryTest.php b/tests/Unit/EcommerceFinance/ProductPriceRepositoryTest.php index 894e0346..d546cd26 100644 --- a/tests/Unit/EcommerceFinance/ProductPriceRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/ProductPriceRepositoryTest.php @@ -15,11 +15,17 @@ class ProductPriceRepositoryTest extends TestCase $query->expects($this->once())->method('select')->willReturnCallback( function (string $sql, array $bindings): array { UpstreamReadOnlyQuery::assertReadOnlySql($sql); - $this->assertStringContainsString('[dbo].[aaronprice]', $sql); - $this->assertStringContainsString('[条形码] LIKE ?', $sql); + $this->assertStringContainsString('[dbo].[pm_priceAdjustment_log]', $sql); + $this->assertStringContainsString('[skucode] LIKE ?', $sql); + $this->assertStringContainsString("CASE [priceType] WHEN '0' THEN N'定价' WHEN '1' THEN N'变价'", $sql); + $this->assertStringContainsString("WHEN '1' THEN N'清货变价'", $sql); + $this->assertStringContainsString("WHEN '2' THEN N'阶段变价'", $sql); + $this->assertStringContainsString("WHEN '4' THEN N'打折入库'", $sql); + $this->assertStringContainsString("CASE [isCostReduction] WHEN '1' THEN N'是' WHEN '0' THEN N'否'", $sql); + $this->assertStringContainsString('[effectStartTime] < DATEADD(day, 1, CAST(? AS date))', $sql); $this->assertStringContainsString('OFFSET 2 ROWS FETCH NEXT 3 ROWS ONLY', $sql); $this->assertSame( - ['%ABC\\%\\_%', '定价', '是', '2026-07-01', '2026-07-31'], + ['%ABC\\%\\_%', '0', '1', '2026-07-01', '2026-07-31'], $bindings, );