作者 lyh

gx数据

... ... @@ -51,14 +51,43 @@ class LyhImportTest extends Command
* @time :2023/11/20 15:13
*/
public function handle(){
// ProjectServer::useProject(3283);
// echo date('Y-m-d H:i:s') . 'start' . PHP_EOL;
ProjectServer::useProject(3283);
echo date('Y-m-d H:i:s') . 'start' . PHP_EOL;
// $this->importProduct('https://ecdn6.globalso.com/upload/p/1/file/2025-03/zy_boss_price_copy1.csv',3283);
// DB::disconnect('custom_mysql');
DB::disconnect('custom_mysql');
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :导入产品分类
* @name :productCategory
* @author :lyh
* @method :post
* @time :2025/3/13 9:58
*/
public function importProductCategory($url,$project_id){
$line_of_text = [];
$opts = [
'http' => [
'method' => 'GET',
'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'
],
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
];
$file_handle = fopen($url, 'r', null, stream_context_create($opts));
while (!feof($file_handle)) {
$line_of_text[] = fgetcsv($file_handle, 0, ',');
}
fclose($file_handle);
foreach ($line_of_text as $k => $val){
}
}
/**
* @remark :导入分类
* @name :importProductCategory
* @author :lyh
... ... @@ -85,7 +114,6 @@ class LyhImportTest extends Command
$cateModel = new Category();
$productModel = new Product();
$detailModel = new Detail();
$columnModel = new Column();
foreach ($line_of_text as $k => $val){
if($k < 2){
continue;
... ... @@ -106,8 +134,8 @@ class LyhImportTest extends Command
$saveData['content'] = $val[3];
$seo = ['seo_title'=>$val[5]];
$saveData['seo_mate'] = json_encode($seo,true);
$thumb = ['alt'=>'主图','url'=>str_replace('/public','',$val[6])];
$gallery = [['alt'=>'主图','url'=>str_replace('/public','',$val[6])]];
$thumb = ['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[6])];
$gallery = [['alt'=>'主图','url'=>str_replace('/public','/upload/p/3283',$val[6])]];
$saveData['thumb'] = json_encode($thumb,true);
$saveData['gallery'] = json_encode($gallery,true);
$id = $productModel->addReturnId($saveData);
... ... @@ -127,22 +155,16 @@ class LyhImportTest extends Command
'content'=>json_encode(['content'=>$val[3]])
];
$detailModel->addReturnId($detail);
//扩展描述设置
$detailFaq = [
'column_name'=>'FAQs',
'product_id'=>$id
];
$faqId = $columnModel->addReturnId($detailFaq);
$faqsDetail = json_decode($val[4],true);
$faqContent = '';
if(!empty($faqsDetail) && is_array($faqsDetail)){
$faqContent = '<div>';
foreach ($faqsDetail as $faq_Val){
$faqContent .= "question:".$faq_Val['question'] . "<br />" . "answer:".$faq_Val['answer']. "<br />";
$faqContent .= "<span>question:".$faq_Val['question'] . "</span><br /><span>" . "answer:".$faq_Val['answer']. "</span><br />";
}
$faqContent .= '</div>';
$detailFaqInfo = [
'product_id'=>$id,
'column_id'=>$faqId,
'column_id'=>1,
'text_type'=>1,
'content'=>json_encode(['content'=>$faqContent])
];
... ...