老数据副表
This commit is contained in:
@@ -89,6 +89,7 @@ class SkuController extends BaseController
|
||||
|
||||
public function import(Request $request)
|
||||
{
|
||||
// ini_set('memory_limit', '512M');
|
||||
$file = $request->file('file');
|
||||
if (!$file) return $this->error('未上传文件');;
|
||||
|
||||
@@ -123,11 +124,11 @@ class SkuController extends BaseController
|
||||
];
|
||||
$fieldsName = array_flip($allowFields);
|
||||
$attributeFields = [
|
||||
'product_name' => '产品尺寸(宽*高*深)',
|
||||
'model' => '开孔尺寸(宽*高*深)',
|
||||
'brand' => '卖点',
|
||||
'category_id' => '外观',
|
||||
'price' => '容积',
|
||||
'产品尺寸(宽*高*深)' => '产品尺寸(宽*高*深)',
|
||||
'开孔尺寸(宽*高*深)' => '开孔尺寸(宽*高*深)',
|
||||
'卖点' => '卖点',
|
||||
'外观' => '外观',
|
||||
'容积' => '容积',
|
||||
];
|
||||
$attributeFieldsName = array_flip($attributeFields);
|
||||
|
||||
@@ -150,7 +151,7 @@ class SkuController extends BaseController
|
||||
}
|
||||
|
||||
//商品属性
|
||||
if (in_array($field, $attributeFields)) {
|
||||
if (in_array($field, $attributeFields) && !empty($rowData[$i])) {
|
||||
$attributes[$attributeFieldsName[$field]] = trim((string)($rowData[$i] ?? ''));
|
||||
}
|
||||
}
|
||||
@@ -159,13 +160,13 @@ class SkuController extends BaseController
|
||||
continue;
|
||||
}
|
||||
|
||||
$data['category_id'] = PostCategory::where('name', $rowData[3])->value('id')??0;
|
||||
|
||||
$data['category_id'] = PostCategory::where('name', $rowData[4])->value('id')??0;
|
||||
|
||||
$spec = [];
|
||||
foreach ($attributes as $key => $attribute) {
|
||||
$skuAttribute = SkuAttribute::where('category_id',$data['category_id'])
|
||||
->where('attr_name', $key)
|
||||
->value('id');
|
||||
->first();
|
||||
if (empty($skuAttribute)) {
|
||||
$skuAttribute = SkuAttribute::create([
|
||||
'category_id' => $data['category_id'],
|
||||
@@ -178,44 +179,44 @@ class SkuController extends BaseController
|
||||
$attr['category_id'] = $data['category_id'];
|
||||
// $spec = ['sku_id' => $skuAttribute->id];
|
||||
$spec[] = $attr;
|
||||
$data['spec_json'] = json_encode($spec);
|
||||
}
|
||||
$data['spec_json'] = json_encode($spec);
|
||||
//商品属性
|
||||
if(!empty($rowData[5])){
|
||||
$speci = explode(';', $rowData[5]);
|
||||
$spec = [];
|
||||
foreach ($speci as $k => $v){
|
||||
$item = explode(':', $v);
|
||||
if (count($item) != 2) {
|
||||
continue;
|
||||
}
|
||||
$attr = ['attr_name'=>$item[0],'attr_value'=>$item[1]];
|
||||
$skuAttribute = SkuAttribute::where('attr_name', $item[0])
|
||||
->where('category_id', $data['category_id'])->first();
|
||||
if (empty($skuAttribute)) {
|
||||
$skuAttribute = SkuAttribute::create([
|
||||
'attr_name' => $item[0],
|
||||
'attr_value' => $item[1],
|
||||
'category_id' => $data['category_id'],
|
||||
'attr_type' => 'text'
|
||||
]);
|
||||
}
|
||||
$attr['attr_id'] = $skuAttribute->id;
|
||||
$attr['category_id'] = $data['category_id'];
|
||||
$spec[] = $attr;
|
||||
$data['spec_json'] = json_encode($spec);
|
||||
}
|
||||
}
|
||||
// if(!empty($rowData[5])){
|
||||
// $speci = explode(';', $rowData[5]);
|
||||
// $spec = [];
|
||||
// foreach ($speci as $k => $v){
|
||||
// $item = explode(':', $v);
|
||||
// if (count($item) != 2) {
|
||||
// continue;
|
||||
// }
|
||||
// $attr = ['attr_name'=>$item[0],'attr_value'=>$item[1]];
|
||||
// $skuAttribute = SkuAttribute::where('attr_name', $item[0])
|
||||
// ->where('category_id', $data['category_id'])->first();
|
||||
// if (empty($skuAttribute)) {
|
||||
// $skuAttribute = SkuAttribute::create([
|
||||
// 'attr_name' => $item[0],
|
||||
// 'attr_value' => $item[1],
|
||||
// 'category_id' => $data['category_id'],
|
||||
// 'attr_type' => 'text'
|
||||
// ]);
|
||||
// }
|
||||
// $attr['attr_id'] = $skuAttribute->id;
|
||||
// $attr['category_id'] = $data['category_id'];
|
||||
// $spec[] = $attr;
|
||||
// $data['spec_json'] = json_encode($spec);
|
||||
// }
|
||||
// }
|
||||
|
||||
//主图
|
||||
if(!empty($rowData[6])){
|
||||
$tmpPath = runtime_path('upload/import/pic/'.$rowData[6]);
|
||||
if(!empty($rowData[7])){
|
||||
$tmpPath = runtime_path('upload/import/pic/'.$rowData[7]);
|
||||
$res = $uploadService->uploadLocalFile(['path' => $tmpPath, 'scene' => 'sku']);
|
||||
$data['main_image'] = $res['file_name'];
|
||||
}
|
||||
//详情
|
||||
if(!empty($rowData[7])){
|
||||
$docxFullPath = runtime_path('upload/import/docs/'.$rowData[7]);
|
||||
if(!empty($rowData[8])){
|
||||
$docxFullPath = runtime_path('upload/import/docs/'.$rowData[8]);
|
||||
|
||||
if (filesize($docxFullPath) !== 0 && file_exists($zipPath)) {
|
||||
$data['desc'] =$this->docxToHtmlWithImages($docxFullPath);
|
||||
|
||||
Reference in New Issue
Block a user