作者 lyh

gx数据

@@ -51,14 +51,43 @@ class LyhImportTest extends Command @@ -51,14 +51,43 @@ class LyhImportTest extends Command
51 * @time :2023/11/20 15:13 51 * @time :2023/11/20 15:13
52 */ 52 */
53 public function handle(){ 53 public function handle(){
54 -// ProjectServer::useProject(3283);  
55 -// echo date('Y-m-d H:i:s') . 'start' . PHP_EOL; 54 + ProjectServer::useProject(3283);
  55 + echo date('Y-m-d H:i:s') . 'start' . PHP_EOL;
56 // $this->importProduct('https://ecdn6.globalso.com/upload/p/1/file/2025-03/zy_boss_price_copy1.csv',3283); 56 // $this->importProduct('https://ecdn6.globalso.com/upload/p/1/file/2025-03/zy_boss_price_copy1.csv',3283);
57 -// DB::disconnect('custom_mysql'); 57 + DB::disconnect('custom_mysql');
58 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 58 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
59 } 59 }
60 60
61 /** 61 /**
  62 + * @remark :导入产品分类
  63 + * @name :productCategory
  64 + * @author :lyh
  65 + * @method :post
  66 + * @time :2025/3/13 9:58
  67 + */
  68 + public function importProductCategory($url,$project_id){
  69 + $line_of_text = [];
  70 + $opts = [
  71 + 'http' => [
  72 + 'method' => 'GET',
  73 + 'header' => 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
  74 + ],
  75 + 'ssl' => [
  76 + 'verify_peer' => false,
  77 + 'verify_peer_name' => false
  78 + ]
  79 + ];
  80 + $file_handle = fopen($url, 'r', null, stream_context_create($opts));
  81 + while (!feof($file_handle)) {
  82 + $line_of_text[] = fgetcsv($file_handle, 0, ',');
  83 + }
  84 + fclose($file_handle);
  85 + foreach ($line_of_text as $k => $val){
  86 +
  87 + }
  88 + }
  89 +
  90 + /**
62 * @remark :导入分类 91 * @remark :导入分类
63 * @name :importProductCategory 92 * @name :importProductCategory
64 * @author :lyh 93 * @author :lyh
@@ -85,7 +114,6 @@ class LyhImportTest extends Command @@ -85,7 +114,6 @@ class LyhImportTest extends Command
85 $cateModel = new Category(); 114 $cateModel = new Category();
86 $productModel = new Product(); 115 $productModel = new Product();
87 $detailModel = new Detail(); 116 $detailModel = new Detail();
88 - $columnModel = new Column();  
89 foreach ($line_of_text as $k => $val){ 117 foreach ($line_of_text as $k => $val){
90 if($k < 2){ 118 if($k < 2){
91 continue; 119 continue;
@@ -106,8 +134,8 @@ class LyhImportTest extends Command @@ -106,8 +134,8 @@ class LyhImportTest extends Command
106 $saveData['content'] = $val[3]; 134 $saveData['content'] = $val[3];
107 $seo = ['seo_title'=>$val[5]]; 135 $seo = ['seo_title'=>$val[5]];
108 $saveData['seo_mate'] = json_encode($seo,true); 136 $saveData['seo_mate'] = json_encode($seo,true);
109 - $thumb = ['alt'=>'主图','url'=>str_replace('/public','',$val[6])];  
110 - $gallery = [['alt'=>'主图','url'=>str_replace('/public','',$val[6])]]; 137 + $thumb = ['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[6])];
  138 + $gallery = [['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[6])]];
111 $saveData['thumb'] = json_encode($thumb,true); 139 $saveData['thumb'] = json_encode($thumb,true);
112 $saveData['gallery'] = json_encode($gallery,true); 140 $saveData['gallery'] = json_encode($gallery,true);
113 $id = $productModel->addReturnId($saveData); 141 $id = $productModel->addReturnId($saveData);
@@ -127,22 +155,16 @@ class LyhImportTest extends Command @@ -127,22 +155,16 @@ class LyhImportTest extends Command
127 'content'=>json_encode(['content'=>$val[3]]) 155 'content'=>json_encode(['content'=>$val[3]])
128 ]; 156 ];
129 $detailModel->addReturnId($detail); 157 $detailModel->addReturnId($detail);
130 - //扩展描述设置  
131 - $detailFaq = [  
132 - 'column_name'=>'FAQs',  
133 - 'product_id'=>$id  
134 - ];  
135 - $faqId = $columnModel->addReturnId($detailFaq);  
136 -  
137 $faqsDetail = json_decode($val[4],true); 158 $faqsDetail = json_decode($val[4],true);
138 - $faqContent = '';  
139 if(!empty($faqsDetail) && is_array($faqsDetail)){ 159 if(!empty($faqsDetail) && is_array($faqsDetail)){
  160 + $faqContent = '<div>';
140 foreach ($faqsDetail as $faq_Val){ 161 foreach ($faqsDetail as $faq_Val){
141 - $faqContent .= "question:".$faq_Val['question'] . "<br />" . "answer:".$faq_Val['answer']. "<br />"; 162 + $faqContent .= "<span>question:".$faq_Val['question'] . "</span><br /><span>" . "answer:".$faq_Val['answer']. "</span><br />";
142 } 163 }
  164 + $faqContent .= '</div>';
143 $detailFaqInfo = [ 165 $detailFaqInfo = [
144 'product_id'=>$id, 166 'product_id'=>$id,
145 - 'column_id'=>$faqId, 167 + 'column_id'=>1,
146 'text_type'=>1, 168 'text_type'=>1,
147 'content'=>json_encode(['content'=>$faqContent]) 169 'content'=>json_encode(['content'=>$faqContent])
148 ]; 170 ];