feat: join installation item mirror and summaries

This commit is contained in:
chenxi 2026-08-31 17:59:39 +08:00
parent 76ea948970
commit b6cefe776b
8 changed files with 90 additions and 11 deletions

View File

@ -21,6 +21,7 @@ use Modules\EcommerceFinance\Repositories\AlibabaBillRepository;
use Modules\EcommerceFinance\Repositories\CourierInformationMirrorRepository;
use Modules\EcommerceFinance\Repositories\EdgeBandingRepository;
use Modules\EcommerceFinance\Repositories\InventoryRepository;
use Modules\EcommerceFinance\Repositories\InstallationDetailMirrorRepository;
use Modules\EcommerceFinance\Repositories\JdWalletBillRepository;
use Modules\EcommerceFinance\Repositories\NonJingxiRefundMirrorRepository;
use Modules\EcommerceFinance\Repositories\PinduoduoSpreadBillRepository;
@ -58,6 +59,7 @@ class Pages extends Controller
public function __construct(
private readonly EdgeBandingRepository $edgeBanding,
private readonly InventoryRepository $inventory,
private readonly InstallationDetailMirrorRepository $installationDetails,
private readonly NonJingxiRefundMirrorRepository $nonJingxiRefunds,
private readonly ProductCatalogMirrorRepository $productCatalog,
private readonly ProductPriceMirrorRepository $productPrices,
@ -173,6 +175,7 @@ class Pages extends Controller
$tabValue = null;
$tabColumn = null;
$upstreamError = null;
$installationSummary = null;
if ($page && $content === null) {
$descriptor = TableRegistry::describe(
@ -189,6 +192,9 @@ class Pages extends Controller
$page['slug'],
50,
);
if ($section['slug'] === 'financial-operations' && $page['slug'] === 'installation-details') {
$installationSummary = $this->installationDetails->summary();
}
} catch (ServiceUnavailableHttpException $exception) {
// 首份快照尚未生成或某个来源暂时不可用时,保留页面、
// 交代原因并允许后台刷新,而不是把整个业务页变成通用 503。
@ -208,6 +214,7 @@ class Pages extends Controller
'descriptor' => $descriptor,
'rows' => $rows,
'upstreamError' => $upstreamError,
'installationSummary' => $installationSummary,
'tabColumn' => null,
'tabValue' => null,
'edgeBanding' => $this->edgeBandingContent($page['slug']),
@ -248,6 +255,7 @@ class Pages extends Controller
'descriptor' => $descriptor,
'rows' => $rows,
'upstreamError' => $upstreamError,
'installationSummary' => $installationSummary,
'tabColumn' => $tabColumn,
'tabValue' => $tabValue,
'edgeBanding' => $page ? $this->edgeBandingContent($page['slug']) : null,

View File

@ -21,7 +21,7 @@ class InstallationDetail extends Model
'department_owner', 'auxiliary_spu', 'product_store_code', 'item_no', 'barcode', 'product_name',
'supplier_name', 'detail_requested_amount', 'detail_requested_quantity', 'detail_settled_amount',
'detail_received_amount', 'change_reason', 'source_created_at', 'source_modified_at',
'product_name_1', 'installation_company_1',
'product_name_1',
];
protected $casts = [
@ -62,7 +62,7 @@ class InstallationDetail extends Model
'detail_requested_amount' => '申请明细金额', 'detail_requested_quantity' => '申请明细数量',
'detail_settled_amount' => '结算明细金额', 'detail_received_amount' => '收款明细金额',
'change_reason' => '变更原因', 'source_created_at' => '创建时间', 'source_modified_at' => '修改时间',
'product_name_1' => '商品名称(1)', 'installation_company_1' => '安装公司',
'product_name_1' => '商品名称(1)',
];
}

View File

