作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !2978
... ... @@ -49,7 +49,120 @@ class Temp extends Command
public function handle()
{
$this->inquiryAiCheck(17259, 27468);
}
/**
* 4301项目特殊产品数据导入
* @return bool
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @author Akun
* @date 2025/10/21 10:11
*/
public function specialImport4301()
{
$file_url = 'D:\work\特维整理后表格.csv';
$project_id = 4301;
$img_path = '/upload/p/' . $project_id . '/image_product/2025-10/';
$is_gbk = 0;
$file_code_type = $this->get_code_type($file_url);
if ($file_code_type === false) {
$this->output('import fail, error: 文件编码格式错误');
return true;
} elseif ($file_code_type === 'GBK') {
$is_gbk = 1;
setlocale(LC_ALL, 'zh_CN');
}
//读取csv文件
$line_of_text = [];
try {
$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($file_url, 'r', null, stream_context_create($opts));
while (!feof($file_handle)) {
$line_of_text[] = fgetcsv($file_handle, 0, ',');
}
fclose($file_handle);
} catch (\Exception $e) {
$this->output('import fail, error: ' . $e->getMessage());
return true;
}
$new_csv = [];
if (count($line_of_text) > 1) {
foreach ($line_of_text as $k => $v) {
if ($k > 0 && isset($v[0]) && $v[0]) {
if ($is_gbk) {
foreach ($v as $kk => $vv) {
$v[$kk] = mb_convert_encoding($vv, 'utf-8', 'gbk');
}
}
$images = glob('D:\work\特维产品图\TW24\\' . $v[8] . '*');
$new_images = [];
foreach ($images as $img) {
$img_arr = explode('\\', $img);
$new_images[] = getImageUrl($img_path . end($img_arr), 1);
}
$new_csv[] = [
$this->special2str($v[0]),
$v[1],
$v[2],
$v[3],
Arr::a2s([
'Number' => $v[8],
'Price' => $v[9],
'Unit' => $v[10],
'Packaging' => $v[11],
'Length' => $v[12],
'Width' => $v[13],
'Height' => $v[14],
'Box Length' => $v[15],
'Box Width' => $v[16],
'Box Height' => $v[17],
'Material Volume' => $v[18],
'Volume' => $v[19],
'Box Number' => $v[20],
'Weight' => $v[21],
'Product Weight' => $v[22],
'Category' => $v[23],
'Color' => $v[24],
'Minimum Order Quantity' => $v[25],
]),
$v[5],
$v[6],
implode('^v6sp$', $new_images)
];
}
}
}
$map = ['产品标题', '自定义路由', '分类(支持多级,用 ^v6sp$ 分割)', '关键词(支持多个,用 ^v6sp$分割)', '参数(json格式)', '短描述', '产品描述', '产品图片集(支持多张,用 ^v6sp$ 分割)'];
//生成文件,发送到客户端
if ($new_csv) {
$table = new BatchExportService($project_id . '_products_need_import');
$file = $table->head($map)->data($new_csv)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
} else {
$this->output('export success');
}
} else {
$this->output('no data');
}
return true;
}
/**
... ... @@ -159,7 +272,7 @@ class Temp extends Command
* @author Akun
* @date 2025/06/05 10:47
*/
public function specialImport()
public function specialImport3531()
{
$file_url = 'https://ecdn6.globalso.com/upload/p/3531/file/2025-07/www-cninfo-com-cn_news_v1-2.csv';
$domain = 'static.cninfo.com.cn';
... ...