老数据副表

This commit is contained in:
2025-12-22 16:01:11 +08:00
parent 079a945e93
commit 90218d8ae3
3 changed files with 113 additions and 39 deletions
+40 -39
View File
@@ -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);
+49
View File
@@ -0,0 +1,49 @@
<?php
namespace app\common\model;
use support\Model;
class PostOld extends Model
{
/**
* The connection name for the model.
*
* @var string|null
*/
protected $connection = 'mysql';
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'post_old';
/**
* The primary key associated with the table.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = true;
protected $dateFormat = 'U';
/**
* 允许自动填充模型字段
*/
protected $fillable = ['id', 'user_id', 'category_id', 'sku_id', 'content', 'shop_name', 'location_name', 'latitude', 'longitude', 'geo', 'status', 'sort', 'like', 'favorite', 'comment', 'is_free', 'model', 'browse', 'created_at', 'updated_at', 'price', 'age'];
/**
* 不允许自动填充模型字段
*/
protected $guarded = [];
}
+24
View File
@@ -3,6 +3,8 @@
namespace app\common\service;
use app\common\logic\AuthLogic;
use app\common\model\Post;
use app\common\model\PostOld;
use app\common\model\UserOld;
use app\common\validate\UserValidate;
use app\common\traits\crud\CrudServiceTrait;
@@ -300,6 +302,28 @@ class UserService
$uinfo->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;
}