|
...
|
...
|
@@ -8,6 +8,7 @@ use App\Models\Product\CategoryRelated; |
|
|
|
use App\Models\Product\Product;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Models\Template\BTemplate;
|
|
|
|
use App\Services\CosService;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -367,4 +368,79 @@ class ProductLogic extends BaseLogic |
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 产品导入
|
|
|
|
* @param $project_id
|
|
|
|
* @param $user_id
|
|
|
|
* @param $data
|
|
|
|
* @return bool
|
|
|
|
* @throws \Exception
|
|
|
|
* @author Akun
|
|
|
|
* @date 2023/09/21 14:55
|
|
|
|
*/
|
|
|
|
public function importProduct($project_id, $user_id, $data)
|
|
|
|
{
|
|
|
|
$category_id = '';
|
|
|
|
if ($data[2]) {
|
|
|
|
//处理分类
|
|
|
|
$categoryLogic = new CategoryLogic();
|
|
|
|
$category_id = $categoryLogic->importProductCategory($project_id, $data[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$keyword_id = '';
|
|
|
|
if($data[3]){
|
|
|
|
//处理关键词
|
|
|
|
$keywordLogic = new KeywordLogic();
|
|
|
|
$keyword_id = $keywordLogic->importProductKeyword($project_id, $data[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$gallery = [];
|
|
|
|
if($data[7]){
|
|
|
|
//处理图片集
|
|
|
|
$img_arr = explode(',',$data[7]);
|
|
|
|
foreach ($img_arr as $v_img){
|
|
|
|
$one_img = CosService::uploadRemote($project_id,'image_product',$v_img);
|
|
|
|
if($one_img){
|
|
|
|
$gallery[] = [
|
|
|
|
'alt' => '这是一张产品图',
|
|
|
|
'url' => $one_img
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$seo_mate = [
|
|
|
|
'title' => $data[8]??'',
|
|
|
|
'keyword' => $data[9]??'',
|
|
|
|
'description' => $data[10]??''
|
|
|
|
];
|
|
|
|
|
|
|
|
$product = $this->model->read(['title' => $data[0]]);
|
|
|
|
if (!$product) {
|
|
|
|
$id = $this->model->addReturnId(
|
|
|
|
[
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'title' => $data[0],
|
|
|
|
'thumb' => Arr::a2s($gallery[0] ?? ''),
|
|
|
|
'gallery' => Arr::a2s($gallery),
|
|
|
|
'attrs' => $data[4]??'',
|
|
|
|
'category_id' => $category_id,
|
|
|
|
'keyword_id' => $keyword_id,
|
|
|
|
'intro' => $data[5] ?? '',
|
|
|
|
'content' => $data[6] ?? '',
|
|
|
|
'seo_mate' => Arr::a2s($seo_mate),
|
|
|
|
'created_uid' => $user_id,
|
|
|
|
'status' => Product::STATUS_ON
|
|
|
|
]
|
|
|
|
);
|
|
|
|
//更新路由
|
|
|
|
$route = RouteMap::setRoute($data[1] ?: $data[0], RouteMap::SOURCE_PRODUCT, $id, $project_id);
|
|
|
|
$this->edit(['route' => $route], ['id' => $id]);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|