作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

... ... @@ -38,7 +38,6 @@ class SyncFile extends Command
echo date('Y-m-d H:i:s') . '编辑的path为:'. $v['path'] .',主键id:'. $v['id'] . PHP_EOL;
$errorFileModel->edit(['status'=>1],['id'=>$v['id']]);
}
gc_collect_cycles();
}
echo date('Y-m-d H:i:s') . '编辑的end为:' . PHP_EOL;
return true;
... ...
<?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,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
namespace App\Console\Commands\WebTraffic;
use App\Helper\Arr;
use App\Models\HomeCount\Count;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use App\Models\Project\WebTrafficConfig;
use App\Models\Visit\SyncSubmitTask;
use App\Models\Visit\Visit;
use App\Models\WebSetting\WebLanguage;
use App\Services\ProjectServer;
use Carbon\Carbon;
use Facade\Ignition\DumpRecorder\Dump;
use GuzzleHttp\Client;
use GuzzleHttp\Promise\Utils;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Str;
/**
* 网站引流 修复
* Class Traffic
* @package App\Console\Commands
* @author zbj
* @date 2023/5/18
*/
class WebTrafficFix extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'web_traffic_fix {type} {date} {need_num}'; // 1 2024-05-16 44
/**
* The console command description.
*
* @var string
*/
protected $description = '网站引流';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* 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 = [720, 280];//访问间隔占比 访问|不访问
//访问页面类型占比 产品详情页、单页|产品分类页
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 {
$type = $this->argument('type');
$date = $this->argument('date');
$need_num = $this->argument('need_num');
// $project_list = $this->getProjectList($type);
// exit;
while (true) {
$project = Redis::rpop('web_traffic_fix');
if(empty($project)){
break;
}
$project_list = [json_decode($project, true)];
foreach ($project_list as $project) {
ProjectServer::useProject($project['project_id']);
// if($project['project_id'] <= 135){
// continue;
// }
echo 'project_id:' . $project['project_id'] . PHP_EOL;
Log::info('web_traffic_fix project_id:' . $project['project_id']);
$ip_num = DB::connection('custom_mysql')->table('gl_customer_visit')->where('updated_date', $date)->count();
if ($ip_num >= 30) {
echo $ip_num . PHP_EOL;
continue;
}
$randomTime = [];
for ($i = 0; $i < $need_num - $ip_num; $i++) {
$randomTime[] = Carbon::make($date)->addSeconds(rand(0, 86400))->toDateTimeString();
}
sort($randomTime);
echo 'count:' . count($randomTime) . PHP_EOL;
$project_urls = $this->getProductUrls($project['project_id']);
$project_urls['home'] = $project['domain'];
$data = [];
foreach ($randomTime as $time) {
//随机引流间隔
$res_sjjg = $this->get_rand($this->sjjg);
if ($res_sjjg == 1) {
continue;
}
//随机访问页面
$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);
$a = time();
$project['ip'] = $this->getIpAreas([$project['project_id']], $time)[0] ?? '';
foreach ($project['visit_urls'] as $url) {
$time = Carbon::make($time)->addSeconds(rand(2, 15))->toDateTimeString();
$url_array = parse_url($project['domain']);
$referrer_url = $this->getReferer($project['ip']['ip_area'], $project['lang']);
$array = [
'ip' => $project['ip']['ip'],
'domain' => $url_array['host'] ?? '',
'referer' => $referrer_url,
'user_agent' => $project['user_agent'],
'data' => [
'url' => $url,
'domain' => empty($url_array['host']) ? '' : $url_array['scheme'] . '://' . $url_array['host'],
'device_port' => in_array($project['device_port'], array_keys(Visit::deviceMap())) ? $project['device_port'] : Visit::DEVICE_PC,
'referrer_url' => $referrer_url
],
];
$data[] = [
'data' => json_encode($array),
'type' => SyncSubmitTask::TYPE_VISIT,
'created_at' => $time,
'updated_at' => $time,
'status' => 3,
'traffic' => 1,
'project_id' => $project['project_id'],
];
}
}
DB::table('gl_sync_submit_task_20240516')->insert($data);
}
}
Log::info('web_traffic_fix finish');
}catch (\Exception $e){
dump($e->getMessage());
Log::info('web_traffic_fix error:' . $e->getMessage());
}
}
/**
* 非俄语站的引流的项目
*/
protected function getProjectList($type){
$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();
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
];
Redis::lpush('web_traffic_fix', json_encode($data));
}
return true;
}
/**
* 获取产品分类、单页和详情链接
*/
protected function getProductUrls($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($project_ids, $time)
{
//本地时间为7-23点的地区
$h = date('H', strtotime($time));
$areas = [];
$list = DB::table('gl_area_timezone')->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'];
}
}
$data = [];
foreach ($project_ids as $project_id){
//引流配置
$config = WebTrafficConfig::getCacheInfoByProjectId($project_id);
$main_countries = !empty($config->main_countries) ? explode(',',$config->main_countries) : [];
$filter_countries = !empty($config->filter_countries) ? explode(',',$config->filter_countries) : [];
if($main_countries){
$areas = $main_countries;
}
if($filter_countries){
$areas2 = [];
foreach ($areas as $v){
if(!in_array($v, $filter_countries)){
$areas2[] = $v;
}
}
$areas = $areas2;
}
//根据地区随机取该地区的IP
$ipdata = DB::table('gl_xunpan_ipdata')->whereIn('ip_area', $areas)->inRandomOrder()->first();
if(!$ipdata){
continue;
}
$ipdata = (array)$ipdata ?: [];
$ipdata['diff'] = $time_zones[$ipdata['ip_area']];
$data[] = $ipdata;
}
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;
}
}
Log::channel('traffic')->info('project_id:访问深度' . $res_sdzb, $url);
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;
}
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Http\Controllers\File;
use App\Enums\Common\Code;
use App\Helper\Translate;
use App\Jobs\SyncImageFileJob;
use App\Models\File\ErrorFile;
use App\Models\File\File;
use App\Models\File\Image as ImageModel;
... ... @@ -146,13 +147,7 @@ class FileController
*/
public function synchronizationFile($fileName){
//同步到大文件
$file_path = config('filesystems.disks.cos')['cdn1'].$this->path.'/'.$fileName;
$cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->path.'" https://v6-file.globalso.com/upload.php';
$code = shell_exec($cmd);
if(200 != (int)$code){
$errorFileModel = new ErrorFile();
$errorFileModel->add(['path'=>$this->path.'/'.$fileName]);
}
SyncImageFileJob::dispatch(['path'=>$this->path,'name'=>$fileName]);
return true;
}
... ...
... ... @@ -204,6 +204,7 @@ class ImageController extends Controller
$this->response('不支持当前格式',Code::SYSTEM_ERROR);
}
$fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
//上传到cos
if($this->upload_location == 0){
$cosService = new CosService();
... ... @@ -265,13 +266,6 @@ class ImageController extends Controller
*/
public function synchronizationImage($fileName){
SyncImageFileJob::dispatch(['path'=>$this->path,'name'=>$fileName]);
// $file_path = getImageUrl($this->path.'/'.$fileName,$this->cache['storage_type'] ?? 0);
// $cmd = 'curl -F "file_path='.$file_path.'" -F "save_path=/www/wwwroot/cos'.$this->path.'" https://v6-file.globalso.com/upload.php';
// $code = shell_exec($cmd);
// if(200 != (int)$code){
// $errorFileModel = new ErrorFile();
// $errorFileModel->add(['path'=>$this->path.'/'.$fileName]);
// }
return true;
}
... ...
... ... @@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\Setting;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Com\UpdateLog;
use App\Models\RouteMap\RouteMap;
use App\Models\User\UserLog;
use App\Models\WebSetting\Translate as TranslateModel;
use App\Models\WebSetting\WebLanguage;
... ... @@ -284,6 +285,37 @@ class TranslateLogic extends BaseLogic
}
/**
* @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 $this->success($data);
}
if($route == '/'){
$data['source'] = 1;
return $this->success($data);
}
$route = basename($route);
$routeModel = new RouteMap();
$routeInfo = $routeModel->read(['route'=>$route]);
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_PAGE){
if($routeInfo['source_id']){
$data = ['source'=>9,'source_id'=>$routeInfo['source_id'],'is_list'=>0,'is_custom'=>0];
}
}
}
/**
* @remark :处理路由
* @name :handleRoute
* @author :lyh
... ...
<?php
namespace App\Models\SyncSubmitTask;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
/**
* @method static where(string $string, mixed $ip)
* @method static create(array $data)
*/
class SyncSubmitTaskZbj extends Model
{
const TYPE_INQUIRY = 'inquiry';
const TYPE_VISIT = 'visit';
const TRAFFIC_DEFAULT = 0;
const TRAFFIC_TRUE = 1;
//设置关联表名
/**
* @var mixed
*/
protected $table = 'gl_sync_submit_task_20240516';
protected $casts = [
'data' => 'array',
];
/**
* @param $type
* @param $data
* @return bool
* @author zbj
* @date 2023/11/28
*/
public static function addTask($type, $data): bool
{
if (empty($data)) {
return false;
}
try {
$data = [
'data' => $data['data'],
'domain' => !empty($data['domain']) ? $data['domain'] : request()->getHost(),
'ip' => !empty($data['ip']) ? $data['ip'] : request()->getClientIp(),
'referer' => !empty($data['referer']) ? $data['referer'] : request()->header('Referer'),
'user_agent' => !empty($data['user_agent']) ? $data['user_agent'] : request()->header('user_agent'),
];
if(empty($data['referer']) || empty($data['user_agent']) || empty($data['data'])){
return false;
}
$model = new self();
$model->type = $type;
$model->data = $data;
!empty($data['submit_time']) && $model->created_at = $data['submit_time'];
$model->save();
} catch (\Exception $e) {
Log::error('SyncSubmitTask addTask error', ['msg' => $e->getMessage(), 'data' => $data]);
return false;
}
return true;
}
}
... ...
... ... @@ -53,11 +53,14 @@ class Visit extends Base
/**
* 访问写入
*/
public static function saveData($data)
public static function saveData($data, $date)
{
if(!$date){
$date = date('Y-m-d');
}
//判断IP当天是否有一条数据
$visit = Visit::where("ip",$data['ip'])->where("created_at",">=",Carbon::now()->today()->startOfDay())
->where("created_at","<=",Carbon::now()->today()->endOfDay())
$visit = Visit::where("ip",$data['ip'])->where("created_at",">=",Carbon::make($date)->startOfDay())
->where("created_at","<=",Carbon::make($date)->endOfDay())
->first();
DB::connection('custom_mysql')->beginTransaction();
if (!empty($visit) && $visit->count() >= 1){
... ...
... ... @@ -31,7 +31,7 @@ class SyncSubmitTaskService
* @author zbj
* @date 2023/11/28
*/
public static function handler($task)
public static function handler($task, $date = '')
{
$data = $task['data'];
$checkIpCountry = self::checkIpCountry($data['domain'], $data['ip'], $task['type']);
... ... @@ -53,7 +53,7 @@ class SyncSubmitTaskService
$action = $task['type'];
$handler = new self();
return $handler->$action($data);
return $handler->$action($data, $date);
}
... ... @@ -85,7 +85,7 @@ class SyncSubmitTaskService
* @author zbj
* @date 2023/12/4
*/
public function inquiry($data)
public function inquiry($data, $date)
{
$this->inquiryFilter($data['project_id'], $data);
... ... @@ -113,7 +113,7 @@ class SyncSubmitTaskService
* @author zbj
* @date 2023/12/4
*/
public function visit($data)
public function visit($data, $date)
{
$visit_data = $data['data'];
... ... @@ -132,7 +132,7 @@ class SyncSubmitTaskService
$visit_data['country'] = $data['country'];
$visit_data['updated_date'] = $data['submit_at']->toDateString();
$visit_data['created_at'] = $data['submit_at'];
Visit::saveData($visit_data);
Visit::saveData($visit_data, $date);
return true;
}
... ...