合并分支 'akun' 到 'master'
Akun 查看合并请求 !91
正在显示
3 个修改的文件
包含
1 行增加
和
335 行删除
| @@ -244,7 +244,7 @@ class ProjectUpdate extends Command | @@ -244,7 +244,7 @@ class ProjectUpdate extends Command | ||
| 244 | for ($i = 0; $i < count($item['category']); $i++) { | 244 | for ($i = 0; $i < count($item['category']); $i++) { |
| 245 | $return = $this->get_category_name_arr($item['category'], $pid); | 245 | $return = $this->get_category_name_arr($item['category'], $pid); |
| 246 | if ($return) { | 246 | if ($return) { |
| 247 | - $category_arr[] = $return['name']; | 247 | + $category_arr[] = $this->special2str($return['name']); |
| 248 | $pid = $return['id']; | 248 | $pid = $return['id']; |
| 249 | } | 249 | } |
| 250 | } | 250 | } |
app/Console/Commands/Update/Temp.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Console\Commands\Update; | ||
| 4 | - | ||
| 5 | -use App\Helper\Arr; | ||
| 6 | -use App\Http\Logic\Bside\Product\CategoryLogic; | ||
| 7 | -use App\Models\Blog\Blog; | ||
| 8 | -use App\Models\Collect\CollectTask; | ||
| 9 | -use App\Models\Com\UpdateLog; | ||
| 10 | -use App\Models\News\News; | ||
| 11 | -use App\Models\Product\Category; | ||
| 12 | -use App\Models\Product\Keyword; | ||
| 13 | -use App\Models\Product\Product; | ||
| 14 | -use App\Models\RouteMap\RouteMap; | ||
| 15 | -use App\Models\Template\BCustomTemplate; | ||
| 16 | -use App\Models\WebSetting\WebSettingReceiving; | ||
| 17 | -use App\Services\ProjectServer; | ||
| 18 | -use Illuminate\Console\Command; | ||
| 19 | -use Illuminate\Support\Facades\DB; | ||
| 20 | -use Illuminate\Support\Facades\Redis; | ||
| 21 | - | ||
| 22 | -/** | ||
| 23 | - * 4.0,5.0升级到6.0,内容同步 | ||
| 24 | - * Class ProjectImport | ||
| 25 | - * @package App\Console\Commands | ||
| 26 | - * @author Akun | ||
| 27 | - * @date 2023/10/9 15:04 | ||
| 28 | - */ | ||
| 29 | -class Temp extends Command | ||
| 30 | -{ | ||
| 31 | - /** | ||
| 32 | - * The name and signature of the console command. | ||
| 33 | - * | ||
| 34 | - * @var string | ||
| 35 | - */ | ||
| 36 | - protected $signature = 'project_update_temp'; | ||
| 37 | - | ||
| 38 | - /** | ||
| 39 | - * The console command description. | ||
| 40 | - * | ||
| 41 | - * @var string | ||
| 42 | - */ | ||
| 43 | - protected $description = '执行项目升级任务'; | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - public function handle() | ||
| 47 | - { | ||
| 48 | - $this->start_update(); | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - protected function start_update() | ||
| 52 | - { | ||
| 53 | - | ||
| 54 | -// $data = UpdateLog::where('project_id','<=',530)->where('api_type','category')->get(); | ||
| 55 | - $data = UpdateLog::where('project_id', '=', 298)->where('api_type', 'category')->get(); | ||
| 56 | - foreach ($data as $task) { | ||
| 57 | - $project_id = $task->project_id; | ||
| 58 | - $api_type = $task->api_type; | ||
| 59 | - $api_url_arr = explode('?', $task->api_url); | ||
| 60 | - $api_url = $api_url_arr[0]; | ||
| 61 | - | ||
| 62 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL; | ||
| 63 | - | ||
| 64 | - //设置数据库 | ||
| 65 | - $project = ProjectServer::useProject($project_id); | ||
| 66 | - if ($project) { | ||
| 67 | - //分类 | ||
| 68 | - $url = $api_url . '?' . http_build_query(['w' => 'category']); | ||
| 69 | - $data = curl_c($url); | ||
| 70 | - if (isset($data['code']) && $data['code'] == 200) { | ||
| 71 | - $items = $data['data'] ?? []; | ||
| 72 | - $this->category_insert($project_id, $items, 0); | ||
| 73 | - } else { | ||
| 74 | - continue; | ||
| 75 | - } | ||
| 76 | - } | ||
| 77 | - //关闭数据库 | ||
| 78 | - DB::disconnect('custom_mysql'); | ||
| 79 | - | ||
| 80 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL; | ||
| 81 | - } | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - //获取地址路由 | ||
| 85 | - protected function get_url_route($url) | ||
| 86 | - { | ||
| 87 | - $arr = parse_url($url); | ||
| 88 | - if (empty($arr['path'])) { | ||
| 89 | - return ''; | ||
| 90 | - } | ||
| 91 | - $path = $arr['path']; | ||
| 92 | - | ||
| 93 | - if (strpos($path, '.') !== false) { | ||
| 94 | - $path = substr($path, 0, strpos($path, '.')); | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - $path_arr = explode('/', $path); | ||
| 98 | - | ||
| 99 | - return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2]; | ||
| 100 | - } | ||
| 101 | - | ||
| 102 | - //多级分类入库 | ||
| 103 | - protected function category_insert($project_id, $items, $pid = 0) | ||
| 104 | - { | ||
| 105 | - $model = new Category(); | ||
| 106 | - foreach ($items as $item) { | ||
| 107 | - if ($item['name'] ?? '') { | ||
| 108 | - $parent = $model->read(['pid' => $pid, 'title' => $item['name']], 'id'); | ||
| 109 | - if (!$parent) { | ||
| 110 | - try { | ||
| 111 | - $item['name'] = $this->special2str($item['name']); | ||
| 112 | - $parent_id = $model->addReturnId([ | ||
| 113 | - 'project_id' => $project_id, | ||
| 114 | - 'title' => $item['name'], | ||
| 115 | - 'pid' => $pid, | ||
| 116 | - 'keywords' => $item['keywords'] ?? '', | ||
| 117 | - 'describe' => $item['description'] ?? '', | ||
| 118 | - 'route' => $this->get_url_route($item['url']) | ||
| 119 | - ]); | ||
| 120 | - $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id); | ||
| 121 | - } catch (\Exception $e) { | ||
| 122 | - echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL; | ||
| 123 | - continue; | ||
| 124 | - } | ||
| 125 | - } else { | ||
| 126 | - $parent_id = $parent['id']; | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - if (!empty($item['children'])) { | ||
| 130 | - $this->category_insert($project_id, $item['children'], $parent_id); | ||
| 131 | - } | ||
| 132 | - } | ||
| 133 | - } | ||
| 134 | - } | ||
| 135 | - | ||
| 136 | - //获取分类名称数组 | ||
| 137 | - protected function get_category_name_arr($category, $pid = 0) | ||
| 138 | - { | ||
| 139 | - foreach ($category as $k => $v) { | ||
| 140 | - if ($v['parent'] == $pid) { | ||
| 141 | - return $v; | ||
| 142 | - } | ||
| 143 | - } | ||
| 144 | - | ||
| 145 | - return []; | ||
| 146 | - } | ||
| 147 | - | ||
| 148 | - //特殊字符转换 | ||
| 149 | - protected function special2str($str) | ||
| 150 | - { | ||
| 151 | - if (strpos($str, ';') === false) { | ||
| 152 | - return $str; | ||
| 153 | - } | ||
| 154 | - | ||
| 155 | - $list = [ | ||
| 156 | - '<' => '<', | ||
| 157 | - '>' => '>', | ||
| 158 | - '&' => '&', | ||
| 159 | - '´' => '´', | ||
| 160 | - '"' => '“', | ||
| 161 | - ' ' => ' ' | ||
| 162 | - ]; | ||
| 163 | - | ||
| 164 | - foreach ($list as $k => $v) { | ||
| 165 | - $str = str_replace($k, $v, $str); | ||
| 166 | - } | ||
| 167 | - | ||
| 168 | - return $str; | ||
| 169 | - } | ||
| 170 | - | ||
| 171 | - //路由入库 | ||
| 172 | - protected function set_map($route, $source, $source_id, $project_id) | ||
| 173 | - { | ||
| 174 | - if ($route) { | ||
| 175 | - $route_map = RouteMap::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->first(); | ||
| 176 | - if (!$route_map) { | ||
| 177 | - $route_map = new RouteMap(); | ||
| 178 | - $route_map->project_id = $project_id; | ||
| 179 | - $route_map->source = $source; | ||
| 180 | - $route_map->source_id = $source_id; | ||
| 181 | - $route_map->route = $route; | ||
| 182 | - | ||
| 183 | - if ($source == RouteMap::SOURCE_NEWS) { | ||
| 184 | - $route_map->path = RouteMap::SOURCE_NEWS; | ||
| 185 | - } elseif ($source == RouteMap::SOURCE_BLOG) { | ||
| 186 | - $route_map->path = RouteMap::SOURCE_BLOG; | ||
| 187 | - } | ||
| 188 | - | ||
| 189 | - $route_map->save(); | ||
| 190 | - } | ||
| 191 | - } | ||
| 192 | - } | ||
| 193 | -} |
app/Console/Commands/Update/Temp2.php
已删除
100644 → 0
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Console\Commands\Update; | ||
| 4 | - | ||
| 5 | -use App\Helper\Arr; | ||
| 6 | -use App\Http\Logic\Bside\Product\CategoryLogic; | ||
| 7 | -use App\Models\Blog\Blog; | ||
| 8 | -use App\Models\Collect\CollectTask; | ||
| 9 | -use App\Models\Com\UpdateLog; | ||
| 10 | -use App\Models\News\News; | ||
| 11 | -use App\Models\Product\Category; | ||
| 12 | -use App\Models\Product\Keyword; | ||
| 13 | -use App\Models\Product\Product; | ||
| 14 | -use App\Models\RouteMap\RouteMap; | ||
| 15 | -use App\Models\Template\BCustomTemplate; | ||
| 16 | -use App\Models\WebSetting\WebSettingReceiving; | ||
| 17 | -use App\Services\ProjectServer; | ||
| 18 | -use Illuminate\Console\Command; | ||
| 19 | -use Illuminate\Support\Facades\DB; | ||
| 20 | -use Illuminate\Support\Facades\Redis; | ||
| 21 | - | ||
| 22 | -/** | ||
| 23 | - * 4.0,5.0升级到6.0,内容同步 | ||
| 24 | - * Class ProjectImport | ||
| 25 | - * @package App\Console\Commands | ||
| 26 | - * @author Akun | ||
| 27 | - * @date 2023/10/9 15:04 | ||
| 28 | - */ | ||
| 29 | -class Temp2 extends Command | ||
| 30 | -{ | ||
| 31 | - /** | ||
| 32 | - * The name and signature of the console command. | ||
| 33 | - * | ||
| 34 | - * @var string | ||
| 35 | - */ | ||
| 36 | - protected $signature = 'project_update_temp2'; | ||
| 37 | - | ||
| 38 | - /** | ||
| 39 | - * The console command description. | ||
| 40 | - * | ||
| 41 | - * @var string | ||
| 42 | - */ | ||
| 43 | - protected $description = '执行项目升级任务'; | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - public function handle() | ||
| 47 | - { | ||
| 48 | - $this->start_update(); | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - protected function start_update() | ||
| 52 | - { | ||
| 53 | - | ||
| 54 | -// $data = UpdateLog::where('project_id','<=',530)->where('api_type','category')->get(); | ||
| 55 | - $data = UpdateLog::where('project_id', '=', 298)->where('api_type', 'post')->get(); | ||
| 56 | - foreach ($data as $task) { | ||
| 57 | - $project_id = $task->project_id; | ||
| 58 | - $api_type = $task->api_type; | ||
| 59 | - $api_url_arr = explode('?', $task->api_url); | ||
| 60 | - $api_url = $api_url_arr[0]; | ||
| 61 | - | ||
| 62 | - $page_size = 20; | ||
| 63 | - | ||
| 64 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL; | ||
| 65 | - | ||
| 66 | - //设置数据库 | ||
| 67 | - $project = ProjectServer::useProject($project_id); | ||
| 68 | - if ($project) { | ||
| 69 | - //产品 | ||
| 70 | - $url = $api_url . '?' . http_build_query(['w' => 'post', 'page' => 1, 'pagesize' => 0]); | ||
| 71 | - $data = curl_c($url); | ||
| 72 | - if (isset($data['code']) && $data['code'] == 200) { | ||
| 73 | - $count = $data['data']['count'] ?? 0; | ||
| 74 | - | ||
| 75 | - $total_page = ceil($count / $page_size); | ||
| 76 | - for ($page = 1; $page <= $total_page; $page++) { | ||
| 77 | - $url_page = $api_url . '?' . http_build_query(['w' => 'post', 'page' => $page, 'pagesize' => $page_size]); | ||
| 78 | - $data_page = curl_c($url_page); | ||
| 79 | - if (isset($data_page['code']) && $data_page['code'] == 200) { | ||
| 80 | - $items = $data_page['data']['data'] ?? []; | ||
| 81 | - | ||
| 82 | - $model = new Product(); | ||
| 83 | - | ||
| 84 | - foreach ($items as $item) { | ||
| 85 | - if ($item['ttile'] ?? '') { | ||
| 86 | - $product = $model->read(['title' => $item['ttile']], 'id'); | ||
| 87 | - if ($product) { | ||
| 88 | - //分类 | ||
| 89 | - $category_id = ''; | ||
| 90 | - if ($item['category'] ?? []) { | ||
| 91 | - $category_arr = []; | ||
| 92 | - | ||
| 93 | - $pid = 0; | ||
| 94 | - for ($i = 0; $i < count($item['category']); $i++) { | ||
| 95 | - $return = $this->get_category_name_arr($item['category'], $pid); | ||
| 96 | - if ($return) { | ||
| 97 | - $category_arr[] = $return['name']; | ||
| 98 | - $pid = $return['id']; | ||
| 99 | - } | ||
| 100 | - } | ||
| 101 | - | ||
| 102 | - if ($category_arr) { | ||
| 103 | - $categoryLogic = new CategoryLogic(); | ||
| 104 | - $category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr)); | ||
| 105 | - } | ||
| 106 | - } | ||
| 107 | - try { | ||
| 108 | - $model->edit(['category_id' => $category_id], ['id' => $product['id']]); | ||
| 109 | - } catch (\Exception $e) { | ||
| 110 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | ||
| 111 | - continue; | ||
| 112 | - } | ||
| 113 | - } | ||
| 114 | - } | ||
| 115 | - } | ||
| 116 | - } | ||
| 117 | - } | ||
| 118 | - } else { | ||
| 119 | - continue; | ||
| 120 | - } | ||
| 121 | - } | ||
| 122 | - //关闭数据库 | ||
| 123 | - DB::disconnect('custom_mysql'); | ||
| 124 | - | ||
| 125 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL; | ||
| 126 | - } | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - | ||
| 130 | - //获取分类名称数组 | ||
| 131 | - protected function get_category_name_arr($category, $pid = 0) | ||
| 132 | - { | ||
| 133 | - foreach ($category as $k => $v) { | ||
| 134 | - if ($v['parent'] == $pid) { | ||
| 135 | - return $v; | ||
| 136 | - } | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | - return []; | ||
| 140 | - } | ||
| 141 | -} |
-
请 注册 或 登录 后发表评论