作者 赵彬吉
... ... @@ -89,9 +89,9 @@ class Count extends Command
DB::table('gl_count')->insert($data);
}
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . $v['test_domain'] . '->' . $e->getMessage() . PHP_EOL;
echo date('Y-m-d H:i:s') . ' error: ' . '->' . $e->getMessage() . PHP_EOL;
}
echo date('Y-m-d H:i:s') . ' end: ' . $v['test_domain'] . PHP_EOL;
echo date('Y-m-d H:i:s') . ' end: ' . PHP_EOL;
echo $this->error;
}
... ...
... ... @@ -16,8 +16,12 @@ use App\Models\Domain\DomainInfo;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BSettingTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\Setting;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
... ... @@ -51,7 +55,7 @@ class VideoTask extends Command
/**
* @var int 最大子任务
*/
public $max_sub_task = 800;
public $max_sub_task = 200;
/**
* @return bool
... ... @@ -97,6 +101,7 @@ class VideoTask extends Command
$task_project->save();
continue;
}
$logo_bg = $this->getImage($domainInfo);
foreach ($keyword as $val) {
$log = KeywordVideoTaskLog::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id])->first();
if ($log){
... ... @@ -109,7 +114,7 @@ class VideoTask extends Command
'keyword' => $val->title,
'data' => json_encode(['url' => $keywordInfo['url'],'title' => $keywordInfo['title'],
'description' => $keywordInfo['keyword_content'], 'images' => $keywordInfo['product_list'],
'keywords' => $keywordInfo['keyword_list']]),
'keywords' => $keywordInfo['keyword_list'], 'logo_bg' => $logo_bg]),
'status' => KeywordVideoTaskLog::STATUS_INIT,
'updated_at' => date('Y-m-d H:i:s'),
'created_at' => date('Y-m-d H:i:s'),
... ... @@ -130,10 +135,11 @@ class VideoTask extends Command
public function sendSubTask()
{
$subTask = KeywordVideoTaskLog::where(['status' => KeywordVideoTaskLog::STATUS_INIT])->orderBy('id', 'asc')->limit($this->max_sub_task)->get();
if ($subTask->isEmpty())
if ($subTask->isEmpty()){
return true;
}
foreach ($subTask as $val) {
$valData = (array)json_decode($val->data);
$valData = json_decode($val->data,true);
$task_id = 'v6-' . uniqid();
$data = [
'project_data' => [
... ... @@ -141,7 +147,9 @@ class VideoTask extends Command
'title' => $valData['title'],
'keywords' => $valData['keywords'],
'description' => $valData['description'],
'images' => $valData['images']
'images' => $valData['images'],
'logo'=> $valData['logo_bg']['logo'] ?? '',
'bg'=> $valData['logo_bg']['bg'] ?? ''
],
'task_id' => $task_id,
'callback_url' => env('APP_URL') . '/api/video_task_callback',
... ... @@ -163,7 +171,7 @@ class VideoTask extends Command
*/
public function getProjectKeyword($number)
{
$keyword_arr_id = Keyword::where('video', null)->whereNotNull('keyword_content')->pluck('id')->toArray();
$keyword_arr_id = Keyword::where('video', null)->where('title', 'not like', '%-tag%')->whereNotNull('keyword_content')->pluck('id')->toArray();
$keyword_id = array_rand($keyword_arr_id, $number);
$keyword = Keyword::whereIn("id", $keyword_id)->get();
return $keyword;
... ... @@ -181,23 +189,39 @@ class VideoTask extends Command
}
/**
* @remark :根据关键字获取产品主图
* @name :getKeywordList
* @author :lyh
* @method :post
* @time :2024/2/23 16:28
* 根据关键字获取产品主图
* @param $keyword_id
* @param $project_id
* @param $domain
* @return array
*/
public function getKeywordImage($keyword_id,$project_id,$domain){
$keywordModel = new Keyword();
$keywordInfo = $keywordModel->read(['id'=>$keyword_id]);
// TODO 当内容太多时,生成视频过长, 尽量保证生成视频30秒左右, 所以需要控制文案内容长度
$content = $keywordInfo['keyword_content'];
$content_array = explode(" ", $content);
if (count($content_array) > 80) {
$content_array = preg_split("/[,,。]/u", $content);
$tmp = '';
foreach ($content_array as $val) {
$tmp .= $val . '.';
$tmp_array = explode(' ', $tmp);
if (count($tmp_array) > 60) {
$content = $tmp;
break;
}
}
}
//TODO::所有产品
$thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
$keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();;
$keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();
$data = [
'url'=>$domain.'/'.$keywordInfo['route'],
'url'=> 'https://' . $domain.'/'.$keywordInfo['route'],
'title'=>$keywordInfo['title'],
'keyword_title'=>$keywordInfo['keyword_title'],
'keyword_content'=>$keywordInfo['keyword_content'],
'keyword_content'=>$content,
'product_list'=>$thumb ?? [],
'keyword_list'=>$keyword_arr ?? []
];
... ... @@ -220,17 +244,24 @@ class VideoTask extends Command
if (count($productIds)<7){
$product_all_id = Product::where("project_id", $project_id)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
$number = 40;
$product_id = array_rand($product_all_id, min(count($product_all_id, $number-count($productIds))));
$randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
$products = $productsQuery->merge($randomData);
$array_count = count($product_all_id);
if ($array_count > 0) {
$product_id = array_rand($product_all_id, min($array_count, $number - count($productIds)));
$randomData = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
$products = $productsQuery->merge($randomData);
}
}else{
$products = $productsQuery;
}
}else{
$product_all_id = Product::where("project_id", $project_id)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
$number = 40;
$product_id = array_rand($product_all_id, min(count($product_all_id, $number-count($productIds))));
$products = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
$array_count = count($product_all_id);
if ($array_count > 0)
{
$product_id = array_rand($product_all_id, min($array_count, $number-count($productIds)));
$products = Product::where("project_id", $project_id)->whereIn("id", $product_id)->get();
}
}
}
$data = [];
... ... @@ -242,10 +273,11 @@ class VideoTask extends Command
if(count($data) > 13){
break;
}
if (strpos($item->keyword_id, ','.$productKeyword->id.',') === false) {
$keyword_id = implode(',',$item->keyword_id);
if (strpos(','.$keyword_id.',', ','.$productKeyword->id.',') === false) {
//不包含
$productModel = new Product();
$keyword_id = $item->keyword_id . $productKeyword->id.',';
$keyword_id = $keyword_id . $productKeyword->id.',';
$productModel->edit(['keyword_id'=>$keyword_id],['id'=>$item->id]);
}
$data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title];
... ... @@ -254,4 +286,37 @@ class VideoTask extends Command
return $data;
}
/**
* 获取图片
* @param $domainInfo
* @return array
*/
public function getImage($domainInfo){
$logo = $bg = '';
try {
$dom = file_get_html('https://'.$domainInfo['domain'].'/');
$logoDom = $dom->find('.logo', 0)->find("img",0);
if($logoDom != null){
$logo = $logoDom->src;
}
$elements = $dom->find('.section-banner-wrap-block');
if (count($elements) >= 2) {
foreach ($elements as $v){
$image = $v->find('img', 0);
if($image != null){
break;
}
}
} else {
$image = $elements->find('img', 0);
}
if($image != null){
$bg = $image->src;
}
$dom->clear();
} catch (\Exception $e) {
Log::error('file_get_html: ' . $domainInfo['domain'] . ', error message: ' . $e->getMessage());
}
return ['logo' => $logo, 'bg' => $bg];
}
}
... ...
... ... @@ -265,7 +265,37 @@ class Demo extends Command
// print_r($include);
// }
public function handle(){
echo '加密字符串:'.md5('company_list+2024-03-05+prod_desc=led&total=10');
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['project_id'=>45]);
if($domainInfo === false){
dd('11111');
}
$bg = '';
$logo = '';
$dom = file_get_html('https://'.$domainInfo['domain'].'/');
$logoDom = $dom->find('.logo', 0)->find("img",0);
if($logoDom != null){
$logo = $logoDom->src;
}
$elements = $dom->find('.section-banner-wrap-block');
if (count($elements) >= 2) {
foreach ($elements as $v){
$image = $v->find('img', 0);
if($image != null){
break;
}
}
} else {
$image = $elements->find('img', 0);
}
if($image != null){
$bg = $image->src;
}
if($image != null){
$bg = $image->src;
}
// return $logo;
dd(['logo'=>$logo ?? '','bg'=>$bg ?? '']);
// $projectModel = new Project();
// $list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]);
// foreach ($list as $v1){
... ...
... ... @@ -665,23 +665,24 @@ class ProjectUpdate extends Command
foreach ($item['extend'] as $ke => $ve) {
$extend = $extend_model->read(['title' => $ke]);
if ($extend) {
$extend_info = $extend_info_model->read(['key' => $extend['key'], 'content_id' => $id]);
if (!$extend_info) {
if ($extend['type'] == 3) {
$gallery = [];
if (is_array($ve)) {
foreach ($ve as $ve_img) {
$gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve_img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
}
} else {
$gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
if ($extend['type'] == 3) {
$gallery = [];
if (is_array($ve)) {
foreach ($ve as $ve_img) {
$gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve_img, $project_id, $domain_arr['host'], $web_url_domain, $home_url, 1)];
}
$value = Arr::a2s($gallery);
} elseif ($extend['type'] == 4) {
$value = Arr::a2s([$this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url)]);
} else {
$value = $ve;
$gallery[] = ['title' => '', 'description' => '', 'url' => $this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url, 1)];
}
$value = Arr::a2s($gallery);
} elseif ($extend['type'] == 4) {
$value = Arr::a2s([$this->source_download($ve, $project_id, $domain_arr['host'], $web_url_domain, $home_url, 1)]);
} else {
$value = $ve;
}
$extend_info = $extend_info_model->read(['key' => $extend['key'], 'content_id' => $id]);
if (!$extend_info) {
$extend_info_model->add([
'key' => $extend['key'],
'type' => $extend['type'],
... ... @@ -690,6 +691,8 @@ class ProjectUpdate extends Command
'module_id' => $custom_info['id'],
'values' => $value,
]);
} else {
$extend_info_model->edit(['type' => $extend['type'], 'values' => $value], ['key' => $extend['key'], 'content_id' => $id]);
}
}
}
... ... @@ -939,7 +942,7 @@ class ProjectUpdate extends Command
}
//资源下载
protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url)
protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url, $same_name = 0)
{
if (!$url) {
return '';
... ... @@ -961,7 +964,7 @@ class ProjectUpdate extends Command
$path = '/' . $path;
}
$url_complete = ($scheme ?: 'https') . '://' . $domain . $path;
$new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
$new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete, '', '', $same_name);
if ($new_url) {
CollectSource::insert([
... ...
... ... @@ -25,7 +25,7 @@ class Kernel extends ConsoleKernel
$schedule->command('rank_data_recomm_domain')->dailyAt('01:40')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次
$schedule->command('rank_data_week')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次
// $schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次
$schedule->command('count')->dailyAt('01:30')->withoutOverlapping(1); //每天凌晨1点执行一次
// $schedule->command('count')->dailyAt('00:30')->withoutOverlapping(1); //每天凌晨1点执行一次
$schedule->command('service_count')->dailyAt('01:00')->withoutOverlapping(1); //服务器使用情况,每天凌晨1点执行一次
$schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
$schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次
... ... @@ -34,7 +34,7 @@ class Kernel extends ConsoleKernel
$schedule->command('web_traffic_russia 2')->cron('*/18 * * * *'); // 俄语站引流 4-8个月的项目,18分钟一次
$schedule->command('web_traffic_russia 3')->cron('*/12 * * * *'); // 俄语站引流 大于9个月的项目,12分钟一次
$schedule->command('sync_channel')->dailyAt('06:00')->withoutOverlapping(1); // 渠道信息,每天执行一次
$schedule->command('month_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计记录
// $schedule->command('month_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计记录
$schedule->command('forward_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计转发询盘记录
$schedule->command('inquiry_delay')->everyMinute()->withoutOverlapping(1);//TODO::上线放开,转发询盘,每分钟执行一次
$schedule->command('inquiry_count')->dailyAt('01:00')->withoutOverlapping(1); // 询盘统计数据,每天凌晨执行一次
... ... @@ -46,12 +46,11 @@ class Kernel extends ConsoleKernel
// $schedule->command('project_file_pdf')->dailyAt('00:00')->withoutOverlapping(1); // 网站项目数据,生成PDF文件
$schedule->command('sync_manager')->dailyAt('01:00')->withoutOverlapping(1); //TODO::手机号码同步 每天执行一次
$schedule->command('recommended_suppliers')->dailyAt('01:00')->withoutOverlapping(1); //每天凌晨1点执行一次生成推荐商
$schedule->command('notice_c')->dailyAt('02:00')->withoutOverlapping(1); //每天凌晨1点执行一次生成推荐商
$schedule->command('recommended_suppliers')->dailyAt('03:00')->withoutOverlapping(1); //每天凌晨1点执行一次生成推荐商
// 每日推送视频任务
$schedule->command('video_task')->dailyAt('01:30')->withoutOverlapping(1);
$schedule->command('video_task')->dailyAt('03:30')->withoutOverlapping(1);
// 每日推送已完成视频任务项目生成对应界面
$schedule->command('notice_c')->dailyAt('02:00')->withoutOverlapping(1);
$schedule->command('notice_c')->dailyAt('04:00')->withoutOverlapping(1);
}
/**
... ...
... ... @@ -16,6 +16,7 @@ use App\Models\RouteMap\RouteMap;
use App\Models\User\User;
use App\Services\ProjectServer;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
* Class PrivateController
... ... @@ -127,4 +128,18 @@ class PrivateController extends BaseController
return $this->success($result);
}
/**
* v6 有效用户
* @param Request $request
* @return false|string
*/
public function validUser(Request $request)
{
// 排除演示项目数据
$valid_user = User::select(['gl_project_user.mobile'])->leftJoin('gl_project', 'gl_project.id', '=', 'gl_project_user.project_id')->where(['delete_status' => 0, 'is_upgrade' => Project::IS_UPGRADE_FALSE])->where('gl_project.id', '>', 1)->pluck('mobile')->toArray();
$upgrade_user = User::select(['gl_project_user.mobile'])->leftJoin('gl_project', 'gl_project.id', '=', 'gl_project_user.project_id')->where(['delete_status' => 0, 'is_upgrade' => Project::IS_UPGRADE_TRUE])->where('gl_project.type', '>', Project::TYPE_ONE)->pluck('mobile')->toArray();
$user = array_unique(array_merge($valid_user, $upgrade_user));
return $this->success($user);
}
}
\ No newline at end of file
... ...
... ... @@ -29,7 +29,7 @@ class KeywordsController extends BaseController
->orWhere('main_keywords', 'like' , '%'.$this->map['search'].'%')->pluck('project_id')->toArray();
$projectModel = new Project();
$lists = $projectModel->formatQuery(['id'=>['in',$ids]])->with('payment')->with('deploy_build')
->with('deploy_optimize')->get()->toArray();
->with('deploy_optimize')->with('domainInfo')->get()->toArray();
$this->response('success',Code::SUCCESS,$lists);
}
}
... ...
... ... @@ -114,6 +114,7 @@ class ProjectController extends BaseController
'gl_project_deploy_optimize.quality_mid AS quality_mid',
'gl_project_deploy_optimize.design_mid AS design_mid',
'gl_project_deploy_optimize.api_no AS api_no',
'gl_project_deploy_optimize.brand_keyword AS brand_keyword',
];
return $select;
}
... ... @@ -264,8 +265,8 @@ class ProjectController extends BaseController
if(isset($this->map['tech_mid'])){
$query = $query->where('gl_project_deploy_optimize.tech_mid',$this->map['tech_mid']);
}
if(isset($this->map['optimist_mid'])){
$query = $query->where('gl_project_deploy_optimize.optimist_mid',$this->map['optimist_mid']);
if(isset($this->map['optimize_optimist_mid'])){
$query = $query->where('gl_project_deploy_optimize.optimist_mid',$this->map['optimize_optimist_mid']);
}
return $query;
}
... ...
... ... @@ -18,6 +18,7 @@ use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\WebSetting\WebLanguage;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
/**
... ... @@ -169,7 +170,9 @@ class CNoticeController extends BaseController
$ids = explode(',',$info['country_lists']);
}
$languageModel = new WebLanguage();
$lists = $languageModel->list(['id'=>['in',$ids]]);
//根据排序查询选中的小语种
$lists = $languageModel->whereIn('id', $ids)->orderByRaw(DB::raw("FIND_IN_SET(id,'" . implode(',', $ids) . "'" . ')'))->get()->toArray();
// $lists = $languageModel->list(['id'=>['in',$ids]]);
$this->response('success',Code::SUCCESS,$lists);
}
... ...
... ... @@ -30,6 +30,7 @@ class ProjectKeywordController extends BaseController
}
$data['search_keywords'] = $info['search_keywords'];
$data['customer_keywords'] = $info['customer_keywords'];
$data['brand_keyword'] = $info['brand_keyword'];
$this->response('success',Code::SUCCESS,$data);
}
... ...
... ... @@ -235,9 +235,15 @@ class LoginController extends BaseController
* @time :2023/8/24 17:37
*/
public function globalSo_v6_login(UserLoginLogic $logic){
$common = new Common();
$arr = $common->decrypt(urldecode($this->param['token']));
if(empty($arr)){
$this->param = $this->request->validate([
'token' => 'required',
],[
'token.required' => 'token不能为空',
]);
try {
$common = new Common();
$arr = $common->decrypt(urldecode($this->param['token']));
}catch (\Exception $e){
$this->response('非法请求!',Code::USER_ERROR);
}
if (empty($arr['timestamp']) || time() - $arr['timestamp'] > 60) {
... ...
... ... @@ -410,7 +410,7 @@ class DomainInfoLogic extends BaseLogic
//创建站点,设置证书
$this->param['key'] = $this->param['private_key'] ?? '';
$this->param['cert'] = $this->param['private_cert'] ?? '';
$this->setDomainSsl($server_info['init_domain'],$this->param['custom_domain'],[],[],0);
$this->setDomainSsl($server_info['init_domain'],$this->param['custom_domain'],[],[],1);
}
return $this->success();
... ...
... ... @@ -778,7 +778,7 @@ class ProjectLogic extends BaseLogic
$token = $common->encrypt($param);
$res = Http::withoutVerifying()->get($url, ['token' => $token])->json();
if(empty($res['code']) || $res['code'] != 200){
$this->fail('ProjectToHagro error');
$this->fail($res['msg']);
}
return true;
}
... ...
... ... @@ -123,7 +123,8 @@ class NavLogic extends BaseLogic
'remark'=>$param['remark'] ?? '',
'group_id'=>$param['group_id'],
'show'=>$param['show'] ?? 0,
'class'=>$param['class'] ?? ''
'class'=>$param['class'] ?? '',
'rel'=>$param['rel'] ?? '',
];
return $this->success($data);
}
... ...
... ... @@ -34,7 +34,7 @@ class TranslateLogic extends BaseLogic
if($this->param['url'] == 'All'){
$info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
if(!empty($info) && !empty($info['data'])){
$translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE);
$translateInfo = json_decode($info['data']);
foreach ($translateInfo as $k => $v){
$data[] = [$k=>$v];
}
... ... @@ -47,22 +47,18 @@ class TranslateLogic extends BaseLogic
$languageInfo = $this->getLanguage($this->param['language_id']);
// 原始校对内容
$info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
//获取当前URl的所有文本内容
$text_array = $this->getUrlRead($url);
// 原始校对程序
$old_key = [];//key值组成数据
if($info !== false){
$data_read = json_decode($info['data'],JSON_UNESCAPED_UNICODE);
$data_read = json_decode($info['data']);
foreach ($data_read as $k => $v){
$old_key[] = $k;
$data[] = [$k => $v];
}
}
$arr2 = array_values(array_diff($text_array, $old_key));
if(!empty($arr2)){
return $this->success($data);
}else{
//获取当前URl的所有文本内容
$text_array = $this->getUrlRead($url);
$i = 0;
TranslateText:
$translate_list = Translate::tran($arr2, $languageInfo['short']);
$translate_list = Translate::tran($text_array, $languageInfo['short']);
if(empty($translate_list)){
if ($i < 3) {
$i++;
... ... @@ -70,43 +66,57 @@ class TranslateLogic extends BaseLogic
}
$this->fail('翻译失败,请稍后重试!');
}
if(count($arr2) == 1){
if(count($text_array) == 1){
$data[] = [
$arr2[0]=>$translate_list
$text_array[0]=>$translate_list
];
}else{
foreach ($arr2 as $k => $v){
foreach ($text_array as $k => $v){
$data[] = [
trim($v)=>$translate_list[$k]
$v=>$translate_list[$k]
];
}
}
return $this->success($data);
}
$data = $this->unique_multidimensional_array($data);
return $this->success($data);
}
/**
* @remark :多维数组去重
* @name :unique_multidimensional_array
* @author :lyh
* @method :post
* @time :2024/3/8 16:38
*/
public function unique_multidimensional_array($array) {
$tempArray = [];
$uniqueArray = [];
foreach ($array as $value) {
// 使用键作为临时数组的键,如果不存在则添加到去重后的数组中
$key = key($value);
if (!isset($tempArray[$key])) {
$tempArray[$key] = true;
$uniqueArray[] = $value;
}
}
return $uniqueArray;
}
// $old_key = [];//key值组成数据
// if($info !== false){
// $data_read = json_decode($info['data']);
// foreach ($data_read as $k => $v){
//// if(!in_array($k,$text_array)){
//// $arr2[] = $k;
//// }
//// $old_key[] = $k;
// $data[] = [$k => $v];
// }
// }else{
// $arr2 = array_values(array_diff($text_array, $old_key));
// }
// if(!empty($arr2)){
// $i = 0;
// TranslateText:
// $translate_list = Translate::tran($arr2, $languageInfo['short']);
// if(empty($translate_list)){
// if ($i < 3) {
// $i++;
// goto TranslateText;
// }
// $this->fail('翻译失败,请稍后重试!');
// }
// if(count($arr2) == 1){
// $data[] = [
// $arr2[0]=>$translate_list
// ];
// }else{
// foreach ($arr2 as $k => $v){
// $data[] = [
// $v=>$translate_list[$k]
// ];
// }
// }
// }
/**
* @remark :获取图片列表
... ... @@ -120,7 +130,7 @@ class TranslateLogic extends BaseLogic
$info = $this->model->read(['url'=>$this->param['url'],'language_id'=>$this->param['language_id'],'type'=>$this->param['type']]);
$data = [];
if(!empty($info) && !empty($info['data'])){
$translateInfo = json_decode($info['data'],JSON_UNESCAPED_UNICODE);
$translateInfo = json_decode($info['data']);
foreach ($translateInfo as $k => $v){
$data[] = [$k=>$v];
}
... ... @@ -141,7 +151,7 @@ class TranslateLogic extends BaseLogic
}
$new_list = $this->getUrlImageRead($url);
$old_list = [];
$data_read = json_decode($info['data'],JSON_UNESCAPED_UNICODE);
$data_read = json_decode($info['data']);
foreach ($data_read as $k=>$v){
$old_list[] = $k;
$data[] = [
... ... @@ -203,7 +213,9 @@ class TranslateLogic extends BaseLogic
if(FALSE !== strpos($country_class, 'country-flag')) {
continue;
}
$need_tran[] = htmlspecialchars_decode(html_entity_decode($string));
if(!in_array(htmlspecialchars_decode(html_entity_decode($string)),$need_tran)){
$need_tran[] = htmlspecialchars_decode(html_entity_decode($string));
}
}
$need_tran[] = $description ? $description->attr['content'] : '';
$need_tran[] = $keywords ? $keywords->attr['content'] : '';
... ... @@ -270,10 +282,10 @@ class TranslateLogic extends BaseLogic
'language_id'=>$this->param['language_id'],
'alias'=>$this->param['alias'],
];
$param['data'] = json_encode($data,JSON_UNESCAPED_UNICODE);
$param['data'] = json_encode($data);
$this->model->add($param);
}else{
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
$data = json_encode($data);
$this->model->edit(['data'=>$data],['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]);
}
}catch (\Exception $e){
... ...
... ... @@ -29,7 +29,7 @@ class WebSettingAmpLogic extends BaseLogic
}
//log图处理
$info['top_logo'] = Arr::s2a($info['top_logo']);
if(!empty($info['top_logo'])){
if (!empty($info['top_logo'])) {
$info['top_logo']['url'] = getImageUrl($info['top_logo']['url'], $this->user['storage_type'], $this->user['project_location']);
}
//banner处理
... ... @@ -39,6 +39,13 @@ class WebSettingAmpLogic extends BaseLogic
$v['url'] = getImageUrl($v['url'], $this->user['storage_type'], $this->user['project_location']);
}
}
//公司主图处理
$info['company_image'] = Arr::s2a($info['company_image']);
if (!empty($info['company_image'])) {
$info['company_image']['url'] = getImageUrl($info['company_image']['url'], $this->user['storage_type'], $this->user['project_location']);
}
//icon处理
$info['web_icon'] = getImageUrl($info['web_icon']);
return $this->success($info);
}
... ... @@ -65,6 +72,13 @@ class WebSettingAmpLogic extends BaseLogic
}
}
$this->param['index_banner'] = Arr::a2s($index_banner);
//公司主图处理
if (isset($this->param['company_image']) && $this->param['company_image']) {
$this->param['company_image']['url'] = str_replace_url($this->param['company_image']['url'] ?? '');
}
$this->param['company_image'] = Arr::a2s($this->param['company_image'] ?? []);
//icon处理
$this->param['web_icon'] = str_replace_url($this->param['web_icon'] ?? '');
$info = $this->model->read(['project_id' => $this->user['project_id']]);
if ($info === false) {
... ...
... ... @@ -227,9 +227,10 @@ class Project extends Base
*/
public function domainInfo()
{
return self::hasOne(\App\Models\Domain\DomainInfo::class, 'project_id', 'project_id')->select('project_id', 'domain');;
return self::hasOne(\App\Models\Domain\DomainInfo::class, 'project_id', 'id')->select('project_id', 'domain');
}
public function setLevelAttribute($value)
{
$this->attributes['level'] = Arr::arrToSet($value);
... ...
... ... @@ -72,17 +72,24 @@ class CosService
* @param $file_url
* @param $key
* @param $body_str
* @param int $same_name 是否保持名称一直
* @return string
* @author Akun
* @date 2023/09/21 9:39
*/
public static function uploadRemote($project_id,$image_type,$file_url,$key='',$body_str='')
public static function uploadRemote($project_id,$image_type,$file_url,$key='',$body_str='',$same_name=0)
{
if(!$key){
$url_arr = parse_url($file_url);
$ext = explode('.',$url_arr['path']);
$filename = uniqid().rand(10000,99999).'.'.end($ext);
if($same_name){
$path_arr = explode('/',$url_arr['path']);
$filename = end($path_arr);
}else{
$ext = explode('.',$url_arr['path']);
$filename = uniqid().rand(10000,99999).'.'.end($ext);
}
$uploads = config('upload.default_file');
$path = $uploads['path_b'].'/'.$project_id.'/'.$image_type.'/'.date('Y-m');
... ...
... ... @@ -5,7 +5,11 @@
* Date: 2024/2/19
* Time: 15:46
*/
namespace App\Services;
namespace App\Services\Html;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Services\TdkService;
class CreateHtmlService
{
... ... @@ -15,40 +19,51 @@ class CreateHtmlService
* 返回最终需要的HTML
* @return string
*/
public function getHtml($project, $route, $lang = [], $page = 0)
public function getHtml($project_id, $route, $lang = [], $page = 0)
{
// 获取页面信息
$page_info = $this->getInfoByRoute($route);
// 根据项目和路由信息返回的结果确定当前页面使用5.0还是6.0的页面;
if ($project && $page_info) {
$html = $this->getHtmlV6($page_info['master_lang'], $lang = [], $page = 0);
} else {
$html = $this->getHtmlV5();
$projectModel = new Project();
$projectInfo = $projectModel->with(['payment', 'deploy_build'])->where(['id'=>$project_id])->first()->toArray();
$routeMapModel = new RouteMap();
$routeInfo = $routeMapModel->read(['route'=>$route]);
if($routeInfo === false){
if($route == 'top-search' || $route == 'products' || $route == 'news' || $route == 'blog'){
$html = '';
}else{
$html = '';
}
}else{
//TODO::5.0,6.0获取html,自定义页面还需要单独处理
if(($routeInfo['source'] == RouteMap::SOURCE_PAGE) && ($route != 'index')){
$customTemplateService = new CustomTemplateService();
$data = $customTemplateService->getHtml($projectInfo,$routeInfo['source_id']);
if($data === false){
return false;
}
$html = $data['html'];
}else{
$generatePageService = new GeneratePageService();
$data = $generatePageService->generateHtml($projectInfo,$routeInfo);
if($data === false){
return false;
}
$html = $data['html'];
}
}
return $html;
}
/**
* 返回5.0页面最终HTML
* @return string
*/
public function getHtmlV5()
{
$html = '';
return $html;
//处理页面tdk
$tdkService = new TdkService();
$html = $tdkService->pageTdkHandle($projectInfo,$html,$routeInfo['source'],$routeInfo);
return ['html'=>$html];
}
/**
* 返回6.0页面最终HTML
* @return mixed
*/
public function getHtmlV6($master_lang, $lang = [], $page = 0)
public function getHtmlV6($project_id,$route)
{
// 初始化后续需要渲染页面需要的数据 路由、主语种、tdk、嵌入等信息
$origin_html = $this->originHtml();
$html = $this->renderData($origin_html, $page);
$origin_html = $this->originHtml($project_id,$route);
$html = $this->renderData($origin_html);
$html = $this->plugHead($html);
$html = $this->processFinal($html);
/** ... 调用其他方法, 直至返回完整的正确的HTML */
... ... @@ -62,18 +77,26 @@ class CreateHtmlService
*/
public function getInfoByRoute($route)
{
$routeMapModel = new RouteMap();
$routeInfo = $routeMapModel->read(['route'=>$route]);
if($routeInfo === false){
if($route == 'top-search' || $route == 'products' || $route == 'news' || $route == 'blog'){
$routeInfo = $route;
}else{
$routeInfo = [];
}
}
// TODO 获取详情需要通过路由查下路由信息, 以及数据信息, 要处理特殊几个路由: top-search、products、news、blog, 这几个如果存在就用查下的信息, 如果不存在要初始化信息
return [];
return $routeInfo;
}
/**
* 获取可视化HTML
* @return string
*/
public function originHtml()
public function originHtml($project_id,$route)
{
$html = '根据路由查询数据库,并拼装HTML';
return $html;
}
/**
... ... @@ -113,4 +136,4 @@ class CreateHtmlService
*/
return $html;
}
}
\ No newline at end of file
}
... ...
<?php
/**
* @remark :
* @name :CustomTemplateService.php
* @author :lyh
* @method :post
* @time :2024/3/11 16:15
*/
namespace App\Services\Html;
use App\Models\Project\PageSetting;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\Setting;
class CustomTemplateService
{
/**
* @remark :获取当前自定义界面详情
* @name :customTemplateInfo
* @author :lyh
* @method :post
* @time :2023/6/29 16:23
*/
public function getHtml($projectInfo,$custom_id){
$info = $this->model->read(['id'=>$custom_id]);
if($info === false){
return false;
}
if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
$html = $this->getBodyHeaderFooter($projectInfo,$info['html'],$info['html_style']);
$info['html'] = $this->getHeadFooter($html);
}
return ['html'=>$info['html']];
}
/**
* @remark :获取body的详情
* @name :getBodyHeaderFooter
* @author :lyh
* @method :post
* @time :2023/7/21 18:08
*/
public function getBodyHeaderFooter($projectInfo,$preg_html,$html_style){
if(empty($preg_html)){
$preg_html = "<main></main>";
$html_style = "<style id='globalsojs-styles'></style>";
}
//获取设置的默认模版
$bSettingModel = new Setting();
$info = $bSettingModel->read(['project_id'=>$projectInfo['id']]);
if($info === false){
return false;
}
//获取type类型
$commonInfo = $this->getCommonPage($projectInfo,$info['template_id']);
$html = $commonInfo['head_css'].$html_style.$commonInfo['footer_css'].$commonInfo['other'].
$commonInfo['head_html'].$preg_html.$commonInfo['footer_html'];
return ['html'=>$html];
}
/**
* @remark :根据类型获取公共头和底
* @name :getCommonPage
* @author :lyh
* @method :post
*/
public function getCommonPage($projectInfo,$template_id){
$is_head = $projectInfo['deploy_build']['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if(isset($is_head) && ($is_head != 0)) {
//查看页面是否设置自定义头部底部
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $projectInfo['id']]);
if ($pageInfo !== false) {
$commonTemplateModel = new BTemplateCommon();
if ($pageInfo['page_list'] != 0) {
//使用独立头和底
$commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $projectInfo['id'], 'type' => 9]);
}
}
}
if(!isset($commonInfo) || $commonInfo === false){
//获取首页公共的头部和底部
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read(['template_id'=>$template_id,'project_id'=>$projectInfo['id'],'type'=>1]);
}
return $commonInfo;
}
/**
* @remark :拼接获取公共头部底部
* @name :getHeadFooter
* @author :lyh
* @method :post
*/
public function getHeadFooter($html = ''){
//获取公共主题头部底部
$serviceSettingModel = new ServiceSettingModel();
$list = $serviceSettingModel->list(['type'=>2],'created_at');
//拼接html
foreach ($list as $v){
if($v['key'] == 'head'){
$html = $v['values'].$html;
}
if($v['key'] == 'footer'){
$html = $html.$v['values'];
}
}
return $html;
}
}
... ...
... ... @@ -7,19 +7,20 @@
* @time :2024/2/19 15:54
*/
namespace App\Services;
namespace App\Services\Html;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\Project\PageSetting;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\BTemplateMain;
use App\Models\Template\Setting;
use App\Models\Template\Template;
use App\Models\Template\TemplateTypeMain;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class GeneratePageService
... ... @@ -27,13 +28,8 @@ class GeneratePageService
protected $route;
protected $param;
protected $project_id = 0;
public function __construct(){
$this->param = request()->all();
$this->route = $this->param['route'];
$this->project_id = $this->param['project_id'];
}
/**
* @remark :生成单页数据
... ... @@ -42,18 +38,14 @@ class GeneratePageService
* @method :post
* @time :2024/2/19 16:57
*/
public function generateHtml(){
public function generateHtml($projectInfo,$routeInfo){
$this->project_id = $projectInfo['id'];
$this->route = $routeInfo['route'];
ProjectServer::useProject($this->project_id);
$routeMapModel = new RouteMap();
$routeInfo = $routeMapModel->read(['route'=>$this->param['route']]);
if($this->param['route'] != RouteMap::SOURCE_INDEX && $routeInfo['source'] == RouteMap::SOURCE_PAGE){
//页面管理单独处理
}else{
$this->handleParam($routeInfo);
$this->getTemplateHtml();
}
$this->handleParam($routeInfo);
$result = $this->getTemplateHtml($projectInfo);
DB::disconnect('custom_mysql');
return true;
return $this->success($result);
}
/**
... ... @@ -129,14 +121,17 @@ class GeneratePageService
* @author :lyh
* @method :post
*/
public function getTemplateHtml(){
public function getTemplateHtml($projectInfo){
$is_custom = $this->param['is_custom'] ?? 0;//是否为扩展模块
$is_list = $this->param['is_list'] ?? 0;//是否为列表页
$template_id = $this->getSettingTemplate($this->param['source'],$is_list,$is_custom);//设置的模版id
$template_id = $this->getSettingTemplate($projectInfo,$this->param['source'],$is_list,$is_custom);//设置的模版id
if($template_id === false){
return false;
}
$templateInfo = $this->webTemplateInfo($this->param['source'],$this->param['source_id'],$template_id,$is_custom,$is_list);
if($templateInfo === false){
if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION){//处理定制页面初始数据
$html = $this->customizedReturnHtml($this->param['source'],$template_id,$is_custom,$is_list);
if($projectInfo['is_customized'] == BTemplate::IS_VISUALIZATION){//处理定制页面初始数据
$html = $this->customizedReturnHtml($projectInfo,$this->param['source'],$template_id,$is_custom,$is_list);
if($html !== false){
return $this->success($html);
}
... ... @@ -149,10 +144,10 @@ class GeneratePageService
}
$mainInfo = ['main_html'=>$templateInfo['main_html'], 'main_css'=>$templateInfo['main_css']];
}
$commonInfo = $this->getCommonHtml($this->param['source'],$is_list,$template_id,$is_custom);//获取非定制头部
$commonInfo = $this->getCommonHtml($projectInfo,$this->param['source'],$is_list,$template_id,$is_custom);//获取非定制头部
$html = $commonInfo['head_css'].$mainInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other']. $commonInfo['head_html'].$mainInfo['main_html'].$commonInfo['footer_html'];
$html = $this->getHeadFooter($html);
$result = ['html'=>$html,'template_id'=>$template_id];
$result = ['html'=>$html];
return $this->success($result);
}
... ... @@ -185,7 +180,7 @@ class GeneratePageService
public function webTemplateInfo($source,$source_id,$template_id,$is_custom,$is_list){
$templateInfo = $this->model->read([
'template_id'=>$template_id, 'source'=>$source,
'project_id'=>$this->user['project_id'], 'source_id'=>$source_id,
'project_id'=>$this->project_id, 'source_id'=>$source_id,
'is_custom'=>$is_custom, 'is_list'=>$is_list
]);
return $this->success($templateInfo);
... ... @@ -198,29 +193,35 @@ class GeneratePageService
* @method :post
* @time :2024/1/10 13:46
*/
public function customizedReturnHtml($source,$template_id,$is_custom,$is_list){
public function customizedReturnHtml($projectInfo,$source,$template_id,$is_custom,$is_list){
//TODO::扩展模块定制单独处理
if($is_custom == BTemplate::IS_CUSTOM){
$customModuleModel = new CustomModule();
$info = $customModuleModel->read(['id'=>$source]);
if($info === false){
$this->fail('当前扩展模块不存在或已被删除');
return false;
}
//扩展模块定制
if($is_list == BTemplate::IS_LIST && $info['list_customized'] == BTemplate::IS_VISUALIZATION){
$html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);
return $this->success(['html'=>$html,'template_id'=>$template_id]);
if($html === false){
return false;
}
return $this->success(['html'=>$html]);
}
if($is_list == BTemplate::IS_DETAIL && $info['detail_customized'] == BTemplate::IS_VISUALIZATION){
$html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);
return $this->success(['html'=>$html,'template_id'=>$template_id]);
if($html === false){
return false;
}
return $this->success(['html'=>$html]);
}
return false;
}
//TODO::默认模块定制
$html = $this->isCustomizedPage($source,$is_list,$is_custom);//获取定制页面的html
if(!empty($html)){
return $this->success(['html'=>$html,'template_id'=>$template_id]);
$html = $this->isCustomizedPage($projectInfo,$source,$is_list,$is_custom);//获取定制页面的html
if($html !== false){
return $this->success(['html'=>$html]);
}
return false;
}
... ... @@ -237,7 +238,7 @@ class GeneratePageService
//TODO::获取初始代码
$customHtmlInfo = $bTemplateMainModel->read(['type'=>$source,'is_list'=>$is_list,'is_custom'=>$is_custom]);
if($customHtmlInfo === false){
$this->fail('定制页面,请先上传代码块');
return false;
}
$commonInfo = $this->getCustomizedCommonHtml($source,$is_custom,$is_list);//获取定制头部
if($commonInfo !== false){
... ... @@ -307,17 +308,17 @@ class GeneratePageService
* @method :post
* @time :2023/12/13 10:55
*/
public function isCustomizedPage($source,$is_list,$is_custom)
public function isCustomizedPage($projectInfo,$source,$is_list,$is_custom)
{
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
$page_array = (array)$projectInfo['is_visualization']->page_array;//获取所有定制界面
if (in_array($type, $page_array)) {//是定制界面
//TODO::获取初始代码
$bTemplateMainModel = new BTemplateMain();
$customHtmlInfo = $bTemplateMainModel->read(['type'=>$source,'is_custom'=>$is_custom,'is_list'=>$is_list]);
if($customHtmlInfo === false){
$this->fail('定制页面,请先上传代码块');
return false;
}
$commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部
if($commonInfo !== false){
... ... @@ -338,7 +339,7 @@ class GeneratePageService
public function getCustomizedCommonHtml($type,$is_custom = 0,$is_list = 0){
$data = [
'template_id' => 0,
'project_id' => $this->user['project_id'],
'project_id' => $this->project_id,
'type'=>$type,
'is_custom'=>$is_custom,
'is_list'=>$is_list
... ... @@ -387,9 +388,9 @@ class GeneratePageService
* @method :post
* @time :2023/12/13 10:48
*/
public function getSettingTemplate($source,$is_list,$is_custom){
public function getSettingTemplate($projectInfo,$source,$is_list,$is_custom){
$template_id = 0;
if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION) {//定制项目
if($projectInfo['is_customized'] == BTemplate::IS_VISUALIZATION) {//定制项目
if($is_custom == BTemplate::IS_CUSTOM){
$customModuleModel = new CustomModule();
$info = $customModuleModel->read(['id'=>$source]);
... ... @@ -405,16 +406,16 @@ class GeneratePageService
}else{
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
$page_array = (array)$projectInfo['is_visualization']->page_array;//获取所有定制界面
if (in_array($type, $page_array)) {//是定制界面
return $this->success($template_id);
}
}
}
$bSettingModel = new Setting();
$info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
$info = $bSettingModel->read(['project_id'=>$this->project_id]);
if($info === false){
$this->fail('请先选择模版');
return false;
}
$template_id = $info['template_id'];
return $this->success($template_id);
... ... @@ -427,11 +428,11 @@ class GeneratePageService
* @method :post
* @time :2023/10/21 16:55
*/
public function getCommonHtml($source,$is_list,$template_id,$is_custom = 0){
$type = $this->getType($source,$is_list,$is_custom);
public function getCommonHtml($ProjectInfo,$source,$is_list,$template_id,$is_custom = 0,){
$type = $this->getType($ProjectInfo,$source,$is_list,$is_custom);
$data = [
'template_id' => $template_id,
'project_id' => $this->user['project_id'],
'project_id' => $this->project_id,
'type'=>$type,
'is_custom'=>0,
];
... ... @@ -444,4 +445,36 @@ class GeneratePageService
return $this->success($commonInfo);
}
/**
* @remark :(非定制)保存时获取获取设置的类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/10/21 17:29
*/
public function getType($projectInfo,$source,$is_list,$is_custom = 0){
$type = BTemplate::SOURCE_HOME;//首页公共头部底部
$is_head = $projectInfo['deploy_build']['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部
return $this->success($type);
}
//查看页面是否设置自定义头部底部
if($is_head != BTemplate::IS_NO_HEADER) {
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $projectInfo['id']]);
if ($pageInfo === false) {
return $this->success($type);
}
if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_PRODUCT_DETAIL;}}
else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_PRODUCT_LIST;}}}
if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_BLOG_DETAIL;}}
else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_BLOG_LIST;}}}
if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_NEWS_DETAIL;}}
else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_NEWS_LIST;}}}
if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}
}
return $this->success($type);
}
}
... ...
<?php
namespace App\Services;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\Module\Module;
use App\Models\Module\ModuleCategory;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\Product\Category;
use App\Models\Product\Keyword;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BCustomTemplate;
use App\Models\WebSetting\WebSetting;
use App\Models\WebSetting\WebSettingSeo;
use Illuminate\Support\Facades\Cache;
use phpQuery;
/**
* C端处理TDK服务
*/
class TdkService{
/**
* 页面TDK处理
*/
public function pageTdkHandle($projectInfo,$html,$type,$routerMapInfo=null): string
{
$titleContent = "";
$descriptionContent = "";
$keywordsContent = "";
$phpQueryDom=phpQuery::newDocument($html);
//首页TDK设置
if ($type == RouteMap::SOURCE_INDEX){
$tdkInfo = $this->indexTDK($projectInfo);
}
//单页面TDK设置
if ($type == RouteMap::SOURCE_PAGE){
$tdkInfo = $this->pageTDK($projectInfo,$routerMapInfo);
}
//自定义模块列表页TDK设置
if ($type == RouteMap::SOURCE_MODULE_CATE){
$tdkInfo = $this->moduleCategoryTDK($projectInfo,$routerMapInfo);
}
//自定义模块详情页TDK设置
if ($type == RouteMap::SOURCE_MODULE){
$tdkInfo = $this->moduleDetailsTDK($projectInfo,$routerMapInfo);
}
//新闻详情TDK设置
if ($type == RouteMap::SOURCE_NEWS){
$tdkInfo = $this->newsDetailsTDK($projectInfo,$routerMapInfo);
}
//博客详情TDK设置
if ($type == RouteMap::SOURCE_BLOG){
$tdkInfo = $this->blogDetailsTDK($projectInfo,$routerMapInfo);
}
//聚合页TDK设置
if ($type == RouteMap::SOURCE_PRODUCT_KEYWORD){
$tdkInfo = $this->productKeywordsTDK($projectInfo,$routerMapInfo);
}
//新闻列表页TDK设置
if ($type == RouteMap::SOURCE_NEWS_CATE){
$tdkInfo = $this->newsCategoryTDK($projectInfo,$routerMapInfo);
}
//博客列表页TDK设置
if ($type == RouteMap::SOURCE_BLOG_CATE){
$tdkInfo = $this->blogCategoryTDK($projectInfo,$routerMapInfo);
}
//产品列表页TDK设置
if ($type == RouteMap::SOURCE_PRODUCT_CATE){
$tdkInfo = $this->productCategoryTDK($projectInfo,$routerMapInfo);
}
if (!empty($tdkInfo)){
$titleContent = strip_tags($tdkInfo["titleContent"]);
$descriptionContent = strip_tags($tdkInfo["descriptionContent"]);
$keywordsContent = strip_tags($tdkInfo["keywordsContent"]);
}
$phpQueryDom->find('title')->text($titleContent);
$phpQueryDom->find('meta[name="description"]')->attr('content', $descriptionContent);
$phpQueryDom->find('meta[name="keywords"]')->attr('content', $keywordsContent);
$phpQueryDom->find('head')->append("<meta property='og:title' content='".$titleContent."'/>");
$phpQueryDom->find('head')->append("<meta property='og:type' content='site'/>");
$phpQueryDom->find('head')->append("<meta property='og:site_name' content='".$titleContent."'/>");
$content = $phpQueryDom->htmlOuter();
unset($html,$tdkInfo,$phpQueryDom);
phpQuery::unloadDocuments();
return $content;
}
/**
* 首页TDK
*/
public function indexTDK($projectInfo): array
{
$tdkInfo = [];
$webSettingInfo = $this->getWebSetting($projectInfo);
if (!empty($webSettingInfo)){
$titleContent = strip_tags($webSettingInfo['title']);
$descriptionContent = strip_tags($webSettingInfo['remark']);
$keywordsContent = strip_tags($webSettingInfo['keyword']);
$tdkInfo["titleContent"] = $titleContent;
$tdkInfo["descriptionContent"] = $descriptionContent;
$tdkInfo["keywordsContent"] = $keywordsContent;
}
return $tdkInfo;
}
/**
* 网站设置
*/
public function getWebSetting($projectInfo)
{
if (Cache::get("project_".$projectInfo['id']."_web_setting") == null) {
$webSettingModel = new WebSetting();
$webSettingInfo = $webSettingModel->read(['project_id'=>$projectInfo['id']]);
if ($webSettingInfo !== false) {
Cache::add("project_".$projectInfo['id']."_web_setting", json_encode($webSettingInfo));
return $webSettingInfo;
}
return [];
}
return (array)json_decode(Cache::get("project_".$projectInfo['id']."_web_setting"));
}
/**
* 新闻列表页TDK
*/
public function newsCategoryTDK($projectInfo,$routerMapInfo): array
{
$tdkInfo = [];
$pageSuffix = "";
$webSetting = $this->getWebSetting($projectInfo);
$newsCategoryModel = new NewsCategory();
$newsCategoryInfo = $newsCategoryModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]);
//seo拼接
$webSeoModel = new WebSettingSeo();
$webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);
if ($webSeoInfo !== false){
$pageSuffix = !empty($webSeoInfo['single_page_suffix']) ? " ".$webSeoInfo['single_page_suffix'] : "";
}
if ($newsCategoryInfo !== false){
//title
if (!empty($newsCategoryInfo['seo_title'])){
$titleContent = $newsCategoryInfo['seo_title'].$pageSuffix;
}else{
$titleContent = $newsCategoryInfo['name'].$pageSuffix;
}
//description
if (!empty($newsCategoryInfo['seo_des'])){
$descriptionContent = $newsCategoryInfo['seo_des'];
}else{
$descriptionContent = !empty($webSetting['remark']) ? $webSetting['remark'] : "";
}
//keyword
if (!empty($newsCategoryInfo['seo_keywords'])){
$keywordsContent = $newsCategoryInfo['seo_keywords'];
}else{
$keywordsContent = !empty($webSetting['keyword']) ? $webSetting['keyword'] : "";
}
$tdkInfo["titleContent"] = $titleContent;
$tdkInfo["descriptionContent"] = $descriptionContent;
$tdkInfo["keywordsContent"] = $keywordsContent;
}
return $tdkInfo;
}
/**
* 博客列表页TDK
*/
public function blogCategoryTDK($projectInfo,$routerMapInfo): array
{
$tdkInfo = [];
$pageSuffix = "";
$webSetting = $this->getWebSetting($projectInfo);
$blogCategoryModel = new BlogCategory();
$blogCategoryInfo = $blogCategoryModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]);
//seo拼接
$webSeoModel = new WebSettingSeo();
$webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);
if ($webSeoInfo !== false){
$pageSuffix = !empty($webSeoInfo['single_page_suffix']) ? " ".$webSeoInfo['single_page_suffix'] : "";
}
if ($blogCategoryInfo !== false){
//title
if (!empty($blogCategoryInfo['seo_title'])){
$titleContent = $blogCategoryInfo['seo_title'].$pageSuffix;
}else{
$titleContent = $blogCategoryInfo['name'].$pageSuffix;
}
//description
if (!empty($blogCategoryInfo['seo_des'])){
$descriptionContent = $blogCategoryInfo['seo_des'];
}else{
$descriptionContent = !empty($webSetting['remark']) ? $webSetting['remark'] : "";
}
//keyword
if (!empty($blogCategoryInfo['seo_keywords'])){
$keywordsContent = $blogCategoryInfo['seo_keywords'];
}else{
$keywordsContent = !empty($webSetting['keyword']) ? $webSetting['keyword'] : "";
}
$tdkInfo["titleContent"] = $titleContent;
$tdkInfo["descriptionContent"] = $descriptionContent;
$tdkInfo["keywordsContent"] = $keywordsContent;
}
return $tdkInfo;
}
/**
* 产品列表页TDK
*/
public function productCategoryTDK($projectInfo,$routerMapInfo): array
{
$tdkInfo = [];
$prefix = "";
$suffix = "";
$webSettingTitle = "";
$webSettingDescription = "";
$webSettingKeyword = "";
$projectCategoryModel = new Category();
$projectCategoryInfo = $projectCategoryModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]);
$webSetting = $this->getWebSetting($projectInfo);
//seo拼接
$webSeoModel = new WebSettingSeo();
$webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);
if ($webSeoInfo !== false){
$prefix = !empty($webSeoInfo['product_cate_prefix']) ? $webSeoInfo['product_cate_prefix']." " : "";
$suffix = !empty($webSeoInfo['product_cate_suffix']) ? " ".$webSeoInfo['product_cate_suffix'] : "";
}
if ($webSetting !== false){
$webSettingTitle = !empty($webSetting['title']) ? $webSetting['title'] : "";
$webSettingDescription = !empty($webSetting['remark']) ? $webSetting['remark'] : "";
$webSettingKeyword = !empty($webSetting['keyword']) ? $webSetting['keyword'] : "";
}
if ($projectCategoryInfo !== false){
//title
if (!empty($projectCategoryInfo['seo_title'])){
$titleContent = $prefix.$projectCategoryInfo['seo_title'].$suffix;
}else{
$titleContent = $prefix.$webSettingTitle.$suffix;
}
//description
if (!empty($projectCategoryInfo['seo_des'])){
$descriptionContent = $projectCategoryInfo['seo_des'];
}else{
$descriptionContent = $webSettingDescription;
}
//keywords
if (!empty($projectCategoryInfo['seo_keywords'])){
$keywordsContent = $projectCategoryInfo['seo_keywords'];
}else{
$keywordsContent = $webSettingKeyword;
}
}else{
$titleContent = $prefix.$webSettingTitle.$suffix;
$descriptionContent = $webSettingDescription;
$keywordsContent = $webSettingKeyword;
}
$tdkInfo["titleContent"] = $titleContent;
$tdkInfo["descriptionContent"] = $descriptionContent;
$tdkInfo["keywordsContent"] = $keywordsContent;
return $tdkInfo;
}
/**
* 产品聚合页TDK
*/
public function productKeywordsTDK($projectInfo,$routerMapInfo): array
{
$tdkInfo = [];
$keywordModel = new Keyword();
$keywordInfo = $keywordModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]);
if ($keywordInfo !== false){
//处理title
$title = $keywordInfo['seo_title'] ?: $keywordInfo['title'];
//seo拼接
$webSeoModel = new WebSettingSeo();
$webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);
$titleContent = $webSeoInfo ? $webSeoInfo['tab_prefix'] . " " . $title . " " . $webSeoInfo['tab_suffix'] : $title;
//处理description
$descriptionContent = $keywordInfo['seo_description'] ?: $keywordInfo['title'];
//处理keywords
$keywordsContent = $keywordInfo['seo_keywords'] ?: $keywordInfo['title'];
$tdkInfo["titleContent"] = $titleContent;
$tdkInfo["descriptionContent"] = $descriptionContent;
$tdkInfo["keywordsContent"] = $keywordsContent;
}
return $tdkInfo;
}
/**
* 新闻详情页TDK
*/
public function newsDetailsTDK($projectInfo,$routerMapInfo): array
{
$tdkInfo = [];
$titleContent = "";
$keywordsContent = "";
$descriptionContent = "";
$newsModel = new News();
$newsInfo = $newsModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id'],'status'=>1]);
return $this->newsBlogTdk($newsInfo, $projectInfo, $titleContent, $descriptionContent, $keywordsContent, $tdkInfo);
}
/**
* 新闻详情页TDK
*/
public function blogDetailsTDK($projectInfo,$routerMapInfo): array
{
$tdkInfo = [];
$titleContent = "";
$keywordsContent = "";
$descriptionContent = "";
$blogMode = new Blog();
$blogInfo = $blogMode->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id'],'status'=>1]);
return $this->newsBlogTdk($blogInfo, $projectInfo, $titleContent, $descriptionContent, $keywordsContent, $tdkInfo);
}
/**
* 自定义模块列表页TDK
*/
public function moduleDetailsTDK($projectInfo,$routerMapInfo): array
{
$tdkInfo = [];
$moduleModel = new CustomModule();
$moduleInfo = $moduleModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id'],'status'=>0]);
$webSetting = $this->getWebSetting($projectInfo);
if ($moduleInfo !== false){
//title
$webSettingTitle = !empty($webSetting['title']) ? $webSetting['title'] : "";
$titleContent = !empty($moduleInfo['seo_title']) ? $moduleInfo['seo_title'] : $webSettingTitle;
//description
$webSettingDescription = !empty($webSetting['remark']) ? $webSetting['remark'] : "";
$descriptionContent = !empty($moduleInfo['seo_description']) ? $moduleInfo['seo_description'] : $webSettingDescription;
//keywords
$webSettingKeyword = !empty($webSetting['keyword']) ? $webSetting['keyword'] : "";
$keywordsContent = !empty($moduleInfo['seo_keywords']) ? $moduleInfo['seo_keywords'] : $webSettingKeyword;
$tdkInfo["titleContent"] = $titleContent;
$tdkInfo["descriptionContent"] = $descriptionContent;
$tdkInfo["keywordsContent"] = $keywordsContent;
}
return $tdkInfo;
}
/**
* 自定义模块列表页TDK
*/
public function moduleCategoryTDK($projectInfo,$routerMapInfo): array
{
$tdkInfo = [];
$moduleCategoryModel = new CustomModuleCategory();
$moduleCategoryInfo = $moduleCategoryModel->read(['project_id'=>$projectInfo['id'],'id'=>$routerMapInfo['source_id']]);
$webSetting = $this->getWebSetting($projectInfo);
if ($moduleCategoryInfo !== false){
//title
$webSettingTitle = !empty($webSetting['title']) ? $webSetting['title'] : "";
$titleContent = !empty($moduleCategoryInfo['seo_title']) ? $moduleCategoryInfo['seo_title'] : $webSettingTitle;
//description
$webSettingDescription = !empty($webSetting['remark']) ? $webSetting['remark'] : "";
$descriptionContent = !empty($moduleCategoryInfo['seo_description']) ? $moduleCategoryInfo['seo_description'] : $webSettingDescription;
//keywords
$webSettingKeyword = !empty($webSetting['keyword']) ? $webSetting['keyword'] : "";
$keywordsContent = !empty($moduleCategoryInfo['seo_keywords']) ? $moduleCategoryInfo['seo_keywords'] : $webSettingKeyword;
$tdkInfo["titleContent"] = $titleContent;
$tdkInfo["descriptionContent"] = $descriptionContent;
$tdkInfo["keywordsContent"] = $keywordsContent;
}
return $tdkInfo;
}
/**
* 单页面TDK
*/
public function pageTDK($projectInfo,$routerMapInfo): array
{
$tdkInfo = [];
if (!empty($routerMap)){
$customModel = new BCustomTemplate();
$webCustomInfo = $customModel->read(['id'=>$routerMapInfo['source_id'],'status'=>1]);
//seo拼接
$webSeoModel = new WebSettingSeo();
$webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);
//网站设置
$webSetting = $this->getWebSetting($projectInfo);
$descriptionContent = "";
$keywordsContent = "";
if ($webCustomInfo !== false){
//title
if ($webCustomInfo['title'] == null){
if (!empty($webSeo)){
$titleContent = $webCustomInfo['name']." ".$webSeoInfo['single_page_suffix'];
}else{
$titleContent = $webCustomInfo['name'];
}
}else{
if (!empty($webSeo)){
$titleContent = $webCustomInfo['title']." ".$webSeoInfo['single_page_suffix'];
}else{
$titleContent = $webCustomInfo['title'];
}
}
//keywords
if ($webCustomInfo['keywords'] == null){
if (!empty($webSetting)){
$keywordsContent = $webSetting['keyword'];
}
}else{
$keywordsContent = $webSetting['keywords'];
}
//description
if ($webCustomInfo['description'] == null){
if (!empty($webSetting)) {
$descriptionContent = $webSetting['remark'];
}
}else{
$descriptionContent = $webCustomInfo['description'];
}
$tdkInfo["titleContent"] = $titleContent;
$tdkInfo["descriptionContent"] = $descriptionContent;
$tdkInfo["keywordsContent"] = $keywordsContent;
}
}
return $tdkInfo;
}
/**
* 新闻博客详情通用版块
*/
public function newsBlogTdk($info, $projectInfo, $titleContent, $descriptionContent, $keywordsContent, array $tdkInfo): array
{
if (!empty($info)) {
//seo拼接
$pageSuffix = "";
$webSeoModel = new WebSettingSeo();
$webSeoInfo = $webSeoModel->read(['project_id'=>$projectInfo['id']]);
$webSetting = $this->getWebSetting($projectInfo);
if (!empty($webSeoInfo)) {
$pageSuffix = !empty($webSeo['single_page_suffix']) ? " " . $webSeo['single_page_suffix'] : "";
}
if ($info['seo_title'] == null) {
$titleContent = !empty($info['name']) ? $info['name'] . $pageSuffix : "";
} else {
$titleContent = $info['seo_title'] . $pageSuffix;
}
//处理description
if ($info['seo_description'] == null) {
$descriptionContent = !empty($webSetting['remark']) ? $webSetting['remark'] : "";
} else {
$descriptionContent = $info['seo_description'];
}
//处理keywords
if ($info['seo_keywords'] == null) {
$keywordsContent = !empty($webSetting['keyword']) ? $webSetting['keyword'] : "";
} else {
$keywordsContent = $info['seo_keywords'];
}
$tdkInfo["titleContent"] = $titleContent;
$tdkInfo["descriptionContent"] = $descriptionContent;
$tdkInfo["keywordsContent"] = $keywordsContent;
}
return $tdkInfo;
}
}
... ...
... ... @@ -42,7 +42,7 @@ class HttpUtils
public static function get($url, $data, $headers = [])
{
LogUtils::info("HttpUtils-GET请求URL:" . $url);
$response = Http::withHeaders($headers)->get($url, $data);
$response = Http::timeout(20)->withHeaders($headers)->get($url, $data);
self::checkSuccess($response);
return $response->getBody()->getContents();
}
... ... @@ -50,7 +50,7 @@ class HttpUtils
public static function post($url, $data, $headers = [])
{
LogUtils::info("HttpUtils-POST请求URL:" . $url);
$response = Http::withHeaders($headers)->post($url, $data);
$response = Http::timeout(20)->withHeaders($headers)->post($url, $data);
self::checkSuccess($response);
return $response->getBody()->getContents();
}
... ...
... ... @@ -28,3 +28,5 @@ Route::any('getOptimizationReport', [\App\Http\Controllers\Api\OptimizationRepor
Route::post('video_task_callback', [\App\Http\Controllers\Api\NoticeController::class, 'videoTaskCallback'])->name('api.video_task_callback');
// 验证是否为6.0用户
Route::any('has_user', [\App\Http\Controllers\Api\PrivateController::class, 'hasUser'])->name('api.has_user');
// 6.0有效用户用户
Route::any('valid_user', [\App\Http\Controllers\Api\PrivateController::class, 'validUser'])->name('api.valid_user');
... ...