ProjectController.php 49.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 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 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
<?php

namespace App\Http\Controllers\Aside\Project;

use App\Enums\Common\Code;
use App\Helper\Arr;
use App\Helper\Country;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Project\OnlineCheckLogic;
use App\Http\Logic\Aside\Project\ProcessRecordsLogic;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Requests\Aside\Project\ProcessRecordsRequest;
use App\Models\ASide\APublicModel;
use App\Models\Channel\Channel;
use App\Models\Channel\User;
use App\Models\Channel\Zone;
use App\Models\Com\City;
use App\Models\Com\NoticeLog;
use App\Models\Com\UpdateLog;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Domain\DomainCreateTask;
use App\Models\Domain\DomainInfo;
use App\Models\Domain\DomainInfo as DomainInfoModel;
use App\Models\HomeCount\Count;
use App\Models\Industry\ProjectIndustry;
use App\Models\Inquiry\InquirySet;
use App\Models\Manage\BelongingGroup;
use App\Models\Manage\ManageHr;
use App\Models\Project\DeployBuild;
use App\Models\Project\Payment;
use App\Models\Project\ProcessRecords;
use App\Models\Project\Project;
use App\Models\Project\ProjectUpdateTdk;
use App\Models\Project\RenewLog;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\RankData\RankData;
use App\Models\Task\Task;
use App\Models\WebSetting\WebLanguage;
use App\Models\WorkOrder\TicketProject;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

/**
 * 项目管理
 * Class ProjectController
 * @package App\Http\Controllers\Aside\Project
 * @author zbj
 * @date 2023/4/25
 */
class ProjectController extends BaseController
{

