CNoticeController.php
7.1 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
<?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\Http\Controllers\Bside\BaseController;
use App\Models\Com\UpdateNotify;
use App\Models\Com\UpdateProgress;
use App\Models\Project\Country as CountryModel;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\WebSetting\WebLanguage;
use Illuminate\Http\Request;
/**
* @remark :通知C端
* @name :CNoticeController
* @author :lyh
* @method :post
* @time :2023/9/12 10:38
*/
class CNoticeController extends BaseController
{
/**
* 更新通知C端
* @param Request $request
* @return \Illuminate\Http\JsonResponse
*/
public function sendNotify(Request $request)
{
$url = $this->user['domain'].'api/update_page/';
$param = [
'project_id' => $this->user['project_id'],
'type' => intval($request->input('type', 1)),
'route' => intval($request->input('page', 1)),
'url' => $request->input('url', []),
'language'=> $request->input('language', []),
];
http_post($url, json_encode($param));
$this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
// $updateProgressModel = new UpdateProgress();
// $progressInfo = $updateProgressModel->formatQuery(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']])->orderBy('id','desc')->first();
// if((!empty($progressInfo))){
// $progressInfo = $progressInfo->toArray();
// if(($progressInfo['total_num'] > $progressInfo['current_num'])){
// $this->response('当前页面正在生成了,请完成后再点击',Code::SUCCESS,$progressInfo);
// }
// }
// //通知更新
// if($this->param['type'] == UpdateNotify::TYPE_MASTER){
// $this->updateMaster();
// }else{
// $this->updateMinorLanguages();
// }
// $urlStr = $this->getString($this->param['type'],$this->param['page']);
// curlGet($urlStr);
// $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();
$lists = $languageModel->list(['id'=>['in',$ids]]);
$this->response('success',Code::SUCCESS,$lists);
}
}