作者 lyh

gx数据

@@ -17,6 +17,7 @@ use App\Models\Product\Category; @@ -17,6 +17,7 @@ use App\Models\Product\Category;
17 use App\Models\Product\CategoryRelated; 17 use App\Models\Product\CategoryRelated;
18 use App\Models\Product\Column; 18 use App\Models\Product\Column;
19 use App\Models\Product\Detail; 19 use App\Models\Product\Detail;
  20 +use App\Models\Product\ExtendInfo;
20 use App\Models\Product\Product; 21 use App\Models\Product\Product;
21 use App\Models\RouteMap\RouteMap; 22 use App\Models\RouteMap\RouteMap;
22 use App\Models\Template\BTemplate; 23 use App\Models\Template\BTemplate;
@@ -140,6 +141,7 @@ class LyhImportTest extends Command @@ -140,6 +141,7 @@ class LyhImportTest extends Command
140 $productModel = new Product(); 141 $productModel = new Product();
141 $detailModel = new Detail(); 142 $detailModel = new Detail();
142 $columnModel = new Column(); 143 $columnModel = new Column();
  144 + $extentInfoModel = new ExtendInfo();
143 foreach ($line_of_text as $k => $val){ 145 foreach ($line_of_text as $k => $val){
144 if($k < 1){ 146 if($k < 1){
145 continue; 147 continue;
@@ -156,42 +158,110 @@ class LyhImportTest extends Command @@ -156,42 +158,110 @@ class LyhImportTest extends Command
156 $saveData['category_id'] = ','.$cateInfo['id'].','; 158 $saveData['category_id'] = ','.$cateInfo['id'].',';
157 } 159 }
158 } 160 }
159 - if(!empty($val[2])){  
160 -  
161 - }  
162 - $saveData['intro'] = $val[2];  
163 - $saveData['content'] = $val[3];  
164 - $seo = ['seo_title'=>$val[5]]; 161 + $saveData['intro'] = $val[6] ?? '';
  162 + $seo = ['seo_title'=>$val[0]];