    /**
     * @remark :项目列表
     * @name   :lists
     * @author :lyh
     * @method :post
     * @time   :2023/8/30 10:11
     */
    public function lists(Project $project){
        $query = $project->leftJoin('gl_project_payment', 'gl_project.id', '=', 'gl_project_payment.project_id')
            ->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id')
            ->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id')
            ->leftJoin('gl_project_online_check', 'gl_project.id', '=', 'gl_project_online_check.project_id')
            ->leftJoin('gl_web_setting_template', 'gl_project.id', '=', 'gl_web_setting_template.project_id')
            ->leftJoin('gl_project_association', 'gl_project.id', '=', 'gl_project_association.project_id')
            ->where('gl_project.delete_status',Project::TYPE_ZERO);
        $query = $this->searchParam($query);
        $query = $this->orderByList($query);
        $lists = $query->paginate($this->row, $this->selectParam(), 'page', $this->page)->toArray();
        if(!empty($lists) && !empty($lists['list'])){
            foreach ($lists['list'] as $k => $v){
                $v = $this->handleParam($v);
                // 组装 工单UUID END
                $lists['list'][$k] = $v;
            }
        }
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * 需要查询的字段
     * @return array
     */
    public function selectParam(){
        $select = [
            'gl_project.id AS id',
            'gl_project.title AS title',
            'gl_project.channel AS channel',
            'gl_project.company AS company',
            'gl_project.type AS type',
            'gl_project.project_type AS project_type',
            'gl_project.extend_type AS extend_type',
            'gl_project.uptime AS uptime',
            'gl_project.is_upgrade AS is_upgrade',
            'gl_project.created_at AS created_at',
            'gl_project.cooperate_date AS cooperate_date',
            'gl_project.site_status AS site_status',
            'gl_project_online_check.id AS online_check_id',
            'gl_project_online_check.question AS question',
            'gl_project_online_check.optimist_status AS optimist_status',
            'gl_project_online_check.qa_status AS qa_status',
            'gl_project_payment.amount AS amount',
            'gl_project_deploy_build.dept_id AS dept_id',
            'gl_project_deploy_build.keyword_num AS key',
            'gl_project_deploy_build.service_duration AS day',
            'gl_project_deploy_build.is_comment AS is_comment',
            'gl_project_deploy_build.leader_mid AS leader_mid',
            'gl_project_deploy_build.manager_mid AS manager_mid',
            'gl_project_deploy_build.designer_mid AS designer_mid',
            'gl_project_deploy_build.tech_mid AS tech_mid',
            'gl_project_deploy_build.test_domain AS test_domain',
            'gl_project_deploy_build.plan AS plan',
            'gl_project_deploy_build.seo_plan AS seo_plan',
            'gl_project_deploy_build.is_participle AS is_participle',
            'gl_project_deploy_optimize.dept_id AS optimize_dept_id',
            'gl_project_deploy_optimize.manager_mid AS optimize_manager_mid',
            'gl_project_deploy_optimize.optimist_mid AS optimize_optimist_mid',
            'gl_project_deploy_optimize.assist_mid AS optimize_assist_mid',
            'gl_project_deploy_optimize.tech_mid AS optimize_tech_mid',
            'gl_project_deploy_optimize.design_mid AS design_mid',
            'gl_project_deploy_optimize.tech_leader AS tech_leader',
            'gl_project_deploy_optimize.domain AS domain',
            'gl_project_deploy_optimize.quality_mid AS quality_mid',
            'gl_project_deploy_optimize.design_mid AS design_mid',
            'gl_project_deploy_optimize.api_no AS api_no',
            'gl_web_setting_template.template_id AS template_id',
            'gl_project_association.friend_id as friend_id',
        ];
        return $select;
    }

    /**
     * @remark :排序
     * @name   :orderByList
     * @author :lyh
     * @method :post
     * @time   :2023/12/29 17:14
     */
    public function orderByList($query){
        $query = $query->orderBy('gl_project.uptime', 'desc')->orderBy('gl_project.id', 'desc');
        return $query;
    }

    /**
     * @remark :搜索参数处理
     * @name   :searchParam
     * @author :lyh
     * @method :post
     * @time   :2023/8/18 10:58
     */
    public function searchParam(&$query){
        //参数type
        $query = $this->searchType($query);
        //根据查看权限获取项目搜索条件(必带)
        $query = $this->getManagerRole($query);
        //搜索技术组
        $query = $this->searchDept($query);
        //搜索技术人员
        $query = $this->searchManager($query);
        //按类型搜索
        $query = $this->searchContent($query);
        //搜索升级项目
        $query = $this->searchUpgrade($query);
        //搜索战队
        $query = $this->searchChannel($query);
        //其他搜索
        $query = $this->searchTechMid($query);
        return $query;
    }

    /**
     * 搜索项目状态
     * @param $query
     * @return mixed
     */
    public function searchType(&$query){
        if(isset($this->map['type'])){
            $query->where('gl_project.extend_type', '!=' ,5)->where('gl_project.extend_type', '!=' ,8);
            if (in_array($this->map['type'], [Project::TYPE_ZERO, Project::TYPE_ONE, Project::TYPE_TWO, Project::TYPE_THREE])){
                $query->where('gl_project.type', $this->map['type']);
            } elseif ($this->map['type'] == 8){
                $query->where('gl_project_online_check.id', null)->where('gl_project.type',Project::TYPE_TWO);
            }else{
                $query->whereIn('gl_project.type', [Project::TYPE_FOUR,Project::TYPE_SIX]);
            }
        }
        if(isset($this->map['uptime']) && is_array($this->map['uptime'])){
            $query->whereBetween('gl_project.uptime', $this->map['uptime']);
        }
        return $query;
    }

    /**
     * @remark :搜索升级项目
     * @name   :searchUpgrade
     * @author :lyh
     * @method :post
     * @time   :2023/11/6 16:27
     */
    public function searchUpgrade(&$query){
        if(isset($this->map['is_upgrade'])){
            $query->where('gl_project.is_upgrade', $this->map['is_upgrade']);
        }
        return $query;
    }

    /**
     * 搜索框
     * @param $query
     * @return mixed
     */
    public function searchContent(&$query){
        if(!empty($this->map['domain_type']) && !empty($this->map['domain_search'])){
            if($this->map['domain_type'] == 'domain'){
                $parsedUrl = parse_url($this->map['domain_search']);
                $this->map['domain_search'] = $parsedUrl['host'] ?? $this->map['domain_search'];
                $ids = DomainInfo::where('domain', 'like', '%'.$this->map['domain_search'].'%')->pluck('id')->toArray();
                $query->whereIn('gl_project_deploy_optimize.domain', $ids);
            }else{
                $query->where('gl_project_deploy_build.test_domain','like','%'.$this->map['domain_search'].'%');
            }
        }
        if(!empty($this->map['search']) && !empty($this->map['search_type'])){
            $query->where(function ($subQuery) {
                // 搜索域名
                if ($this->map['search_type'] == 'domain') {
                    $parsedUrl = parse_url($this->map['search']);
                    $this->map['search'] = $parsedUrl['host'] ?? $this->map['search'];
                    $ids = DomainInfo::where('domain', 'like', '%'.$this->map['search'].'%')->pluck('id')->toArray();
                    $subQuery->whereIn('gl_project_deploy_optimize.domain', $ids);
                } else if($this->map['search_type'] == 'test_domain'){
                    $subQuery->where('gl_project_deploy_build.test_domain','like','%'.$this->map['search'].'%');
                } else {
                    // 搜索名称
                    $subQuery->orwhere('gl_project.company','like','%'.$this->map['search'].'%')
                        ->orwhere('gl_project.title','like','%'.$this->map['search'].'%');
                }
            });
        }
        return $query;
    }

    /**
     * @remark :搜索战队
     * @name   :searchChannel
     * @author :lyh
     * @method :post
     * @time   :2023/11/9 10:16
     */
    public function searchChannel(&$query){
        if(isset($this->map['zone_id']) && !empty($this->map['zone_id'])){
            $query->where('gl_project.channel','like','%"zone_id": "'.$this->map['zone_id'].'"%');
        }
        if(isset($this->map['channel_id']) && !empty($this->map['channel_id'])){
            $query->where('gl_project.channel','like','%"channel_id": "'.$this->map['channel_id'].'"%');
        }
        if(isset($this->map['user_id']) && !empty($this->map['user_id'])){
            $query->where('gl_project.channel','like','%"user_id": "'.$this->map['user_id'].'"%');
        }
        return $query;
    }

    /**
     * @remark :搜索技术组
     * @name   :searchDept
     * @author :lyh
     * @method :post
     * @time   :2023/9/7 18:40
     */
    public function searchDept(&$query){
        if(!empty($this->map['dept_id'])){
            if($this->map['dept_id'] == 7 || $this->map['dept_id'] == 9){//7,9代表合并组H+F组
                $query->whereIn('gl_project_deploy_build.dept_id', [7,9]);
            }else{
                $query->where(function ($subQuery) {
                    $subQuery->orwhere('gl_project_deploy_build.dept_id',$this->map['dept_id'])
                        ->orwhere('gl_project_deploy_optimize.dept_id',$this->map['dept_id']);
                });
            }
        }
        return $query;
    }

    /**
     * @remark :搜索售后技术
     * @name   :searchTechMid
     * @author :lyh
     * @method :post
     * @time   :2024/3/4 14:58
     */
    public function searchTechMid(&$query){
        if(isset($this->map['tech_mid'])){
            $query = $query->where('gl_project_deploy_optimize.tech_mid',$this->map['tech_mid']);
        }
        if(isset($this->map['optimize_optimist_mid'])){
            $query = $query->where('gl_project_deploy_optimize.optimist_mid',$this->map['optimize_optimist_mid']);
        }
        if(isset($this->map['plan'])){
            $query = $query->where('gl_project_deploy_build.plan',$this->map['plan']);
        }
        if(isset($this->map['friend_id'])){
            if($this->map['friend_id'] == 1){
                $query = $query->where('gl_project_association.friend_id', '!=', 0);
            }else{
                $query = $query->where(function ($subQuery) {
                    $subQuery->where('gl_project_association.friend_id', 0)
                        ->orWhereNull('gl_project_association.friend_id');
                });
            }
        }
        if(isset($this->map['seo_plan'])){
            $query = $query->where('gl_project_deploy_build.seo_plan',$this->map['seo_plan']);
        }
        if(isset($this->map['site_status'])){
            $query = $query->where('gl_project.site_status',$this->map['site_status']);
        }
        if(isset($this->map['domain'])){
            if($this->map['domain'] == 0){
                $query = $query->where('gl_project_deploy_optimize.domain',null);
            }else{
                $query = $query->where('gl_project_deploy_optimize.domain','!=',null);
            }
        }
        if(isset($this->map['project_type'])){
            $query = $query->where('gl_project.project_type',$this->map['project_type']);
        }
        return $query;
    }

    /**
     * @remark :访问权限
     * @name   :getManagerRole
     * @author :lyh
     * @method :post
     * @time   :2023/9/7 17:28
     */
    public function getManagerRole(&$query){
        if(($this->manage['role'] != 1)){//1代表查看所有
            //获取用户所在组
            $managerHr = new ManageHr();
            $info = $managerHr->read(['manage_id'=>$this->manage['id']]);
            //获取当前用户自己的项目
            $query->where(function ($subQuery) use ($info) {
                $subQuery->whereIn('gl_project.id', [1]) // 项目1 + 项目3默认显示
                ->orWhere('gl_project_deploy_build.leader_mid', $info['id'])
                    ->orWhere('gl_project_deploy_build.manager_mid', $info['id'])
                    ->orWhere('gl_project_deploy_build.designer_mid', $info['id'])
                    ->orWhere('gl_project_deploy_build.tech_mid', $info['id'])
                    ->orWhere('gl_project_deploy_optimize.manager_mid', $info['id'])
                    ->orWhere('gl_project_deploy_optimize.optimist_mid', $info['id'])
                    ->orWhere('gl_project_deploy_optimize.assist_mid', $info['id'])
                    ->orWhere('gl_project_deploy_optimize.tech_mid', $info['id'])
                    ->orWhere('gl_project_deploy_optimize.tech_leader', $info['id'])
                    ->orWhere('gl_project_deploy_optimize.quality_mid', $info['id'])
                    ->orWhere('gl_project_deploy_optimize.design_mid', $info['id']);
                // 处理 dept_id 条件
                if (in_array($info['belong_group'], [7, 9])) {
                    // 7, 9 代表合并组 H + F 组
                    $subQuery->orWhere(function ($innerQuery) {
                        $innerQuery->where('gl_project_deploy_build.dept_id', 7)
                            ->orWhere('gl_project_deploy_build.dept_id', 9);
                    });
                } else {
                    $subQuery->orWhere('gl_project_deploy_build.dept_id', $info['belong_group'])
                        ->orWhere('gl_project_deploy_optimize.dept_id', $info['belong_group']);
                }
            });
        }
        return $query;
    }

    /**
     * @remark :搜索技术人员
     * @name   :searchManager
     * @author :lyh
     * @method :post
     * @time   :2023/9/7 17:16
     */
    public function searchManager(&$query)
    {
        if (!empty($this->map['manage_id'])) {
            $query->where(function ($subQuery) {
                $subQuery->orWhere('gl_project_deploy_build.leader_mid', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_build.manager_mid', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_build.designer_mid', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_build.tech_mid', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_optimize.manager_mid', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_optimize.optimist_mid', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_optimize.assist_mid', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_optimize.tech_mid', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_optimize.tech_leader', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_optimize.quality_mid', $this->map['manage_id'])
                    ->orWhere('gl_project_deploy_optimize.design_mid', $this->map['manage_id']);
            });
        }
        return $query;
    }

    /**
     * @remark :参数处理
     * @name   :handleParam
     * @author :lyh
     * @method :post
     * @time   :2023/8/18 14:44
     */
    public function handleParam(&$item){
        if(($item['type'] != Project::TYPE_ZERO)){
            $data = APublicModel::getNumByProjectId($item['id']);
        }
        if($item['type'] == Project::TYPE_ONE){//建站中
            $processModel = new ProcessRecords();
            $item['sign_project'] = 1;
            $count = $processModel->counts(['project_id'=>$item['id']]);
            if($count < 1){
                $item['sign_project'] = 0;
            }else{
                $proInfo = $processModel->read(['project_id'=>$item['id'],'date'=>['>=',date('Y-m-d', strtotime('-3 days'))]],['id']);
                if($proInfo !== false){
                    $item['sign_project'] = 0;
                }
            }
        }
        if(!empty($item['extend_type'])){
            $item['type'] = $item['extend_type'];
        }
        $manageModel = new ManageHr();
        $item['channel'] = Channel::getChannelText($item['channel']['user_id'] ?? 0);
        $item['build_leader'] = $manageModel->getName($item['leader_mid']);
        $item['build_manager'] = $manageModel->getName($item['manager_mid']);
        $item['build_designer'] = $manageModel->getName($item['designer_mid']);
        $item['build_tech'] = $manageModel->getName($item['tech_mid']);
        $item['optimize_manager'] = $manageModel->getName($item['optimize_manager_mid']);
        $item['optimize_optimist'] = $manageModel->getName($item['optimize_optimist_mid']);
        $item['optimize_assist'] = $manageModel->getName($item['optimize_assist_mid']);
        $item['optimize_tech'] = $manageModel->getName($item['optimize_tech_mid']);
        $item['quality_mid_name'] = $manageModel->getName($item['quality_mid']);
        $planMap = Project::planMap();
        $seoPlanMap = Project::seoMap();
        $item['plan'] = $planMap[$item['plan']] ?? '';
        $item['seo_plan'] = $seoPlanMap[$item['seo_plan']] ?? '';
        $item['created_at'] = date('Y年m月d日', strtotime($item['cooperate_date']));
        $item['autologin_code'] = getAutoLoginCode($item['id']);
        $domainModel = new DomainInfo();
        $item['domain'] = !empty($item['domain']) ?  $domainModel->getDomain($item['domain']) : '';
        $item['product_num'] = $data['product'] ?? 0;
        $item['keyword_num'] = $data['key'] ?? 0;
        $item['article_num'] = ($data['blog'] ?? 0) + ($data['news'] ?? 0);
        $item['task_finish_num'] = Task::getNumByProjectId($item['id'], Task::STATUS_DOWN);
        $item['task_pending_num'] = Task::getNumByProjectId($item['id'], [Task::STATUS_DONGING, Task::STATUS_WAIT]);
        $item['collect_time'] = $item['is_upgrade'] ? UpdateLog::getProjectUpdate($item['id']) : '';
        $item['uuid'] = TicketProject::where('table_id', $item['id'])->where('project_cate', 2)->value('uuid') ?? null;
        $item['friend_id'] = ProjectAssociation::where('project_id', $item['id'])->where('status', ProjectAssociation::STATUS_NORMAL)->where('binding_app', ProjectAssociation::ENTERPRISE_WECHAT)->value('friend_id') ?? null;
        return $item;
    }

    /**
     * @remark :获取数据详情
     * @name   :info
     * @author :lyh
     * @method :post
     * @time   :2023/8/17 16:42
     */
    public function info(ProjectLogic $logic){
        $this->request->validate([
            'id'=>'required'
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $data = $logic->getProjectInfo($this->param['id']);
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :逻辑删除
     * @name   :deleteMinorLanguages
     * @author :lyh
     * @method :post
     * @time   :2024/6/18 11:53
     */
    public function deleteMinorLanguages(ProjectLogic $logic){
        $this->request->validate([
            'id'=>'required'
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $data = $logic->deleteMinorLanguages();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * @remark :保存数据
     * @name   :save
     * @author :lyh
     * @method :post
     * @time   :2023/8/17 16:42
     */
    public function save(ProjectLogic $logic)
    {
        $this->request->validate([
            'type'=>'required',
            'serve_id'=>'required',
        ],[
            'type.required' => '类型不能为空',
            'serve_id.required' => '请选择服务器'
        ]);
        $logic->projectSave();
        $this->response('success');
    }

    /**
     * 询盘通知设置
     * @author zbj
     * @date 2023/5/17
     */
    public function inquiry_set(Request $request, ProjectLogic $logic){
        $request->validate([
            'project_id'=>'required'
        ],[
            'project_id.required' => '项目ID不能为空'
        ]);
        if($request->isMethod('get')){
            $data = InquirySet::where('project_id', $request->project_id)->first();
            if(!$data){
                $data = ['emails' => '', 'phones' => ''];
            }else{
                $data = $data->toArray();
            }
            $this->response('success',Code::SUCCESS,$data);
        }
        $data = $logic->saveInquirySet($this->param);
        $this->response('success',Code::SUCCESS,$data);
    }


    /**
     * @remark :项目相关数据
     * @name   :data_source
     * @author :lyh
     * @method :post
     * @time   :2023/12/7 10:41
     */
    public function data_source(ProjectLogic $logic){
        $data = $logic->dataSource();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * 省市数据源
     * @author zbj
     * @date 2023/6/27
     */
    public function city_source(){
        $data = City::source($this->param['id'] ?? 0);
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * 渠道数据源
     * @author zbj
     * @date 2023/6/27
     */
    public function channel_source(ProjectLogic $logic){
        $data = $logic->channelSource($this->param);
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * 进程记录
     * @author zbj
     * @date 2023/6/25
     */
    public function get_process_records(Request $request, ProcessRecordsLogic $logic){
        $request->validate([
            'project_id'=>'required'
        ],[
            'project_id.required' => '项目ID不能为空'
        ]);
        $data = $logic->getInfo($this->param['project_id']);
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * 保存进程记录
     * @author zbj
     * @date 2023/6/25
     */
    public function save_process_records(ProcessRecordsRequest $request, ProcessRecordsLogic $logic){
        $request->validated();
        $logic->recordSave();
        $this->response('success');
    }

    /**
     * 获取合同票据
     * @author zbj
     * @date 2023/6/27
     */
    public function get_contract_bill(Request $request){
        $request->validate([
            'id'=>'required'
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $payment = Payment::where('project_id', $this->param['id'])->select(['contract', 'bill'])->first();
        $data = $payment->makeVisible(['contract', 'bill']);
        $this->response('success',Code::SUCCESS,$data ? $data->toArray() : []);
    }

    /**
     * @remark :提交审核
     * @name   :submit_check
     * @author :lyh
     * @method :post
     * @time   :2023/12/2 9:59
     */
    public function submit_check(OnlineCheckLogic $logic){
        $this->request->validate([
            'id'=>'required'
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $logic->saveOnlineCheck();
        $this->response('success');
    }

    /**
     * @remark :上线审核
     * @name   :online_check
     * @author :lyh
     * @method :post
     * @time   :2023/8/30 19:01
     */
    public function online_check(OnlineCheckLogic $logic){
        $this->request->validate([
            'id'=>'required',
            'type'=>'required|in:optimist,qa',
            'status'=>'required|in:0,1'
        ],[
            'id.required' => 'ID不能为空',
            'type.required' => '请选择审核类型',
            'type.in' => '审核类型值无效',
            'status.required' => '请选择审核状态',
            'status.in' => '审核状态值无效',
        ]);
        $logic->onlineCheck();
        $this->response('success');
    }

    /**
     * @remark :获取组
     * @name   :getBelongingGroup
     * @author :lyh
     * @method :post
     * @time   :2023/8/4 16:27
     */
    public function getBelongingGroup(){
        $this->request->validate([
            'type'=>'required',
        ],[
            'type.required' => '请选择审核类型'
        ]);
        $belongGroupModel = new BelongingGroup();
        $lists = $belongGroupModel->list($this->map,'name',['id','name','type'],'asc');
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :根据用户组获取成员
     * @name   :getManager
     * @author :lyh
     * @method :post
     * @time   :2023/8/8 10:29
     */
    public function getManagerList(){
        $hrManagerModel = new ManageHr();
        if(!isset($this->map['status'])){
            $this->map['status'] = $hrManagerModel::STATUS_ONE;
        }else{
            if(!is_array($this->map['status'])){
                $this->map['status'] = [$this->map['status']];
            }
            $this->map['status'] = ['in',$this->map['status']];
        }
        if(isset($this->map['entry_position']) && !empty($this->map['entry_position'])){
            $this->map['entry_position'] = ['in',$this->map['entry_position']];
        }
        $lists = $hrManagerModel->list($this->map,['sort','id'],['id','manage_id','name','entry_position','is_leader']);
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :获取项目服务器与数据库列表
     * @name   :getServiceConfig
     * @author :lyh
     * @method :post
     * @time   :2023/8/14 10:23 todo::后面删除
     */
    public function getServiceConfig(){
        $serviceConfigModel = new ServerConfig();
        $list = $serviceConfigModel->list($this->param,'id',['id','type','title','count','init_domain','service_type']);
        $this->response('success',Code::SUCCESS,$list);
    }

    /**
     * @remark :获取域名列表
     * @name   :getDomain
     * @author :lyh
     * @method :post
     * @time   :2023/8/14 10:29
     */
    public function getDomain(){
        $this->request->validate([
            'project_id'=>'required',
        ],[
            'project_id.required' => 'project_id不能为空',
        ]);
        $domainModel = new DomainInfo();
        $list = $domainModel->list(['status'=>0,'project_id'=>['or',$this->param['project_id']]]);
        $this->response('success',Code::SUCCESS,$list);
    }

    /**
     * 通过企业名称查询项目是否在服务中, 有项目并且在服务中的返回1, 其他的返回0
     * @author zbj
     * @date 2023/9/4
     */
    public function getProjectInService(){
        $company = $this->param['company'];
        if(!$company){
            $this->response('企业名称必传',Code::SYSTEM_ERROR);
        }
        $project = Project::where('company', $company)->first();
        if($project && ($project['remain_day'] > 0 || in_array($project['type'], [0, 1,6]))){
            $in_service = 1;
        }else{
            $in_service = 0;
        }
        $this->response('success',Code::SUCCESS, ['in_service' => $in_service]);
    }

    /**
     * @remark :逻辑删除项目
     * @name   :del
     * @author :lyh
     * @method :post
     * @time   :2023/9/8 15:21
     */
    public function del(ProjectLogic $logic){
        $this->request->validate([
            'id'=>'required',
        ],[
            'id.required' => 'id不能为空',
        ]);
        $logic->projectDel();
        $this->response('success');
    }

    /**
     * 根据渠道商查询项目
     * @author zbj
     * @date 2023/9/11
     */
    public function getProjectByChannel(){
        $id = $this->param['id'] ?? '';
        $notice_order_id = $this->param['notice_order_id'] ?? '';
        $source_id = $this->param['channel_id'] ?? 0; //原系统渠道id
        $size = $this->param['page_size'] ?? 20;
        $type = $this->param['type'] ?? '';
        $company = $this->param['company'] ?? '';

        if(!$source_id && !$id){
            $this->response('参数异常',Code::SYSTEM_ERROR);
        }
        $channel_id = 0;
        if($source_id){
            $channel = Channel::where('source_id', $source_id)->first();
            if(!$channel){
                $this->response('渠道不存在',Code::SYSTEM_ERROR);
            }
            $channel_id = $channel->id;
        }

        if ($id){
            if(!is_array($id)){
                $id = explode(',', $id);
            }
        }
        if ($notice_order_id){
            if(!is_array($notice_order_id)){
                $notice_order_id = explode(',', $notice_order_id);
            }
        }

        $data = Project::with(['deploy_build', 'deploy_optimize', 'online_check'])
            ->where('delete_status', 0)
            ->where(function ($query) use ($channel_id, $type, $company, $id, $notice_order_id){
            if ($channel_id) {
                $query->where('channel->channel_id', $channel_id);
            }
            if ($type) {
                $query->where('type', $type);
            }
            if ($company) {
                $query->where('company', 'like', '%' . $company . '%');
            }
            if ($id) {
                $query->whereIn('id', $id);
            }
            if ($notice_order_id) {
                $query->whereIn('notice_order_id', $notice_order_id);
            }
        })->orderBy('id', 'desc')->paginate($size)->toArray();
        $list = [];
        foreach ($data['list'] as $item){
            $domain = '';
            if ($item['deploy_optimize']['domain']) {
                $domain_pro = DomainInfo::where('id', $item['deploy_optimize']['domain'])->first();
                $domain_array = parse_url($domain_pro ? $domain_pro->domain : '');
                $domain = $domain_array['host'] ?? $domain_array['path'];
            }
            $manageHr = new ManageHr();
            $param = [
                  "id" => $item['id'],
                  "title" => $item['title'],
                  "company" => $item['company'],
                  "type" => $item['extend_type'] ?: $item['type'],
                  "type_text" => Project::typeMap()[$item['type']] ?? '',
                  "channel" => $item['channel'],
                  "created_at" => $item['created_at'],
                  "updated_at" => $item['updated_at'],
                  "post_id" => $item['post_id'],
                  "from_order_id" =>  $item['from_order_id'],
                  "remain_day" => $item['remain_day'],
                  "last_inquiry_time" => $item['last_inquiry_time'],
                  "plan" => $item['deploy_build']['plan'] ?: 0,
                  "plan_text" => Project::planMap()[$item['deploy_build']['plan']] ?? '',
                  "start_date" => $item['deploy_optimize']['start_date'] ?? '',
                  "domain" => $domain ? 'https://' . $domain : $domain,
                  "test_domain" => $item['deploy_build']['test_domain'] ?? '',
//                  "online_time" => $item['online_check']['qa_check_time'] ?? '',
                  "online_time" => $item['uptime'] ?? '',
                  "cooperate_date" => $item['cooperate_date'],
                  "project_manager_name" => $manageHr->getName($item['deploy_build']['manager_mid']), //项目经理
                  "after_sales_manager_name" => $manageHr->getName($item['deploy_optimize']['manager_mid']), //售后服务经理
                  "leader_name" => $manageHr->getName($item['deploy_build']['leader_mid']), //组长
            ];
            if ($item['type'] == Project::TYPE_TWO) {
                $param['is_compliance'] = RankData::where('project_id', $item['id'])->where('lang', '')->value('is_compliance') ?: 0;
            } else {
                $param['is_compliance'] = 1;
            }
            $yesterday_count = Count::where('project_id', $item['id'])->where('date', date('Y-m-d', strtotime('-1 day')))->first();
            $today_count = Count::where('project_id', $item['id'])->where('date', date('Y-m-d'))->first();
            $param['yesterday_ip_count'] = $yesterday_count['ip_num'] ?? 0;
            $param['today_ip_count'] = $today_count['ip_num'] ?? 0;
            $param['inquiry_num'] = $today_count['inquiry_num'] ?? 0;

            $list[] = $param;
        }
        $data['list'] = $list;
        $this->response('success',Code::SUCCESS, $data);
    }

    /**
     * @remark :获取已续费的续费单日志
     * @name   :getRenewLog
     * @author :lyh
     * @method :post
     * @time   :2023/9/28 9:09
     */
    public function getRenewLog(RenewLog $renewLog){
        $lists = $renewLog->lists($this->map,$this->page,$this->row,$this->order);
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * @remark :tdk更新记录
     * @name   :tdkList
     * @author :lyh
     * @method :post
     * @time   :2023/11/8 11:17
     */
    public function tdkList(){
        $this->request->validate([
            'project_id'=>'required',
        ],[
            'project_id.required' => '项目ID不能为空',
        ]);
        $tdkModel = new ProjectUpdateTdk();
        $list = $tdkModel->list(['project_id'=>$this->map['project_id']],'id',['*'],'desc',5);
        if(!empty($list)){
            foreach ($list as $k => $v){
                $list[$k] = $this->handleTdk($v);
            }
        }
        $this->response('success',Code::SUCCESS,$list);
    }

    /**
     * @remark :处理tdk
     * @name   :handleTdk
     * @author :lyh
     * @method :post
     * @time   :2023/12/29 11:16
     */
    public function handleTdk($item){
        $data = [
            'gl_product'=>'产品',
            'gl_product_category'=>'产品分类',
            'gl_product_keyword'=>'产品关键字',
            'gl_news'=>'新闻',
            'gl_news_category'=>'新闻分类',
            'gl_blog'=>'博客',
            'gl_blog_category'=>'博客分类',
            'gl_web_custom_template'=>'自定义页面',
        ];
        foreach ($data as $k => $v){
            if(isset($item[$k])){
                $data = Arr::s2a($item[$k]);
                //{"des": 3500, "title": 0, "keyword": 3501, "total_page": 8458, "keyword_title": 3500, "keyword_content": 3500}
                $item[$k] = $v.'总条数:'.$data['total_page'].
                    ', title更新数:'.$data['title'].
                    ',keyword更新数:'.$data['keyword'].
                    ',des更新数:'.$data['des'];
                if($k == 'gl_product_keyword'){
                    $item[$k] .= ',keyword_title更新数:'.($data['keyword_title']??0);
                    $item[$k] .= ',keyword_content更新数:'.($data['keyword_content']??0);
                }
            }

        }
        return $item;
    }

    /**
     * @remark :复制项目
     * @name   :copyProject
     * @author :lyh
     * @method :post
     * @time   :2023/11/8 14:17
     */
    public function copyProject(ProjectLogic $logic){
        $this->request->validate([
            'project_id'=>'required',
        ],[
            'project_id.required' => 'project_id不能为空',
        ]);
        $data = $logic->copyProject();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * AICC采集数据接口token
     * @author zbj
     * @date 2023/11/10
     */
    public function site_token(ProjectLogic $logic){
        $this->request->validate([
            'project_id'=>'required',
        ],[
            'project_id.required' => 'project_id不能为空',
        ]);
        $token = $logic->getSiteToken($this->map);
        $this->response('success',Code::SUCCESS,['site_token' => $token]);
    }

    /**
     * @remark :单独保存其他项目配置
     * @name   :saveOtherProject
     * @author :lyh
     * @method :post
     * @time   :2023/11/17 15:23
     */
    public function saveOtherProject(ProjectLogic $logic){
        $this->request->validate([
            'id'=>'required',
            'aicc'=>'required',
            'hagro'=>'required',
        ],[
            'id.required' => 'id不能为空',
            'aicc.required' => 'aicc是否开启不能为空',
            'hagro.required' => 'hagro是否开启不能为空',
        ]);
        $logic->saveOtherProject();
        $this->response('success');
    }

    /**
     * @remark :获取其他项目配置
     * @name   :getOtherProject
     * @author :lyh
     * @method :post
     * @time   :2023/11/17 15:23
     */
    public function getOtherProject(ProjectLogic $logic){
        $this->request->validate([
            'id'=>'required',
        ],[
            'id.required' => 'id不能为空',
        ]);
        $info = $logic->getOtherProject();
        $this->response('success',Code::SUCCESS,$info);
    }

    /**
     * @remark :获取渠道信息
     * @name   :getChannel
     * @author :lyh
     * @method :post
     * @time   :2023/11/17 16:08
     */
    public function getChannel(){
        $zoneModel = new Zone();
        $zone_list = $zoneModel->list();
        $channelModel = new Channel();
        $channelUserModel = new User();
        foreach ($zone_list as $k => $v){
            $channel_list = $channelModel->list(['zone_id'=>$v['id']]);
            foreach ($channel_list as $k1 => $v1){
                $user_list = $channelUserModel->list(['channel_id'=>$v1['id']]);
                $channel_list[$k1]['sub'] = $user_list;
            }
            $zone_list[$k]['sub'] = $channel_list;
        }
        $this->response('success',Code::SUCCESS,$zone_list);
    }

    /**
     * @remark :获取小语种列表
     * @name   :lists
     * @author :lyh
     * @method :post
     * @time   :2023/11/30 10:59
     */
    public function languageLists(){
        $webLanguageModel = new WebLanguage();
        $lists = $webLanguageModel->list();
        $this->response('success',Code::SUCCESS,$lists);
    }

    /**
     * 获取国家地区列表
     * @author zbj
     * @date 2024/1/19
     */
    public function countryLists(){
        $this->response('success',Code::SUCCESS, Country::getCountryList());
    }

    /**
     * 保存询盘过滤配置
     * @author zbj
     * @date 2024/1/19
     */
    public function saveInquiryFilterConfig(ProjectLogic $logic){
        $this->request->validate([
            'project_id'=>'required',
        ],[
            'project_id.required' => '项目id不能为空',
        ]);
        $logic->saveInquiryFilterConfig($this->param);
        $this->response('success');
    }

    /**
     * 保存引流设置
     * @author zbj
     * @date 2024/3/29
     */
    public function saveWebTrafficConfig(ProjectLogic $logic){
        $this->request->validate([
            'project_id'=>'required',
        ],[
            'project_id.required' => '项目id不能为空',
        ]);
        $logic->saveWebTrafficConfig($this->param);
        $this->response('success');
    }

    /**
     * @remark :更新项目的管理员
     * @name   :updateProjectManager
     * @author :lyh
     * @method :post
     * @time   :2024/4/7 10:41
     */
    public function updateProjectManager(ProjectLogic $logic){
        $this->request->validate([
            'old_id'=>'required',
            'new_id'=>'required'
        ],[
            'old_id.required' => '参数不能为空',
            'new_id.required' => '参数不能为空',
        ]);
        //查看当前用户是否存在
        $hrModel = new ManageHr();
        $oldHrInfo = $hrModel->read(['id'=>$this->param['old_id']]);
        if($oldHrInfo === false){
            $this->response('当前用户不存在',Code::SYSTEM_ERROR);
        }
        $newHrInfo = $hrModel->read(['id'=>$this->param['new_id'],'status'=>1]);
        if($newHrInfo === false){
            $this->response('变更的用户不存在',Code::SYSTEM_ERROR);
        }
        if($oldHrInfo['entry_position'] != $newHrInfo['entry_position']){
            $this->response('不同岗位不允许变更',Code::SYSTEM_ERROR);
        }
        $logic->getManagerFiled($newHrInfo['entry_position'],$this->param['old_id'],$this->param['new_id'],$this->param['project_id'] ?? []);
        $this->response('success');
    }

    /**
     * @remark :开启与关闭分词搜索
     * @name   :setIsParticiple
     * @author :lyh
     * @method :post
     * @time   :2024/6/19 10:07
     */
    public function setIsParticiple(){
        $this->request->validate([
            'project_id'=>'required',
            'is_participle'=>'required'
        ],[
            'project_id.required' => '项目id不能为空',
            'is_participle.required' => '项目id不能为空',
        ]);
        $deployBuildModel = new DeployBuild();
        $deployBuildModel->edit(['is_participle'=>$this->param['is_participle']],['project_id'=>$this->param['project_id']]);
        $this->response('success');
    }

    /**
     * @remark :(on/off)站点
     * @param  : site_status(站点状态0/1:开启/关闭),id(项目id)
     * @name   :saveSiteStatus
     * @author :lyh
     * @method :post
     * @time   :2024/7/29 17:12
     */
    public function saveSiteStatus(){
        $this->request->validate([
            'id'=>'required',
            'site_status'=>'required'
        ],[
            'id.required' => '项目id不能为空',
            'site_status.required' => '状态不能为空',
        ]);

        //获取项目数据
        $projectModel = new Project();
        $projectInfo = $projectModel->read(['id'=>$this->param['id']],['project_type','serve_id','site_status','site_token']);
        if(!$projectInfo){
            $this->fail('获取项目数据失败');
        }
        if($projectInfo['site_status'] == $this->param['site_status']){
            $this->response('success');
        }

        if($projectInfo['serve_id'] == 8){
            //自建站项目
            if($this->param['site_status'] == 1){
                //关闭站点
                $site_token = $projectInfo['site_token'] ? $projectInfo['site_token'].'_expired' : '';
            }else{
                //开启站点
                $site_token = str_replace('_expired','',$projectInfo['site_token']);
            }

            $projectModel->edit(['site_status'=>$this->param['site_status'],'site_token'=>$site_token],['id'=>$this->param['id']]);
        }else{
            //普通项目
            //获取域名数据
            $domainModel = new DomainInfoModel();
            $domainInfo = $domainModel->read(['project_id'=>$this->param['id']],['id','domain','amp_status']);
            if(!$domainInfo){
                $this->fail('获取域名数据失败');
            }

            if($this->param['site_status'] == 1){
                //关闭站点:通知C端
                $re = curl_get('https://'.$domainInfo['domain'].'/api/stop_or_start_website');
                if(isset($re['status']) && $re['status'] !== 200){
                    $this->fail($re['message']);
                }
            }else{
                //开启站点:创建建站任务
                $serverIpModel = new ServersIp();
                $serversIpInfo = $serverIpModel->read(['id' => $projectInfo['serve_id']], ['servers_id']);
                if(!$serversIpInfo){
                    $this->fail('获取项目所属服务器失败');
                }

                if ($projectInfo['project_type'] == Project::PROJECT_TYPE_SEO) {
                    $type = DomainCreateTask::TYPE_BLOG;
                } else {
                    $type = DomainCreateTask::TYPE_MAIN;
                }

                //创建更新站点证书任务
                $domainCreateTaskModel = new DomainCreateTask();
                $task_info = $domainCreateTaskModel->read(['type' => $type, 'domain_id' => $domainInfo['id'], 'is_open' => DomainCreateTask::IS_OPEN, 'status' => ['<', DomainCreateTask::STATUS_SUC]], ['id']);
                if (!$task_info) {
                    $domainCreateTaskModel->add([
                        'server_id' => $serversIpInfo['servers_id'],
                        'project_id' => $this->param['id'],
                        'domain_id' => $domainInfo['id'],
                        'type' => $type,
                        'is_open' => DomainCreateTask::IS_OPEN
                    ]);
                }

                if($domainInfo['amp_status']){
                    $task_info_amp = $domainCreateTaskModel->read(['type' => DomainCreateTask::TYPE_AMP, 'domain_id' => $domainInfo['id'], 'is_open' => DomainCreateTask::IS_OPEN, 'status' => ['<', DomainCreateTask::STATUS_SUC]], ['id']);
                    if (!$task_info_amp) {
                        $domainCreateTaskModel->add([
                            'server_id' => $serversIpInfo['servers_id'],
                            'project_id' => $this->param['id'],
                            'domain_id' => $domainInfo['id'],
                            'type' => DomainCreateTask::TYPE_AMP,
                            'is_open' => DomainCreateTask::IS_OPEN
                        ]);
                    }
                }
            }

            $projectModel->edit(['site_status'=>$this->param['site_status']],['id'=>$this->param['id']]);
        }

        $this->response('success');
    }

    /**
     * 获取项目所有行业列表
     * @author Akun
     * @date 2025/03/05 11:40
     */
    public function industryList()
    {
        $model = new ProjectIndustry();
        $lists = $model->list(['status' => 1], 'id', ['id', 'industry_name'], 'asc');
        $this->response('success', Code::SUCCESS, $lists);
    }

    /**
     * @remark :生成关键词图表数据
     * @name   :generateCountCharts
     * @author :lyh
     * @method :post
     * @time   :2025/6/10 10:51
     */
    public function generateCountCharts(){
        $this->request->validate([
            'project_id'=>'required',
        ],[
            'project_id.required' => '项目id不能为空',
        ]);
        $noticeModel = new NoticeLog();
        $info = $noticeModel->read(['type'=>NoticeLog::TYPE_GENERATE_COUNT_CHARTS,'status'=>0,'data'=>['like','%"'.$this->param['project_id'].'"%']]);
        if($info !== false){
            $this->fail('当前数据在生成中');
        }
        NoticeLog::createLog(NoticeLog::TYPE_GENERATE_COUNT_CHARTS, ['project_id' => $this->param['project_id']]);
        $this->response('success');
    }

    /**
     * @remark :更新项目tdk
     * @name   :updateTdk
     * @author :lyh
     * @method :post
     * @time   :2025/7/2 11:04
     */
    public function updateTdk(){
        $this->request->validate([
            'project_id'=>'required',
            'url'=>'required'
        ],[
            'project_id.required' => '项目id不能为空',
            'url.required' => '文件路径不为空',
        ]);
        NoticeLog::createLog(NoticeLog::TYPE_UPDATE_PROJECT_TDK, ['project_id' => $this->param['project_id'],'url'=>$this->param['url']]);
        $this->response('success',Code::SUCCESS,['url'=>$this->param['url']]);
    }

    /**
     * @remark :统计剩余服务时常
     * @name   :serviceNumCount
     * @author :lyh
     * @method :post
     * @time   :2025/7/29 14:12
     */
    public function serviceNumCount(){
        $this->request->validate([
            'end_date'=>'required',
            'project_id'=>'required',
        ],[
            'end_date.required' => '结束时常不能为空',
            'project_id.required' => '项目id不能为空',
        ]);
        if(isset($this->param['renewal_record']) && !empty($this->param['renewal_record'])){
            $paymentModel = new Payment();
            $renewal_record = Arr::a2s($this->param['renewal_record']);
            $paymentModel->edit(['renewal_record'=>$renewal_record],['project_id'=>$this->param['project_id']]);
        }
        $projectModel = new Project();
        $projectInfo = $projectModel->read(['id'=>$this->param['project_id']],['uptime','project_type']);
        $diff = (strtotime($this->param['end_date']) - strtotime($projectInfo['uptime'])) / (60 * 60 * 24);
        $deployBuildModel = new DeployBuild();
        if($projectModel['project_type'] == Project::PROJECT_TYPE_SEO){
            $param = ['seo_service_duration'=>$diff];
        }else{
            $param = ['service_duration'=>$diff];
        }
        $deployBuildModel->edit($param,['project_id'=>$this->param['project_id']]);
        $this->response('success');
    }
}