diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 769756eb..a5622105 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -497,18 +497,14 @@ class Pages extends Controller protected function contentForProductPrices(): array { - $priceType = trim((string) request('price_type', '')); - $costReduction = trim((string) request('cost_reduction', '')); $filters = [ 'barcode' => mb_substr(trim((string) request('barcode', '')), 0, 191), - 'price_type' => in_array($priceType, ['pricing', 'repricing'], true) ? $priceType : '', - 'cost_reduction' => in_array($costReduction, ['yes', 'no'], true) ? $costReduction : '', - 'effective_from' => $this->dateFilter(request('effective_from')), - 'effective_to' => $this->dateFilter(request('effective_to')), + 'completed_from' => $this->dateFilter(request('completed_from')), + 'completed_to' => $this->dateFilter(request('completed_to')), ]; $page = max((int) request('page', 1), 1); $limit = min(max((int) setting('default.list_limit', 25), 1), 100); - $cache = $this->upstreamCaches->forSource('jiansun'); + $cache = $this->upstreamCaches->forSource('operations_replica'); try { $result = $cache->remember( diff --git a/modules/EcommerceFinance/Repositories/ProductPriceRepository.php b/modules/EcommerceFinance/Repositories/ProductPriceRepository.php index adba2572..e83041f4 100644 --- a/modules/EcommerceFinance/Repositories/ProductPriceRepository.php +++ b/modules/EcommerceFinance/Repositories/ProductPriceRepository.php @@ -6,22 +6,13 @@ use Modules\EcommerceFinance\Services\UpstreamReadOnlyQuery; use Modules\EcommerceFinance\Services\UpstreamReadOnlyQueryFactory; /** - * Supplier product pricing and repricing records from JianSun. + * Completed product price-limit approvals from the operations replica. */ class ProductPriceRepository { - private const SOURCE = 'jiansun'; - private const TABLE = '[dbo].[pm_priceAdjustment_log]'; + private const SOURCE = 'operations_replica'; - private const PRICE_TYPES = [ - 'pricing' => '0', - 'repricing' => '1', - ]; - - private const COST_REDUCTION = [ - 'yes' => '1', - 'no' => '0', - ]; + private const TABLE = '[rpt].[Bulk_Price_Limit]'; private readonly UpstreamReadOnlyQuery $query; @@ -39,54 +30,41 @@ class ProductPriceRepository $bindings = []; if (($filters['barcode'] ?? '') !== '') { - $where[] = "[skucode] LIKE ? ESCAPE '\\'"; + $where[] = "[product_code] LIKE ? ESCAPE '\\'"; $bindings[] = $this->contains((string) $filters['barcode']); } - $priceType = self::PRICE_TYPES[(string) ($filters['price_type'] ?? '')] ?? null; - - if ($priceType !== null) { - $where[] = '[priceType] = ?'; - $bindings[] = $priceType; + if (($filters['completed_from'] ?? '') !== '') { + $where[] = '[process_end_date] >= CAST(? AS date)'; + $bindings[] = (string) $filters['completed_from']; } - $costReduction = self::COST_REDUCTION[(string) ($filters['cost_reduction'] ?? '')] ?? null; - - if ($costReduction !== null) { - $where[] = '[isCostReduction] = ?'; - $bindings[] = $costReduction; - } - - if (($filters['effective_from'] ?? '') !== '') { - $where[] = '[effectStartTime] >= CAST(? AS date)'; - $bindings[] = (string) $filters['effective_from']; - } - - if (($filters['effective_to'] ?? '') !== '') { - $where[] = '[effectStartTime] < DATEADD(day, 1, CAST(? AS date))'; - $bindings[] = (string) $filters['effective_to']; + if (($filters['completed_to'] ?? '') !== '') { + $where[] = '[process_end_date] < DATEADD(day, 1, CAST(? AS date))'; + $bindings[] = (string) $filters['completed_to']; } $whereSql = $where === [] ? '' : ' WHERE ' . implode(' AND ', $where); $offset = ($page - 1) * $limit; $fetch = $limit + 1; $sql = 'SELECT ' - . '[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 ' + . '[product_code] AS barcode, ' + . '[spu] AS spu, ' + . '[product_name] AS product_name, ' + . '[category] AS category, ' + . '[production_status] AS production_status, ' + . '[min_price] AS minimum_price, ' + . '[price_limit] AS price_limit, ' + . '[purchase_price] AS purchase_price, ' + . '[shipping_fee] AS shipping_fee, ' + . '[jingxi_limit_price] AS jingxi_limit_price, ' + . "CASE [status] WHEN 'COMPLETED' THEN N'已完成' ELSE NULLIF([status], '') END AS approval_status, " + . "CASE [result] WHEN 'agree' THEN N'已同意' WHEN 'refuse' THEN N'已拒绝' ELSE NULLIF([result], '') END AS approval_result, " + . '[title] AS workflow_title, ' + . 'CONVERT(varchar(19), [process_end_date], 120) AS completed_at ' . 'FROM ' . self::TABLE . $whereSql - . ' ORDER BY COALESCE([updateTime], [createTime]) DESC, [Id] DESC, [skucode] ASC' + . ' ORDER BY [process_end_date] DESC, [businessId] DESC, [product_code] ASC' . " OFFSET {$offset} ROWS FETCH NEXT {$fetch} ROWS ONLY"; return ['rows' => array_map([$this, 'normalize'], $this->query->select($sql, $bindings))]; @@ -100,7 +78,7 @@ class ProductPriceRepository /** @param array $row */ private function normalize(array $row): array { - foreach (['price_before', 'price_after', 'price_diff'] as $field) { + foreach (['minimum_price', 'price_limit', 'purchase_price', 'shipping_fee', 'jingxi_limit_price'] as $field) { $row[$field] = $row[$field] === null || $row[$field] === '' ? null : (float) $row[$field]; diff --git a/modules/EcommerceFinance/Services/JianSunSnapshotRefresher.php b/modules/EcommerceFinance/Services/JianSunSnapshotRefresher.php index f24e43ca..a376b2e4 100644 --- a/modules/EcommerceFinance/Services/JianSunSnapshotRefresher.php +++ b/modules/EcommerceFinance/Services/JianSunSnapshotRefresher.php @@ -10,7 +10,6 @@ use Modules\EcommerceFinance\Repositories\GoodsReconciliationRepository; use Modules\EcommerceFinance\Repositories\InventoryRepository; use Modules\EcommerceFinance\Repositories\JdWalletBillRepository; use Modules\EcommerceFinance\Repositories\PinduoduoSpreadBillRepository; -use Modules\EcommerceFinance\Repositories\ProductPriceRepository; use Modules\EcommerceFinance\Repositories\RawBoardPayablesRepository; use Modules\EcommerceFinance\Repositories\SupplierPayableRepository; use Modules\EcommerceFinance\Repositories\SupplierPayableReportRepository; @@ -28,7 +27,6 @@ class JianSunSnapshotRefresher implements UpstreamSnapshotRefresher private readonly InventoryRepository $inventory, private readonly AlibabaBillRepository $alibaba, private readonly PinduoduoSpreadBillRepository $pinduoduo, - private readonly ProductPriceRepository $productPrices, private readonly RawBoardPayablesRepository $rawBoardPayables, private readonly TmallTaobaoSpreadBillRepository $taobaoAlipay, private readonly SupplierPayableRepository $supplier, @@ -162,11 +160,6 @@ class JianSunSnapshotRefresher implements UpstreamSnapshotRefresher ), 'taobao-alipay-bills.options' => $this->taobaoAlipay->storeOptions(), - 'supplier-payables.product-prices.list' => $this->productPrices->paginate( - $filters, - $page, - $limit, - ), 'supplier-payables.board-deductions.list' => $this->supplierPayableReports->boardDeductions( $filters, $page, diff --git a/modules/EcommerceFinance/Services/OperationsReplicaSnapshotRefresher.php b/modules/EcommerceFinance/Services/OperationsReplicaSnapshotRefresher.php index 03467a1c..88373d78 100644 --- a/modules/EcommerceFinance/Services/OperationsReplicaSnapshotRefresher.php +++ b/modules/EcommerceFinance/Services/OperationsReplicaSnapshotRefresher.php @@ -5,6 +5,7 @@ namespace Modules\EcommerceFinance\Services; use App\Business\UpstreamBusinessInformation; use Modules\EcommerceFinance\Contracts\UpstreamSnapshotRefresher; use Modules\EcommerceFinance\Repositories\OrderDataRepository; +use Modules\EcommerceFinance\Repositories\ProductPriceRepository; /** * 将经营分析副本库已登记的业务信息查询还原为共享快照刷新任务。 @@ -17,6 +18,7 @@ class OperationsReplicaSnapshotRefresher implements UpstreamSnapshotRefresher private readonly UpstreamQueryCacheFactory $caches, private readonly UpstreamBusinessInformation $information, private readonly OrderDataRepository $orders, + private readonly ProductPriceRepository $productPrices, ) { } @@ -44,6 +46,11 @@ class OperationsReplicaSnapshotRefresher implements UpstreamSnapshotRefresher (int) ($parameters['page'] ?? 1), (int) ($parameters['limit'] ?? 25), ), + 'supplier-payables.product-prices.list' => $this->productPrices->paginate( + (array) ($parameters['filters'] ?? []), + (int) ($parameters['page'] ?? 1), + (int) ($parameters['limit'] ?? 25), + ), default => $this->information->snapshot($scope, $parameters), }, ); diff --git a/resources/views/business/pages/supplier-payables/product-prices.blade.php b/resources/views/business/pages/supplier-payables/product-prices.blade.php index f8658b08..84abf3e2 100644 --- a/resources/views/business/pages/supplier-payables/product-prices.blade.php +++ b/resources/views/business/pages/supplier-payables/product-prices.blade.php @@ -7,7 +7,7 @@