作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !2978
@@ -49,7 +49,120 @@ class Temp extends Command @@ -49,7 +49,120 @@ class Temp extends Command
49 49
50 public function handle() 50 public function handle()
51 { 51 {
52 - $this->inquiryAiCheck(17259, 27468); 52 +
  53 + }
  54 +
  55 + /**
  56 + * 4301项目特殊产品数据导入
  57 + * @return bool
  58 + * @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
  59 + * @author Akun
  60 + * @date 2025/10/21 10:11
  61 + */
  62 + public function specialImport4301()
  63 + {
  64 + $file_url = 'D:\work\特维整理后表格.csv';
  65 + $project_id = 4301;
  66 + $img_path = '/upload/p/' . $project_id . '/image_product/2025-10/';
  67 +
  68 + $is_gbk = 0;
  69 + $file_code_type = $this->get_code_type($file_url);
  70 + if ($file_code_type === false) {
  71 + $this->output('import fail, error: 文件编码格式错误');
  72 + return true;
  73 + } elseif ($file_code_type === 'GBK') {
  74 + $is_gbk = 1;
  75 + setlocale(LC_ALL, 'zh_CN');
  76 + }
  77 +
  78 + //读取csv文件
  79 + $line_of_text = [];
  80 + try {
  81 + $opts = [
  82 + 'http' => [
  83 + 'method' => 'GET',
  84 + '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'
  85 + ],
  86 + 'ssl' => [
  87 + 'verify_peer' => false,
  88 + 'verify_peer_name' => false
  89 + ]
  90 + ];
  91 + $file_handle = fopen($file_url, 'r', null, stream_context_create($opts));
  92 + while (!feof($file_handle)) {
  93 + $line_of_text[] = fgetcsv($file_handle, 0, ',');
  94 + }
  95 + fclose($file_handle);
  96 + } catch (\Exception $e) {
  97 + $this->output('import fail, error: ' . $e->getMessage());
  98 + return true;
  99 + }
  100 +
  101 + $new_csv = [];
  102 + if (count($line_of_text) > 1) {
  103 + foreach ($line_of_text as $k => $v) {
  104 + if ($k > 0 && isset($v[0]) && $v[0]) {
  105 +
  106 + if ($is_gbk) {
  107 + foreach ($v as $kk => $vv) {
  108 + $v[$kk] = mb_convert_encoding($vv, 'utf-8', 'gbk');
  109 + }
  110 + }
  111 +
  112 + $images = glob('D:\work\特维产品图\TW24\\' . $v[8] . '*');
  113 + $new_images = [];
  114 + foreach ($images as $img) {
  115 + $img_arr = explode('\\', $img);
  116 + $new_images[] = getImageUrl($img_path . end($img_arr), 1);
  117 + }
  118 + $new_csv[] = [
  119 + $this->special2str($v[0]),
  120 + $v[1],
  121 + $v[2],
  122 + $v[3],
  123 + Arr::a2s([
  124 + 'Number' => $v[8],
  125 + 'Price' => $v[9],
  126 + 'Unit' => $v[10],
  127 + 'Packaging' => $v[11],
  128 + 'Length' => $v[12],
  129 + 'Width' => $v[13],
  130 + 'Height' => $v[14],
  131 + 'Box Length' => $v[15],
  132 + 'Box Width' => $v[16],
  133 + 'Box Height' => $v[17],
  134 + 'Material Volume' => $v[18],
  135 + 'Volume' => $v[19],
  136 + 'Box Number' => $v[20],
  137 + 'Weight' => $v[21],
  138 + 'Product Weight' => $v[22],
  139 + 'Category' => $v[23],
  140 + 'Color' => $v[24],
  141 + 'Minimum Order Quantity' => $v[25],
  142 + ]),
  143 + $v[5],
  144 + $v[6],
  145 + implode('^v6sp$', $new_images)
  146 + ];
  147 + }
  148 + }
  149 + }
  150 +
  151 + $map = ['产品标题', '自定义路由', '分类(支持多级,用 ^v6sp$ 分割)', '关键词(支持多个,用 ^v6sp$分割)', '参数(json格式)', '短描述', '产品描述', '产品图片集(支持多张,用 ^v6sp$ 分割)'];
  152 + //生成文件,发送到客户端
  153 + if ($new_csv) {
  154 + $table = new BatchExportService($project_id . '_products_need_import');
  155 + $file = $table->head($map)->data($new_csv)->save();
  156 + if (!$file) {
  157 + $this->output('文件生成失败,请重试');
  158 + } else {
  159 + $this->output('export success');
  160 + }
  161 + } else {
  162 + $this->output('no data');
  163 + }
  164 +
  165 + return true;
53 } 166 }
54 167
55 /** 168 /**
@@ -159,7 +272,7 @@ class Temp extends Command @@ -159,7 +272,7 @@ class Temp extends Command
159 * @author Akun 272 * @author Akun
160 * @date 2025/06/05 10:47 273 * @date 2025/06/05 10:47
161 */ 274 */
162 - public function specialImport() 275 + public function specialImport3531()
163 { 276 {
164 $file_url = 'https://ecdn6.globalso.com/upload/p/3531/file/2025-07/www-cninfo-com-cn_news_v1-2.csv'; 277 $file_url = 'https://ecdn6.globalso.com/upload/p/3531/file/2025-07/www-cninfo-com-cn_news_v1-2.csv';
165 $domain = 'static.cninfo.com.cn'; 278 $domain = 'static.cninfo.com.cn';