feat: 同步快递属性并排除工厂快递配件运费扣款
This commit is contained in:
parent
3ad61407f0
commit
5ef5e17984
@ -9086,13 +9086,13 @@ class Pages extends Controller
|
||||
|
||||
fputs($csv, chr(0xEF) . chr(0xBB) . chr(0xBF));
|
||||
fputcsv($csv, [
|
||||
'ID', '快递公司代码', '快递公司名称', '外部编码', '杉橙快递代码', '运费打款方式',
|
||||
'ID', '快递公司代码', '快递公司名称', '快递属性', '外部编码', '杉橙快递代码', '运费打款方式',
|
||||
'是否启用', '可达服务', '是否快运', '自动寻号', '配货单号寻号', '数量拆单', '重量0寻号',
|
||||
'停运时间', '合同主体', '合同开始时间', '合同结束时间', '签订公司', '联系人', '联系电话', '自定义1', '自定义2', '扣款方式',
|
||||
...array_values(\App\Models\Business\CourierProfile::SHIPPING_FIELDS),
|
||||
'体积0寻号', '手工单号', '解密', '电子签章经办人', '最后修改',
|
||||
'入驻单号', '入驻状态', '入驻主体',
|
||||
...array_map(static fn (string $field): string => \App\Models\Business\CourierOnboarding::PROFILE_FIELDS[$field][0], \App\Business\CourierProfileData::APPENDED_PROFILE_FIELDS),
|
||||
...array_map(static fn (string $field): string => $field === 'courier_attribute' ? '入驻快递属性' : \App\Models\Business\CourierOnboarding::PROFILE_FIELDS[$field][0], \App\Business\CourierProfileData::APPENDED_PROFILE_FIELDS),
|
||||
'财务系统已修改字段',
|
||||
]);
|
||||
|
||||
@ -9119,6 +9119,7 @@ class Pages extends Controller
|
||||
$row->Id ?? '',
|
||||
$this->csvText($row->expcode ?? null),
|
||||
$this->csvText($row->expname ?? null),
|
||||
$this->csvText($row->exp_properties ?? null),
|
||||
$this->csvText($row->outcode ?? null),
|
||||
$this->csvText($row->scexpcode ?? null),
|
||||
$this->csvText($row->paymethod ?? null),
|
||||
|
||||
@ -97,6 +97,8 @@
|
||||
|
||||
## JianSun 旧业务库(jiansun)
|
||||
|
||||
快递资料列表与导出的“快递属性”直接读取现有 `js_wp_express.exp_properties`,与财务系统的“入驻快递属性”分别展示。供应商配件运费扣除明细复用该字段,属性为“工厂”的包裹不参与扣款;不新增上游数据集或改变原同步频率。
|
||||
|
||||
| 业务范围 | 上游对象 |
|
||||
| --- | --- |
|
||||
| 店铺收款账单旧来源(已停用) | `dbo.alipay_Bill_Detail` |
|
||||
|
||||
@ -8,6 +8,8 @@
|
||||
|
||||
未匹配商品、商品未维护供应商、未匹配供应商档案、联系人省缺失、供应商或省份冲突、运费无效,均列为待核实,扣款额为零。同一条形码的多条商品记录若供应商相同,或同一供应商多份档案的省份经上述归一后一致,只计算一笔运费。零运费列为不扣款。金额按整数分汇总,页面和导出口径一致。
|
||||
|
||||
快递属性取工作平台 `wp_express.exp_properties` 的现有共享镜像,按明细显示的快递名称(`express_name1`,为空时使用 `express_name2`)精确匹配 `expname`,不做名称包含搜索,不使用财务入驻属性代替。属性为“工厂”的包裹统一不扣款,金额为零,并保留商品、供应商和原始运费供核对;可扣款筛选与汇总、CSV 导出共同使用该规则。多个同名档案属性一致时只算一次,属性冲突时原可扣款记录改为待核实;空属性或未匹配快递沿用原有其余规则。快递镜像未完成首次同步或读取失败时,页面和导出拒绝返回不完整扣款结果。明细及导出增加“快递属性”列。
|
||||
|
||||
默认展示可扣款,可切换全部、不扣款、待核实;支持月份、交易单号、快递单号、供应商、处理后条形码、联系人省筛选及每页50条翻页。上方汇总统计当前文字筛选范围内全部状态。列设置支持隐藏、拖动排序、恢复默认,按用户和公司存于浏览器;CSV导出覆盖当前状态及筛选结果全部行,按可见列顺序导出,额外保留月份、发货记录ID和仓库供核对,长单号按文本保护并转义公式字符。
|
||||
|
||||
只读取现有共享镜像,不新增数据库表、不写回商品、供应商或发货数据,不自动进入供应商应付汇总或执行财务入账。页面与导出沿用供应商应付页级权限。
|
||||
|
||||
@ -21,14 +21,19 @@ class SupplierAccessoryFreightRepository
|
||||
{
|
||||
$productDataset = $this->datasets->get(ProductCatalogMirrorRepository::DATASET_KEY);
|
||||
$supplierDataset = $this->datasets->get(SupplierManagementMirrorRepository::DATASET);
|
||||
if (!$this->mirror->ready($productDataset) || !$this->mirror->ready($supplierDataset)) {
|
||||
throw new RuntimeException('商品或供应商资料尚未完成首次同步');
|
||||
$courierDataset = $this->datasets->get(CourierInformationMirrorRepository::DATASET_KEY);
|
||||
if (!$this->mirror->ready($productDataset) || !$this->mirror->ready($supplierDataset) || !$this->mirror->ready($courierDataset)) {
|
||||
throw new RuntimeException('商品、供应商或快递资料尚未完成首次同步');
|
||||
}
|
||||
$db = $this->mirror->connection();
|
||||
// 供应商档案数量较小,一次读取,批量商品查询避免逐单访问数据库。
|
||||
$suppliers = $db->table($supplierDataset->targetTable())->get(['scmname', 'linkerprovience'])
|
||||
->groupBy(static fn ($row) => trim((string) $row->scmname))
|
||||
->map(static fn ($group) => $group->map(static fn ($row) => (array) $row)->all());
|
||||
// 快递资料约 1,900 条,仅读取名称和原始属性;同名候选保留供规则核实,不逐单查询。
|
||||
$couriers = $db->table($courierDataset->targetTable())->get(['expname', 'exp_properties'])
|
||||
->groupBy(static fn ($row) => trim((string) $row->expname))
|
||||
->map(static fn ($group) => $group->map(static fn ($row) => (array) $row)->all());
|
||||
$start = \Carbon\Carbon::createFromFormat('!Y-m', $month);
|
||||
foreach ($this->shipping->accessoryFreightBatches($start->format('Y-m-d'), $start->copy()->addMonth()->format('Y-m-d')) as $batch) {
|
||||
$barcodes = array_values(array_unique(array_filter(array_map(static fn ($row) => AccessoryReshipMatcher::barcode((string) ($row['barcode'] ?? '')), $batch), static fn ($value) => $value !== '')));
|
||||
@ -39,7 +44,8 @@ class SupplierAccessoryFreightRepository
|
||||
$barcode = AccessoryReshipMatcher::barcode((string) ($row['barcode'] ?? ''));
|
||||
$candidates = $products->get($barcode, []);
|
||||
$supplierName = trim((string) ($candidates[0]['supplier_name'] ?? ''));
|
||||
yield $this->matcher->match($row, $candidates, $suppliers->get($supplierName, []));
|
||||
$courierName = trim((string) ($row['express_name1'] ?? '')) ?: trim((string) ($row['express_name2'] ?? ''));
|
||||
yield $this->matcher->match($row, $candidates, $suppliers->get($supplierName, []), $couriers->get($courierName, []));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,15 +6,26 @@ class SupplierAccessoryFreightMatcher
|
||||
{
|
||||
public const STATES = ['ready' => '可扣款', 'excluded' => '不扣款', 'pending' => '待核实'];
|
||||
|
||||
public function match(array $row, array $products, array $suppliers): array
|
||||
public function match(array $row, array $products, array $suppliers, array $couriers = []): array
|
||||
{
|
||||
$result = $this->matchSupplier($row, $products, $suppliers);
|
||||
$attributes = array_values(array_unique(array_map(static fn ($courier) => trim((string) ($courier['exp_properties'] ?? '')), $couriers)));
|
||||
$result['courier_attribute'] = implode(' / ', array_filter($attributes, static fn ($value) => $value !== ''));
|
||||
foreach (['express_name1', 'express_name2'] as $field) {
|
||||
if (trim((string) ($row[$field] ?? '')) !== '外采快递') continue;
|
||||
$result['state'] = 'excluded';
|
||||
$result['deduction_cents'] = 0;
|
||||
$result['reason'] = '外采快递不扣配件运费';
|
||||
break;
|
||||
return $result;
|
||||
}
|
||||
if ($attributes === ['工厂']) {
|
||||
$result['state'] = 'excluded';
|
||||
$result['deduction_cents'] = 0;
|
||||
$result['reason'] = '快递属性为工厂,不扣配件运费';
|
||||
} elseif (count($attributes) > 1 && $result['state'] === 'ready') {
|
||||
$result['state'] = 'pending';
|
||||
$result['deduction_cents'] = 0;
|
||||
$result['reason'] = '同名快递属性冲突,需核实';
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ class SupplierAccessoryFreightPageData
|
||||
{
|
||||
public const TITLE = '新河北仓、曹县仓配件运费扣除明细';
|
||||
public const TEXT_FILTERS = ['trade_no' => '交易单号', 'express_no' => '快递单号', 'supplier_name' => '供应商', 'normalized_barcode' => '处理后条形码', 'province' => '联系人省'];
|
||||
public const COLUMNS = ['state' => '扣款状态', 'trade_no' => '交易单号', 'express_no' => '快递单号', 'courier' => '快递名称', 'ship_time' => '发货时间', 'barcode' => '原始条形码', 'normalized_barcode' => '处理后条形码', 'product_name' => '商品名称', 'supplier_name' => '供应商', 'province' => '联系人省', 'freight' => '配件运费(元)', 'deduction' => '扣款金额(元)', 'reason' => '说明'];
|
||||
public const COLUMNS = ['state' => '扣款状态', 'trade_no' => '交易单号', 'express_no' => '快递单号', 'courier' => '快递名称', 'courier_attribute' => '快递属性', 'ship_time' => '发货时间', 'barcode' => '原始条形码', 'normalized_barcode' => '处理后条形码', 'product_name' => '商品名称', 'supplier_name' => '供应商', 'province' => '联系人省', 'freight' => '配件运费(元)', 'deduction' => '扣款金额(元)', 'reason' => '说明'];
|
||||
|
||||
public function exportColumns(): array
|
||||
{
|
||||
@ -69,7 +69,7 @@ class SupplierAccessoryFreightPageData
|
||||
}
|
||||
} catch (\Throwable $exception) {
|
||||
report($exception);
|
||||
$error = '发货、商品或供应商资料暂时无法读取,或尚未完成同步,请稍后重试。';
|
||||
$error = '发货、商品、供应商或快递资料暂时无法读取,或尚未完成同步,请稍后重试。';
|
||||
$summary = array_fill_keys(array_keys($summary), 0);
|
||||
$items = [];
|
||||
$total = 0;
|
||||
|
||||
@ -502,12 +502,12 @@
|
||||
<table class="courier-information-table" aria-label="快递资料">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th><th>快递公司代码</th><th>快递公司名称</th><th>外部编码</th><th>杉橙快递代码</th><th>运费打款方式</th>
|
||||
<th>ID</th><th>快递公司代码</th><th>快递公司名称</th><th title="工作平台快递资料中的属性">快递属性</th><th>外部编码</th><th>杉橙快递代码</th><th>运费打款方式</th>
|
||||
<th>是否启用</th><th>可达服务</th><th>是否快运</th><th>自动寻号</th><th>配货单号寻号</th><th>数量拆单</th><th>重量0寻号</th>
|
||||
<th>停运时间</th><th title="合作合同的乙方">合同主体</th><th>合同开始时间</th><th>合同结束时间</th><th title="合作合同的甲方">签订公司</th><th>联系人</th><th>联系电话</th><th>自定义1</th><th>自定义2</th><th>扣款方式</th>
|
||||
@foreach (\App\Models\Business\CourierProfile::SHIPPING_FIELDS as $shippingLabel)<th>{{ $shippingLabel }}</th>@endforeach
|
||||
<th>体积0寻号</th><th>手工单号</th><th>解密</th><th>电子签章经办人</th><th>最后修改</th>
|
||||
<th class="is-onboarding">入驻单号</th><th class="is-onboarding">入驻状态</th><th class="is-onboarding">ERP 开通</th><th class="is-onboarding">入驻主体</th>@foreach (\App\Business\CourierProfileData::APPENDED_PROFILE_FIELDS as $profileField)<th class="is-onboarding">{{ \App\Models\Business\CourierOnboarding::PROFILE_FIELDS[$profileField][0] }}</th>@endforeach
|
||||
<th class="is-onboarding">入驻单号</th><th class="is-onboarding">入驻状态</th><th class="is-onboarding">ERP 开通</th><th class="is-onboarding">入驻主体</th>@foreach (\App\Business\CourierProfileData::APPENDED_PROFILE_FIELDS as $profileField)<th class="is-onboarding">{{ $profileField === 'courier_attribute' ? '入驻快递属性' : \App\Models\Business\CourierOnboarding::PROFILE_FIELDS[$profileField][0] }}</th>@endforeach
|
||||
<th class="is-onboarding">证照</th><th class="is-onboarding">生效报价</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -531,6 +531,7 @@
|
||||
@endif
|
||||
</td>
|
||||
<td class="is-clamped {{ $cell('expname') }}" title="{{ $row->expname ?? '' }}"><strong>{{ $row->expname ?? '-' }}</strong></td>
|
||||
<td>{{ filled($row->exp_properties ?? null) ? $row->exp_properties : '-' }}</td>
|
||||
<td class="is-code">{{ $row->outcode ?? '-' }}</td>
|
||||
<td class="is-code">{{ $row->scexpcode ?? '-' }}</td>
|
||||
<td class="{{ $cell('paymethod') }}">{{ $row->paymethod ?? '-' }}</td>
|
||||
@ -562,7 +563,7 @@
|
||||
@include('business.pages.courier-payables.partials.courier-onboarding-cells', ['info' => $row->_info ?? null, 'platformName' => $row->expname ?? null, 'platformCode' => $row->expcode ?? null])
|
||||
</tr>
|
||||
@empty
|
||||
<tr><td colspan="{{ 44 + count(\App\Models\Business\CourierProfile::SHIPPING_FIELDS) }}" class="courier-information-empty">{{ $courierError ? '数据暂时不可用。' : '当前筛选条件下没有快递资料。' }}</td></tr>
|
||||
<tr><td colspan="{{ 45 + count(\App\Models\Business\CourierProfile::SHIPPING_FIELDS) }}" class="courier-information-empty">{{ $courierError ? '数据暂时不可用。' : '当前筛选条件下没有快递资料。' }}</td></tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
@ -21,16 +21,16 @@
|
||||
<div><span>待核实</span><strong>{{ number_format($freightSummary['pending']) }}</strong></div>
|
||||
<div><span>可扣运费合计(元)</span><strong>{{ number_format($freightSummary['amount'] / 100, 2) }}</strong></div>
|
||||
</div>
|
||||
<details class="sf-rules"><summary>扣款规则与金额口径</summary><p>仅取所选月份仓库为“常州简尚家居有限公司”的发货包裹。取第一个逗号前的条形码,再去掉最后一个“-”及其后缀,用处理后的条形码匹配商品资料条形码,再按商品供应商名称匹配供应商管理。联系人省为山东、山东省、河北、河北省的供应商,扣除对应包裹全部运费。每个发货包裹只计一次;不需要匹配首发单。外采快递不扣运费;其他省份不扣,未匹配、资料缺失、供应商或省份冲突、运费异常的记录待核实。此处展示扣除明细,不自动入账。</p></details>
|
||||
<details class="sf-rules"><summary>扣款规则与金额口径</summary><p>仅取所选月份仓库为“常州简尚家居有限公司”的发货包裹。取第一个逗号前的条形码,再去掉最后一个“-”及其后缀,用处理后的条形码匹配商品资料条形码,再按商品供应商名称匹配供应商管理。联系人省为山东、山东省、河北、河北省的供应商,扣除对应包裹全部运费。每个发货包裹只计一次;不需要匹配首发单。外采快递不扣运费;按快递名称匹配工作平台快递资料,快递属性为“工厂”的包裹不扣运费。同名快递属性冲突时待核实;属性为空或未匹配时沿用其余规则。其他省份不扣,未匹配、资料缺失、供应商或省份冲突、运费异常的记录待核实。此处展示扣除明细,不自动入账。</p></details>
|
||||
@if($freightError)<div class="sf-error" role="alert">{{ $freightError }}</div>@endif
|
||||
<section class="sf-panel" aria-label="配件运费扣除明细">
|
||||
<div class="sf-table-scroll"><table><thead><tr>
|
||||
@foreach(\Modules\EcommerceFinance\View\SupplierAccessoryFreightPageData::COLUMNS as $key => $column)<th data-column-key="{{ $key }}">{{ $column }}</th>@endforeach
|
||||
</tr></thead><tbody>
|
||||
@forelse($freightRows as $row)
|
||||
<tr><td><span class="sf-status {{ $row['state'] }}">{{ $states[$row['state']] }}</span></td><td>{{ $row['trade_no'] ?: '—' }}</td><td>{{ $row['express_no'] ?: '—' }}</td><td>{{ ($row['express_name1'] ?? '') ?: ($row['express_name2'] ?? '') ?: '—' }}</td><td>{{ $row['ship_time'] }}</td><td class="sf-barcode">{{ $row['barcode'] ?: '—' }}</td><td class="sf-barcode">{{ $row['normalized_barcode'] ?: '—' }}</td><td>{{ $row['product_name'] ?: '—' }}</td><td>{{ $row['supplier_name'] ?: '—' }}</td><td>{{ $row['province'] ?: '—' }}</td><td class="sf-money">{{ $row['freight_cents'] === null ? '待核实' : number_format($row['freight_cents'] / 100, 2) }}</td><td class="sf-money">{{ number_format($row['deduction_cents'] / 100, 2) }}</td><td>{{ $row['reason'] }}</td></tr>
|
||||
<tr><td><span class="sf-status {{ $row['state'] }}">{{ $states[$row['state']] }}</span></td><td>{{ $row['trade_no'] ?: '—' }}</td><td>{{ $row['express_no'] ?: '—' }}</td><td>{{ ($row['express_name1'] ?? '') ?: ($row['express_name2'] ?? '') ?: '—' }}</td><td>{{ $row['courier_attribute'] ?? '' ?: '—' }}</td><td>{{ $row['ship_time'] }}</td><td class="sf-barcode">{{ $row['barcode'] ?: '—' }}</td><td class="sf-barcode">{{ $row['normalized_barcode'] ?: '—' }}</td><td>{{ $row['product_name'] ?: '—' }}</td><td>{{ $row['supplier_name'] ?: '—' }}</td><td>{{ $row['province'] ?: '—' }}</td><td class="sf-money">{{ $row['freight_cents'] === null ? '待核实' : number_format($row['freight_cents'] / 100, 2) }}</td><td class="sf-money">{{ number_format($row['deduction_cents'] / 100, 2) }}</td><td>{{ $row['reason'] }}</td></tr>
|
||||
@empty
|
||||
<tr><td colspan="13" class="sf-empty">{{ $freightError ?: '当前筛选条件下暂无记录,请调整月份、状态或筛选条件。' }}</td></tr>
|
||||
<tr><td colspan="{{ count(\Modules\EcommerceFinance\View\SupplierAccessoryFreightPageData::COLUMNS) }}" class="sf-empty">{{ $freightError ?: '当前筛选条件下暂无记录,请调整月份、状态或筛选条件。' }}</td></tr>
|
||||
@endforelse
|
||||
</tbody></table></div>
|
||||
<div class="sf-footer">当前状态共 {{ number_format($freightRows->total()) }} 条,每页50条。上方汇总包含当前文字筛选范围内的全部状态。{{ $freightRows->links() }}</div>
|
||||
|
||||
@ -68,6 +68,7 @@ class CourierInformationPageTest extends FeatureTestCase
|
||||
'Id' => 1,
|
||||
'expcode' => 'SF',
|
||||
'expname' => '顺丰速运',
|
||||
'exp_properties' => '工厂',
|
||||
'status' => 1,
|
||||
'tradebody' => '乙方顺丰物流有限公司',
|
||||
'signcom' => '甲方商贸有限公司',
|
||||
@ -88,6 +89,8 @@ class CourierInformationPageTest extends FeatureTestCase
|
||||
->assertOk()
|
||||
->assertSeeText('顺丰速运')
|
||||
->assertSeeText('SF')
|
||||
->assertSeeText('快递属性')->assertSeeText('工厂')
|
||||
->assertSeeText('入驻快递属性')
|
||||
->assertSeeText('同步正常')
|
||||
->assertSeeText('可达服务')
|
||||
->assertSeeText('合同主体')->assertSeeText('乙方顺丰物流有限公司')
|
||||
@ -110,6 +113,7 @@ class CourierInformationPageTest extends FeatureTestCase
|
||||
$repository->shouldReceive('exportRows')->once()->andReturnUsing(static function (): \Generator {
|
||||
yield (object) [
|
||||
'Id' => 1, 'expcode' => 'EXP-1', 'expname' => '导出快递简称',
|
||||
'exp_properties' => '=工厂',
|
||||
'tradebody' => '导出乙方有限公司', 'signcom' => '=甲方公式样式名称',
|
||||
];
|
||||
});
|
||||
@ -121,5 +125,7 @@ class CourierInformationPageTest extends FeatureTestCase
|
||||
$this->assertSame('导出乙方有限公司', $row['合同主体']);
|
||||
$this->assertSame("'=甲方公式样式名称", $row['签订公司']);
|
||||
$this->assertSame('导出快递简称', $row['快递公司名称']);
|
||||
$this->assertSame("'=工厂", $row['快递属性']);
|
||||
$this->assertSame('', $row['入驻快递属性']);
|
||||
}
|
||||
}
|
||||
|
||||
@ -9,6 +9,7 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use Modules\EcommerceFinance\Contracts\BusinessMirrorDataset;
|
||||
use Modules\EcommerceFinance\Repositories\GenericBusinessMirrorRepository;
|
||||
use Modules\EcommerceFinance\Repositories\CourierInformationMirrorRepository;
|
||||
use Modules\EcommerceFinance\Repositories\ProductCatalogMirrorRepository;
|
||||
use Modules\EcommerceFinance\Repositories\ShippingOrderRepository;
|
||||
use Modules\EcommerceFinance\Repositories\SupplierAccessoryFreightRepository;
|
||||
@ -91,6 +92,38 @@ class SupplierAccessoryFreightTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_factory_attribute_exempts_freight_even_when_other_details_are_missing(): void
|
||||
{
|
||||
$matcher = new SupplierAccessoryFreightMatcher;
|
||||
foreach (['12.35', '0', null] as $freight) {
|
||||
foreach ([[], [['name' => '成品', 'supplier_name' => '甲']]] as $products) {
|
||||
$row = $matcher->match($this->row(['freight' => $freight]), $products, [['linkerprovience' => '河北省']], [
|
||||
['exp_properties' => ' 工厂 '], ['exp_properties' => '工厂'],
|
||||
]);
|
||||
$this->assertSame('excluded', $row['state']);
|
||||
$this->assertSame(0, $row['deduction_cents']);
|
||||
$this->assertSame('工厂', $row['courier_attribute']);
|
||||
$this->assertSame('快递属性为工厂,不扣配件运费', $row['reason']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function test_other_attributes_keep_existing_rules_and_conflicting_attributes_require_review(): void
|
||||
{
|
||||
$matcher = new SupplierAccessoryFreightMatcher;
|
||||
$products = [['name' => '成品', 'supplier_name' => '甲']];
|
||||
$suppliers = [['linkerprovience' => '山东']];
|
||||
foreach ([[], [['exp_properties' => '']], [['exp_properties' => '简尚']]] as $couriers) {
|
||||
$row = $matcher->match($this->row(), $products, $suppliers, $couriers);
|
||||
$this->assertSame('ready', $row['state']);
|
||||
$this->assertSame(1235, $row['deduction_cents']);
|
||||
}
|
||||
$row = $matcher->match($this->row(), $products, $suppliers, [['exp_properties' => '工厂'], ['exp_properties' => '简尚']]);
|
||||
$this->assertSame('pending', $row['state']);
|
||||
$this->assertSame(0, $row['deduction_cents']);
|
||||
$this->assertSame('同名快递属性冲突,需核实', $row['reason']);
|
||||
}
|
||||
|
||||
public function test_other_provinces_zero_invalid_and_equivalent_duplicate_provinces(): void
|
||||
{
|
||||
$matcher = new SupplierAccessoryFreightMatcher;
|
||||
@ -117,13 +150,19 @@ class SupplierAccessoryFreightTest extends TestCase
|
||||
$connection = app('db')->connection();
|
||||
$connection->statement('CREATE TABLE products (sku_id TEXT, sku_type TEXT, name TEXT, supplier_name TEXT)');
|
||||
$connection->statement('CREATE TABLE suppliers (scmname TEXT, linkerprovience TEXT)');
|
||||
$connection->statement('CREATE TABLE couriers (expname TEXT, exp_properties TEXT)');
|
||||
$connection->table('couriers')->insert([
|
||||
['expname' => '工厂快递', 'exp_properties' => '工厂'],
|
||||
['expname' => '补发快递', 'exp_properties' => '简尚'],
|
||||
['expname' => '补发快递-其他', 'exp_properties' => '工厂'],
|
||||
]);
|
||||
$connection->table('products')->insert([
|
||||
['sku_id' => 'GBGJ-SJ038024N1410V02', 'sku_type' => 'normal', 'name' => '成品', 'supplier_name' => '商品供应商'],
|
||||
['sku_id' => 'GBGJ-SJ038024N1410V02', 'sku_type' => 'combine', 'name' => '组合', 'supplier_name' => '其他供应商'],
|
||||
]);
|
||||
$connection->table('suppliers')->insert(['scmname' => '商品供应商', 'linkerprovience' => '河北省']);
|
||||
$registry = Mockery::mock(BusinessMirrorDatasetRegistry::class);
|
||||
foreach ([ProductCatalogMirrorRepository::DATASET_KEY => 'products', SupplierManagementMirrorRepository::DATASET => 'suppliers'] as $key => $table) {
|
||||
foreach ([ProductCatalogMirrorRepository::DATASET_KEY => 'products', SupplierManagementMirrorRepository::DATASET => 'suppliers', CourierInformationMirrorRepository::DATASET_KEY => 'couriers'] as $key => $table) {
|
||||
$dataset = Mockery::mock(BusinessMirrorDataset::class);
|
||||
$dataset->shouldReceive('targetTable')->andReturn($table);
|
||||
$registry->shouldReceive('get')->with($key)->andReturn($dataset);
|
||||
@ -132,12 +171,25 @@ class SupplierAccessoryFreightTest extends TestCase
|
||||
$mirror->shouldReceive('ready')->andReturnTrue();
|
||||
$mirror->shouldReceive('connection')->andReturn($connection);
|
||||
$shipping = Mockery::mock(ShippingOrderRepository::class);
|
||||
$shipping->shouldReceive('accessoryFreightBatches')->once()->with('2026-09-01', '2026-10-01')->andReturn((function () { yield [$this->row(['supplier_name' => '错误的历史供应商'])]; })());
|
||||
$shipping->shouldReceive('accessoryFreightBatches')->once()->with('2026-09-01', '2026-10-01')->andReturn((function () {
|
||||
yield [$this->row(['supplier_name' => '错误的历史供应商']),
|
||||
$this->row(['express_name1' => '工厂快递']),
|
||||
$this->row(['express_name1' => '', 'express_name2' => '工厂快递']),
|
||||
$this->row(['express_name1' => '补发快递', 'express_name2' => '工厂快递'])];
|
||||
})());
|
||||
$repo = new SupplierAccessoryFreightRepository($shipping, $registry, $mirror, new SupplierAccessoryFreightMatcher);
|
||||
$rows = iterator_to_array($repo->rows('2026-09'));
|
||||
$this->assertCount(1, $rows);
|
||||
$this->assertCount(4, $rows);
|
||||
$this->assertSame('商品供应商', $rows[0]['supplier_name']);
|
||||
$this->assertSame(1235, $rows[0]['deduction_cents']);
|
||||
$this->assertSame('简尚', $rows[0]['courier_attribute']);
|
||||
foreach ([1, 2] as $index) {
|
||||
$this->assertSame('工厂', $rows[$index]['courier_attribute']);
|
||||
$this->assertSame('excluded', $rows[$index]['state']);
|
||||
$this->assertSame(0, $rows[$index]['deduction_cents']);
|
||||
}
|
||||
$this->assertSame('ready', $rows[3]['state']);
|
||||
$this->assertSame('简尚', $rows[3]['courier_attribute']);
|
||||
}
|
||||
|
||||
private function data(): SupplierAccessoryFreightPageData
|
||||
@ -151,6 +203,52 @@ class SupplierAccessoryFreightTest extends TestCase
|
||||
return new SupplierAccessoryFreightPageData($repository);
|
||||
}
|
||||
|
||||
public function test_factory_rows_are_zero_in_summary_ready_filter_and_csv(): void
|
||||
{
|
||||
$repository = Mockery::mock(SupplierAccessoryFreightRepository::class);
|
||||
$repository->shouldReceive('rows')->with('2026-09')->andReturnUsing(function () {
|
||||
$matcher = new SupplierAccessoryFreightMatcher;
|
||||
foreach (['工厂', '简尚'] as $attribute) {
|
||||
yield $matcher->match($this->row(['express_no' => $attribute === '工厂' ? 'FACTORY-1' : 'NORMAL-1']),
|
||||
[['name' => '成品', 'supplier_name' => '甲']], [['linkerprovience' => '河北']], [['exp_properties' => $attribute]]);
|
||||
}
|
||||
});
|
||||
$data = new SupplierAccessoryFreightPageData($repository);
|
||||
app()->instance('request', Request::create('/?month=2026-09&state=ready'));
|
||||
$page = $data->page();
|
||||
$this->assertSame(['all' => 2, 'ready' => 1, 'excluded' => 1, 'pending' => 0, 'amount' => 1235], $page['freightSummary']);
|
||||
$this->assertCount(1, $page['freightRows']);
|
||||
$this->assertSame('NORMAL-1', $page['freightRows']->items()[0]['express_no']);
|
||||
$controller = new \App\Http\Controllers\Business\SupplierAccessoryFreight;
|
||||
$response = $controller->export($data);
|
||||
ob_start(); $response->sendContent(); $csv = ob_get_clean();
|
||||
$this->assertStringNotContainsString('FACTORY-1', $csv);
|
||||
app()->instance('request', Request::create('/?month=2026-09&state=excluded&columns=express_no,courier_attribute,deduction,reason'));
|
||||
$response = $controller->export($data);
|
||||
ob_start(); $response->sendContent(); $csv = ob_get_clean();
|
||||
$lines = explode("\n", trim(substr($csv, 3)));
|
||||
$this->assertCount(2, $lines);
|
||||
$this->assertSame(['FACTORY-1', '工厂', '0.00', '快递属性为工厂,不扣配件运费'], array_slice(str_getcsv($lines[1]), 3));
|
||||
}
|
||||
|
||||
public function test_unready_courier_mirror_does_not_produce_deductions(): void
|
||||
{
|
||||
$registry = Mockery::mock(BusinessMirrorDatasetRegistry::class);
|
||||
foreach ([ProductCatalogMirrorRepository::DATASET_KEY, SupplierManagementMirrorRepository::DATASET, CourierInformationMirrorRepository::DATASET_KEY] as $key) {
|
||||
$dataset = Mockery::mock(BusinessMirrorDataset::class);
|
||||
$registry->shouldReceive('get')->with($key)->andReturn($dataset);
|
||||
$datasets[$key] = $dataset;
|
||||
}
|
||||
$mirror = Mockery::mock(GenericBusinessMirrorRepository::class);
|
||||
foreach ($datasets as $key => $dataset) $mirror->shouldReceive('ready')->with($dataset)->andReturn($key !== CourierInformationMirrorRepository::DATASET_KEY);
|
||||
$mirror->shouldNotReceive('connection');
|
||||
$shipping = Mockery::mock(ShippingOrderRepository::class);
|
||||
$shipping->shouldNotReceive('accessoryFreightBatches');
|
||||
$this->expectException(\RuntimeException::class);
|
||||
$this->expectExceptionMessage('商品、供应商或快递资料尚未完成首次同步');
|
||||
iterator_to_array((new SupplierAccessoryFreightRepository($shipping, $registry, $mirror, new SupplierAccessoryFreightMatcher))->rows('2026-09'));
|
||||
}
|
||||
|
||||
public function test_summary_pagination_and_filters_use_full_month_without_multiplying_amount(): void
|
||||
{
|
||||
app()->instance('request', Request::create('/?month=2026-09&state=all&page=2'));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user