|
...
|
...
|
@@ -381,65 +381,91 @@ class ProductLogic extends BaseLogic |
|
|
|
*/
|
|
|
|
public function importProduct($project_id, $user_id, $data)
|
|
|
|
{
|
|
|
|
$category_id = '';
|
|
|
|
if ($data[2]) {
|
|
|
|
//处理分类
|
|
|
|
$categoryLogic = new CategoryLogic();
|
|
|
|
$category_id = $categoryLogic->importProductCategory($project_id, $data[2]);
|
|
|
|
}
|
|
|
|
$product = $this->model->read(['title' => $data[0]]);
|
|
|
|
if (!$product) {
|
|
|
|
|
|
|
|
$keyword_id = '';
|
|
|
|
if($data[3]){
|
|
|
|
//处理关键词
|
|
|
|
$keywordLogic = new KeywordLogic();
|
|
|
|
$keyword_id = $keywordLogic->importProductKeyword($project_id, $data[3]);
|
|
|
|
}
|
|
|
|
$category_id = '';
|
|
|
|
if ($data[2]) {
|
|
|
|
//处理分类
|
|
|
|
$categoryLogic = new CategoryLogic();
|
|
|
|
$category_id = $categoryLogic->importProductCategory($project_id, $data[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$gallery = [];
|
|
|
|
$thumb = '';
|
|
|
|
if($data[7]){
|
|
|
|
//处理图片
|
|
|
|
$img_arr = explode(',',$data[7]);
|
|
|
|
foreach ($img_arr as $v_img){
|
|
|
|
if($v_img){
|
|
|
|
$one_img = CosService::uploadRemote($project_id,'image_product',$v_img);
|
|
|
|
if($one_img){
|
|
|
|
$one_gallery = [
|
|
|
|
'alt' => '这是一张产品图',
|
|
|
|
'url' => $one_img
|
|
|
|
];
|
|
|
|
$keyword_id = '';
|
|
|
|
if($data[3]){
|
|
|
|
//处理关键词
|
|
|
|
$keywordLogic = new KeywordLogic();
|
|
|
|
$keyword_id = $keywordLogic->importProductKeyword($project_id, $data[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
$gallery = [];
|
|
|
|
$thumb = '';
|
|
|
|
if($data[7]){
|
|
|
|
//处理图片
|
|
|
|
$img_arr = explode(',',$data[7]);
|
|
|
|
foreach ($img_arr as $v_img){
|
|
|
|
if($v_img){
|
|
|
|
$one_img = CosService::uploadRemote($project_id,'image_product',$v_img);
|
|
|
|
if($one_img){
|
|
|
|
$one_gallery = [
|
|
|
|
'alt' => '这是一张产品图',
|
|
|
|
'url' => $one_img
|
|
|
|
];
|
|
|
|
|
|
|
|
if(!$thumb){
|
|
|
|
$thumb = Arr::a2s($one_gallery);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!$thumb){
|
|
|
|
$thumb = Arr::a2s($one_gallery);
|
|
|
|
$gallery[] = $one_gallery;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$gallery[] = $one_gallery;
|
|
|
|
$intro = '';
|
|
|
|
if($data[5]){
|
|
|
|
//处理短描述中的图片
|
|
|
|
$pattern = '<img src="(.*?)">';
|
|
|
|
preg_match_all($pattern, $data[5], $result_intro);
|
|
|
|
if($result_intro[1]){
|
|
|
|
foreach ($result_intro[1] as $vi_img){
|
|
|
|
$data[5] = str_replace($vi_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_img)),$data[5]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$intro = $data[5];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$content = '';
|
|
|
|
if($data[6]){
|
|
|
|
//处理内容中的图片
|
|
|
|
$pattern = '<img src="(.*?)">';
|
|
|
|
preg_match_all($pattern, $data[6], $result_content);
|
|
|
|
if($result_content[1]){
|
|
|
|
foreach ($result_content[1] as $vc_img){
|
|
|
|
$data[6] = str_replace($vc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_img)),$data[6]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$content = $data[6];
|
|
|
|
}
|
|
|
|
|
|
|
|
//处理seo
|
|
|
|
$seo_mate = [
|
|
|
|
'title' => $data[8]??'',
|
|
|
|
'keyword' => $data[9]??'',
|
|
|
|
'description' => $data[10]??''
|
|
|
|
];
|
|
|
|
//处理seo
|
|
|
|
$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' => $thumb,
|
|
|
|
'gallery' => Arr::a2s($gallery),
|
|
|
|
'attrs' => $data[4] ? $data[4] : Arr::a2s([]),
|
|
|
|
'attrs' => trim($data[4]) ? $data[4] : Arr::a2s([]),
|
|
|
|
'category_id' => $category_id,
|
|
|
|
'keyword_id' => $keyword_id,
|
|
|
|
'intro' => $data[5] ?? '',
|
|
|
|
'content' => $data[6] ?? '',
|
|
|
|
'intro' => $intro,
|
|
|
|
'content' => $content,
|
|
|
|
'seo_mate' => Arr::a2s($seo_mate),
|
|
|
|
'created_uid' => $user_id,
|
|
|
|
'status' => Product::STATUS_ON
|
...
|
...
|
|