作者 刘锟

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

<?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 UpgradeProjectCount 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(){
$project_id = 555;
ProjectServer::useProject($project_id);
$this->count($project_id);
DB::disconnect('custom_mysql');
}
/**
* @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;
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();
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;
}
}
... ...
<?php
namespace App\Console\Commands;
use App\Models\Com\NoticeLog;
use App\Models\Product\Keyword;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
/**
* Class InitKeyword
* @package App\Console\Commands
*/
class InitKeyword extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'init_keyword';
/**
* The console command description.
*
* @var string
*/
protected $description = '批量导入关键字生成路由';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* @return bool
*/
public function handle()
{
while (true){
$notice_id = $this->getTask();
if (empty($notice_id)) {
sleep(30);
continue;
}
try {
$this->output(' taskID: ' . $notice_id . ' start');
$this->bind($notice_id);
$this->output(' taskID: ' . $notice_id . ' end');
} catch (\Exception $e) {
$this->output(' taskID: ' . $notice_id . ', error: ' . $e->getMessage());
}
sleep(2);
}
return true;
}
/**
* 处理子任务
* @param $notice_id
* @return bool
* @throws \Exception
*/
public function bind($notice_id)
{
$notice = NoticeLog::where(['id' => $notice_id])->first();
if (empty($notice) || $notice->type != NoticeLog::TYPE_INIT_KEYWORD || $notice->status != NoticeLog::STATUS_PENDING){
return true;
}
ProjectServer::useProject($notice['data']['project_id']);
$keyword = Keyword::whereNull('route')->get();
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']);
$val->route = $route;
$val->save();
} catch (\Exception $e) {
$this->output(' keywordID: ' . $val->id . ', title: ' . $val->title . ', error: ' . $e->getMessage());
}
}
$notice->status = NoticeLog::STATUS_SUCCESS;
$notice->save();
DB::disconnect('custom_mysql');
return true;
}
/**
* 获取需要处理的任务
* @return mixed
*/
public function getTask()
{
$key = 'notice_log_type_keyword';
$notice_id = Redis::rpop($key);
if ($notice_id){
return $notice_id;
}
$ids = NoticeLog::where('type', NoticeLog::TYPE_INIT_KEYWORD)->where('status', NoticeLog::STATUS_PENDING)->limit(100)->pluck('id');
foreach ($ids as $id) {
Redis::lpush($key, $id);
}
$notice_id = Redis::rpop($key);
return $notice_id;
}
/**
* 输出message
* @param $message
*/
public function output($message)
{
echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
}
}
... ...
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
*/
namespace App\Console\Commands\MonthlyCount;
use App\Helper\FormGlobalsoApi;
use App\Models\HomeCount\MonthCount;
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 UpgradeProjectCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_month_count';
/**
* The console command description.
*
* @var string
*/
protected $description = '升级项目统计';
public function handle(){
$project_id = 555;
$url = 'www.sincoherenaesthetics.com';
ProjectServer::useProject($project_id);
$this->count($project_id,$url);
DB::disconnect('custom_mysql');
}
/**
* @remark :日统计记录
* @name :count
* @author :lyh
* @method :post
* @time :2024/1/8 9:05
*/
public function count($project_id,$url){
$list = DB::connection('custom_mysql')->table('gl_customer_visit')
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
->groupBy('month')->get()->toArray();
foreach ($list as $k=>$v){
$v = (array)$v;
$monthCountModel = new MonthCount();
$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['month_total'] = 0;
if(isset($res['data']['count'])){
$arr['month_total'] = $res['data']['count'];
}
if(isset($res['data']['data'])){
$arr['country'] = json_encode($res['data']['data']);
}
$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;
$arr['month_total'] = $pv_ip->inquiry_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,$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;
}
}
... ...
... ... @@ -51,14 +51,15 @@ class UpdateRoute extends Command
*/
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['id'=>475]);
$list = $projectModel->list(['id'=>209]);
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();
$this->setProductKeyword();
// $this->getRouteMap();
$this->getProductCategory();
// $this->getProductCategory();
// $this->delRouteMap();
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
... ... @@ -101,24 +102,24 @@ class UpdateRoute extends Command
* @method :post
* @time :2023/12/8 11:13
*/
// public function getProductKeyword(){
// $keywordModel = new Keyword();
// $lists = $keywordModel->list(['status'=>1,'route'=>'']);
// if(!empty($lists)){
// foreach ($lists as $v){
// $tag = "-tag";
// if (!(substr($v['route'], -strlen($tag)) === $tag)) {
// echo date('Y-m-d H:i:s') . '拼接'.$tag . PHP_EOL;
// $route = $v['route'].$tag;
// // 如果不是以 '-tag' 结尾,则拼接上 '-tag'
// $routeModel = new RouteMap();
// $routeModel->edit(['route'=>$route],['source'=>RouteMap::SOURCE_PRODUCT_KEYWORD,'source_id'=>$v['id']]);
// $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
// echo date('Y-m-d H:i:s') . 'end'.$v['id'] . PHP_EOL;
// }
// }
// }
// }
public function getProductKeyword(){
$keywordModel = new Keyword();
$lists = $keywordModel->list(['status'=>1,'route'=>'']);
if(!empty($lists)){
foreach ($lists as $v){
$tag = "-tag";
if (!(substr($v['route'], -strlen($tag)) === $tag)) {
echo date('Y-m-d H:i:s') . '拼接'.$tag . PHP_EOL;
$route = $v['route'].$tag;
// 如果不是以 '-tag' 结尾,则拼接上 '-tag'
$routeModel = new RouteMap();
$routeModel->edit(['route'=>$route],['source'=>RouteMap::SOURCE_PRODUCT_KEYWORD,'source_id'=>$v['id']]);
$keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
echo date('Y-m-d H:i:s') . 'end'.$v['id'] . PHP_EOL;
}
}
}
}
public function getProduct(){
$productModel = new Product();
... ... @@ -225,4 +226,11 @@ class UpdateRoute extends Command
return true;
}
public function delRouteMap(){
$productKeywordModel = new Keyword();
$list = $productKeywordModel->list();
foreach ($list as $k=>$v){
RouteMap::setRoute($v['route'],'product_keyword',$v['id'],569);
}
}
}
... ...
... ... @@ -3,14 +3,17 @@
namespace App\Console\Commands;
use App\Helper\Arr;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\Domain\DomainInfo;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Carbon\Carbon;
use GuzzleHttp\Client;
use GuzzleHttp\Promise\Utils;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Str;
/**
... ... @@ -143,60 +146,71 @@ class WebTraffic extends Command
*/
public function handle()
{
$type = $this->argument('type');
try {
$type = $this->argument('type');
$this->sleep($type);
$this->sleep($type);
$project_list = $this->getProjectList($type);
$project_chunk = array_chunk($project_list,500,true);
foreach ($project_chunk as $chunk) {
$need_project = [];
foreach ($chunk as $project) {
//随机引流间隔
$res_sjjg = $this->get_rand($this->sjjg);
if ($res_sjjg == 1) {
continue;
$page = 1;
while (true){
$project_list = $this->getProjectList($type, $page);
if(!$project_list){
break;
}
$need_project = [];
foreach ($project_list as $project) {
//随机引流间隔
$res_sjjg = $this->get_rand($this->sjjg);
if ($res_sjjg == 1) {
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);
$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));
//最多10层深度
$client = new Client(['verify' => false]);
for ($j = 0; $j < 10; $j++) {
$need_project[] = $project;
}
//随机访问ip
$ips = $this->getIpAreas(count($need_project));
//最多10层深度
$client = new Client(['verify' => false]);
for ($j = 0; $j < 10; $j++) {
//并发请求
$promises = [];
foreach ($need_project as $project_key => $project) {
if (empty($project['visit_urls'][$j])) {
continue;
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'],
'referrer_url' => $this->getReferer($ips[$project_key]['ip_area']),
'url' => $project['visit_urls'][$j],
'device_port' => $project['device_port'],
'domain' => $project['domain'],
];
Log::channel('traffic')->info('traffic project_id:' . $project['project_id'], $data);
$promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
}
$data = [
'ip' => $ips[$project_key]['ip'],
'referer' => $this->getReferer($ips[$project_key]['ip_area']),
'url' => $project['visit_urls'][$j],
'device_port' => $this->get_rand($this->yddzb)
];
$promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
if($promises){
Utils::settle($promises)->wait();
//每个深度随机等待
sleep(rand(2, 10));
}
}
Utils::settle($promises)->wait();
//每个深度随机等待
sleep(rand(2, 10));
}
$page++;
}
}catch (\Exception $e){
Log::channel('traffic')->error($e->getMessage());
}
}
... ... @@ -216,35 +230,76 @@ class WebTraffic extends Command
/**
* 引流的项目
*/
protected function getProjectList($type){
//todo 根据type获取需要引流的项目
return [
[
'project_id' => 1,
'domain' => 'https://demomark.globalso.com/',
]
];
protected function getProjectList($type, $page){
//推广项目
$list = Project::with('domainInfo')
->leftJoin('gl_project_deploy_optimize', 'gl_project_deploy_optimize.project_id', '=', 'gl_project.id')
->where('gl_project_deploy_optimize.domain', '>', 0)
->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
->whereIn('gl_project_deploy_optimize.project_id', [6,25]) //todo 测试两个项目 后面删掉
->where(function ($query) use ($type){
if($type == 1){
//1-3个月项目
$startTime = Carbon::now()->addMonths(-4)->toDateString();
$endTime = Carbon::now()->addMonths(-1)->toDateString();
$query->whereBetween('gl_project_deploy_optimize.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('gl_project_deploy_optimize.start_date', [$startTime,$endTime]);
}else{
//大于9个月项目
$startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
$query->whereBetween('gl_project_deploy_optimize.start_date', '<', $startTime);
}
})->select('gl_project_deploy_optimize.project_id')->forPage($page, 500)->get();
//其他地方在引流的域名
$other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
$data = [];
foreach ($list as $project) {
//其他地方在引流就不再引流了
if(in_array($project->domainInfo['domain'], $other)){
continue;
}
$data[] = [
'project_id' => $project['project_id'],
'domain' => 'https://' . $project->domainInfo['domain'] . '/',
];
}
return $data;
}
/**
* 获取产品分类、单页和详情链接
*/
protected function getProductUrls($project_id){
//产品分类页面
ProjectServer::useProject($project_id);
//产品分类页面
$product_cate_ids = DB::connection('custom_mysql')->table('gl_product_category')
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
//只查发布的分类路由
$data['urls_cats'] = DB::connection('custom_mysql')->table('gl_route_map')
->where('project_id', $project_id)->where('source', 'product_category')->whereIn('source_id', $product_cate_ids)->get()->toArray();
->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT_CATE)
->whereIn('source_id', $product_cate_ids)->get()->toArray();
//单页面
//todo 发布状态的单页面id
$page_ids = DB::connection('custom_mysql')->table('gl_web_custom_template')
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
//只查发布的单页面
$data['urls_page'] = DB::connection('custom_mysql')->table('gl_route_map')
->where('project_id', $project_id)->where('source', 'page')->get()->toArray();
->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PAGE)
->whereIn('source_id', $page_ids)->get()->toArray();
//产品详情页
$product_ids = DB::connection('custom_mysql')->table('gl_product_category')
$product_ids = DB::connection('custom_mysql')->table('gl_product')
->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
$data['urls_details'] = DB::connection('custom_mysql')->table('gl_route_map')
->where('project_id', $project_id)->where('source', 'product')->whereIn('source_id', $product_ids)->get()->toArray();
->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT)
->whereIn('source_id', $product_ids)->get()->toArray();
$data['urls_cats'] = array_merge($data['urls_cats'], $data['urls_page']);
if(empty($data['urls_cats'])){
... ...
... ... @@ -26,9 +26,9 @@ class Kernel extends ConsoleKernel
$schedule->command('rank_data_week')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次
// $schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次
$schedule->command('count')->dailyAt('01:00')->withoutOverlapping(1); //每天凌晨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分钟一次
// $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分钟一次
$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号执行月统计转发询盘记录
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Helper;
use App\Models\Project\Project;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
... ... @@ -51,6 +52,8 @@ class FormGlobalsoApi
*/
public function getInquiryList($domain, $search = '', $page = 1, $page_size = 20)
{
$project = Project::getProjectByDomain($domain);
$is_upgrade = $project['is_upgrade'] ??0;
$api_url = $this->url . '/api/external-interface/6a1bd159b1fd60af';
$params = [
... ... @@ -58,7 +61,7 @@ class FormGlobalsoApi
'domain' => $domain,
'limit' => $page_size,
'page' => $page,
'source' => '1,3' //来源类型 新项目用1,3
'source' => $is_upgrade ? '1,2,3,4' : '1,3' //来源类型 新项目用1,3
];
if($search){
$params['name'] = $search;
... ...
<?php
/**
* Created by PhpStorm.
* User: zhl
* Date: 2024/1/6
* Time: 17:41
*/
namespace App\Http\Controllers\Api;
use App\Models\Domain\DomainInfo;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\Project\OnlineCheck;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Http\Request;
/**
* Class PrivateController
* @package App\Http\Controllers\Api
*/
class PrivateController extends BaseController
{
/**
* 优化中项目列表
* @param Request $request
* @return false|string
*/
public function optimizeProjectList(Request $request)
{
$page_size = $request->input('page_size', 20);
$field = ['gl_project.id', 'gl_project.company', 'gl_project.is_upgrade', 'b.start_date', 'd.domain'];
$result = Project::select($field)->leftJoin('gl_project_deploy_optimize as b', 'gl_project.id', '=', 'b.project_id')
->leftJoin('gl_project_online_check as c', 'gl_project.id', '=', 'c.project_id')
->leftJoin('gl_domain_info as d', 'gl_project.id', '=', 'd.project_id')
->where('c.qa_status', '=', OnlineCheck::STATUS_ONLINE_TRUE)
->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
->paginate($page_size)
->toArray();
return $this->success($result);
}
/**
* 获取项目链接
* FIXME 当前直接获取的产品和产品分类, 后期需要封装到内部, 需要添加完整的链接规则
* @param Request $request
* @return false|string
*/
public function getProjectRoute(Request $request)
{
$project_id = intval($request->input('project_id'));
// $type = $request->input('type');
$type = [RouteMap::SOURCE_PRODUCT, RouteMap::SOURCE_PRODUCT_CATE];
$project = Project::where(['id' => $project_id])->first();
if (empty($project))
return $this->error('未发现需要查找的项目!');
$project = ProjectServer::useProject($project_id);
$domain = DomainInfo::where(['project_id' => $project_id])->first();
$host = FALSE == empty($domain) ? 'https://' . $domain->domain . '/' : $project->deploy_build->test_domain;
// 需要标题, 不能直接查询map表
// $list = RouteMap::where(['project_id' => $project_id])
// ->when($type, function ($query) use ($type) {
// return $query->whereIn('source', $type);
// })
// ->get();
//
// $result = [];
// foreach ($list as $val) {
// // 排除首页
// if ($val->source == RouteMap::SOURCE_PAGE && in_array($val->route, ['index', '']))
// continue;
// $result[$val->source][] = $host . $val->route;
// }
$result = [];
$product = Product::where(['status' => Product::STATUS_ON])->get(['title', 'route'])->toArray();
foreach ($product as $val) {
$val['route'] = $host . $val['route'];
// FALSE == preg_match('/(\.html|\.htm)$/', $val['route'])
if (FALSE === strpos($val['route'], '.htm')) {
$val['route'] .= '/';
}
$result[RouteMap::SOURCE_PRODUCT][] = $val;
}
$product_category= Category::get(['title', 'route'])->toArray();
foreach ($product_category as $val) {
$val['route'] = $host . $val['route'];
if (FALSE === strpos($val['route'], '.htm')) {
$val['route'] .= '/';
}
$result[RouteMap::SOURCE_PRODUCT_CATE][] = $val;
}
return $this->success($result);
}
}
\ No newline at end of file
... ...
... ... @@ -69,7 +69,7 @@ class OptimizeController extends BaseController
if(!empty($list)){
foreach ($list as $v) {
$last = Arr::last($v);
if(isset($last['g']) && ($last['g'] == 1)){
if(isset($last['g']) && ($last['g'] == 1) && ($last['position'] <= 10) && ($last['position'] >= 1)){
$num = $num+1;
}
}
... ...
... ... @@ -63,6 +63,7 @@ class KeywordController extends BaseController
if(!empty($map['keyword_title'])){
$map['keyword_title'] = ['like','%'.$map['keyword_title'].'%'];
}
$map['route'] = ['<>',''];
$map['project_id'] = $this->user['project_id'];
return $this->success($map);
}
... ... @@ -99,11 +100,11 @@ class KeywordController extends BaseController
}
/**
* @remark :批量添加
* @name :batchAdd
* @author :lyh
* @method :post
* @time :2023/8/28 14:25
* 批量添加关键词
* FIXME 添加通知, 异步处理任务
* @param KeywordLogic $logic
* @throws \App\Exceptions\AsideGlobalException
* @throws \App\Exceptions\BsideGlobalException
*/
public function batchAdd(KeywordLogic $logic){
$this->request->validate([
... ... @@ -114,7 +115,7 @@ class KeywordController extends BaseController
'title.max' => '批量操作不能超过1000条数据'
]);
$logic->batchAdd();
$this->response('success');
$this->response('关键词后台异步添加中,请稍后刷新查看!');
}
/**
... ...
... ... @@ -297,7 +297,12 @@ class ProductController extends BaseController
}elseif($v['type'] == 4){
$arr1 = json_decode($info['values']);
foreach ($arr1 as $k1=>$v1){
$v1 = getFileUrl($v1);
$v1 = (array)$v1;
if(isset($v1['url'])){
$v1['url'] = getFileUrl($v1['url']);
}else{
$v1 = getFileUrl($v1);
}
$arr1[$k1] = $v1;
}
$v['values'] = $arr1;
... ...
... ... @@ -49,12 +49,15 @@ class CustomModuleLogic extends BaseLogic
* @time :2023/12/4 15:47
*/
public function customModuleSave(){
ProjectServer::useProject($this->param['project_id']);
$this->param = $this->handleParam($this->param);
$this->checkIsName($this->param['name'],$this->param['id'] ?? 0);
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->moduleEdit();
}else{
$this->moduleAdd();
}
DB::disconnect('custom_mysql');
return $this->success();
}
... ... @@ -81,12 +84,10 @@ class CustomModuleLogic extends BaseLogic
* @time :2023/12/5 9:39
*/
public function moduleAdd(){
ProjectServer::useProject($this->param['project_id']);
$rs = (new CustomModule())->add($this->param);
if($rs === false){
$this->fail('系统错误,请联系管理员');
}
DB::disconnect('custom_mysql');
return $this->success();
}
... ... @@ -98,16 +99,32 @@ class CustomModuleLogic extends BaseLogic
* @time :2023/12/5 9:39
*/
public function moduleEdit(){
ProjectServer::useProject($this->param['project_id']);
$rs = (new CustomModule())->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('系统错误,请联系管理员');
}
DB::disconnect('custom_mysql');
return $this->success();
}
/**
* @remark :验证名称是否存在
* @name :checkIsName
* @author :lyh
* @method :post
* @time :2024/1/6 14:06
*/
public function checkIsName($name,$id = 0){
$param['name'] = $name;
if(!empty($id)){
$param['id'] = ['id'=>['!=',$id],];
}
$info = (new CustomModule())->read($param);
if($info !== false){
$this->fail('当前名称已存在');
}
return $this->success();
}
/**
* @remark :删除数据
* @name :ModuleDel
* @author :lyh
... ...
... ... @@ -30,7 +30,7 @@ class MonthCountLogic extends BaseLogic
*/
public function getCountLists($map,$order = 'created_at',$filed = ['*']){
$map['project_id'] = $this->user['project_id'];
$lists = $this->model->list($map,$order,$filed);
$lists = $this->model->list($map,$order,$filed,'desc',10);
if(isset($this->project['is_record_china_visit']) && ($this->project['is_record_china_visit'] == 0)){
foreach ($lists as $k => $v){
if(empty($v['source_country'])){
... ...
... ... @@ -7,6 +7,7 @@ use App\Helper\Arr;
use App\Helper\Common;
use App\Helper\Translate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Com\NoticeLog;
use App\Models\News\News;
use App\Models\Product\Keyword;
use App\Models\Product\KeywordRelated;
... ... @@ -129,17 +130,12 @@ class KeywordLogic extends BaseLogic
}
/**
* @remark :批量添加数据
* @name :batchAdd
* @author :lyh
* @method :post
* @time :2023/8/28 14:03
* 批量添加关键词任务, 异步处理
* @return array
* @throws BsideGlobalException
* @throws \App\Exceptions\AsideGlobalException
*/
public function batchAdd(){
$route_array = Translate::tran($this->param['title'], 'en');
if (empty($route_array)) {
$this->fail('路由生成失败,请稍后重试!');
}
try {
foreach ($this->param['title'] as $k=>$v){
if(empty($v)){
... ... @@ -152,19 +148,43 @@ class KeywordLogic extends BaseLogic
$param['created_at'] = date('Y-m-d H:i:s');
$param['updated_at'] = $param['created_at'];
$param['title'] = $v;
$id = $this->model->insertGetId($param);
$route = RouteMap::setRoute($route_array[$k], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
// $this->curlDelRoute(['new_route'=>$route]);
$this->model->edit(['route'=>$route],['id'=>$id]);
$this->model->insertGetId($param);
}
}
NoticeLog::createLog(NoticeLog::TYPE_INIT_KEYWORD, ['project_id' => $this->user['project_id']]);
}catch (\Exception $e){
$this->fail('error');
$this->fail('创建任务添加关键词任务失败,请稍后重试!');
}
return $this->success();
}
/**
* @remark :
* @name :specialRouteCheck
* @author :lyh
* @method :post
* @time :2024/1/6 14:50
*/
public function specialRouteCheck($title)
{
if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $title)){
$title = Translate::tran($title, 'en');
}
$suffix = '-tag';
$i = 1;
$sign = generateRoute($title);
$route = $sign . $suffix;
resetRoute:
$log = RouteMap::getRouteInfo($route, $this->user['project_id']);
if ($log) {
$route = $sign .'-'.$i.$suffix;
$i++;
goto resetRoute;
}
return $route;
}
/**
* @remark :删除标签
* @name :keywordDelete
* @author :lyh
... ...
... ... @@ -175,7 +175,7 @@ class ProductLogic extends BaseLogic
$v['values'] = json_encode($v['values']);
}elseif ($v['type'] == 4){
foreach ($v['values'] as $k1=>$v1){
$v1 = str_replace_url($v1);
$v1['url'] = str_replace_url($v1['url']);
$v['values'][$k1] = $v1;
}
$v['values'] = json_encode($v['values']);
... ...
... ... @@ -12,7 +12,7 @@ class NoticeLog extends Model
const TYPE_PROJECT = 'project';
const TYPE_RANK_DATA = 'rank_data';
const TYPE_INIT_PROJECT = 'init_project';
const TYPE_INIT_KEYWORD = 'init_keyword';
const STATUS_PENDING = 0;
const STATUS_SUCCESS = 1;
const STATUS_FAIL = 2;
... ...
... ... @@ -9,4 +9,6 @@ class OnlineCheck extends Base
//设置关联表名
protected $table = 'gl_project_online_check';
const STATUS_ONLINE_FALSE = 0;
const STATUS_ONLINE_TRUE = 1;
}
... ...
... ... @@ -22,8 +22,8 @@ class Project extends Base
const STATUS_ONE = 1;//审核通过
const TYPE_ZERO = 0;//初始导入项目
const TYPE_ONE = 1;//建站中
const TYPE_TWO = 2;//建站完成
const TYPE_THREE = 3;//建站完成(推广)
const TYPE_TWO = 2;//建站完成(推广)
const TYPE_THREE = 3;//建站完成
const TYPE_FOUR = 4;//推广续费
const TYPE_FIVE = 5;//未续费网站
const TYPE_SIX = 6;//特殊推广项目
... ... @@ -202,6 +202,16 @@ class Project extends Base
return self::hasOne(After::class, 'project_id', 'id');
}
/**
* 域名
* @return \Illuminate\Database\Eloquent\Relations\HasOne
* @author zbj
*/
public function domainInfo()
{
return self::hasOne(\App\Models\Domain\DomainInfo::class, 'project_id', 'project_id')->select('project_id', 'domain');;
}
public function setLevelAttribute($value)
{
$this->attributes['level'] = Arr::arrToSet($value);
... ... @@ -284,24 +294,15 @@ class Project extends Base
*/
public static function getProjectByDomain($domain)
{
$cache_key = 'project_' . $domain;
$data = Cache::get($cache_key);
if (!$data) {
//是否测试域名
$project_id = DeployBuild::where('test_domain', $domain)->value('project_id');
//是否正式域名
if (!$project_id) {
$project_id = DeployOptimize::where('domain', $domain)->value('project_id');
}
if (!$project_id) {
return [];
}
$data = self::find($project_id);
if ($data) {
Cache::put($cache_key, $data);
}
$domain = parse_url($domain);
$domain = $domain['host'] ?? $domain;
//是否测试域名
$project_id = DeployBuild::where('test_domain', $domain)->value('project_id');
//是否正式域名
if (!$project_id) {
$project_id = \App\Models\Domain\DomainInfo::where('domain', $domain)->value('project_id');
}
return $data;
return self::find($project_id ?: 0);
}
/**
... ...
... ... @@ -60,6 +60,12 @@ return [
'via' => \App\Factory\LogFormatterFactory::class,
'prefix' => 'bside',
],
//自定义引流日志
'traffic' => [
'driver' => 'custom',
'via' => \App\Factory\LogFormatterFactory::class,
'prefix' => 'traffic',
],
'wechatside' => [
'driver' => 'custom',
'via' => \App\Factory\LogFormatterFactory::class,
... ...
... ... @@ -18,4 +18,6 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::any('traffic_visit', [\App\Http\Controllers\Api\NoticeController::class, 'trafficVisit'])->name('api.traffic_visit');
\ No newline at end of file
Route::any('traffic_visit', [\App\Http\Controllers\Api\NoticeController::class, 'trafficVisit'])->name('api.traffic_visit');
Route::get('optimize_project_list', [\App\Http\Controllers\Api\PrivateController::class, 'optimizeProjectList'])->name('api.optimize_project_list');
Route::get('get_project_route', [\App\Http\Controllers\Api\PrivateController::class, 'getProjectRoute'])->name('api.get_project_route');
\ No newline at end of file
... ...