作者 lyh

gx

@@ -64,7 +64,7 @@ class SyncProject extends Command @@ -64,7 +64,7 @@ class SyncProject extends Command
64 while (true){ 64 while (true){
65 $list = NoticeLog::where('type', NoticeLog::TYPE_PROJECT)->where('status', NoticeLog::STATUS_PENDING)->get(); 65 $list = NoticeLog::where('type', NoticeLog::TYPE_PROJECT)->where('status', NoticeLog::STATUS_PENDING)->get();
66 foreach ($list as $item){ 66 foreach ($list as $item){
67 - echo 'start:' . $item['id'] . PHP_EOL; 67 + echo date('Y-m-d') . ' start:' . $item['id'] . PHP_EOL;
68 try { 68 try {
69 $is_update = $item['data']['is_update']??0;//是否是4.0或5.0更新到6.0 69 $is_update = $item['data']['is_update']??0;//是否是4.0或5.0更新到6.0
70 $order_id = $item['data']['order_id']; 70 $order_id = $item['data']['order_id'];
@@ -97,7 +97,7 @@ class SyncProject extends Command @@ -97,7 +97,7 @@ class SyncProject extends Command
97 $item->save(); 97 $item->save();
98 echo 'success:' . $item['id'] . PHP_EOL; 98 echo 'success:' . $item['id'] . PHP_EOL;
99 }catch (\Exception $e){ 99 }catch (\Exception $e){
100 - echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL; 100 + echo 'error:' . $item['id'] . $e->getMessage() .' line ' . $e->getLine() . PHP_EOL;
101 errorLog('项目同步失败', $item, $e); 101 errorLog('项目同步失败', $item, $e);
102 $this->retry($item, $e->getMessage()); 102 $this->retry($item, $e->getMessage());
103 } 103 }
@@ -217,7 +217,7 @@ class SyncProject extends Command @@ -217,7 +217,7 @@ class SyncProject extends Command
217 DB::beginTransaction(); 217 DB::beginTransaction();
218 try { 218 try {
219 $id = $this->saveProject($data['project']); 219 $id = $this->saveProject($data['project']);
220 - $this->setPostId($data['deploy_build']['plan'],$id);; 220 + $this->setPostId($data['deploy_build']['plan'],$id);
221 $this->savePayment($data['payment'],$id); 221 $this->savePayment($data['payment'],$id);
222 $this->saveDeployBuild($data['deploy_build'],$id); 222 $this->saveDeployBuild($data['deploy_build'],$id);
223 $this->saveDeployOptimize($data['deploy_optimize'],$id); 223 $this->saveDeployOptimize($data['deploy_optimize'],$id);
@@ -230,8 +230,16 @@ class SyncProject extends Command @@ -230,8 +230,16 @@ class SyncProject extends Command
230 //初始账号 230 //初始账号
231 $this->createUser($data['project']['mobile'],$id,$data['project']['lead_name']); 231 $this->createUser($data['project']['mobile'],$id,$data['project']['lead_name']);
232 //新增数据抓取任务 232 //新增数据抓取任务
  233 + $task_list = [];
233 foreach ($param['api_type'] as $v_type){ 234 foreach ($param['api_type'] as $v_type){
234 - UpdateLog::createLog($id,$v_type,$param['get_data_url']); 235 + if($v_type == 'category'){
  236 + UpdateLog::createLog($id,$v_type,$param['get_data_url']);
  237 + }else{
  238 + $task_list[] = $v_type;
  239 + }
  240 + }
  241 + foreach ($task_list as $task){
  242 + UpdateLog::createLog($id,$task,$param['get_data_url']);
235 } 243 }
236 } 244 }
237 DB::commit(); 245 DB::commit();
@@ -8,10 +8,12 @@ use App\Http\Logic\Bside\Product\KeywordLogic; @@ -8,10 +8,12 @@ use App\Http\Logic\Bside\Product\KeywordLogic;
8 use App\Models\Blog\Blog; 8 use App\Models\Blog\Blog;
9 use App\Models\Com\UpdateLog; 9 use App\Models\Com\UpdateLog;
10 use App\Models\News\News; 10 use App\Models\News\News;
  11 +use App\Models\Product\Category;
11 use App\Models\Product\Keyword; 12 use App\Models\Product\Keyword;
12 use App\Models\Product\Product; 13 use App\Models\Product\Product;
13 use App\Models\RouteMap\RouteMap; 14 use App\Models\RouteMap\RouteMap;
14 use App\Models\Template\BCustomTemplate; 15 use App\Models\Template\BCustomTemplate;
  16 +use App\Models\WebSetting\WebSettingReceiving;
15 use App\Services\ProjectServer; 17 use App\Services\ProjectServer;
16 use Illuminate\Console\Command; 18 use Illuminate\Console\Command;
17 use Illuminate\Support\Facades\DB; 19 use Illuminate\Support\Facades\DB;
@@ -52,7 +54,7 @@ class ProjectUpdate extends Command @@ -52,7 +54,7 @@ class ProjectUpdate extends Command
52 { 54 {
53 $task_id = $this->get_task(); 55 $task_id = $this->get_task();
54 if (!$task_id) { 56 if (!$task_id) {
55 - sleep(2); 57 + sleep(60);
56 return true; 58 return true;
57 } 59 }
58 60
@@ -77,28 +79,140 @@ class ProjectUpdate extends Command @@ -77,28 +79,140 @@ class ProjectUpdate extends Command
77 //设置数据库 79 //设置数据库
78 $project = ProjectServer::useProject($task->project_id); 80 $project = ProjectServer::useProject($task->project_id);
79 if ($project) { 81 if ($project) {
80 - if ($api_type == 'website_info') { 82 + if ($api_type == 'category') {
  83 + //分类
  84 + $url = $api_url . '?' . http_build_query(['w' => 'category']);
  85 + $data = http_get($url, ['charset' => 'UTF-8']);
  86 + if (isset($data['code']) && $data['code'] == 200) {
  87 + $items = $data['data'] ?? [];
  88 + $this->category_insert($project_id, $items, 0);
  89 +// $model = new Category();
  90 +// foreach ($items as $item) {
  91 +// $parent = $model->read(['pid' => 0, 'title' => $item['name']], 'id');
  92 +// if (!$parent) {
  93 +// try {
  94 +// $parent_id = $model->addReturnId([
  95 +// 'project_id' => $project_id,
  96 +// 'title' => $item['name'],
  97 +// 'pid' => 0,
  98 +// 'keywords' => $item['keywords'],
  99 +// 'describe' => $item['description']
  100 +// ]);
  101 +// $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
  102 +// $model->edit(['route' => $route], ['id' => $parent_id]);
  103 +// } catch (\Exception $e) {
  104 +// echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  105 +// continue;
  106 +// }
  107 +// } else {
  108 +// $parent_id = $parent['id'];
  109 +// }
  110 +//
  111 +// foreach ($item['children'] as $child) {
  112 +// $child_info = $model->read(['pid' => $parent_id, 'title' => $child['name']]);
  113 +// if (!$child_info) {
  114 +// try {
  115 +// $child_id = $model->addReturnId([
  116 +// 'project_id' => $project_id,
  117 +// 'title' => $child['name'],
  118 +// 'pid' => $parent_id,
  119 +// 'keywords' => $child['keywords'],
  120 +// 'describe' => $child['description']
  121 +// ]);
  122 +// $route = RouteMap::setRoute($child['url'] ? $this->get_url_route($child['url']) : $child['name'], RouteMap::SOURCE_PRODUCT_CATE, $child_id, $project_id);
  123 +// $model->edit(['route' => $route], ['id' => $child_id]);
  124 +// } catch (\Exception $e) {
  125 +// echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  126 +// continue;
  127 +// }
  128 +// }
  129 +// }
  130 +// }
  131 + } else {
  132 + return true;
  133 + }
  134 + } elseif ($api_type == 'tag') {
81 //关键词 135 //关键词
82 - $url = $api_url . '?' . http_build_query(['w' => 'website_info']); 136 + $url = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => 1, 'pagesize' => 0]);
83 $data = http_get($url, ['charset' => 'UTF-8']); 137 $data = http_get($url, ['charset' => 'UTF-8']);
84 if (isset($data['code']) && $data['code'] == 200) { 138 if (isset($data['code']) && $data['code'] == 200) {
85 - $items = $data['data']['tags'] ?? []; 139 + $count = $data['data']['count'] ?? 0;
  140 +
  141 + $total_page = ceil($count / $page_size);
  142 + for ($page = 1; $page <= $total_page; $page++) {
  143 + $url_page = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => $page, 'pagesize' => $page_size]);
  144 + $data_page = http_get($url_page, ['charset' => 'UTF-8']);
  145 + if (isset($data_page['code']) && $data_page['code'] == 200) {
  146 + $items = $data_page['data']['data'] ?? [];
86 147
87 - $model = new Keyword();  
88 - foreach ($items as $item) {  
89 - if (strlen($item) > 50) {  
90 - continue; 148 + $model = new Keyword();
  149 + foreach ($items as $item) {
  150 + if ($item['name'] ?? '') {
  151 + $keyword = $model->read(['title' => $item['name']], 'id');
  152 + if (!$keyword) {
  153 + try {
  154 + $id = $model->addReturnId([
  155 + 'project_id' => $project_id,
  156 + 'title' => $item['name'],
  157 + 'seo_title' => $item['seo_title'] ?? '',
  158 + 'seo_keywords' => $item['seo_keywords'] ?? '',
  159 + 'seo_description' => $item['seo_description'] ?? '',
  160 + ]);
  161 + $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
  162 + $model->edit(['route' => $route], ['id' => $id]);
  163 + } catch (\Exception $e) {
  164 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  165 + continue;
  166 + }
  167 + }
  168 + }
  169 + }
91 } 170 }
92 - $keyword = $model->read(['title' => $item], 'id');  
93 - if (!$keyword) {  
94 - $id = $model->addReturnId([  
95 - 'project_id' => $project_id,  
96 - 'title' => $item  
97 - ]);  
98 - $route = RouteMap::setRoute($item, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);  
99 - $model->edit(['route' => $route], ['id' => $id]); 171 + }
  172 + } else {
  173 + return true;
  174 + }
  175 + } elseif ($api_type == 'website_info') {
  176 + //网站信息
  177 + $url = $api_url . '?' . http_build_query(['w' => 'website_info']);
  178 + $data = http_get($url, ['charset' => 'UTF-8']);
  179 + if (isset($data['code']) && $data['code'] == 200) {
  180 + $phones = $data['data']['phones'] ?? '';
  181 + $emails = $data['data']['emails'] ?? '';
  182 +
  183 + $model = new WebSettingReceiving();
  184 + if ($phones) {
  185 + $phone_arr = explode(',', $phones);
  186 + foreach ($phone_arr as $v_phone) {
  187 + if ($v_phone) {
  188 + $receiving_phones = $model->read(['type' => 2, 'values' => $v_phone]);
  189 + if (!$receiving_phones) {
  190 + $model->add([
  191 + 'type' => 1,
  192 + 'values' => $v_phone,
  193 + 'project_id' => $project_id
  194 + ]);
  195 + }
  196 + }
  197 + }
  198 + }
  199 + if ($emails) {
  200 + $email_arr = explode(',', $emails);
  201 + foreach ($email_arr as $v_email) {
  202 + if ($v_email) {
  203 + $receiving_emails = $model->read(['type' => 1, 'values' => $v_email]);
  204 + if (!$receiving_emails) {
  205 + $model->add([
  206 + 'type' => 2,
  207 + 'values' => $v_email,
  208 + 'project_id' => $project_id
  209 + ]);
  210 + }
  211 + }
100 } 212 }
101 } 213 }
  214 + } else {
  215 + return true;
102 } 216 }
103 } elseif ($api_type == 'post') { 217 } elseif ($api_type == 'post') {
104 //产品 218 //产品
@@ -117,58 +231,61 @@ class ProjectUpdate extends Command @@ -117,58 +231,61 @@ class ProjectUpdate extends Command
117 $model = new Product(); 231 $model = new Product();
118 232
119 foreach ($items as $item) { 233 foreach ($items as $item) {
120 -  
121 - $product = $model->read(['title' => $item['ttile']], 'id');  
122 - if (!$product) {  
123 - //图片  
124 - $gallery = [];  
125 - foreach ($item['images'] as $k_img => $img) {  
126 - $gallery[] = ['alt' => '这是一张产品图', 'url' => $img];  
127 - }  
128 - //关键词  
129 - $keyword_id = '';  
130 - if ($item['keywords']) {  
131 - $keywordLogic = new KeywordLogic();  
132 - $keyword_id = $keywordLogic->importProductKeyword($project_id, $item['keywords']);  
133 - }  
134 - //分类  
135 - $category_id = '';  
136 - if ($item['category']) {  
137 - $category_arr = [];  
138 - foreach ($item['category'] as $cate) {  
139 - if ($cate['parent'] == 0) {  
140 - array_unshift($category_arr, $cate['name']);  
141 - } else {  
142 - array_push($category_arr, $cate['name']); 234 + if ($item['ttile'] ?? '') {
  235 + $product = $model->read(['title' => $item['ttile']], 'id');
  236 + if (!$product) {
  237 + //图片
  238 + $gallery = [];
  239 + if ($item['images'] ?? []) {
  240 + foreach ($item['images'] as $k_img => $img) {
  241 + $gallery[] = ['alt' => '这是一张产品图', 'url' => $img];
  242 + }
  243 + }
  244 + //分类
  245 + $category_id = '';
  246 + if ($item['category'] ?? []) {
  247 + $category_arr = [];
  248 + foreach ($item['category'] as $cate) {
  249 + if ($cate['parent'] == 0) {
  250 + array_unshift($category_arr, $cate['name']);
  251 + } else {
  252 + array_push($category_arr, $cate['name']);
  253 + }
  254 + }
  255 + if ($category_arr) {
  256 + $categoryLogic = new CategoryLogic();
  257 + $category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr));
143 } 258 }
144 } 259 }
145 - if ($category_arr) {  
146 - $categoryLogic = new CategoryLogic();  
147 - $category_id = $categoryLogic->importProductCategory($project_id, implode('/', $category_arr)); 260 + try {
  261 + $id = $model->addReturnId([
  262 + 'project_id' => $project_id,
  263 + 'title' => $item['ttile'],
  264 + 'intro' => $item['description'] ?? '',
  265 + 'content' => $item['content'] ?? '',
  266 + 'category_id' => $category_id,
  267 + 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
  268 + 'gallery' => Arr::a2s($gallery),
  269 + 'seo_mate' => Arr::a2s([
  270 + 'title' => $item['ttile'],
  271 + 'keyword' => $item['keywords'] ?? '',
  272 + 'description' => $item['description'] ?? ''
  273 + ]),
  274 + 'status' => Product::STATUS_ON
  275 + ]);
  276 + $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);
  277 + $model->edit(['route' => $route], ['id' => $id]);
  278 + } catch (\Exception $e) {
  279 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  280 + continue;
148 } 281 }
149 } 282 }
150 - $id = $model->addReturnId([  
151 - 'project_id' => $project_id,  
152 - 'title' => $item['ttile'],  
153 - 'intro' => $item['description'],  
154 - 'content' => $item['content'],  
155 - 'keyword_id' => $keyword_id,  
156 - 'category_id' => $category_id,  
157 - 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',  
158 - 'gallery' => Arr::a2s($gallery),  
159 - 'seo_mate' => Arr::a2s([  
160 - 'title' => $item['ttile'],  
161 - 'keyword' => $item['keywords'],  
162 - 'description' => $item['description']  
163 - ]),  
164 - 'status' => Product::STATUS_ON  
165 - ]);  
166 - $route = RouteMap::setRoute($item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);  
167 - $model->edit(['route' => $route], ['id' => $id]);  
168 } 283 }
169 } 284 }
170 } 285 }
171 } 286 }
  287 + } else {
  288 + return true;
172 } 289 }
173 } elseif ($api_type == 'news' || $api_type == 'blog') { 290 } elseif ($api_type == 'news' || $api_type == 'blog') {
174 //新闻或博客 291 //新闻或博客
@@ -192,22 +309,33 @@ class ProjectUpdate extends Command @@ -192,22 +309,33 @@ class ProjectUpdate extends Command
192 309
193 foreach ($items as $item) { 310 foreach ($items as $item) {
194 311
195 - $news = $model->read(['name' => $item['ttile']], 'id');  
196 - if (!$news) {  
197 - $id = $model->addReturnId([  
198 - 'project_id' => $project_id,  
199 - 'name' => $item['ttile'],  
200 - 'seo_title' => $item['ttile'],  
201 - 'text' => $item['content'],  
202 - 'image' => $item['images'][0] ?? '',  
203 - 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE  
204 - ]);  
205 - $route = RouteMap::setRoute($item['ttile'], $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);  
206 - $model->edit(['url' => $route], ['id' => $id]); 312 + if ($item['ttile'] ?? '') {
  313 + $news = $model->read(['name' => $item['ttile']], 'id');
  314 + if (!$news) {
  315 + try {
  316 + $id = $model->addReturnId([
  317 + 'project_id' => $project_id,
  318 + 'name' => $item['ttile'],
  319 + 'seo_title' => $item['ttile'],
  320 + 'seo_keywords' => $item['keywords'] ?? '',
  321 + 'seo_description' => $item['description'] ?? '',
  322 + 'text' => $item['content'] ?? '',
  323 + 'image' => $item['images'][0] ?? '',
  324 + 'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE
  325 + ]);
  326 + $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
  327 + $model->edit(['url' => $route], ['id' => $id]);
  328 + } catch (\Exception $e) {
  329 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  330 + continue;
  331 + }
  332 + }
207 } 333 }
208 } 334 }
209 } 335 }
210 } 336 }
  337 + } else {
  338 + return true;
211 } 339 }
212 } else { 340 } else {
213 //单页 341 //单页
@@ -226,20 +354,32 @@ class ProjectUpdate extends Command @@ -226,20 +354,32 @@ class ProjectUpdate extends Command
226 $model = new BCustomTemplate(); 354 $model = new BCustomTemplate();
227 355
228 foreach ($items as $item) { 356 foreach ($items as $item) {
229 -  
230 - $custom = $model->read(['name' => $item['ttile']], 'id');  
231 - if (!$custom) {  
232 - $id = $model->addReturnId([  
233 - 'project_id' => $project_id,  
234 - 'name' => $item['ttile'],  
235 - 'html' => $item['content']  
236 - ]);  
237 - $route = RouteMap::setRoute($item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);  
238 - $model->edit(['url' => $route], ['id' => $id]); 357 + if ($item['ttile'] ?? '') {
  358 + $custom = $model->read(['name' => $item['ttile']], 'id');
  359 + if (!$custom) {
  360 + try {
  361 + $id = $model->addReturnId([
  362 + 'project_id' => $project_id,
  363 + 'name' => $item['ttile'],
  364 + 'title' => $item['ttile'],
  365 + 'keywords' => $item['keywords'] ?? '',
  366 + 'description' => $item['description'] ?? '',
  367 + 'html' => $item['content'] ?? '',
  368 + 'status' => 1
  369 + ]);
  370 + $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);
  371 + $model->edit(['url' => $route], ['id' => $id]);
  372 + } catch (\Exception $e) {
  373 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  374 + continue;
  375 + }
  376 + }
239 } 377 }
240 } 378 }
241 } 379 }
242 } 380 }
  381 + } else {
  382 + return true;
243 } 383 }
244 } 384 }
245 } 385 }
@@ -263,7 +403,7 @@ class ProjectUpdate extends Command @@ -263,7 +403,7 @@ class ProjectUpdate extends Command
263 return $task_id; 403 return $task_id;
264 } 404 }
265 405
266 - $task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->limit(20)->get(); 406 + $task_list = UpdateLog::where('status', UpdateLog::STATUS_UN)->orderBy('project_id', 'asc')->orderBy('sort', 'asc')->limit(7)->get();
267 if ($task_list->count() == 0) { 407 if ($task_list->count() == 0) {
268 return false; 408 return false;
269 } 409 }
@@ -276,4 +416,37 @@ class ProjectUpdate extends Command @@ -276,4 +416,37 @@ class ProjectUpdate extends Command
276 return $task_id; 416 return $task_id;
277 } 417 }
278 418
  419 + //获取地址路由
  420 + protected function get_url_route($url)
  421 + {
  422 + $arr = explode('/', $url);
  423 + return $arr[count($arr) - 2];
  424 + }
  425 +
  426 + protected function category_insert($project_id, $items, $pid = 0)
  427 + {
  428 + $model = new Category();
  429 + foreach ($items as $item) {
  430 + if ($item['name'] ?? '') {
  431 + $parent = $model->read(['pid' => $pid, 'title' => $item['name']], 'id');
  432 + if (!$parent) {
  433 + $parent_id = $model->addReturnId([
  434 + 'project_id' => $project_id,
  435 + 'title' => $item['name'],
  436 + 'pid' => $pid,
  437 + 'keywords' => $item['keywords'] ?? '',
  438 + 'describe' => $item['description'] ?? ''
  439 + ]);
  440 + $route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
  441 + $model->edit(['route' => $route], ['id' => $parent_id]);
  442 + } else {
  443 + $parent_id = $parent['id'];
  444 + }
  445 +
  446 + if (!empty($item['children'])) {
  447 + $this->category_insert($project_id, $item['children'], $parent_id);
  448 + }
  449 + }
  450 + }
  451 + }
