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 387da59a..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].[aaronprice]'; + private const SOURCE = 'operations_replica'; - private const PRICE_TYPES = [ - 'pricing' => '定价', - 'repricing' => '变价', - ]; - - private const COST_REDUCTION = [ - 'yes' => '是', - 'no' => '否', - ]; + private const TABLE = '[rpt].[Bulk_Price_Limit]'; private readonly UpstreamReadOnlyQuery $query; @@ -39,53 +30,41 @@ class ProductPriceRepository $bindings = []; if (($filters['barcode'] ?? '') !== '') { - $where[] = "[条形码] 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[] = '[价格类型] = ?'; - $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[] = '[是否采购降本] = ?'; - $bindings[] = $costReduction; - } - - if (($filters['effective_from'] ?? '') !== '') { - $where[] = 'TRY_CONVERT(date, [生效开始时间]) >= ?'; - $bindings[] = (string) $filters['effective_from']; - } - - if (($filters['effective_to'] ?? '') !== '') { - $where[] = 'TRY_CONVERT(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 ' - . '[条形码] 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 ' + . '[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 TRY_CONVERT(datetime2, [流程完成时间]) DESC, [条形码] 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))]; @@ -99,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 @@