ProjectLogic.php
42.6 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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
<?php
namespace App\Http\Logic\Aside\Project;
use App\Enums\Common\Code;
use App\Events\CopyImageFile;
use App\Events\CopyProject;
use App\Exceptions\AsideGlobalException;
use App\Helper\Arr;
use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Http\Logic\Aside\BaseLogic;
use App\Jobs\CopyImageFileJob;
use App\Jobs\CopyProjectJob;
use App\Models\Ai\AiBlogAuthor;
use App\Models\Channel\Channel;
use App\Models\Channel\User;
use App\Models\Channel\Zone;
use App\Models\Com\NoticeLog;
use App\Models\Com\UpdateLog;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainInfo;
use App\Models\Industry\ProjectIndustryRelated;
use App\Models\Inquiry\InquiryIP;
use App\Models\Inquiry\InquirySet;
use App\Models\Manage\Manage;
use App\Models\Project\After;
use App\Models\Project\AiBlogTask;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\InquiryFilterConfig;
use App\Models\Project\MinorLanguages;
use App\Models\Project\Payment;
use App\Models\Project\Project;
use App\Models\Project\ProjectAiSetting;
use App\Models\Project\ProjectKeyword;
use App\Models\Project\ProjectRenew;
use App\Models\Project\WebTrafficConfig;
use App\Models\RankData\ExternalLinks;
use App\Models\RankData\IndexedPages;
use App\Models\RankData\RankData;
use App\Models\RankData\RankWeek;
use App\Models\RankData\RecommDomain;
use App\Models\RankData\Speed;
use App\Models\User\ProjectMenu;
use App\Models\User\ProjectRole;
use App\Models\User\User as UserModel;
use App\Models\WebSetting\WebLanguage;
use App\Services\AiBlogService;
use App\Services\ProjectServer;
use App\Services\SyncService;
use App\Utils\LogUtils;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
/**
* Class ProjectLogic
* @package App\Http\Logic\Aside\Project
* @author zbj
* @date 2023/4/26
*/
class ProjectLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new Project();
}
/**
* @remark :获取当前数据详情
* @name :getProjectInfo
* @author :lyh
* @method :post
* @time :2023/7/28 17:11
*/
public function getProjectInfo($id){
$info = $this->model->with(['payment', 'deploy_build', 'deploy_optimize', 'online_check',
'project_after','inquiry_filter_config','web_traffic_config','project_keyword'])->where(['id'=>$id])->first()->toArray();
$info['online_check']['name'] = (new Manage())->getName($info['online_check']['created_manage_id'] ?? 0);
$info['init_domain'] = $this->getInitDomain($info['serve_id'])['domain'];
if($info['extend_type'] != 0){
$info['type'] = $info['extend_type'];
}
$info['domain_url'] = (new DomainInfo())->getDomain($info['deploy_optimize']['domain'] ?? 0);
//升级项目初始上传配置
if(empty($info['upload_config'])){
$info['upload_config'] =["upload_max_num"=>100, "allow_file_type"=>"doc,docx,xls,xlsx,pdf,txt,csv,png,jpg,jpeg", "upload_max_size"=>5];
}
if(empty($info['channel'])){
$info['channel'] = ["user_id"=>"", "zone_id"=>"", "channel_id"=>""];
}
if(empty($info['payment']['renewal_record'])){
$info['payment']['renewal_record'] = [["amount"=> null, "remark"=> null, "expire_at"=> null]];
}
if(isset($info['is_customized']) && $info['is_customized'] == 1){
$info['is_visualization'] = json_decode($info['is_visualization']);
}
if(isset($info['deploy_build']['other_project']) && !empty($info['deploy_build']['other_project'])){
$info['deploy_build']['other_project']= json_decode($info['deploy_build']['other_project']);
}
if(isset($info['project_keyword']['operator_log']) && !empty($info['project_keyword']['operator_log'])){
$info['project_keyword']['operator_log'] = json_decode($info['project_keyword']['operator_log']);
}
//is_product:"0",is_news:"0",is_blogs:"0",is_module:"0"
//获取小语种
$info['minor_languages'] = $this->getProjectMinorLanguages($id);
//升级项目采集完成时间
$info['collect_time'] = $info['is_upgrade'] ? UpdateLog::getProjectUpdate($id) : '';
//获取项目所属行业
$info['industry'] = ProjectIndustryRelated::where('project_id', $id)->pluck('industry_id')->toArray();
return $this->success($info);
}
/**
* @remark :获取当前项目的小语种配置
* @name :getProjectMinorLanguages
* @author :lyh
* @method :post
* @time :2024/6/18 11:05
*/
public function getProjectMinorLanguages($project_id){
$projectMinorLanguagesModel = new MinorLanguages();
$lists = $projectMinorLanguagesModel->list(['project_id'=>$project_id,'is_delete'=>0]);
return $this->success($lists);
}
/**
* @remark :获取初始域名
* @name :getInitDomain
* @author :lyh
* @method :post
* @time :2023/9/16 9:40
*/
public function getInitDomain($serve_id = ''){
$domain = '';
if(!empty($serve_id)){
$serverIpModel = new ServersIp();
$info = $serverIpModel->read(['id'=>$serve_id]);
if($info !== false){
$domain = $info['domain'];
}
}
return $this->success(['domain'=>$domain]);
}
/**
* @remark :保存项目数据
* @name :projectSave
* @author :lyh
* @method :post
* @time :2023/8/30 11:57
*/
public function projectSave(){
DB::beginTransaction();
try {
if($this->param['type'] == Project::TYPE_SEVEN){
//错误单直接返回,单独处理
$this->setTypeSevenEdit($this->param);
}else{
//初始化项目
$this->createProjectData($this->param);
//双向绑定服务器,需放到保存项目的上方
$this->setServers($this->param['serve_id'],$this->param['id']);
//ai_blog
$this->setAiBlog($this->param['id'],$this->param['main_lang_id'],$this->param['is_ai_blog'],$this->param['title']);
//保存项目信息
$this->saveProject($this->param);
//保存建站部署信息
$this->saveProjectDeployBuild($this->param['deploy_build']);
//保存付费信息
$this->saveProjectPayment($this->param['payment']);
//保存优化信息
$this->saveProjectDeployOptimize($this->param['deploy_optimize']);
//保存项目关键字
$this->saveProjectKeyword($this->param['project_keyword'] ?? [],$this->param['id']);
//保存售后信息
$this->saveProjectAfter($this->param['project_after']);
//单独保存小语种配置
$this->saveMinorLanguages($this->param['minor_languages'] ?? [],$this->param['id']);
//同步图片文件
$this->syncImageFile($this->param['project_location'],$this->param['id']);
//同步信息表
(new SyncService())->projectAcceptAddress($this->param['id']);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('保存失败,请联系管理员');
}
return $this->success();
}
/**
* @remark :开启AI博客后
* @name :setAiBlog
* @author :lyh
* @method :post
* @time :2025/2/13 16:02
*/
public function setAiBlog($project_id,$main_lang_id,$is_ai_blog,$title){
if(empty($main_lang_id) || empty($is_ai_blog)){
return true;
}
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$project_id],['title','is_ai_blog','main_lang_id','company']);
//获取项目主语种
$languageModel = new WebLanguage();
$languageInfo = $languageModel->read(['id'=>$main_lang_id],['short']);
if($languageInfo == false){
return true;
}
$aiSettingModel = new ProjectAiSetting();
$aiSettingInfo = $aiSettingModel->read(['project_id'=>$project_id]);
if($aiSettingInfo === false){
$aiBlogService = new AiBlogService();
$result = $aiBlogService->createProject($title,$languageInfo['short'],$projectInfo['company']);
if(isset($result['status']) && $result['status'] == 200){
//查看当前项目是否已有记录
$resData = [
'project_id'=>$project_id,
'mch_id'=>$result['data']['mch_id'],
'key'=>$result['data']['key'],
];
$aiSettingModel->add($resData);
$this->createAuthor($project_id,$result['data']['mch_id'],$result['data']['key']);
}
}else{
//有信息更新
if(($projectInfo['title'] != $title) || ($projectInfo['main_lang_id'] != $main_lang_id)){
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
$aiBlogService->key = $aiSettingInfo['key'];
$aiBlogService->updatedProject($title,$languageInfo['short']);
}
}
return true;
}
/**
* @remark :创建作者
* @name :createAuthor
* @author :lyh
* @method :post
* @time :2025/2/21 11:17
*/
public function createAuthor($project_id,$mch_id,$key){
//查看当前项目是否已经创建了作者
$aiBlogTaskModel = new AiBlogTask();
$count = $aiBlogTaskModel->counts(['project_id'=>$project_id]);
if($count > 0){
return true;
}
$aiBlogService = new AiBlogService();
$aiBlogService->mch_id = $mch_id;
$aiBlogService->key = $key;
$result = $aiBlogService->createAuthor();
if($result['status'] == 200){
$aiBlogTaskModel->add(['project_id'=>$project_id,'status'=>1,'type'=>1]);
}
return true;
}
/**
* @remark :选择服务器后双向绑定
* @name :setServers
* @author :lyh
* @method :post
* @time :2024/6/25 15:34
*/
public function setServers($servers_id,$project_id){
if(empty($servers_id)){
return $this->success();
}
//查看當前項目服務器是否有更改
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$project_id],['serve_id']);
$serversIpModel = new ServersIp();
$serversModel = new Servers();
if(!empty($projectInfo['serve_id'])){
if($projectInfo['serve_id'] == $servers_id){
return $this->success();
}
$oldServerIpInfo = $serversIpModel->read(['id'=>$projectInfo['serve_id']]);
if($oldServerIpInfo !== false){
$serversIpModel->where(['id'=>$projectInfo['serve_id']])->decrement('total',1);
$serversModel->where(['id'=>$oldServerIpInfo['servers_id']])->decrement('being_number',1);
}
}
if(empty($servers_id)){
return $this->success();
}
$serversIpInfo = $serversIpModel->read(['id'=>$servers_id]);
$serversInfo = $serversModel->read(['id'=>$serversIpInfo['servers_id']]);
if($serversIpInfo['total'] >= $serversInfo['ip_total']){
$this->fail('请选择其他服务器,当前ip已满');
}
$serversIpModel->where(['id'=>$servers_id])->increment('total',1);
$serversModel->where(['id'=>$serversInfo['id']])->increment('being_number',1);
return $this->success();
}
/**
* @remark :危险项目同步图片与文件
* @name :syncImageFile
* @author :lyh
* @method :post
* @time :2024/6/18 10:51
*/
public function syncImageFile($location,$project_id){
if($location == 1){
CopyImageFileJob::dispatch(['project_id'=>$project_id]);
}
return $this->success();
}
/**
* @remark :保存项目
* @name :setExtendType
* @author :lyh
* @method :post
* @time :2023/8/30 12:14
*/
public function saveProject($param){
if((($param['type'] == Project::TYPE_TWO) || ($param['type'] == Project::TYPE_THREE)) && empty($param['uptime'])){
$param['uptime'] = date('Y-m-d H:i:s');
}
if($param['type'] == Project::TYPE_FIVE){
$param['extend_type'] = Project::TYPE_FIVE;
unset($param['type']);
}
if(isset($param['level']) && !empty($param['level'])){
$param['level'] = Arr::arrToSet($param['level']);
}
if(isset($param['channel']) && !empty($param['channel'])){
$param['channel'] = Arr::a2s($param['channel']);
}
if(isset($param['notice_file']) && !empty($param['notice_file'])){
foreach ($param['notice_file'] as &$v1) {
if(isset($v1['url']) && !empty($v1['url'])){
$v1['url'] = str_replace_url($v1['url']);
}
}
$param['notice_file'] = Arr::a2s($param['notice_file']);
}
if(isset($param['confirm_file']) && !empty($param['confirm_file'])){
foreach ($param['confirm_file'] as &$v2) {
if(isset($v2['url']) && !empty($v2['url'])){
$v2['url'] = str_replace_url($v2['url']);
}
}
$param['confirm_file'] = Arr::a2s($param['confirm_file']);
}
$param['remain_day'] = $param['deploy_build']['service_duration'] - $param['finish_remain_day'];
$param['remain_day'] = ($param['remain_day'] > 0) ? $param['remain_day'] : 0;
//文件上传默认值
if($param['is_upload_manage']){
$param['upload_config'] = [
'upload_max_num' => $param['upload_config']['upload_max_num'] ?? 100,
'allow_file_type' => $param['upload_config']['allow_file_type'] ?? 'doc,docx,xls,xlsx,pdf,txt,csv,png,jpg,jpeg',
'upload_max_size' => $param['upload_config']['upload_max_size'] ?? 5,
];
}
if(isset($param['is_customized']) && ($param['is_customized'] == 1)){
if(!empty($param['is_visualization'])){
$param['is_visualization'] = json_encode($param['is_visualization']);
}
}
$param['upload_config'] = json_encode($param['upload_config'] ?? []);
$param['web_traffic_config'] = json_encode($param['web_traffic_config'] ?? []);
$robots = $this->model->read(['id'=>$param['id']],['robots'])['robots'];
if($robots == Project::TYPE_ONE){//开启
$param['robots'] = Project::TYPE_ONE;
}
$this->model->edit($param,['id'=>$param['id']]);
Common::del_user_cache($this->model->getTable(),$param['id']);
return $this->success();
}
/**
* @remark :保存付款续费
* @name :savePayment
* @author :lyh
* @method :post
* @time :2023/8/29 16:19
*/
protected function saveProjectPayment($payment){
$paymentModel = new Payment();
if(isset($payment['contract']) && !empty($payment['contract'])){
$payment['contract'] = Arr::a2s($payment['contract']);
}
if(isset($payment['bill']) && !empty($payment['bill'])){
$payment['bill'] = Arr::a2s($payment['bill']);
}
if(isset($payment['renewal_record']) && !empty($payment['renewal_record'])){
$payment['renewal_record'] = Arr::a2s($payment['renewal_record']);
}
$paymentModel->edit($payment,['id'=>$payment['id']]);
return $this->success();
}
/**
* @remark :保存建站部署
* @name :saveDeployBuild
* @author :lyh
* @method :post
* @time :2023/8/29 16:19
*/
protected function saveProjectDeployBuild($deploy_build){
$deployBuildModel = new DeployBuild();
$deploy_build['configuration'] = Arr::a2s(!empty($deploy_build['configuration']) ? $deploy_build['configuration'] : []);
$deployBuildModel->edit($deploy_build,['id'=>$deploy_build['id']]);
return $this->success();
}
/**
* @remark :保存优化部署
* @name :saveDeployOptimize
* @author :lyh
* @method :post
* @time :2023/8/30 13:45
*/
protected function saveProjectDeployOptimize($deploy_optimize){
$deployOptimizeModel = new DeployOptimize();
if(isset($deploy_optimize['domain']) && !empty($deploy_optimize['domain'])){
//更改域名
$this->editDomainStatus($deploy_optimize['domain'],$deploy_optimize['project_id']);
}
$deploy_optimize['g_top_plan'] = Arr::a2s($deploy_optimize['g_top_plan'] ?? []);
$deploy_optimize['special'] = !empty($deploy_optimize['special']) ? ','.trim($deploy_optimize['special'],',').',' : '';
//是否更新了api_no
$api_no = DeployOptimize::where('id', $deploy_optimize['id'])->value('api_no');
if(!empty($api_no)){
if($api_no != $deploy_optimize['api_no']){
if($deploy_optimize['api_no']){
NoticeLog::createLog(NoticeLog::TYPE_RANK_DATA, ['api_no' => $deploy_optimize['api_no'] ?: 0]);
}else{
//清空已有排名数据
RankData::where('project_id', $deploy_optimize['project_id'])->delete();
ExternalLinks::where('project_id', $deploy_optimize['project_id'])->delete();
IndexedPages::where('project_id', $deploy_optimize['project_id'])->delete();
RecommDomain::where('project_id', $deploy_optimize['project_id'])->delete();
Speed::where('project_id', $deploy_optimize['project_id'])->delete();
RankWeek::where('project_id', $deploy_optimize['project_id'])->delete();
}
}
}
$deployOptimizeModel->edit($deploy_optimize,['id'=>$deploy_optimize['id']]);
return $this->success();
}
/**
* @remark :保存项目关键字
* @name :saveProjectKeyword
* @author :lyh
* @method :post
* @time :2024/7/22 11:45
*/
public function saveProjectKeyword($project_keyword,$project_id){
$projectKeywordModel = new ProjectKeyword();
$info = $projectKeywordModel->read(['project_id'=>$project_id]);
$data = [
'main_keyword'=>$project_keyword['main_keyword'] ?? '',
'customer_keywords'=>$project_keyword['customer_keywords'] ?? '',
'search_keywords'=>$project_keyword['search_keywords'] ?? '',
];
if(isset($project_keyword['operator_log']) && !empty($project_keyword['operator_log'])){
$data['operator_log'] = json_encode($project_keyword['operator_log'] ?? []);
}
if($info === false){
$data['project_id'] = $project_id;
$projectKeywordModel->addReturnId($data);
}else{
$projectKeywordModel->edit($data,['id'=>$info['id']]);
}
return $this->success();
}
/**
* @remark :保存为售后部署
* @name :saveProjectAfter
* @author :lyh
* @method :post
* @time :2023/8/30 13:57
*/
protected function saveProjectAfter($project_after){
//查询数据是否存在
$afterModel = new After();
$afterModel->edit($project_after,['id'=>$project_after['id']]);
return $this->success();
}
/**
* @remark :保存小语种配置
* @name :saveMinorLanguages
* @author :lyh
* @method :post
* @time :2023/8/30 13:57
*/
protected function saveMinorLanguages($minor_language,$project_id){
$data = [];
$languageModel = new MinorLanguages();
if(!empty($minor_language)){
$webLanguageModel = new WebLanguage();
$result = [];
foreach ($minor_language as $v){
if(!empty($v['lang'])){
$zh = $webLanguageModel->read(['short'=>$v['lang']],['chinese']);
if($zh === false){
continue;
}
$info = $languageModel->read(['lang'=>$v['lang'],'project_id'=>$project_id]);
if($info === false){
//获取小语种达标天数
$result['language'] = $zh['chinese'];
$result['lang'] = $v['lang'];
$result['created_at'] = date('Y-m-d H:i:s');
$result['updated_at'] = date('Y-m-d H:i:s');
$result['project_id'] = $project_id;
$result['service_day'] = $v['service_day'] ?? 50;
$result['type'] = $v['type'] ?? 0;
$result['keywords'] = $v['keywords'] ?? 50;
$result['minor_keywords'] = $v['minor_keywords'] ?? '';
$data[] = $result;
}else{
$editParam = [
'service_day'=>$v['service_day'],
'type'=>$v['type'],
'keywords'=>$v['keywords'],
'minor_keywords'=>$v['minor_keywords'] ?? '',
'is_delete'=>0
];
$languageModel->edit($editParam,['id'=>$info['id']]);
}
}
}
if(!empty($data)){
$languageModel->insert($data);
}
}
return $this->success();
}
/**
* @remark :删除小语种(主键id)
* @name :deleteMinorLanguages
* @author :lyh
* @method :post
* @time :2024/6/18 11:32
*/
public function deleteMinorLanguages(){
$languageModel = new MinorLanguages();
return $languageModel->edit(['is_delete'=>1],['id'=>$this->param['id']]);
}
/**
* @remark :创建初始数据
* @name :createProjectData
* @author :lyh
* @method :post
* @time :2023/8/30 14:30
*/
public function createProjectData($param){
//查看当前项目状态是否为初始项目
$info = $this->model->read(['id'=>$param['id']]);
//项目为初始项目时,只能选择建站中
if(($info['type'] == Project::TYPE_ZERO) && ($info['type'] != Project::TYPE_FIVE)){
$param['type'] = Project::TYPE_ONE;
}
//创建默认数据库
if($param['type'] == Project::TYPE_ONE){
//改为异步
NoticeLog::createLog(NoticeLog::TYPE_INIT_PROJECT, ['project_id' => $param['id']]);
}
return $this->success();
}
/**
* 保存询盘过滤配置
* @param $config
* @return array
* @author zbj
* @date 2024/1/19
*/
public function saveInquiryFilterConfig($config){
$config['filter_countries'] = !empty($config['filter_countries']) ? Arr::lineToArray($config['filter_countries']) : json_encode([]);
$config['filter_contents'] = !empty($config['filter_contents']) ? Arr::lineToArray($config['filter_contents']) : json_encode([]);
$config['filter_referers'] = !empty($config['filter_referers']) ? Arr::lineToArray($config['filter_referers']) : json_encode([]);
$config['filter_emails'] = !empty($config['filter_emails']) ? Arr::lineToArray($config['filter_emails']) : json_encode([]);
$config['filter_mobiles'] = !empty($config['filter_mobiles']) ? Arr::lineToArray($config['filter_mobiles']) : json_encode([]);
$config['filter_names'] = !empty($config['filter_names']) ? Arr::lineToArray($config['filter_names']) : json_encode([]);
$config['black_ips'] = !empty($config['black_ips']) ? Arr::lineToArray($config['black_ips']) : json_encode([]);
$InquiryFilterConfigModel = new InquiryFilterConfig();
$info = $InquiryFilterConfigModel->read(['project_id'=>$config['project_id']]);
if($info === false){
$InquiryFilterConfigModel->add($config);
}else{
$InquiryFilterConfigModel->edit($config,['project_id'=>$config['project_id']]);
}
Cache::forget(InquiryFilterConfig::cacheKey($config['project_id']));
return $this->success();
}
/**
* @remark :根据类型状态设置
* @name :setTypeStatusEdit
* @author :lyh
* @method :post
* @time :2023/9/12 11:20
*/
public function setTypeSevenEdit($param){
$info = $this->model->read(['id'=>$param['id']]);
if($info['delete_status'] == 0){
//删除原始项目
$this->edit(['delete_status' => 1,'type'=>$param['type']], ['id' => $param['id']]);
//添加到续费单
$data = [
'title' => '【续费单】' . $param['title'],
'company' => $param['company'],
'lead_name' => $param['lead_name'],
'mobile' => $param['mobile'],
'qq' => $param['qq'] ?? '',
'channel' => json_encode($param['channel']),
'requirement' => $param['requirement'],
'cooperate_date' => $param['cooperate_date'],
'service_duration' => $param['deploy_build']['service_duration'],
'plan' => $param['deploy_build']['plan'],
'amount' => $param['payment']['amount'],
'contract' => json_encode($param['payment']['contract'] ?? []),
'bill' => json_encode($param['payment']['bill'] ?? []),
];
$renewModel = new ProjectRenew();
$renewModel->add($data);
}
return $this->success();
}
/**
* @remark :初始化数据库
* @name :initializationMysql
* @author :lyh
* @method :post
* @time :2023/8/4 15:08
*/
public function initializationMysql($project_id){
//切换数据库配置
$project = ProjectServer::useProject($project_id);
//创建数据库
ProjectServer::createDatabase($project);
//创建表
ProjectServer::initTable();
//初始数据
ProjectServer::saveInitParam($project_id);
return $this->success();
}
/**
* @remark :创建用户
* @name :createUser
* @author :lyh
* @method :post
* @time :2023/8/28 18:03
*/
public function createUser($mobile,$project_id,$lead_name){
$userModel = new UserModel();
//查看当前项目是否存在超级管理员
$info = $userModel->read(['role_id'=>0,'project_id'=>$project_id]);
if($info === false){
$data = [
'mobile'=>$mobile,
'password'=>base64_encode(md5('123456')),
'project_id'=>$project_id,
'name'=>$lead_name,
'type'=>UserModel::TYPE_ONE,
'operator_id'=>$this->manager['id'] ?? 0,
'create_id'=>$this->manager['id'] ?? 0,
];
$userModel->add($data);
}else{
$userModel->edit(['mobile'=>$mobile,'name'=>$lead_name],['id'=>$info['id']]);
}
return $this->success();
}
/**
* @remark :创建角色
* @name :createdRole
* @author :lyh
* @method :post
* @time :2023/9/6 11:16
*/
public function createdRole($project_id){
$roleModel = new ProjectRole();
//查看当前用户是否存在
$info = $roleModel->read(['project_id'=>$project_id]);
if($info === false){
$menuModel = new ProjectMenu();
$ids = $menuModel->where(['status'=>0])->pluck('id')->toArray();
$data = [
'name'=>'管理员',
'role_menu'=>implode(',',$ids),
'project_id'=>$project_id,
'type'=>1,
'operator_id'=>0,
'create_id'=>0,
];
$roleModel->add($data);
}
return $this->success();
}
public function clearCache($id)
{
parent::clearCache($id);
parent::setWith(['payment', 'deploy_build', 'deploy_optimize', 'online_check']);
parent::clearCache($id);
}
/**
* 保存询盘通知设置
* @author zbj
* @date 2023/5/17
*/
public function saveInquirySet($param)
{
$project = $this->getCacheInfo($param['project_id']);
//同步到接口
$domain = parse_url((!empty($project['deploy_optimize']['domain']) ? ((new DomainInfo())->getDomain($project['deploy_optimize']['domain'])) : ''))['host'];
$emails = Arr::arrToSet($param['emails']??'', 'trim');
$phones = Arr::arrToSet($param['phones']??'', 'trim');
$form_global_api = new FormGlobalsoApi();
$res = $form_global_api->setInquiry($domain, $emails, $phones);
if (!$res) {
$this->fail('保存失败');
}
if ($res['status'] != 200) {
$this->fail($res['message'] ?? '保存失败');
}
//保存
$set = InquirySet::where('project_id', $param['project_id'])->first();
if (!$set) {
$set = new InquirySet();
}
$set->project_id = $param['project_id'];
$set->emails = $emails;
$set->phones = $phones;
$set->save();
return $this->success();
}
public function dataSource(){
$data = [];
$data['level'] = $this->model::levelMap();
$data['type'] = $this->model::typeMap();
$data['special'] = $this->model::specialMap();
$data['search'] = $this->model::searchParam();
$data['plan'] = $this->model::planMap();
return $this->success($data);
}
public function channelSource($param){
switch ($param['type']){
case Project::TYPE_ONE:
$data = [0=>'所有'];
$list = (new Zone())->list([],'id',['id','title'],'asc');
foreach ($list as $v){
$data[$v['id']] = $v['title'];
}
return $data;
case Project::TYPE_TWO:
if(isset($param['alias'])){
return Channel::where('alias', 'like' ,'%'.$param['alias'].'%')->pluck('alias', 'id')->toArray();
}
$map = [];
if($param['zone_id'] != 0){
$map['zone_id'] = $param['zone_id'];
}
return Channel::where($map)->pluck('alias', 'id')->toArray();
case Project::TYPE_THREE:
return User::where('channel_id', $param['channel_id']??0)->pluck('name', 'id')->toArray();
}
return $this->success();
}
/**
* @remark :修改域名时,同时更改其状态
* @name :domainStatus
* @author :lyh
* @method :post
* @time :2023/9/4 14:29
*/
public function editDomainStatus($domain,$project_id){
$projectOptimize = new DeployOptimize();
$optimizeInfo = $projectOptimize->read(['project_id'=>$project_id],['domain']);
if($optimizeInfo['domain'] == $domain){
return $this->success();
}
$domainModel = new DomainInfo();
//查看当前域名是否已使用
$domainInfo = $domainModel->read(['id'=>$domain,'project_id'=>['!=',0]]);
if($domainInfo !== false){
$this->fail('当前域名已被其他服务器使用');
}
//先清空上一次所绑定的域名
$info = $domainModel->read(['project_id'=>$project_id]);
if($info !== false){
$domainModel->edit(['project_id'=>0,'status'=>DomainInfo::STATUS_ZERO],['id'=>$info['id']]);
}
//重新设置域名
$domainModel->edit(['status'=>DomainInfo::STATUS_ONE,'project_id'=>$project_id],['id'=>$domain]);
return $this->success();
}
/**
* @remark :删除
* @name :projectDel
* @author :lyh
* @method :post
* @time :2023/9/8 15:23
*/
public function projectDel(){
$rs = $this->edit(['delete_status'=>1],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
//更新当前项目所有账号状态
$userModel = new UserModel();
$userModel->edit(['status'=>1],['project_id'=>$this->param['id']]);
return $this->success();
}
/**
* @remark :复制项目
* @name :copyProject
* @author :lyh
* @method :post
* @time :2023/11/8 14:23
*/
public function copyProject(){
//查看当前是否有执行任务
$noticeModel = new NoticeLog();
$info = $noticeModel->read(['type'=>NoticeLog::TYPE_COPY_PROJECT,'status'=>0,'data'=>['like','%"'.$this->param['project_id'].'"%']]);
if($info !== false){
return $this->success('当前项目已在复制中');
}
NoticeLog::createLog(NoticeLog::TYPE_COPY_PROJECT, ['project_id' => $this->param['project_id']]);
return $this->success('项目复制中,请稍后前往初始化项目查看;');
}
/**
* 对外接口token
* @param $data
* @return string
* @author zbj
* @date 2023/11/10
*/
public function getSiteToken($data){
$project = $this->getCacheInfo($data['project_id']);
if(empty($project['site_token']) || !empty($data['refresh'])){
$token = strtolower(base64_encode("6.0") . md5('project_' . $data['project_id'] . '_' . time()));
$project->site_token = $token;
$project->save();
}
return $project->site_token;
}
/**
* 保存其他配置
* AICC、hagro、token
* @return array
* @throws AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
*/
public function saveOtherProject(){
//获取当前数据详情
$projectInfo = $this->getProjectInfo($this->param['id']);
if(($projectInfo['created_at'] >= '2014-12-01 00:00:00')){//12月1号过后默认不开启
$this->param['aicc'] = Project::TYPE_ZERO;
}
if($this->param['aicc'] == Project::TYPE_ONE && !empty($this->param['exclusive_aicc_day'])){
$data = [
'company_name'=>$projectInfo['company'],
'principal_mobile'=>$projectInfo['mobile'],
'remark'=>'',
'exclusive_aicc_day'=>$this->param['exclusive_aicc_day'] ?: 1,
'from_order_id'=>$projectInfo['from_order_id'],
'nickname' => $projectInfo['lead_name'] ?? $projectInfo['mobile'],
];
$this->toAicc($data);
}
//黑格 从关闭到开启状态才同步, 改成只要是开启状态就同步, 需要修改有效时间
if($this->param['hagro'] == Project::TYPE_ONE && !empty($this->param['exclusive_hagro_day'])){
$data = [
'company_name'=>$projectInfo['company'],
'principal_mobile'=>$projectInfo['mobile'],
'exclusive_hagro_day'=>$this->param['exclusive_hagro_day'] ?: 1,
'from_order_id'=>$projectInfo['from_order_id'],
'company_id'=>$projectInfo['channel']['channel_id'],
'nickname' => $projectInfo['lead_name'] ?? $projectInfo['mobile'],
];
$this->toHagro($data);
}
if(empty($this->param['exclusive_aicc_day'])){
unset($this->param['exclusive_aicc_day']);
}
if(empty($this->param['exclusive_hagro_day'])){
unset($this->param['exclusive_hagro_day']);
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('保存失败,请联系管理员');
}
return $this->success($this->param);
}
/**
* @remark :获取其他配置
* @name :getOtherProject
* @author :lyh
* @method :post
* @time :2023/11/21 15:45
*/
public function getOtherProject(){
$info = $this->model->read(['id'=>$this->param['id']],['aicc','hagro','exclusive_aicc_day','exclusive_hagro_day']);
return $this->success($info);
}
/**
* 同步到AICC
* @param $data
* @return bool
*/
protected function toAicc($data){
$url = 'https://biz.ai.cc/api/sync_company_for_order';
$param = [
'company_name' => $data['company_name'],
'company_address' => '',
'company_tel' => $data['principal_mobile'],
'company_email' => '',
'remark' => $data['remark'],
'level_id' => 6,
'level_day' => $data['exclusive_aicc_day'] ?: 1,
'from_order_id' => $data['from_order_id'],
'nickname' => $data['nickname'],
];
//sign
ksort($param);
$tem = [];
foreach ($param as $key => $val) {
$tem[] = $key . '=' . urlencode($val);
}
$string = implode('&', $tem);
$key = md5('quanqiusou.com');
$param['sign'] = md5($string . $key);
$res = Http::withoutVerifying()->post($url, $param)->json();
if(empty($res['status']) || $res['status'] != 200){
LogUtils::error('ProjectToAicc error', $res);
}
return true;
}
/**
* 同步到Hagro
* @param $data
* @return bool
* @throws AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
*/
protected function toHagro($data){
$url = 'https://admin.hagro.cn/globalso/create_project';
$param = [
'company' => $data['company_name'],
'phone' => $data['principal_mobile'],
'planday' => $data['exclusive_hagro_day'] ?: 1,
'from_order_id' => $data['from_order_id'],
'agent_phone' => Channel::where('id', $data['company_id'])->value('contact_mobile') ?: '',
'nickname' => $data['nickname'],
];
$common = new Common();
$token = $common->encrypt($param);
$res = Http::withoutVerifying()->get($url, ['token' => $token])->json();
if(empty($res['code']) || $res['code'] != 200){
$this->fail($res['msg']);
}
return true;
}
/**
* 保存引流配置
* @param $config
* @return array
* @author zbj
* @date 2024/3/29
*/
public function saveWebTrafficConfig($config){
$config['main_countries'] = textareaToArr($config['main_countries']);
$config['filter_countries'] = textareaToArr($config['filter_countries']);
$ip_area = InquiryIP::getIpAreas();
foreach ($config['main_countries'] as $v) {
if (!in_array($v, $ip_area)) {
throw new AsideGlobalException(Code::SYSTEM_ERROR, '[' . $v . ']不存在,请检查后再次提交');
}
}
foreach ($config['filter_countries'] as $v) {
if (!in_array($v, $ip_area)) {
throw new AsideGlobalException(Code::SYSTEM_ERROR, '[' . $v . ']不存在,请检查后再次提交');
}
}
$config['main_countries'] = json_encode($config['main_countries']);
$config['filter_countries'] = json_encode($config['filter_countries']);
$model = WebTrafficConfig::where('project_id', $config['project_id'])->first();
if (!$model) {
$model = new WebTrafficConfig();
$model->add($config);
} else {
$model->edit($config, ['project_id' => $config['project_id']]);
}
Cache::forget(WebTrafficConfig::cacheKey($config['project_id']));
return $this->success();
}
/**
* @remark :根据管理员的人事角色获取对应更新字段
* @name :getManagerFiled
* @author :lyh
* @method :post
* @time :2024/4/7 11:12
*/
public function getManagerFiled($entry_position,$old_id,$new_id,$project_id = []){
if(!empty($project_id)){
$param['project_id'] = ['in',$project_id];
}
switch ($entry_position){
//技术经理
case 41:
$param['leader_mid'] = $old_id;
$deployBuildModel = new DeployBuild();
$deployBuildModel->edit(['leader_mid'=>$new_id],$param);
break;
//项目经理
case 39:
$param['manager_mid'] = $old_id;
$deployBuildModel = new DeployBuild();
$deployBuildModel->edit(['manager_mid'=>$new_id],$param);
break;
//设计师
case 38:
$param['designer_mid'] = $old_id;
$deployBuildModel = new DeployBuild();
$deployBuildModel->edit(['designer_mid'=>$new_id],$param);
break;
//技术助理
case 40:
$param['tech_mid'] = $old_id;
$deployBuildModel = new DeployBuild();
$deployBuildModel->edit(['tech_mid'=>$new_id],$param);
break;
//优化主管+优化经理
case 51:
case 48:
$param['manager_mid'] = $old_id;
$deployOptimizeModel = new DeployOptimize();
$deployOptimizeModel->edit(['manager_mid'=>$new_id],$param);
$param['tech_leader'] = $old_id;
unset($param['manager_mid']);
$deployOptimizeModel->edit(['tech_leader'=>$new_id],$param);
break;
//优化师
case 46:
$param['optimist_mid'] = $old_id;
$deployOptimizeModel = new DeployOptimize();
$deployOptimizeModel->edit(['optimist_mid'=>$new_id],$param);
$param['assist_mid'] = $old_id;
unset($param['optimist_mid']);
$deployOptimizeModel->edit(['assist_mid'=>$new_id],$param);
break;
case 49:
//优化师助理
$param['assist_mid'] = $old_id;
$deployOptimizeModel = new DeployOptimize();
$deployOptimizeModel->edit(['assist_mid'=>$new_id],$param);
break;
case 45:
//售后技术
$param['tech_mid'] = $old_id;
$deployOptimizeModel = new DeployOptimize();
$deployOptimizeModel->edit(['tech_mid'=>$new_id],$param);
break;
case 38:
//品控
$param['design_mid'] = $old_id;
$deployOptimizeModel = new DeployOptimize();
$deployOptimizeModel->edit(['design_mid'=>$new_id],$param);
break;
default:
break;
}
return true;
}
}