作者 lyh

ggx

... ... @@ -511,3 +511,27 @@ if (!function_exists('getAutoLoginCode')) {
return $encrypt->authcode(json_encode(['project_id' => $project_id]), 'ENCODE', 'autologin', 3600);
}
}
if (!function_exists('str_replace_url')) {
/**
* @remark :截取域名以外的部分
* @name :str_replace_url
* @author :lyh
* @method :post
* @time :2023/8/31 14:57
*/
function str_replace_url($url)
{
// 使用 parse_url 函数来解析 URL
$urlParts = parse_url($url);
// 检查是否存在 host(域名)部分
if (isset($urlParts['host'])) {
$domain = $urlParts['host'];
// 使用 str_replace 函数删除域名信息
$urlWithoutDomain = str_replace($domain, '', $url);
return $urlWithoutDomain;
} else {
return $url;
}
}
}
... ...
... ... @@ -7,6 +7,7 @@ use App\Enums\Common\Common;
use App\Exceptions\BsideGlobalException;
use App\Http\Logic\Logic;
use App\Models\Com\UpdateNotify;
use App\Models\Project\Project;
use Illuminate\Support\Facades\Cache;
/**
... ... @@ -33,11 +34,32 @@ class BaseLogic extends Logic
$this->requestAll = $this->getParam();
$this->user = Cache::get(request()->header('token'));
if(!empty($this->user)){
$this->project = Cache::get('user-'.$this->user['project_id']);
$this->project = $this->getProjectInfo();
}
}
/**
* @remark :获取项目详情
* @name :getProjectInfo
* @author :lyh
* @method :post
* @time :2023/8/31 15:11
*/
public function getProjectInfo(){
$info = Cache::get('user-'.$this->user['project_id']);
if($info === false){
$projectModel = new Project();
$info = $projectModel->with('payment')->with('deploy_build')
->with('deploy_optimize')->with('online_check')->where(['id'=>$this->user['project_id']])->first();
if($info['extend_type'] != 0){
$info['type'] = $info['extend_type'];
}
Cache::add('user-'.$this->user['project_id'],$info);
}
return $this->success($info);
}
/**
* @remark :请求参数处理
* @name :getParam
* @author :lyh
... ...
... ... @@ -176,7 +176,7 @@ class UserLoginLogic
$info['domain'] = (!empty($project['deploy_optimize']['domain']) ?
$project['deploy_optimize']['domain'] : ($project['deploy_build']['test_domain'] ?? ''));
//保存项目缓存
Cache::put('user-'.$info['project_id'],$project,now()->addMinutes(60));
Cache::put('user-'.$info['project_id'],$project,$minutes = null);
return $this->success($info);
}
... ...
... ... @@ -205,7 +205,7 @@ class Project extends Base
{
$value = Arr::s2a($value);
foreach ($value as $k => $v){
$v = (int)$v;
$v = (string)$v;
$value[$k] = $v;
}
return $value;
... ... @@ -214,7 +214,7 @@ class Project extends Base
public function setNoticeFileAttribute($value)
{
foreach ($value as &$v) {
$v['url'] = basename($v['url']);
$v['url'] = str_replace_url($v['url']);
}
$this->attributes['notice_file'] = Arr::a2s($value);
}
... ... @@ -233,7 +233,7 @@ class Project extends Base
public function setConfirmFileAttribute($value)
{
foreach ($value as &$v) {
$v['url'] = basename($v['url']);
$v['url'] = str_replace_url($v['url']);
}
$this->attributes['confirm_file'] = Arr::a2s($value);
}
... ...