@ -170,6 +170,11 @@ return [
['SubmitTime', 'Id'],
],
],
'jiansun.dbo.fys_Ticketing_install_item' => [
'source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'fys_Ticketing_install_item',
'target' => 'js_fys_ticketing_install_item', 'keys' => ['Id'], 'watermark' => 'modifyTime',
'indexes' => [['guid', 'Id']],
],
'jiansun.dbo.finance_purchaseReturn' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'finance_purchaseReturn', 'target' => 'js_finance_purchase_return', 'keys' => ['id']],
'jiansun.dbo.finance_invoiceDeduction' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'finance_invoiceDeduction', 'target' => 'js_finance_invoice_deduction', 'keys' => ['id'], 'watermark' => 'createTime'],
'jiansun.dbo.fys_supplierPaymentSummary' => ['source_key' => 'jiansun', 'schema' => 'dbo', 'object' => 'fys_supplierPaymentSummary', 'target' => 'js_supplier_payment_summary', 'keys' => ['id'], 'watermark' => 'modifiedTime'],

View File

@ -39,6 +39,7 @@
| --- | --- |
| 营销账户 | `dbo.tmall_spread_bills`、`dbo.pdd_spread_bills`、`dbo.alibaba_bill`、`dbo.jd_spreadBills`、`dbo.jd_costBills` |
| 供应商应付 | `dbo.finance_purchaseReturn`、`dbo.finance_invoiceDeduction`、`dbo.fys_supplierPaymentSummary`、`dbo.finance_advanceLoans`、`dbo.pm_unOrderDetails`、`dbo.finance_sampleDeduction`、`dbo.fys_express_courier_settlement` |
| 安装明细 | `dbo.fys_Ticketing_install_view`、`dbo.fys_Ticketing_install_item` |
| 板材 | `dbo.finance_boardDeduction`、`dbo.pm_plainPlateData`、`dbo.pm_boardPurchasePrice`、`dbo.pm_boardPriceChangeImport`、`dbo.pm_boardApplyDetail` |
| 封边条 | `dbo.pm_edgeBandData`、`dbo.pm_edgeBandApplyDetail`、`dbo.pm_edgeBandProfitInfo`、`dbo.finance_edgeBandDeductio`、`dbo.pm_averageUnitPrice` |
| 库存与货款对账 | `dbo.pm_boardInventoryDetail_snapshot`、`dbo.fys_supplierGoods_sttlement_purchase`、`dbo.fys_supplierGoods_sttlement_sale`、`dbo.pm_purchaseIn` |

View File

