From 90218d8ae3ec2dacbd76abb20c42fc3c4e28d5e5 Mon Sep 17 00:00:00 2001 From: "WIN-C27C5MSVTPO\\16961" <1696136552@qq.com> Date: Mon, 22 Dec 2025 16:01:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=80=81=E6=95=B0=E6=8D=AE=E5=89=AF=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/admin/controller/SkuController.php | 79 +++++++++++++------------- app/common/model/PostOld.php | 49 ++++++++++++++++ app/common/service/UserService.php | 24 ++++++++ 3 files changed, 113 insertions(+), 39 deletions(-) create mode 100644 app/common/model/PostOld.php diff --git a/app/admin/controller/SkuController.php b/app/admin/controller/SkuController.php index 6b737d5..22f61da 100644 --- a/app/admin/controller/SkuController.php +++ b/app/admin/controller/SkuController.php @@ -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); diff --git a/app/common/model/PostOld.php b/app/common/model/PostOld.php new file mode 100644 index 0000000..5c5e17e --- /dev/null +++ b/app/common/model/PostOld.php @@ -0,0 +1,49 @@ +mobile = $mobile; $uinfo->save(); + $postOld = PostOld::where('mobile', $mobile)->get(); + if (!empty($postOld)) { + foreach ($postOld as $item) { + $post = [ + "id" => $item->id, + "user_id" => $uinfo->id, + "category_id" => $item->id, + "sku_id" => $item->sku_id, + "content" => $item->content, + "shop_name" => $item->shop_name, + "location_name" => $item->location_name, + "status" => 1, + "is_free" => $item->is_free, + "model" => $item->model, + "browse" => $item->browse, + "price" => $item->price, + "age" => $item->age, + ]; + Post::firstOrCreate($post); + } + } + return $wxinfo; }