279 } 452 }
@@ -44,12 +44,17 @@ class UpdateProgress extends Command @@ -44,12 +44,17 @@ class UpdateProgress extends Command
44 //获取所有项目 44 //获取所有项目
45 $projectModel = new Project(); 45 $projectModel = new Project();
46 $list = $projectModel->list(['type'=>['in',[1,2,3,4]]]); 46 $list = $projectModel->list(['type'=>['in',[1,2,3,4]]]);
47 - foreach ($list as $v){  
48 - echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL;  
49 - ProjectServer::useProject($v['id']);  
50 - $this->getUpdateProgress($v['id']);  
51 - DB::disconnect('custom_mysql'); 47 + try {
  48 + foreach ($list as $v) {
  49 + echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL;
  50 + ProjectServer::useProject($v['id']);
  51 + $this->getUpdateProgress($v['id']);
  52 + DB::disconnect('custom_mysql');
  53 + }
  54 + }catch (\Exception $e){
  55 + echo date('Y-m-d H:i:s') . ' error: ->' . $e->getMessage() . PHP_EOL;
52 } 56 }
  57 + echo date('Y-m-d H:i:s') . ' end: ' . PHP_EOL;
53 } 58 }
54 59
55 /** 60 /**
@@ -9,9 +9,11 @@ use App\Helper\Translate; @@ -9,9 +9,11 @@ use App\Helper\Translate;
9 use App\Models\Ai\AiCommand; 9 use App\Models\Ai\AiCommand;
10 use App\Models\Mail\Mail; 10 use App\Models\Mail\Mail;
11 use App\Models\Project\DeployOptimize; 11 use App\Models\Project\DeployOptimize;
  12 +use App\Models\Project\ProjectUpdateTdk;
12 use App\Models\User\User; 13 use App\Models\User\User;
13 use App\Services\ProjectServer; 14 use App\Services\ProjectServer;
14 use Illuminate\Console\Command; 15 use Illuminate\Console\Command;
  16 +use Illuminate\Support\Facades\Cache;
15 use Illuminate\Support\Facades\DB; 17 use Illuminate\Support\Facades\DB;
16 use Illuminate\Support\Facades\Redis; 18 use Illuminate\Support\Facades\Redis;
17 19
@@ -132,47 +134,54 @@ class UpdateSeoTdk extends Command @@ -132,47 +134,54 @@ class UpdateSeoTdk extends Command
132 public function handle() 134 public function handle()
133 { 135 {
134 while (true) { 136 while (true) {
135 - $project_id = Redis::rpop('updateSeoTdk');  
136 - if (!$project_id) {  
137 - sleep(2); 137 + $task = ProjectUpdateTdk::getPendingTask();
  138 + if (!$task) {
  139 + sleep(10);
138 continue; 140 continue;
139 } 141 }
  142 + $project_id = $task->project_id;
  143 +
140 echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL; 144 echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL;
141 try { 145 try {
142 ProjectServer::useProject($project_id); 146 ProjectServer::useProject($project_id);
143 - $this->seo_tdk($project_id); 147 + $this->seo_tdk($project_id, $task->id);
144 DB::disconnect('custom_mysql'); 148 DB::disconnect('custom_mysql');
145 }catch (\Exception $e){ 149 }catch (\Exception $e){
146 - echo date('Y-m-d H:i:s') . ' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL; 150 + echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
  151 + ProjectUpdateTdk::retry($task->id, $e->getMessage());
147 } 152 }
148 - echo date('Y-m-d H:i:s') . ' end: ' . $project_id . PHP_EOL; 153 + echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL;
149 } 154 }
150 } 155 }
151 156
152 - public function seo_tdk($project_id) 157 + public function seo_tdk($project_id, $task_id)
153 { 158 {
154 - $data = [];  
155 - $update = [  
156 - 'created_at'=>date('Y-m-d H:i:s'),  
157 - 'updated_at'=>date('Y-m-d H:i:s'),  
158 - 'project_id'=>$project_id,  
159 - ];//更新统计 159 +
  160 + //更新统计
  161 + $update = [];
160 $ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray(); 162 $ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray();
161 $ai_commands = Arr::setValueToKey($ai_commands, 'key'); 163 $ai_commands = Arr::setValueToKey($ai_commands, 'key');
162 foreach ($this->maps as $table => $map) { 164 foreach ($this->maps as $table => $map) {
163 $update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0]; 165 $update[$table] = ['total_page'=>0, 'title'=>0, 'keyword'=>0, 'des'=>0];
164 - echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL . json_encode($update[$table]); 166 + echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
165 $list = DB::connection('custom_mysql')->table($table)->get(); 167 $list = DB::connection('custom_mysql')->table($table)->get();
166 if (!empty($list)) { 168 if (!empty($list)) {
167 $list = $list->toArray(); 169 $list = $list->toArray();
168 foreach ($list as $v) { 170 foreach ($list as $v) {
169 - echo '打印数据:'.date('Y-m-d H:i:s') . $update[$table]['total_page'].PHP_EOL;  
170 $update[$table]['total_page']++; 171 $update[$table]['total_page']++;
171 $v = (array)$v; 172 $v = (array)$v;
172 - echo date('Y-m-d H:i:s') . '更新--' . $table . ':id' . $v['id'] . PHP_EOL; 173 +
  174 + //缓存 在处理的项目数据 id
  175 + $cache_key = "seo_tdk_{$project_id}_{$table}_{$v['id']}";
  176 + if(!Redis::setnx($cache_key, 1)){
  177 + continue;
  178 + }
  179 + Redis::expire($cache_key, 120);
  180 +
  181 + echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
  182 +
173 $data = []; 183 $data = [];
174 $json_field = ''; 184 $json_field = '';
175 - echo date('Y-m-d H:i:s') . json_encode($map) . PHP_EOL;  
176 foreach ($map as $ai_key => $field) { 185 foreach ($map as $ai_key => $field) {
177 $field_arr = explode('.', $field); 186 $field_arr = explode('.', $field);
178 if (count($field_arr) > 1) { 187 if (count($field_arr) > 1) {
@@ -186,6 +195,7 @@ class UpdateSeoTdk extends Command @@ -186,6 +195,7 @@ class UpdateSeoTdk extends Command
186 echo $field.'已有值 跳过' . PHP_EOL; 195 echo $field.'已有值 跳过' . PHP_EOL;
187 continue; 196 continue;
188 } 197 }
  198 +
189 //AI生成 199 //AI生成
190 if (!empty($ai_commands[$ai_key]['ai'])) { 200 if (!empty($ai_commands[$ai_key]['ai'])) {
191 $prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v); 201 $prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v);
@@ -255,17 +265,16 @@ class UpdateSeoTdk extends Command @@ -255,17 +265,16 @@ class UpdateSeoTdk extends Command
255 } 265 }
256 if($json_field){ 266 if($json_field){
257 $old_data = json_decode($v[$field_arr[0]], true); 267 $old_data = json_decode($v[$field_arr[0]], true);
258 - foreach ($old_data as $kk=>$vv){ 268 + foreach ($old_data ?: [] as $kk=>$vv){
259 empty($data[$json_field][$kk]) && $data[$json_field][$kk] = $vv; 269 empty($data[$json_field][$kk]) && $data[$json_field][$kk] = $vv;
260 } 270 }
261 $data[$json_field] = json_encode($data[$json_field]); 271 $data[$json_field] = json_encode($data[$json_field]);
262 } 272 }
263 DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data); 273 DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data);
264 } 274 }
265 - $update[$table] = json_encode($update[$table]);  
266 } 275 }
267 } 276 }
268 - DB::table('gl_project_update_tdk')->insert($update); 277 + ProjectUpdateTdk::finish($task_id, $update);
269 } 278 }
270 279
271 public function getPrompt($project_id, $prompt, $table, $data){ 280 public function getPrompt($project_id, $prompt, $table, $data){
@@ -298,8 +307,6 @@ class UpdateSeoTdk extends Command @@ -298,8 +307,6 @@ class UpdateSeoTdk extends Command
298 } 307 }
299 $prompt .= '.Please answer in ' . ($lang ?: 'English'); 308 $prompt .= '.Please answer in ' . ($lang ?: 'English');
300 309
301 - echo $prompt . PHP_EOL;  
302 -  
303 return $prompt; 310 return $prompt;
304 } 311 }
305 312
@@ -151,6 +151,9 @@ class Arr extends \Illuminate\Support\Arr @@ -151,6 +151,9 @@ class Arr extends \Illuminate\Support\Arr
151 */ 151 */
152 public static function s2a($str) 152 public static function s2a($str)
153 { 153 {
  154 + if(!$str){
  155 + return [];
  156 + }
154 if (is_array($str)) { 157 if (is_array($str)) {
155 return $str; 158 return $str;
156 } 159 }
@@ -74,7 +74,7 @@ class Common @@ -74,7 +74,7 @@ class Common
74 if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) { 74 if (isset($result['texts']['sl']) && isset(Translate::$tls_list[$result['texts']['sl']])) {
75 $lang = Translate::$tls_list[$result['texts']['sl']]['text']; 75 $lang = Translate::$tls_list[$result['texts']['sl']]['text'];
76 } else { 76 } else {
77 - $lang = 'Chinese'; 77 + $lang = 'English';
78 } 78 }
79 } 79 }
80 $str = 'Please answer in '.$lang; 80 $str = 'Please answer in '.$lang;
@@ -14,9 +14,20 @@ use Illuminate\Support\Facades\Log; @@ -14,9 +14,20 @@ use Illuminate\Support\Facades\Log;
14 */ 14 */
15 class Gpt 15 class Gpt
16 { 16 {
17 - public $api = 'http://openai.waimaoq.com/'; 17 + /**
  18 + * 头
  19 + * @var string[]
  20 + */
  21 + public $header = [
  22 + 'apikey' => 'UkzZljFv83Z2qBi5YR1o3f2otAVWtug6',
  23 + 'X-CmerApi-Host' => 'bizopenai.p.cmer.com',
  24 + ];
18 25
19 - public $header = []; 26 + /**
  27 + * 请求域名
  28 + * @var string
  29 + */
  30 + public $api = 'https://api.cmer.com';
20 31
21 private static $instance; 32 private static $instance;
22 33
@@ -35,7 +46,7 @@ class Gpt @@ -35,7 +46,7 @@ class Gpt
35 */ 46 */
36 public function openai_chat_qqs($content, $system_content = '') 47 public function openai_chat_qqs($content, $system_content = '')
37 { 48 {
38 - $url = $this->api . 'v2/openai_chat_qqs'; 49 + $url = $this->api . '/v1/openai_chat';
39 50
40 $data = [ 51 $data = [
41 'messages' => [], 52 'messages' => [],
@@ -57,9 +68,10 @@ class Gpt @@ -57,9 +68,10 @@ class Gpt
57 ->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json') 68 ->withBody(json_encode($data, JSON_UNESCAPED_UNICODE), 'application/json')
58 ->post($url); 69 ->post($url);
59 $json = $result->json(); 70 $json = $result->json();
60 - if (!isset($json['text'])) { 71 + if (!isset($json['text']) || $json['code'] !==200) {
61 Log::error('openai_chat_qqs data:', $data); 72 Log::error('openai_chat_qqs data:', $data);
62 Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json); 73 Log::error('openai_chat_qqs result:' . (time() - $time), $json === null ? ['null'] : $json);
  74 + $json = [];
63 } 75 }
64 } catch (\Throwable $e) { 76 } catch (\Throwable $e) {
65 Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage()); 77 Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage());
1 <?php 1 <?php
2 2
3 use App\Models\File\Image; 3 use App\Models\File\Image;
  4 +use App\Models\RouteMap\RouteMap;
4 use App\Services\CosService; 5 use App\Services\CosService;
5 use App\Utils\EncryptUtils; 6 use App\Utils\EncryptUtils;
6 use App\Utils\LogUtils; 7 use App\Utils\LogUtils;
@@ -560,3 +561,24 @@ function ends_with($string, $suffix) @@ -560,3 +561,24 @@ function ends_with($string, $suffix)
560 { 561 {
561 return substr($string, -strlen($suffix)) === $suffix; 562 return substr($string, -strlen($suffix)) === $suffix;
562 } 563 }
  564 +
  565 +/**
  566 + * @remark :获取二级路由
  567 + * @name :getRouteMap
  568 + * @author :lyh
  569 + * @method :post
  570 + * @time :2023/11/10 14:29
  571 + */
  572 +function getRouteMap($source,$source_id){
  573 + $route = '';
  574 + $routeMapModel = new RouteMap();
  575 + $info = $routeMapModel->read(['source'=>$source,'source_id'=>$source_id]);
  576 + if($info !== false){
  577 + if(!empty($info['path'])){
  578 + $route = $info['path'].'/'.$info['route'];
  579 + }else{
  580 + $route = $info['route'];
  581 + }
  582 + }
  583 + return $route;
  584 +}
@@ -11,6 +11,7 @@ namespace App\Http\Controllers\Aside\Com; @@ -11,6 +11,7 @@ namespace App\Http\Controllers\Aside\Com;
11 11
12 use App\Helper\Common; 12 use App\Helper\Common;
13 use App\Http\Controllers\Bside\BaseController; 13 use App\Http\Controllers\Bside\BaseController;
  14 +use App\Models\Project\ProjectUpdateTdk;
14 use App\Services\ProjectServer; 15 use App\Services\ProjectServer;
15 use Illuminate\Support\Facades\DB; 16 use Illuminate\Support\Facades\DB;
16 use Illuminate\Support\Facades\Redis; 17 use Illuminate\Support\Facades\Redis;
@@ -37,7 +38,7 @@ class UpdateController extends BaseController @@ -37,7 +38,7 @@ class UpdateController extends BaseController
37 ],[ 38 ],[
38 'project_id.required' => 'project_id不能为空', 39 'project_id.required' => 'project_id不能为空',
39 ]); 40 ]);
40 - Redis::lpush('updateSeoTdk', $this->param['project_id']); 41 + ProjectUpdateTdk::add_task($this->param['project_id']);
41 $this->response('任务添加成功'); 42 $this->response('任务添加成功');
42 } 43 }
43 } 44 }
@@ -311,7 +311,7 @@ class ProjectController extends BaseController @@ -311,7 +311,7 @@ class ProjectController extends BaseController
311 $domainModel = new DomainInfo(); 311 $domainModel = new DomainInfo();
312 $item['domain'] = !empty($item['domain']) ? $domainModel->getDomain($item['domain']) : ''; 312 $item['domain'] = !empty($item['domain']) ? $domainModel->getDomain($item['domain']) : '';
313 $item['product_num'] = $data['product'] ?? 0; 313 $item['product_num'] = $data['product'] ?? 0;
314 - $item['keyword_num'] = $item['key'] ?? 0; 314 + $item['keyword_num'] = $data['key'] ?? 0;
315 $item['autologin_code'] = getAutoLoginCode($item['id']); 315 $item['autologin_code'] = getAutoLoginCode($item['id']);
316 $item['article_num'] = ($data['blog'] ?? 0) + ($data['news'] ?? 0); 316 $item['article_num'] = ($data['blog'] ?? 0) + ($data['news'] ?? 0);
317 $item['task_finish_num'] = Task::getNumByProjectId($item['id'], Task::STATUS_DOWN); 317 $item['task_finish_num'] = Task::getNumByProjectId($item['id'], Task::STATUS_DOWN);
@@ -777,6 +777,9 @@ class ProjectController extends BaseController @@ -777,6 +777,9 @@ class ProjectController extends BaseController
777 * @time :2023/11/8 14:17 777 * @time :2023/11/8 14:17
778 */ 778 */
779 public function copyProject(ProjectLogic $logic){ 779 public function copyProject(ProjectLogic $logic){
  780 + if($this->manage['mobile'] != '15680871314' || $this->manage['mobile'] != '18008059100'){
  781 + $this->response('当前账号不支持复制项目');
  782 + }
780 $this->request->validate([ 783 $this->request->validate([
781 'project_id'=>'required', 784 'project_id'=>'required',
782 ],[ 785 ],[
@@ -786,4 +789,21 @@ class ProjectController extends BaseController @@ -786,4 +789,21 @@ class ProjectController extends BaseController
786 $this->response('success',Code::SUCCESS,$data); 789 $this->response('success',Code::SUCCESS,$data);
787 } 790 }
788 791
  792 + /**
  793 + * AICC采集数据接口token
  794 + * @author zbj
  795 + * @date 2023/11/10
  796 + */
  797 + public function site_token(Request $request, ProjectLogic $logic){
  798 + $this->request->validate([
  799 + 'project_id'=>'required',
  800 + ],[
  801 + 'project_id.required' => 'project_id不能为空',
  802 + ]);
  803 +
  804 + $token = $logic->getAiccToken($this->map);
  805 +
  806 + $this->response('success',Code::SUCCESS,['site_token' => $token]);
  807 +
  808 + }
789 } 809 }
@@ -27,7 +27,7 @@ class BlogCategoryController extends BaseController @@ -27,7 +27,7 @@ class BlogCategoryController extends BaseController
27 $blogModel = new BlogModel(); 27 $blogModel = new BlogModel();
28 foreach ($lists as $k => $v){ 28 foreach ($lists as $k => $v){
29 $v['num'] = $blogModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count(); 29 $v['num'] = $blogModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
30 - $v['url'] = $this->user['domain'] . $v['alias'].'/'; 30 + $v['url'] = $this->user['domain'] . getRouteMap(RouteMap::SOURCE_BLOG_CATE,$v['id']);
31 $lists[$k] = $v; 31 $lists[$k] = $v;
32 } 32 }
33 if(!isset($this->map['name'])){ 33 if(!isset($this->map['name'])){
@@ -81,7 +81,6 @@ class BlogCategoryController extends BaseController @@ -81,7 +81,6 @@ class BlogCategoryController extends BaseController
81 'id.required' => 'ID不能为空' 81 'id.required' => 'ID不能为空'
82 ]); 82 ]);
83 $info = $blogCategoryLogic->info_blog_category(); 83 $info = $blogCategoryLogic->info_blog_category();
84 - $info['url'] = $this->user['domain'] . $info['alias'];  
85 $this->response('success',Code::SUCCESS,$info); 84 $this->response('success',Code::SUCCESS,$info);
86 } 85 }
87 86
@@ -10,6 +10,7 @@ use App\Models\Blog\Blog as BlogModel; @@ -10,6 +10,7 @@ use App\Models\Blog\Blog as BlogModel;
10 use App\Models\Blog\BlogCategory; 10 use App\Models\Blog\BlogCategory;
11 use App\Models\Blog\BlogCategory as BlogCategoryModel; 11 use App\Models\Blog\BlogCategory as BlogCategoryModel;
12 use App\Models\Product\Category; 12 use App\Models\Product\Category;
  13 +use App\Models\RouteMap\RouteMap;