@ -9,6 +9,7 @@ use Modules\EcommerceFinance\Services\BusinessMirrorDatasetRegistry;
class InstallationDetailMirrorRepository
{
public const DATASET = 'jiansun.dbo.fys_Ticketing_install_view';
public const ITEM_DATASET = 'jiansun.dbo.fys_Ticketing_install_item';
public function __construct(
private readonly GenericBusinessMirrorRepository $mirror,
@ -22,18 +23,42 @@ class InstallationDetailMirrorRepository
{
$connection = $this->mirror->connection();
$dataset = $this->datasets->get(self::DATASET);
if (! $this->mirror->ready($dataset) || ! Schema::connection($connection->getName())->hasTable($dataset->targetTable())) {
$items = $this->datasets->get(self::ITEM_DATASET);
if (! $this->ready($dataset, $items, $connection->getName())) {
return ['data' => [], 'total' => 0, 'ready' => false];
}
$perPage = min(max($perPage, 1), 100);
$query = $connection->table($dataset->targetTable());
$query = $connection->table($dataset->targetTable() . ' AS v')
->leftJoin($items->targetTable() . ' AS i', 'i.guid', '=', 'v.SourceGuid')
->select(['v.*', 'i.Id AS detail_id', 'i.guid AS detail_guid', 'i.shopproid', 'i.Spu', 'i.shopskucode',
'i.proCode', 'i.barCode', 'i.skuName', 'i.scmname', 'i.applyItemAmount', 'i.installcount',
'i.settleItemAmount', 'i.acceptItemAmount', 'i.remark', 'i.createTime AS item_created_at', 'i.modifyTime AS item_modified_at']);
$total = (clone $query)->count();
$rows = $query->orderByDesc('Id')->forPage(max($page, 1), $perPage)->get();
$rows = $query->orderByDesc('v.Id')->orderByDesc('i.Id')->forPage(max($page, 1), $perPage)->get();
return ['data' => $rows->map(fn (object $row): array => $this->map((array) $row))->all(), 'total' => $total, 'ready' => true];
}
private function ready($dataset, $items, string $connection): bool
{
return $this->mirror->ready($dataset) && $this->mirror->ready($items)
&& Schema::connection($connection)->hasTable($dataset->targetTable())
&& Schema::connection($connection)->hasTable($items->targetTable());
}
/** @return array{rows:int,requested:float,settled:float,paid:float} */
public function summary(): array
{
$dataset = $this->datasets->get(self::DATASET);
$connection = $this->mirror->connection();
if (! $this->mirror->ready($dataset) || ! Schema::connection($connection->getName())->hasTable($dataset->targetTable())) {
return ['rows' => 0, 'requested' => 0.0, 'settled' => 0.0, 'paid' => 0.0];
}
$row = $connection->table($dataset->targetTable())->selectRaw('COUNT(*) AS rows, COALESCE(SUM(installcost),0) AS requested, COALESCE(SUM(settleAmount),0) AS settled, COALESCE(SUM(acceptAmount),0) AS paid')->first();
return ['rows' => (int) $row->rows, 'requested' => (float) $row->requested, 'settled' => (float) $row->settled, 'paid' => (float) $row->paid];
}
/** @param array<string,mixed> $row */
private function map(array $row): array
{
@ -45,24 +70,52 @@ class InstallationDetailMirrorRepository
};
$mapped = [
'id' => $value($row, 'Id'), 'installation_no' => $value($row, 'ordernum_id', 'OrderNum'),
'quote_status' => $value($row, 'BidStatus'), 'quote_deadline' => $value($row, 'BidEndTime'),
'id' => $value($row, 'detail_id', 'Id'), 'installation_no' => $value($row, 'ordernum_id', 'OrderNum'),
'delete_status' => $value($row, 'Delete'), 'quote_status' => $value($row, 'BidStatus'), 'quote_deadline' => $value($row, 'BidEndTime'),
'installation_company' => $value($row, 'installCompanyName'), 'submitted_at' => $value($row, 'SubmitTime'),
'shipped_at' => $value($row, 'ShipTIme'), 'buyer_nickname' => $value($row, 'BuyersNick'),
'store_name' => $value($row, 'shop_name', 'shopname'), 'order_no' => $value($row, 'OrderNum'),
'store_name' => $value($row, 'shop_name', 'shopname'), 'installation_type' => $value($row, 'TypeDto'),
'pre_push_verification' => $value($row, 'checkMsg'), 'push_status' => $value($row, 'apistatus'),
'push_result' => $value($row, 'apiresult'), 'arranged_status' => $this->arranged($value($row, 'StatusId')),
'order_no' => $value($row, 'OrderNum'),
'item_quantity' => $value($row, 'Num'), 'buyer_name' => $value($row, 'BuyersName'), 'buyer_phone' => $value($row, 'Mobile'),
'notes' => $value($row, 'Nots'), 'province' => $value($row, 'Province'), 'city' => $value($row, 'City'),
'district' => $value($row, 'Area'), 'address' => $value($row, 'Address'), 'requested_amount' => $value($row, 'installcost'),
'settled_amount' => $value($row, 'settleAmount'), 'image_urls' => $value($row, 'Picture'), 'completed_status' => $value($row, 'installComplete'),
'customer_service_reviewed_at' => $value($row, 'kfshTime'), 'finance_reviewed_at' => $value($row, 'cwshTime'),
'settled_amount' => $value($row, 'settleAmount'), 'image_urls' => $value($row, 'Picture'),
'completed_status' => $this->yesNo($value($row, 'installComplete')),
'customer_service_review' => $this->review($value($row, 'kfsh')), 'customer_service_reviewed_at' => $value($row, 'kfshTime'),
'finance_review' => $this->review($value($row, 'cwsh')), 'finance_reviewed_at' => $value($row, 'cwshTime'),
'actual_install_quantity' => $value($row, 'installNum'), 'actual_install_fee' => $value($row, 'install_Cost'),
'actual_install_product_name' => $value($row, 'installGoodsName'), 'installer_phone' => $value($row, 'installTel'),
'installation_company_notes' => $value($row, 'installNote'), 'installation_fee_payer' => $value($row, 'costtaker'),
'payment_channel' => $value($row, 'costWay'), 'payment_transaction_no' => $value($row, 'actporderNum'),
'payment_voucher' => $value($row, 'costWayVoucher'), 'payment_amount' => $value($row, 'acceptAmount'),
'creator' => $value($row, 'Operation'), 'related_guid' => $value($row, 'detail_guid', 'SourceGuid'),
'product_id' => $value($row, 'shopproid'), 'auxiliary_spu' => $value($row, 'Spu'),
'product_store_code' => $value($row, 'shopskucode'), 'item_no' => $value($row, 'proCode'),
'barcode' => $value($row, 'barCode'), 'product_name' => $value($row, 'skuName'), 'supplier_name' => $value($row, 'scmname'),
'detail_requested_amount' => $value($row, 'applyItemAmount'), 'detail_requested_quantity' => $value($row, 'installcount'),
'detail_settled_amount' => $value($row, 'settleItemAmount'), 'detail_received_amount' => $value($row, 'acceptItemAmount'),
'change_reason' => $value($row, 'remark'), 'source_created_at' => $value($row, 'item_created_at'),
'source_modified_at' => $value($row, 'item_modified_at'),
];
// 页面按模板的完整 61 列渲染;视图暂未提供的字段必须显式为 null,
// 不能让 Blade 读取未定义属性。
return array_replace(array_fill_keys(array_keys(\App\Models\Business\InstallationDetail::columnLabels()), null), $mapped);
}
private function yesNo(mixed $value): ?string
{
return $value === null ? null : ((int) $value === 1 ? '是' : '否');
}
private function review(mixed $value): ?string
{
return $value === null ? null : ((int) $value === 1 ? '已审核' : '未审核');
}
private function arranged(mixed $value): ?string
{
return $value === null ? null : ((int) $value > 0 ? '已安排' : '未安排');
}
}

View File

@ -521,6 +521,15 @@
@endunless
</div>
@if ($page['slug'] === 'installation-details' && is_array($installationSummary ?? null))
<dl class="upstream-data-summary" aria-label="安装明细汇总">
<div><dt>安装明细</dt><dd>{{ number_format((int) ($installationSummary['rows'] ?? 0)) }}</dd></div>
<div><dt>申请总金额</dt><dd>{{ number_format((float) ($installationSummary['requested'] ?? 0), 2) }}</dd></div>
<div><dt>结算总金额</dt><dd>{{ number_format((float) ($installationSummary['settled'] ?? 0), 2) }}</dd></div>
<div><dt>收款金额</dt><dd>{{ number_format((float) ($installationSummary['paid'] ?? 0), 2) }}</dd></div>
</dl>
@endif
<div class="biz-table-wrap">
<table class="biz-table">
<thead>

View File

@ -31,6 +31,7 @@ class ManagementCrudTest extends FeatureTestCase
'store_name' => '测试店铺', 'requested_amount' => '120.50', 'settled_amount' => '100.00', 'item_quantity' => 2,
])],
]);
$mirror->shouldReceive('summary')->once()->andReturn(['rows' => 1, 'requested' => 120.50, 'settled' => 100.00, 'paid' => 0.0]);
$this->app->instance(InstallationDetailMirrorRepository::class, $mirror);
$this->loginAs()

View File

@ -277,11 +277,13 @@ class BusinessMirrorSynchronizerTest extends TestCase
$datasets = (new BusinessMirrorDatasetRegistry())->all();
$targets = array_map(fn ($dataset): string => $dataset->targetTable(), $datasets);
$this->assertCount(38, $datasets);
$this->assertGreaterThanOrEqual(38, count($datasets));
$this->assertCount(count($targets), array_unique($targets));
$this->assertContains('operations_replica', array_map(fn ($dataset): string => $dataset->sourceKey(), $datasets));
$this->assertContains('jiansun', array_map(fn ($dataset): string => $dataset->sourceKey(), $datasets));
$this->assertNotContains('Bulk_Price_Limit', array_map(fn ($dataset): string => $dataset->sourceObject(), $datasets));
$this->assertContains('fys_Ticketing_install_view', array_map(fn ($dataset): string => $dataset->sourceObject(), $datasets));
$this->assertContains('fys_Ticketing_install_item', array_map(fn ($dataset): string => $dataset->sourceObject(), $datasets));
}
/** @return array<string,mixed> */