合并分支 'lyh-server' 到 'master'
oa端增加根据文件更新项目tdk 查看合并请求 !2254
正在显示
1 个修改的文件
包含
98 行增加
和
12 行删除
| @@ -9,10 +9,24 @@ | @@ -9,10 +9,24 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Console\Commands\Tdk; | 10 | namespace App\Console\Commands\Tdk; |
| 11 | 11 | ||
| 12 | +use App\Models\Blog\Blog; | ||
| 13 | +use App\Models\Blog\BlogCategory; | ||
| 12 | use App\Models\Com\NoticeLog; | 14 | use App\Models\Com\NoticeLog; |
| 15 | +use App\Models\CustomModule\CustomModuleCategory; | ||
| 16 | +use App\Models\CustomModule\CustomModuleContent; | ||
| 17 | +use App\Models\News\News; | ||
| 18 | +use App\Models\News\NewsCategory; | ||
| 19 | +use App\Models\Product\Category; | ||
| 20 | +use App\Models\Product\Keyword; | ||
| 21 | +use App\Models\Product\Product; | ||
| 22 | +use App\Models\Project\Project; | ||
| 23 | +use App\Models\RouteMap\RouteMap; | ||
| 24 | +use App\Services\ProjectServer; | ||
| 13 | use Illuminate\Console\Command; | 25 | use Illuminate\Console\Command; |
| 26 | +use Illuminate\Support\Facades\DB; | ||
| 14 | use Illuminate\Support\Facades\Redis; | 27 | use Illuminate\Support\Facades\Redis; |
| 15 | use PhpOffice\PhpSpreadsheet\IOFactory; | 28 | use PhpOffice\PhpSpreadsheet\IOFactory; |
| 29 | +use function Aws\default_http_handler; | ||
| 16 | 30 | ||
| 17 | class UpdateProjectTdk extends Command | 31 | class UpdateProjectTdk extends Command |
| 18 | { | 32 | { |
| @@ -40,32 +54,48 @@ class UpdateProjectTdk extends Command | @@ -40,32 +54,48 @@ class UpdateProjectTdk extends Command | ||
| 40 | continue; | 54 | continue; |
| 41 | } | 55 | } |
| 42 | $info = $noticeLogModel->read(['id'=>$task_id]); | 56 | $info = $noticeLogModel->read(['id'=>$task_id]); |
| 43 | - if($info === false){ | 57 | + if($info !== false){ |
| 58 | + echo 'start--'.PHP_EOL; | ||
| 44 | $project_id = $info['data']['project_id'] ?? 0; | 59 | $project_id = $info['data']['project_id'] ?? 0; |
| 45 | if(empty($project_id)){ | 60 | if(empty($project_id)){ |
| 46 | echo date('Y-m-d H:i:s').'未获取到项目id.'.PHP_EOL; | 61 | echo date('Y-m-d H:i:s').'未获取到项目id.'.PHP_EOL; |
| 47 | $noticeLogModel->edit(['status'=>$noticeLogModel::STATUS_FAIL],['id'=>$task_id]); | 62 | $noticeLogModel->edit(['status'=>$noticeLogModel::STATUS_FAIL],['id'=>$task_id]); |
| 48 | continue; | 63 | continue; |
| 49 | } | 64 | } |
| 65 | + ProjectServer::useProject($project_id); | ||
| 50 | $url = $info['data']['url'] ?? ''; | 66 | $url = $info['data']['url'] ?? ''; |
| 51 | if(empty($url)){ | 67 | if(empty($url)){ |
| 52 | echo date('Y-m-d H:i:s').'未获取到项目更新文件.项目id为:'.$project_id.PHP_EOL; | 68 | echo date('Y-m-d H:i:s').'未获取到项目更新文件.项目id为:'.$project_id.PHP_EOL; |
| 53 | //未获取到文件,跳过 | 69 | //未获取到文件,跳过 |
| 54 | - $noticeLogModel->edit(['status'=>$noticeLogModel::STATUS_SUCCESS],['id'=>$task_id]); | 70 | + $noticeLogModel->edit(['status'=>$noticeLogModel::STATUS_FAIL],['id'=>$task_id]); |
| 71 | + DB::disconnect('custom_mysql'); | ||
| 55 | continue; | 72 | continue; |
| 56 | } | 73 | } |
| 57 | - if (!file_exists($url)) { | ||
| 58 | - return '文件不存在'; | ||
| 59 | - } | ||
| 60 | - | 74 | + // 下载到 Laravel storage 的临时路径 |
| 75 | + $tempPath = storage_path('app/temp_url.xlsx'); | ||
| 76 | + file_put_contents($tempPath, file_get_contents($url)); | ||
| 61 | // 载入 Excel | 77 | // 载入 Excel |
| 62 | - $spreadsheet = IOFactory::load($url); | ||
| 63 | - $sheet = $spreadsheet->getActiveSheet(); | ||
| 64 | - $rows = $sheet->toArray(); | ||
| 65 | - dd($rows); | ||
| 66 | - // 假设第一行是表头 | ||
| 67 | - $header = $rows[0]; | 78 | + try { |
| 79 | + $spreadsheet = IOFactory::load($tempPath); | ||
| 80 | + $sheet = $spreadsheet->getActiveSheet(); | ||
| 81 | + $rows = $sheet->toArray(); | ||
| 82 | + unlink($tempPath); | ||
| 83 | + }catch (\Exception $e){ | ||
| 84 | + echo '文件打不开'.PHP_EOL; | ||
| 85 | + $noticeLogModel->edit(['status'=>$noticeLogModel::STATUS_FAIL],['id'=>$task_id]); | ||
| 86 | + DB::disconnect('custom_mysql'); | ||
| 87 | + continue; | ||
| 88 | + } | ||
| 68 | $dataRows = array_slice($rows, 1); | 89 | $dataRows = array_slice($rows, 1); |
| 90 | + foreach ($dataRows as $item){ | ||
| 91 | + //获取路由 | ||
| 92 | + $route = trim($item[0],'/'); | ||
| 93 | + $route = basename($route); | ||
| 94 | + $this->updateTdk($route,$item); | ||
| 95 | + } | ||
| 96 | + echo date('Y-m-d H:i:s').',end'.PHP_EOL; | ||
| 97 | + $noticeLogModel->edit(['status'=>$noticeLogModel::STATUS_SUCCESS],['id'=>$task_id]); | ||
| 98 | + DB::disconnect('custom_mysql'); | ||
| 69 | } | 99 | } |
| 70 | } | 100 | } |
| 71 | return true; | 101 | return true; |
| @@ -93,4 +123,60 @@ class UpdateProjectTdk extends Command | @@ -93,4 +123,60 @@ class UpdateProjectTdk extends Command | ||
| 93 | } | 123 | } |
| 94 | return $task_id; | 124 | return $task_id; |
| 95 | } | 125 | } |
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * @remark :更新tdk | ||
| 129 | + * @name :updateTdk | ||
| 130 | + * @author :lyh | ||
| 131 | + * @method :post | ||
| 132 | + * @time :2025/7/2 14:59 | ||
| 133 | + */ | ||
| 134 | + public function updateTdk($route,$item){ | ||
| 135 | + $routeMapModel = new RouteMap(); | ||
| 136 | + $routeInfo = $routeMapModel->read(['route'=>$route]); | ||
| 137 | + if($routeInfo === false){ | ||
| 138 | + return false; | ||
| 139 | + } | ||
| 140 | + switch ($routeInfo['source']){ | ||
| 141 | + case $routeMapModel::SOURCE_PRODUCT: | ||
| 142 | + $productModel = new Product(); | ||
| 143 | + $productModel->edit(['seo_mate'=>json_encode(['title'=>$item[1],'description'=>$item[2],'keyword'=>$item[3]])],['id'=>$routeInfo['source_id']]); | ||
| 144 | + break; | ||
| 145 | + case $routeMapModel::SOURCE_PRODUCT_CATE: | ||
| 146 | + $productCategoryModel = new Category(); | ||
| 147 | + $productCategoryModel->edit(['seo_title'=>$item[1],'seo_des'=>$item[2],'seo_keywords'=>$item[3]],['id'=>$routeInfo['source_id']]); | ||
| 148 | + break; | ||
| 149 | + case $routeMapModel::SOURCE_PRODUCT_KEYWORD: | ||
| 150 | + $productKeywordModel = new Keyword(); | ||
| 151 | + $productKeywordModel->edit(['seo_title'=>$item[1],'seo_description'=>$item[2],'seo_keywords'=>$item[3]],['id'=>$routeInfo['source_id']]); | ||
| 152 | + break; | ||
| 153 | + case $routeMapModel::SOURCE_BLOG: | ||
| 154 | + $blogModel = new Blog(); | ||
| 155 | + $blogModel->edit(['seo_title'=>$item[1],'seo_description'=>$item[2],'seo_keywords'=>$item[3]],['id'=>$routeInfo['source_id']]); | ||
| 156 | + break; | ||
| 157 | + case $routeMapModel::SOURCE_BLOG_CATE: | ||
| 158 | + $blogCateModel = new BlogCategory(); | ||
| 159 | + $blogCateModel->edit(['seo_title'=>$item[1],'seo_des'=>$item[2],'seo_keywords'=>$item[3]],['id'=>$routeInfo['source_id']]); | ||
| 160 | + break; | ||
| 161 | + case $routeMapModel::SOURCE_NEWS: | ||
| 162 | + $newsModel = new News(); | ||
| 163 | + $newsModel->edit(['seo_title'=>$item[1],'seo_description'=>$item[2],'seo_keywords'=>$item[3]],['id'=>$routeInfo['source_id']]); | ||
| 164 | + break; | ||
| 165 | + case $routeMapModel::SOURCE_NEWS_CATE: | ||
| 166 | + $newsCateModel = new NewsCategory(); | ||
| 167 | + $newsCateModel->edit(['seo_title'=>$item[1],'seo_des'=>$item[2],'seo_keywords'=>$item[3]],['id'=>$routeInfo['source_id']]); | ||
| 168 | + break; | ||
| 169 | + case $routeMapModel::SOURCE_MODULE: | ||
| 170 | + $contentModel = new CustomModuleContent(); | ||
| 171 | + $contentModel->edit(['seo_title'=>$item[1],'seo_description'=>$item[2],'seo_keywords'=>$item[3]],['id'=>$routeInfo['source_id']]); | ||
| 172 | + break; | ||
| 173 | + case $routeMapModel::SOURCE_MODULE_CATE: | ||
| 174 | + $categoryModel = new CustomModuleCategory(); | ||
| 175 | + $categoryModel->edit(['seo_title'=>$item[1],'seo_description'=>$item[2],'seo_keywords'=>$item[3]],['id'=>$routeInfo['source_id']]); | ||
| 176 | + break; | ||
| 177 | + default: | ||
| 178 | + break; | ||
| 179 | + } | ||
| 180 | + return true; | ||
| 181 | + } | ||
| 96 | } | 182 | } |
-
请 注册 或 登录 后发表评论