165 $saveData['seo_mate'] = json_encode($seo,true); 163 $saveData['seo_mate'] = json_encode($seo,true);
166 - $thumb = ['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[6])];  
167 - $gallery = [['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[6])]]; 164 + $thumb = ['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[11])];
  165 + $gallery = [['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[11])]];
168 $saveData['thumb'] = json_encode($thumb,true); 166 $saveData['thumb'] = json_encode($thumb,true);
169 $saveData['gallery'] = json_encode($gallery,true); 167 $saveData['gallery'] = json_encode($gallery,true);
170 $id = $productModel->addReturnId($saveData); 168 $id = $productModel->addReturnId($saveData);
171 - echo date('Y-m-d H:i:s') . '新增产品id:'.$id . PHP_EOL;  
172 //设置关联关系 169 //设置关联关系
173 if($cateInfo !== false){ 170 if($cateInfo !== false){
174 CategoryRelated::saveRelated($id,[$cateInfo['id']]); 171 CategoryRelated::saveRelated($id,[$cateInfo['id']]);
175 } 172 }
176 //设置路由 173 //设置路由
177 - $route = RouteMap::setRoute($val[1],RouteMap::SOURCE_PRODUCT,$id,$project_id); 174 + $route = RouteMap::setRoute($val[0],RouteMap::SOURCE_PRODUCT,$id,$project_id);
178 $productModel->edit(['route'=>$route],['id'=>$id]); 175 $productModel->edit(['route'=>$route],['id'=>$id]);
  176 + echo date('Y-m-d H:i:s') . '新增产品id:'.$id . PHP_EOL;
  177 + if(!empty($val[2])){
  178 + $extent = [
  179 + 'key'=>'pd_extended_field_4',
  180 + 'product_id'=>$id,
  181 + 'project_id'=>$project_id,
  182 + 'values'=>$val[2],
  183 + ];
  184 + $extentInfoModel->addReturnId($extent);
  185 + }
  186 + if(!empty($val[3])){
  187 + $extent = [
  188 + 'key'=>'pd_extended_field_1',
  189 + 'product_id'=>$id,
  190 + 'project_id'=>$project_id,
  191 + 'values'=>$val[3],
  192 + ];
  193 + $extentInfoModel->addReturnId($extent);
  194 + }
  195 + if(!empty($val[4])){
  196 + $extent = [
  197 + 'key'=>'pd_extended_field_2',
  198 + 'product_id'=>$id,
  199 + 'project_id'=>$project_id,
  200 + 'values'=>$val[4],
  201 + ];
  202 + $extentInfoModel->addReturnId($extent);
  203 + }
  204 + if(!empty($val[5])){
  205 + $extent = [
  206 + 'key'=>'pd_extended_field_3',
  207 + 'product_id'=>$id,
  208 + 'project_id'=>$project_id,
  209 + 'values'=>$val[5],
  210 + ];
  211 + $extentInfoModel->addReturnId($extent);
  212 + }
  213 + //产品描述
  214 + if(!empty($val[7])){
  215 + //设置产品描述
  216 + $detail = [
  217 + 'title'=>'SEODescription',
  218 + 'product_id'=>$id,
  219 + 'column_id'=>1,
  220 + 'text_type'=>1,
  221 + 'content'=>json_encode(['content'=>$val[7]])
  222 + ];
  223 + $detailModel->addReturnId($detail);
  224 + }
  225 + //产品描述
  226 + if(!empty($val[8])){
179 //设置产品描述 227 //设置产品描述
180 $detail = [ 228 $detail = [
  229 + 'title'=>'SEOSpecification',
181 'product_id'=>$id, 230 'product_id'=>$id,
182 'column_id'=>1, 231 'column_id'=>1,
183 'text_type'=>1, 232 'text_type'=>1,
184 - 'content'=>json_encode(['content'=>$val[3]]) 233 + 'content'=>json_encode(['content'=>$val[8]])
185 ]; 234 ];
186 $detailModel->addReturnId($detail); 235 $detailModel->addReturnId($detail);
187 - //扩展描述设置  
188 - $detailFaq = [  
189 - 'column_name'=>'FAQs',  
190 - 'product_id'=>$id 236 + }
  237 + if(!empty($val[9])){
  238 + try {
  239 + $faqsDetail = json_decode($val[9],true);
  240 + if(!empty($faqsDetail) && is_array($faqsDetail)){
  241 + $faqContent = '<div>';
  242 + foreach ($faqsDetail as $faq_Val){
  243 + $faqContent .= "<span>question:".$faq_Val['question'] . "</span><br /><span>" . "answer:".$faq_Val['answer']. "</span><br />";
  244 + }
  245 + $faqContent .= '</div>';
  246 + $detailFaqInfo = [
  247 + 'title'=>'SEOQandA',
  248 + 'product_id'=>$id,
  249 + 'column_id'=>1,
  250 + 'text_type'=>1,
  251 + 'content'=>json_encode(['content'=>$faqContent])
191 ]; 252 ];
192 - $faqId = $columnModel->addReturnId($detailFaq);  
193 -  
194 - $faqsDetail = json_decode($val[4],true); 253 + $detailModel->addReturnId($detailFaqInfo);
  254 + }else{
  255 + @file_put_contents(storage_path('logs/lyh_error.log'), var_export('产品标题:'. $val[0] . PHP_EOL .'faqs数据有问题:' . $val[9], true) . PHP_EOL, FILE_APPEND);
  256 + echo date('Y-m-d H:i:s') . '产品标题:'. $val[0] . PHP_EOL .'faqs数据有问题:' . $val[9];
  257 + }
  258 + }catch(\Exception $e){
  259 + echo 'fqs';
  260 + }
  261 + }
  262 + if(!empty($val[10])){
  263 + try {
  264 + $faqsDetail = json_decode($val[10],true);
195 if(!empty($faqsDetail) && is_array($faqsDetail)){ 265 if(!empty($faqsDetail) && is_array($faqsDetail)){
196 $faqContent = '<div>'; 266 $faqContent = '<div>';
197 foreach ($faqsDetail as $faq_Val){ 267 foreach ($faqsDetail as $faq_Val){
@@ -199,15 +269,20 @@ class LyhImportTest extends Command @@ -199,15 +269,20 @@ class LyhImportTest extends Command
199 } 269 }
200 $faqContent .= '</div>'; 270 $faqContent .= '</div>';
201 $detailFaqInfo = [ 271 $detailFaqInfo = [
  272 + 'title'=>'SEOQandA_Product',
202 'product_id'=>$id, 273 'product_id'=>$id,
203 - 'column_id'=>$faqId, 274 + 'column_id'=>1,
204 'text_type'=>1, 275 'text_type'=>1,
205 'content'=>json_encode(['content'=>$faqContent]) 276 'content'=>json_encode(['content'=>$faqContent])
206 ]; 277 ];
207 $detailModel->addReturnId($detailFaqInfo); 278 $detailModel->addReturnId($detailFaqInfo);
208 }else{ 279 }else{
209 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export('产品标题:'. $val[1] . PHP_EOL .'faqs数据有问题:' . $val[4], true) . PHP_EOL, FILE_APPEND);  
210 - echo date('Y-m-d H:i:s') . '产品标题:'. $val[1] . PHP_EOL .'faqs数据有问题:' . $val[4]; 280 + @file_put_contents(storage_path('logs/lyh_error.log'), var_export('产品标题:'. $val[0] . PHP_EOL .'faqs数据有问题:' . $val[10], true) . PHP_EOL, FILE_APPEND);
  281 + echo date('Y-m-d H:i:s') . '产品标题:'. $val[0] . PHP_EOL .'SEOQandA_Product数据有问题:' . $val[10];
  282 + }
  283 + }catch(\Exception $e){
  284 + continue;
  285 + }
211 } 286 }
212 } 287 }
213 return true; 288 return true;