作者 lyh

gx

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :DomainSettingController.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/3/20 11:23
  8 + */
  9 +
  10 +namespace App\Http\Controllers\Bside\SeoSetting;
  11 +
  12 +use App\Enums\Common\Code;
  13 +use App\Http\Controllers\Bside\BaseController;
  14 +use App\Models\Domain\DomainInfo;
  15 +use Illuminate\Http\Request;
  16 +
  17 +/**
  18 + * @remark :白帽系统设置二级域名
  19 + * @name :DomainSettingController
  20 + * @author :lyh
  21 + * @method :post
  22 + * @time :2025/3/20 11:23
  23 + */
  24 +class DomainSettingController extends BaseController
  25 +{
  26 + public function __construct(Request $request)
  27 + {
  28 + $this->model = new DomainInfo();
  29 + parent::__construct($request);
  30 + }
  31 +
  32 + /**
  33 + * @remark :获取当前二级域名详情
  34 + * @name :getInfo
  35 + * @author :lyh
  36 + * @method :post
  37 + * @time :2025/3/20 11:26
  38 + */
  39 + public function getInfo(){
  40 + $data = $this->model->read(['project_id'=>$this->user['project_id']]);
  41 + $this->response('success',Code::SUCCESS,$data);
  42 + }
  43 +
  44 + /**
  45 + * @remark :保存域名数据
  46 + * @name :save
  47 + * @author :lyh
  48 + * @method :post
  49 + * @time :2025/3/20 11:29
  50 + */
  51 + public function save(){
  52 + $this->request->validate([
  53 + 'domain'=>['required'],
  54 + ],[
  55 + 'domain.required' => 'domain不能为空',
  56 + ]);
  57 + $domain = parse_url($this->param['domain'], PHP_URL_HOST);
  58 + if(!empty($domain)){
  59 + $this->param['domain'] = trim($domain['host']);
  60 + }
  61 + //添加域名到域名管理
  62 + $info = $this->model->read(['project_id'=>$this->user['project_id']]);
  63 + if($info === false){
  64 + $domainInfo = $this->model->read(['domain'=>$domain]);
  65 + if ($domainInfo !== false) {
  66 + $this->fail('当前域名已存在');
  67 + }
  68 + //保存数据
  69 + $id = $this->model->addReturnId(['domain'=>$this->param['domain'],'project_id'=>$this->user['project_id'],'belong_to'=>2,'status'=>1]);
  70 + $projectModel = new Project();
  71 + $projectModel->edit(['domain'=>$id],['project_id'=>$this->user['project_id']]);
  72 + }else{
  73 + $id = $info['id'];
  74 + $domainInfo = $this->model->read(['domain'=>$domain,'id'=>['!=',$id]]);
  75 + if ($domainInfo !== false) {
  76 + $this->fail('当前域名已存在');
  77 + }
  78 + $this->model->edit(['domain'=>$this->param['domain']],['project_id'=>$this->user['project_id']]);
  79 + }
  80 + }
  81 +}