13 use App\Models\User\User; 14 use App\Models\User\User;
14 15
15 class BlogController extends BaseController 16 class BlogController extends BaseController
@@ -35,7 +36,7 @@ class BlogController extends BaseController @@ -35,7 +36,7 @@ class BlogController extends BaseController
35 $user = new User(); 36 $user = new User();
36 foreach ($lists['list'] as $k => $v){ 37 foreach ($lists['list'] as $k => $v){
37 $v['category_name'] = $this->categoryName($v['category_id'],$data); 38 $v['category_name'] = $this->categoryName($v['category_id'],$data);
38 - $v['url'] = $this->user['domain'] .$v['url'].'/'; 39 + $v['url'] = $this->user['domain'] . getRouteMap(RouteMap::SOURCE_BLOG,$v['id']);
39 $v['image_link'] = getImageUrl($v['image']); 40 $v['image_link'] = getImageUrl($v['image']);
40 $v['operator_name'] = $user->getName($v['operator_id']); 41 $v['operator_name'] = $user->getName($v['operator_id']);
41 $lists['list'][$k] = $v; 42 $lists['list'][$k] = $v;
@@ -27,7 +27,7 @@ class NewsCategoryController extends BaseController @@ -27,7 +27,7 @@ class NewsCategoryController extends BaseController
27 $newsModel = new NewsModel(); 27 $newsModel = new NewsModel();
28 foreach ($lists as $k => $v){ 28 foreach ($lists as $k => $v){
29 $v['num'] = $newsModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count(); 29 $v['num'] = $newsModel->formatQuery(['category_id'=>['like','%,' . $v['id'] . ',%']])->count();
30 - $v['url'] = $this->user['domain'] . $v['alias'].'/'; 30 + $v['url'] = $this->user['domain'].getRouteMap(RouteMap::SOURCE_NEWS_CATE,$v['id']);
31 $lists[$k] = $v; 31 $lists[$k] = $v;
32 } 32 }
33 if(!isset($this->map['name'])){ 33 if(!isset($this->map['name'])){
@@ -8,6 +8,7 @@ use App\Http\Logic\Bside\News\NewsLogic; @@ -8,6 +8,7 @@ use App\Http\Logic\Bside\News\NewsLogic;
8 use App\Http\Requests\Bside\News\NewsRequest; 8 use App\Http\Requests\Bside\News\NewsRequest;
9 use App\Models\News\News as NewsModel; 9 use App\Models\News\News as NewsModel;
10 use App\Models\News\NewsCategory; 10 use App\Models\News\NewsCategory;
  11 +use App\Models\RouteMap\RouteMap;
11 use App\Models\User\User; 12 use App\Models\User\User;
12 13
13 14
@@ -35,7 +36,7 @@ class NewsController extends BaseController @@ -35,7 +36,7 @@ class NewsController extends BaseController
35 $user = new User(); 36 $user = new User();
36 foreach ($lists['list'] as $k => $v){ 37 foreach ($lists['list'] as $k => $v){
37 $v['category_name'] = $this->categoryName($v['category_id'],$data); 38 $v['category_name'] = $this->categoryName($v['category_id'],$data);
38 - $v['url'] = $this->user['domain'] .$v['url'].'/'; 39 + $v['url'] = $this->user['domain'].getRouteMap(RouteMap::SOURCE_NEWS,$v['id']);
39 $v['image_link'] = getImageUrl($v['image']); 40 $v['image_link'] = getImageUrl($v['image']);
40 $v['operator_name'] = $user->getName($v['operator_id']); 41 $v['operator_name'] = $user->getName($v['operator_id']);
41 $lists['list'][$k] = $v; 42 $lists['list'][$k] = $v;
@@ -44,6 +45,8 @@ class NewsController extends BaseController @@ -44,6 +45,8 @@ class NewsController extends BaseController
44 $this->response('success',Code::SUCCESS,$lists); 45 $this->response('success',Code::SUCCESS,$lists);
45 } 46 }
46 47
  48 +
  49 +
47 /** 50 /**
48 * @remark :处理列表返回参数 51 * @remark :处理列表返回参数
49 * @name :handleReturnParam 52 * @name :handleReturnParam
@@ -35,6 +35,7 @@ use App\Models\User\User as UserModel; @@ -35,6 +35,7 @@ use App\Models\User\User as UserModel;
35 use Illuminate\Support\Facades\DB; 35 use Illuminate\Support\Facades\DB;
36 use Illuminate\Support\Facades\Log; 36 use Illuminate\Support\Facades\Log;
37 use Illuminate\Support\Facades\Schema; 37 use Illuminate\Support\Facades\Schema;
  38 +use Illuminate\Support\Str;
38 39
39 /** 40 /**
40 * Class ProjectLogic 41 * Class ProjectLogic
@@ -535,34 +536,82 @@ class ProjectLogic extends BaseLogic @@ -535,34 +536,82 @@ class ProjectLogic extends BaseLogic
535 * @time :2023/11/8 14:23 536 * @time :2023/11/8 14:23
536 */ 537 */
537 public function copyProject(){ 538 public function copyProject(){
538 - //复制初始项目  
539 - $data = $this->model::where('id', $this->param['project_id'])->first();  
540 - $data = $data->getAttributes();  
541 - $data['type'] = 0;  
542 - $data['title'] = $data['title'].'-copy';  
543 - unset($data['id']);  
544 - $project_id = $this->model->insertGetId($data);  
545 - //复制部署表  
546 - $buildModel = new DeployBuild();  
547 - $buildData = $buildModel::where('project_id', $this->param['project_id'])->first();  
548 - if(!empty($buildData)){  
549 - $buildData = $buildData->getAttributes();  
550 - $buildData['project_id'] = $project_id;  
551 - $hashids = new Hashids('test_domain', 5, 'abcdefghjkmnpqrstuvwxyz1234567890');  
552 - $code = $hashids->encode($project_id);  
553 - $buildData['test_domain'] = 'https://v6-' . $code . '.globalso.site/';  
554 - unset($buildData['id']);  
555 - $buildModel->insert($buildData);  
556 - }  
557 - //复制优化表  
558 - $optimizeModel = new DeployOptimize();  
559 - $optimizeData = $optimizeModel::where('project_id', $this->param['project_id'])->first();  
560 - if(!empty($optimizeData)){  
561 - $optimizeData = $optimizeData->getAttributes();  
562 - unset($optimizeData['id'],$optimizeData['domain']);  
563 - $optimizeData['project_id'] = $project_id;  
564 - $optimizeModel->insert($optimizeData); 539 + DB::beginTransaction();
  540 + try {
  541 + //复制初始项目
  542 + $data = $this->model::where('id', $this->param['project_id'])->first();
  543 + $data = $data->getAttributes();
  544 + $type = $data['type'];
  545 + $data['type'] = 0;
  546 + $data['title'] = $data['title'].'-copy';
  547 + unset($data['id']);
  548 + $project_id = $this->model->insertGetId($data);
  549 + //复制部署表
  550 + $buildModel = new DeployBuild();
  551 + $buildData = $buildModel::where('project_id', $this->param['project_id'])->first();
  552 + if(!empty($buildData)){
  553 + $buildData = $buildData->getAttributes();
  554 + $buildData['project_id'] = $project_id;
  555 + $hashids = new Hashids('test_domain', 5, 'abcdefghjkmnpqrstuvwxyz1234567890');
  556 + $code = $hashids->encode($project_id);
  557 + $buildData['test_domain'] = 'https://v6-' . $code . '.globalso.site/';
  558 + unset($buildData['id']);
  559 + $buildModel->insert($buildData);
  560 + }
  561 + //复制优化表
  562 + $optimizeModel = new DeployOptimize();
  563 + $optimizeData = $optimizeModel::where('project_id', $this->param['project_id'])->first();
  564 + if(!empty($optimizeData)){
  565 + $optimizeData = $optimizeData->getAttributes();
  566 + unset($optimizeData['id'],$optimizeData['domain']);
  567 + $optimizeData['project_id'] = $project_id;
  568 + $optimizeModel->insert($optimizeData);
  569 + }
  570 + //复制付费表
  571 + $paymentModel = new Payment();
  572 + $paymentData = $paymentModel::where('project_id', $this->param['project_id'])->first();
  573 + if(!empty($paymentData)){
  574 + $paymentData = $paymentData->getAttributes();
  575 + unset($paymentData['id']);
  576 + $paymentData['project_id'] = $project_id;
  577 + $paymentModel->insert($paymentData);
  578 + }
  579 + //复制售后表
  580 + $afterModel = new After();
  581 + $afterData = $afterModel::where('project_id', $this->param['project_id'])->first();
  582 + if(!empty($afterData)){
  583 + $afterData = $afterData->getAttributes();
  584 + unset($afterData['id']);
  585 + $afterData['project_id'] = $project_id;
  586 + $afterModel->insert($afterData);
  587 + }
  588 + //复制用户
  589 + $userModel = new UserModel();
  590 + $userData = $userModel::where('project_id', $this->param['project_id'])->where('role_id',0)->first();
  591 + if(!empty($userData)){
  592 + $userData = $userData->getAttributes();
  593 + unset($userData['id']);
  594 + $userData['project_id'] = $project_id;
  595 + $userModel->insert($userData);
  596 + }
  597 + //复制设置的模版
  598 + $settingTemplateModel = new Setting();
  599 + $settingData = $settingTemplateModel::where('project_id', $this->param['project_id'])->first();
  600 + if(!empty($settingData)){
  601 + $settingData = $settingData->getAttributes();
  602 + unset($settingData['id']);
  603 + $settingData['project_id'] = $project_id;
  604 + $settingTemplateModel->insert($settingData);
  605 + }
  606 + DB::commit();
  607 + }catch (\Exception $e){
  608 + DB::rollBack();
  609 + $this->fail('error');
565 } 610 }
  611 + if($type != 0){
  612 + $this->copyMysql($this->param['project_id'],$project_id);
  613 + }
  614 +<<<<<<< HEAD
566 //复制付费表 615 //复制付费表
567 $paymentModel = new Payment(); 616 $paymentModel = new Payment();
568 $paymentData = $paymentModel::where('project_id', $this->param['project_id'])->first(); 617 $paymentData = $paymentModel::where('project_id', $this->param['project_id'])->first();
@@ -600,6 +649,8 @@ class ProjectLogic extends BaseLogic @@ -600,6 +649,8 @@ class ProjectLogic extends BaseLogic
600 $settingTemplateModel->insert($settingData); 649 $settingTemplateModel->insert($settingData);
601 } 650 }
602 $this->copyMysql($this->param['project_id'],$project_id); 651 $this->copyMysql($this->param['project_id'],$project_id);
  652 +=======
  653 +>>>>>>> e1fa24b098cb6fa80fc919409b2426954c9a660b
603 return $this->success($data); 654 return $this->success($data);
604 } 655 }
605 656
@@ -647,4 +698,21 @@ class ProjectLogic extends BaseLogic @@ -647,4 +698,21 @@ class ProjectLogic extends BaseLogic
647 return true; 698 return true;
648 } 699 }
649 700
  701 + /**
  702 + * 获取AICC采集数据接口token
  703 + * @param $data
  704 + * @return string
  705 + * @author zbj
  706 + * @date 2023/11/10
  707 + */
  708 + public function getAiccToken($data){
  709 + $project = $this->getCacheInfo($data['project_id']);
  710 + if(empty($project['site_token']) || !empty($data['refresh'])){
  711 + $token = strtolower(Str::random() . base64_encode("globalso_v6"));
  712 + $project->site_token = $token;
  713 + $project->save();
  714 + }
  715 + return $project->site_token;
  716 + }
  717 +
