ProjectController.php 9.8 KB
<?php

namespace App\Http\Controllers\Aside\Project;

use App\Enums\Common\Code;
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\Http\Requests\Aside\Project\ProjectRequest;
use App\Models\ASide\APublicModel;
use App\Models\Com\City;
use App\Models\Devops\ServerConfig;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquirySet;
use App\Models\Manage\BelongingGroup;
use App\Models\Manage\ManageHr;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Payment;
use App\Models\Project\Project;
use Illuminate\Http\Request;


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

    public function list(ProjectLogic $logic)
    {
        $map = [];
        //搜索类型
        if(isset($this->param['type']) && $this->param['type'] == Project::TYPE_THREE){
            $map[] = ['type', 'in' ,[Project::TYPE_FOUR,Project::TYPE_SIX]];
        }
        if(isset($this->param['type']) && $this->param['type'] == Project::TYPE_TWO){
            $map[] = ['type', 'in', [Project::TYPE_TWO,Project::TYPE_THREE]];
        }
        if(isset($this->param['type']) && $this->param['type'] == Project::TYPE_ONE){
            $map[] = ['type','in',[Project::TYPE_ONE]];
        }
        if(isset($this->param['type']) && $this->param['type'] == Project::TYPE_ZERO){
            $map[] = ['type','in',[Project::TYPE_ZERO]];
        }
        //搜索技术组
        if(!empty($this->param['dep_id'])){
            $map[] = ['id', 'in', DeployBuild::where('dept_id', $this->param['dep_id'])->pluck('project_id')->toArray()];
        }
        //搜索技术人员
        if(!empty($this->param['manage_id'])){
            $map[] = ['id', 'in', DeployBuild::where('leader_mid', $this->param['manage_id'])
                ->orwhere('manager_mid', $this->param['manage_id'])
                ->orwhere('designer_mid', $this->param['manage_id'])
                ->orwhere('tech_mid', $this->param['manage_id'])
                ->pluck('project_id')
                ->toArray()];
        }
        //按类型搜索
        if(!empty($this->param['search']) && !empty($this->param['search_type'])){
            if($this->param['search_type'] == 'domain'){
                //搜索域名
                $map[] = ['id', 'in', DeployOptimize::where('domain', 'like', "%{$this->param['search']}%")->pluck('project_id')->toArray()];
            }else{
                $map[] = [$this->param['search_type'], 'like', "%{$this->param['search']}%"];
            }
        }
        $sort = ['id' => 'desc'];
        $data = $logic->getList($map, $sort,['*'],$this->row);
        $this->response('success',Code::SUCCESS,$data);
    }

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

    /**
     * @remark :保存数据
     * @name   :save
     * @author :lyh
     * @method :post
     * @time   :2023/8/17 16:42
     */
    public function save(ProjectRequest $request, ProjectLogic $logic)
    {
        $request->validated();
        $logic->save($this->param);
        $this->response('success');
    }

    /**
     * 询盘通知设置
     * @param ProjectRequest $request
     * @param ProjectLogic $logic
     * @return \Illuminate\Http\JsonResponse
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     * @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);
    }


    /**
     * 数据源
     * @param ProjectLogic $logic
     * @return \Illuminate\Http\JsonResponse
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     * @author zbj
     * @date 2023/6/20
     */
    public function data_source(ProjectLogic $logic){
        $data = $logic->dataSource();
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * 省市数据源
     * @param ProjectLogic $logic
     * @return \Illuminate\Http\JsonResponse
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     * @author zbj
     * @date 2023/6/27
     */
    public function city_source(){
        $data = City::source($this->param['id'] ?? 0);
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * 渠道数据源
     * @param ProjectLogic $logic
     * @return \Illuminate\Http\JsonResponse
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     * @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){
        $data = $logic->save($this->param);
        $this->response('success',Code::SUCCESS,$data);
    }

    /**
     * 获取合同票据
     * @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() : []);
    }

    /**
     * 提交审核
     * @author zbj
     * @date 2023/6/29
     */
    public function submit_check(Request $request, OnlineCheckLogic $logic){
        $request->validate([
            'id'=>'required'
        ],[
            'id.required' => 'ID不能为空'
        ]);
        $logic->saveOnlineCheck();
        $this->response('success');
    }

    /**
     * 上线审核
     * @author zbj
     * @date 2023/6/29
     */
    public function online_check(Request $request, OnlineCheckLogic $logic){
        $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->param);
        $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);
        $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();
        $lists = $hrManagerModel->list($this->map,'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
     */
    public function getServiceConfig(){
        $serviceConfigModel = new ServerConfig();
        $list = $serviceConfigModel->list($this->param);
        $this->response('success',Code::SUCCESS,$list);
    }

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