导入
This commit is contained in:
@@ -122,6 +122,14 @@ class SkuController extends BaseController
|
|||||||
//'spec_json' => '商品属性'
|
//'spec_json' => '商品属性'
|
||||||
];
|
];
|
||||||
$fieldsName = array_flip($allowFields);
|
$fieldsName = array_flip($allowFields);
|
||||||
|
$attributeFields = [
|
||||||
|
'product_name' => '产品尺寸(宽*高*深)',
|
||||||
|
'model' => '开孔尺寸(宽*高*深)',
|
||||||
|
'brand' => '卖点',
|
||||||
|
'category_id' => '外观',
|
||||||
|
'price' => '容积',
|
||||||
|
];
|
||||||
|
$attributeFieldsName = array_flip($attributeFields);
|
||||||
|
|
||||||
$insertData = [];
|
$insertData = [];
|
||||||
$now = time();
|
$now = time();
|
||||||
@@ -135,10 +143,16 @@ class SkuController extends BaseController
|
|||||||
)[0];
|
)[0];
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
$attributes = [];
|
||||||
foreach ($header as $i => $field) {
|
foreach ($header as $i => $field) {
|
||||||
if (in_array($field, $allowFields)) {
|
if (in_array($field, $allowFields)) {
|
||||||
$data[$fieldsName[$field]] = trim((string)($rowData[$i] ?? ''));
|
$data[$fieldsName[$field]] = trim((string)($rowData[$i] ?? ''));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//商品属性
|
||||||
|
if (in_array($field, $attributeFields)) {
|
||||||
|
$attributes[$attributeFieldsName[$field]] = trim((string)($rowData[$i] ?? ''));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($data['product_name'])) {
|
if (empty($data['product_name'])) {
|
||||||
@@ -147,6 +161,25 @@ class SkuController extends BaseController
|
|||||||
|
|
||||||
$data['category_id'] = PostCategory::where('name', $rowData[3])->value('id')??0;
|
$data['category_id'] = PostCategory::where('name', $rowData[3])->value('id')??0;
|
||||||
|
|
||||||
|
|
||||||
|
foreach ($attributes as $key => $attribute) {
|
||||||
|
$skuAttribute = SkuAttribute::where('category_id',$data['category_id'])
|
||||||
|
->where('attr_name', $key)
|
||||||
|
->value('id');
|
||||||
|
if (empty($skuAttribute)) {
|
||||||
|
$skuAttribute = SkuAttribute::create([
|
||||||
|
'category_id' => $data['category_id'],
|
||||||
|
'attr_name' => $key,
|
||||||
|
'attr_type' => 'text',
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
$attr = ['attr_name' => $key,'attr_value'=> $attribute];
|
||||||
|
$attr['attr_id'] = $skuAttribute->id;
|
||||||
|
$attr['category_id'] = $data['category_id'];
|
||||||
|
// $spec = ['sku_id' => $skuAttribute->id];
|
||||||
|
$spec[] = $attr;
|
||||||
|
$data['spec_json'] = json_encode($spec);
|
||||||
|
}
|
||||||
//商品属性
|
//商品属性
|
||||||
if(!empty($rowData[5])){
|
if(!empty($rowData[5])){
|
||||||
$speci = explode(';', $rowData[5]);
|
$speci = explode(';', $rowData[5]);
|
||||||
|
|||||||
Reference in New Issue
Block a user