正在显示
1 个修改的文件
包含
117 行增加
和
101 行删除
| @@ -9,6 +9,7 @@ use App\Models\Domain\DomainCreateTask; | @@ -9,6 +9,7 @@ use App\Models\Domain\DomainCreateTask; | ||
| 9 | use App\Models\Domain\DomainInfo; | 9 | use App\Models\Domain\DomainInfo; |
| 10 | use App\Models\Domain\DomainRedirectTask; | 10 | use App\Models\Domain\DomainRedirectTask; |
| 11 | use App\Models\Project\CountryCustom; | 11 | use App\Models\Project\CountryCustom; |
| 12 | +use App\Models\Project\DeployBuild; | ||
| 12 | use App\Models\Project\Project; | 13 | use App\Models\Project\Project; |
| 13 | 14 | ||
| 14 | class DomainInfoLogic extends BaseLogic | 15 | class DomainInfoLogic extends BaseLogic |
| @@ -32,21 +33,21 @@ class DomainInfoLogic extends BaseLogic | @@ -32,21 +33,21 @@ class DomainInfoLogic extends BaseLogic | ||
| 32 | public function saveDomain() | 33 | public function saveDomain() |
| 33 | { | 34 | { |
| 34 | $domain = parse_url($this->param['domain'], PHP_URL_HOST); | 35 | $domain = parse_url($this->param['domain'], PHP_URL_HOST); |
| 35 | - if(!empty($domain)){ | 36 | + if (!empty($domain)) { |
| 36 | $this->param['domain'] = trim($domain['host']); | 37 | $this->param['domain'] = trim($domain['host']); |
| 37 | } | 38 | } |
| 38 | //验证域名 | 39 | //验证域名 |
| 39 | - $this->verifyDomain($this->param['domain'],$this->param['id'] ?? ''); | ||
| 40 | - if(isset($this->param['id']) && !empty($this->param['id'])){ | ||
| 41 | - $rs = $this->model->edit($this->param,['id'=>$this->param['id']]); | ||
| 42 | - }else{ | 40 | + $this->verifyDomain($this->param['domain'], $this->param['id'] ?? ''); |
| 41 | + if (isset($this->param['id']) && !empty($this->param['id'])) { | ||
| 42 | + $rs = $this->model->edit($this->param, ['id' => $this->param['id']]); | ||
| 43 | + } else { | ||
| 43 | //查看域名是否以WWW开头 | 44 | //查看域名是否以WWW开头 |
| 44 | if (strpos($this->param['domain'], 'www.') === 0) { | 45 | if (strpos($this->param['domain'], 'www.') === 0) { |
| 45 | - $this->param['other_domain'] = json_encode([str_replace('www', '*', $this->param['domain']),str_replace('www.', '', $this->param['domain'])]); | 46 | + $this->param['other_domain'] = json_encode([str_replace('www', '*', $this->param['domain']), str_replace('www.', '', $this->param['domain'])]); |
| 46 | } | 47 | } |
| 47 | $rs = $this->model->add($this->param); | 48 | $rs = $this->model->add($this->param); |
| 48 | } | 49 | } |
| 49 | - if($rs === false){ | 50 | + if ($rs === false) { |
| 50 | $this->fail('error'); | 51 | $this->fail('error'); |
| 51 | } | 52 | } |
| 52 | return $this->success(); | 53 | return $this->success(); |
| @@ -60,14 +61,15 @@ class DomainInfoLogic extends BaseLogic | @@ -60,14 +61,15 @@ class DomainInfoLogic extends BaseLogic | ||
| 60 | * @method :post | 61 | * @method :post |
| 61 | * @time :2023/8/1 14:59 | 62 | * @time :2023/8/1 14:59 |
| 62 | */ | 63 | */ |
| 63 | - public function verifyDomain($domain,$id = ''){ | ||
| 64 | - if(!empty($id)){ | ||
| 65 | - $info = $this->model->read(['domain'=>$domain,'id'=>['!=',$id]]); | 64 | + public function verifyDomain($domain, $id = '') |
| 65 | + { | ||
| 66 | + if (!empty($id)) { | ||
| 67 | + $info = $this->model->read(['domain' => $domain, 'id' => ['!=', $id]]); | ||
| 66 | if ($info !== false) { | 68 | if ($info !== false) { |
| 67 | $this->fail('当前域名已存在'); | 69 | $this->fail('当前域名已存在'); |
| 68 | } | 70 | } |
| 69 | - }else{ | ||
| 70 | - $info = $this->model->read(['domain'=>$domain]); | 71 | + } else { |
| 72 | + $info = $this->model->read(['domain' => $domain]); | ||
| 71 | if ($info !== false) { | 73 | if ($info !== false) { |
| 72 | $this->fail('当前域名已存在'); | 74 | $this->fail('当前域名已存在'); |
| 73 | } | 75 | } |
| @@ -82,16 +84,17 @@ class DomainInfoLogic extends BaseLogic | @@ -82,16 +84,17 @@ class DomainInfoLogic extends BaseLogic | ||
| 82 | * @method :post | 84 | * @method :post |
| 83 | * @time :2023/8/1 15:43 | 85 | * @time :2023/8/1 15:43 |
| 84 | */ | 86 | */ |
| 85 | - public function editDomainStatus(){ | 87 | + public function editDomainStatus() |
| 88 | + { | ||
| 86 | //查看当前域名是否有项目在使用 | 89 | //查看当前域名是否有项目在使用 |
| 87 | - if($this->param['status'] != $this->model::STATUS_ONE){ | ||
| 88 | - $info = $this->model->read(['id'=>$this->param['id']]); | ||
| 89 | - if($info === false){ | 90 | + if ($this->param['status'] != $this->model::STATUS_ONE) { |
| 91 | + $info = $this->model->read(['id' => $this->param['id']]); | ||
| 92 | + if ($info === false) { | ||
| 90 | $this->fail('当前域名有项目正在使用中'); | 93 | $this->fail('当前域名有项目正在使用中'); |
| 91 | } | 94 | } |
| 92 | } | 95 | } |
| 93 | - $rs = $this->model->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]); | ||
| 94 | - if($rs === false){ | 96 | + $rs = $this->model->edit(['status' => $this->param['status']], ['id' => $this->param['id']]); |
| 97 | + if ($rs === false) { | ||
| 95 | $this->fail('error'); | 98 | $this->fail('error'); |
| 96 | } | 99 | } |
| 97 | return $this->success(); | 100 | return $this->success(); |
| @@ -104,21 +107,23 @@ class DomainInfoLogic extends BaseLogic | @@ -104,21 +107,23 @@ class DomainInfoLogic extends BaseLogic | ||
| 104 | * @method :post | 107 | * @method :post |
| 105 | * @time :2023/8/1 16:10 | 108 | * @time :2023/8/1 16:10 |
| 106 | */ | 109 | */ |
| 107 | - public function getProjectList($map){ | 110 | + public function getProjectList($map) |
| 111 | + { | ||
| 108 | $projectModel = new Project(); | 112 | $projectModel = new Project(); |
| 109 | - $lists = $projectModel->list($map,'id',['id','title']); | 113 | + $lists = $projectModel->list($map, 'id', ['id', 'title']); |
| 110 | return $this->success($lists); | 114 | return $this->success($lists); |
| 111 | } | 115 | } |
| 112 | 116 | ||
| 113 | /** | 117 | /** |
| 114 | * 删除域名 | 118 | * 删除域名 |
| 115 | */ | 119 | */ |
| 116 | - public function delDomain(){ | 120 | + public function delDomain() |
| 121 | + { | ||
| 117 | $ids = $this->param['id']; | 122 | $ids = $this->param['id']; |
| 118 | // 初始化数据 | 123 | // 初始化数据 |
| 119 | if (FALSE == is_array($ids)) | 124 | if (FALSE == is_array($ids)) |
| 120 | $ids = [$ids]; | 125 | $ids = [$ids]; |
| 121 | - foreach ($ids as $k => $v){ | 126 | + foreach ($ids as $k => $v) { |
| 122 | $domain = DomainInfo::where(['id' => $v])->first(); | 127 | $domain = DomainInfo::where(['id' => $v])->first(); |
| 123 | if (empty($domain)) | 128 | if (empty($domain)) |
| 124 | continue; | 129 | continue; |
| @@ -130,13 +135,14 @@ class DomainInfoLogic extends BaseLogic | @@ -130,13 +135,14 @@ class DomainInfoLogic extends BaseLogic | ||
| 130 | } | 135 | } |
| 131 | 136 | ||
| 132 | 137 | ||
| 133 | - public function infoDomain(){ | ||
| 134 | - $info = $this->model->read(['id'=>$this->param['id']]); | ||
| 135 | - if($info === false){ | 138 | + public function infoDomain() |
| 139 | + { | ||
| 140 | + $info = $this->model->read(['id' => $this->param['id']]); | ||
| 141 | + if ($info === false) { | ||
| 136 | $this->fail('当前数据不存在或者已被删除'); | 142 | $this->fail('当前数据不存在或者已被删除'); |
| 137 | } | 143 | } |
| 138 | - if(!empty($info['project_id'])){ | ||
| 139 | - $info['company'] = (new Project())->read(['id'=>$info['project_id']],['title'])['title']; | 144 | + if (!empty($info['project_id'])) { |
| 145 | + $info['company'] = (new Project())->read(['id' => $info['project_id']], ['title'])['title']; | ||
| 140 | } | 146 | } |
| 141 | return $this->success($info); | 147 | return $this->success($info); |
| 142 | } | 148 | } |
| @@ -148,40 +154,41 @@ class DomainInfoLogic extends BaseLogic | @@ -148,40 +154,41 @@ class DomainInfoLogic extends BaseLogic | ||
| 148 | * @method :post | 154 | * @method :post |
| 149 | * @time :2023/11/6 10:50 | 155 | * @time :2023/11/6 10:50 |
| 150 | */ | 156 | */ |
| 151 | - public function sslSave(){ | ||
| 152 | - $info = $this->model->read(['id'=>$this->param['id']]); | ||
| 153 | - if($info === false || empty($info['domain'])){ | 157 | + public function sslSave() |
| 158 | + { | ||
| 159 | + $info = $this->model->read(['id' => $this->param['id']]); | ||
| 160 | + if ($info === false || empty($info['domain'])) { | ||
| 154 | $this->fail('当前数据不存在或者已被删除'); | 161 | $this->fail('当前数据不存在或者已被删除'); |
| 155 | } | 162 | } |
| 156 | //获取项目数据 | 163 | //获取项目数据 |
| 157 | $project_model = new Project(); | 164 | $project_model = new Project(); |
| 158 | - $project_info = $project_model->read(['id'=>$info['project_id']],'serve_id'); | ||
| 159 | - if($project_info === false){ | 165 | + $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id'); |
| 166 | + if ($project_info === false) { | ||
| 160 | $this->fail('获取项目数据失败'); | 167 | $this->fail('获取项目数据失败'); |
| 161 | } | 168 | } |
| 162 | $serverIpModel = new ServersIp(); | 169 | $serverIpModel = new ServersIp(); |
| 163 | - $serversIpInfo = $serverIpModel->read(['id'=>$project_info['serve_id']],['servers_id','ip','domain']); | ||
| 164 | - if($serversIpInfo === false){ | 170 | + $serversIpInfo = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id', 'ip', 'domain']); |
| 171 | + if ($serversIpInfo === false) { | ||
| 165 | $this->fail('获取服务器数据失败'); | 172 | $this->fail('获取服务器数据失败'); |
| 166 | } | 173 | } |
| 167 | - if($serversIpInfo['servers_id'] == ServerConfig::SELF_TEST_ID){ | 174 | + if ($serversIpInfo['servers_id'] == ServerConfig::SELF_TEST_ID) { |
| 168 | $this->fail('请切换服务器,生成站点不能使用测试服务器'); | 175 | $this->fail('请切换服务器,生成站点不能使用测试服务器'); |
| 169 | } | 176 | } |
| 170 | - if($serversIpInfo['servers_id'] == ServerConfig::SELF_SITE_ID){ | ||
| 171 | - $this->model->edit(['amp_status' => $this->param['amp_status'] ?? 0],['id'=>$this->param['id']]); | ||
| 172 | - $this->fail('自建站服务器无法生成站点'); | 177 | + if ($serversIpInfo['servers_id'] == ServerConfig::SELF_SITE_ID) { |
| 178 | + $this->model->edit(['amp_status' => $this->param['amp_status'] ?? 0], ['id' => $this->param['id']]); | ||
| 179 | + $this->fail('自建站服务器无需生成站点'); | ||
| 173 | } | 180 | } |
| 174 | //域名是否都已经解析 | 181 | //域名是否都已经解析 |
| 175 | - if(!check_domain_record($info['domain'], $serversIpInfo)){ | 182 | + if (!check_domain_record($info['domain'], $serversIpInfo)) { |
| 176 | $this->fail('域名' . $info['domain'] . '未解析至目标服务器'); | 183 | $this->fail('域名' . $info['domain'] . '未解析至目标服务器'); |
| 177 | } | 184 | } |
| 178 | $domain_301 = ''; | 185 | $domain_301 = ''; |
| 179 | - foreach ($this->param['other_domain']??[] as $other_domain){ | ||
| 180 | - if($other_domain && substr($other_domain,0,2) != '*.'){ | ||
| 181 | - if(check_domain_record($other_domain,['domain'=>'','ip'=>DomainInfo::SERVER_IP_301])){ | 186 | + foreach ($this->param['other_domain'] ?? [] as $other_domain) { |
| 187 | + if ($other_domain && substr($other_domain, 0, 2) != '*.') { | ||
| 188 | + if (check_domain_record($other_domain, ['domain' => '', 'ip' => DomainInfo::SERVER_IP_301])) { | ||
| 182 | $domain_301 = $other_domain; | 189 | $domain_301 = $other_domain; |
| 183 | - }else{ | ||
| 184 | - if(!check_domain_record($other_domain, $serversIpInfo)){ | 190 | + } else { |
| 191 | + if (!check_domain_record($other_domain, $serversIpInfo)) { | ||
| 185 | $this->fail('域名' . $other_domain . '未解析至目标服务器'); | 192 | $this->fail('域名' . $other_domain . '未解析至目标服务器'); |
| 186 | } | 193 | } |
| 187 | } | 194 | } |
| @@ -189,32 +196,32 @@ class DomainInfoLogic extends BaseLogic | @@ -189,32 +196,32 @@ class DomainInfoLogic extends BaseLogic | ||
| 189 | } | 196 | } |
| 190 | 197 | ||
| 191 | //如果要开通amp站点,判断m域名是否已经解析 | 198 | //如果要开通amp站点,判断m域名是否已经解析 |
| 192 | - if(isset($this->param['amp_status']) && $this->param['amp_status'] == 1){ | 199 | + if (isset($this->param['amp_status']) && $this->param['amp_status'] == 1) { |
| 193 | $domain_array = parse_url($info['domain']); | 200 | $domain_array = parse_url($info['domain']); |
| 194 | $host = $domain_array['host'] ?? $domain_array['path']; | 201 | $host = $domain_array['host'] ?? $domain_array['path']; |
| 195 | - $host_array = explode('.',$host); | 202 | + $host_array = explode('.', $host); |
| 196 | if (count($host_array) <= 2) { | 203 | if (count($host_array) <= 2) { |
| 197 | array_unshift($host_array, 'm'); | 204 | array_unshift($host_array, 'm'); |
| 198 | } else { | 205 | } else { |
| 199 | $host_array[0] = 'm'; | 206 | $host_array[0] = 'm'; |
| 200 | } | 207 | } |
| 201 | - $amp_domain = implode('.',$host_array); | ||
| 202 | - if(!check_domain_record($amp_domain, $serversIpInfo)){ | 208 | + $amp_domain = implode('.', $host_array); |
| 209 | + if (!check_domain_record($amp_domain, $serversIpInfo)) { | ||
| 203 | $this->fail('AMP站点域名' . $amp_domain . '未解析至目标服务器'); | 210 | $this->fail('AMP站点域名' . $amp_domain . '未解析至目标服务器'); |
| 204 | } | 211 | } |
| 205 | 212 | ||
| 206 | $is_redirect = $this->param['is_redirect'] ?? 0; | 213 | $is_redirect = $this->param['is_redirect'] ?? 0; |
| 207 | - }else{ | 214 | + } else { |
| 208 | //未开通amp站,主站和m站相互跳转也自动取消 | 215 | //未开通amp站,主站和m站相互跳转也自动取消 |
| 209 | $is_redirect = 0; | 216 | $is_redirect = 0; |
| 210 | } | 217 | } |
| 211 | 218 | ||
| 212 | $not_allow_ip = array_filter($this->param['not_allow_ip'] ?? []); | 219 | $not_allow_ip = array_filter($this->param['not_allow_ip'] ?? []); |
| 213 | - if($not_allow_ip){ | 220 | + if ($not_allow_ip) { |
| 214 | //判断禁止访问IP是否填写正确 | 221 | //判断禁止访问IP是否填写正确 |
| 215 | - foreach ($not_allow_ip as $vn){ | ||
| 216 | - $vn_count = count(explode('.',$vn)); | ||
| 217 | - if($vn_count != 4){ | 222 | + foreach ($not_allow_ip as $vn) { |
| 223 | + $vn_count = count(explode('.', $vn)); | ||
| 224 | + if ($vn_count != 4) { | ||
| 218 | $this->fail('禁止访问IP填写有误'); | 225 | $this->fail('禁止访问IP填写有误'); |
| 219 | } | 226 | } |
| 220 | } | 227 | } |
| @@ -222,9 +229,9 @@ class DomainInfoLogic extends BaseLogic | @@ -222,9 +229,9 @@ class DomainInfoLogic extends BaseLogic | ||
| 222 | 229 | ||
| 223 | $extend_config = []; | 230 | $extend_config = []; |
| 224 | $unique_extend = []; | 231 | $unique_extend = []; |
| 225 | - if(isset($this->param['extend_config']) && $this->param['extend_config']){ | ||
| 226 | - foreach ($this->param['extend_config'] as $k=>$v){ | ||
| 227 | - if($v['origin'] && (!in_array($v['origin'],$unique_extend))){ | 232 | + if (isset($this->param['extend_config']) && $this->param['extend_config']) { |
| 233 | + foreach ($this->param['extend_config'] as $k => $v) { | ||
| 234 | + if ($v['origin'] && (!in_array($v['origin'], $unique_extend))) { | ||
| 228 | $unique_extend[] = $v['origin']; | 235 | $unique_extend[] = $v['origin']; |
| 229 | $extend_config[] = $v; | 236 | $extend_config[] = $v; |
| 230 | } | 237 | } |
| @@ -233,38 +240,46 @@ class DomainInfoLogic extends BaseLogic | @@ -233,38 +240,46 @@ class DomainInfoLogic extends BaseLogic | ||
| 233 | 240 | ||
| 234 | $amp_extend_config = []; | 241 | $amp_extend_config = []; |
| 235 | $amp_unique_extend = []; | 242 | $amp_unique_extend = []; |
| 236 | - if(isset($this->param['amp_extend_config']) && $this->param['amp_extend_config']){ | ||
| 237 | - foreach ($this->param['amp_extend_config'] as $ka=>$va){ | ||
| 238 | - if($va['origin'] && (!in_array($va['origin'],$amp_unique_extend))){ | 243 | + if (isset($this->param['amp_extend_config']) && $this->param['amp_extend_config']) { |
| 244 | + foreach ($this->param['amp_extend_config'] as $ka => $va) { | ||
| 245 | + if ($va['origin'] && (!in_array($va['origin'], $amp_unique_extend))) { | ||
| 239 | $amp_unique_extend[] = $va['origin']; | 246 | $amp_unique_extend[] = $va['origin']; |
| 240 | $amp_extend_config[] = $va; | 247 | $amp_extend_config[] = $va; |
| 241 | } | 248 | } |
| 242 | } | 249 | } |
| 243 | } | 250 | } |
| 244 | 251 | ||
| 252 | + //小语种为二级目录的站点,强制跳转https | ||
| 253 | + $is_https = $this->param['is_https'] ?? 0; | ||
| 254 | + $buildModel = new DeployBuild(); | ||
| 255 | + $build_info = $buildModel->read(['project_id' => $info['project_id']], ['linking_format']); | ||
| 256 | + if ($build_info && $build_info['linking_format'] == 1) { | ||
| 257 | + $is_https = 1; | ||
| 258 | + } | ||
| 259 | + | ||
| 245 | //保存301跳转数据+其他域名 | 260 | //保存301跳转数据+其他域名 |
| 246 | $data = [ | 261 | $data = [ |
| 247 | - 'other_domain'=>json_encode(array_filter($this->param['other_domain'] ?? [])), | ||
| 248 | - 'extend_config'=>json_encode($extend_config), | ||
| 249 | - 'type'=>$this->param['type'], | 262 | + 'other_domain' => json_encode(array_filter($this->param['other_domain'] ?? [])), |
| 263 | + 'extend_config' => json_encode($extend_config), | ||
| 264 | + 'type' => $this->param['type'], | ||
| 250 | 'private_key' => $this->param['key'] ?? '', | 265 | 'private_key' => $this->param['key'] ?? '', |
| 251 | 'private_cert' => $this->param['cert'] ?? '', | 266 | 'private_cert' => $this->param['cert'] ?? '', |
| 252 | - 'is_https' => $this->param['is_https'] ?? 0, | 267 | + 'is_https' => $is_https, |
| 253 | 'amp_status' => $this->param['amp_status'] ?? 0, | 268 | 'amp_status' => $this->param['amp_status'] ?? 0, |
| 254 | 'amp_type' => $this->param['amp_type'] ?? 0, | 269 | 'amp_type' => $this->param['amp_type'] ?? 0, |
| 255 | - 'amp_extend_config'=>json_encode($amp_extend_config), | 270 | + 'amp_extend_config' => json_encode($amp_extend_config), |
| 256 | 'amp_private_key' => $this->param['amp_key'] ?? '', | 271 | 'amp_private_key' => $this->param['amp_key'] ?? '', |
| 257 | 'amp_private_cert' => $this->param['amp_cert'] ?? '', | 272 | 'amp_private_cert' => $this->param['amp_cert'] ?? '', |
| 258 | - 'not_allow_country'=>json_encode(array_filter($this->param['not_allow_country'] ?? [])), | ||
| 259 | - 'not_allow_ip'=>json_encode($not_allow_ip), | 273 | + 'not_allow_country' => json_encode(array_filter($this->param['not_allow_country'] ?? [])), |
| 274 | + 'not_allow_ip' => json_encode($not_allow_ip), | ||
| 260 | 'is_redirect' => $is_redirect, | 275 | 'is_redirect' => $is_redirect, |
| 261 | ]; | 276 | ]; |
| 262 | - $this->model->edit($data,['id'=>$this->param['id']]); | 277 | + $this->model->edit($data, ['id' => $this->param['id']]); |
| 263 | 278 | ||
| 264 | //新增建站任务 | 279 | //新增建站任务 |
| 265 | $task_model = new DomainCreateTask(); | 280 | $task_model = new DomainCreateTask(); |
| 266 | - $task_info = $task_model->read(['type'=>DomainCreateTask::TYPE_MAIN,'domain_id'=>$this->param['id'],'status'=>['<',DomainCreateTask::STATUS_SUC]]); | ||
| 267 | - if(!$task_info){ | 281 | + $task_info = $task_model->read(['type' => DomainCreateTask::TYPE_MAIN, 'domain_id' => $this->param['id'], 'status' => ['<', DomainCreateTask::STATUS_SUC]]); |
| 282 | + if (!$task_info) { | ||
| 268 | $task_model->add([ | 283 | $task_model->add([ |
| 269 | 'server_id' => $serversIpInfo['servers_id'], | 284 | 'server_id' => $serversIpInfo['servers_id'], |
| 270 | 'project_id' => $info['project_id'], | 285 | 'project_id' => $info['project_id'], |
| @@ -272,9 +287,9 @@ class DomainInfoLogic extends BaseLogic | @@ -272,9 +287,9 @@ class DomainInfoLogic extends BaseLogic | ||
| 272 | 'type' => DomainCreateTask::TYPE_MAIN | 287 | 'type' => DomainCreateTask::TYPE_MAIN |
| 273 | ]); | 288 | ]); |
| 274 | } | 289 | } |
| 275 | - if($data['amp_status']){ | ||
| 276 | - $task_amp_info = $task_model->read(['type'=>DomainCreateTask::TYPE_AMP,'domain_id'=>$this->param['id'],'status'=>['<',DomainCreateTask::STATUS_SUC]]); | ||
| 277 | - if(!$task_amp_info){ | 290 | + if ($data['amp_status']) { |
| 291 | + $task_amp_info = $task_model->read(['type' => DomainCreateTask::TYPE_AMP, 'domain_id' => $this->param['id'], 'status' => ['<', DomainCreateTask::STATUS_SUC]]); | ||
| 292 | + if (!$task_amp_info) { | ||
| 278 | $task_model->add([ | 293 | $task_model->add([ |
| 279 | 'server_id' => $serversIpInfo['servers_id'], | 294 | 'server_id' => $serversIpInfo['servers_id'], |
| 280 | 'project_id' => $info['project_id'], | 295 | 'project_id' => $info['project_id'], |
| @@ -286,11 +301,11 @@ class DomainInfoLogic extends BaseLogic | @@ -286,11 +301,11 @@ class DomainInfoLogic extends BaseLogic | ||
| 286 | 301 | ||
| 287 | //新增重定向任务 | 302 | //新增重定向任务 |
| 288 | $redirect_model = new DomainRedirectTask(); | 303 | $redirect_model = new DomainRedirectTask(); |
| 289 | - if($domain_301){ | ||
| 290 | - $task_redirect_info = $redirect_model->read(['origin_domain'=>$domain_301]); | ||
| 291 | - if(!$task_redirect_info){ | 304 | + if ($domain_301) { |
| 305 | + $task_redirect_info = $redirect_model->read(['origin_domain' => $domain_301]); | ||
| 306 | + if (!$task_redirect_info) { | ||
| 292 | $redirect_model->add([ | 307 | $redirect_model->add([ |
| 293 | - 'origin_domain'=> $domain_301, | 308 | + 'origin_domain' => $domain_301, |
| 294 | 'other_domain' => json_encode([]), | 309 | 'other_domain' => json_encode([]), |
| 295 | 'target_domain' => $info['domain'] | 310 | 'target_domain' => $info['domain'] |
| 296 | ]); | 311 | ]); |
| @@ -307,63 +322,64 @@ class DomainInfoLogic extends BaseLogic | @@ -307,63 +322,64 @@ class DomainInfoLogic extends BaseLogic | ||
| 307 | * @author Akun | 322 | * @author Akun |
| 308 | * @date 2024/03/05 9:48 | 323 | * @date 2024/03/05 9:48 |
| 309 | */ | 324 | */ |
| 310 | - public function country_custom($project_id){ | 325 | + public function country_custom($project_id) |
| 326 | + { | ||
| 311 | $project_model = new Project(); | 327 | $project_model = new Project(); |
| 312 | - $project_info = $project_model->read(['id'=>$project_id],'serve_id'); | ||
| 313 | - if($project_info === false){ | 328 | + $project_info = $project_model->read(['id' => $project_id], 'serve_id'); |
| 329 | + if ($project_info === false) { | ||
| 314 | $this->fail('获取项目数据失败'); | 330 | $this->fail('获取项目数据失败'); |
| 315 | } | 331 | } |
| 316 | 332 | ||
| 317 | $custom_model = new CountryCustom(); | 333 | $custom_model = new CountryCustom(); |
| 318 | - if($this->param['is_create']){ | 334 | + if ($this->param['is_create']) { |
| 319 | //需要创建站点 | 335 | //需要创建站点 |
| 320 | $serverIpModel = new ServersIp(); | 336 | $serverIpModel = new ServersIp(); |
| 321 | - $serversIpInfo = $serverIpModel->read(['id'=>$project_info['serve_id']],['servers_id','ip','domain']); | ||
| 322 | - if($serversIpInfo === false){ | 337 | + $serversIpInfo = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id', 'ip', 'domain']); |
| 338 | + if ($serversIpInfo === false) { | ||
| 323 | $this->fail('获取服务器数据失败'); | 339 | $this->fail('获取服务器数据失败'); |
| 324 | } | 340 | } |
| 325 | - if($serversIpInfo['servers_id'] == ServerConfig::SELF_TEST_ID){ | 341 | + if ($serversIpInfo['servers_id'] == ServerConfig::SELF_TEST_ID) { |
| 326 | $this->fail('请切换服务器,生成站点不能使用测试服务器'); | 342 | $this->fail('请切换服务器,生成站点不能使用测试服务器'); |
| 327 | } | 343 | } |
| 328 | - if($serversIpInfo['servers_id'] == ServerConfig::SELF_SITE_ID){ | 344 | + if ($serversIpInfo['servers_id'] == ServerConfig::SELF_SITE_ID) { |
| 329 | $this->fail('自建站服务器无法生成站点'); | 345 | $this->fail('自建站服务器无法生成站点'); |
| 330 | } | 346 | } |
| 331 | //域名是否都已经解析 | 347 | //域名是否都已经解析 |
| 332 | - if(strpos($this->param['custom_domain'],'//') === false){ | ||
| 333 | - $this->param['custom_domain'] = '//'.$this->param['custom_domain']; | 348 | + if (strpos($this->param['custom_domain'], '//') === false) { |
| 349 | + $this->param['custom_domain'] = '//' . $this->param['custom_domain']; | ||
| 334 | } | 350 | } |
| 335 | $domain_arr = parse_url($this->param['custom_domain']); | 351 | $domain_arr = parse_url($this->param['custom_domain']); |
| 336 | - if(!isset($domain_arr['host'])){ | 352 | + if (!isset($domain_arr['host'])) { |
| 337 | $this->fail('自定义域名填写错误'); | 353 | $this->fail('自定义域名填写错误'); |
| 338 | } | 354 | } |
| 339 | $this->param['custom_domain'] = $domain_arr['host']; | 355 | $this->param['custom_domain'] = $domain_arr['host']; |
| 340 | //判断域名是否已经被使用 | 356 | //判断域名是否已经被使用 |
| 341 | - $has_info = $custom_model->read(['custom_domain'=>$this->param['custom_domain']]); | ||
| 342 | - if($has_info && ($has_info['project_id'] != $project_id || $has_info['language_id'] != $this->param['language_id'])){ | 357 | + $has_info = $custom_model->read(['custom_domain' => $this->param['custom_domain']]); |
| 358 | + if ($has_info && ($has_info['project_id'] != $project_id || $has_info['language_id'] != $this->param['language_id'])) { | ||
| 343 | $this->fail('自定义域名已被使用'); | 359 | $this->fail('自定义域名已被使用'); |
| 344 | } | 360 | } |
| 345 | - if(!check_domain_record($this->param['custom_domain'], $serversIpInfo)){ | 361 | + if (!check_domain_record($this->param['custom_domain'], $serversIpInfo)) { |
| 346 | $this->fail('域名' . $this->param['custom_domain'] . '未解析至目标服务器'); | 362 | $this->fail('域名' . $this->param['custom_domain'] . '未解析至目标服务器'); |
| 347 | } | 363 | } |
| 348 | - }else{ | ||
| 349 | - $this->param['custom_domain'] = str_replace('https://','',$this->param['custom_domain']); | ||
| 350 | - $this->param['custom_domain'] = str_replace('http://','',$this->param['custom_domain']); | ||
| 351 | - $this->param['custom_domain'] = str_replace('//','',$this->param['custom_domain']); | 364 | + } else { |
| 365 | + $this->param['custom_domain'] = str_replace('https://', '', $this->param['custom_domain']); | ||
| 366 | + $this->param['custom_domain'] = str_replace('http://', '', $this->param['custom_domain']); | ||
| 367 | + $this->param['custom_domain'] = str_replace('//', '', $this->param['custom_domain']); | ||
| 352 | } | 368 | } |
| 353 | 369 | ||
| 354 | - $info = $custom_model->read(['project_id'=>$project_id,'language_id'=>$this->param['language_id']]); | ||
| 355 | - if($info === false){ | 370 | + $info = $custom_model->read(['project_id' => $project_id, 'language_id' => $this->param['language_id']]); |
| 371 | + if ($info === false) { | ||
| 356 | $this->param['project_id'] = $project_id; | 372 | $this->param['project_id'] = $project_id; |
| 357 | $id = $custom_model->addReturnId($this->param); | 373 | $id = $custom_model->addReturnId($this->param); |
| 358 | - }else{ | ||
| 359 | - $custom_model->edit($this->param,['id'=>$info['id']]); | 374 | + } else { |
| 375 | + $custom_model->edit($this->param, ['id' => $info['id']]); | ||
| 360 | $id = $info['id']; | 376 | $id = $info['id']; |
| 361 | } | 377 | } |
| 362 | 378 | ||
| 363 | - if($this->param['is_create']){ | 379 | + if ($this->param['is_create']) { |
| 364 | $task_model = new DomainCreateTask(); | 380 | $task_model = new DomainCreateTask(); |
| 365 | - $task_amp_info = $task_model->read(['type'=>DomainCreateTask::TYPE_CUSTOM,'domain_id'=>$id,'status'=>['<',DomainCreateTask::STATUS_SUC]]); | ||
| 366 | - if(!$task_amp_info){ | 381 | + $task_amp_info = $task_model->read(['type' => DomainCreateTask::TYPE_CUSTOM, 'domain_id' => $id, 'status' => ['<', DomainCreateTask::STATUS_SUC]]); |
| 382 | + if (!$task_amp_info) { | ||
| 367 | $task_model->add([ | 383 | $task_model->add([ |
| 368 | 'server_id' => $serversIpInfo['servers_id'], | 384 | 'server_id' => $serversIpInfo['servers_id'], |
| 369 | 'project_id' => $project_id, | 385 | 'project_id' => $project_id, |
-
请 注册 或 登录 后发表评论