作者 lyh

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop

... ... @@ -50,6 +50,18 @@ class ProjectImport extends Command
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import start' . PHP_EOL;
$is_gbk = 0;
$file_code_type = $this->get_code_type($task->file_url);
if ($file_code_type === false) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import fail, error: 文件编码格式错误' . PHP_EOL;
$task->status = ImportTask::STATUS_COM;//导入完成
$task->save();
return true;
} elseif ($file_code_type === 'GBK') {
$is_gbk = 1;
setlocale(LC_ALL, 'zh_CN');
}
//读取csv文件
$line_of_text = [];
try {
... ... @@ -67,7 +79,6 @@ class ProjectImport extends Command
$total_count = 0; //总条数
$success_count = 0; //成功导入条数
setlocale(LC_ALL,'zh_CN');
if (count($line_of_text) > 1) {
$task->status = ImportTask::STATUS_ING;//导入中
$task->save();
... ... @@ -78,8 +89,10 @@ class ProjectImport extends Command
foreach ($line_of_text as $k => $v) {
if ($k > 0 && isset($v[0]) && $v[0]) {
foreach ($v as $kk=>$vv){
$v[$kk] = mb_convert_encoding($vv, 'utf-8', 'gbk');
if ($is_gbk) {
foreach ($v as $kk => $vv) {
$v[$kk] = mb_convert_encoding($vv, 'utf-8', 'gbk');
}
}
$total_count += 1;
... ... @@ -109,11 +122,25 @@ class ProjectImport extends Command
$task->status = ImportTask::STATUS_COM;//导入完成
$task->total_count = $total_count;
$task->success_count = $success_count;
$task->success_count += $success_count;
$task->save();
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import end, total count: ' . $total_count . ', success count: ' . $success_count . PHP_EOL;
sleep(2);
}
//判断编码格式
function get_code_type($file)
{
$list = array('GBK', 'UTF-8');
$str = file_get_contents($file);
foreach ($list as $item) {
$tmp = mb_convert_encoding($str, $item, $item);
if (md5($tmp) == md5($str)) {
return $item;
}
}
return false;
}
}
... ...
... ... @@ -270,15 +270,16 @@ class BlogLogic extends BaseLogic
*/
public function importBlog($project_id, $user_id, $data)
{
$category_id = '';
if ($data[2]) {
//处理分类
$blogCategoryLogic = new BlogCategoryLogic();
$category_id = $blogCategoryLogic->importBlogCategory($project_id, $user_id, $data[2]);
}
$blog = $this->model->read(['name' => $data[0]]);
if (!$blog) {
$category_id = '';
if ($data[2]) {
//处理分类
$blogCategoryLogic = new BlogCategoryLogic();
$category_id = $blogCategoryLogic->importBlogCategory($project_id, $user_id, $data[2]);
}
$id = $this->model->addReturnId(
[
'name' => $data[0],
... ...
... ... @@ -269,15 +269,16 @@ class NewsLogic extends BaseLogic
*/
public function importNews($project_id, $user_id, $data)
{
$category_id = '';
if ($data[2]) {
//处理分类
$newsCategoryLogic = new NewsCategoryLogic();
$category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]);
}
$news = $this->model->read(['name' => $data[0]]);
if (!$news) {
$category_id = '';
if ($data[2]) {
//处理分类
$newsCategoryLogic = new NewsCategoryLogic();
$category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]);
}
$id = $this->model->addReturnId(
[
'name' => $data[0],
... ...
... ... @@ -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
... ...
... ... @@ -74,7 +74,6 @@ class CosService
*/
public static function uploadRemote($project_id,$image_type,$file_url)
{
return '';
$ext = explode('.',$file_url);
$filename = uniqid().rand(10000,99999).'.'.end($ext);
... ...