|
...
|
...
|
@@ -51,14 +51,63 @@ 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->importProductCategory('https://ecdn6.globalso.com/upload/p/3283/file/2025-03/zy_boss_pricelistcat_202503131025.csv','3283');
|
|
|
|
// $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);
|
|
|
|
$categoryModel = new Category();
|
|
|
|
foreach ($line_of_text as $k => $val){
|
|
|
|
if($k < 1){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(empty($val[1])){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$id = $categoryModel->addReturnId(['project_id'=>$project_id,'title'=>$val[1],'seo_title'=>$val[0],'seo_keyword'=>$val[2]]);
|
|
|
|
$pid = 0;
|
|
|
|
if($val[2] != 0){
|
|
|
|
//查询上级id
|
|
|
|
$pidCate = $categoryModel->read(['seo_title'=>$val[2]]);
|
|
|
|
if($pidCate !== false){
|
|
|
|
$pid = $pidCate['id'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$route = RouteMap::setRoute($val[1],RouteMap::SOURCE_PRODUCT_CATE,$id,$project_id);
|
|
|
|
$categoryModel->edit(['route'=>$route,'pid'=>$pid],['id'=>$id]);
|
|
|
|
echo date('Y-m-d H:i:s') . '产品分类id:'. $id;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :导入分类
|
|
|
|
* @name :importProductCategory
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -85,7 +134,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 +154,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 +175,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])
|
|
|
|
];
|
...
|
...
|
|