添加市场
This commit is contained in:
@@ -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