添加市场
This commit is contained in:
@@ -108,12 +108,14 @@ class ExportTest extends ProcurementTestCase
|
||||
'cost_price' => '5.00',
|
||||
'spec' => '10斤/箱',
|
||||
'supplier_id' => $supplierA->id,
|
||||
'market' => '新发地',
|
||||
]);
|
||||
$meat = ProductModel::factory()->create([
|
||||
'status' => ProductModel::STATUS_ON,
|
||||
'cost_price' => '20.00',
|
||||
'spec' => '20斤/箱',
|
||||
'supplier_id' => $supplierB->id,
|
||||
'market' => '岳各庄',
|
||||
]);
|
||||
|
||||
$this->actingAsMiniStore($storeA);
|
||||
@@ -154,24 +156,25 @@ class ExportTest extends ProcurementTestCase
|
||||
if ($rows->count() !== 8) {
|
||||
return false;
|
||||
}
|
||||
// 列头含参考零售价与门店列
|
||||
// 列头含市场/参考零售价与门店列(市场列在供应商后,门店列从索引 12 起)
|
||||
$header = $rows[3];
|
||||
if ($header[7] !== '参考零售价' || $header[11] !== $storeA->name || $header[12] !== $storeB->name) {
|
||||
if ($header[4] !== '市场' || $header[8] !== '参考零售价' || $header[12] !== $storeA->name || $header[13] !== $storeB->name) {
|
||||
return false;
|
||||
}
|
||||
// 蔬菜行:数量 2+3=5、金额 25、参考零售价 5÷10=0.50、门店列 2/3
|
||||
// 蔬菜行:市场 新发地、数量 2+3=5、金额 25、参考零售价 5÷10=0.50、门店列 2/3
|
||||
$vegRow = $rows->firstWhere(2, $veg->name);
|
||||
if ($vegRow === null
|
||||
|| (float) $vegRow[8] !== 5.0 || (float) $vegRow[10] !== 25.0
|
||||
|| (float) $vegRow[7] !== 0.5
|
||||
|| (float) $vegRow[11] !== 2.0 || (float) $vegRow[12] !== 3.0) {
|
||||
|| $vegRow[4] !== '新发地'
|
||||
|| (float) $vegRow[9] !== 5.0 || (float) $vegRow[11] !== 25.0
|
||||
|| (float) $vegRow[8] !== 0.5
|
||||
|| (float) $vegRow[12] !== 2.0 || (float) $vegRow[13] !== 3.0) {
|
||||
return false;
|
||||
}
|
||||
// 无订货商品行:数量 0、参考零售价留空、门店列 0
|
||||
$extraRow = $rows->firstWhere(2, $extra->name);
|
||||
if ($extraRow === null
|
||||
|| (float) $extraRow[8] !== 0.0 || $extraRow[7] !== ''
|
||||
|| (float) $extraRow[11] !== 0.0) {
|
||||
|| (float) $extraRow[9] !== 0.0 || $extraRow[8] !== ''
|
||||
|| (float) $extraRow[12] !== 0.0) {
|
||||
return false;
|
||||
}
|
||||
// 合计行:总数量 6、总金额 45、门店列合计 3/3
|
||||
@@ -179,8 +182,8 @@ class ExportTest extends ProcurementTestCase
|
||||
if ($total[2] !== '合计') {
|
||||
return false;
|
||||
}
|
||||
return (float) $total[8] === 6.0 && (float) $total[10] === 45.0
|
||||
&& (float) $total[11] === 3.0 && (float) $total[12] === 3.0;
|
||||
return (float) $total[9] === 6.0 && (float) $total[11] === 45.0
|
||||
&& (float) $total[12] === 3.0 && (float) $total[13] === 3.0;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -234,12 +237,12 @@ class ExportTest extends ProcurementTestCase
|
||||
if ($rows->count() !== 6) {
|
||||
return false;
|
||||
}
|
||||
if ($rows[2] !== ['序号', '品名', '包规', '单位', '单价', '数量', '重量(斤)', '预计金额']) {
|
||||
if ($rows[2] !== ['序号', '品名', '市场', '包规', '单位', '单价', '数量', '重量(斤)', '预计金额']) {
|
||||
return false;
|
||||
}
|
||||
// 合计:数量 2+1=3,金额 10+20=30
|
||||
$total = $rows->last();
|
||||
return $total[1] === '合计' && (int) $total[5] === 3 && (float) $total[7] === 30.0;
|
||||
return $total[1] === '合计' && (int) $total[6] === 3 && (float) $total[8] === 30.0;
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -294,23 +297,23 @@ class ExportTest extends ProcurementTestCase
|
||||
if ($titles !== [$supplierA->name, $supplierB->name]) {
|
||||
return false;
|
||||
}
|
||||
// 供应商甲:蔬菜 2+3=5 件、金额 5×5=25
|
||||
// 供应商甲:蔬菜 2+3=5 件、金额 5×5=25(市场列在品名后)
|
||||
$rowsA = $sheets[0]->collection()->values();
|
||||
if ($rowsA[2] !== ['序号', '品名', '包规', '单位', '成本价', '数量', '重量(斤)', '金额']) {
|
||||
if ($rowsA[2] !== ['序号', '品名', '市场', '包规', '单位', '成本价', '数量', '重量(斤)', '金额']) {
|
||||
return false;
|
||||
}
|
||||
$vegRow = $rowsA->firstWhere(1, $veg->name);
|
||||
if ($vegRow === null || (int) $vegRow[5] !== 5 || (float) $vegRow[7] !== 25.0) {
|
||||
if ($vegRow === null || $vegRow[2] !== '新发地' || (int) $vegRow[6] !== 5 || (float) $vegRow[8] !== 25.0) {
|
||||
return false;
|
||||
}
|
||||
$totalA = $rowsA->last();
|
||||
if ($totalA[1] !== '合计' || (int) $totalA[5] !== 5 || (float) $totalA[7] !== 25.0) {
|
||||
if ($totalA[1] !== '合计' || (int) $totalA[6] !== 5 || (float) $totalA[8] !== 25.0) {
|
||||
return false;
|
||||
}
|
||||
// 供应商乙:肉 1 件、金额 20
|
||||
$rowsB = $sheets[1]->collection()->values();
|
||||
$meatRow = $rowsB->firstWhere(1, $meat->name);
|
||||
return $meatRow !== null && (int) $meatRow[5] === 1 && (float) $meatRow[7] === 20.0;
|
||||
return $meatRow !== null && $meatRow[2] === '岳各庄' && (int) $meatRow[6] === 1 && (float) $meatRow[8] === 20.0;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
ProductModel::factory()->create([
|
||||
'category_id' => $leaf->id,
|
||||
'supplier_id' => $supplier->id,
|
||||
'market' => '新发地',
|
||||
'name' => '上海青',
|
||||
'spec' => '10斤/箱',
|
||||
'unit' => '斤',
|
||||
@@ -93,19 +94,19 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
if ($row === null) {
|
||||
return false;
|
||||
}
|
||||
// [品名, 分类路径, 供应商, 规格, 单位, 成本价, 排序, 库存, 保质期, 状态, 备注]
|
||||
if ($row[1] !== '蔬菜/叶菜类' || $row[2] !== '张三蔬菜批发' || $row[9] !== '上架') {
|
||||
// [品名, 分类路径, 供应商, 市场, 规格, 单位, 成本价, 排序, 库存, 保质期, 状态, 备注]
|
||||
if ($row[1] !== '蔬菜/叶菜类' || $row[2] !== '张三蔬菜批发' || $row[3] !== '新发地' || $row[10] !== '上架') {
|
||||
return false;
|
||||
}
|
||||
if ((float) $row[5] !== 2.5 || (int) $row[6] !== 3 || (int) $row[7] !== 100 || (int) $row[8] !== 2) {
|
||||
if ((float) $row[6] !== 2.5 || (int) $row[7] !== 3 || (int) $row[8] !== 100 || (int) $row[9] !== 2) {
|
||||
return false;
|
||||
}
|
||||
if ($row[10] !== '新鲜直达') {
|
||||
if ($row[11] !== '新鲜直达') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$offRow = $rows->firstWhere(0, '下架商品');
|
||||
return $offRow !== null && $offRow[9] === '下架' && $offRow[2] === '';
|
||||
return $offRow !== null && $offRow[10] === '下架' && $offRow[2] === '' && $offRow[3] === '';
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -164,6 +165,22 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
$this->assertFalse($response->json('success'), '缺少导出权限点应被拦截');
|
||||
}
|
||||
|
||||
/** 列表按市场模糊筛选 */
|
||||
public function test_list_filters_by_market(): void
|
||||
{
|
||||
ProductModel::factory()->create(['name' => '大白菜X', 'market' => '新发地']);
|
||||
ProductModel::factory()->create(['name' => '土豆X', 'market' => '岳各庄']);
|
||||
ProductModel::factory()->create(['name' => '无市场商品X', 'market' => '']);
|
||||
|
||||
$this->actingAsSysUser();
|
||||
$response = $this->getJson('/product/goods?market=新发');
|
||||
$response->assertJsonPath('success', true);
|
||||
$names = collect($response->json('data.data'))->pluck('name');
|
||||
$this->assertContains('大白菜X', $names);
|
||||
$this->assertNotContains('土豆X', $names);
|
||||
$this->assertNotContains('无市场商品X', $names);
|
||||
}
|
||||
|
||||
// ==================== 导入 ====================
|
||||
|
||||
/** 正常导入:新增商品 + 供应商自动创建 + 默认值(单位斤/状态上架) */
|
||||
@@ -174,8 +191,8 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
$this->actingAsSysUser();
|
||||
$file = $this->makeUploadFile([
|
||||
ProductExport::HEADERS,
|
||||
['上海青', '叶菜类', '新供应商A', '10斤/箱', '', 2.5, 3, 100, 2, '下架', '备注信息'],
|
||||
['西红柿', '蔬菜/茄果类', '', '散装', '箱', 1.8, '', '', '', '', ''],
|
||||
['上海青', '叶菜类', '新供应商A', '新发地', '10斤/箱', '', 2.5, 3, 100, 2, '下架', '备注信息'],
|
||||
['西红柿', '蔬菜/茄果类', '', '', '散装', '箱', 1.8, '', '', '', '', ''],
|
||||
]);
|
||||
// 第二行用到了不存在的「茄果类」路径 → 先补建该分类
|
||||
ProductCategoryModel::create(['name' => '茄果类', 'parent_id' => $leaf->parent_id, 'sort' => 1, 'status' => 1]);
|
||||
@@ -187,6 +204,7 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
$productA = ProductModel::where('name', '上海青')->first();
|
||||
$this->assertNotNull($productA);
|
||||
$this->assertSame($leaf->id, $productA->category_id);
|
||||
$this->assertSame('新发地', $productA->market);
|
||||
$this->assertSame('斤', $productA->unit, '单位留空应默认斤');
|
||||
$this->assertSame(ProductModel::STATUS_OFF, $productA->status);
|
||||
$this->assertSame('2.50', (string) $productA->cost_price);
|
||||
@@ -197,6 +215,7 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
|
||||
$productB = ProductModel::where('name', '西红柿')->first();
|
||||
$this->assertNotNull($productB);
|
||||
$this->assertSame('', $productB->market, '市场留空应为空字符串');
|
||||
$this->assertSame(0, $productB->supplier_id, '供应商留空应为 0(不创建)');
|
||||
$this->assertSame(ProductModel::STATUS_ON, $productB->status, '状态留空应默认上架');
|
||||
$this->assertSame(0, $productB->sort);
|
||||
@@ -211,7 +230,7 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
$this->actingAsSysUser();
|
||||
$file = $this->makeUploadFile([
|
||||
ProductExport::HEADERS,
|
||||
['黄瓜', '叶菜类', '老供应商', '散装', '斤', 1.2, 0, 0, 0, '上架', ''],
|
||||
['黄瓜', '叶菜类', '老供应商', '', '散装', '斤', 1.2, 0, 0, 0, '上架', ''],
|
||||
]);
|
||||
$this->post('/product/goods/import', ['file' => $file])->assertJsonPath('success', true);
|
||||
|
||||
@@ -227,10 +246,10 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
$this->actingAsSysUser();
|
||||
$file = $this->makeUploadFile([
|
||||
ProductExport::HEADERS,
|
||||
['正常商品', '叶菜类', '供应商X', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['', '叶菜类', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['坏商品A', '不存在的分类', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['坏商品B', '叶菜类', '', '散装', '斤', 'abc', 0, 0, 0, '上架', ''],
|
||||
['正常商品', '叶菜类', '供应商X', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['', '叶菜类', '', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['坏商品A', '不存在的分类', '', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['坏商品B', '叶菜类', '', '', '散装', '斤', 'abc', 0, 0, 0, '上架', ''],
|
||||
]);
|
||||
$response = $this->post('/product/goods/import', ['file' => $file]);
|
||||
|
||||
@@ -260,16 +279,17 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
// 路径写法命中蔬菜/叶菜
|
||||
$file = $this->makeUploadFile([
|
||||
ProductExport::HEADERS,
|
||||
['菠菜', '蔬菜/叶菜', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['菠菜', '蔬菜/叶菜', '', '岳各庄', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
]);
|
||||
$this->post('/product/goods/import', ['file' => $file])->assertJsonPath('success', true);
|
||||
$this->assertSame($vegLeaf->id, ProductModel::where('name', '菠菜')->value('category_id'));
|
||||
$this->assertSame('岳各庄', ProductModel::where('name', '菠菜')->value('market'));
|
||||
|
||||
// 单名称歧义 + 非末级分类 → 报错零写入
|
||||
$file = $this->makeUploadFile([
|
||||
ProductExport::HEADERS,
|
||||
['歧义商品', '叶菜', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['非末级商品', '蔬菜', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['歧义商品', '叶菜', '', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['非末级商品', '蔬菜', '', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
]);
|
||||
$response = $this->post('/product/goods/import', ['file' => $file]);
|
||||
$response->assertJsonPath('success', false);
|
||||
@@ -299,7 +319,7 @@ class ProductImportExportTest extends ProcurementTestCase
|
||||
|
||||
$file = $this->makeUploadFile([
|
||||
ProductExport::HEADERS,
|
||||
['上海青', '叶菜类', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
['上海青', '叶菜类', '', '', '散装', '斤', 1.0, 0, 0, 0, '上架', ''],
|
||||
]);
|
||||
$response = $this->post('/product/goods/import', ['file' => $file]);
|
||||
$this->assertFalse($response->json('success'), '缺少导入权限点应被拦截');
|
||||
|
||||
Reference in New Issue
Block a user