作者 lyh

gx

正在显示 49 个修改的文件 包含 2972 行增加653 行删除

要显示太多修改。

为保证性能只显示 49 of 49+ 个文件。

... ... @@ -44,9 +44,9 @@ class ShareUser extends Command
//获取所有ayr_share用户
$ayr_share_model = new AyrShareModel();
$ayr_release = new AyrReleaseModel();
$ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=','']]);
$ayr_share_list = $ayr_share_model->list(['profile_key'=>['!=',''],'project_id'=>410]);
foreach ($ayr_share_list as $v){
$time = Carbon::now()->modify('-7 days')->toDateString();
$time = Carbon::now()->modify('-1 days')->toDateString();
//创建时间小于7天前的当前时间
if($v['created_at'] > $time){
continue;
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Console\Commands\DayCount;
use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryForm;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
... ... @@ -42,18 +43,18 @@ class Count extends Command
public function handle()
{
$list = DB::table('gl_project')->where('gl_project.extend_type','=',0)
->where('gl_project.type','!=',0)
->whereIn('gl_project.type',[1,2,3,4,6])
->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id')
->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id')
->select($this->selectParam())->get();
try {
if(!empty($list)){
$list = $list->toArray();
$data = [];
$yesterday = Carbon::yesterday()->toDateString();
$domainInfo = new DomainInfo();
foreach ($list as $v){
$v = (array)$v;
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
if($v['type'] == Project::TYPE_ZERO){
continue;
}
... ... @@ -75,23 +76,31 @@ class Count extends Command
//服务达标天数
$arr['compliance_day'] = $v['finish_remain_day'];
//剩余服务时常
$arr['service_day'] = $v['remain_day'] - 1;
$arr['service_day'] = ($v['remain_day'] - 1) < 0 ? 0: $v['remain_day'] - 1;
//项目id
$arr['project_id'] = $v['project_id'];
$arr['created_at'] = date('Y-m-d H:i:s');
$arr['updated_at'] = date('Y-m-d H:i:s');
//询盘统计
$arr = $this->inquiry($arr,$v['test_domain'], $v['id']);
echo date('Y-m-d H:i:s') . json_encode($arr) . '->' . PHP_EOL;
$data[] = $arr;
if($arr === false){
continue;
}
//查询当天数据是否存在 存在则更新
$countModel = new \App\Models\HomeCount\Count();
$info = $countModel->read(['date'=>$arr['date'],'project_id'=>$v['id']]);
if($info === false){
DB::table('gl_count')->insert($arr);
}else{
$countModel->edit($arr,['id'=>$info['id']]);
}
Log::channel('day_count')->error('日期:'.$arr['created_at'].'success: ' .$v['test_domain']);
}
//判断数据是否存在
DB::table('gl_count')->insert($data);
}
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . ' error: ' . '->' . $e->getMessage() . PHP_EOL;
Log::channel('day_count')->error('day_count:->error ' . $e->getMessage());
}
echo date('Y-m-d H:i:s') . ' end: ' . PHP_EOL;
Log::channel('day_count')->error('success:end');
echo $this->error;
}
... ... @@ -127,6 +136,9 @@ class Count extends Command
*/
public function inquiry($arr,$domain,$project_id){
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
if($inquiry_list == false){
return false;
}
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
$countryArr = [];
... ... @@ -143,7 +155,6 @@ class Count extends Command
}
}
}
//加上其他询盘
ProjectServer::useProject($project_id);
$arr['inquiry_num'] += InquiryFormData::getCount();
... ... @@ -155,8 +166,6 @@ class Count extends Command
$countryArr[$v1['country']] = $v1['count'];
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 20, true);
$arr['country'] = json_encode($top20);
... ...
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
... ... @@ -9,6 +9,8 @@
namespace App\Console\Commands\DayCount;
use App\Helper\FormGlobalsoApi;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Project\Project;
use App\Models\Visit\Visit;
use App\Services\ProjectServer;
... ... @@ -16,14 +18,16 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeCount extends Command
class CountAll extends Command
{
const STATUS_ERROR = 400;
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_counts';
protected $signature = 'count_all';
/**
* The console command description.
... ... @@ -34,7 +38,7 @@ class UpgradeCount extends Command
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]);
$list = $projectModel->list(['delete_status'=>0,'type'=>['in',[1,2,3,4,6]]]);
foreach ($list as $v) {
echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
... ... @@ -90,6 +94,52 @@ class UpgradeCount extends Command
}
/**
* @param $arr
* @param $domain
* @name :(询盘统计)inquiry
* @author :lyh
* @method :post
* @time :2023/6/14 15:44
*/
public function inquiry($arr,$domain,$project_id){
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
if($inquiry_list == false){
return false;
}
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
$countryArr = [];
}else{
$arr['inquiry_num'] = $inquiry_list['data']['total'];
//询盘国家统计
$countryData = $inquiry_list['data']['data'];
$countryArr = [];
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']]++;
}else{
$countryArr[$v1['country']] = 1;
}
}
}
//加上其他询盘
ProjectServer::useProject($project_id);
$arr['inquiry_num'] += InquiryFormData::getCount();
$countryData = InquiryFormData::getCountryCount();
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
}else{
$countryArr[$v1['country']] = $v1['count'];
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 20, true);
$arr['country'] = json_encode($top20);
return $arr;
}
/**
* @remark :询盘数量
* @name :inquiry_num
* @author :lyh
... ...
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
... ... @@ -9,6 +9,10 @@
namespace App\Console\Commands\DayCount;
use App\Helper\FormGlobalsoApi;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Models\Visit\Visit;
use App\Services\ProjectServer;
... ... @@ -16,14 +20,16 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeProjectCount extends Command
class CountProject extends Command
{
const STATUS_ERROR = 400;
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_count {project_id}';
protected $signature = 'count_project {project_id}';
/**
* The console command description.
... ... @@ -51,6 +57,19 @@ class UpgradeProjectCount extends Command
->groupBy('updated_date')->get()->toArray();
$project = new Project();
$projectInfo = $project->read(['id'=>$project_id]);
$projectOptimizeModel = new DeployOptimize();
$optimizeInfo = $projectOptimizeModel->read(['project_id'=>$project_id]);
$domain = '';
if(!empty($optimizeInfo['domain'])){
$domainInfoModel = new DomainInfo();
$domainInfo = $domainInfoModel->read(['id'=>$optimizeInfo['domain']]);
if($domainInfo !== false){
$domain = $domainInfo['domain'];
}
}
if(empty($domain)){
return false;
}
if(!empty($list)){
$arr = [];
foreach ($list as $k=>$v){
... ... @@ -64,12 +83,11 @@ class UpgradeProjectCount extends Command
$arr['date'] = $v['updated_date'];
$arr['pv_num'] = $this->pv_num($v['updated_date']);
$arr['ip_num'] = $this->ip_num($v['updated_date']);
$arr['inquiry_num'] = $this->inquiry_num($v['updated_date']);
//服务达标天数
$arr['compliance_day'] = $projectInfo['finish_remain_day'];
//剩余服务时常
$arr['service_day'] = $projectInfo['remain_day'];
$arr['country'] = json_encode([]);
$arr = $this->inquiry($arr,$domain, $project_id);
//查询当天数据是否存在 存在则更新
$info = $count->read(['date'=>$v['updated_date'],'project_id'=>$project_id]);
if($info === false){
... ... @@ -103,7 +121,6 @@ class UpgradeProjectCount extends Command
* @time :2023/6/14 15:40
*/
public function pv_num($day){
//$pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $day)->count();
$pv = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->sum('depth');
return $pv;
}
... ... @@ -119,6 +136,50 @@ class UpgradeProjectCount extends Command
return $ip;
}
/**
* @param $arr
* @param $domain
* @name :(询盘统计)inquiry
* @author :lyh
* @method :post
* @time :2023/6/14 15:44
*/
public function inquiry($arr,$domain,$project_id){
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
if($inquiry_list == false){
return false;
}
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
$countryArr = [];
}else{
$arr['inquiry_num'] = $inquiry_list['data']['total'];
//询盘国家统计
$countryData = $inquiry_list['data']['data'];
$countryArr = [];
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']]++;
}else{
$countryArr[$v1['country']] = 1;
}
}
}
//加上其他询盘
ProjectServer::useProject($project_id);
$arr['inquiry_num'] += InquiryFormData::getCount();
$countryData = InquiryFormData::getCountryCount();
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
}else{
$countryArr[$v1['country']] = $v1['count'];
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 20, true);
$arr['country'] = json_encode($top20);
return $arr;
}
}
... ...
... ... @@ -6,6 +6,7 @@ use App\Models\Inquiry\InquiryCount as InquiryCountModel;
use App\Models\Inquiry\InquiryInfo;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
/**
* @remark :
... ... @@ -62,6 +63,7 @@ class InquiryCount extends Command
//获取昨天的时间
$yesterday = Carbon::yesterday()->toDateString();
$inquiryInfoModel = new InquiryInfo();
try {
foreach ($this->status as $k=>$v){
$total = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']]])->count();
$untreated = $inquiryInfoModel->formatQuery(['created_at'=>['between',[$yesterday.' 00:00:00',$yesterday.' 23:59:59']],'status'=>1])->count();
... ... @@ -76,6 +78,9 @@ class InquiryCount extends Command
}
$inquiryCount = new InquiryCountModel();
$inquiryCount->insert($data);
}catch (\Exception $e){
Log::error('inquiry_count : error');
}
return true;
}
}
... ...
<?php
/**
* @remark :
* @name :DeleteProductCategory.php
* @author :lyh
* @method :post
* @time :2024/5/16 14:59
*/
namespace App\Console\Commands\DeleteCategory;
use App\Helper\Arr;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory;
use App\Models\Com\NoticeLog;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* @remark :删除分类
* @name :DeleteProductCategory
* @author :lyh
* @method :post
* @time :2024/5/16 15:00
*/
class DeleteBlogCategory extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'delete_blog_category';
/**
* The console command description.
*
* @var string
*/
protected $description = '删除博客分类';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @remark :批量处理
* @name :handle
* @author :lyh
* @method :post
* @time :2024/5/16 15:02
*/
public function handle(){
while (true){
$noticeLogModel = new NoticeLog();
$list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_BLOG_CATEGORY],'id',['*'],'asc',100);
if(empty($list)){
sleep(10);
continue;
}
foreach ($list as $item){
echo 'start:' . $item['id'] . PHP_EOL;
try {
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]);
if($projectInfo === false){
continue;
}
ProjectServer::useProject($projectInfo['id']);
$this->updateCategory();
DB::disconnect('custom_mysql');
$noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]);
echo 'success:' . $item['id'] . PHP_EOL;
}catch (\Exception $e){
echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL;
errorLog('delete_blog_category删除失败', $item, $e);
}
}
return true;
}
}
/**
* @remark :更新分类
* @name :updateProductCategory
* @author :lyh
* @method :post
* @time :2024/5/16 15:38
*/
public function updateCategory(){
$page = 1;
$blogModel = new Blog();
while (true){
$blogList = $blogModel->lists(['status'=>1],$page,1000,'id',['id','category_id']);
if(empty($blogList) || empty($blogList['list'])){
return false;
}
foreach ($blogList['list'] as $v){
$category_id_arr = Arr::setToArr(trim($v['category_id'],','));
if(empty($category_id_arr)){
continue;
}
$categoryModel = new BlogCategory();
foreach ($category_id_arr as $k=>$cate_id){
$cateInfo = $categoryModel->read(['id'=>$cate_id],['id']);
if($cateInfo == false){
//删除关联表
unset($category_id_arr[$k]);
}
}
$str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : '';
$blogModel->edit(['category_id'=>$str],['id'=>$v['id']]);
}
$page++;
}
return true;
}
}
... ...
<?php
/**
* @remark :
* @name :DeleteProductCategory.php
* @author :lyh
* @method :post
* @time :2024/5/16 14:59
*/
namespace App\Console\Commands\DeleteCategory;
use App\Helper\Arr;
use App\Models\Com\NoticeLog;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* @remark :删除分类
* @name :DeleteProductCategory
* @author :lyh
* @method :post
* @time :2024/5/16 15:00
*/
class DeleteCustomCategory extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'delete_custom_category';
/**
* The console command description.
*
* @var string
*/
protected $description = '删除扩展模块分类';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @remark :批量处理
* @name :handle
* @author :lyh
* @method :post
* @time :2024/5/16 15:02
*/
public function handle(){
while (true){
$noticeLogModel = new NoticeLog();
$list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_CUSTOM_CATEGORY],'id',['*'],'asc',100);
if(empty($list)){
sleep(10);
continue;
}
foreach ($list as $item){
echo 'start:' . $item['id'] . PHP_EOL;
try {
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]);
if($projectInfo === false){
continue;
}
ProjectServer::useProject($projectInfo['id']);
$this->updateCategory();
DB::disconnect('custom_mysql');
$noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]);
echo 'success:' . $item['id'] . PHP_EOL;
}catch (\Exception $e){
echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL;
errorLog('delete_custom_category删除失败', $item, $e);
}
}
return true;
}
}
/**
* @remark :更新分类
* @name :updateProductCategory
* @author :lyh
* @method :post
* @time :2024/5/16 15:38
*/
public function updateCategory(){
$page = 1;
$customModel = new CustomModuleContent();
while (true){
$customList = $customModel->lists(['status'=>0],$page,1000,'id',['id','category_id']);
if(empty($customList) || empty($customList['list'])){
return false;
}
foreach ($customList['list'] as $v){
$category_id_arr = $v['category_id'];
if(empty($category_id_arr)){
continue;
}
$categoryModel = new CustomModuleCategory();
foreach ($category_id_arr as $k=>$cate_id){
$cateInfo = $categoryModel->read(['id'=>$cate_id],['id']);
if($cateInfo == false){
//删除关联表
unset($category_id_arr[$k]);
}
}
$str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : '';
$customModel->edit(['category_id'=>$str],['id'=>$v['id']]);
}
$page++;
}
return true;
}
}
... ...
<?php
/**
* @remark :
* @name :DeleteProductCategory.php
* @author :lyh
* @method :post
* @time :2024/5/16 14:59
*/
namespace App\Console\Commands\DeleteCategory;
use App\Helper\Arr;
use App\Models\Com\NoticeLog;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* @remark :删除分类
* @name :DeleteProductCategory
* @author :lyh
* @method :post
* @time :2024/5/16 15:00
*/
class DeleteNewsCategory extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'delete_news_category';
/**
* The console command description.
*
* @var string
*/
protected $description = '删除新闻分类';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @remark :批量处理
* @name :handle
* @author :lyh
* @method :post
* @time :2024/5/16 15:02
*/
public function handle(){
while (true){
$noticeLogModel = new NoticeLog();
$list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_NEWS_CATEGORY],'id',['*'],'asc',100);
if(empty($list)){
sleep(10);
continue;
}
foreach ($list as $item){
echo 'start:' . $item['id'] . PHP_EOL;
try {
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]);
if($projectInfo === false){
continue;
}
ProjectServer::useProject($projectInfo['id']);
$this->updateCategory();
DB::disconnect('custom_mysql');
$noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]);
echo 'success:' . $item['id'] . PHP_EOL;
}catch (\Exception $e){
echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL;
errorLog('delete_news_category删除失败', $item, $e);
}
}
return true;
}
}
/**
* @remark :更新分类
* @name :updateProductCategory
* @author :lyh
* @method :post
* @time :2024/5/16 15:38
*/
public function updateCategory(){
$page = 1;
$newsModel = new News();
while (true){
$newsList = $newsModel->lists(['status'=>1],$page,1000,'id',['id','category_id']);
if(empty($newsList) || empty($newsList['list'])){
return false;
}
foreach ($newsList['list'] as $v){
$category_id_arr = Arr::setToArr(trim($v['category_id'],','));
if(empty($category_id_arr)){
continue;
}
$categoryModel = new NewsCategory();
foreach ($category_id_arr as $k=>$cate_id){
$cateInfo = $categoryModel->read(['id'=>$cate_id],['id']);
if($cateInfo === false){
//删除关联表
unset($category_id_arr[$k]);
}
}
$str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : '';
$newsModel->edit(['category_id'=>$str],['id'=>$v['id']]);
}
$page++;
}
return true;
}
}
... ...
<?php
/**
* @remark :
* @name :DeleteProductCategory.php
* @author :lyh
* @method :post
* @time :2024/5/16 14:59
*/
namespace App\Console\Commands\DeleteCategory;
use App\Helper\Arr;
use App\Models\Com\NoticeLog;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* @remark :删除分类
* @name :DeleteProductCategory
* @author :lyh
* @method :post
* @time :2024/5/16 15:00
*/
class DeleteProductCategory extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'delete_product_category';
/**
* The console command description.
*
* @var string
*/
protected $description = '删除产品分类';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @remark :批量处理
* @name :handle
* @author :lyh
* @method :post
* @time :2024/5/16 15:02
*/
public function handle(){
while (true){
$noticeLogModel = new NoticeLog();
$list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_PRODUCT_CATEGORY],'id',['*'],'asc',100);
if(empty($list)){
sleep(10);
continue;
}
foreach ($list as $item){
echo 'start:' . $item['id'] . PHP_EOL;
try {
$projectModel = new Project();
$projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]);
if($projectInfo === false){
continue;
}
ProjectServer::useProject($projectInfo['id']);
$this->updateCategory();
DB::disconnect('custom_mysql');
$noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]);
echo 'success:' . $item['id'] . PHP_EOL;
}catch (\Exception $e){
echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL;
errorLog('delete_product_category删除失败', $item, $e);
}
}
return true;
}
}
/**
* @remark :更新分类
* @name :updateProductCategory
* @author :lyh
* @method :post
* @time :2024/5/16 15:38
*/
public function updateCategory(){
$page = 1;
while (true){
$productModel = new Product();
$productList = $productModel->lists(['status'=>1],$page,1000,'id',['id','category_id']);
if(empty($productList) || empty($productList['list'])){
return false;
}
foreach ($productList['list'] as $v){
$categoryRelatedModel = new CategoryRelated();
if(empty($v['category_id'])){
$categoryRelatedModel->del(['product_id'=>$v['id']]);
continue;
}
$category_id_arr = $v['category_id'];
$categoryModel = new Category();
foreach ($category_id_arr as $k=>$cate_id){
$cateInfo = $categoryModel->read(['id'=>$cate_id],['id']);
if($cateInfo == false){
//删除关联表
$categoryRelatedModel->del(['cate_id'=>$cate_id]);
unset($category_id_arr[$k]);
}
}
$str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : '';
$productModel->edit(['category_id'=>$str],['id'=>$v['id']]);
}
$page++;
}
return true;
}
}
... ...
<?php
/**
* @remark :
* @name :TemplateLog.php
* @author :lyh
* @method :post
* @time :2024/7/10 14:44
*/
namespace App\Console\Commands\DeleteTemplate;
use App\Models\Project\Project;
use App\Models\Template\BTemplateLog;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class TemplateLog extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'delete_template_log';
/**
* The console command description.
*
* @var string
*/
protected $description = '定时清理日志';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['delete_status'=>0]);
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->deleteTemplate();
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :定时清理可视化日志
* @name :deleteTemplate
* @author :lyh
* @method :post
* @time :2024/7/10 14:48
*/
public function deleteTemplate(){
$startDate = date("Y-m-01 00:00:00");
$endDate = date("Y-m-t 23:59:59");
$templateLogModel = new BTemplateLog();
return $templateLogModel->del(['created_at'=>['not between'=>[$startDate,$endDate]]]);
}
}
... ...
... ... @@ -9,7 +9,10 @@
namespace App\Console\Commands\Domain;
use App\Models\Devops\ServerConfig;
use App\Models\Devops\ServersIp;
use App\Models\Project\CountryCustom;
use App\Models\Project\Project;
use Illuminate\Console\Command;
use App\Models\Domain\DomainInfo as DomainInfoModel;
... ... @@ -61,7 +64,7 @@ class DomainInfo extends Command
public function startUpdateDomain()
{
$domainModel = new DomainInfoModel();
$list = $domainModel->where('status', '!=', 2)->where(function ($query) {
$list = $domainModel->where('status', '=', 1)->where(function ($query) {
$query->whereNull('domain_end_time')->orWhere('domain_end_time', '<', date('Y-m-d H:i:s'));
})->get()->toArray();
foreach ($list as $v) {
... ... @@ -70,7 +73,6 @@ class DomainInfo extends Command
'domain_start_time' => $time['start'],
'domain_end_time' => $time['end']
];
$domainModel->edit($data, ['id' => $v['id']]);
}
}
... ... @@ -83,8 +85,9 @@ class DomainInfo extends Command
public function startUpdateCert()
{
$domainModel = new DomainInfoModel();
$projectModel = new Project();
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
$list = $domainModel->where('status', '!=', 2)->where(function ($query) use ($end_day) {
$list = $domainModel->where('status', '=', 1)->where(function ($query) use ($end_day) {
$query->whereNull('certificate_end_time')->orWhere('certificate_end_time', '<', $end_day);
})->get()->toArray();
foreach ($list as $v) {
... ... @@ -95,8 +98,12 @@ class DomainInfo extends Command
$ssl['from'] && $data['certificate_start_time'] = $ssl['from'];
$ssl['to'] && $data['certificate_end_time'] = $ssl['to'];
if ($v['type'] == 1 && $ssl['to'] < $end_day) {
//申请免费证书
$project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
if ($v['type'] == 1 && $ssl['to'] < $end_day && $project_info) {
$serverIpModel = new ServersIp();
$servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']);
if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) {
//非自建站项目,申请免费证书
$this->updatePrivate($v);
$ssl_new = $this->updateDomainSsl($v['domain']);
... ... @@ -104,6 +111,8 @@ class DomainInfo extends Command
$ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to'];
}
}
$domainModel->edit($data, ['id' => $v['id']]);
}
}
... ... @@ -116,8 +125,9 @@ class DomainInfo extends Command
public function startUpdateAmpCert()
{
$domainModel = new DomainInfoModel();
$projectModel = new Project();
$end_day = date('Y-m-d H:i:s', time() + 3 * 24 * 3600);//3天后到期
$list = $domainModel->where('status', '!=', 2)->where('amp_status', 1)->where(function ($query) use ($end_day) {
$list = $domainModel->where('status', '=', 1)->where('amp_status', 1)->where(function ($query) use ($end_day) {
$query->whereNull('amp_certificate_end_time')->orWhere('amp_certificate_end_time', '<', $end_day);
})->get()->toArray();
foreach ($list as $v) {
... ... @@ -137,14 +147,19 @@ class DomainInfo extends Command
$ssl['from'] && $data['amp_certificate_start_time'] = $ssl['from'];
$ssl['to'] && $data['amp_certificate_end_time'] = $ssl['to'];
if ($v['amp_type'] == 1 && $ssl['to'] < $end_day) {
//申请免费证书
$this->updateAmpPrivate($v['domain']);
$project_info = $projectModel->read(['id' => $v['project_id']], ['serve_id']);
if ($v['amp_type'] == 1 && $ssl['to'] < $end_day && $project_info) {
$serverIpModel = new ServersIp();
$servers_ip_info = $serverIpModel->read(['id' => $project_info['serve_id']], ['servers_id']);
if ($servers_ip_info && $servers_ip_info['servers_id'] != ServerConfig::SELF_SITE_ID) {
//非自建站项目,申请免费证书
$this->updateAmpPrivate($v);
$ssl_new = $this->updateDomainSsl($v['domain']);
$ssl_new['from'] && $data['certificate_start_time'] = $ssl_new['from'];
$ssl_new['to'] && $data['certificate_end_time'] = $ssl_new['to'];
}
}
$domainModel->edit($data, ['id' => $v['id']]);
}
... ... @@ -197,24 +212,28 @@ class DomainInfo extends Command
"rewrite" => $param['extend_config'],
'other_domain' => $param['other_domain'],
'is_https' => $param['is_https'],
'not_allow_country' => $param['not_allow_country'],
'not_allow_ip' => $param['not_allow_ip'],
'is_redirect' => $param['is_redirect']
];
return $this->curlRequest($url, $param);
}
/**
* 更新amp站证书
* @param $domain
* @param $param
* @return array
* @author Akun
* @date 2024/02/26 10:25
*/
public function updateAmpPrivate($domain)
public function updateAmpPrivate($param)
{
$url = 'https://' . $domain . '/api/createSiteAmp/';
$url = 'https://' . $param['domain'] . '/api/createSiteAmp/';
$param = [
"domain" => $domain,
'private_key' => '',
'cert' => ''
"domain" => $param['domain'],
'not_allow_country' => $param['not_allow_country'],
'not_allow_ip' => $param['not_allow_ip'],
'is_redirect' => $param['is_redirect']
];
return $this->curlRequest($url, $param);
}
... ... @@ -283,9 +302,9 @@ class DomainInfo extends Command
],
]);
$stream = stream_socket_client('ssl://' . $domain . ':443', $errno, $errstr, 30, STREAM_CLIENT_CONNECT, $context);
if($stream){
if ($stream) {
$remote_cert = stream_context_get_params($stream)['options']['ssl']['peer_certificate'];
if($remote_cert){
if ($remote_cert) {
$valid_from = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validFrom_time_t']);
$valid_to = date('Y-m-d H:i:s', openssl_x509_parse($remote_cert)['validTo_time_t']);
}
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Console\Commands\Domain;
use App\Models\Project\DeployOptimize;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use Illuminate\Console\Command;
... ... @@ -22,6 +23,9 @@ class RemainDay extends Command
*/
protected $signature = 'remain_day';
protected $projectId = [
1434
];//需要单独处理的项目
/**
* The console command description.
*
... ... @@ -44,22 +48,29 @@ class RemainDay extends Command
*/
public function handle()
{
$list = Project::whereIn('type', [2,3,4])->get();
$list = Project::whereIn('type', [Project::TYPE_TWO,Project::TYPE_THREE,Project::TYPE_FOUR])->get();
foreach ($list as $item){
if(in_array($item->id,$this->projectId)){//已开始优化的时间结算
$optimizeModel = new DeployOptimize();
$opInfo = $optimizeModel->read(['project_id'=>$item->id],['start_date']);
if($opInfo === false){
continue;
}
$diff = time() - strtotime($opInfo['start_date'] ?? $item->uptime);
$remain_day = $item['deploy_build']['service_duration'] - floor($diff / (60 * 60 * 24));
}else{
if($item['type'] == Project::TYPE_TWO){
//排名达标天数
// $compliance_day = GoogleRankModel::where(['project_id' => $item['id'], 'lang' => ''])->value('compliance_day') ?: 0;
//获取当前项目的达标天数
$compliance_day = Project::where(['id' => $item['id']])->value('finish_remain_day') ?: 0;
$compliance_day = $item->finish_remain_day ?? 0;
$remain_day = $item['deploy_build']['service_duration'] - $compliance_day;
}else{
//审核上线后开始
$check_time = OnlineCheck::where('project_id', $item['id'])->where('status', 1)->value('created_at') ?: '';
if(!$check_time){
$remain_day = $item['deploy_build']['service_duration'];
if($item->uptime){
$diff = time() - strtotime($item->uptime);
$item->finish_remain_day = floor($diff / (60 * 60 * 24));
$remain_day = $item['deploy_build']['service_duration'] - floor($diff / (60 * 60 * 24));
}else{
$diff = time() - strtotime($check_time);
$remain_day = floor($diff / (60 * 60 * 24));
$remain_day = $item['deploy_build']['service_duration'];
}
}
}
$item->remain_day = $remain_day > 0 ? $remain_day : 0;
... ...
... ... @@ -62,6 +62,7 @@ class ServiceCount extends Command
}
$model->edit(['count'=>$count],['id'=>$v['id']]);
}
return true;
}
}
... ...
... ... @@ -42,8 +42,7 @@ class ImportChannel extends Command
'channel'=>['like','%"user_id": "0"%'],
];
$lists = $projectModel->list($map);
// var_dump($lists);
// die();
if(!empty($lists)){
foreach ($lists as $k => $v){
$order_id = $v['notice_order_id'];
$api = new OaGlobalsoApi();
... ... @@ -52,6 +51,7 @@ class ImportChannel extends Command
$channel = Channel::getProjectChannel($data['company_id'], $data['username_sales']);
$projectModel->edit(['channel'=>$channel],['id'=>$v['id']]);
}
return 1;
}
return true;
}
}
... ...
... ... @@ -30,7 +30,7 @@ class ImportManager extends Command
*
* @var string
*/
protected $description = '导入数据';
protected $description = '导入数据(同步5.0人事信息)';
/**
* @remark :导入5.0管理员数据
* @name :handle
... ...
... ... @@ -57,13 +57,10 @@ class LastInquiry extends Command
//其他询盘的最新时间
ProjectServer::useProject($item['id']);
$other_last_time = InquiryFormData::orderBy('id', 'desc')->value('submit_at');
$last_inquiry_time = $last_time > $other_last_time ? $last_time : $other_last_time;
if(!$last_inquiry_time){
continue;
}
$item->last_inquiry_time = $last_inquiry_time;
$item->save();
}
... ...
... ... @@ -16,8 +16,12 @@ use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
class VideoTask extends Command
{
... ... @@ -49,15 +53,19 @@ class VideoTask extends Command
* @var int 最大子任务
*/
public $max_sub_task = 200;
public $max_num = 49000;
/**
* @return bool
*/
public function handle()
{
echo '开始:'.PHP_EOL;
Log::info('开始视频推广任务');
$this->createSubTask();
$number = KeywordVideoTaskLog::getMonthVideoNum();
if($number >= $this->max_num){
Log::info('当月以达到最大视频生成数,任务执行数:' . $number);
return true;
}
$this->createSubTask($number);
$this->sendSubTask();
Log::info('结束视频推广任务');
return true;
... ... @@ -68,17 +76,21 @@ class VideoTask extends Command
* TODO 获取需要生成子任务的项目,获取项目中未生成视频的关键词,通过关键词生成初始化子任务
* @return bool
*/
public function createSubTask()
public function createSubTask($number)
{
$sub_task_num = $this->max_sub_task;
while (true) {
if ($sub_task_num <= 0){
break;
}
if($number >= $this->max_num){
break;
}
$task_project = KeywordVideoTask::where(['status' => KeywordVideoTask::STATUS_OPEN])->orderBy('sort', 'desc')->orderBy('id', 'desc')->first();
if (empty($task_project)){
break;
}
echo '开始,项目id:'.$task_project->project_id.PHP_EOL;
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['project_id'=>$task_project->project_id]);
if($domainInfo === false){
... ... @@ -87,7 +99,10 @@ class VideoTask extends Command
continue;
}
ProjectServer::useProject($task_project->project_id);
$keyword = $this->getProjectKeyword($task_project->number);
if(!empty($task_project->keywords)){
$keywords = explode(',',trim(',',$task_project->keywords));
}
$keyword = $this->getProjectKeyword($task_project->number,$keywords ?? []);
// 已经没有需要生成视频的关键词
if (!$keyword) {
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
... ... @@ -96,7 +111,7 @@ class VideoTask extends Command
}
$logo_bg = $this->getImage($domainInfo);
foreach ($keyword as $val) {
$log = KeywordVideoTaskLog::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id])->first();
$log = KeywordVideoTaskLog::where(['project_id' => $task_project->project_id, 'keyword_id' => $val->id , 'result_status'=>'200'])->first();
if ($log){
continue;
}
... ... @@ -113,10 +128,13 @@ class VideoTask extends Command
'updated_at' => date('Y-m-d H:i:s'),
'created_at' => date('Y-m-d H:i:s'),
];
KeywordVideoTaskLog::insert($array);
$rs = KeywordVideoTaskLog::insert($array);
if($rs && ($sub_task_num > 0)){
$sub_task_num--;
}
}
}
Cache::put('video_keyword_number_month',$number + count($keyword),3600);
$task_project->status = KeywordVideoTask::STATUS_CLOSE;
$task_project->save();
}
... ... @@ -168,11 +186,18 @@ class VideoTask extends Command
* @param $number
* @return mixed
*/
public function getProjectKeyword($number)
public function getProjectKeyword($number,$keywords = [])
{
$keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->pluck('id')->toArray();
$keyword_id = array_rand($keyword_arr_id, $number);
$keyword = Keyword::whereIn("id", $keyword_id)->get();
$keyword_id = Keyword::where('video', null)->whereIn("title", $keywords)
->where('route', 'not like', '%-tag')->whereNotNull('keyword_content')->limit($number)->pluck('id')->toArray();
$need = $number - count($keyword_id);
if ($need > 0) {
$keyword_arr_id = Keyword::where('video', null)->where('route', 'not like', '%-tag')
->whereNotNull('keyword_content')->whereNotIn('id', $keyword_id)->orderBy('id','asc')->limit($need)->pluck('id')->toArray();
}
$keyword_arr_id = array_merge($keyword_id, $keyword_arr_id);
$keyword = Keyword::whereIn("id", $keyword_arr_id)->get();
return $keyword;
}
... ... @@ -213,7 +238,7 @@ class VideoTask extends Command
}
}
//TODO::所有产品
$thumb = $this->getRecommendAndHotProducts($keywordInfo['route'],$project_id);
$thumb = $this->getRecommendAndHotProducts($keyword_id);
$keyword_arr = Keyword::where("project_id",$project_id)->where("status",1)->inRandomOrder()->take(10)->pluck('title')->toArray();
$data = [
'url'=> 'https://' . $domain.'/'.$keywordInfo['route'],
... ... @@ -229,38 +254,24 @@ class VideoTask extends Command
/**
* 关键词聚合页-推荐&热门产品
*/
public function getRecommendAndHotProducts($route,$project_id): ?array
public function getRecommendAndHotProducts($keyword_id): ?array
{
$productIds = [];
$productKeyword = Keyword::where("project_id",$project_id)->where("route",$route)->first();
if (!empty($productKeyword)){
$productsQuery = Product::where("project_id", $project_id)->where("status",1)->where("keyword_id","like","%,".$productKeyword->id.",%")->limit(7)->get();
if (!empty($productsQuery)){
$productsQuery = Product::where("status",1)->where("keyword_id","like","%,".$keyword_id.",%")->limit(13)->get();
if (count($productsQuery) > 0){
foreach ($productsQuery as $item){
$productIds[] = $item->id;
}
if (count($productIds)<7){
$product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
$number = 40;
$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();
if (count($productIds) < 13){
$product_all_id = Product::where('thumb','!=',null)->whereNotIn('id', $productIds)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20 - count($productIds))->pluck('id')->toArray();
$randomData = Product::whereIn("id", $product_all_id)->orderByRaw(DB::raw("FIELD(id, " . implode(',', $product_all_id) . ")"))->get();
$products = $productsQuery->merge($randomData);
}
}else{
$products = $productsQuery;
}
}else{
$product_all_id = Product::where("project_id", $project_id)->where('thumb','!=',null)->where("status",Product::STATUS_ON)->pluck('id')->toArray();
$number = 40;
$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();
}
}
$product_all_id = Product::where('thumb','!=',null)->where("status",Product::STATUS_ON)->inRandomOrder()->take(20)->pluck('id')->toArray();
$products = Product::whereIn("id", $product_all_id)->orderByRaw(DB::raw("FIELD(id, " . implode(',', $product_all_id) . ")"))->get();
}
$data = [];
if (!empty($products)){
... ... @@ -271,12 +282,13 @@ class VideoTask extends Command
if(count($data) > 13){
break;
}
$keyword_id = implode(',',$item->keyword_id);
if (strpos(','.$keyword_id.',', ','.$productKeyword->id.',') === false) {
$keyword_ids = implode(',',$item->keyword_id);
if (strpos(','.$keyword_ids.',', ','.$keyword_id.',') === false) {
//不包含
$productModel = new Product();
$keyword_id = ','.$keyword_id.',' . $productKeyword->id.',';
$productModel->edit(['keyword_id'=>$keyword_id],['id'=>$item->id]);
$keyword_ids = !empty($keyword_ids) ? ','.$keyword_ids.',' : ',' ;
$keyword_id_str = $keyword_ids . $keyword_id.',';
$productModel->edit(['keyword_id'=>$keyword_id_str],['id'=>$item->id]);
}
$data[] = ['url'=>getImageUrl($item->thumb['url']),'title'=>$item->title];
}
... ...
<?php
namespace App\Console\Commands\MonthlyCount;
use App\Helper\FormGlobalsoApi;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class InquiryMonthlyCount extends Command
{
const STATUS_ERROR = 400;
public $error = 0;
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'month_count';
/**
* The console command description.
*
* @var string
*/
protected $description = '询盘月报告统计';
/**
* @remark :询盘月报告
* @name :handle
* @author :lyh
* @method :post
* @time :2023/6/30 9:32
*/
public function handle(){
$list = DB::table('gl_project')->where('gl_project.extend_type','=',0)
->where('gl_project.type','!=',0)
->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id')
->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id')
->select($this->selectParam())->get()->toArray();
// 获取上个月的开始时间
$startTime = Carbon::now()->subMonth()->startOfMonth()->toDateString();
// 获取上个月的结束时间
$endTime = Carbon::now()->subMonth()->endOfMonth()->toDateString();
$domainInfo = new DomainInfo();
foreach ($list as $value){
$value = (array)$value;
if($value['type'] == Project::TYPE_ZERO){
continue;
}
if(!empty($value['domain'])){
$info = $domainInfo->read(['id'=>$value['domain']]);
if($info !== false){
$value['test_domain'] = $info['domain'];
}
}
$arr = [];
//按月统计询盘记录
$arr = $this->inquiryCount($arr,$startTime,$endTime,$value['test_domain'],$value['project_id']);
$arr = $this->flowCount($arr,$startTime,$endTime,$value['project_id']);
ProjectServer::useProject($value['project_id']);
$arr = $this->sourceCount($arr,$value['test_domain'],$startTime,$endTime);
DB::disconnect('custom_mysql');
$arr['created_at'] = date('Y-m-d H:i:s');
$arr['updated_at'] = date('Y-m-d H:i:s');
$arr['project_id'] = $value['project_id'];
// 获取当前日期时间
$arr['month'] = Carbon::now()->subMonth()->format('Y-m');
DB::table('gl_month_count')->insert($arr);
}
return true;
}
/**
* @param $domain
* @param $project_id
* @remark :询盘按月统计
* @name :inquiryCount
* @author :lyh
* @method :post
* @time :2023/6/30 14:29
*/
public function inquiryCount(&$arr,&$startTime,&$endTime,$domain,$project_id){
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
//总数
$arr['total'] = $inquiry_list['data']['total'] ?? 0;
//数据详情
$data = $inquiry_list['data']['data'] ?? 0;
$arr['month_total'] = 0;
$countryArr = [];
$arr['country'] = "";
if(!empty($data)){
foreach ($data as $v){
if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){
$arr['month_total']++;
if(isset($countryArr[$v['country']])){
$countryArr[$v['country']]++;
}else{
$countryArr[$v['country']] = 1;
}
}
}
}
//加上其他询盘
ProjectServer::useProject($project_id);
$arr['total'] += InquiryFormData::count();
$arr['month_total'] += InquiryFormData::getCount([$startTime, $endTime]);
$countryData = InquiryFormData::getCountryCount([$startTime, $endTime]);
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
}else{
$countryArr[$v1['country']] = $v1['count'];
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 15, true);
$arr['country'] = json_encode($top20);
return $arr;
}
/**
* @remark :流量统计
* @name :flowCount
* @author :lyh
* @method :post
* @time :2023/6/30 14:31
*/
public function flowCount(&$arr,&$startTime,&$endTime,$project_id){
$pv_ip = DB::table('gl_count')
->where(['project_id'=>$project_id])
->where('date','>=',$startTime.' 00:00:00')
->where('date','<=',$endTime.' 23:59:59')
->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'))
->first();
$arr['pv'] = $pv_ip->pv_num;
$arr['ip'] = $pv_ip->ip_num;
if($arr['ip'] != 0){
$arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
}
return $arr;
}
/**
* @remark :来源访问前8
* @name :sourceCount
* @author :lyh
* @method :post
* @time :2023/6/30 16:14
*/
public function sourceCount(&$arr,$domain,$startTime,$endTime){
//访问来源前10
$source = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('referrer_url', DB::raw('COUNT(*) as count'))
->groupBy('referrer_url')
->whereBetween('updated_date', [$startTime,$endTime])
->orderByDesc('count')->limit(10)->get()->toArray();
$arr['source'] = json_encode($source);
//访问国家前15
$source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
->groupBy('country')
->whereBetween('updated_date', [$startTime,$endTime])
->orderBy('ip','desc')->limit(15)->get()->toArray();
$arr['source_country'] = json_encode($source_country);
//受访界面前15
$referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('url',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('url')
->limit(15)->get()->toArray();
$arr['referrer_url'] = json_encode($referrer_url);
//访问端口
$referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('device_port',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('device_port')
->limit(15)->get()->toArray();
$arr['referrer_port'] = json_encode($referrer_port);
return $arr;
}
/**
* @name :(查询参数设置)selectParam
* @author :lyh
* @method :post
* @time :2023/6/14 15:00
*/
public function selectParam(){
$select = [
'gl_project.id AS id',
'gl_project.type AS type',
'gl_project.extend_type AS extend_type',
'gl_project_deploy_build.test_domain AS test_domain',
'gl_project_deploy_optimize.domain AS domain',
'gl_project_deploy_build.project_id AS project_id',
'gl_project.cooperate_date AS cooperate_date',
'gl_project_deploy_build.service_duration AS service_duration',
];
return $select;
}
}
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
... ... @@ -13,6 +13,7 @@ use App\Helper\FormGlobalsoApi;
use App\Models\Com\UpdateOldInfo;
use App\Models\Domain\DomainInfo;
use App\Models\HomeCount\MonthCount;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Project\Project;
use App\Models\Visit\Visit;
use App\Services\ProjectServer;
... ... @@ -20,14 +21,14 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeCount extends Command
class MonthAllCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_month_counts';
protected $signature = 'month_all';
/**
* The console command description.
... ... @@ -38,8 +39,9 @@ class UpgradeCount extends Command
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]);
$list = $projectModel->list(['delete_status'=>0,'type'=>['in',[1,2,3,4,6]]]);
foreach ($list as $v) {
if($v['is_upgrade'] == 1){
$oldModel = new UpdateOldInfo();
$info = $oldModel->read(['project_id' => $v['id']]);
if ($info !== false) {
... ... @@ -47,6 +49,14 @@ class UpgradeCount extends Command
}else{
continue;
}
}else{
$domainModel = new DomainInfo();
$info = $domainModel->read(['project_id'=>$v['id']]);
if($info === false){
continue;
}
$url = $info['domain'];
}
ProjectServer::useProject($v['id']);
echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL;
$this->count($v['id'], $url);
... ... @@ -67,9 +77,7 @@ class UpgradeCount extends Command
->groupBy('month')->get()->toArray();
foreach ($list as $k=>$v){
$v = (array)$v;
if($v['month'] == date('Y-m')){
continue;
}
$arr = [];
$monthCountModel = new MonthCount();
$info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
// 获取当月开始时间
... ... @@ -78,7 +86,7 @@ class UpgradeCount extends Command
$end = date('Y-m-t', strtotime($v['month']));
$arr['project_id'] = $project_id;
$res = $this->inquiry($url,$v['month']);
// $arr['month_total'] = 0;
$arr['total'] = $arr['month_total'] = 0;
if(isset($res['data']['count'])){
echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL;
$arr['month_total'] = $res['data']['count'];
... ... @@ -91,9 +99,21 @@ class UpgradeCount extends Command
$arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);
}
}
//获取当月的其他询盘
$arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
$country = [];
if(isset($res['data']['data'])){
$arr['country'] = json_encode($res['data']['data']);
$country = $res['data']['data'];
}
$countryData = InquiryFormData::getCountryCount([$start.' 00:00:00',$end.' 00:00:00']);
foreach ($countryData as $v1){
if(isset($country[$v1['country']])){
$country[$v1['country']] += $v1['count'];
}else{
$country[$v1['country']] = $v1['count'];
}
}
$arr['country'] = json_encode($country);
$arr['month'] = $v['month'];
$arr = $this->pv_ip($arr,$start,$end,$project_id);
$arr = $this->sourceCount($arr,$start,$end);
... ...
<?php
/**
* @remark :
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
*/
namespace App\Console\Commands\MonthlyCount;
use App\Models\Com\UpdateOldInfo;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\MonthCount AS MonthCountModel;
class MonthCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'month_counts';
/**
* The console command description.
*
* @var string
*/
protected $description = '每天生成月统计记录';
public function handle(){
$list = DB::table('gl_project')->where('gl_project.extend_type','=',0)
->whereIn('gl_project.type',[1,2,3,4,6])
->leftJoin('gl_project_deploy_build', 'gl_project.id', '=', 'gl_project_deploy_build.project_id')
->leftJoin('gl_project_deploy_optimize', 'gl_project.id', '=', 'gl_project_deploy_optimize.project_id')
->select($this->selectParam())->get()->toArray();
foreach ($list as $v) {
$v = (array)$v;
if($v['type'] == Project::TYPE_ZERO){
continue;
}
if($v['is_upgrade'] == 1){
$oldModel = new UpdateOldInfo();
$info = $oldModel->read(['project_id' => $v['id']]);
if ($info !== false) {
$url = $info['old_domain_online'];
}else{
continue;
}
}else{
$domainInfo = new DomainInfo();
if(!empty($v['domain'])){
$info = $domainInfo->read(['id'=>$v['domain']]);
if($info !== false){
$url = $info['domain'];
}
}else{
$url = $v['test_domain'];
}
}
ProjectServer::useProject($v['id']);
echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL;
$this->count($v['id'], $url);
DB::disconnect('custom_mysql');
}
}
/**
* @name :(查询参数设置)selectParam
* @author :lyh
* @method :post
* @time :2023/6/14 15:00
*/
public function selectParam(){
$select = [
'gl_project.id AS id',
'gl_project.type AS type',
'gl_project.extend_type AS extend_type',
'gl_project_deploy_build.test_domain AS test_domain',
'gl_project.is_upgrade AS is_upgrade',
'gl_project_deploy_optimize.domain AS domain',
'gl_project_deploy_build.project_id AS project_id',
'gl_project.cooperate_date AS cooperate_date',
'gl_project_deploy_build.service_duration AS service_duration',
];
return $select;
}
/**
* @remark :日统计记录
* @name :count
* @author :lyh
* @method :post
* @time :2024/1/8 9:05
*/
public function count($project_id,$url){
$arr = [];
$v = ['month'=>date('Y-m')];
$monthCountModel = new MonthCountModel();
$info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
// 获取当月开始时间
$start = date('Y-m-01', strtotime($v['month']));
// 获取当月结束时间
$end = date('Y-m-t', strtotime($v['month']));
$arr['project_id'] = $project_id;
$res = $this->inquiry($url,$v['month']);
$arr['total'] = $arr['month_total'] = 0;
if(isset($res['data']['count'])){
echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL;
$arr['month_total'] = $res['data']['count'];
//获取上一个的count
$previousMonth = date('Y-m', strtotime($v['month'] . ' -1 month'));
$previousInfo = $monthCountModel->read(['month'=>$previousMonth,'project_id'=>$project_id]);
if($previousInfo === false){
$arr['total'] = $arr['month_total'];
}else{
$arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);
}
}
//获取当月的其他询盘
$arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
$country = [];
if(isset($res['data']['data'])){
$country = $res['data']['data'];
}
$countryData = InquiryFormData::getCountryCount([$start.' 00:00:00',$end.' 00:00:00']);
foreach ($countryData as $v1){
if(isset($country[$v1['country']])){
$country[$v1['country']] += $v1['count'];
}else{
$country[$v1['country']] = $v1['count'];
}
}
$arr['country'] = json_encode($country);
$arr['month'] = $v['month'];
$arr = $this->pv_ip($arr,$start,$end,$project_id);
$arr = $this->sourceCount($arr,$start,$end);
if($info === false){
$selectedDate = $start;
$firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
$arr['created_at'] = $firstDayOfNextMonth;
$arr['updated_at'] = $firstDayOfNextMonth;
// echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL;
$monthCountModel->insert($arr);
}else{
$monthCountModel->edit($arr,['id'=>$info['id']]);
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :本月询盘总量
* @name :month_total
* @author :lyh
* @method :post
* @time :2024/1/8 11:02
*/
public function pv_ip(&$arr,$start,$end,$project_id){
$pv_ip = DB::table('gl_count')
->where(['project_id'=>$project_id])
->where('date','>=',$start.' 00:00:00')
->where('date','<=',$end.' 23:59:59')
->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'),DB::raw('SUM(inquiry_num) as inquiry_num'))
->first();
$arr['pv'] = $pv_ip->pv_num;
$arr['ip'] = $pv_ip->ip_num;
if($arr['ip'] != 0){
$arr['rate'] = round((($arr['month_total'] ?? 0) / $arr['ip']) * 10,2);
}
return $arr;
}
/**
* @remark :来源访问前8
* @name :sourceCount
* @author :lyh
* @method :post
* @time :2023/6/30 16:14
*/
public function sourceCount(&$arr,$startTime,$endTime){
//访问来源前10
$source = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('referrer_url', DB::raw('COUNT(*) as count'))
->groupBy('referrer_url')
->whereBetween('updated_date', [$startTime,$endTime])
->orderByDesc('count')->limit(10)->get()->toArray();
$arr['source'] = json_encode($source);
//访问国家前15
$source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
->groupBy('country')
->whereBetween('updated_date', [$startTime,$endTime])
->orderBy('ip','desc')->limit(15)->get()->toArray();
$arr['source_country'] = json_encode($source_country);
//受访界面前15
$referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('url',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('url')
->limit(15)->get()->toArray();
$arr['referrer_url'] = json_encode($referrer_url);
//访问端口
$referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('device_port',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('device_port')
->limit(15)->get()->toArray();
$arr['referrer_port'] = json_encode($referrer_port);
return $arr;
}
public function inquiry($url,$month){
$url = 'https://'.$url.'/';
$token = md5($url.date("Y-m-d"));
$url = 'https://form.globalso.com/api/external-interface/country_con/15243d63ed5a5738?domain='.$url.'&token='.$token.'&source=1,2,3,4&model=month&sta_date='.$month;
$res = http_get($url,['charset=utf-8']);
echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL;
return $res;
}
}
... ...
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
... ... @@ -13,6 +13,7 @@ use App\Helper\FormGlobalsoApi;
use App\Models\Com\UpdateOldInfo;
use App\Models\Domain\DomainInfo;
use App\Models\HomeCount\MonthCount;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Project\Project;
use App\Models\Visit\Visit;
use App\Services\ProjectServer;
... ... @@ -20,14 +21,14 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeProjectCount extends Command
class MonthProjectCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_month_count {project_id}';
protected $signature = 'month_project {project_id}';
/**
* The console command description.
... ... @@ -64,10 +65,8 @@ class UpgradeProjectCount extends Command
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
->groupBy('month')->get()->toArray();
foreach ($list as $k=>$v){
$arr = [];
$v = (array)$v;
if($v['month'] == date('Y-m')){
continue;
}
$monthCountModel = new MonthCount();
$info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
// 获取当月开始时间
... ... @@ -76,7 +75,7 @@ class UpgradeProjectCount extends Command
$end = date('Y-m-t', strtotime($v['month']));
$arr['project_id'] = $project_id;
$res = $this->inquiry($url,$v['month']);
// $arr['month_total'] = 0;
$arr['total'] = $arr['month_total'] = 0;
if(isset($res['data']['count'])){
echo date('Y-m-d H:i:s') . '数据:'.$res['data']['count'] . PHP_EOL;
$arr['month_total'] = $res['data']['count'];
... ... @@ -89,9 +88,21 @@ class UpgradeProjectCount extends Command
$arr['total'] = $res['data']['count'] + ($previousInfo['total'] ?? 0);
}
}
//获取当月的其他询盘
$arr['total'] += InquiryFormData::getCount([$start.' 00:00:00',$end.' 00:00:00']);
$country = [];
if(isset($res['data']['data'])){
$arr['country'] = json_encode($res['data']['data']);
$country = $res['data']['data'];
}
$countryData = InquiryFormData::getCountryCount([$start.' 00:00:00',$end.' 00:00:00']);
foreach ($countryData as $v1){
if(isset($country[$v1['country']])){
$country[$v1['country']] += $v1['count'];
}else{
$country[$v1['country']] = $v1['count'];
}
}
$arr['country'] = json_encode($country);
$arr['month'] = $v['month'];
$arr = $this->pv_ip($arr,$start,$end,$project_id);
$arr = $this->sourceCount($arr,$start,$end);
... ...
... ... @@ -13,6 +13,7 @@ use App\Models\Com\KeywordVideoTaskLog;
use App\Models\Domain\DomainInfo;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
/**
* @remark :通知C端生成界面
... ... @@ -65,6 +66,7 @@ class Notice extends Command
}
foreach ($domainList as $v1){
//TODO::通知C端
@file_put_contents(storage_path('logs/notice_c'.'.log'), var_export($v1['domain'], true) . PHP_EOL, FILE_APPEND);
$this->curlDelRoute($v1['domain'],$v1['project_id']);
}
return true;
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Console\Commands\Project;
use App\Helper\Translate;
use App\Models\Com\NoticeLog;
use App\Models\Product\Keyword;
use App\Models\RouteMap\RouteMap;
... ... @@ -80,7 +81,12 @@ class InitKeyword extends Command
foreach ($keyword as $val) {
$this->output(' keywordID: ' . $val->id . ', title: ' . $val->title);
try {
$route = RouteMap::setRoute($val['title'],RouteMap::SOURCE_PRODUCT_KEYWORD, $val->id, $notice['data']['project_id']);
if(contains_russian($val['title'])){
$title = Translate::tran($val['title'], 'en');
}else{
$title = $val['title'];
}
$route = RouteMap::setRoute($title,RouteMap::SOURCE_PRODUCT_KEYWORD, $val->id, $notice['data']['project_id']);
$val->route = $route;
$val->save();
} catch (\Exception $e) {
... ...
... ... @@ -61,10 +61,6 @@ class InitProject extends Command
$project_logic->createUser($project['mobile'],$project['id'],$project['lead_name']);
}
$project_logic->createdRole($project['id']);
//更改服务器状态
if(!empty($project['serve_id'])){
$project_logic->updateServe($project['serve_id']);
}
$item->status = NoticeLog::STATUS_SUCCESS;
$item->save();
echo 'success:' . $item['id'] . PHP_EOL;
... ...
... ... @@ -446,6 +446,8 @@ class SyncProject extends Command
ProjectServer::createDatabase($project);
//创建表
ProjectServer::initTable();
//初始数据
ProjectServer::saveInitParam($project_id);
}
/**
... ...
... ... @@ -65,7 +65,7 @@ class RankData extends BaseCommands
$error = 0;
$api = new QuanqiusouApi();
//有排名api编号的项目
$list = DeployOptimize::where('api_no', '>', 0)->select('api_no', 'minor_languages', 'project_id')->orderBy('project_id', 'asc')->get();
$list = DeployOptimize::where('api_no', '>', 0)->select('api_no', 'project_id')->orderBy('project_id', 'asc')->get();
Log::channel('rank_data')->info('开始-排名数据-' . count($list));
//当日所有站点谷歌收录数据
$site_res = $api->getSiteRes();
... ...
... ... @@ -62,7 +62,10 @@ class ReplaceHtml extends Command
while (true){
$replaceHtmlModel = new TemplateReplaceHtml();
$replaceHtmlList = $replaceHtmlModel->list(['status'=>$replaceHtmlModel::STATUS]);
if(!empty($replaceHtmlList)){
if(empty($replaceHtmlList)){
sleep(20);
continue;
}
foreach ($replaceHtmlList as $v){
ProjectServer::useProject($v['project_id']);
echo '开始,任务id:'.$v['id'].PHP_EOL;
... ... @@ -76,9 +79,7 @@ class ReplaceHtml extends Command
echo '结束'.PHP_EOL;
DB::disconnect('custom_mysql');
}
}
sleep(5);
return true;
sleep(10);
}
}
... ... @@ -104,7 +105,7 @@ class ReplaceHtml extends Command
'source_id'=>$v['id'],
'is_rollback'=>$info['is_rollback'],
'template_id'=>$info['template_id'],
'name'=>$v['name'],
'source_name'=>$v['name'],
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
... ... @@ -124,6 +125,21 @@ class ReplaceHtml extends Command
* @time :2024/5/10 17:26
*/
public function createReplaceHtmlLog($info){
if($info['is_rollback'] != 0){
$saveData = [];
$templateHtmlLogModel = new TemplateReplaceHtmlLog();
$list = $templateHtmlLogModel->list(['replace_id'=>$info['rollback_id']]);
foreach ($list as $value){
unset($value['id']);
$value['replace_id'] = $info['id'];
$value['is_rollback'] = $info['is_rollback'];
$value['old_html'] = $info['old_html'];
$value['html'] = $info['html'];
$value['created_at'] = date('Y-m-d H:i:s');
$value['updated_at'] = date('Y-m-d H:i:s');
$saveData[] = $value;
}
}else{
$bTemplateModel = new BTemplate();
$condition = ['is_custom'=>$info['is_custom'], 'is_list'=>$info['is_list'], 'template_id'=>$info['template_id']];
if($info['source'] != 0){
... ... @@ -138,8 +154,11 @@ class ReplaceHtml extends Command
$saveData = [];
foreach ($bTemplateList as $v){
$source_id = $v['source'] == 1 ? 0 : $v['source_id'];
$name = $this->getSourceName($v['source'],$source_id,$v['is_list'],$v['is_custom']);
$saveData[] = $this->saveData($info,$v,$source_id,$name);
$name_route = $this->getSourceName($v['source'],$source_id,$v['is_list'],$v['is_custom']);
if($name_route !== false){
$saveData[] = $this->saveData($info,$v,$source_id,$name_route);
}
}
}
if(!empty($saveData)){
$templateHtmlLogModel = new TemplateReplaceHtmlLog();
... ... @@ -155,7 +174,7 @@ class ReplaceHtml extends Command
* @method :post
* @time :2024/5/13 11:29
*/
public function saveData($info,$v,$source_id,$name){
public function saveData($info,$v,$source_id,$name_route){
return [
'replace_id'=>$info['id'],
'project_id'=>$info['project_id'],
... ... @@ -168,7 +187,8 @@ class ReplaceHtml extends Command
'is_list'=>$v['is_list'],
'is_rollback'=>$info['is_rollback'],
'template_id'=>$info['template_id'],
'source_name'=>$name,
'source_name'=>$name_route['name'],
'route'=>$name_route['route'],
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
... ... @@ -186,7 +206,7 @@ class ReplaceHtml extends Command
return $this->getCustomName($source,$source_id,$is_list);
}
if($source == BTemplate::SOURCE_HOME){
return '';
return ['name'=>'','route'=>''];
}elseif ($source == BTemplate::SOURCE_PRODUCT){
return $this->getProductName($source_id,$is_list);
}elseif ($source == BTemplate::SOURCE_BLOG){
... ... @@ -230,6 +250,7 @@ class ReplaceHtml extends Command
return false;
}
$name = $cateInfo['name'];
$route = $cateInfo['alias'];
}else{
$newsModel = new News();
$newsInfo = $newsModel->read(['id'=>$source_id]);
... ... @@ -237,8 +258,9 @@ class ReplaceHtml extends Command
return false;
}
$name = $newsInfo['name'];
$route = $newsInfo['url'];
}
return $name;
return ['name'=>$name,'route'=>$route];
}
/**
... ... @@ -256,6 +278,7 @@ class ReplaceHtml extends Command
return false;
}
$name = $cateInfo['name'];
$route = $cateInfo['alias'];
}else{
$blogModel = new Blog();
$productInfo = $blogModel->read(['id'=>$source_id]);
... ... @@ -263,8 +286,9 @@ class ReplaceHtml extends Command
return false;
}
$name = $productInfo['name'];
$route = $productInfo['url'];
}
return $name;
return ['name'=>$name,'route'=>$route];
}
/**
... ... @@ -282,6 +306,7 @@ class ReplaceHtml extends Command
return false;
}
$name = $cateInfo['title'];
$route = $cateInfo['route'];
}else{
$productModel = new Product();
$productInfo = $productModel->read(['id'=>$source_id]);
... ... @@ -289,8 +314,9 @@ class ReplaceHtml extends Command
return false;
}
$name = $productInfo['title'];
$route = $productInfo['route'];
}
return $name;
return ['name'=>$name,'route'=>$route];
}
/**
... ... @@ -313,6 +339,7 @@ class ReplaceHtml extends Command
return false;
}
$name = $cateInfo['name'];
$route = $cateInfo['route'];
}else{
$contentModel = new CustomModuleContent();
$contentInfo = $contentModel->read(['id'=>$source_id],['id','name']);
... ... @@ -320,7 +347,8 @@ class ReplaceHtml extends Command
return false;
}
$name = $contentInfo['name'];
$route = $contentInfo['route'];
}
return $name;
return ['name'=>$name,'route'=>$route];
}
}
... ...
... ... @@ -66,7 +66,7 @@ class ReplaceHtmlLog extends Command
echo '结束'.PHP_EOL;
}
}
sleep(5);
sleep(20);
return true;
}
... ... @@ -80,7 +80,7 @@ class ReplaceHtmlLog extends Command
public function replaceHtml($info){
$source_id = $info['source'] == 1 ? 0 : $info['source_id'];
$bTemplateModel = new BTemplate();
$condition = ['source'=>$info['source'],'source_id'=>$info['source_id'],
$condition = ['source'=>$info['source'],'source_id'=>$source_id,
'template_id'=>$info['template_id'],'is_custom'=>$info['is_custom'],'is_list'=>$info['is_list']];
$old_html = $info['old_html'];
$html = $info['html'];
... ...
... ... @@ -9,14 +9,13 @@
namespace App\Console\Commands\Suppliers;
use App\Models\Com\Purchaser;
use App\Models\Product\Keyword;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Models\Purchaser\Purchaser;
use App\Models\Purchaser\PurchaserInfo;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class RecommendedSuppliers extends Command
{
... ... @@ -52,27 +51,20 @@ class RecommendedSuppliers extends Command
{
$projectModel = new DeployBuild();
$project_list = $projectModel->list(['is_supplier'=>1]);//TODO::已开启推荐供应商
foreach ($project_list as $k => $v){
foreach ($project_list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['project_id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$info = Keyword::inRandomOrder()->first();
if(empty($info)){
continue;
}
$keywordInfo = $this->getPurchaser($info['title']);
if($keywordInfo !== false){
continue;
}
ProjectServer::useProject($v['project_id']);
$title = $this->getKeywords($v['project_id']);
echo date('Y-m-d H:i:s') . '开始:'.$v['project_id'] . PHP_EOL;
$this->savePurchaser($v['id'],$info['title']);
$this->savePurchaser($v['project_id'],$title);
DB::disconnect('custom_mysql');
}
return true;
}
public function getPurchaser($keyword){
public function getPurchaser($keyword,$project_id){
$purchaserModel = new Purchaser();
return $purchaserModel->read(['keyword'=>$keyword]);
return $purchaserModel->read(['keyword'=>$keyword,'project_id'=>$project_id]);
}
/**
... ... @@ -83,7 +75,7 @@ class RecommendedSuppliers extends Command
* @time :2024/3/5 11:38
*/
public function savePurchaser($project_id,$keyword,$row = 10){
$url = 'https://admin.hagro.cn/api/company_list';
$url = 'https://fob.ai.cc/api/company_list';
$data = [
'prod_desc'=>$keyword,
'total'=>$row ?? 10,
... ... @@ -97,7 +89,9 @@ class RecommendedSuppliers extends Command
'total'=>$this->param['row'] ?? 10,
];
$res = http_post($url,json_encode($param));
if(!empty($res) && $res['code'] == 200){
echo date('Y-m-d H:i:s') . json_encode($res) . PHP_EOL;
if(!empty($res) && $res['code'] == 200 && !empty($res['data'])){
//保存多条数据
$saveData = [
'project_id'=>$project_id,
'keyword'=>$keyword,
... ... @@ -105,6 +99,54 @@ class RecommendedSuppliers extends Command
];
$purchaserModel = new Purchaser();
$purchaserModel->add($saveData);
$this->savePurchaserInfo($project_id,$keyword,$res['data']);
}else{
$title = $this->getKeywords($project_id);
$this->savePurchaser($project_id,$title);
}
return true;
}
/**
* @remark :取关键词
* @name :getKeywords
* @author :lyh
* @method :post
* @time :2024/7/1 18:07
*/
public function getKeywords($project_id){
$keywordModel = new Keyword();
$keywordModel->
$info = Keyword::inRandomOrder()->first();
$keywordInfo = $this->getPurchaser($info->title,$project_id);
if($keywordInfo !== false){
$this->getKeywords($project_id);
}
return $info->title;
}
/**
* @remark :保存供应商详情
* @name :savePurchaserInfo
* @author :lyh
* @method :post
* @time :2024/5/29 16:38
*/
public function savePurchaserInfo($project_id,$keyword,$data){
$purchaserInfoModel = new PurchaserInfo();
foreach ($data as $k =>$v){
$v['project_id'] = $project_id;
$v['keyword'] = $keyword;
$v['email'] = json_encode($v['email'],JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$v['mobile'] = json_encode($v['mobile'],JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
$v['social_media'] = json_encode($v['social_media'],JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
// $v['created_at'] = date('Y-m-d H:i:s');
// $v['updated_at'] = $v['created_at'];
$param = $v;
$info = $purchaserInfoModel->read(['keyword'=>$keyword,'buyer'=>$v['buyer'],'project_id'=>$project_id],['id']);
if($info === false){
$purchaserInfoModel->add($param);
}
}
return true;
}
... ...
... ... @@ -33,11 +33,16 @@ class SyncFile extends Command
$errorFileModel = new ErrorFile();
$lists = $errorFileModel->list(['status'=>0]);//未同步成功的图片及文件
foreach ($lists as $k => $v){
if(strpos($v['path'], '/181/') !== false ){
$code = $this->synchronizationFiles($v['path']);
}else{
$code = $this->synchronizationFile($v['path']);
}
if((int)$code == 200){
echo date('Y-m-d H:i:s') . '编辑的path为:'. $v['path'] .',主键id:'. $v['id'] . PHP_EOL;
$errorFileModel->edit(['status'=>1],['id'=>$v['id']]);
}
}
echo date('Y-m-d H:i:s') . '编辑的end为:' . PHP_EOL;
return true;
... ... @@ -57,4 +62,13 @@ class SyncFile extends Command
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php';
return shell_exec($cmd);
}
public function synchronizationFiles($path_name){
//同步到大文件
$file_path = config('filesystems.disks.s3')['cdn'].$path_name;
$directoryPath = pathinfo($path_name, PATHINFO_DIRNAME);
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php';
return shell_exec($cmd);
}
}
... ...
... ... @@ -28,30 +28,29 @@ class SyncSubmitTask extends Command
public function handle()
{
$backup = false;
while (true) {
$task_id = $this->getTaskId();
if ($task_id > 2000000) {
$backup = true;
}
if (empty($task_id)) {
if ($backup) {
$this->backup();
$backup = false;
}
sleep(5);
$task_id = Redis::rpop('sync_submit_task');
if(!$task_id){
continue;
}
$this->output('任务' . $task_id . '开始');
$time = time();
DB::enableQueryLog(); //启用查询日志
//清除之前的查询日志
DB::flushQueryLog();
$task_info = SyncSubmitTaskModel::find($task_id);
if (empty($task_info) || $task_info->status) {
if (empty($task_info) || $task_info->status !=3) {
$this->output('任务不存在或者已执行');
continue;
}
try {
$project = Project::getProjectByDomain($task_info['data']['domain'] ?? '');
$task_info->project_id = $project->id;
SyncSubmitTaskService::handler($task_info);
$task_info->status = 1;
$task_info->save();
... ... @@ -76,20 +75,15 @@ class SyncSubmitTask extends Command
$this->output('任务失败:' . $e->getMessage());
}
}
}
public function getTaskId()
{
$task_id = Redis::rpop('sync_submit_task');
if (empty($task_id)) {
$ids = SyncSubmitTaskModel::where('status', 0)->limit(100)->pluck('id');
foreach ($ids as $id) {
Redis::lpush('sync_submit_task', $id);
$use_time = time() - $time;
if($use_time > 1){
//数据库查询
$this->output('任务用时:' .$use_time . ' | ' . json_encode(DB::getQueryLog(),JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
}
$task_id = Redis::rpop('sync_submit_task');
//清除之前的查询日志
DB::flushQueryLog();
}
return $task_id;
}
/**
... ... @@ -100,31 +94,4 @@ class SyncSubmitTask extends Command
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
return true;
}
/**
* 备份数据
* @author zbj
* @date 2024/1/23
*/
public function backup()
{
DB::beginTransaction();
try {
$table = (new SyncSubmitTaskModel())->getTable();
$new_table = $table . '_backup_' . date('Ymd');
//重命名当前表
Schema::rename($table, $new_table);
//克隆表数据
DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table);
DB::commit();
$this->output('数据备份成功');
} catch (\Exception $e) {
$this->output('数据备份失败' . $e->getMessage());
DB::rollBack();
}
return true;
}
}
... ...
<?php
namespace App\Console\Commands\Sync;
use App\Exceptions\InquiryFilterException;
use App\Models\Project\Project;
use App\Models\SyncSubmitTask\SyncSubmitTask as SyncSubmitTaskModel;
use App\Services\SyncSubmitTaskService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
/**
*
* Class SyncSubmitTask
* @package App\Console\Commands
* @author zbj
* @date 2023/11/28
*/
class SyncSubmitTaskDistribution extends Command
{
protected $signature = 'sync_submit_task_distribution';
protected $description = '询盘、访问异步任务分发';
public function handle()
{
while (true) {
$len = Redis::llen('sync_submit_task');
if (!$len) {
$max_id = SyncSubmitTaskModel::orderBy('id', 'desc')->value('id');
if ($max_id > 2000000) {
$this->backup();
} else {
$tasks = SyncSubmitTaskModel::where('status', 0)->limit(100)->get();
foreach ($tasks as $task) {
$task->status = 3;
$task->save();
Redis::lpush('sync_submit_task', $task->id);
}
}
}
}
}
/**
* 输出处理日志
*/
public function output($message): bool
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
return true;
}
/**
* 备份数据
* @author zbj
* @date 2024/1/23
*/
public function backup()
{
DB::beginTransaction();
try {
$table = (new SyncSubmitTaskModel())->getTable();
$new_table = $table . '_backup_' . date('Ymd');
//重命名当前表
Schema::rename($table, $new_table);
//克隆表数据
DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table);
//未入队的写到新表
$list = DB::table($new_table)->where('status', 0)->get();
$data = [];
foreach ($list as $task) {
$data[] = [
'type' => $task->type,
'data' => json_encode($task->data),
'created_at' => $task['created_at'],
'updated_at' => $task['updated_at'],
];
}
$data && SyncSubmitTaskModel::insert($data);
DB::commit();
$this->output('数据备份成功');
} catch (\Exception $e) {
$this->output('数据备份失败' . $e->getMessage());
DB::rollBack();
}
return $new_table ?? '';
}
}
... ...
<?php
namespace App\Console\Commands\Sync;
use App\Exceptions\InquiryFilterException;
use App\Models\Project\Project;
use App\Models\SyncSubmitTask\SyncSubmitTaskZbj as SyncSubmitTaskModel;
use App\Services\SyncSubmitTaskService;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Str;
/**
*
* Class SyncSubmitTask
* @package App\Console\Commands
* @author zbj
* @date 2023/11/28
*/
class SyncSubmitTaskZbj extends Command
{
protected $signature = 'sync_submit_task_zbj';
protected $description = '询盘、访问异步任务';
public function handle()
{
$backup = false;
while (true) {
$task_id = $this->getTaskId();
if ($task_id > 2000000) {
$backup = true;
}
if (empty($task_id)) {
if ($backup) {
$this->backup();
$backup = false;
}
sleep(5);
continue;
}
$this->output('任务' . $task_id . '开始');
$task_info = SyncSubmitTaskModel::find($task_id);
if (empty($task_info) || $task_info->status != 3) {
$this->output('任务不存在或者已执行');
continue;
}
try {
$project = Project::getProjectByDomain($task_info['data']['domain'] ?? '');
$task_info->project_id = $project->id;
SyncSubmitTaskService::handler($task_info, $task_info->created_at);
$task_info->status = 1;
$task_info->save();
$this->output('任务完成');
} catch (InquiryFilterException $e) {
$task_info->status = 1;
$task_info->is_filtered = 1;
$task_info->remark = $e->getMessage();
$task_info->save();
$this->output('任务完成');
} catch (\Exception $e) {
$task_info->retry = $task_info->retry + 1;
if ($task_info->retry >= 3) {
$task_info->status = 2;
$task_info->remark = Str::substr($e->getMessage(), 0, 200);
} else {
Redis::lpush('sync_submit_task_zbj', $task_id);
}
$task_info->save();
$this->output('任务失败:' . $e->getMessage());
}
}
}
public function getTaskId()
{
$task_id = Redis::rpop('sync_submit_task_zbj');
if (empty($task_id)) {
$ids = SyncSubmitTaskModel::where('status', 3)->limit(100)->pluck('id');
foreach ($ids as $id) {
Redis::lpush('sync_submit_task_zbj', $id);
}
$task_id = Redis::rpop('sync_submit_task_zbj');
}
return $task_id;
}
/**
* 输出处理日志
*/
public function output($message): bool
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
return true;
}
/**
* 备份数据
* @author zbj
* @date 2024/1/23
*/
public function backup()
{
DB::beginTransaction();
try {
$table = (new SyncSubmitTaskModel())->getTable();
$new_table = $table . '_backup_' . date('Ymd');
//重命名当前表
Schema::rename($table, $new_table);
//克隆表数据
DB::statement('CREATE TABLE ' . $table . ' LIKE ' . $new_table);
DB::commit();
$this->output('数据备份成功');
} catch (\Exception $e) {
$this->output('数据备份失败' . $e->getMessage());
DB::rollBack();
}
return true;
}
}
... ...
... ... @@ -10,6 +10,7 @@ use App\Models\Domain\DomainInfo;
use App\Models\Mail\Mail;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\ProjectKeyword;
use App\Models\Project\ProjectUpdateTdk;
use App\Models\User\User;
use App\Models\WebSetting\WebLanguage;
... ... @@ -199,7 +200,7 @@ class UpdateSeoTdk extends Command
if($table == 'gl_product'){
foreach ($map as $field){
$field_arr = explode('.', $field);
$query->orWhereRaw('JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") IS NULL OR JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") = ""');
$query->orWhereRaw('JSON_CONTAINS('.$field_arr[0].', "null", "$.'.$field_arr[1].'") OR JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") = ""');
}
}else{
foreach ($map as $field){
... ... @@ -375,7 +376,13 @@ class UpdateSeoTdk extends Command
$info = Cache::get($cache_key);
if(!$info){
$projectOptimizeModel = new DeployOptimize();
$info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description', 'main_keywords']);
$info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description']);
$projectKeywordModel = new ProjectKeyword();
$keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]);
$info['main_keyword'] = '';
if($keywordInfo === false){
$info['main_keyword'] = $keywordInfo['main_keyword'];
}
Cache::put($cache_key, $info, 600);
}
return $info;
... ... @@ -412,12 +419,12 @@ class UpdateSeoTdk extends Command
{
$str = '';
$info = $this->getDeployOptimize($project_id);
if (!empty($info['main_keywords'])) {
$main_keywords = explode("\r\n", $info['main_keywords']);
if (!empty($info['main_keyword'])) {
$main_keyword = explode("\r\n", $info['main_keyword']);
//随机取
shuffle($main_keywords);
$main_keywords = array_slice($main_keywords, 0, $num);
$str = implode(", ", $main_keywords);
shuffle($main_keyword);
$main_keyword = array_slice($main_keyword, 0, $num);
$str = implode(", ", $main_keyword);
}
return $str;
}
... ...
<?php
namespace App\Console\Commands\Tdk;
use App\Helper\Arr;
use App\Helper\Common;
use App\Helper\Gpt;
use App\Models\Ai\AiCommand;
use App\Models\Domain\DomainInfo;
use App\Models\Mail\Mail;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\ProjectKeyword;
use App\Models\Project\ProjectUpdateTdk;
use App\Models\User\User;
use App\Models\WebSetting\WebLanguage;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Str;
/**
* 指定跑某个项目
* Class InitProject
* @package App\Console\Commands
* @author zbj
* @date 2023/10/8
*/
class UpdateSeoTdkByTaskId extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update_seo_tdk_by {task_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = '一键生成tdk';
protected $project;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* '表' => [
* '指令key' => '表字段'
* ]
* @return array
* @author zbj
* @date 2023/11/3
*/
protected $maps = [
'gl_web_custom_template' => [
'page_title' => 'title',
'page_meta_keywords' => 'keywords',
'page_meta_description' => 'description',
],
'gl_product' => [
'product_title' => 'seo_mate.title',
'product_meta_keywords' => 'seo_mate.keyword',
'product_meta_description' => 'seo_mate.description',
],
'gl_product_category' => [
'product_cat_title' => 'seo_title',
'product_cat_meta_keywords' => 'seo_keywords',
'product_cat_meta_description' => 'seo_des',
],
'gl_blog' => [
'blog_title' => 'seo_title',
'blog_meta_keywords' => 'seo_keywords',
'blog_meta_description' => 'seo_description',
],
'gl_blog_category' => [
'blog_cat_title' => 'seo_title',
'blog_cat_meta_keywords' => 'seo_keywords',
'blog_cat_meta_description' => 'seo_des',
],
'gl_news' => [
'news_title' => 'seo_title',
'news_meta_keywords' => 'seo_keywords',
'news_meta_description' => 'seo_description',
],
'gl_news_category' => [
'news_cat_title' => 'seo_title',
'news_cat_meta_keywords' => 'seo_keywords',
'news_cat_meta_description' => 'seo_des',
],
'gl_product_keyword' => [
'tags_title' => 'seo_title',
'tags_meta_keywords' => 'seo_keywords',
'tags_meta_description' => 'seo_description',
'tags_content_title' => 'keyword_title',
'tags_content_description' => 'keyword_content',
]
];
/**
* topic-对相应字段
* @var array
*/
protected $topic_fields = [
'gl_web_custom_template' => 'name',
'gl_product' => 'title',
'gl_product_category' => 'title',
'gl_blog' => 'name',
'gl_blog_category' => 'name',
'gl_news' => 'name',
'gl_news_category' => 'name',
'gl_product_keyword' => 'title'
];
/**
* 使用核心关键词的key 数量
* @var array
*/
protected $core_keyword_keys = [
'page_meta_keywords' => 1,
'blog_cat_meta_keywords' => 8,
'news_cat_meta_keywords' => 8,
];
/**
* @return bool
*/
public function handle()
{
$task_id = $this->argument('task_id');
$task = ProjectUpdateTdk::where('status', ProjectUpdateTdk::STATUS_PENDING)->where('id', $task_id)->first();
if (!$task) {
echo date('Y-m-d H:i:s') . ' 任务不存在: ' . $task_id . PHP_EOL;
}
$project_id = $task->project_id;
echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL;
try {
$this->project = ProjectServer::useProject($project_id);
$this->seo_tdk($project_id, $task->id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
ProjectUpdateTdk::retry($task->id, $e->getMessage());
}
Cache::forget('project_deploy_optimize_info_' . $project_id);
echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL;
}
public function sendNotify($project_id, $route)
{
//获取当前项目的域名
$domainModel = new DomainInfo();
$domainInfo = $domainModel->read(['project_id'=>$project_id]);
if($domainInfo === false){
//获取测试域名
$deployBuildModel = new DeployBuild();
$buildInfo = $deployBuildModel->read(['project_id'=>$project_id]);
$this->param['domain'] = $buildInfo['test_domain'];
}else{
$this->param['domain'] = 'https://'.$domainInfo['domain'].'/';
}
$url = $this->param['domain'].'api/update_page/';
$param = [
'project_id' => $project_id,
'type' => 1,
'route' => $route,
'url' => [],
'language'=> [],
];
http_post($url, json_encode($param));
echo '更新中请稍后, 更新完成将会发送站内信通知更新结果!'. PHP_EOL;
}
public function seo_tdk($project_id, $task_id)
{
$notify_master = $notify_keyword = false;
//更新统计
$update = [];
$ai_commands = AiCommand::where('is_batch', 1)->select('key', 'scene', 'ai')->get()->toArray();
$ai_commands = Arr::setValueToKey($ai_commands, 'key');
foreach ($this->maps as $table => $map) {
$total_page = DB::connection('custom_mysql')->table($table)->count();
$update[$table] = ['total_page'=>$total_page, 'title'=>0, 'keyword'=>0, 'des'=>0,'keyword_title'=>0,'keyword_content'=>0];
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
$list = DB::connection('custom_mysql')->table($table)
->where(function ($query) use ($table, $map){
if($table == 'gl_product'){
foreach ($map as $field){
$field_arr = explode('.', $field);
$query->orWhereRaw('JSON_CONTAINS('.$field_arr[0].', "null", "$.'.$field_arr[1].'") OR JSON_EXTRACT('.$field_arr[0].', "$.'.$field_arr[1].'") = ""');
}
}else{
foreach ($map as $field){
$query->orWhereRaw($field . " IS NULL OR ".$field." = ''");
}
}
})->select('id')->get();
if (!empty($list)) {
$list = $list->toArray();
foreach ($list as $v) {
$v = (array)$v;
//缓存 在处理的项目数据 id
$cache_key = "seo_tdk_{$project_id}_{$table}_{$v['id']}";
if(!Redis::setnx($cache_key, 1)){
continue;
}
Redis::expire($cache_key, 120);
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
$v = DB::connection('custom_mysql')->table($table)->where('id', $v['id'])->first();
$v = (array)$v;
$data = [];
$json_field = '';
foreach ($map as $ai_key => $field) {
$field_arr = explode('.', $field);
if (count($field_arr) > 1) {
$json_field = $field_arr[0];
$value = json_decode($v[$field_arr[0]], true)[$field_arr[1]] ?? '';
} else {
$value = $v[$field] ?? '';
}
//已有值的 跳过
if ($value) {
echo $field.'已有值 跳过' . PHP_EOL;
continue;
}
//AI生成
if (!empty($ai_commands[$ai_key]['ai'])) {
$prompt = $this->getPrompt($project_id, $ai_commands[$ai_key]['ai'], $table, $v);
if(!$prompt){
continue;
}
if (count($field_arr) > 1) {
if($field_arr[1] == 'title'){
$update[$table]['title']++;
}elseif ($field_arr[1] == 'keyword'){
$update[$table]['keyword']++;
}elseif ($field_arr[1] == 'description'){
$update[$table]['des']++;
}
$data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt);
}else{
if($field == 'title' || $field == 'seo_title'){
$update[$table]['title']++;
}
if($field == 'keywords' || $field == 'seo_keywords'){
$update[$table]['keyword']++;
}
if($field == 'seo_description' || $field == 'description' || $field == 'seo_des'){
$update[$table]['des']++;
}
if($field == 'keyword_title'){
$update[$table]['keyword_title']++;
}
if($field == 'keyword_content'){
$update[$table]['keyword_content']++;
}
$data[$field] = $this->ai_send($prompt);
}
} else {
//直接使用topic
if (count($field_arr) > 1) {
$data[$field_arr[0]][$field_arr[1]] = $v[$this->topic_fields[$table]] ?? '';
//使用核心关键词
if(in_array($ai_key, array_keys($this->core_keyword_keys))){
$data[$field_arr[0]][$field_arr[1]] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]);
if(!empty($data[$field_arr[0]][$field_arr[1]])){
if($field_arr[1] == 'title'){
$data[$table]['title']++;
}elseif ($field_arr[1] == 'keyword'){
$data[$table]['keyword']++;
}elseif ($field_arr[1] == 'description'){
$data[$table]['des']++;
}
}
}
}else{
$data[$field] = $v[$this->topic_fields[$table]] ?? '';
//使用核心关键词
if(in_array($ai_key, array_keys($this->core_keyword_keys))){
$data[$field] = $this->mainKeywords($project_id, $this->core_keyword_keys[$ai_key]);
if(!empty($data[$field])){
if($field == 'title' || $field == 'seo_title'){
$update[$table]['title']++;
}
if($field == 'keywords' || $field == 'seo_keywords'){
$update[$table]['keyword']++;
}
if($field == 'seo_description' || $field == 'description' || $field == 'seo_des'){
$update[$table]['des']++;
}
if($field == 'keyword_title'){
$update[$table]['keyword_title']++;
}
if($field == 'keyword_content'){
$update[$table]['keyword_content']++;
}
}
}
}
}
}
if(!$data){
continue;
}
if($json_field){
$old_data = json_decode($v[$field_arr[0]], true);
foreach ($old_data ?: [] as $kk=>$vv){
empty($data[$json_field][$kk]) && $data[$json_field][$kk] = $vv;
}
$data[$json_field] = json_encode($data[$json_field]);
}
DB::connection('custom_mysql')->table($table)->where(['id' => $v['id']])->update($data);
if($table == 'gl_product_keyword'){
$notify_keyword = true;
}else{
$notify_master = true;
}
}
}
}
ProjectUpdateTdk::finish($task_id, $update);
//通知C端更新界面
$notify_master && $this->sendNotify($project_id, 1); //通知主站更新
$notify_keyword && $this->sendNotify($project_id, 4); //通知聚合页更新
}
public function getPrompt($project_id, $prompt, $table, $data){
if(strpos($prompt, '{topic}') !== false){
$topic = $data[$this->topic_fields[$table]] ?? '';
if(!$topic){
echo 'topic为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace('{topic}', $topic, $prompt);
}
if(strpos($prompt, '{keyword}') !== false) {
$keyword = $this->mainKeywords($project_id, 1);
if(!$keyword){
echo '核心关键词为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace('{keyword}', $keyword, $prompt);
}
if(strpos($prompt, '{company name}') !== false) {
$company_name = $this->companyName($project_id);
if(!$company_name){
echo '公司英文全称为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace('{company name}', $company_name, $prompt);
}
$prompt .= '.Please answer in ' . $this->getLang();
return $prompt;
}
public function getDeployOptimize($project_id){
$cache_key = 'project_deploy_optimize_info_' . $project_id;
$info = Cache::get($cache_key);
if(!$info){
$projectOptimizeModel = new DeployOptimize();
$info = $projectOptimizeModel->read(['project_id' => $project_id], ['id', 'company_en_name', 'company_en_description']);
$projectKeywordModel = new ProjectKeyword();
$keywordInfo = $projectKeywordModel->read(['project_id'=>$project_id]);
$info['main_keyword'] = '';
if($keywordInfo === false){
$info['main_keyword'] = $keywordInfo['main_keyword'];
}
Cache::put($cache_key, $info, 600);
}
return $info;
}
/**
* @remark :获取公司英文名称
* @name :companyName
* @author :lyh
* @method :post
* @time :2023/10/30 11:22
*/
public function companyName($project_id, $key = '')
{
$data = [
'product_long_description',
];
$info = $this->getDeployOptimize($project_id);
if (in_array($key, $data)) {
return $info['company_en_description'];
} else {
return $info['company_en_name'];
}
}
/**
* @remark :获取公司核心关键词
* @name :mainKeywords
* @author :lyh
* @method :post
* @time :2023/10/30 11:22
*/
public function mainKeywords($project_id, $num)
{
$str = '';
$info = $this->getDeployOptimize($project_id);
if (!empty($info['main_keyword'])) {
$main_keyword = explode("\r\n", $info['main_keyword']);
//随机取
shuffle($main_keyword);
$main_keyword = array_slice($main_keyword, 0, $num);
$str = implode(", ", $main_keyword);
}
return $str;
}
public function getLang(){
$lang = WebLanguage::getLangById($this->project['main_lang_id']??1);
return $lang['english'] ?? 'English';
}
/**
* @remark :AI发送
* @name :ai_send
* @author :lyh
* @method :post
* @time :2023/8/19 10:40
*/
public function ai_send($prompt)
{
$text = Gpt::instance()->openai_chat_qqs($prompt);
$text = Common::deal_keywords($text);
$text = Common::deal_str($text);
//包含这写字 重新生成
if(Str::contains(Str::lower($text), ['[your brand]', '[brand name]'])){
return $this->ai_send($prompt);
}
return $text;
}
/**
* @remark :发送站内信
* @name :send_message
* @author :lyh
* @method :post
* @time :2023/11/4 10:22
*/
public function send_message($project_id){
$user = new User();
$userInfo = $user->read(['project_id'=>$project_id,'role_id'=>0]);
$data["title"] = "seo更新通知---完成";
$data["user_list"] = $userInfo['id'];
$data["content"] = "seo更新成功,更新完成时间".date('Y-m-d H:i:s');
$mail = new Mail();
return $mail->add($data);
}
}
... ...
<?php
/**
* @remark :
* @name :PopularTemplateLabel.php
* @author :lyh
* @method :post
* @time :2024/6/3 17:00
*/
namespace App\Console\Commands\TemplateLabel;
use App\Models\Template\Template;
use App\Models\Template\TemplateLabel as TemplateLabelModel;
use App\Models\Template\TemplateModule;
use Illuminate\Console\Command;
class PopularTemplateLabel extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'popular_template_label';
/**
* The console command description.
*
* @var string
*/
protected $description = '设置热门label';
/**
* @remark :执行脚本
* @name :handle
* @author :lyh
* @method :post
* @time :2024/6/3 17:01
*/
public function handle(){
$this->setTemplate();
$this->setTemplateModule();
return true;
}
/**
* @remark :公共模块热门模块
* @name :setTemplate
* @author :lyh
* @method :post
* @time :2024/6/3 15:56
*/
public function setTemplate(){
$templateModel = new Template();
$info = $templateModel->list(['test_model'=>0,'number'=>['<>',0]],'number',['id'],'desc',50);
if(empty($info)){
return true;
}else{
//清除当前所有最新标签
$labelModel = new TemplateLabelModel();
$labelModel->del(['name'=>'热门','type'=>1]);
$data = [];
foreach ($info as $v){
$data[] = [
'name'=>'热门',
'type'=>1,
'template_id'=>$v['id'],
'manager_id'=>0,
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
}
//设置为最新
$labelModel->insert($data);
}
return true;
}
/**
* @remark :左侧模块
* @name :templateModule
* @author :lyh
* @method :post
* @time :2024/6/3 15:54
*/
public function setTemplateModule(){
$templateModuleModel = new TemplateModule();
$moduleInfo = $templateModuleModel->list(['test_model'=>0,'number'=>['<>',0]],'id',['id']);
if(empty($moduleInfo)){
return true;
}else{
//清除当前所有最新标签
$labelModel = new TemplateLabelModel();
$labelModel->del(['name'=>'热门','type'=>2]);
$moduleData = [];
foreach ($moduleInfo as $k => $v){
$moduleData[] = [
'name'=>'热门',
'type'=>2,
'template_id'=>$v['id'],
'manager_id'=>0,
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
}
//设置为最新
$labelModel->insert($moduleData);
}
return true;
}
}
... ...
<?php
/**
* @remark :
* @name :TemplateLabel.php
* @author :lyh
* @method :post
* @time :2024/6/3 11:33
*/
namespace App\Console\Commands\TemplateLabel;
use App\Models\Template\Template;
use App\Models\Template\TemplateModule;
use Illuminate\Console\Command;
use App\Models\Template\TemplateLabel as TemplateLabelModel;
class TemplateLabel extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'template_label';
/**
* The console command description.
*
* @var string
*/
protected $description = '设置label';
/**
* @remark :执行脚本
* @name :handle
* @author :lyh
* @method :post
* @time :2024/6/3 11:35
*/
public function handle(){
//获取最近7天模版的记录
$start_time = now()->subDays(90)->startOfDay()->toDateString();
$end_time = now()->startOfDay()->toDateString();
$this->setTemplateModule($start_time,$end_time);
$this->setTemplate($start_time,$end_time);
return true;
}
/**
* @remark :公共模块
* @name :setTemplate
* @author :lyh
* @method :post
* @time :2024/6/3 15:56
*/
public function setTemplate($start_time,$end_time){
$templateModel = new Template();
$info = $templateModel->list(['created_at'=>['between',[$start_time,$end_time]],'test_model'=>0],'id',['id']);
if(empty($info)){
return true;
}else{
//清除当前所有最新标签
$labelModel = new TemplateLabelModel();
$labelModel->del(['name'=>'最新','type'=>1]);
$data = [];
foreach ($info as $k => $v){
$data[] = [
'name'=>'最新',
'type'=>1,
'template_id'=>$v['id'],
'manager_id'=>0,
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
}
//设置为最新
$labelModel->insert($data);
}
return true;
}
/**
* @remark :左侧模块
* @name :templateModule
* @author :lyh
* @method :post
* @time :2024/6/3 15:54
*/
public function setTemplateModule($start_time,$end_time){
$templateModuleModel = new TemplateModule();
$moduleInfo = $templateModuleModel->list(['created_at'=>['between',[$start_time,$end_time]],'test_model'=>0],'id',['id']);
if(empty($moduleInfo)){
return true;
}else{
//清除当前所有最新标签
$labelModel = new TemplateLabelModel();
$labelModel->del(['name'=>'最新','type'=>2]);
$moduleData = [];
foreach ($moduleInfo as $k => $v){
$moduleData[] = [
'name'=>'最新',
'type'=>2,
'template_id'=>$v['id'],
'manager_id'=>0,
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s')
];
}
//设置为最新
$labelModel->insert($moduleData);
}
return true;
}
}
... ...
... ... @@ -7,39 +7,29 @@
*/
namespace App\Console\Commands\Test;
use App\Helper\Common;
use App\Models\Blog\Blog;
use App\Models\Com\KeywordVideoTask;
use App\Models\Com\KeywordVideoTaskLog;
use App\Models\Devops\ServerConfig;
use App\Models\Domain\DomainInfo;
use App\Models\Devops\Servers;
use App\Models\Devops\ServersIp;
use App\Models\File\File;
use App\Models\File\File as FileModel;
use App\Models\File\Image;
use App\Models\File\Image as ImageModel;
use App\Models\Manage\BelongingGroup;
use App\Models\Manage\Dept;
use App\Models\Manage\EntryPosition;
use App\Models\Manage\ManageHr;
use App\Models\Nav\BNav;
use App\Models\Nav\BNavGroup;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\DeployOptimize;
use App\Models\Project\MinorLanguages;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BCustomTemplate;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCom;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\Setting;
use App\Models\WebSetting\WebSettingService;
use App\Models\Purchaser\PurchaserInfo;
use App\Services\AmazonS3Service;
use App\Services\ProjectServer;
use App\Services\SyncService;
use GuzzleHttp\Client;
use App\Utils\EncryptUtils;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Schema;
class Demo extends Command
{
... ... @@ -56,84 +46,16 @@ class Demo extends Command
* @var string
*/
protected $description = 'demo';
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$projectModel = new Project();
$list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]);
$data = [];
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
DB::table('gl_web_template_com')->truncate();
$templateComModel = new BTemplateCom();
$templateComModel->truncate();
$this->saveTemplateCom($v['id']);
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
public function saveTemplateCom($project_id){
//获取当前项目选择的模版
$settingModel = new Setting();
$settingInfo = $settingModel->read(['project_id'=>$project_id]);
echo date('Y-m-d H:i:s') . '设置的模版:'.json_encode($settingInfo) . PHP_EOL;
if($settingInfo !== false){
$templateCommonModel = new BTemplateCommon();
$commonList = $templateCommonModel->list(['template_id'=>['in',[$settingInfo['template_id'],0]]]);
if(!empty($commonList)){
foreach ($commonList as $v){
$typeArr = [1, 2, 3];
foreach ($typeArr as $type){
if($type == 1){
$headData = [
'project_id'=>$v['project_id'],
'source'=>$v['type'] == 1 ? 99 : $v['type'],
'common_type'=>1,
'template_id'=>$v['template_id'],
'html'=>$v['head_html'],
'html_style'=>$v['head_css'],
'is_custom'=>$v['is_custom'],
'is_list'=>$v['is_list']
];
$templateComModel = new BTemplateCom();
$templateComModel->add($headData);
}elseif ($type == 2){
$footerData = [
'project_id'=>$v['project_id'],
'source'=>$v['type'] == 1 ? 99 : $v['type'],
'common_type'=>2,
'template_id'=>$v['template_id'],
'html'=>$v['footer_html'],
'html_style'=>$v['footer_css'],
'is_custom'=>$v['is_custom'],
'is_list'=>$v['is_list']
];
$templateComModel = new BTemplateCom();
$templateComModel->add($footerData);
}elseif ($type == 3){
$otherData = [
'project_id'=>$v['project_id'],
'source'=>$v['type'] == 1 ? 99 : $v['type'],
'common_type'=>3,
'template_id'=>$v['template_id'],
'html'=>$v['other'],
'html_style'=>null,
'is_custom'=>$v['is_custom'],
'is_list'=>$v['is_list']
];
$templateComModel = new BTemplateCom();
$templateComModel->add($otherData);
}
}
public function handle(){
$this->synchronizationFile('/upload/m/file/2024-07/tongli-haiyuan-keywords.pdf');
}
}
}
return true;
public function synchronizationFile($path_name){
//同步到大文件
$file_path = config('filesystems.disks.cos')['cdn1'].$path_name;
$directoryPath = pathinfo($path_name, PATHINFO_DIRNAME);
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php';
return shell_exec($cmd);
}
}
... ...
<?php
/**
* @remark :
* @name :HeaderFooter.php
* @author :lyh
* @method :post
* @time :2024/5/21 9:42
*/
namespace App\Console\Commands\Test;
use App\Models\Template\BTemplateCom;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\Setting;
use Illuminate\Console\Command;
/**
* @remark :头部底部分开 脚本数据
* @name :HeaderFooter
* @author :lyh
* @method :post
* @time :2024/5/21 9:42
*/
class HeaderFooter extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'common_header';
/**
* The console command description.
*
* @var string
*/
protected $description = 'common_header';
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$projectModel = new Project();
$list = $projectModel->list(['delete_status'=>0,'type'=>['!=',0]]);
$data = [];
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
DB::table('gl_web_template_com')->truncate();
$this->saveTemplateCom($v['id']);
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :头部底部分开脚本
* @name :saveTemplateCom
* @author :lyh
* @method :post
* @time :2024/6/17 14:46
*/
public function saveTemplateCom($project_id){
//获取当前项目选择的模版
$settingModel = new Setting();
$settingInfo = $settingModel->read(['project_id'=>$project_id]);
echo date('Y-m-d H:i:s') . '设置的模版:'.json_encode($settingInfo) . PHP_EOL;
if($settingInfo !== false){
$templateCommonModel = new BTemplateCommon();
$commonList = $templateCommonModel->list(['template_id'=>['in',[$settingInfo['template_id'],0]]]);
if(!empty($commonList)){
foreach ($commonList as $v){
$typeArr = [1, 2, 3];
foreach ($typeArr as $type){
if($type == 1){
$headData = [
'project_id'=>$v['project_id'],
'source'=>$v['type'] == 1 ? 99 : $v['type'],
'common_type'=>1,
'template_id'=>$v['template_id'],
'html'=>$v['head_html'],
'html_style'=>$v['head_css'],
'is_custom'=>$v['is_custom'],
'is_list'=>$v['is_list']
];
$templateComModel = new BTemplateCom();
$templateComModel->add($headData);
}elseif ($type == 2){
$footerData = [
'project_id'=>$v['project_id'],
'source'=>$v['type'] == 1 ? 99 : $v['type'],
'common_type'=>2,
'template_id'=>$v['template_id'],
'html'=>$v['footer_html'],
'html_style'=>$v['footer_css'],
'is_custom'=>$v['is_custom'],
'is_list'=>$v['is_list']
];
$templateComModel = new BTemplateCom();
$templateComModel->add($footerData);
}elseif ($type == 3){
$otherData = [
'project_id'=>$v['project_id'],
'source'=>$v['type'] == 1 ? 99 : $v['type'],
'common_type'=>3,
'template_id'=>$v['template_id'],
'html'=>$v['other'],
'html_style'=>null,
'is_custom'=>$v['is_custom'],
'is_list'=>$v['is_list']
];
$templateComModel = new BTemplateCom();
$templateComModel->add($otherData);
}
}
}
}
}
return true;
}
}
... ...
<?php
/**
* @remark :
* @name :ProductFileUpload.php
* @author :lyh
* @method :post
* @time :2024/6/18 15:43
*/
namespace App\Console\Commands\Test;
use App\Models\File\File;
use App\Models\Product\Product;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class ProductFileUpload extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'files_upload {project_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = '重新上传文件获取文件后缀';
/**
* @remark :
* @name :handle
* @author :lyh
* @method :post
* @time :2024/6/18 15:46
*/
public function handle(){
$project_id = $this->argument('project_id');
ProjectServer::useProject($project_id);
$productModel = new Product();
$lists = $productModel->list(['status'=>1,'id'=>['<=',106]]);
foreach ($lists as $k => $v){
if(!empty($v['files']) && !empty($v['files']['url'])){
$url = str_replace_url($v['files']['url']);
//获取当前图片的原名称
$files = new File();
$fileInfo = $files->read(['path'=>$url,'project_id'=>$project_id]);
if($fileInfo === false){
continue;
}
$newName = $fileInfo['name'];
$code = $this->synchronizationFile($url,$newName);
if((int)$code == 200){
echo date('Y-m-d H:i:s') . '编辑的path为:'. $url .',主键id:'. $v['id'] . PHP_EOL;
$v['files']['url'] = preg_replace('#/[^/]*$#', '/', $url).$newName;
$productModel->edit(['files'=>json_encode($v['files'])],['id'=>$v['id']]);
}
}
}
DB::disconnect('custom_mysql');
}
/**
* @remark :指定同步文件到獨立177服務器
* @name :synchronizationFile
* @author :lyh
* @method :post
* @time :2024/4/8 11:10
*/
public function synchronizationFile($path_name,$newName){
//同步到大文件
$file_path = config('filesystems.disks.cos')['cdn1'].$path_name;
echo date('Y-m-d H:i:s') . '编辑的path为:'. $file_path. PHP_EOL;
$directoryPath = pathinfo($path_name, PATHINFO_DIRNAME);
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" -F "file_name='.$newName.'" https://v6-file.globalso.com/fileUploads.php';
return shell_exec($cmd);
}
}
... ...
<?php
/**
* @remark :
* @name :SyncProjectFile.php
* @author :lyh
* @method :post
* @time :2024/6/18 14:53
*/
namespace App\Console\Commands\Test;
use App\Models\File\ErrorFile;
use App\Models\File\File;
use Illuminate\Console\Command;
class SyncProjectFile extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'sync_project_file {project_id}';
/**
* The console command description.
*
* @var string
*/
protected $description = '同步图片与文件';
public function handle(){
$project_id = $this->argument('project_id');
$fileModel = new File();
$lists = $fileModel->list(['project_id'=>$project_id]);//未同步成功的图片及文件
foreach ($lists as $k => $v){
if(strpos($v['path'], '/181/') !== false ){
$code = $this->synchronizationFiles($v['path']);
}else{
$code = $this->synchronizationFile($v['path']);
}
if((int)$code == 200){
echo date('Y-m-d H:i:s') . '编辑的path为:'. $v['path'] .',主键id:'. $v['id'] . PHP_EOL;
}
}
echo date('Y-m-d H:i:s') . '编辑的end为:' . PHP_EOL;
return true;
}
/**
* @remark :指定同步文件到獨立177服務器
* @name :synchronizationFile
* @author :lyh
* @method :post
* @time :2024/4/8 11:10
*/
public function synchronizationFile($path_name){
//同步到大文件
$file_path = config('filesystems.disks.cos')['cdn1'].$path_name;
$directoryPath = pathinfo($path_name, PATHINFO_DIRNAME);
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php';
return shell_exec($cmd);
}
public function synchronizationFiles($path_name){
//同步到大文件
$file_path = config('filesystems.disks.s3')['cdn'].$path_name;
$directoryPath = pathinfo($path_name, PATHINFO_DIRNAME);
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$directoryPath.'" https://v6-file.globalso.com/upload.php';
return shell_exec($cmd);
}
}
... ...
... ... @@ -93,4 +93,9 @@ class TdkTest extends Command
}
}
}
public function ceshi(){
//under_ceshi
$model = new Cesjo();
}
}
... ...
... ... @@ -34,108 +34,24 @@ class Temp extends Command
*/
protected $description = '临时脚本';
public function handle()
{
$domain_model = new DomainInfo();
$notify_model = new Notify();
$project_model = new Project();
public function handle(){
ProjectServer::useProject(1515);
$domain_list = $domain_model->list(['amp_status' => 1]);
foreach ($domain_list as $info) {
if ($info['project_id'] > 0) {
$notify_info = $notify_model->read(['project_id' => $info['project_id'], 'type' => 3]);
if (!$notify_info) {
$products = Product::select(['id','content'])->get();
$domain_array = parse_url($info['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$amp_domain = implode('.', $host_array);
foreach ($products as $product){
$content = $product->content;
$content = str_replace('<h1','<h2', $content);
$content = str_replace('</h1','</h2', $content);
$project_info = $project_model->read(['id' => $info['project_id']]);
$product->content = $content;
$product->save();
$notify_model->add([
'project_id' => $info['project_id'],
'type' => 3,
'data' => json_encode(['domain' => $amp_domain, 'url' => [], 'language' => []]),
'server_id' => $project_info['serve_id'],
]);
}
}
}
$this->output('productID:'.$product->id.',success');
}
// public function handle()
// {
// $domain_model = new DomainInfo();
// $server_model = new ServerConfig();
// $project_model = new Project();
//
// $domain_list = $domain_model->list(['domain' => ['like', 'www.%']], 'id', ['id', 'domain', 'project_id'], 'asc');
// foreach ($domain_list as $info) {
// $this->output('domain:' . $info['domain'] . ',开始');
//
// $project_info = $project_model->read(['id' => $info['project_id']], 'serve_id');
// if ($project_info === false) {
// $this->output('获取项目数据失败');
// continue;
// }
//
// $server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
// if ($server_info === false) {
// $this->output('获取服务器数据失败');
// continue;
// }
//
// $domain_array = parse_url($info['domain']);
// $host = $domain_array['host'] ?? $domain_array['path'];
// $host_array = explode('.', $host);
// if (count($host_array) <= 2) {
// array_unshift($host_array, 'm');
// } else {
// $host_array[0] = 'm';
// }
// $amp_domain = implode('.', $host_array);
// if (!$this->check_cname($amp_domain, $server_info)) {
// $this->output('AMP站点域名' . $amp_domain . '未解析至目标服务器');
// continue;
// }
//
// $api_url = 'http://' . $server_info['init_domain'] . '/api/createSiteAmp';
// $api_param = [
// 'domain' => $info['domain'],
// 'private_key' => '',
// 'cert' => ''
// ];
//
// try {
// $rs = HttpUtils::get($api_url, $api_param);
// $rs = json_decode($rs, true);
// if (isset($rs['status']) && $rs['status'] == 200) {
// $this->output('创建AMP站点成功');
// } else {
// $this->output($rs['message'] ?? '');
// continue;
// }
// } catch (\Exception | GuzzleException $e) {
// errorLog('创建AMP站点', $api_param, $e);
// $this->output('创建AMP站点失败');
// continue;
// }
//
// $data = [
// 'amp_status' => 1,
// 'amp_type' => 1,
// ];
// $domain_model->edit($data, ['id' => $info['id']]);
// }
//
// echo '成功' . PHP_EOL;
// }
$this->output('end');
}
public function check_cname($domain, $server_info)
{
... ... @@ -147,7 +63,7 @@ class Temp extends Command
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkA = strpos($line, $server_info['host']) !== false;
$checkA = strpos($line, $server_info['ip']) !== false;
if ($checkA) {
return $domain;
}
... ... @@ -160,7 +76,7 @@ class Temp extends Command
$output = explode(PHP_EOL, $process->getOutput());
foreach ($output as $line) {
if ($line) {
$checkCname = (strpos($line, $server_info['init_domain']) !== false);
$checkCname = (strpos($line, $server_info['domain']) !== false);
if ($checkCname) {
return $domain;
}
... ...
... ... @@ -10,11 +10,16 @@ use App\Models\HomeCount\Count;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Nav\BNav;
use App\Models\Nav\BNavGroup;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use App\Models\SyncSubmitTask\SyncSubmitTask as SyncSubmitTaskModel;
use App\Models\WebSetting\Translate as TranslateModel;
use App\Models\WebSetting\WebLanguage;
use App\Services\ProjectServer;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* Class Test
... ... @@ -53,6 +58,19 @@ class Test extends Command
*/
public function handle()
{
$date = '2024-05-16';
$list = $this->getProjectList();
foreach ($list as $item){
ProjectServer::useProject($item['project_id']);
//pv统计
$pv_num = $this->pv_num($date);
//ip统计
$ip_num = $this->ip_num($date);
echo $item['project_id'] . ',pv:' . $pv_num . ',ip:' . $ip_num . PHP_EOL;
}
exit;
$i=0;
while (true){
... ... @@ -167,4 +185,78 @@ class Test extends Command
$arr['country'] = json_encode($top20);
return $arr;
}
protected function getProjectList($type = 1){
$ru_lang_id = WebLanguage::getIdByLang('ru');
//推广项目
$list = Project::with('domainInfo')
->leftJoin('gl_project_deploy_optimize as pdo', 'pdo.project_id', '=', 'gl_project.id')
->leftJoin('gl_project_online_check as poc', 'poc.project_id', '=', 'gl_project.id')
->where('pdo.domain', '>', 0)
->where('poc.qa_status', OnlineCheck::STATUS_ONLINE_TRUE)
->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
->where('gl_project.is_upgrade', 0) //非升级项目
->where('gl_project.main_lang_id', '<>', $ru_lang_id) //非俄语站
->where(function ($query) use ($type) {
if($type == 1){
//1-3个月项目
$startTime = Carbon::now()->addMonths(-4)->toDateString();
$endTime = Carbon::now()->addMonths(-1)->toDateString();
$query->whereBetween('pdo.start_date', [$startTime,$endTime]);
}elseif($type == 2){
//4-8个月项目
$startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
$endTime = Carbon::now()->addMonths(-4)->endOfDay()->toDateTimeString();
$query->whereBetween('pdo.start_date', [$startTime,$endTime]);
}else{
//大于9个月项目
$startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
$query->where('pdo.start_date', '<', $startTime);
}
})->select(['pdo.project_id','gl_project.main_lang_id','gl_project.id'])
->orderBy('project_id')
->get();
//其他地方在引流的域名
$other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
$data = [];
foreach ($list as $project) {
$lang = WebLanguage::getLangById($project['main_lang_id']??1)['short'];
if(empty($project->domainInfo['domain'])){
continue;
}
//其他地方在引流就不再引流了
if(in_array($project->domainInfo['domain'], $other)){
continue;
}
$data[] = [
'project_id' => $project['project_id'],
'domain' => 'https://' . $project->domainInfo['domain'] . '/',
'lang' => $lang
];
}
return $data;
}
/**
* @name :(统计pv)pv_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function pv_num($yesterday){
$pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->where('updated_date', $yesterday)->count();
return $pv;
}
/**
* @name :(统计ip)ip_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function ip_num($yesterday)
{
$ip = DB::connection('custom_mysql')->table('gl_customer_visit')->where('updated_date', $yesterday)->count();
return $ip;
}
}
... ...
<?php
/**
* @remark :
* @name :Translate.php
* @author :lyh
* @method :post
* @time :2024/5/21 9:32
*/
namespace App\Console\Commands\Test;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplateCom;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\Setting;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class Translate extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'translate';
/**
* The console command description.
*
* @var string
*/
protected $description = 'translate';
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['id'=>452]);
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$translateModel = new \App\Models\WebSetting\Translate();
$translateList = $translateModel->list(['id'=>['between',[150000,200000]]],'id',['id','url']);
if(!empty($translateList)){
foreach ($translateList as $value){
echo date('Y-m-d H:i:s') . '数据路由:'.$value['url'] . PHP_EOL;
$data = $this->getRouteSource($value['url']);
if($data === false){
continue;
}
$rs = $translateModel->edit($data,['id'=>$value['id']]);
gc_collect_cycles();
}
}
DB::disconnect('custom_mysql');
}
DB::disconnect('custom_mysql');
}
/**
* @remark :根据路由获取source+source_id
* @name :getRouteSource
* @author :lyh
* @method :post
* @time :2024/5/17 15:11
*/
public function getRouteSource($route){
$data = ['source'=>0,'source_id'=>0,'is_list'=>0,'is_custom'=>0];
if(strtolower($route) == 'all'){
return $data;
}
if($route == '/'){
$data['source'] = 1;
return $data;
}
$route = $this->handleRoute($route);
$routeModel = new RouteMap();
$routeInfo = $routeModel->read(['route'=>$route]);
if($routeInfo === false){
return false;
}
return $this->resultData($routeInfo,$data);
}
/**
* @remark :处理路由
* @name :handleRoute
* @author :lyh
* @method :post
* @time :2024/1/18 17:25
*/
public function handleRoute($url){
$str = trim($url,'/');
$route = 'index';
if(!empty($str)){
$arr = explode('/',$str);
$num = count($arr);
if($num == 1){
$route = $arr[0];
}elseif ($num == 2){
if(ctype_digit($arr[1])){//是数字的情况
$route = $arr[0];
}else{
$route = $arr[1];
}
}elseif($num == 3){
if(ctype_digit($arr[2])){//是数字的情况
$route = $arr[0];
}else{
if($arr[2] == 'page'){
$route = $arr[1];
}else{
$route = $arr[0];
}
}
}elseif ($num == 4){
if(ctype_digit($arr[3])){//是数字的情况
$route = $arr[1];
}
}
}
return $route;
}
/**
* @remark :返回数据
* @name :resultData
* @author :lyh
* @method :post
* @time :2024/5/20 11:54
*/
public function resultData($routeInfo,$data){
if($routeInfo['source'] == RouteMap::SOURCE_PAGE){
if($routeInfo['source_id']){
$data = ['source'=>9,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_PRODUCT){
if($routeInfo['source_id']){
$data = ['source'=>2,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_PRODUCT_CATE){
if($routeInfo['source_id']){
$data = ['source'=>2,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_BLOG){
if($routeInfo['source_id']){
$data = ['source'=>3,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_BLOG_CATE){
if($routeInfo['source_id']){
$data = ['source'=>3,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_NEWS){
if($routeInfo['source_id']){
$data = ['source'=>4,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_NEWS_CATE){
if($routeInfo['source_id']){
$data = ['source'=>4,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>0];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_MODULE){
if($routeInfo['source_id']){
$data = ['source'=>7,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>1];
}
}
if($routeInfo['source'] == RouteMap::SOURCE_MODULE_CATE){
if($routeInfo['source_id']){
$data = ['source'=>7,'source_id'=>$routeInfo['source_id'],'is_list'=>1,'is_custom'=>1];
}
}
return $data;
}
}
... ...
... ... @@ -50,12 +50,14 @@ class UpdateProductCategory extends Command
public function handle(){
//获取所有项目
$projectModel = new Project();
$list = $projectModel->list(['id'=>['in',[621]]],'id',['id']);
$list = $projectModel->list(['id'=>978],'id',['id']);
echo date('Y-m-d H:i:s') . ' start: ' . json_encode($list) . PHP_EOL;
try {
foreach ($list as $v) {
echo date('Y-m-d H:i:s') . ' start: ' . $v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$cateRelatedModel = new CategoryRelated();
$cateRelatedModel->truncate();
$this->getUpdateProductCategory();
DB::disconnect('custom_mysql');
}
... ... @@ -74,7 +76,7 @@ class UpdateProductCategory extends Command
*/
public function getUpdateProductCategory(){
$productModel = new Product();
$lists = $productModel->list(['status'=>1],'id',['id','category_id']);
$lists = $productModel->list(['deleted_at'=>null],'id',['id','category_id']);
foreach ($lists as $k => $v){
if(!empty($v['category_id'])){
$this->handleCategory($v['id'],$v['category_id']);
... ... @@ -96,8 +98,10 @@ class UpdateProductCategory extends Command
$categoryModel = new Category();
$info = $categoryModel->read(['id'=>$v],['id']);
if($info === false){
$cateRelatedModel = new CategoryRelated();
$cateRelatedModel->del(['cate_id'=>$v]);
continue;
}else{
}
//更新关联表
$cateRelatedModel = new CategoryRelated();
$relateInfo = $cateRelatedModel->read(['product_id'=>$id,'cate_id'=>$v]);
... ... @@ -107,5 +111,4 @@ class UpdateProductCategory extends Command
}
}
}
}
}
... ...
... ... @@ -20,6 +20,7 @@ use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
/**
* @remark :更新所有项目的路由
... ... @@ -53,11 +54,12 @@ class UpdateRoute extends Command
*/
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['id'=>688]);
$list = $projectModel->list(['id'=>['in',[664]]]);
$data = [];
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
// $this->getProduct();
$this->setProductKeyword();
DB::disconnect('custom_mysql');
}
... ... @@ -105,29 +107,83 @@ class UpdateRoute extends Command
if(!empty($lists)){
foreach ($lists as $v){
if(!empty($v['route'])){
// $tag = "-tag";
// if ((substr($v['route'], -strlen($tag)) === $tag)) {
// echo date('Y-m-d H:i:s') . '拼接 :'.$v['id'] . PHP_EOL;
// $route = Translate::tran($v['route'], 'en').$tag;
// // 如果不是以 '-tag' 结尾,则拼接上 '-tag'
// $route = trim($v['route'],'-tag');
// $route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']);
// $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
// }else{
// $route = Translate::tran($v['title'], 'en').$tag;
// $route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']);
// $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
// }
echo date('Y-m-d H:i:s') . 'route :'.$v['id'] . PHP_EOL;
continue;
}else{
echo date('Y-m-d H:i:s') . 'route :'.$v['id'] . PHP_EOL;
$route = Translate::tran($v['title'], 'en');
echo date('Y-m-d H:i:s') . 'route :'.$route . PHP_EOL;
$route = RouteMap::setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']);
if(!empty($route)){
echo date('Y-m-d H:i:s') . $route . PHP_EOL;
$route = $this->setRoute($route, RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $v['project_id']);
$keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
}
// echo date('Y-m-d H:i:s') . 'end :' . PHP_EOL;
}
}
}
}
/**
* @param $title
* @param $source
* @param $source_id
* @param int $project_id
* @return bool
* @throws \Exception
* @author zbj
* @date 2023/4/17
*/
public static function setRoute($title, $source, $source_id, $project_id = 0){
$route = self::generateRoute($title, $source, $source_id, $project_id);
if(!$route){
throw new \Exception('路由生成失败');
}
try {
$route_map = RouteMap::where('project_id', $project_id)->where('source_id', $source_id)->where('source', $source)->first();
if(!$route_map){
$route_map = new RouteMap();
$route_map->source = $source;
$route_map->source_id = $source_id;
$route_map->project_id = $project_id;
}
$route_map->route = $route;
$route_map->save();
}catch (\Exception $e){
throw new \Exception('路由映射失败');
}
return $route;
}
/**
* 生成路由标识
* @param $title
* @param $source
* @param $source_id
* @param $project_id
* @return string
* @author zbj
* @date 2023/4/17
*/
public static function generateRoute($title, $source, $source_id, $project_id){
$i=1;
$sign = generateRoute($title);
$length = strlen($sign);
if($length > 100){
$sign = trim(mb_substr($sign, 0, 100, 'UTF-8'),'-');
}
$info = RouteMap::where(['project_id' => $project_id, 'source' => $source, 'source_id'=>$source_id])->first();
$suffix = '';
if(empty($info)){
if($source == 'product'){
$suffix = '-product';
}
}
$route = $sign.$suffix;
while(RouteMap::isExist($route, $source_id, $project_id)){
$route = $sign .'-'.$i.$suffix;
$i++;
}
return $route;
}
/**
* @remark :产品关键字
... ... @@ -157,7 +213,7 @@ class UpdateRoute extends Command
public function getProduct(){
$productModel = new Product();
$lists = $productModel->list(['status'=>1]);
$lists = $productModel->list(['status'=>1,'id'=>['<=',501]]);
if(!empty($lists)){
foreach ($lists as $v){
if(!empty($v['route'])){
... ... @@ -173,9 +229,10 @@ class UpdateRoute extends Command
// $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT, $v['id'], $v['project_id']);
// $productModel->edit(['route'=>$route],['id'=>$v['id']]);
}
continue;
}else{
echo date('Y-m-d H:i:s') . 'id :'.$v['id'] . PHP_EOL;
// $v['title'] = Translate::tran($v['title'], 'en');
$v['title'] = Translate::tran($v['title'], 'en');
$route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT, $v['id'], $v['project_id']);
$productModel->edit(['route'=>$route],['id'=>$v['id']]);
}
... ... @@ -278,4 +335,55 @@ class UpdateRoute extends Command
RouteMap::setRoute($v['route'],'product_keyword',$v['id'],569);
}
}
public function copyTable()
{
$sourceTable = 'gl_route_map';
$destinationTable = 'gl_route_map_copy';
if (!Schema::connection('custom_mysql')->hasTable($sourceTable)) {
$this->error("Source table {$sourceTable} does not exist.");
return false;
}
if (Schema::connection('custom_mysql')->hasTable($destinationTable)) {
Schema::connection('custom_mysql')->dropIfExists($destinationTable);
}
$columns = DB::connection('custom_mysql')->select(DB::raw("SHOW COLUMNS FROM {$sourceTable}"));
$columnsDefinition = collect($columns)->map(function($column) {
$columnDefinition = $column->Field . ' ' . $column->Type .
($column->Null === 'NO' ? ' NOT NULL' : '') .
($column->Default !== null ? " DEFAULT '" . $column->Default . "'" : '') .
($column->Extra ? ' ' . $column->Extra : '');
return $columnDefinition;
})->implode(', ');
// Add PRIMARY KEY to the id column
$primaryKey = collect($columns)->firstWhere('Field', 'id') ? 'PRIMARY KEY (id)' : '';
$columnsDefinition = $columnsDefinition . ($primaryKey ? ', ' . $primaryKey : '');
DB::connection('custom_mysql')->statement("CREATE TABLE {$destinationTable} ({$columnsDefinition})");
DB::connection('custom_mysql')->statement("INSERT INTO {$destinationTable} SELECT * FROM {$sourceTable}");
$this->info("Table {$sourceTable} has been copied to {$destinationTable} successfully.");
}
/**
* @remark :routeMap去重
* @name :routeMapDeduplication
* @author :lyh
* @method :post
* @time :2024/5/28 11:31
*/
public function routeMapDeduplication(){
$routeMapModel = new RouteMap();
$lists = $routeMapModel->list(['source'=>'product_keyword'],'id',['id'],'asc');
foreach ($lists as $v){
echo date('Y-m-d H:i:s') . '关键字id:'.$v['id'] . PHP_EOL;
//查询当前数据详情
$info = $routeMapModel->read(['id'=>$v['id']],['id','source_id']);
if($info !== false){
//删除其他一样的数据
$routeMapModel->del(['id'=>['!=',$info['id']],'source'=>'product_keyword','source_id'=>$info['source_id']]);
}
}
return true;
}
}
... ...
... ... @@ -47,7 +47,7 @@ class HtmlCollect extends Command
public function handle()
{
ini_set('memory_limit', '512M');
ini_set('memory_limit', '1024M');
while (true) {
$this->start_collect();
}
... ... @@ -92,8 +92,6 @@ class HtmlCollect extends Command
try {
$html = curl_c('https://' . $collect_info->domain . $collect_info->route, false);
if (strlen($html) < 4) {
$collect_info->status = CollectTask::STATUS_FAIL;
$collect_info->save();
if ($html == 404) {
//原数据页面404,需要将6.0数据存入草稿箱
... ... @@ -123,7 +121,9 @@ class HtmlCollect extends Command
$model = new BCustomTemplate();
$status_draft = BCustomTemplate::STATUS_DRAFT;
}
$model->edit(['status' => $status_draft], ['project_id' => $project_id, 'id' => $collect_info->source_id]);
$model->edit(['status' => $status_draft], ['project_id' => $project_id, 'id' => $collect_info->source_id, 'six_read' => 1]);
CollectTask::where('source', $collect_info->source)->where('source_id', $collect_info->source_id)->delete();
}
echo 'date:' . date('Y-m-d H:i:s') . ', project_id: ' . $project_id . ', collect_id: ' . $collect_id . ', error: ' . $html . PHP_EOL;
... ... @@ -347,6 +347,14 @@ class HtmlCollect extends Command
$source[] = $check_vv2;
}
}
preg_match_all('/<iframe\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_video_3);
$video_3 = $result_video_3[2] ?? [];
foreach ($video_3 as $vv3) {
$check_vv3 = $this->url_check($vv3, $project_id, $domain, $web_url_domain, $home_url);
if ($check_vv3 && (!in_array($check_vv3, $source))) {
$source[] = $check_vv3;
}
}
//css
preg_match_all('/<link\s+[^>]*?href\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $html, $result_css);
... ... @@ -434,7 +442,12 @@ class HtmlCollect extends Command
foreach ($source as $vs) {
if ($vs['download']) {
if ($project_id == 1355 && in_array(substr($vs['url_complete'], -3), ['pdf', 'zip', 'rar', '.gz'])) {
//项目id为1355的项目,可下载类资源要保持原名称,做特殊处理
$new_source = CosService::uploadRemote($project_id, 'source', $vs['url_complete'], '', '', 1);
} else {
$new_source = CosService::uploadRemote($project_id, 'source', $vs['url_complete']);
}
if ($new_source) {
CollectSource::insert([
'project_id' => $project_id,
... ...
... ... @@ -308,6 +308,13 @@ class ProjectUpdate extends Command
$keyword_id = ',' . implode(',', array_column($keyword_arr, 'id')) . ',';
}
}
//产品参数
$attrs = [];
if ($item['attr'] ?? []) {
foreach ($item['attr'] as $k_attr => $attr) {
$attrs[] = ['key' => $k_attr, 'value' => $attr];
}
}
//名称去掉特殊符号
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
... ... @@ -323,6 +330,7 @@ class ProjectUpdate extends Command
'keyword_id' => $keyword_id,
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
'gallery' => Arr::a2s($gallery),
'attrs' => Arr::a2s($attrs),
'seo_mate' => Arr::a2s([
'title' => $item['ttile'],
'keyword' => $item['keywords'] ?? '',
... ... @@ -353,6 +361,7 @@ class ProjectUpdate extends Command
'keyword_id' => $keyword_id,
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
'gallery' => Arr::a2s($gallery),
'attrs' => Arr::a2s($attrs),
'seo_mate' => Arr::a2s([
'title' => $item['ttile'],
'keyword' => $item['keywords'] ?? '',
... ... @@ -361,15 +370,20 @@ class ProjectUpdate extends Command
'send_time' => $item['post_date'] ?? date('Y-m-d H:i:s'),
'sort' => $item['sort'] ?? 0,
], ['id' => $id]);
} else {
//按6.0展示只更新分类
$model->edit([
'category_id' => $category_id
], ['id' => $id]);
}
}
if ($six_read) {
//关联分类
if ($category_arr) {
CategoryRelated::saveRelated($id, array_column($category_arr, 'id'));
}
if ($six_read) {
//扩展字段
if ($item['extend'] ?? []) {
foreach (array_reverse($item['extend']) as $ke => $ve) {
... ... @@ -649,9 +663,17 @@ class ProjectUpdate extends Command
$new_img = $this->source_download($image, $project_id, $domain_arr['host'], $web_url_domain, $home_url);
//名称去掉特殊符号
$item['title'] = $this->special2str($item['title'] ?? '');
//排序
$sort = 0;
if (isset($item['listorder'])) {
$sort = $item['listorder'];
}
if (isset($item['sort'])) {
$sort = $item['sort'];
}
try {
$custom_content = $model->read(['route' => $route], ['id','six_read']);
$custom_content = $model->read(['route' => $route], ['id', 'six_read']);
if (!$custom_content) {
$id = $model->insertGetId([
'project_id' => $project_id,
... ... @@ -659,7 +681,7 @@ class ProjectUpdate extends Command
'module_id' => $custom_info['id'],
'category_id' => $category_id,
'content' => $item['content'] ?? '',
'sort' => $item['sort'] ?? 0,
'sort' => $sort,
'image' => $new_img,
'created_at' => $item['post_time'] ?? date('Y-m-d H:i:s'),
'updated_at' => $item['post_time'] ?? date('Y-m-d H:i:s'),
... ... @@ -675,12 +697,12 @@ class ProjectUpdate extends Command
} else {
$id = $custom_content['id'];
$six_read = $custom_content['six_read'];
if($six_read){
if ($six_read) {
$model->edit([
'name' => $item['title'],
'category_id' => $category_id,
'content' => $item['content'] ?? '',
'sort' => $item['sort'] ?? 0,
'sort' => $sort,
'release_at' => $item['post_time'] ?? date('Y-m-d H:i:s'),
'image' => $new_img
], ['id' => $id]);
... ... @@ -688,7 +710,7 @@ class ProjectUpdate extends Command
}
//扩展字段
if($six_read){
if ($six_read) {
if ($item['extend'] ?? []) {
foreach ($item['extend'] as $ke => $ve) {
$extend = $extend_model->read(['title' => $ke]);
... ... @@ -776,11 +798,7 @@ class ProjectUpdate extends Command
//获取地址路由
protected function get_url_route($url)
{
if (strpos($url, '%ec') !== false) {
$url = str_replace('%ec', 'v6SpecialStr', $url);
$url = urldecode($url);
$url = str_replace('v6SpecialStr', '%ec', $url);
} else {
if (strpos($url, '%3A') !== false || strpos($url, '%2F') !== false) {
$url = urldecode($url);
}
$arr = parse_url($url);
... ...