fix(顾家对账): 修复数字订单号收货匹配索引失效 (#1279)
数字订单号保持字符串绑定,避免 varchar 索引隐式数值转换;补充回归测试。
This commit is contained in:
parent
039a366717
commit
2ea6326bdf
@ -499,13 +499,16 @@ class KukaReconciliationPageData
|
||||
$tokens = [];
|
||||
foreach ($sourceRows as $source) {
|
||||
foreach ($this->orderTokens($source['values']) as $token) {
|
||||
$tokens[$token] = true;
|
||||
// 保留字符串类型;数字订单号不能作为数组键,否则会变成整数,
|
||||
// MySQL 与 varchar 索引比较时发生隐式数值转换并触发全表扫描。
|
||||
$tokens[] = $token;
|
||||
}
|
||||
}
|
||||
$tokens = array_values(array_unique($tokens));
|
||||
|
||||
$lookup = [];
|
||||
$connection = $this->databases->connection($connectionName);
|
||||
foreach (array_chunk(array_keys($tokens), 400) as $chunk) {
|
||||
foreach (array_chunk($tokens, 400) as $chunk) {
|
||||
$rows = $connection->table('jst_oms_shipping')
|
||||
->whereIn('trade_no', $chunk)
|
||||
->get([
|
||||
|
||||
@ -72,12 +72,14 @@ class KukaReconciliationPageDataTest extends TestCase
|
||||
public function test_builds_rule_based_rows_for_each_reconciliation_view(): void
|
||||
{
|
||||
$connection = DB::connection('business_mirror');
|
||||
$connection->enableQueryLog();
|
||||
$numericOrderNo = '3317157192129049568';
|
||||
$connection->table('kuka_posting_base_imports')->insert([
|
||||
'company_id' => 1,
|
||||
'period' => '2026-10',
|
||||
'completed_at' => '2026-11-01 08:00:00',
|
||||
]);
|
||||
$this->insertBaseRow(2, $this->payload('O-1', 'P-1', 'S-1', 'I-1', 'M-1', '2', '10.00'));
|
||||
$this->insertBaseRow(2, $this->payload($numericOrderNo, 'P-1', 'S-1', 'I-1', 'M-1', '2', '10.00'));
|
||||
$this->insertBaseRow(3, $this->payload('O-2', 'P-2', 'S-2', 'I-2', 'M-1', '1', '10.00'));
|
||||
$this->insertBaseRow(4, $this->payload('O-3', 'P-3', 'S-3', 'I-3', 'M-2', '', ''));
|
||||
$this->insertBaseRow(5, $this->payload('O-4', 'P-4', 'S-4', 'I-4', '', '1', '10.00'));
|
||||
@ -90,7 +92,7 @@ class KukaReconciliationPageDataTest extends TestCase
|
||||
]);
|
||||
$connection->table('jst_oms_shipping')->insert([
|
||||
[
|
||||
'trade_no' => 'O-1',
|
||||
'trade_no' => $numericOrderNo,
|
||||
'barcode' => 'P-1',
|
||||
'product_code' => 'S-1',
|
||||
'receiver_name' => '张三',
|
||||
@ -143,6 +145,15 @@ class KukaReconciliationPageDataTest extends TestCase
|
||||
$this->assertSame('33.33', $data['summary']['sales_amount_total']);
|
||||
$this->assertSame(2, $data['summary']['shipping_matched_rows']);
|
||||
$this->assertSame(1, $data['summary']['receiver_phone_rows']);
|
||||
$shippingBindings = [];
|
||||
foreach ($connection->getQueryLog() as $query) {
|
||||
if (! str_contains((string) $query['query'], 'jst_oms_shipping')) {
|
||||
continue;
|
||||
}
|
||||
$shippingBindings = array_merge($shippingBindings, $query['bindings']);
|
||||
}
|
||||
$this->assertContains($numericOrderNo, $shippingBindings, true);
|
||||
$this->assertNotContains((int) $numericOrderNo, $shippingBindings, true);
|
||||
|
||||
$this->assertSame([[
|
||||
'2026', '10', 'M-1', '测试物料', '3.0000', '10.00', '30.00',
|
||||
@ -157,8 +168,8 @@ class KukaReconciliationPageDataTest extends TestCase
|
||||
$this->assertSame('22.22', $virtual[9]);
|
||||
$this->assertSame('常州欧伯娜家居有限公司', $virtual[10]);
|
||||
$this->assertSame('435421', $virtual[11]);
|
||||
$this->assertSame('O-1', $virtual[12]);
|
||||
$this->assertSame('INTERNAL-1', $virtual[13]);
|
||||
$this->assertSame($numericOrderNo, $virtual[12]);
|
||||
$this->assertSame('INTERNAL-8', $virtual[13]);
|
||||
$this->assertSame('EXPRESS-1', $virtual[14]);
|
||||
|
||||
$erp = $data['views']['erp-product-import']['rows'][0];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user