作者 lyh

gx

<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
*/
namespace App\Console\Commands\DayCount;
use App\Models\Project\Project;
use App\Models\Visit\Visit;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_count';
/**
* The console command description.
*
* @var string
*/
protected $description = '升级项目统计';
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]);
foreach ($list as $v) {
echo date('Y-m-d H:i:s') . '项目id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->count($v['id']);
DB::disconnect('custom_mysql');
}
return true;
}
/**
* @remark :日统计记录
* @name :count
* @author :lyh
* @method :post
* @time :2024/1/8 9:05
*/
public function count($project_id){
$list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date')
->groupBy('updated_date')->get()->toArray();
$project = new Project();
$projectInfo = $project->read(['id'=>$project_id]);
if(!empty($list)){
$arr = [];
foreach ($list as $k=>$v){
$v = (array)$v;
if($v['updated_date'] == date('Y-m-d')){
continue;
}
echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL;
$count = new Count();
$arr['project_id'] = $project_id;
$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([]);
//查询当天数据是否存在 存在则更新
$info = $count->read(['date'=>$v['updated_date'],'project_id'=>$project_id]);
if($info === false){
$arr['created_at'] = $v['updated_date'].' 01:00:00';
$arr['updated_at'] = $v['updated_date'].' 01:00:00';
$count->insert($arr);
}else{
$count->edit($arr,['id'=>$info['id']]);
}
}
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :询盘数量
* @name :inquiry_num
* @author :lyh
* @method :post
* @time :2024/1/8 9:24
*/
public function inquiry_num($day){
$count = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->where('is_inquiry',1)->count();
return $count;
}
/**
* @name :(统计pv)pv_num
* @author :lyh
* @method :post
* @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;
}
/**
* @name :(统计ip)ip_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function ip_num($day){
$ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->count();
return $ip;
}
}
... ...
... ... @@ -55,7 +55,7 @@ class UpdateRoute extends Command
*/
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['id'=>249]);
$list = $projectModel->list(['id'=>264]);
$data = [];
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
... ...
... ... @@ -39,7 +39,7 @@ class UpdateSeoTdkCrontab extends Command
try {
ProjectUpdateTdk::add_task($project_id);
}catch (\Exception $e){
dump($e->getMessage());
}
}
}
... ...
... ... @@ -210,9 +210,11 @@ class WebTrafficRussia extends Command
}
$need_project = [];
foreach ($project_list as $project) {
Log::channel('traffic')->info('开始俄语站引流 project_id:' . $project['project_id']);
//随机引流间隔
$res_sjjg = $this->get_rand($this->sjjg);
if ($res_sjjg == 1) {
Log::channel('traffic')->info('随机不俄语站引流 project_id:' . $project['project_id']);
continue;
}
... ... @@ -260,6 +262,7 @@ class WebTrafficRussia extends Command
}
//不访问
if($res == 1){
Log::channel('traffic')->info('特殊日期随机不引流 project_id:' . $project['project_id']);
unset($need_project[$project_key]);
unset($ips[$project_key]);
}
... ... @@ -430,7 +433,7 @@ class WebTrafficRussia extends Command
$data = [];
for ($i=0;$i<$num;$i++){
//ip国家占比
$ip_area = $this->get_rand($this->country_ratio);
$ip_area = $this->get_rand($country_ratio);
$res = DB::table('gl_xunpan_ipdata')->where('ip_area', $ip_area)->inRandomOrder()->first();
$res = (array)$res;
$res['diff'] = $time_zones[$res['ip_area']];
... ...
<?php
namespace App\Console\Commands;
use App\Helper\Arr;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use App\Models\Template\BCustomTemplate;
use App\Models\WebSetting\WebLanguage;
use App\Services\ProjectServer;
use Carbon\Carbon;
use GuzzleHttp\Client;
use GuzzleHttp\Promise\Utils;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
/**
* 俄语站网站特殊引流
* Class Traffic
* @package App\Console\Commands
* @author zbj
* @date 2023/5/18
*/
class WebTrafficRussiaSpecial extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'web_traffic_russia_special';
/**
* The console command description.
*
* @var string
*/
protected $description = '俄语站网站特殊引流';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
protected $projects = [
969 => 30,
];
/**
* 国家概率
* @var array
*/
protected $country_ratio = [
'俄罗斯' => 75,
'白俄罗斯' => 6,
'哈萨克斯坦' => 6,
'乌兹别克斯坦' => 2,
'塔吉克斯坦' => 2,
'土耳其' => 2,
'吉尔吉斯坦' => 1,
'土库曼斯坦' => 1,
'乌克兰' => 1,
'亚美尼亚' => 2,
'阿塞拜疆' => 2,
'摩尔多瓦' => 2,
'格鲁吉亚' => 2,
'美国' => 1,
'德国' => 1,
'法国' => 1,
'意大利' => 1,
'加拿大' => 1,
'西班牙' => 1,
'葡萄牙' => 1,
'韩国' => 1,
'日本' => 1,
'印度' => 1,
'菲律宾' => 1,
'越南' => 1,
'荷兰' => 1,
'瑞典' => 1,
'泰国' => 1,
'英国' => 1,
];
/**
* google域名后缀
* @var string[]
*/
protected $suffix = [
'co.jp' => '日本',
'com.tr' => '土耳其',
'nl' => '荷兰',
'ru' => '俄罗斯',
'fr' => '法国',
'co.kr' => '韩国',
'fi' => '芬兰',
'be' => '比利时',
'lt' => '立陶宛',
'es' => '西班牙',
'it' => '意大利',
'com.au' => '澳大利亚',
'no' => '挪威',
'al' => '阿尔巴尼亚',
'pt' => '葡萄牙',
'lv' => '拉脱维亚',
'hu' => '匈牙利',
'cz' => '捷克',
'de' => '德国',
'ca' => '加拿大',
'co.in' => '印度',
'co.uk' => '英国',
'com.vn' => '越南',
'com.br' => '巴西',
'co.il' => '以色列',
'pl' => '波兰',
'com.eg' => '埃及',
'co.th' => '泰国',
'sk' => '斯洛伐克',
'ro' => '罗马尼亚',
'com.mx' => '墨西哥',
'com.my' => '马来西亚',
'com.pk' => '巴基斯坦',
'co.nz' => '新西兰',
'co.za' => '南非',
'com.ar' => '阿根廷',
'com.kw' => '科威特',
'com.sg' => '新加坡',
'com.co' => '哥伦比亚',
'co.id' => '印度尼西亚',
'gr' => '希腊',
'bg' => '保加利亚',
'mn' => '蒙古',
'dk' => '丹麦',
'com.sa' => '沙特阿拉伯',
'com.pe' => '秘鲁',
'com.ph' => '菲律宾',
'com.ua' => '乌克兰',
'ge' => '格鲁吉亚',
'ae' => '阿拉伯联合酋长国',
'tn' => '突尼斯',
];
/**
* 概率值
* @var int[]
*/
protected $sjjg = [360, 640];//访问间隔占比 访问|不访问 比非俄语站降一般
//访问页面类型占比 产品详情页、单页|产品分类页
protected $ymzb = [
'urls_cats' => 700,
'urls_details' => 300
];
protected $sdzb = [600, 200, 150, 50]; //访问页面深度占比 1页|2页|3-6页|7-11页
protected $yddzb = [1 => 700, 2 => 300]; //移动端占比 pc|mobile
//模拟访问来源占比 (美国)
protected $lyzb = [
'https://www.google.com/' => 630,
'http://www.google.com/' => 30,
'http://www.bing.com/' => 20,
'https://www.bing.com/' => 5,
'https://www.youtube.com/' => 5,
'https://search.yahoo.com/' => 5,
'https://www.facebook.com/' => 5,
];
//俄语
protected $eylyzb = [
'https://www.yandex.com/' => 630,
'https://www.google.com/' => 30,
'http://www.google.com/' => 30,
'http://www.bing.com/' => 20,
'https://www.bing.com/' => 5,
'https://www.youtube.com/' => 5,
'https://search.yahoo.com/' => 5,
'https://www.facebook.com/' => 5,
];
protected $otherzb = [700, 300]; //模拟访问来源占比 (非美国) google.com|google.其他后缀
protected $pc_ua = [
0 => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11',
1 => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36',
2 => 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1'
];
protected $mobile_ua = [
0 => 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko; googleweblight) Chrome/38.0.1025.166 Mobile Safari/535.19',
];
/**
* @return bool
*/
public function handle()
{
try {
$this->sleep();
$page = 1;
while (true){
$project_list = $this->getProjectList($page);
if(!$project_list){
break;
}
$need_project = [];
foreach ($project_list as $project) {
Log::channel('traffic')->info('开始俄语站特殊引流 project_id:' . $project['project_id']);
//随机引流间隔
$res_sjjg = $this->get_rand($this->sjjg);
if ($res_sjjg == 1) {
Log::channel('traffic')->info('随机不俄语站特殊引流 project_id:' . $project['project_id']);
continue;
}
$project_urls = $this->getProductUrls($project['project_id']);
$project_urls['home'] = $project['domain'];
//随机访问页面
$project['visit_urls'] = $this->getVisitUrls($project_urls);
//随机客户端
$project['device_port'] = $this->get_rand($this->yddzb);
$project['user_agent'] = $project['device_port'] == 1 ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
$need_project[] = $project;
}
//随机访问ip
$ips = $this->getIpAreas(count($need_project));
//特殊日期 降访问率
foreach ($need_project as $project_key => $project){
$diff = $ips[$project_key]['diff'];
//当地时间
$w = date('w', strtotime($diff . 'hour'));
$date = date('m-d', strtotime($diff . 'hour'));
//元旦节和圣诞节按照周六的比例处理
if(in_array($date, ['01-01', '12-25'])){
$w = 6;
}
switch ($w){
case 0:
//周日降70-80%
$rate = rand(70, 80) * 10;
$res = $this->get_rand([1000-$rate, $rate]);
break;
case 5:
//周5降30-40%
$rate = rand(30, 40) * 10;
$res = $this->get_rand([1000-$rate, $rate]);
break;
case 6:
//周6降60-70%
$rate = rand(60, 70) * 10;
$res = $this->get_rand([1000-$rate, $rate]);
break;
default:
$res = 0;
}
//不访问
if($res == 1){
Log::channel('traffic')->info('特殊日期随机不特殊引流 project_id:' . $project['project_id']);
unset($need_project[$project_key]);
unset($ips[$project_key]);
}
}
//最多10层深度
$client = new Client(['verify' => false]);
for ($j = 0; $j < 10; $j++) {
for ($j = 0; $j < 10; $j++) {
//并发请求
$promises = [];
foreach ($need_project as $project_key => $project) {
if (empty($project['visit_urls'][$j])) {
continue;
}
$data = [
'ip' => $ips[$project_key]['ip'],
'url' => $project['visit_urls'][$j],
'device_port' => $project['device_port'],
'referrer_url' => $this->getReferer($ips[$project_key]['ip_area'], $project['lang']),
'user_agent' => $project['user_agent'],
];
Log::channel('traffic')->info('ru_traffic project_id:' . $project['project_id'], $data);
$promises[] = $client->postAsync($project['domain'] . 'api/traffic_visit', ['form_params' => $data]);
}
if($promises){
Utils::settle($promises)->wait();
//每个深度随机等待
sleep(rand(2, 10));
}
}
}
$page++;
}
}catch (\Exception $e){
Log::channel('traffic')->error("ru:line" . $e->getLine() . ',error:' . $e->getMessage());
}
}
/**
* 不同项目 休眠
*/
protected function sleep(){
sleep(rand(5,480));
}
/**
* 俄语站引流的项目
*/
protected function getProjectList($page){
$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)// 俄语站
->whereIn('gl_project.id', array_keys($this->projects))
->select(['pdo.project_id','gl_project.main_lang_id','gl_project.id'])->forPage($page, 500)->get();
//其他地方在引流的域名
// $other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
$other = [];
$data = [];
foreach ($list as $project) {
//根据增加的次数 设置间隔
if(Cache::get('web_traffic_russia_special_' . $project['project_id'])){
continue;
}else{
$ttl = 24 * 60 * 60 / $this->projects[$project['project_id']];
Cache::put('web_traffic_russia_special_' . $project['project_id'], 1, $ttl);
}
$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;
}
/**
* 获取产品分类、单页和详情链接
*/
protected function getProductUrls($project_id){
ProjectServer::useProject($project_id);
//已发布产品分类页面
$data['urls_cats'] = DB::connection('custom_mysql')->table('gl_product_category')
->where('project_id', $project_id)->where('status', Category::STATUS_ACTIVE)
->whereNull('deleted_at')
->pluck('route','id')->toArray();
//已发布单页面
$data['urls_page'] = [];
// $data['urls_page'] = DB::connection('custom_mysql')->table('gl_web_custom_template')
// ->where('project_id', $project_id)->where('url', '<>', '404')->where('status', BCustomTemplate::STATUS_ACTIVE)->pluck('url', 'id')->toArray();
//已发布产品详情页
$data['urls_details'] = DB::connection('custom_mysql')->table('gl_product')
->where('project_id', $project_id)->where('status', Product::STATUS_ON)
->whereNull('deleted_at')
->pluck('route', 'id')->toArray();
$data['urls_cats'] = array_merge($data['urls_cats'], $data['urls_page']);
if(empty($data['urls_cats'])){
$data['urls_cats'] = $data['urls_details'];
}
DB::disconnect('custom_mysql');
return $data;
}
/**
* 获取地区IP
*/
protected function getIpAreas($num)
{
//本地时间为7-23点的地区
$h = date('H');
$areas = [];
$list = DB::table('gl_area_timezone')->whereIn('name', array_keys($this->country_ratio))->get();
$time_zones = [];
foreach ($list as $v) {
$v = (array)$v;
$country_hour = $h + $v['diff'];
if ($country_hour < 0) {
$country_hour = 24 + $country_hour;
}
if ($country_hour >= 7 && $country_hour < 23) {
$areas[] = $v['name'];
$time_zones[$v['name']] = $v['diff'];
}
}
//不在时区的国家概率去掉
$country_ratio = $this->country_ratio;
foreach ($country_ratio as $k => $v){
if(!in_array($k, array_keys($time_zones))){
unset($country_ratio[$k]);
}
}
$data = [];
for ($i=0;$i<$num;$i++){
//ip国家占比
$ip_area = $this->get_rand($country_ratio);
$res = DB::table('gl_xunpan_ipdata')->where('ip_area', $ip_area)->inRandomOrder()->first();
$res = (array)$res;
$res['diff'] = $time_zones[$res['ip_area']];
$data[] = $res;
}
return $data;
}
/**
* 概率算法
*/
protected function get_rand($proArr) {
$result = '';
$proSum = array_sum($proArr);
foreach ($proArr as $key => $proCur) {
$randNum = mt_rand(1, $proSum);
if ($randNum <= $proCur) {
$result = $key;
break;
} else {
$proSum -= $proCur;
}
}
unset ($proArr);
return $result;
}
/**
* 根据随机访问深度 随机获取访问页面
*/
protected function getVisitUrls($project_urls){
//没有分类页 就只访问首页
if(!$project_urls['urls_cats']){
$url[] = $project_urls['home'];
return $url;
}
//随机访问深度
$res_sdzb = $this->get_rand($this->sdzb);
//随机访问页面类型
$res_ymzb = $this->get_rand($this->ymzb);
$all_url = array_merge($project_urls['urls_cats'],$project_urls['urls_details']);
if(!$all_url){
$url[] = $project_urls['home'];
return $url;
}
$url = [];
if($res_sdzb == 0){//深度一页
$url[] = $project_urls[$res_ymzb] ? Arr::random($project_urls[$res_ymzb]) : '';
}elseif($res_sdzb == 1){//深度两页
$url[] = $project_urls['home'];
$url[] = $project_urls[$res_ymzb] ? Arr::random($project_urls[$res_ymzb]) : '';
}elseif($res_sdzb == 2){//深度3-6页
$yms = rand(2,5); //随机页面数
$url = Arr::random($all_url, $yms);
$url = Arr::prepend($url, $project_urls['home']);//首页加到最前面去
}elseif($res_sdzb == 3){//深度7-11页
$yms = rand(6,10); //随机页面数
$url = Arr::random($all_url, $yms);
$url = Arr::prepend($url, $project_urls['home']);//首页加到最前面去
}
foreach ($url as &$v){
if(!Str::contains($v, $project_urls['home'])){
if (FALSE === strpos($v, '.htm')) {
$v .= '/';
}
$v = $project_urls['home'] . $v;
}
}
return array_unique(array_filter($url));
}
/**
* 获取访问来路
*/
protected function getReferer($ip_area, $lang){
if($lang == 'ru'){
return $this->get_rand($this->eylyzb);
}
if($ip_area == '美国'){
$referer = $this->get_rand($this->lyzb);
}else{
$referer = 'https://www.google.com/';
$suffix = array_search($ip_area, $this->suffix);
if($suffix){
$res_qtzb = $this->get_rand($this->otherzb);
if($res_qtzb == 1){
$referer = 'https://www.google.'.$suffix.'/';
}
}
}
return $referer;
}
}
... ...
... ... @@ -24,11 +24,10 @@ class Kernel extends ConsoleKernel
$schedule->command('rank_data_external_links')->dailyAt('18:00')->withoutOverlapping(1); // 排名数据-外链,每周一凌晨执行一次
$schedule->command('rank_data_indexed_pages')->dailyAt('07:30')->withoutOverlapping(1); // 排名数据-页面收录,每周一凌晨执行一次
$schedule->command('rank_data_recomm_domain')->dailyAt('07:40')->withoutOverlapping(1); // 排名数据-引荐域名,每周一凌晨执行一次
$schedule->command('rank_data_week')->weeklyOn([1,2], '08:300')->withoutOverlapping(1); // 排名数据,每周一、二早上执行一次
// $schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次
// $schedule->command('count')->dailyAt('00:30')->withoutOverlapping(1); //每天凌晨1点执行一次
$schedule->command('rank_data_week')->weeklyOn([1,2], '08:30')->withoutOverlapping(1); // 排名数据,每周一、二早上执行一次
$schedule->command('service_count')->dailyAt('01:00')->withoutOverlapping(1); //服务器使用情况,每天凌晨1点执行一次
$schedule->command('web_traffic_special')->everyMinute()->withoutOverlapping(1); // 特殊引流
$schedule->command('web_traffic_russia_special')->everyMinute()->withoutOverlapping(1); // 特殊引流
$schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
$schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次
$schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次
... ... @@ -36,16 +35,12 @@ class Kernel extends ConsoleKernel
$schedule->command('web_traffic_russia 2')->cron('*/18 * * * *'); // 俄语站引流 4-8个月的项目,18分钟一次
$schedule->command('web_traffic_russia 3')->cron('*/12 * * * *'); // 俄语站引流 大于9个月的项目,12分钟一次
$schedule->command('sync_channel')->dailyAt('06:00')->withoutOverlapping(1); // 渠道信息,每天执行一次
// $schedule->command('month_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计记录
$schedule->command('forward_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计转发询盘记录
$schedule->command('inquiry_delay')->everyMinute()->withoutOverlapping(1);//TODO::上线放开,转发询盘,每分钟执行一次
$schedule->command('inquiry_count')->dailyAt('01:00')->withoutOverlapping(1); // 询盘统计数据,每天凌晨执行一次
$schedule->command('domain_info')->dailyAt('01:20')->withoutOverlapping(1);// 更新域名|证书结束时间,每天凌晨1点执行一次
$schedule->command('last_inquiry')->dailyAt('04:00')->withoutOverlapping(1);// 最近一次询盘信息
// $schedule->command('update_progress')->everyThirtyMinutes()->withoutOverlapping(1);//监控更新
$schedule->command('update_seo_tdk_crontab')->dailyAt('20:00')->withoutOverlapping(1); //更新上线项目TDK
// $schedule->command('website_data')->dailyAt('01:00')->withoutOverlapping(1); // 向AICC推送数据
// $schedule->command('project_file_pdf')->dailyAt('00:00')->withoutOverlapping(1); // 网站项目数据,生成PDF文件
$schedule->command('sync_manager')->dailyAt('01:00')->withoutOverlapping(1); //TODO::手机号码同步 每天执行一次
$schedule->command('update_keyword_route')->dailyAt('01:00')->withoutOverlapping(1); //升级项目--清除路由相同的关键字
$schedule->command('recommended_suppliers')->dailyAt('03:00')->withoutOverlapping(1); //每天凌晨1点执行一次生成推荐商
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Logic\Aside\Domain;
use App\Http\Logic\Aside\BaseLogic;
use App\Jobs\EditCustomDomainBt;
use App\Jobs\EditDomainBt;
use App\Models\Devops\ServerConfig;
use App\Models\Domain\DomainInfo;
... ... @@ -403,16 +404,18 @@ class DomainInfoLogic extends BaseLogic
$info = $custom_model->read(['project_id'=>$project_id,'language_id'=>$this->param['language_id']]);
if($info === false){
$this->param['project_id'] = $project_id;
$custom_model->add($this->param);
$id = $custom_model->addReturnId($this->param);
}else{
$custom_model->edit($this->param,['id'=>$info['id']]);
$id = $info['id'];
}
if($this->param['is_create']){
//创建站点,设置证书
$this->param['key'] = $this->param['private_key'] ?? '';
$this->param['cert'] = $this->param['private_cert'] ?? '';
$this->setDomainSsl($server_info['init_domain'],$this->param['custom_domain'],[],[],1);
EditCustomDomainBt::dispatch($id);
// $this->param['key'] = $this->param['private_key'] ?? '';
// $this->param['cert'] = $this->param['private_cert'] ?? '';
// $this->setDomainSsl($server_info['init_domain'],$this->param['custom_domain'],[],[],1);
}
return $this->success();
... ...
... ... @@ -397,7 +397,7 @@ class ProjectLogic extends BaseLogic
$info = $this->model->read(['id'=>$param['id']]);
if($info['delete_status'] == 0){
//删除原始项目
$this->edit(['delete_status' => 1], ['id' => $param['id']]);
$this->edit(['delete_status' => 1,'type'=>$param['type']], ['id' => $param['id']]);
//添加到续费单
$data = [
'title' => '【续费单】' . $param['title'],
... ... @@ -411,8 +411,8 @@ class ProjectLogic extends BaseLogic
'service_duration' => $param['deploy_build']['service_duration'],
'plan' => $param['deploy_build']['plan'],
'amount' => $param['payment']['amount'],
'contract' => json_encode($param['payment']['contract']),
'bill' => json_encode($param['payment']['bill']),
'contract' => json_encode($param['payment']['contract'] ?? []),
'bill' => json_encode($param['payment']['bill'] ?? []),
];
$renewModel = new ProjectRenew();
$renewModel->add($data);
... ...
... ... @@ -217,10 +217,14 @@ class NewsLogic extends BaseLogic
*/
public function getCategory($category){
$str = '';
foreach ($category as $v){
$str .= $v.',';
if(is_array($category) && $category){
$str = ','.implode(',',$category).',';
}
return !empty(trim($str,',')) ? ','.$str.',' : '';
return $str;
// foreach ($category as $v){
// $str .= $v.',';
// }
// return !empty(trim($str,',')) ? ','.$str.',' : '';
}
/**
... ...
... ... @@ -247,12 +247,16 @@ class CategoryLogic extends BaseLogic
*/
public function getLastCategory($category){
$str = '';
if(isset($category) && !empty($category)){
foreach ($category as $v){
$str .= $v.',';
}
if(is_array($category) && $category){
$str = ','.implode(',',$category).',';
}
return !empty(trim($str,',')) ? ','.$str.',' : '';
return $str;
// if(isset($category) && !empty($category)){
// foreach ($category as $v){
// $str .= $v.',';
// }
// }
// return !empty(trim($str,',')) ? ','.$str.',' : '';
}
/**
... ...
... ... @@ -10,6 +10,8 @@
namespace App\Http\Logic\Bside\Setting;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Com\UpdateLog;
use App\Models\User\UserLog;
use App\Models\WebSetting\Translate as TranslateModel;
use App\Models\WebSetting\WebLanguage;
use App\Helper\Translate;
... ... @@ -271,9 +273,10 @@ class TranslateLogic extends BaseLogic
}
}
}
$this->param['data'] = $data;
}
try {
$info = $this->model->read(['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]);
$info = $this->model->read(['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'project_id'=>$this->user['project_id'],'type'=>$this->param['type']]);
if($info === false){
$param = [
'type'=>$this->param['type'],
... ... @@ -285,9 +288,14 @@ class TranslateLogic extends BaseLogic
$param['data'] = json_encode($data,JSON_UNESCAPED_UNICODE);
$this->model->add($param);
}else{
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
$this->model->edit(['data'=>$data],['language_id'=>$this->param['language_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]);
if(!empty($data)){
$data = json_encode($data,JSON_UNESCAPED_UNICODE);
$this->model->edit(['data'=>$data],['language_id'=>$this->param['language_id'],'project_id'=>$this->user['project_id'],'url'=>$this->param['url'],'type'=>$this->param['type']]);
}
}
//写日志
$userLogModel = new UserLog();
$userLogModel->add(['model'=>'translate/save','remark'=>json_encode($this->param,true),'type'=>0,'operator_id'=>$this->user['id'],'project_id'=>$this->user['project_id']]);
}catch (\Exception $e){
$this->fail('系统错误请联系管理员');
}
... ...
<?php
namespace App\Jobs;
use App\Models\Devops\ServerConfig;
use App\Models\Project\CountryCustom;
use App\Models\Project\Project;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
class EditCustomDomainBt implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $tries = 1; // 可配置任务重试次数
protected $domain_id;
/**
* Create a new job instance.
*
* @param $domain_id
*/
public function __construct($domain_id)
{
$this->domain_id = $domain_id;
}
/**
* Execute the job.
*
* @return bool
*/
public function handle()
{
//获取域名数据
$domain_model = new CountryCustom();
$domain_info = $domain_model->read(['id' => $this->domain_id]);
if ($domain_info === false) {
return $this->output($domain_info['custom_domain'] . ':获取域名数据失败');
}
//获取项目数据
$project_model = new Project();
$project_info = $project_model->read(['id' => $domain_info['project_id']], 'serve_id');
if ($project_info === false) {
return $this->output($domain_info['custom_domain'] . ':获取项目数据失败');
}
//获取服务器数据
$server_model = new ServerConfig();
$server_info = $server_model->read(['id' => $project_info['serve_id']], ['init_domain', 'host']);
if ($server_info === false) {
return $this->output($domain_info['custom_domain'] . ':获取服务器数据失败');
}
//编辑站点
if ($domain_info['type'] == 2) {
$api_url = 'http://' . $server_info['init_domain'] . '/api/setSsl';
$api_param = [
'domain' => $domain_info['custom_domain'],
'private_key' => $domain_info['private_key'],
'cert' => $domain_info['private_cert'],
'rewrite' => [],
'other_domain' => [],
'is_https' => 1
];
} else {
$api_url = 'http://' . $server_info['init_domain'] . '/api/applySsl';
$api_param = [
'domain' => $domain_info['custom_domain'],
'rewrite' => [],
'other_domain' => [],
'is_https' => 1
];
}
try {
$rs = HttpUtils::get($api_url, $api_param);
$rs = json_decode($rs, true);
if (isset($rs['status']) && $rs['status'] == 200) {
$this->output($domain_info['custom_domain'] . ':站点编辑成功');
} else {
$this->output($domain_info['custom_domain'] . ':站点编辑失败,原因:' . ($rs['message'] ?? ''));
}
} catch (\Exception | GuzzleException $e) {
$this->output($domain_info['custom_domain'] . ':站点编辑失败,原因:' . $e->getMessage());
}
return true;
}
/**
* 输出处理日志
* @param $message
* @return bool
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' | ' . $message . PHP_EOL;
return true;
}
public function failed(\Exception $exception)
{
return $this->output($exception->getMessage());
}
}
... ...