FetchTicketProjects.php
15.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
<?php
namespace App\Console\Commands\WorkOrder;
use App\Models\Manage\Manage;
use App\Models\Manage\ManageHr;
use App\Models\Project\Project;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\WorkOrder\TicketProject;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
class FetchTicketProjects extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'workorder:fetch-ticket-projects {action}';
/**
* The console command description.
*
* @var string
*/
protected $description = '同步V5,V6的项目到 gl_ticket_projects 表';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$action = $this->argument('action');
$this->$action();
return 0;
}
/**
* @return void
* 请求:https://www.quanqiusou.cn/extend_api/webs/globalso_all.php
*/
public function fetchV5()
{
$page = 1;
$postids = [];
while (true) {
$response = Http::get('https://www.quanqiusou.cn/extend_api/webs/globalso_all.php?page=' . $page);
if ($response->status() == 200) {
$resp_json = $response->json();
$items = $resp_json['data'] ?? [];
if (empty($items))
{
echo now() . " | INFO | V5: not found items on page $page \n";
break;
}
foreach ($items as $item) {
# V5: 版本号+postid
$uuid = md5("V5{$item['postid']}");
$project = TicketProject::where('uuid', $uuid)->first();
// 项目状态, 根据 $item['cate'] 判断,建站中,建站客户,推广
if (strpos($item['cate'], '推广') !== false)
$status=3; // 推广
elseif ($item['cate'] == "建站客户")
$status=2; // 建站客户
elseif ($item['cate'] == "建站中")
$status=1; // 建站中
$assm_id = Manage::where('name', $item['assm'])->value('id') ?? Manage::where('name', '张鸿飞')->value('id') ?? 0; //售后服务经理
$seom_id = Manage::where('name', $item['yhs'])->value('id') ?? Manage::where('name', '陶婵')->value('id') ?? 0; //优化师
$pm_id = Manage::where('name', $item['pm'])->value('id') ?? Manage::where('name', '李洁玉')->value('id') ?? 0; // 项目经理
/**
* 第一负责人逻即说明:
* 优化推广项目:找售后服务经理??鸿飞
* 建站中:项目经理
* 建站完成:杨长远
*/
if ($status == 3)
$engineer_id = $assm_id; // 推广类项目找售后服务经理
elseif ($status == 2)
$engineer_id = Manage::where('name', '杨长远')->value('id') ?? 0; //建站完成
elseif ($status == 1)
$engineer_id = $pm_id; // 建站中找项目经理
$fields = [
'post_id' => $item['postid'],
'company_name' => $item['company'],
'title' => $item['title'],
'engineer_id' => $engineer_id, // 第一负责人
'assm_id' => $assm_id,
'seom_id' => $seom_id,
'website' => $item['main_url'] ?? '',
'test_website' => $item['test_url'] ?? '',
'is_del' => 0,
'plan' => $item['plan'] ?? '',
'project_cate' => 1,
'pm_id' => $pm_id,
'status' => $status, // 项目状态
'wechat_group_id' => $item['wx_id']
];
if (!$project) {
$new = new TicketProject();
$new->uuid = $uuid;
$new->version = 5;
$new->table_id = 0;
foreach ($fields as $k => $v) {
$new->$k = $v;
}
$new->save();
} else {
$changed = false;
foreach ($fields as $k => $v) {
if ($project->$k != $v) {
$project->$k = $v;
$changed = true;
}
}
if ($changed) {
$project->save();
}
}
echo now() . " | INFO | V5: {$item['postid']} {$item['company']} fetch ok \n";
}
$page++;
$postids = array_merge($postids, collect($items)->pluck('postid')->toArray());
}
}
if ($postids)
{
// 软删除 gl_ticket_projects 中不存在的项目
TicketProject::where('version', 5)
->whereNotIn('post_id', $postids)
->update(['is_del' => 1]);
}
}
/**
* @return void
* 1. 按照ID升序查询 gl_project 表 limit 10
* 2。同步到 TicketProject 后,redis 缓存 ID
*/
public function fetchV6()
{
$lastid = 0;
while (true) {
try {
$items = Project::where('id', '>', intval($lastid))
// ->where('delete_status', 0)
// ->where('extend_type', '!=', 5) // 排除归档项目
// ->where('type', '!=', 8) // 排除归档项目
->orderBy('id', 'asc')
->limit(10)
->get();
if ($items->isEmpty()) {
echo "not found items \n";
break;
}
foreach ($items as $item) {
$uuid = md5("V6{$item->id}");
$project = TicketProject::where('uuid', $uuid)->first();
// 项目状态
if ($item->type == Project::TYPE_ONE)
$status = 1; // 建站中
elseif ($item->type == Project::TYPE_THREE)
$status = 2; // 建站完成
else
$status = 3; // 推广找售后服务经理
// 售后服务经理
$assm_id = collect([
ManageHr::find($item->deploy_optimize->manager_mid)->manage_id ?? 0,
ManageHr::find($item->deploy_optimize->tech_leader)->manage_id ?? 0,
8, //张鸿飞
])->first(fn($v) => $v !== null && $v !== 0, 0);
// 优化师
$seom_id = ManageHr::find($item->deploy_optimize->optimist_mid) ? ManageHr::find($item->deploy_optimize->optimist_mid)->manage_id : 0;
// 项目经理
$pm_id = ManageHr::find($item->deploy_build->manager_mid)->manage_id ?? ManageHr::where('name', '李洁玉')->value('manage_id') ?? 0;
// 第一负责人
if ($status == 1)
$engineer_id = $pm_id; // 建站中找项目经理
elseif ($status == 2)
$engineer_id = Manage::where('name', '杨长远')->value('id') ?? 0; // 建站完成找杨长远
else
$engineer_id = $assm_id; // 推广找售后服务经理
$is_del = (
$item->extend_type == 5
|| $item->type == 8
|| $item->delete_status == 1
|| $item->site_status == 1
) ? 1 : 0;
$fields = [
'company_name' => $item->company,
'title' => $item->title,
'assm_id' => $assm_id,
'seom_id' => $seom_id,
'engineer_id' => $engineer_id,
'is_del' => $is_del,
'website' => !empty($item->domainInfo->domain) ? 'https://'.$item->domainInfo->domain : '',
'test_website' => $item->deploy_build->test_domain ?? '',
'version' => empty($item->version) ? 7 : $item->version, // 版本号
'plan' => $item->planMap()[$item->deploy_build->plan] ?? '',
'project_cate' => 2,
'wechat_group_id' => ProjectAssociation::where('project_id', $project->table_id)
->where('status', ProjectAssociation::STATUS_NORMAL)
->where('binding_app', ProjectAssociation::ENTERPRISE_WECHAT)
->value('friend_id'),
'pm_id' => $pm_id,
'status' => $status, // 项目状态
];
if (!$project) {
$project = new TicketProject();
$project->uuid = $uuid;
$project->post_id = $item->post_id;
$project->table_id = $item->id;
foreach ($fields as $k => $v) {
$project->$k = $v;
}
$project->save();
} else {
$changed = false;
foreach ($fields as $k => $v) {
if ($project->$k != $v) {
$project->$k = $v;
$changed = true;
}
}
if ($changed) {
$project->save();
}
}
$lastid = $item->id;
echo date('Y-m-d H:i:s') . " V6: $item->id {$item->company} fetch ok \n";
}
} catch (\Exception $exception) {
echo $exception;
break;
}
}
}
public function fetchAICC()
{
$lastid = 0;
while (true) {
try {
$response = Http::withBasicAuth('bill', 'bill@ai.cc')
->get('https://fob.ai.cc/api/tickets/projects', [
'lastid' => $lastid,
]);
$items = $response->json();
if (empty($items))
{
echo now() . " | INFO | not found items \n";
break;
}
foreach ($items as $item) {
foreach ($item['plans'] as $plan)
{
// 判断套餐是超迹还是域途, 如果 $item['plans'][0]['name'] 包含 '超迹' 则为超迹,否则为域途
$project_cate = Str::contains($plan['name'], '超迹') ? 3 : 4;
$uuid = md5("AICC{$item['id']}{$project_cate}");
$project = TicketProject::where('uuid', $uuid)->first();
if ($project_cate == 3)
{
// 售后服务经理
$assm_id = collect([
ManageHr::where('name', $item['cj_assm']['real_name'] ?? '')->first()->manage_id ?? 0,
20, //徐莹
])->first(fn($v) => $v !== null && $v !== 0, 0);
}else
{
// 域途
$assm_id = collect([
ManageHr::where('name', $item['yutu_assm']['real_name'] ?? '')->first()->manage_id ?? 0,
85, //黄小玉
])->first(fn($v) => $v !== null && $v !== 0, 0);
}
// 优化师
$seom_id = 0;
// 第一负责人
$engineer_id = $assm_id;
$is_del = 0;
$fields = [
'company_name' => $item['company'],
'title' => $item['company'] . " - " . $plan['name'],
'assm_id' => $assm_id,
'seom_id' => $seom_id,
'engineer_id' => $engineer_id,
'is_del' => $is_del,
'website' => '',
'test_website' => '',
'version' => 1, // 版本号
'plan' => $plan['name'] ?? '',
'project_cate' => $project_cate,
'wechat_group_id' => $item['chatroom_id'],
];
if (!$project) {
$project = new TicketProject();
$project->uuid = $uuid;
$project->post_id = $item['postid'];
$project->table_id = $item['id'];
foreach ($fields as $k => $v) {
$project->$k = $v;
}
$project->save();
} else {
$changed = false;
foreach ($fields as $k => $v) {
if ($project->$k != $v) {
$project->$k = $v;
$changed = true;
}
}
if ($changed) {
$project->save();
}
}
$lastid = $item['id'];
echo now() . " | INFO | AICC: {$item['id']} {$item['company']} fetch ok \n";
}
}
}catch (\Exception $exception){
echo now() . " | ERROR | " . $exception->getMessage() . "\n" . $exception->getTraceAsString() . "\n";
break;
}
}
}
public function fetch_uuid()
{
$lastid = 0;
while (true) {
try {
$items = TicketProject::where('id', '>', $lastid)
->where('version', 6)
->orderBy('id', 'asc')
->limit(10)
->get();
if ($items->isEmpty()) {
echo "not found items \n";
break;
}
foreach ($items as $item) {
$uuid = md5("V6{$item->table_id}");
$item->uuid = $uuid;
$item->save();
$lastid = $item->id;
echo date('Y-m-d H:i:s') . " V6: $item->id fetch ok \n";
}
} catch (\Exception $exception) {
echo $exception;
break;
}
}
}
}