作者 lyh
... ... @@ -11,7 +11,6 @@ use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
/**
... ... @@ -358,7 +357,7 @@ class HtmlCollect extends Command
continue;
}
$path_arr = explode('.', $vcs);
if (end($path_arr) == 'html') {
if (in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) {
continue;
}
... ...
... ... @@ -9,6 +9,7 @@ use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
... ... @@ -75,29 +76,8 @@ class HtmlLanguageCollect extends Command
$collect_info->status = CollectTask::STATUS_ING;
$collect_info->save();
//获取英文站域名
$domain = $collect_info->domain;
if (strpos($domain, '/') !== false) {
$domain = substr($domain, 0, strpos($domain, '/'));
} else {
$domain = str_replace($collect_info->language, 'www', $domain);
}
$web_url_domain = $domain;
$home_url = $domain;
$url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text';
$data_config = curl_c($url_web_config);
if ($data_config) {
$web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
if (isset($web_url_arr['host'])) {
$web_url_domain = $web_url_arr['host'];
}
$home_url_arr = parse_url($data_config['home_url'] ?? '');
if (isset($home_url_arr['host'])) {
$home_url = $home_url_arr['host'];
}
}
//获取站点正式和测试域名
$old_info = $this->getOldDomain($project_id, $collect_info->domain);
//采集html页面,下载资源到本地并替换
try {
... ... @@ -110,7 +90,15 @@ class HtmlLanguageCollect extends Command
return true;
}
$source_list = $this->html_preg($html, $project_id, $collect_info->domain, $web_url_domain, $home_url);
//如果有base64图片,先替换掉,再进行资源匹配
$new_html = $html;
preg_match_all("/data:([^;]*);base64,(.*)?\"/", $new_html, $result_img);
$img_base64 = $result_img[2] ?? [];
foreach ($img_base64 as $v64) {
$new_html = str_replace($v64, '', $new_html);
}
$source_list = $this->html_preg($new_html, $project_id, $collect_info->domain, $old_info['web_url_domain'], $old_info['home_url']);
if ($source_list) {
$html = $this->upload_source($html, $source_list, $project_id);
... ... @@ -162,9 +150,6 @@ class HtmlLanguageCollect extends Command
case 'blog':
$source = RouteMap::SOURCE_BLOG;
break;
case 'tag':
$source = RouteMap::SOURCE_PRODUCT_KEYWORD;
break;
default:
$source = RouteMap::SOURCE_PRODUCT;
break;
... ... @@ -197,6 +182,42 @@ class HtmlLanguageCollect extends Command
return $task_id;
}
//获取站点老域名
protected function getOldDomain($project_id, $domain)
{
$key = 'project_collect_lan_domain_' . $project_id;
$data = Cache::get($key);
if (!$data) {
$web_url_domain = $domain;
$home_url = $domain;
$url_web_config = 'https://' . $domain . '/wp-content/cache/user_config.text';
$data_config = curl_c($url_web_config);
if ($data_config) {
$web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
if (isset($web_url_arr['host'])) {
$web_url_domain = $web_url_arr['host'];
}
$home_url_arr = parse_url($data_config['home_url'] ?? '');
if (isset($home_url_arr['host'])) {
$home_url = $home_url_arr['host'];
}
}
$data = [
'web_url_domain' => $web_url_domain,
'home_url' => $home_url,
];
Cache::add($key, $data, 3600);//缓存1小时
}
return $data;
}
//正则匹配html资源
protected function html_preg($html, $project_id, $domain, $web_url_domain, $home_url)
{
... ... @@ -246,6 +267,13 @@ class HtmlLanguageCollect extends Command
$check_vc_b && $source[] = $check_vc_b;
}
//a标签下载资源
preg_match_all('/<a\s+[^>]*?href\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_a);
$down = $result_a[2] ?? [];
foreach ($down as $vd) {
$check_vd = $this->url_check($vd, $project_id, $domain, $web_url_domain, $home_url);
$check_vd && $source[] = $check_vd;
}
return $source;
}
... ... @@ -265,7 +293,7 @@ class HtmlLanguageCollect extends Command
(empty($host) || $host == $web_url_domain || $host == $home_url)
&& $path
&& (strpos($path, '.') !== false)
&& (end($path_arr) != 'html')
&& (!in_array(end($path_arr), ['html', 'php', 'com', 'xml']))
) {
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
if (!$source) {
... ... @@ -329,7 +357,7 @@ class HtmlLanguageCollect extends Command
continue;
}
$path_arr = explode('.', $vcs);
if(end($path_arr) == 'html'){
if(in_array(end($path_arr), ['html', 'php', 'com', 'xml'])){
continue;
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Bside\Inquiry;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Inquiry\InquiryLogic;
use App\Models\Inquiry\InquiryForm;
use App\Rules\Ids;
use App\Services\BatchExportService;
use Illuminate\Http\Request;
... ... @@ -20,9 +21,24 @@ use Illuminate\Support\Facades\Storage;
class InquiryController extends BaseController
{
public function form_list(){
$list = InquiryForm::where('is_default', 0)->get();
$data = $list->toArray();
foreach ($data as &$item){
$field_text = [];
foreach ($item['field'] as $v){
$field_text[$v] = InquiryForm::fieldMap($v);
}
$item['field_text'] = $field_text;
}
return $this->success($data);
}
public function index(InquiryLogic $logic)
{
if(($this->param['type']??'') == 'other'){
if(!empty($this->param['form_id'])){
$data = $logic->getFormDataList();
}elseif(($this->param['type']??'') == 'other'){
$data = $logic->getOtherList();
}else{
$data = $logic->getApiList();
... ... @@ -36,7 +52,10 @@ class InquiryController extends BaseController
],[
'id.required' => 'ID不能为空'
]);
if(($this->param['type']??'') == 'other'){
if(!empty($this->param['form_id'])){
$data = $logic->getFormDataInfo($this->param['id'], $this->param['form_id']);
}elseif(($this->param['type']??'') == 'other'){
$data = $logic->getOtherInfo($this->param['id']);
}else{
$data = $logic->getInfo($this->param['id']);
... ... @@ -52,7 +71,9 @@ class InquiryController extends BaseController
],[
'ids.required' => 'ID不能为空'
]);
if(($this->param['type']??'') == 'other'){
if(!empty($this->param['form_id'])){
$logic->deleteFormData($this->param['ids'], ['form_id' => $this->param['form_id']]);
}elseif(($this->param['type']??'') == 'other'){
$logic->deleteOther($this->param['ids']);
}else{
$logic->delete($this->param['ids']);
... ... @@ -71,13 +92,24 @@ class InquiryController extends BaseController
*/
public function export(InquiryLogic $logic)
{
if(($this->param['type']??'') == 'other'){
if(!empty($this->param['form_id'])){
$data = $logic->getFormDataList(true);
$field = InquiryForm::getField($this->param['form_id']);
$map = [
'submit_time' => '询盘发送时间',
];
foreach ($field as $v) {
$map[$v] = InquiryForm::fieldMap($v);
}
$map['ip_address'] = '访问国家/地区(IP)';
$map['refer'] = '发送页面';
}elseif(($this->param['type']??'') == 'other'){
$data = $logic->getOtherList(true);
$map = [
'submit_time' => '询盘发送时间',
'email' => '邮箱',
'ip_address' => '访问国家/地区(IP)',
'referer' => '发送页面',
'refer' => '发送页面',
];
}else{
$data = $logic->getApiList(true);
... ... @@ -95,6 +127,10 @@ class InquiryController extends BaseController
$data = $data['list'] ?? [];
foreach ($data as &$item){
$item['ip_address'] = "{$item['country']}({$item['ip']})";
if(!empty($this->param['form_id'])){
$item = array_merge($item, $item['data']);
}
}
//生成文件,发送到客户端
... ...
... ... @@ -8,8 +8,9 @@ use App\Helper\Translate;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryForm;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Inquiry\InquiryOther;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
/**
... ... @@ -68,7 +69,6 @@ class InquiryLogic extends BaseLogic
if($search){
$map['email'] = ['like','%'.$search.'%'];
}
ProjectServer::useProject($this->user['project_id']);
$data = (new InquiryOther())->lists($map,$page,$page_size,'id',
['id', 'email', 'ip', 'country', 'domain', DB::raw('referer as refer'), DB::raw('status as read_status'), 'submit_time']
... ... @@ -77,6 +77,27 @@ class InquiryLogic extends BaseLogic
return $this->success($data);
}
public function getFormDataList($export = false){
$page_size = $export ? 1000 : 20;
$search = $this->request['search'] ?: '';
$page = $this->request['page'] ?: 1;
$form_id = $this->request['form_id'] ?? '';
$field = InquiryForm::getField($form_id);
$map = [
'form_id' => $form_id
];
if($search){
foreach ($field as $v){
$map['data->' . $v] = $search;
}
}
$fields = ['id', 'data', 'ip', 'country', 'domain', DB::raw('referer as refer'), DB::raw('status as read_status'), DB::raw('submit_at as submit_time')];
$lists = InquiryFormData::select($fields)->orderBy('id')->paginate($page_size, ['*'], 'page', $page);
$data = $lists->toArray();
return $this->success($data);
}
public function getInfo($id)
{
$project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
... ... @@ -93,10 +114,22 @@ class InquiryLogic extends BaseLogic
return $this->success(['trans_message' => $trans_message]);
}
public function getFormDataInfo($id, $form_id){
//修改状态为已读
if($this->request['read_status']){
(new InquiryFormData())->edit(['status' => 1], ['id' => $id, 'form_id' => $form_id]);
}
//翻译
$trans_message = '';
if($this->request['message']){
$trans_message = Translate::tran($this->request['message'], 'zh');
}
return $this->success(['trans_message' => $trans_message]);
}
public function getOtherInfo($id){
//修改状态为已读
if($this->request['read_status']){
ProjectServer::useProject($this->user['project_id']);
(new InquiryOther())->edit(['status' => 1], ['id' => $id]);
}
return $this->success(['trans_message' => '']);
... ... @@ -120,11 +153,21 @@ class InquiryLogic extends BaseLogic
if(!$ids){
$this->fail('ID不能为空');
}
ProjectServer::useProject($this->user['project_id']);
(new InquiryOther())->del(['id'=>['in',$ids]]);
return $this->success();
}
public function deleteFormData($ids, $map = [])
{
$ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
if(!$ids){
$this->fail('ID不能为空');
}
$map['id'] = ['in',$ids];
(new InquiryFormData())->del($map);
return $this->success();
}
}
... ...
<?php
namespace App\Models\Inquiry;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Cache;
/**
* Class InquiryForm
* @package App\Models\Inquiry
* @author zbj
* @date 2023/12/5
*/
class InquiryForm extends Base
{
use SoftDeletes;
//设置关联表名
/**
* @var mixed
*/
protected $connection = "custom_mysql";
protected $table = 'gl_inquiry_form';
/**
* 预设字段名称
* @author zbj
* @date 2023/12/5
*/
public static function fieldMap($field = ''){
$map = [
'name' => '姓名',
'email' => '邮箱',
'phone' => '电话',
'mobile' => '电话',
'message' => '询盘内容',
'company' => '公司名称'
];
if($field){
return $map[$field] ?? $field;
}
return $map;
}
public function getFieldAttribute($value)
{
return json_decode($value, true);
}
/**
* @author zbj
* @date 2023/12/5
*/
public static function getField($form_id){
$cache_key = 'inquiry_form_field_' . $form_id;
$field = Cache::get($cache_key);
if(!$field){
$field = self::where('id', $form_id)->value('field');
$field && Cache::set($cache_key, $field, 3600);
}
return $field;
}
}
... ...
<?php
namespace App\Models\Inquiry;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class InquiryFormData
* @package App\Models\Inquiry
* @author zbj
* @date 2023/12/4
*/
class InquiryFormData extends Base
{
use SoftDeletes;
//设置关联表名
/**
* @var mixed
*/
protected $connection = "custom_mysql";
protected $table = 'gl_inquiry_form_data';
public function getDataAttribute($value)
{
return json_decode($value, true);
}
}
... ...
... ... @@ -83,9 +83,17 @@ class RouteMap extends Base
if(in_array($route, $fixed)){
return true;
}
$path = '';
if($source == self::SOURCE_NEWS){
$path = self::SOURCE_NEWS;
}elseif ($source == self::SOURCE_BLOG){
$path = self::SOURCE_BLOG.'s';
}
$where = [
'project_id' => $project_id,
'route' => $route,
'path' => $path,
];
$route = self::where($where)->first();
if($route){
... ...
... ... @@ -271,6 +271,7 @@ Route::middleware(['bloginauth'])->group(function () {
//精准询盘
Route::prefix('inquiry')->group(function () {
Route::get('/', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'index'])->name('inquiry');
Route::get('/form_list', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'form_list'])->name('inquiry_form_list');
Route::get('/info', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'info'])->name('inquiry_info');
Route::any('/delete', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'delete'])->name('inquiry_delete');
Route::any('/export', [\App\Http\Controllers\Bside\Inquiry\InquiryController::class, 'export'])->name('inquiry_export');
... ...