作者 lyh

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

@@ -50,6 +50,18 @@ class ProjectImport extends Command @@ -50,6 +50,18 @@ class ProjectImport extends Command
50 50
51 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import start' . PHP_EOL; 51 echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import start' . PHP_EOL;
52 52
  53 + $is_gbk = 0;
  54 + $file_code_type = $this->get_code_type($task->file_url);
  55 + if ($file_code_type === false) {
  56 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', import fail, error: 文件编码格式错误' . PHP_EOL;
  57 + $task->status = ImportTask::STATUS_COM;//导入完成
  58 + $task->save();
  59 + return true;
  60 + } elseif ($file_code_type === 'GBK') {
  61 + $is_gbk = 1;
  62 + setlocale(LC_ALL, 'zh_CN');
  63 + }
  64 +
53 //读取csv文件 65 //读取csv文件
54 $line_of_text = []; 66 $line_of_text = [];
55 try { 67 try {
@@ -67,7 +79,6 @@ class ProjectImport extends Command @@ -67,7 +79,6 @@ class ProjectImport extends Command
67 79
68 $total_count = 0; //总条数 80 $total_count = 0; //总条数
69 $success_count = 0; //成功导入条数 81 $success_count = 0; //成功导入条数
70 - setlocale(LC_ALL,'zh_CN');  
71 if (count($line_of_text) > 1) { 82 if (count($line_of_text) > 1) {
72 $task->status = ImportTask::STATUS_ING;//导入中 83 $task->status = ImportTask::STATUS_ING;//导入中
73 $task->save(); 84 $task->save();
@@ -78,9 +89,11 @@ class ProjectImport extends Command @@ -78,9 +89,11 @@ class ProjectImport extends Command
78 foreach ($line_of_text as $k => $v) { 89 foreach ($line_of_text as $k => $v) {
79 if ($k > 0 && isset($v[0]) && $v[0]) { 90 if ($k > 0 && isset($v[0]) && $v[0]) {
80 91
81 - foreach ($v as $kk=>$vv){ 92 + if ($is_gbk) {
  93 + foreach ($v as $kk => $vv) {
82 $v[$kk] = mb_convert_encoding($vv, 'utf-8', 'gbk'); 94 $v[$kk] = mb_convert_encoding($vv, 'utf-8', 'gbk');
83 } 95 }
  96 + }
84 97
85 $total_count += 1; 98 $total_count += 1;
86 try { 99 try {
@@ -109,11 +122,25 @@ class ProjectImport extends Command @@ -109,11 +122,25 @@ class ProjectImport extends Command
109 122
110 $task->status = ImportTask::STATUS_COM;//导入完成 123 $task->status = ImportTask::STATUS_COM;//导入完成
111 $task->total_count = $total_count; 124 $task->total_count = $total_count;
112 - $task->success_count = $success_count; 125 + $task->success_count += $success_count;
113 $task->save(); 126 $task->save();
114 127
115 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; 128 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;
116 129
117 sleep(2); 130 sleep(2);
118 } 131 }
  132 +
  133 + //判断编码格式
  134 + function get_code_type($file)
  135 + {
  136 + $list = array('GBK', 'UTF-8');
  137 + $str = file_get_contents($file);
  138 + foreach ($list as $item) {
  139 + $tmp = mb_convert_encoding($str, $item, $item);
  140 + if (md5($tmp) == md5($str)) {
  141 + return $item;
  142 + }
  143 + }
  144 + return false;
  145 + }
119 } 146 }
@@ -270,6 +270,9 @@ class BlogLogic extends BaseLogic @@ -270,6 +270,9 @@ class BlogLogic extends BaseLogic
270 */ 270 */
271 public function importBlog($project_id, $user_id, $data) 271 public function importBlog($project_id, $user_id, $data)
272 { 272 {
  273 + $blog = $this->model->read(['name' => $data[0]]);
  274 + if (!$blog) {
  275 +
273 $category_id = ''; 276 $category_id = '';
274 if ($data[2]) { 277 if ($data[2]) {
275 //处理分类 278 //处理分类
@@ -277,8 +280,6 @@ class BlogLogic extends BaseLogic @@ -277,8 +280,6 @@ class BlogLogic extends BaseLogic
277 $category_id = $blogCategoryLogic->importBlogCategory($project_id, $user_id, $data[2]); 280 $category_id = $blogCategoryLogic->importBlogCategory($project_id, $user_id, $data[2]);
278 } 281 }
279 282
280 - $blog = $this->model->read(['name' => $data[0]]);  
281 - if (!$blog) {  
282 $id = $this->model->addReturnId( 283 $id = $this->model->addReturnId(
283 [ 284 [
284 'name' => $data[0], 285 'name' => $data[0],
@@ -269,6 +269,9 @@ class NewsLogic extends BaseLogic @@ -269,6 +269,9 @@ class NewsLogic extends BaseLogic
269 */ 269 */
270 public function importNews($project_id, $user_id, $data) 270 public function importNews($project_id, $user_id, $data)
271 { 271 {
  272 + $news = $this->model->read(['name' => $data[0]]);
  273 + if (!$news) {
  274 +
272 $category_id = ''; 275 $category_id = '';
273 if ($data[2]) { 276 if ($data[2]) {
274 //处理分类 277 //处理分类
@@ -276,8 +279,6 @@ class NewsLogic extends BaseLogic @@ -276,8 +279,6 @@ class NewsLogic extends BaseLogic
276 $category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]); 279 $category_id = $newsCategoryLogic->importNewsCategory($project_id, $user_id, $data[2]);
277 } 280 }
278 281
279 - $news = $this->model->read(['name' => $data[0]]);  
280 - if (!$news) {  
281 $id = $this->model->addReturnId( 282 $id = $this->model->addReturnId(
282 [ 283 [
283 'name' => $data[0], 284 'name' => $data[0],
@@ -381,6 +381,9 @@ class ProductLogic extends BaseLogic @@ -381,6 +381,9 @@ class ProductLogic extends BaseLogic
381 */ 381 */
382 public function importProduct($project_id, $user_id, $data) 382 public function importProduct($project_id, $user_id, $data)
383 { 383 {
  384 + $product = $this->model->read(['title' => $data[0]]);
  385 + if (!$product) {
  386 +
384 $category_id = ''; 387 $category_id = '';
385 if ($data[2]) { 388 if ($data[2]) {
386 //处理分类 389 //处理分类
@@ -419,6 +422,31 @@ class ProductLogic extends BaseLogic @@ -419,6 +422,31 @@ class ProductLogic extends BaseLogic
419 } 422 }
420 } 423 }
421 424
  425 + $intro = '';
  426 + if($data[5]){
  427 + //处理短描述中的图片
  428 + $pattern = '<img src="(.*?)">';
  429 + preg_match_all($pattern, $data[5], $result_intro);
  430 + if($result_intro[1]){
  431 + foreach ($result_intro[1] as $vi_img){
  432 + $data[5] = str_replace($vi_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_img)),$data[5]);
  433 + }
  434 + }
  435 + $intro = $data[5];
  436 + }
  437 +
  438 + $content = '';
  439 + if($data[6]){
  440 + //处理内容中的图片
  441 + $pattern = '<img src="(.*?)">';
  442 + preg_match_all($pattern, $data[6], $result_content);
  443 + if($result_content[1]){
  444 + foreach ($result_content[1] as $vc_img){
  445 + $data[6] = str_replace($vc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_img)),$data[6]);
  446 + }
  447 + }
  448 + $content = $data[6];
  449 + }
422 450
423 //处理seo 451 //处理seo
424 $seo_mate = [ 452 $seo_mate = [
@@ -427,19 +455,17 @@ class ProductLogic extends BaseLogic @@ -427,19 +455,17 @@ class ProductLogic extends BaseLogic
427 'description' => $data[10]??'' 455 'description' => $data[10]??''
428 ]; 456 ];
429 457
430 - $product = $this->model->read(['title' => $data[0]]);  
431 - if (!$product) {  
432 $id = $this->model->addReturnId( 458 $id = $this->model->addReturnId(
433 [ 459 [
434 'project_id' => $project_id, 460 'project_id' => $project_id,
435 'title' => $data[0], 461 'title' => $data[0],
436 'thumb' => $thumb, 462 'thumb' => $thumb,
437 'gallery' => Arr::a2s($gallery), 463 'gallery' => Arr::a2s($gallery),
438 - 'attrs' => $data[4] ? $data[4] : Arr::a2s([]), 464 + 'attrs' => trim($data[4]) ? $data[4] : Arr::a2s([]),
439 'category_id' => $category_id, 465 'category_id' => $category_id,
440 'keyword_id' => $keyword_id, 466 'keyword_id' => $keyword_id,
441 - 'intro' => $data[5] ?? '',  
442 - 'content' => $data[6] ?? '', 467 + 'intro' => $intro,
  468 + 'content' => $content,
443 'seo_mate' => Arr::a2s($seo_mate), 469 'seo_mate' => Arr::a2s($seo_mate),
444 'created_uid' => $user_id, 470 'created_uid' => $user_id,
445 'status' => Product::STATUS_ON 471 'status' => Product::STATUS_ON
@@ -74,7 +74,6 @@ class CosService @@ -74,7 +74,6 @@ class CosService
74 */ 74 */
75 public static function uploadRemote($project_id,$image_type,$file_url) 75 public static function uploadRemote($project_id,$image_type,$file_url)
76 { 76 {
77 - return '';  
78 $ext = explode('.',$file_url); 77 $ext = explode('.',$file_url);
79 78
80 $filename = uniqid().rand(10000,99999).'.'.end($ext); 79 $filename = uniqid().rand(10000,99999).'.'.end($ext);