作者 赵彬吉

询盘 关联域名

... ... @@ -4,6 +4,7 @@ namespace App\Console\Commands\Sync;
use App\Exceptions\InquiryFilterException;
use App\Models\Inquiry\InquiryRelateDomain;
use App\Models\Project\Project;
use App\Models\SyncSubmitTask\SyncSubmitTask as SyncSubmitTaskModel;
use App\Services\SyncSubmitTaskService;
... ... @@ -53,10 +54,18 @@ class SyncSubmitTask extends Command
try {
$project = Project::getProjectByDomain($task_info['data']['domain'] ?? '');
if(!$project){
throw new \Exception('项目不存在');
//是否有关联的域名
$relate_domain = InquiryRelateDomain::where('from_domain', $task_info['data']['domain'] ?? '')->value('to_domain');
if(!$relate_domain){
throw new \Exception('项目不存在1');
}
$project = Project::getProjectByDomain($relate_domain);
if(!$project){
throw new \Exception('项目不存在2');
}
}
$task_info->project_id = $project->id;
SyncSubmitTaskService::handler($task_info);
SyncSubmitTaskService::handler($task_info, '', $relate_domain??'');
$task_info->status = 1;
$task_info->save();
... ...
... ... @@ -21,6 +21,8 @@ use Illuminate\Support\Facades\Cache;
class BaseController extends Controller
{
public $param;
public $request;
public function __construct(Request $request)
{
$this->request = $request;
... ...
... ... @@ -12,6 +12,7 @@ use App\Http\Logic\Bside\User\UserLoginLogic;
use App\Models\Ai\AiBlog;
use App\Models\Blog\Blog;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryRelateDomain;
use App\Models\News\News;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
... ... @@ -463,4 +464,31 @@ class PrivateController extends BaseController
$result = json_decode($json, true) ?: [];
return $this->success($result);
}
public function inquiry_relate_domain(Request $request){
$this->request->validate([
'from_domain' => 'required',
'to_domain' => 'required',
]);
$from_domain = trim($this->param['from_domain']);
$to_domain = trim($this->param['to_domain']);
$from_domain = parse_url($from_domain, PHP_URL_HOST) ?: $from_domain;
$to_domain = parse_url($to_domain, PHP_URL_HOST) ?: $to_domain;
$project = Project::getProjectByDomain($to_domain);
if (empty($project)) {
return $this->error('未找到被关联域名对应的项目!');
}
$relate = InquiryRelateDomain::where('from_domain', $from_domain)->first();
if(!$relate){
$relate = new InquiryRelateDomain();
}
$relate->from_domain = $from_domain;
$relate->to_domain = $to_domain;
$relate->save();
return $this->success($relate);
}
}
... ...
<?php
namespace App\Models\Inquiry;
use App\Models\Base;
/**
* Class InquiryRelateDomain
* @package App\Models\Inquiry
* @author zbj
* @date 2025/4/12
*/
class InquiryRelateDomain extends Base
{
//设置关联表名
protected $table = 'gl_inquiry_relate_domain';
}
... ...
... ... @@ -42,9 +42,23 @@ class SyncSubmitTaskService
* @author zbj
* @date 2023/11/28
*/
public static function handler($task, $date = '')
public static function handler($task, $date = '', $relate_domain = '')
{
$data = $task['data'];
//有关联域名 替换原数据url
if($relate_domain){
foreach ($data as $k=>&$item){
if($k == 'data'){
foreach ($item as &$v){
$v = str_replace($data['domain'], $relate_domain, $v);
}
}else{
$item = str_replace($data['domain'], $relate_domain, $item);
}
}
}
$checkIpCountry = self::checkIpCountry($data['domain'], $data['ip'], $task['type']);
$data['ip'] = $checkIpCountry['ip'];
... ...
... ... @@ -68,4 +68,7 @@ Route::post('selfSiteVerify', [\App\Http\Controllers\Api\SelfSiteController::cla
//创建301跳转任务
Route::any('/addRedirect',[\App\Http\Controllers\Api\NoticeController::class,'addRedirect']);
//关联域名
Route::post('/inquiry_relate_domain', [\App\Http\Controllers\Api\PrivateController::class, 'inquiry_relate_domain']);
... ...