正在显示
1 个修改的文件
包含
117 行增加
和
1 行删除
| @@ -8,9 +8,12 @@ use App\Models\Devops\ServerConfig; | @@ -8,9 +8,12 @@ use App\Models\Devops\ServerConfig; | ||
| 8 | use App\Models\Devops\ServersIp; | 8 | use App\Models\Devops\ServersIp; |
| 9 | use App\Models\Domain\DomainCreateTask; | 9 | use App\Models\Domain\DomainCreateTask; |
| 10 | use App\Models\Domain\DomainInfo; | 10 | use App\Models\Domain\DomainInfo; |
| 11 | +use App\Models\Product\Category; | ||
| 11 | use App\Models\Product\Keyword; | 12 | use App\Models\Product\Keyword; |
| 13 | +use App\Models\Product\Product; | ||
| 12 | use App\Models\Project\DeployBuild; | 14 | use App\Models\Project\DeployBuild; |
| 13 | use App\Models\Project\Project; | 15 | use App\Models\Project\Project; |
| 16 | +use App\Models\Template\BCustomTemplate; | ||
| 14 | use App\Models\WebSetting\WebLanguage; | 17 | use App\Models\WebSetting\WebLanguage; |
| 15 | use App\Services\BatchExportService; | 18 | use App\Services\BatchExportService; |
| 16 | use App\Services\ProjectServer; | 19 | use App\Services\ProjectServer; |
| @@ -35,7 +38,120 @@ class Temp extends Command | @@ -35,7 +38,120 @@ class Temp extends Command | ||
| 35 | 38 | ||
| 36 | public function handle() | 39 | public function handle() |
| 37 | { | 40 | { |
| 38 | - $this->check_server_main_site(); | 41 | + $this->importTdk(); |
| 42 | + } | ||
| 43 | + | ||
| 44 | + public function importTdk() | ||
| 45 | + { | ||
| 46 | + $project_id = 2379; | ||
| 47 | + $source = 'page'; | ||
| 48 | + $file_url = 'https://ecdn6.globalso.com/upload/p/2379/image_other/2025-04/products.csv'; | ||
| 49 | + | ||
| 50 | + //判断文件编码格式是否正确 | ||
| 51 | + $is_gbk = 0; | ||
| 52 | + $file_code_type = $this->get_code_type($file_url); | ||
| 53 | + if ($file_code_type === false) { | ||
| 54 | + $this->output('文件编码格式错误'); | ||
| 55 | + return true; | ||
| 56 | + } elseif ($file_code_type === 'GBK') { | ||
| 57 | + $is_gbk = 1; | ||
| 58 | + setlocale(LC_ALL, 'zh_CN'); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + //读取文件内容 | ||
| 62 | + //读取csv文件 | ||
| 63 | + $line_of_text = []; | ||
| 64 | + try { | ||
| 65 | + $opts = [ | ||
| 66 | + 'http' => [ | ||
| 67 | + 'method' => 'GET', | ||
| 68 | + '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' | ||
| 69 | + ], | ||
| 70 | + 'ssl' => [ | ||
| 71 | + 'verify_peer' => false, | ||
| 72 | + 'verify_peer_name' => false | ||
| 73 | + ] | ||
| 74 | + ]; | ||
| 75 | + $file_handle = fopen($file_url, 'r', null, stream_context_create($opts)); | ||
| 76 | + while (!feof($file_handle)) { | ||
| 77 | + $line_of_text[] = fgetcsv($file_handle, 0, ','); | ||
| 78 | + } | ||
| 79 | + fclose($file_handle); | ||
| 80 | + } catch (\Exception $e) { | ||
| 81 | + $this->output($e->getMessage()); | ||
| 82 | + return true; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + $success_count = 0; //成功导入条数 | ||
| 86 | + if (count($line_of_text) > 1) { | ||
| 87 | + //设置数据库 | ||
| 88 | + $project = ProjectServer::useProject($project_id); | ||
| 89 | + if ($project) { | ||
| 90 | + foreach ($line_of_text as $k => $v) { | ||
| 91 | + if ($k > 0 && isset($v[0]) && $v[0]) { | ||
| 92 | + | ||
| 93 | + if ($is_gbk) { | ||
| 94 | + foreach ($v as $kk => $vv) { | ||
| 95 | + $v[$kk] = mb_convert_encoding($vv, 'utf-8', 'gbk'); | ||
| 96 | + } | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + $url = $v[0]; | ||
| 100 | + $title = $v[1]; | ||
| 101 | + $desc = $v[2]; | ||
| 102 | + $keyword = $v[3]; | ||
| 103 | + | ||
| 104 | + $route = trim(str_replace('https://www.docareco.com/', '', $url), '/'); | ||
| 105 | + if ($route) { | ||
| 106 | + if ($source == 'page') { | ||
| 107 | + $model = new BCustomTemplate(); | ||
| 108 | + $model->edit([ | ||
| 109 | + 'title' => $title, | ||
| 110 | + 'keywords' => $keyword, | ||
| 111 | + 'description' => $desc | ||
| 112 | + ], ['url' => $route]); | ||
| 113 | + } elseif ($source == 'product_category') { | ||
| 114 | + $model = new Category(); | ||
| 115 | + $model->edit([ | ||
| 116 | + 'seo_title' => $title, | ||
| 117 | + 'seo_keywords' => $keyword, | ||
| 118 | + 'seo_des' => $desc | ||
| 119 | + ], ['route' => $route]); | ||
| 120 | + } elseif ($source == 'product') { | ||
| 121 | + $model = new Product(); | ||
| 122 | + $model->edit(['seo_mate' => Arr::a2s([ | ||
| 123 | + 'title' => $title, | ||
| 124 | + 'keyword' => $keyword, | ||
| 125 | + 'description' => $desc | ||
| 126 | + ])], ['route' => $route]); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + $success_count += 1; | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + } | ||
| 133 | + } | ||
| 134 | + //关闭数据库 | ||
| 135 | + DB::disconnect('custom_mysql'); | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + $this->output('导入tdk成功执行' . $success_count . '条'); | ||
| 139 | + | ||
| 140 | + return true; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + //判断编码格式 | ||
| 144 | + protected function get_code_type($file) | ||
| 145 | + { | ||
| 146 | + $list = array('GBK', 'UTF-8'); | ||
| 147 | + $str = curl_c($file, false); | ||
| 148 | + foreach ($list as $item) { | ||
| 149 | + $tmp = mb_convert_encoding($str, $item, $item); | ||
| 150 | + if (md5($tmp) == md5($str)) { | ||
| 151 | + return $item; | ||
| 152 | + } | ||
| 153 | + } | ||
| 154 | + return false; | ||
| 39 | } | 155 | } |
| 40 | 156 | ||
| 41 | /** | 157 | /** |
-
请 注册 或 登录 后发表评论