650 } 718 }
@@ -29,15 +29,11 @@ class UserLogic extends BaseLogic @@ -29,15 +29,11 @@ class UserLogic extends BaseLogic
29 */ 29 */
30 public function user_info() 30 public function user_info()
31 { 31 {
32 - $info = Common::get_user_cache($this->model, $this->param['id'], 'A');  
33 - if (empty($info)) {  
34 - $info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'role_id' ,'mobile', 'operator_id']);  
35 - if ($info === false) {  
36 - $this->fail('当前数据不存在');  
37 - }  
38 - $info['project_name'] = (new Project())->read(['id' => $info['project_id']], ['title'])['title'];  
39 - Common::set_user_cache($info, $this->model, $this->param['id'], 'A'); 32 + $info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'role_id' ,'mobile', 'operator_id']);
  33 + if ($info === false) {
  34 + $this->fail('当前数据不存在');
40 } 35 }
  36 + $info['project_name'] = (new Project())->read(['id' => $info['project_id']], ['title'])['title'];
41 return $this->success($info); 37 return $this->success($info);
42 } 38 }
43 39
@@ -181,10 +181,6 @@ class CustomTemplateLogic extends BaseLogic @@ -181,10 +181,6 @@ class CustomTemplateLogic extends BaseLogic
181 'route'=>$info['url'], 181 'route'=>$info['url'],
182 ]; 182 ];
183 $this->setRouteDeleteSave($data); 183 $this->setRouteDeleteSave($data);
184 - //"字符串以\"-product\"结尾"  
185 - if (!ends_with($route, "-tag")) {  
186 - $route = $route."-tag";  
187 - }  
188 } 184 }
189 return $route; 185 return $route;
190 } 186 }
@@ -59,6 +59,7 @@ class KeywordLogic extends BaseLogic @@ -59,6 +59,7 @@ class KeywordLogic extends BaseLogic
59 }else{ 59 }else{
60 $this->param['project_id'] = $this->user['project_id']; 60 $this->param['project_id'] = $this->user['project_id'];
61 $this->param['created_at'] = date('Y-m-d H:i:s'); 61 $this->param['created_at'] = date('Y-m-d H:i:s');
  62 + $this->param['title'] = $this->param['title'].'-tag';
62 $this->param['updated_at'] = $this->param['created_at']; 63 $this->param['updated_at'] = $this->param['created_at'];
63 $id = $this->model->insertGetId($this->param); 64 $id = $this->model->insertGetId($this->param);
64 //路由映射 65 //路由映射
@@ -36,8 +36,10 @@ class APublicModel extends Base @@ -36,8 +36,10 @@ class APublicModel extends Base
36 ->where('project_id', $project_id)->where('status', self::STATUS_ON)->count(); 36 ->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
37 $newsNumber = DB::connection('custom_mysql')->table('gl_news') 37 $newsNumber = DB::connection('custom_mysql')->table('gl_news')
38 ->where('project_id', $project_id)->where('status', self::STATUS_ON)->count(); 38 ->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
  39 + $keyNumber = DB::connection('custom_mysql')->table('gl_product_keyword')
  40 + ->where('project_id', $project_id)->where('status', self::STATUS_ON)->count();
39 DB::disconnect('custom_mysql'); 41 DB::disconnect('custom_mysql');
40 - return ['product'=>$productNumber,'blog'=>$blogNumber,'news'=>$newsNumber]; 42 + return ['product'=>$productNumber,'blog'=>$blogNumber,'news'=>$newsNumber,'key'=>$keyNumber];
41 } 43 }
42 44
43 } 45 }
@@ -9,10 +9,115 @@ @@ -9,10 +9,115 @@
9 9
10 namespace App\Models\Project; 10 namespace App\Models\Project;
11 11
  12 +use App\Helper\Arr;
