作者 lyh

gx

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :ServersController.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/6/24 16:18
  8 + */
  9 +
  10 +namespace App\Http\Controllers\Aside\Devops;
  11 +
  12 +use App\Enums\Common\Code;
  13 +use App\Http\Controllers\Aside\BaseController;
  14 +use App\Http\Logic\Aside\Devops\ServersLogic;
  15 +use App\Models\Devops\Servers;
  16 +use App\Models\Devops\Servers as ServersModel;
  17 +
  18 +class ServersController extends BaseController
  19 +{
  20 + /**
  21 + * @remark :服务器列表
  22 + * @name :lists
  23 + * @author :lyh
  24 + * @method :post
  25 + * @time :2024/6/24 16:25
  26 + */
  27 + public function lists(){
  28 + if(isset($this->map['server_name']) && !empty($this->map['server_name'])){
  29 + $this->map['server_name'] = ['like','%'.$this->map['server_name'].'%'];
  30 + }
  31 + $serversModel = new ServersModel();
  32 + $data = $serversModel->lists($this->map,$this->page,$this->row,$this->order);
  33 + $this->response('success',Code::SUCCESS,$data);
  34 + }
  35 +
  36 + /**
  37 + * @remark :获取详情
  38 + * @name :Info
  39 + * @author :lyh
  40 + * @method :post
  41 + * @time :2024/6/24 17:05
  42 + */
  43 + public function info(ServersLogic $serversLogic){
  44 + $this->request->validate([
  45 + 'id'=>'required'
  46 + ],[
  47 + 'id.required' => '主键不能为空'
  48 +
  49 + ]);
  50 + $data = $serversLogic->infoServers();
  51 + $this->response('success',Code::SUCCESS,$data);
  52 + }
  53 +
  54 + /**
  55 + * @remark :保存数据
  56 + * @name :save
  57 + * @author :lyh
  58 + * @method :post
  59 + * @time :2024/6/24 16:25
  60 + */
  61 + public function save(ServersLogic $serversLogic){
  62 + $this->request->validate([
  63 + 'server_name'=>'required',
  64 + 'service_type'=>'required',
  65 + 'total'=>'required',
  66 + 'account'=>'required',
  67 + 'password'=>'required',
  68 + 'port'=>'required'
  69 + ],[
  70 + 'server_name.required' => '服务器名称server_name不能为空',
  71 + 'service_type.required' => '服务器类型不能为空',
  72 + 'total.required' => '总数不能为空',
  73 + 'account.required' => '账号不能为空',
  74 + 'password.required' => '密码不能为空',
  75 + 'port.required' => '端口不能为空'
  76 + ]);
  77 + $data = $serversLogic->saveServers();
  78 + $this->response('success',Code::SUCCESS,$data);
  79 + }
  80 +}
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :ServersIpController.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/6/24 16:23
  8 + */
  9 +
  10 +namespace App\Http\Controllers\Aside\Devops;
  11 +
  12 +use App\Enums\Common\Code;
  13 +use App\Http\Controllers\Aside\BaseController;
  14 +use App\Http\Logic\Aside\Devops\ServersIpLogic;
  15 +use App\Models\Devops\ServersIp as ServersIpModel;
  16 +
  17 +class ServersIpController extends BaseController
  18 +{
  19 + /**
  20 + * @remark :当前服务器器对应的ip列表
  21 + * @name :list
  22 + * @author :lyh
  23 + * @method :post
  24 + * @time :2024/6/24 16:23
  25 + */
  26 + public function list(){
  27 + $this->request->validate([
  28 + 'servers_id'=>'required'
  29 + ],[
  30 + 'servers_id.required' => '服务器servers_id不能为空'
  31 + ]);
  32 + $serversIpModel = new ServersIpModel();
  33 + $data = $serversIpModel->lists($this->map,$this->page,$this->row,$this->order);
  34 + $this->response('success',Code::SUCCESS,$data);
  35 + }
  36 +
  37 +
  38 + /**
  39 + * @remark :保存数据
  40 + * @name :save
  41 + * @author :lyh
  42 + * @method :post
  43 + * @time :2024/6/24 16:24
  44 + */
  45 + public function save(ServersIpLogic $serversIpLogic){
  46 + $this->request->validate([
  47 + 'ip'=>'required',
  48 + 'servers_id'=>'required',
  49 + 'domain'=>'required'
  50 + ],[
  51 + 'ip.required' => 'ip不能为空',
  52 + 'servers_id.required' => '服务器servers_id不能为空',
  53 + 'domain.required' => 'cname域名不能为空',
  54 + ]);
  55 + $data = $serversIpLogic->saveServersIp();
  56 + $this->response('success',Code::SUCCESS,$data);
  57 + }
  58 +
  59 + /**
  60 + * @remark :批量保存ip_domain
  61 + * @name :batchSave
  62 + * @author :lyh
  63 + * @method :post
  64 + * @time :2024/6/24 17:23
  65 + */
  66 + public function batchSave(ServersIpLogic $serversIpLogic){
  67 + $this->request->validate([
  68 + 'data'=>'required',
  69 + 'servers_id'=>'required',
  70 + ],[
  71 + 'data.required' => 'data集合不能为空',
  72 + 'servers_id.required' => '服务器servers_id不能为空',
  73 + ]);
  74 + $data = $serversIpLogic->batchSaveServersIp();
  75 + $this->response('success',Code::SUCCESS,$data);
  76 + }
  77 +}
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :ServersIpLogic.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/6/24 16:21
  8 + */
  9 +
  10 +namespace App\Http\Logic\Aside\Devops;
  11 +
  12 +use App\Http\Logic\Aside\BaseLogic;
  13 +use App\Models\Devops\ServersIp;
  14 +
  15 +class ServersIpLogic extends BaseLogic
  16 +{
  17 + /**
  18 + * 数据初始化
  19 + */
  20 + public function __construct()
  21 + {
  22 + parent::__construct();
  23 + $this->param = $this->requestAll;
  24 + $this->model = new ServersIp();
  25 + }
  26 +
  27 + /**
  28 + * @remark :保存数据
  29 + * @name :saveServersIp
  30 + * @author :lyh
  31 + * @method :post
  32 + * @time :2024/6/24 17:28
  33 + */
  34 + public function saveServersIp(){
  35 + if(isset($this->param['id']) && !empty($this->param['id'])){
  36 + $id = $this->param['id'];
  37 + $this->model->edit($this->param,['id'=>$this->param['id']]);
  38 + }else{
  39 + $id = $this->model->addReturnId($this->param);
  40 + }
  41 + return $this->success(['id'=>$id]);
  42 + }
  43 +
  44 + /**
  45 + * @remark :批量添加
  46 + * @name :batchSaveServersIp
  47 + * @author :lyh
  48 + * @method :post
  49 + * @time :2024/6/24 17:25
  50 + */
  51 + public function batchSaveServersIp(){
  52 + $data = [];
  53 + foreach ($this->param['data'] as $v){
  54 + if(empty($v['ip']) || empty($v['domain'])){
  55 + continue;
  56 + }
  57 + $data[] = [
  58 + 'ip'=>$v['ip'],
  59 + 'domain'=>$v['domain'],
  60 + 'servers_id'=>$this->param['servers_id']
  61 + ];
  62 + }
  63 + return $this->addReturnId($data);
  64 + }
  65 +}
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :ServersLogic.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/6/24 16:19
  8 + */
  9 +
  10 +namespace App\Http\Logic\Aside\Devops;
  11 +
  12 +use App\Http\Logic\Aside\BaseLogic;
  13 +use App\Models\Devops\Servers;
  14 +use App\Utils\EncryptUtils;
  15 +
  16 +class ServersLogic extends BaseLogic
  17 +{
  18 + /**
  19 + * 数据初始化
  20 + */
  21 + public function __construct()
  22 + {
  23 + parent::__construct();
  24 + $this->param = $this->requestAll;
  25 + $this->model = new Servers();
  26 + }
  27 +
  28 + /**
  29 + * @remark :获取信息
  30 + * @name :getServiceConfig
  31 + * @author :lyh
  32 + * @method :post
  33 + * @time :2024/6/24 17:05
  34 + */
  35 + public function infoServers(){
  36 + $info = $this->model->read(['id'=>$this->param['id']]);
  37 + if($info === false){
  38 + $this->fail('当前数据不存在或者被删除');
  39 + }
  40 + return $this->success($info);
  41 + }
  42 +
  43 + /**
  44 + * @remark :保存数据
  45 + * @name :saveServers
  46 + * @author :lyh
  47 + * @method :post
  48 + * @time :2024/6/24 16:33
  49 + */
  50 + public function saveServers(){
  51 + $encrypt = new EncryptUtils();
  52 + $this->param['account'] = $encrypt->lock_url($this->param['account']);
  53 + $this->param['password'] = $encrypt->lock_url($this->param['password']);
  54 + $this->param['port'] = $encrypt->lock_url($this->param['port']);
  55 + if(isset($this->param['id']) && !empty($this->param['id'])){
  56 + $id = $this->param['id'];
  57 + $this->model->edit($this->param,['id'=>$id]);
  58 + }else{
  59 + $id = $this->model->addReturnId($this->param);
  60 + }
  61 + return $this->success(['id'=>$id]);
  62 + }
  63 +}
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :Servers.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/6/24 16:19
  8 + */
  9 +
  10 +namespace App\Models\Devops;
  11 +
  12 +use App\Models\Base;
  13 +use App\Utils\EncryptUtils;
  14 +
  15 +class Servers extends Base
  16 +{
  17 + protected $table = 'gl_servers';
  18 + const SELF_SITE_ID = 8;//自建站服务器ID
  19 +
  20 + /**
  21 + * @remark :获取数据用户名解密
  22 + * @name :getUserAttribute
  23 + * @author :lyh
  24 + * @method :post
  25 + * @time :2023/9/12 16:05
  26 + */
  27 + public function getAccountAttribute($value){
  28 + return (new EncryptUtils())->unlock_url($value);
  29 + }
  30 +
  31 + /**
  32 + * @remark :密码解密
  33 + * @name :getPasswordAttribute
  34 + * @author :lyh
  35 + * @method :post
  36 + * @time :2023/9/12 16:05
  37 + */
  38 + public function getPasswordAttribute($value){
  39 + return (new EncryptUtils())->unlock_url($value);
  40 + }
  41 +
  42 + /**
  43 + * @remark :端口解密
  44 + * @name :getPasswordAttribute
  45 + * @author :lyh
  46 + * @method :post
  47 + * @time :2023/9/12 16:05
  48 + */
  49 + public function getPortAttribute($value){
  50 + return (new EncryptUtils())->unlock_url($value);
  51 + }
  52 +}
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :ServersIp.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/6/24 16:20
  8 + */
  9 +
  10 +namespace App\Models\Devops;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class ServersIp extends Base
  15 +{
  16 + protected $table = 'gl_servers_ip';
  17 +}