作者 李宇航

合并分支 'lyh-server' 到 'master'

Lyh server



查看合并请求 !1419
@@ -51,14 +51,44 @@ class LyhImportTest extends Command @@ -51,14 +51,44 @@ 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->importProductCategory('https://ecdn6.globalso.com/upload/p/3283/file/2025-03/zy_boss_pricelistcat_202503131025.csv','3283');
56 // $this->importProduct('https://ecdn6.globalso.com/upload/p/1/file/2025-03/zy_boss_price_copy1.csv',3283); 57 // $this->importProduct('https://ecdn6.globalso.com/upload/p/1/file/2025-03/zy_boss_price_copy1.csv',3283);
57 -// DB::disconnect('custom_mysql'); 58 + DB::disconnect('custom_mysql');
58 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 59 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
59 } 60 }
60 61
61 /** 62 /**
  63 + * @remark :导入产品分类
  64 + * @name :productCategory
  65 + * @author :lyh
  66 + * @method :post
  67 + * @time :2025/3/13 9:58
  68 + */
  69 + public function importProductCategory($url,$project_id){
  70 + $line_of_text = [];
  71 + $opts = [
  72 + 'http' => [
  73 + 'method' => 'GET',
  74 + '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'
  75 + ],
  76 + 'ssl' => [
  77 + 'verify_peer' => false,
  78 + 'verify_peer_name' => false
  79 + ]
  80 + ];
  81 + $file_handle = fopen($url, 'r', null, stream_context_create($opts));
  82 + while (!feof($file_handle)) {
  83 + $line_of_text[] = fgetcsv($file_handle, 0, ',');
  84 + }
  85 + fclose($file_handle);
  86 + foreach ($line_of_text as $k => $val){
  87 +
  88 + }
  89 + }
  90 +
  91 + /**
62 * @remark :导入分类 92 * @remark :导入分类
63 * @name :importProductCategory 93 * @name :importProductCategory
64 * @author :lyh 94 * @author :lyh
@@ -85,7 +115,6 @@ class LyhImportTest extends Command @@ -85,7 +115,6 @@ class LyhImportTest extends Command
85 $cateModel = new Category(); 115 $cateModel = new Category();
86 $productModel = new Product(); 116 $productModel = new Product();
87 $detailModel = new Detail(); 117 $detailModel = new Detail();
88 - $columnModel = new Column();  
89 foreach ($line_of_text as $k => $val){ 118 foreach ($line_of_text as $k => $val){
90 if($k < 2){ 119 if($k < 2){
91 continue; 120 continue;
@@ -106,8 +135,8 @@ class LyhImportTest extends Command @@ -106,8 +135,8 @@ class LyhImportTest extends Command
106 $saveData['content'] = $val[3]; 135 $saveData['content'] = $val[3];
107 $seo = ['seo_title'=>$val[5]]; 136 $seo = ['seo_title'=>$val[5]];
108 $saveData['seo_mate'] = json_encode($seo,true); 137 $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])]]; 138 + $thumb = ['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[6])];
  139 + $gallery = [['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[6])]];
111 $saveData['thumb'] = json_encode($thumb,true); 140 $saveData['thumb'] = json_encode($thumb,true);
112 $saveData['gallery'] = json_encode($gallery,true); 141 $saveData['gallery'] = json_encode($gallery,true);
113 $id = $productModel->addReturnId($saveData); 142 $id = $productModel->addReturnId($saveData);
@@ -127,22 +156,16 @@ class LyhImportTest extends Command @@ -127,22 +156,16 @@ class LyhImportTest extends Command
127 'content'=>json_encode(['content'=>$val[3]]) 156 'content'=>json_encode(['content'=>$val[3]])
128 ]; 157 ];
129 $detailModel->addReturnId($detail); 158 $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); 159 $faqsDetail = json_decode($val[4],true);
138 - $faqContent = '';  
139 if(!empty($faqsDetail) && is_array($faqsDetail)){ 160 if(!empty($faqsDetail) && is_array($faqsDetail)){
  161 + $faqContent = '<div>';
140 foreach ($faqsDetail as $faq_Val){ 162 foreach ($faqsDetail as $faq_Val){
141 - $faqContent .= "question:".$faq_Val['question'] . "<br />" . "answer:".$faq_Val['answer']. "<br />"; 163 + $faqContent .= "<span>question:".$faq_Val['question'] . "</span><br /><span>" . "answer:".$faq_Val['answer']. "</span><br />";
142 } 164 }
  165 + $faqContent .= '</div>';
143 $detailFaqInfo = [ 166 $detailFaqInfo = [
144 'product_id'=>$id, 167 'product_id'=>$id,
145 - 'column_id'=>$faqId, 168 + 'column_id'=>1,
146 'text_type'=>1, 169 'text_type'=>1,
147 'content'=>json_encode(['content'=>$faqContent]) 170 'content'=>json_encode(['content'=>$faqContent])
148 ]; 171 ];