12 use App\Models\Base; 13 use App\Models\Base;
  14 +use Illuminate\Support\Facades\DB;
  15 +use Illuminate\Support\Facades\Log;
  16 +use Illuminate\Support\Facades\Redis;
13 17
14 class ProjectUpdateTdk extends Base 18 class ProjectUpdateTdk extends Base
15 { 19 {
16 //设置关联表名 20 //设置关联表名
17 protected $table = 'gl_project_update_tdk'; 21 protected $table = 'gl_project_update_tdk';
  22 +
  23 + const STATUS_PENDING = 0;
  24 + const STATUS_SUCCESS = 1;
  25 + const STATUS_FAIL = 2;
  26 +
  27 + /**
  28 + * 新建任务
  29 + * @param $project_id
  30 + * @author zbj
  31 + * @date 2023/11/9
  32 + */
  33 + public static function add_task($project_id){
  34 + Redis::lpush('updateSeoTdk', $project_id);
  35 + $model = new self();
  36 + $model->project_id = $project_id;
  37 + $model->save();
  38 + }
  39 +
  40 + /**
  41 + * 获取待处理任务
  42 + * @return mixed
  43 + * @author zbj
  44 + * @date 2023/11/9
  45 + */
  46 + public static function getPendingTask(){
  47 + //有其他任务 就取其他任务 没有其他任务运行未结束的任务
  48 + $project_id = Redis::rpop('updateSeoTdk');
  49 + $data = [];
  50 + if($project_id){
  51 + $data = self::find($project_id);
  52 + }
  53 + if($data){
  54 + return $data;
  55 + }
  56 + return self::where('status', self::STATUS_PENDING)->orderBy('id', 'asc')->first();
  57 + }
  58 +
  59 + /**
  60 + * 重试任务
  61 + * @param $id
  62 + * @param $remark
  63 + * @author zbj
  64 + * @date 2023/11/9
  65 + */
  66 + public static function retry($id, $remark)
  67 + {
  68 + DB::beginTransaction();
  69 + try {
  70 + //行锁 避免脏读写
  71 + $data = self::where('id', $id)->lockForUpdate()->first();
  72 + $data->retry = $data->retry + 1;
  73 + if ($data->retry > 3) {
  74 + $data->status = self::STATUS_FAIL;
  75 + }else{
  76 + $data->status = self::STATUS_PENDING;
  77 + }
  78 + $data->remark = mb_substr($remark, 0, 250);
  79 + $data->save();
  80 +
  81 + DB::commit();
  82 + } catch (\Exception $e) {
  83 + DB::rollback();
  84 + Log::error('project_update_tdk retry error:' . $e->getMessage());
  85 + }
  86 + }
  87 +
  88 + /**
  89 + * 完成
  90 + * @param $id
  91 + * @param $update_data
  92 + * @author zbj
  93 + * @date 2023/11/9
  94 + */
  95 + public static function finish($id, $update_data){
  96 + DB::beginTransaction();
  97 + try {
  98 + //行锁 避免脏读写
  99 + $data = self::where('id', $id)->lockForUpdate()->first();
  100 + $data->status = self::STATUS_SUCCESS;
  101 +
  102 + foreach($update_data as $field => $item){
  103 + $old_date = Arr::s2a($data->$field);
  104 + $new_data = [];
  105 + foreach($item as $k=>$v){
  106 + if($k == 'total_page'){
  107 + $new_data[$k] = $v;
  108 + }else{
  109 + $new_data[$k] = $v + ($old_date[$k] ?? 0);
  110 + }
  111 + }
  112 + $data->$field = $new_data;
  113 + }
  114 +
  115 + $data->save();
  116 +
  117 + DB::commit();
  118 + } catch (\Exception $e) {
  119 + DB::rollback();
  120 + Log::error('project_update_tdk finish error:' . $e->getMessage());
  121 + }
  122 + }
18 } 123 }
@@ -170,6 +170,7 @@ Route::middleware(['aloginauth'])->group(function () { @@ -170,6 +170,7 @@ Route::middleware(['aloginauth'])->group(function () {
170 Route::any('/getRenewLog', [Aside\Project\ProjectController::class, 'getRenewLog'])->name('admin.project_getRenewLog'); 170 Route::any('/getRenewLog', [Aside\Project\ProjectController::class, 'getRenewLog'])->name('admin.project_getRenewLog');
171 Route::any('/tdkList', [Aside\Project\ProjectController::class, 'tdkList'])->name('admin.project_tdkList'); 171 Route::any('/tdkList', [Aside\Project\ProjectController::class, 'tdkList'])->name('admin.project_tdkList');
172 Route::any('/copyProject', [Aside\Project\ProjectController::class, 'copyProject'])->name('admin.project_copyProject'); 172 Route::any('/copyProject', [Aside\Project\ProjectController::class, 'copyProject'])->name('admin.project_copyProject');
  173 + Route::any('/site_token', [Aside\Project\ProjectController::class, 'site_token'])->name('admin.project_site_token');
173 //获取关键词前缀和后缀 174 //获取关键词前缀和后缀
174 Route::prefix('keyword')->group(function () { 175 Route::prefix('keyword')->group(function () {
175 Route::any('/getKeywordPrefix', [Aside\Project\KeywordPrefixController::class, 'getKeywordPrefix'])->name('admin.keyword_getKeywordPrefix'); 176 Route::any('/getKeywordPrefix', [Aside\Project\KeywordPrefixController::class, 'getKeywordPrefix'])->name('admin.keyword_getKeywordPrefix');