CNoticeController.php
16.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
<?php
/**
* @remark :
* @name :CNoticeController.php
* @author :lyh
* @method :post
* @time :2023/9/12 10:04
*/
namespace App\Http\Controllers\Bside\BCom;
use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Http\Controllers\Bside\BaseController;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory;
use App\Models\Com\NoticeLog;
use App\Models\Com\Notify;
use App\Models\Com\UpdateLog;
use App\Models\Com\UpdateNotify;
use App\Models\Com\UpdateProgress;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\Country as CountryModel;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\WebSetting\SettingNum;
use App\Models\WebSetting\TranslateBigProject;
use App\Models\WebSetting\WebLanguage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* @remark :通知C端
* @name :CNoticeController
* @author :lyh
* @method :post
* @time :2023/9/12 10:38
*/
class CNoticeController extends BaseController
{
/**
* @remark :统计所有小语种
* @name :countLanguagePage
* @author :lyh
* @method :post
* @time :2025/1/4 10:13
*/
public function countLanguagePage(){
$this->request->validate([
'language'=>'required',
],[
'language.required' => 'language不能为空',
]);
$bigProjectModel = new TranslateBigProject();
$project_id_arr = $bigProjectModel->selectField(['status'=>1],'project_id') ?? [];
if(in_array($this->user['project_id'],$project_id_arr)){
$this->response('success');
}
$lang_num = count($this->param['language']);
$keyword_num = (new Keyword())->counts(['route'=>['!=',null]]);
$data_num = $this->productNum() + $this->customNum() + $this->newsNum() + $this->blogNum();
$number = $keyword_num * 18 + $lang_num * $data_num;
if($number >= 450000){
$this->response('success',Code::SUCCESS,['msg'=>'翻译数量过多, 大概页面数量:'.$number.', 磁盘空间占用可能会超过40G,请联系管理员操作!']);
}
//? Copyright - 2010-2024 : All Rights Reserved.© Copyright - 2010-2024 : All Rights Reserved.
$this->response('success');
}
/**
* @remark :产品分类页面数量
* @name :productCateNum
* @author :lyh
* @method :post
* @time :2025/1/4 10:43
*/
public function productNum(){
$number = (new Product())->counts(['status'=>1]);
$settingModel = new SettingNum();
$info = $settingModel->read(['type'=>1]);
if($info === false){
$product_page_number = 15;
}else{
$product_page_number = $info['num'];
}
$productCateModel = new Category();
$productCateList = $productCateModel->list(['status'=>1]);
if(!empty($productCateList)){
$cateReModel = new CategoryRelated();
foreach ($productCateList as $v){
$cate_num = $cateReModel->counts(['cate_id'=>$v['id']]);
if($cate_num == 0){
$number += 1;
}else{
$number += ceil($cate_num / $product_page_number);
}
}
}
return $number;
}
/**
* @remark :新闻数量
* @name :newsNum
* @author :lyh
* @method :post
* @time :2025/1/4 11:21
*/
public function newsNum(){
$newsModel = new News();
$number = $newsModel->counts(['status'=>1]);
$settingModel = new SettingNum();
$info = $settingModel->read(['type'=>2]);
if($info === false){
$news_page_number = 10;
}else{
$news_page_number = $info['num'];
}
$newsCateModel = new NewsCategory();
$newsCateList = $newsCateModel->list(['status'=>0]);
if(!empty($newsCateList)){
foreach ($newsCateList as $v){
$cate_num = $newsModel->counts(['category_id'=>['like',','.$v['id'].',']]);
if($cate_num == 0){
$number += 1;
}else{
$number += ceil($cate_num / $news_page_number);
}
}
}
return $number;
}
/**
* @remark :博客数量
* @name :blogNum
* @author :lyh
* @method :post
* @time :2025/1/4 11:21
*/
public function blogNum(){
$blogModel = new Blog();
$number = $blogModel->counts(['status'=>1]);
$settingModel = new SettingNum();
$info = $settingModel->read(['type'=>3]);
if($info === false){
$news_page_number = 10;
}else{
$news_page_number = $info['num'];
}
$blogCateModel = new BlogCategory();
$blogCateList = $blogCateModel->list(['status'=>0]);
if(!empty($blogCateList)){
foreach ($blogCateList as $v){
$cate_num = $blogModel->counts(['category_id'=>['like',','.$v['id'].',']]);
if($cate_num == 0){
$number += 1;
}else{
$number += ceil($cate_num / $news_page_number);
}
}
}
return $number;
}
/**
* @remark :扩展模块数量
* @name :blogNum
* @author :lyh
* @method :post
* @time :2025/1/4 11:21
*/
public function customNum(){
$contentModel = new CustomModuleContent();
$number = $contentModel->counts(['status'=>0]);
$settingModel = new SettingNum();
$info = $settingModel->read(['type'=>2]);
if($info === false){
$news_page_number = 10;
}else{
$news_page_number = $info['num'];
}
$cateModel = new CustomModuleCategory();
$cateList = $cateModel->list(['status'=>0]);
if(!empty($cateList)){
foreach ($cateList as $v){
$cate_num = $contentModel->counts(['category_id'=>['like',','.$v['id'].',']]);
if($cate_num == 0){
$number += 1;
}else{
$number += ceil($cate_num / $news_page_number);
}
}
}
return $number;
}
/**
* 更新通知C端
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @param : type : 1->主站更新 4->聚合页更新 7->ai博客
*/
public function sendNotify(Request $request)
{
$project_id = $this->user['project_id'];
$type = intval($request->input('type', 1));
$route = intval($request->input('page', 1));
// if(($this->user['is_upgrade'] == 0) && ($type == 2) && in_array($route,[4,6])){
// $this->fail('聚合页翻译请联系管理员');
// }
$url = $request->input('url', []);
$language = $request->input('language', []);
$is_sitemap = intval($request->input('is_sitemap', 0));
if($type == 4){//代表聚合页更新
$keywordModel = new Keyword();
$keywordInfo = $keywordModel->whereNull('seo_title')->orWhereNull('seo_keywords')->orWhereNull('seo_description')->first();
if(!empty($keywordInfo)){
$this->fail('TDK不全,禁止提交。');
}
}
//获取项目所在服务器
$project_model = new Project();
$project_info = $project_model->read(['id'=>$project_id],['serve_id','is_upgrade', 'main_lang_id']);
if(!$project_info){
$this->fail('未查询到项目数据');
}
// --------------------------------------------------- 特殊处理通知生成页面 --------------------------------------------------------------
if ($type == 2 && $project_info['main_lang_id'] == 8) {
$this->fail('申请项目主语种为俄语,禁止翻译小语种,如若需要翻译小语种, 请联系售后人员确认!');
}
$serve_ip_model = new ServersIp();
$serve_ip_info = $serve_ip_model->read(['id'=>$project_info['serve_id']],['servers_id']);
$servers_id = $serve_ip_info ? $serve_ip_info['servers_id'] : 0;
//如果是升级项目,判断是否还有采集在进行中
if($project_info['is_upgrade'] == 1){
$collect_info = UpdateLog::getProjectUpdate($project_id);
if($collect_info == '采集中'){
$this->fail('当前升级项目还有页面正在采集,请采集完成之后再更新静态页面');
}
}
if($servers_id == ServerConfig::SELF_SITE_ID){
//自建站服务器:如果项目已经上线,不请求C端接口,数据直接入库
$domain_model = new DomainInfo();
$domain_info = $domain_model->read(['project_id'=>$this->user['project_id']],['domain']);
if($domain_info){
//判断是否已有更新进行中
$notify_model = new Notify();
$type = $is_sitemap == 1 ? Notify::TYPE_ALL_SITEMAP : $type;
$data = [
'project_id' => $project_id,
'type' => $type,
'route' => $route,
'server_id' => ServerConfig::SELF_SITE_ID,
'status' => ['!=',Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data,['id']);
if(!$notify){
$domain = $domain_info['domain'];
if($type == Notify::TYPE_AMP){
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.',$host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$domain = implode('.',$host_array);
}
$data['data'] = Arr::a2s(['domain'=>$domain,'url'=>$url,'language'=>$language]);
$data['status'] = $is_sitemap == 1 ? Notify::STATUS_FINISH_PAGE : Notify::STATUS_INIT;
$data['is_pull_html_zip'] = $is_sitemap == 1 ? Notify::IS_PULL_HTML_ZIP_TRUE : Notify::IS_PULL_HTML_ZIP_FALSE;
$data['sort'] = 1;
$notify_model->add($data);
}
}
}else{
//其他服务器:请求对应C端接口
$c_url = $this->user['domain'].'api/update_page/';
$c_param = [
'project_id' => $this->user['project_id'],
'type' => $type,
'route' => $route,
'url' => $url,
'language'=> $language,
'is_sitemap' => $is_sitemap
];
try {
http_post($c_url, json_encode($c_param));
}catch (\Exception $e){
NoticeLog::createLog(NoticeLog::GENERATE_PAGE, json_encode(['c_url'=>$c_url,'c_params'=>$c_param]));
}
}
$this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
}
/**
* @remark :主站通知
* @name :updateMaster
* @author :lyh
* @method :post
* @time :2023/9/12 14:46
*/
public function updateMaster(){
try {
$updateNotifyModel = new UpdateNotify();
if($this->param['page'] == UpdateNotify::PAGE_ALL){
//如果是更新所有
$routeMapModel = new RouteMap();
$count = $routeMapModel->formatQuery(['project_id'=>$this->user['project_id']])->count();
$updateNotifyModel->edit(['status' => 1], ['project_id' => $this->user['project_id'], 'status' => 0]);
$this->addProgress($count,$this->param['type'],$this->param['page']);
}elseif($this->param['page'] == UpdateNotify::PAGE_SINGLE){
//更新所有已修改的更新
$count = $updateNotifyModel->formatQuery(['project_id' => $this->user['project_id'], 'status' => 0])->count();
$updateNotifyModel->edit(['status' => 1], ['project_id' => $this->user['project_id'], 'status' => 0]);
$this->addProgress($count,$this->param['type'],$this->param['page']);
}else{
//根据传递的参数更新
$count = count($this->param['url']);
$extent = json_encode(['url'=>$this->param['url']]);
$this->addProgress($count,$this->param['type'],$this->param['page'],$extent);
}
}catch (\Exception $e){
$this->response('error',Code::USER_ERROR);
}
return true;
}
/**
* @remark :更新小语种
* @name :updateMinorLanguages
* @author :lyh
* @method :post
* @time :2023/9/12 14:48
*/
public function updateMinorLanguages(){
$updateNotifyModel = new UpdateNotify();
try {
if($this->param['page'] == UpdateNotify::PAGE_ALL){
//如果是更新所有
$routeMapModel = new RouteMap();
$count = $routeMapModel->formatQuery(['project_id'=>$this->user['project_id']])->count();
$updateNotifyModel->edit(['minor_languages_status' => 1], ['project_id' => $this->user['project_id'], 'minor_languages_status' => 0]);
$extent = json_encode(['language'=>$this->param['language']]);
$this->addProgress($count,$this->param['type'],$this->param['page'],$extent);
}else{
//根据传递的参数更新
$count = count($this->param['url']);
$extent = json_encode(['url'=>$this->param['url'],'language'=>$this->param['language']]);
$this->addProgress($count,$this->param['type'],$this->param['page'],$extent);
}
//更新小语种,同步更新项目表已翻译小语种
if(isset($this->user['is_domain']) && ($this->user['is_domain'] != 0)){
$projectModel = new Project();
$projectModel->edit(['is_language'=>$this->user['is_domain']],['id'=>$this->user['project_id']]);
}
}catch (\Exception $e){
$this->response('error',Code::USER_ERROR);
}
return true;
}
/**
* @remark :生成一条更新记录
* @name :addProgress
* @author :lyh
* @method :post
* @time :2023/9/6 17:01
*/
public function addProgress($count,$type,$page,$extend = ''){
$data = [
'total_num'=>$count,
'current_num'=>0,
'type'=>$type,
'page'=>$page,
'extends'=>!empty($extend) ? $extend : json_encode([]),
'project_id'=>$this->user['project_id'],
'created_at'=>date('Y-m-d H;i:s')
];
$updateProgressModel = new UpdateProgress();
$updateProgressModel->insert($data);
return true;
}
/**
* @remark :通知参数处理
* @name :getString
* @author :lyh
* @method :post
* @time :2023/9/6 17:03
*/
public function getString($type,$page){
$param = [
'project_id' => $this->user['project_id'],
'type' => $type,
'route' => $page
];
$string = http_build_query($param);
return $this->user['domain'].'api/updateHtmlNotify/?' . $string;
}
/**
* @remark :获取当前项目选中的语种
* @name :getCountry
* @author :lyh
* @method :post
* @time :2023/9/12 15:20
*/
public function getCountry(){
$countryModel = new CountryModel();
$info = $countryModel->read(['project_id'=>$this->user['project_id']],['id','country_lists']);
$ids = [];
if($info !== false){
$ids = explode(',',$info['country_lists']);
}
$languageModel = new WebLanguage();
if(empty($ids)){
array_push($ids,1);
}
//根据排序查询选中的小语种
$lists = $languageModel->whereIn('id', $ids)->orderByRaw(DB::raw("FIND_IN_SET(id,'" . implode(',', $ids) . "'" . ')'))->get()->toArray();
$this->response('success',Code::SUCCESS,$lists);
}
}