作者 刘锟

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

  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :UpgradeProjectCount.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/1/8 9:03
  8 + */
  9 +
  10 +namespace App\Console\Commands\DayCount;
  11 +
  12 +use App\Models\Project\Project;
  13 +use App\Models\Visit\Visit;
  14 +use App\Services\ProjectServer;
  15 +use Illuminate\Console\Command;
  16 +use Illuminate\Support\Facades\DB;
  17 +use App\Models\HomeCount\Count;
  18 +
  19 +class UpgradeProjectCount extends Command
  20 +{
  21 + /**
  22 + * The name and signature of the console command.
  23 + *
  24 + * @var string
  25 + */
  26 + protected $signature = 'upgrade_count';
  27 +
  28 + /**
  29 + * The console command description.
  30 + *
  31 + * @var string
  32 + */
  33 + protected $description = '升级项目统计';
  34 +
  35 + public function handle(){
  36 + $project_id = 555;
  37 + ProjectServer::useProject($project_id);
  38 + $this->count($project_id);
  39 + DB::disconnect('custom_mysql');
  40 + }
  41 +
  42 + /**
  43 + * @remark :日统计记录
  44 + * @name :count
  45 + * @author :lyh
  46 + * @method :post
  47 + * @time :2024/1/8 9:05
  48 + */
  49 + public function count($project_id){
  50 + $list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date')
  51 + ->groupBy('updated_date')->get()->toArray();
  52 + $project = new Project();
  53 + $projectInfo = $project->read(['id'=>$project_id]);
  54 + if(!empty($list)){
  55 + $arr = [];
  56 + foreach ($list as $k=>$v){
  57 + $v = (array)$v;
  58 + echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL;
  59 + $count = new Count();
  60 + $arr['project_id'] = $project_id;
  61 + $arr['date'] = $v['updated_date'];
  62 + $arr['pv_num'] = $this->pv_num($v['updated_date']);
  63 + $arr['ip_num'] = $this->ip_num($v['updated_date']);
  64 + $arr['inquiry_num'] = $this->inquiry_num($v['updated_date']);
  65 + //服务达标天数
  66 + $arr['compliance_day'] = $projectInfo['finish_remain_day'];
  67 + //剩余服务时常
  68 + $arr['service_day'] = $projectInfo['remain_day'];
  69 + $arr['country'] = json_encode([]);
  70 + //查询当天数据是否存在 存在则更新
  71 + $info = $count->read(['date'=>$v['updated_date'],'project_id'=>$project_id]);
  72 + if($info === false){
  73 + $arr['created_at'] = $v['updated_date'].' 01:00:00';
  74 + $arr['updated_at'] = $v['updated_date'].' 01:00:00';
  75 + $count->insert($arr);
  76 + }else{
  77 + $count->edit($arr,['id'=>$info['id']]);
  78 + }
  79 + }
  80 + }
  81 + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
  82 + }
  83 +
  84 + /**
  85 + * @remark :询盘数量
  86 + * @name :inquiry_num
  87 + * @author :lyh
  88 + * @method :post
  89 + * @time :2024/1/8 9:24
  90 + */
  91 + public function inquiry_num($day){
  92 + $count = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->where('is_inquiry',1)->count();
  93 + return $count;
  94 + }
  95 +
  96 + /**
  97 + * @name :(统计pv)pv_num
  98 + * @author :lyh
  99 + * @method :post
  100 + * @time :2023/6/14 15:40
  101 + */
  102 + public function pv_num($day){
  103 + $pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $day)->count();
  104 + return $pv;
  105 + }
  106 +
  107 + /**
  108 + * @name :(统计ip)ip_num
  109 + * @author :lyh
  110 + * @method :post
  111 + * @time :2023/6/14 15:40
  112 + */
  113 + public function ip_num($day){
  114 + $ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->count();
  115 + return $ip;
  116 + }
  117 +
  118 +
  119 +
  120 +}
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Models\Com\NoticeLog;
  6 +use App\Models\Product\Keyword;
  7 +use App\Models\RouteMap\RouteMap;
  8 +use App\Services\ProjectServer;
  9 +use Illuminate\Console\Command;
  10 +use Illuminate\Support\Facades\DB;
  11 +use Illuminate\Support\Facades\Redis;
  12 +
  13 +/**
  14 + * Class InitKeyword
  15 + * @package App\Console\Commands
  16 + */
  17 +class InitKeyword extends Command
  18 +{
  19 + /**
  20 + * The name and signature of the console command.
  21 + *
  22 + * @var string
  23 + */
  24 + protected $signature = 'init_keyword';
  25 +
  26 + /**
  27 + * The console command description.
  28 + *
  29 + * @var string
  30 + */
  31 + protected $description = '批量导入关键字生成路由';
  32 +
  33 + /**
  34 + * Create a new command instance.
  35 + *
  36 + * @return void
  37 + */
  38 + public function __construct()
  39 + {
  40 + parent::__construct();
  41 + }
  42 +
  43 + /**
  44 + * @return bool
  45 + */
  46 + public function handle()
  47 + {
  48 + while (true){
  49 + $notice_id = $this->getTask();
  50 + if (empty($notice_id)) {
  51 + sleep(30);
  52 + continue;
  53 + }
  54 + try {
  55 + $this->output(' taskID: ' . $notice_id . ' start');
  56 + $this->bind($notice_id);
  57 + $this->output(' taskID: ' . $notice_id . ' end');
  58 + } catch (\Exception $e) {
  59 + $this->output(' taskID: ' . $notice_id . ', error: ' . $e->getMessage());
  60 + }
  61 + sleep(2);
  62 + }
  63 + return true;
  64 + }
  65 +
  66 + /**
  67 + * 处理子任务
  68 + * @param $notice_id
  69 + * @return bool
  70 + * @throws \Exception
  71 + */
  72 + public function bind($notice_id)
  73 + {
  74 + $notice = NoticeLog::where(['id' => $notice_id])->first();
  75 + if (empty($notice) || $notice->type != NoticeLog::TYPE_INIT_KEYWORD || $notice->status != NoticeLog::STATUS_PENDING){
  76 + return true;
  77 + }
  78 + ProjectServer::useProject($notice['data']['project_id']);
  79 + $keyword = Keyword::whereNull('route')->get();
  80 + foreach ($keyword as $val) {
  81 + $this->output(' keywordID: ' . $val->id . ', title: ' . $val->title);
  82 + try {
  83 + $route = RouteMap::setRoute($val['title'],RouteMap::SOURCE_PRODUCT_KEYWORD, $val->id, $notice['data']['project_id']);
  84 + $val->route = $route;
  85 + $val->save();
  86 + } catch (\Exception $e) {
  87 + $this->output(' keywordID: ' . $val->id . ', title: ' . $val->title . ', error: ' . $e->getMessage());
  88 + }
  89 + }
  90 +
  91 + $notice->status = NoticeLog::STATUS_SUCCESS;
  92 + $notice->save();
  93 + DB::disconnect('custom_mysql');
  94 + return true;
  95 + }
  96 +
  97 + /**
  98 + * 获取需要处理的任务
  99 + * @return mixed
  100 + */
  101 + public function getTask()
  102 + {
  103 + $key = 'notice_log_type_keyword';
  104 + $notice_id = Redis::rpop($key);
  105 + if ($notice_id){
  106 + return $notice_id;
  107 + }
  108 + $ids = NoticeLog::where('type', NoticeLog::TYPE_INIT_KEYWORD)->where('status', NoticeLog::STATUS_PENDING)->limit(100)->pluck('id');
  109 + foreach ($ids as $id) {
  110 + Redis::lpush($key, $id);
  111 + }
  112 + $notice_id = Redis::rpop($key);
  113 + return $notice_id;
  114 + }
  115 +
  116 + /**
  117 + * 输出message
  118 + * @param $message
  119 + */
  120 + public function output($message)
  121 + {
  122 + echo date('Y-m-d H:i:s') . ' ' . $message . PHP_EOL;
  123 + }
  124 +}
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :UpgradeProjectCount.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2024/1/8 9:03
  8 + */
  9 +
  10 +namespace App\Console\Commands\MonthlyCount;
  11 +
  12 +use App\Helper\FormGlobalsoApi;
  13 +use App\Models\HomeCount\MonthCount;
  14 +use App\Models\Project\Project;
  15 +use App\Models\Visit\Visit;
  16 +use App\Services\ProjectServer;
  17 +use Illuminate\Console\Command;
  18 +use Illuminate\Support\Facades\DB;
  19 +use App\Models\HomeCount\Count;
  20 +
  21 +class UpgradeProjectCount extends Command
  22 +{
  23 + /**
  24 + * The name and signature of the console command.
  25 + *
  26 + * @var string
  27 + */
  28 + protected $signature = 'upgrade_month_count';
  29 +
  30 + /**
  31 + * The console command description.
  32 + *
  33 + * @var string
  34 + */
  35 + protected $description = '升级项目统计';
  36 +
  37 + public function handle(){
  38 + $project_id = 555;
  39 + $url = 'www.sincoherenaesthetics.com';
  40 + ProjectServer::useProject($project_id);
  41 + $this->count($project_id,$url);
  42 +
  43 + DB::disconnect('custom_mysql');
  44 + }
  45 +
  46 + /**
  47 + * @remark :日统计记录
  48 + * @name :count
  49 + * @author :lyh
  50 + * @method :post
  51 + * @time :2024/1/8 9:05
  52 + */
  53 + public function count($project_id,$url){
  54 + $list = DB::connection('custom_mysql')->table('gl_customer_visit')
  55 + ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
  56 + ->groupBy('month')->get()->toArray();
  57 + foreach ($list as $k=>$v){
  58 + $v = (array)$v;
  59 + $monthCountModel = new MonthCount();
  60 + $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
  61 + // 获取当月开始时间
  62 + $start = date('Y-m-01', strtotime($v['month']));
  63 + // 获取当月结束时间
  64 + $end = date('Y-m-t', strtotime($v['month']));
  65 + $arr['project_id'] = $project_id;
  66 + $res = $this->inquiry($url,$v['month']);
  67 + $arr['month_total'] = 0;
  68 + if(isset($res['data']['count'])){
  69 + $arr['month_total'] = $res['data']['count'];
  70 + }
  71 + if(isset($res['data']['data'])){
  72 + $arr['country'] = json_encode($res['data']['data']);
  73 + }
  74 + $arr['month'] = $v['month'];
  75 + $arr = $this->pv_ip($arr,$start,$end,$project_id);
  76 + $arr = $this->sourceCount($arr,$start,$end);
  77 + if($info === false){
  78 + $selectedDate = $start;
  79 + $firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
  80 + $arr['created_at'] = $firstDayOfNextMonth;
  81 + $arr['updated_at'] = $firstDayOfNextMonth;
  82 +// echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL;
  83 + $monthCountModel->insert($arr);
  84 + }else{
  85 + $monthCountModel->edit($arr,['id'=>$info['id']]);
  86 + }
  87 + }
  88 + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
  89 + }
  90 +
  91 + /**
  92 + * @remark :本月询盘总量
  93 + * @name :month_total
  94 + * @author :lyh
  95 + * @method :post
  96 + * @time :2024/1/8 11:02
  97 + */
  98 + public function pv_ip(&$arr,$start,$end,$project_id){
  99 + $pv_ip = DB::table('gl_count')
  100 + ->where(['project_id'=>$project_id])
  101 + ->where('date','>=',$start.' 00:00:00')
  102 + ->where('date','<=',$end.' 23:59:59')
  103 + ->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'))
  104 + ->first();
  105 + $arr['pv'] = $pv_ip->pv_num;
  106 + $arr['ip'] = $pv_ip->ip_num;
  107 + $arr['month_total'] = $pv_ip->inquiry_num;
  108 + if($arr['ip'] != 0){
  109 + $arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
  110 + }
  111 + return $arr;
  112 + }
  113 + /**
  114 + * @remark :来源访问前8
  115 + * @name :sourceCount
  116 + * @author :lyh
  117 + * @method :post
  118 + * @time :2023/6/30 16:14
  119 + */
  120 + public function sourceCount(&$arr,$startTime,$endTime){
  121 + //访问来源前10
  122 + $source = DB::connection('custom_mysql')->table('gl_customer_visit')
  123 + ->select('referrer_url', DB::raw('COUNT(*) as count'))
  124 + ->groupBy('referrer_url')
  125 + ->whereBetween('updated_date', [$startTime,$endTime])
  126 + ->orderByDesc('count')->limit(10)->get()->toArray();
  127 + $arr['source'] = json_encode($source);
  128 + //访问国家前15
  129 + $source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
  130 + ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
  131 + ->groupBy('country')
  132 + ->whereBetween('updated_date', [$startTime,$endTime])
  133 + ->orderBy('ip','desc')->limit(15)->get()->toArray();
  134 + $arr['source_country'] = json_encode($source_country);
  135 + //受访界面前15
  136 + $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
  137 + ->select('url',DB::raw('COUNT(*) as num'))
  138 + ->orderBy('num','desc')
  139 + ->whereBetween('updated_date', [$startTime,$endTime])
  140 + ->groupBy('url')
  141 + ->limit(15)->get()->toArray();
  142 + $arr['referrer_url'] = json_encode($referrer_url);
  143 + //访问端口
  144 + $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
  145 + ->select('device_port',DB::raw('COUNT(*) as num'))
  146 + ->orderBy('num','desc')
  147 + ->whereBetween('updated_date', [$startTime,$endTime])
  148 + ->groupBy('device_port')
  149 + ->limit(15)->get()->toArray();
  150 + $arr['referrer_port'] = json_encode($referrer_port);
  151 + return $arr;
  152 + }
  153 +
  154 + public function inquiry($url,$month){
  155 + $url = 'https://'.$url.'/';
  156 + $token = md5($url.date("Y-m-d"));
  157 + $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;
  158 + $res = http_get($url,['charset=utf-8']);
  159 + echo date('Y-m-d H:i:s') . '数据:'.json_encode($res) . PHP_EOL;
  160 + return $res;
  161 + }
  162 +
  163 +}
@@ -51,14 +51,15 @@ class UpdateRoute extends Command @@ -51,14 +51,15 @@ class UpdateRoute extends Command
51 */ 51 */
52 public function handle(){ 52 public function handle(){
53 $projectModel = new Project(); 53 $projectModel = new Project();
54 - $list = $projectModel->list(['id'=>475]); 54 + $list = $projectModel->list(['id'=>209]);
55 foreach ($list as $v){ 55 foreach ($list as $v){
56 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL; 56 echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
57 ProjectServer::useProject($v['id']); 57 ProjectServer::useProject($v['id']);
58 // $this->getProduct(); 58 // $this->getProduct();
59 -// $this->setProductKeyword(); 59 + $this->setProductKeyword();
60 // $this->getRouteMap(); 60 // $this->getRouteMap();
61 - $this->getProductCategory(); 61 +// $this->getProductCategory();
  62 +// $this->delRouteMap();
62 DB::disconnect('custom_mysql'); 63 DB::disconnect('custom_mysql');
63 } 64 }
64 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 65 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
@@ -101,24 +102,24 @@ class UpdateRoute extends Command @@ -101,24 +102,24 @@ class UpdateRoute extends Command
101 * @method :post 102 * @method :post
102 * @time :2023/12/8 11:13 103 * @time :2023/12/8 11:13
103 */ 104 */
104 -// public function getProductKeyword(){  
105 -// $keywordModel = new Keyword();  
106 -// $lists = $keywordModel->list(['status'=>1,'route'=>'']);  
107 -// if(!empty($lists)){  
108 -// foreach ($lists as $v){  
109 -// $tag = "-tag";  
110 -// if (!(substr($v['route'], -strlen($tag)) === $tag)) {  
111 -// echo date('Y-m-d H:i:s') . '拼接'.$tag . PHP_EOL;  
112 -// $route = $v['route'].$tag;  
113 -// // 如果不是以 '-tag' 结尾,则拼接上 '-tag'  
114 -// $routeModel = new RouteMap();  
115 -// $routeModel->edit(['route'=>$route],['source'=>RouteMap::SOURCE_PRODUCT_KEYWORD,'source_id'=>$v['id']]);  
116 -// $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);  
117 -// echo date('Y-m-d H:i:s') . 'end'.$v['id'] . PHP_EOL;  
118 -// }  
119 -// }  
120 -// }  
121 -// } 105 + public function getProductKeyword(){
  106 + $keywordModel = new Keyword();
  107 + $lists = $keywordModel->list(['status'=>1,'route'=>'']);
  108 + if(!empty($lists)){
  109 + foreach ($lists as $v){
  110 + $tag = "-tag";
  111 + if (!(substr($v['route'], -strlen($tag)) === $tag)) {
  112 + echo date('Y-m-d H:i:s') . '拼接'.$tag . PHP_EOL;
  113 + $route = $v['route'].$tag;
  114 + // 如果不是以 '-tag' 结尾,则拼接上 '-tag'
  115 + $routeModel = new RouteMap();
  116 + $routeModel->edit(['route'=>$route],['source'=>RouteMap::SOURCE_PRODUCT_KEYWORD,'source_id'=>$v['id']]);
  117 + $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);
  118 + echo date('Y-m-d H:i:s') . 'end'.$v['id'] . PHP_EOL;
  119 + }
  120 + }
  121 + }
  122 + }
122 123
123 public function getProduct(){ 124 public function getProduct(){
124 $productModel = new Product(); 125 $productModel = new Product();
@@ -225,4 +226,11 @@ class UpdateRoute extends Command @@ -225,4 +226,11 @@ class UpdateRoute extends Command
225 return true; 226 return true;
226 } 227 }
227 228
  229 + public function delRouteMap(){
  230 + $productKeywordModel = new Keyword();
  231 + $list = $productKeywordModel->list();
  232 + foreach ($list as $k=>$v){
  233 + RouteMap::setRoute($v['route'],'product_keyword',$v['id'],569);
  234 + }
  235 + }
228 } 236 }
@@ -3,14 +3,17 @@ @@ -3,14 +3,17 @@
3 namespace App\Console\Commands; 3 namespace App\Console\Commands;
4 4
5 use App\Helper\Arr; 5 use App\Helper\Arr;
6 -use App\Models\Product\Category;  
7 -use App\Models\Product\Product; 6 +use App\Models\Domain\DomainInfo;
  7 +use App\Models\Project\DeployOptimize;
  8 +use App\Models\Project\Project;
8 use App\Models\RouteMap\RouteMap; 9 use App\Models\RouteMap\RouteMap;
9 use App\Services\ProjectServer; 10 use App\Services\ProjectServer;
  11 +use Carbon\Carbon;
10 use GuzzleHttp\Client; 12 use GuzzleHttp\Client;
11 use GuzzleHttp\Promise\Utils; 13 use GuzzleHttp\Promise\Utils;
12 use Illuminate\Console\Command; 14 use Illuminate\Console\Command;
13 use Illuminate\Support\Facades\DB; 15 use Illuminate\Support\Facades\DB;
  16 +use Illuminate\Support\Facades\Log;
14 use Illuminate\Support\Str; 17 use Illuminate\Support\Str;
15 18
16 /** 19 /**
@@ -143,16 +146,19 @@ class WebTraffic extends Command @@ -143,16 +146,19 @@ class WebTraffic extends Command
143 */ 146 */
144 public function handle() 147 public function handle()
145 { 148 {
  149 + try {
146 $type = $this->argument('type'); 150 $type = $this->argument('type');
147 151
148 $this->sleep($type); 152 $this->sleep($type);
149 153
150 - $project_list = $this->getProjectList($type);  
151 - $project_chunk = array_chunk($project_list,500,true);  
152 -  
153 - foreach ($project_chunk as $chunk) { 154 + $page = 1;
  155 + while (true){
  156 + $project_list = $this->getProjectList($type, $page);
  157 + if(!$project_list){
  158 + break;
  159 + }
154 $need_project = []; 160 $need_project = [];
155 - foreach ($chunk as $project) { 161 + foreach ($project_list as $project) {
156 //随机引流间隔 162 //随机引流间隔
157 $res_sjjg = $this->get_rand($this->sjjg); 163 $res_sjjg = $this->get_rand($this->sjjg);
158 if ($res_sjjg == 1) { 164 if ($res_sjjg == 1) {
@@ -169,7 +175,6 @@ class WebTraffic extends Command @@ -169,7 +175,6 @@ class WebTraffic extends Command
169 175
170 $need_project[] = $project; 176 $need_project[] = $project;
171 } 177 }
172 -  
173 //随机访问ip 178 //随机访问ip
174 $ips = $this->getIpAreas(count($need_project)); 179 $ips = $this->getIpAreas(count($need_project));
175 //最多10层深度 180 //最多10层深度
@@ -185,19 +190,28 @@ class WebTraffic extends Command @@ -185,19 +190,28 @@ class WebTraffic extends Command
185 190
186 $data = [ 191 $data = [
187 'ip' => $ips[$project_key]['ip'], 192 'ip' => $ips[$project_key]['ip'],
188 - 'referer' => $this->getReferer($ips[$project_key]['ip_area']), 193 + 'referrer_url' => $this->getReferer($ips[$project_key]['ip_area']),
189 'url' => $project['visit_urls'][$j], 194 'url' => $project['visit_urls'][$j],
190 - 'device_port' => $this->get_rand($this->yddzb) 195 + 'device_port' => $project['device_port'],
  196 + 'domain' => $project['domain'],
191 ]; 197 ];
  198 + Log::channel('traffic')->info('traffic project_id:' . $project['project_id'], $data);
192 $promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]); 199 $promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
193 } 200 }
194 - Utils::settle($promises)->wait();  
195 201
  202 + if($promises){
  203 + Utils::settle($promises)->wait();
196 //每个深度随机等待 204 //每个深度随机等待
197 sleep(rand(2, 10)); 205 sleep(rand(2, 10));
198 } 206 }
199 } 207 }
200 } 208 }
  209 +
  210 + $page++;
  211 + }
  212 + }catch (\Exception $e){
  213 + Log::channel('traffic')->error($e->getMessage());
  214 + }
201 } 215 }
202 216
203 /** 217 /**
@@ -216,35 +230,76 @@ class WebTraffic extends Command @@ -216,35 +230,76 @@ class WebTraffic extends Command
216 /** 230 /**
217 * 引流的项目 231 * 引流的项目
218 */ 232 */
219 - protected function getProjectList($type){  
220 - //todo 根据type获取需要引流的项目  
221 - return [  
222 - [  
223 - 'project_id' => 1,  
224 - 'domain' => 'https://demomark.globalso.com/',  
225 - ] 233 + protected function getProjectList($type, $page){
  234 + //推广项目
  235 + $list = Project::with('domainInfo')
  236 + ->leftJoin('gl_project_deploy_optimize', 'gl_project_deploy_optimize.project_id', '=', 'gl_project.id')
  237 + ->where('gl_project_deploy_optimize.domain', '>', 0)
  238 + ->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
  239 + ->whereIn('gl_project_deploy_optimize.project_id', [6,25]) //todo 测试两个项目 后面删掉
  240 + ->where(function ($query) use ($type){
  241 + if($type == 1){
  242 + //1-3个月项目
  243 + $startTime = Carbon::now()->addMonths(-4)->toDateString();
  244 + $endTime = Carbon::now()->addMonths(-1)->toDateString();
  245 + $query->whereBetween('gl_project_deploy_optimize.start_date', [$startTime,$endTime]);
  246 + }elseif($type == 2){
  247 + //4-8个月项目
  248 + $startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
  249 + $endTime = Carbon::now()->addMonths(-4)->endOfDay()->toDateTimeString();
  250 + $query->whereBetween('gl_project_deploy_optimize.start_date', [$startTime,$endTime]);
  251 + }else{
  252 + //大于9个月项目
  253 + $startTime = Carbon::now()->addMonths(-9)->startOfDay()->toDateTimeString();
  254 + $query->whereBetween('gl_project_deploy_optimize.start_date', '<', $startTime);
  255 + }
  256 + })->select('gl_project_deploy_optimize.project_id')->forPage($page, 500)->get();
  257 +
  258 + //其他地方在引流的域名
  259 + $other = DB::connection('projects_mysql')->table('projects')->where('switch', 1)->pluck('domain')->toArray();
  260 +
  261 + $data = [];
  262 + foreach ($list as $project) {
  263 + //其他地方在引流就不再引流了
  264 + if(in_array($project->domainInfo['domain'], $other)){
  265 + continue;
  266 + }
  267 + $data[] = [
  268 + 'project_id' => $project['project_id'],
  269 + 'domain' => 'https://' . $project->domainInfo['domain'] . '/',
226 ]; 270 ];
227 } 271 }
228 272
  273 + return $data;
  274 + }
  275 +
229 /** 276 /**
230 * 获取产品分类、单页和详情链接 277 * 获取产品分类、单页和详情链接
231 */ 278 */
232 protected function getProductUrls($project_id){ 279 protected function getProductUrls($project_id){
233 - //产品分类页面  
234 ProjectServer::useProject($project_id); 280 ProjectServer::useProject($project_id);
  281 + //产品分类页面
235 $product_cate_ids = DB::connection('custom_mysql')->table('gl_product_category') 282 $product_cate_ids = DB::connection('custom_mysql')->table('gl_product_category')
236 ->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray(); 283 ->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
  284 + //只查发布的分类路由
237 $data['urls_cats'] = DB::connection('custom_mysql')->table('gl_route_map') 285 $data['urls_cats'] = DB::connection('custom_mysql')->table('gl_route_map')
238 - ->where('project_id', $project_id)->where('source', 'product_category')->whereIn('source_id', $product_cate_ids)->get()->toArray(); 286 + ->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT_CATE)
  287 + ->whereIn('source_id', $product_cate_ids)->get()->toArray();
  288 +
239 //单页面 289 //单页面
240 - //todo 发布状态的单页面id 290 + $page_ids = DB::connection('custom_mysql')->table('gl_web_custom_template')
  291 + ->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
  292 + //只查发布的单页面
241 $data['urls_page'] = DB::connection('custom_mysql')->table('gl_route_map') 293 $data['urls_page'] = DB::connection('custom_mysql')->table('gl_route_map')
242 - ->where('project_id', $project_id)->where('source', 'page')->get()->toArray(); 294 + ->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PAGE)
  295 + ->whereIn('source_id', $page_ids)->get()->toArray();
  296 +
243 //产品详情页 297 //产品详情页
244 - $product_ids = DB::connection('custom_mysql')->table('gl_product_category') 298 + $product_ids = DB::connection('custom_mysql')->table('gl_product')
245 ->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray(); 299 ->where('project_id', $project_id)->where('status', 1)->pluck('id')->toArray();
246 $data['urls_details'] = DB::connection('custom_mysql')->table('gl_route_map') 300 $data['urls_details'] = DB::connection('custom_mysql')->table('gl_route_map')
247 - ->where('project_id', $project_id)->where('source', 'product')->whereIn('source_id', $product_ids)->get()->toArray(); 301 + ->where('project_id', $project_id)->where('source', RouteMap::SOURCE_PRODUCT)
  302 + ->whereIn('source_id', $product_ids)->get()->toArray();
248 303
249 $data['urls_cats'] = array_merge($data['urls_cats'], $data['urls_page']); 304 $data['urls_cats'] = array_merge($data['urls_cats'], $data['urls_page']);
250 if(empty($data['urls_cats'])){ 305 if(empty($data['urls_cats'])){
@@ -26,9 +26,9 @@ class Kernel extends ConsoleKernel @@ -26,9 +26,9 @@ class Kernel extends ConsoleKernel
26 $schedule->command('rank_data_week')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次 26 $schedule->command('rank_data_week')->dailyAt('01:00')->withoutOverlapping(1); // 排名数据,每周一凌晨执行一次
27 // $schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次 27 // $schedule->command('share_user')->dailyAt('01:00')->withoutOverlapping(1); // 清除用户ayr_share数据,每天凌晨1点执行一次
28 $schedule->command('count')->dailyAt('01:00')->withoutOverlapping(1); //每天凌晨1点执行一次 28 $schedule->command('count')->dailyAt('01:00')->withoutOverlapping(1); //每天凌晨1点执行一次
29 - $schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次  
30 - $schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次  
31 - $schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次 29 +// $schedule->command('web_traffic 1')->everyThirtyMinutes(); // 引流 1-3个月的项目,半小时一次
  30 +// $schedule->command('web_traffic 2')->cron('*/18 * * * *'); // 引流 4-8个月的项目,18分钟一次
  31 +// $schedule->command('web_traffic 3')->cron('*/12 * * * *'); // 引流 大于9个月的项目,12分钟一次
32 $schedule->command('sync_channel')->dailyAt('06:00')->withoutOverlapping(1); // 渠道信息,每天执行一次 32 $schedule->command('sync_channel')->dailyAt('06:00')->withoutOverlapping(1); // 渠道信息,每天执行一次
33 $schedule->command('month_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计记录 33 $schedule->command('month_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计记录
34 $schedule->command('forward_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计转发询盘记录 34 $schedule->command('forward_count')->monthlyOn(1,'01:00')->withoutOverlapping(1);//没月月初1号执行月统计转发询盘记录
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 3
4 namespace App\Helper; 4 namespace App\Helper;
5 5
  6 +use App\Models\Project\Project;
6 use App\Utils\HttpUtils; 7 use App\Utils\HttpUtils;
7 use GuzzleHttp\Exception\GuzzleException; 8 use GuzzleHttp\Exception\GuzzleException;
8 9
@@ -51,6 +52,8 @@ class FormGlobalsoApi @@ -51,6 +52,8 @@ class FormGlobalsoApi
51 */ 52 */
52 public function getInquiryList($domain, $search = '', $page = 1, $page_size = 20) 53 public function getInquiryList($domain, $search = '', $page = 1, $page_size = 20)
53 { 54 {
  55 + $project = Project::getProjectByDomain($domain);
  56 + $is_upgrade = $project['is_upgrade'] ??0;
54 $api_url = $this->url . '/api/external-interface/6a1bd159b1fd60af'; 57 $api_url = $this->url . '/api/external-interface/6a1bd159b1fd60af';
55 58
56 $params = [ 59 $params = [
@@ -58,7 +61,7 @@ class FormGlobalsoApi @@ -58,7 +61,7 @@ class FormGlobalsoApi
58 'domain' => $domain, 61 'domain' => $domain,
59 'limit' => $page_size, 62 'limit' => $page_size,
60 'page' => $page, 63 'page' => $page,
61 - 'source' => '1,3' //来源类型 新项目用1,3 64 + 'source' => $is_upgrade ? '1,2,3,4' : '1,3' //来源类型 新项目用1,3
62 ]; 65 ];
63 if($search){ 66 if($search){
64 $params['name'] = $search; 67 $params['name'] = $search;
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: zhl
  5 + * Date: 2024/1/6
  6 + * Time: 17:41
  7 + */
  8 +namespace App\Http\Controllers\Api;
  9 +
  10 +use App\Models\Domain\DomainInfo;
  11 +use App\Models\Product\Category;
  12 +use App\Models\Product\Product;
  13 +use App\Models\Project\OnlineCheck;
  14 +use App\Models\Project\Project;
  15 +use App\Models\RouteMap\RouteMap;
  16 +use App\Services\ProjectServer;
  17 +use Illuminate\Http\Request;
  18 +
  19 +/**
  20 + * Class PrivateController
  21 + * @package App\Http\Controllers\Api
  22 + */
  23 +class PrivateController extends BaseController
  24 +{
  25 + /**
  26 + * 优化中项目列表
  27 + * @param Request $request
  28 + * @return false|string
  29 + */
  30 + public function optimizeProjectList(Request $request)
  31 + {
  32 + $page_size = $request->input('page_size', 20);
  33 + $field = ['gl_project.id', 'gl_project.company', 'gl_project.is_upgrade', 'b.start_date', 'd.domain'];
  34 + $result = Project::select($field)->leftJoin('gl_project_deploy_optimize as b', 'gl_project.id', '=', 'b.project_id')
  35 + ->leftJoin('gl_project_online_check as c', 'gl_project.id', '=', 'c.project_id')
  36 + ->leftJoin('gl_domain_info as d', 'gl_project.id', '=', 'd.project_id')
  37 + ->where('c.qa_status', '=', OnlineCheck::STATUS_ONLINE_TRUE)
  38 + ->whereIn('gl_project.type', [Project::TYPE_TWO, Project::TYPE_FOUR])
  39 + ->paginate($page_size)
  40 + ->toArray();
  41 + return $this->success($result);
  42 + }
  43 +
  44 + /**
  45 + * 获取项目链接
  46 + * FIXME 当前直接获取的产品和产品分类, 后期需要封装到内部, 需要添加完整的链接规则
  47 + * @param Request $request
  48 + * @return false|string
  49 + */
  50 + public function getProjectRoute(Request $request)
  51 + {
  52 + $project_id = intval($request->input('project_id'));
  53 +// $type = $request->input('type');
  54 + $type = [RouteMap::SOURCE_PRODUCT, RouteMap::SOURCE_PRODUCT_CATE];
  55 +
  56 + $project = Project::where(['id' => $project_id])->first();
  57 + if (empty($project))
  58 + return $this->error('未发现需要查找的项目!');
  59 +
  60 + $project = ProjectServer::useProject($project_id);
  61 +
  62 + $domain = DomainInfo::where(['project_id' => $project_id])->first();
  63 + $host = FALSE == empty($domain) ? 'https://' . $domain->domain . '/' : $project->deploy_build->test_domain;
  64 +
  65 + // 需要标题, 不能直接查询map表
  66 +// $list = RouteMap::where(['project_id' => $project_id])
  67 +// ->when($type, function ($query) use ($type) {
  68 +// return $query->whereIn('source', $type);
  69 +// })
  70 +// ->get();
  71 +//
  72 +// $result = [];
  73 +// foreach ($list as $val) {
  74 +// // 排除首页
  75 +// if ($val->source == RouteMap::SOURCE_PAGE && in_array($val->route, ['index', '']))
  76 +// continue;
  77 +// $result[$val->source][] = $host . $val->route;
  78 +// }
  79 + $result = [];
  80 + $product = Product::where(['status' => Product::STATUS_ON])->get(['title', 'route'])->toArray();
  81 + foreach ($product as $val) {
  82 + $val['route'] = $host . $val['route'];
  83 + // FALSE == preg_match('/(\.html|\.htm)$/', $val['route'])
  84 + if (FALSE === strpos($val['route'], '.htm')) {
  85 + $val['route'] .= '/';
  86 + }
  87 + $result[RouteMap::SOURCE_PRODUCT][] = $val;
  88 + }
  89 + $product_category= Category::get(['title', 'route'])->toArray();
  90 + foreach ($product_category as $val) {
  91 + $val['route'] = $host . $val['route'];
  92 + if (FALSE === strpos($val['route'], '.htm')) {
  93 + $val['route'] .= '/';
  94 + }
  95 + $result[RouteMap::SOURCE_PRODUCT_CATE][] = $val;
  96 + }
  97 + return $this->success($result);
  98 + }
  99 +}
@@ -69,7 +69,7 @@ class OptimizeController extends BaseController @@ -69,7 +69,7 @@ class OptimizeController extends BaseController
69 if(!empty($list)){ 69 if(!empty($list)){
70 foreach ($list as $v) { 70 foreach ($list as $v) {
71 $last = Arr::last($v); 71 $last = Arr::last($v);
72 - if(isset($last['g']) && ($last['g'] == 1)){ 72 + if(isset($last['g']) && ($last['g'] == 1) && ($last['position'] <= 10) && ($last['position'] >= 1)){
73 $num = $num+1; 73 $num = $num+1;
74 } 74 }
75 } 75 }
@@ -63,6 +63,7 @@ class KeywordController extends BaseController @@ -63,6 +63,7 @@ class KeywordController extends BaseController
63 if(!empty($map['keyword_title'])){ 63 if(!empty($map['keyword_title'])){
64 $map['keyword_title'] = ['like','%'.$map['keyword_title'].'%']; 64 $map['keyword_title'] = ['like','%'.$map['keyword_title'].'%'];
65 } 65 }
  66 + $map['route'] = ['<>',''];
66 $map['project_id'] = $this->user['project_id']; 67 $map['project_id'] = $this->user['project_id'];
67 return $this->success($map); 68 return $this->success($map);
68 } 69 }
@@ -99,11 +100,11 @@ class KeywordController extends BaseController @@ -99,11 +100,11 @@ class KeywordController extends BaseController
99 } 100 }
100 101
101 /** 102 /**
102 - * @remark :批量添加  
103 - * @name :batchAdd  
104 - * @author :lyh  
105 - * @method :post  
106 - * @time :2023/8/28 14:25 103 + * 批量添加关键词
  104 + * FIXME 添加通知, 异步处理任务
  105 + * @param KeywordLogic $logic
  106 + * @throws \App\Exceptions\AsideGlobalException
  107 + * @throws \App\Exceptions\BsideGlobalException
107 */ 108 */
108 public function batchAdd(KeywordLogic $logic){ 109 public function batchAdd(KeywordLogic $logic){
109 $this->request->validate([ 110 $this->request->validate([
@@ -114,7 +115,7 @@ class KeywordController extends BaseController @@ -114,7 +115,7 @@ class KeywordController extends BaseController
114 'title.max' => '批量操作不能超过1000条数据' 115 'title.max' => '批量操作不能超过1000条数据'
115 ]); 116 ]);
116 $logic->batchAdd(); 117 $logic->batchAdd();
117 - $this->response('success'); 118 + $this->response('关键词后台异步添加中,请稍后刷新查看!');
118 } 119 }
119 120
120 /** 121 /**
@@ -297,7 +297,12 @@ class ProductController extends BaseController @@ -297,7 +297,12 @@ class ProductController extends BaseController
297 }elseif($v['type'] == 4){ 297 }elseif($v['type'] == 4){
298 $arr1 = json_decode($info['values']); 298 $arr1 = json_decode($info['values']);
299 foreach ($arr1 as $k1=>$v1){ 299 foreach ($arr1 as $k1=>$v1){
  300 + $v1 = (array)$v1;
  301 + if(isset($v1['url'])){
  302 + $v1['url'] = getFileUrl($v1['url']);
  303 + }else{
300 $v1 = getFileUrl($v1); 304 $v1 = getFileUrl($v1);
  305 + }
301 $arr1[$k1] = $v1; 306 $arr1[$k1] = $v1;
302 } 307 }
303 $v['values'] = $arr1; 308 $v['values'] = $arr1;
@@ -49,12 +49,15 @@ class CustomModuleLogic extends BaseLogic @@ -49,12 +49,15 @@ class CustomModuleLogic extends BaseLogic
49 * @time :2023/12/4 15:47 49 * @time :2023/12/4 15:47
50 */ 50 */
51 public function customModuleSave(){ 51 public function customModuleSave(){
  52 + ProjectServer::useProject($this->param['project_id']);
52 $this->param = $this->handleParam($this->param); 53 $this->param = $this->handleParam($this->param);
  54 + $this->checkIsName($this->param['name'],$this->param['id'] ?? 0);
53 if(isset($this->param['id']) && !empty($this->param['id'])){ 55 if(isset($this->param['id']) && !empty($this->param['id'])){
54 $this->moduleEdit(); 56 $this->moduleEdit();
55 }else{ 57 }else{
56 $this->moduleAdd(); 58 $this->moduleAdd();
57 } 59 }
  60 + DB::disconnect('custom_mysql');
58 return $this->success(); 61 return $this->success();
59 } 62 }
60 63
@@ -81,12 +84,10 @@ class CustomModuleLogic extends BaseLogic @@ -81,12 +84,10 @@ class CustomModuleLogic extends BaseLogic
81 * @time :2023/12/5 9:39 84 * @time :2023/12/5 9:39
82 */ 85 */
83 public function moduleAdd(){ 86 public function moduleAdd(){
84 - ProjectServer::useProject($this->param['project_id']);  
85 $rs = (new CustomModule())->add($this->param); 87 $rs = (new CustomModule())->add($this->param);
86 if($rs === false){ 88 if($rs === false){
87 $this->fail('系统错误,请联系管理员'); 89 $this->fail('系统错误,请联系管理员');
88 } 90 }
89 - DB::disconnect('custom_mysql');  
90 return $this->success(); 91 return $this->success();
91 } 92 }
92 93
@@ -98,16 +99,32 @@ class CustomModuleLogic extends BaseLogic @@ -98,16 +99,32 @@ class CustomModuleLogic extends BaseLogic
98 * @time :2023/12/5 9:39 99 * @time :2023/12/5 9:39
99 */ 100 */
100 public function moduleEdit(){ 101 public function moduleEdit(){
101 - ProjectServer::useProject($this->param['project_id']);  
102 $rs = (new CustomModule())->edit($this->param,['id'=>$this->param['id']]); 102 $rs = (new CustomModule())->edit($this->param,['id'=>$this->param['id']]);
103 if($rs === false){ 103 if($rs === false){
104 $this->fail('系统错误,请联系管理员'); 104 $this->fail('系统错误,请联系管理员');
105 } 105 }
106 - DB::disconnect('custom_mysql');  
107 return $this->success(); 106 return $this->success();
108 } 107 }
109 108
110 /** 109 /**
  110 + * @remark :验证名称是否存在
  111 + * @name :checkIsName
  112 + * @author :lyh
  113 + * @method :post
  114 + * @time :2024/1/6 14:06
  115 + */
  116 + public function checkIsName($name,$id = 0){
  117 + $param['name'] = $name;
  118 + if(!empty($id)){
  119 + $param['id'] = ['id'=>['!=',$id],];
  120 + }
  121 + $info = (new CustomModule())->read($param);
  122 + if($info !== false){
  123 + $this->fail('当前名称已存在');
  124 + }
  125 + return $this->success();
  126 + }
  127 + /**
111 * @remark :删除数据 128 * @remark :删除数据
112 * @name :ModuleDel 129 * @name :ModuleDel
113 * @author :lyh 130 * @author :lyh
@@ -30,7 +30,7 @@ class MonthCountLogic extends BaseLogic @@ -30,7 +30,7 @@ class MonthCountLogic extends BaseLogic
30 */ 30 */
31 public function getCountLists($map,$order = 'created_at',$filed = ['*']){ 31 public function getCountLists($map,$order = 'created_at',$filed = ['*']){
32 $map['project_id'] = $this->user['project_id']; 32 $map['project_id'] = $this->user['project_id'];
33 - $lists = $this->model->list($map,$order,$filed); 33 + $lists = $this->model->list($map,$order,$filed,'desc',10);
34 if(isset($this->project['is_record_china_visit']) && ($this->project['is_record_china_visit'] == 0)){ 34 if(isset($this->project['is_record_china_visit']) && ($this->project['is_record_china_visit'] == 0)){
35 foreach ($lists as $k => $v){ 35 foreach ($lists as $k => $v){
36 if(empty($v['source_country'])){ 36 if(empty($v['source_country'])){
@@ -7,6 +7,7 @@ use App\Helper\Arr; @@ -7,6 +7,7 @@ use App\Helper\Arr;
7 use App\Helper\Common; 7 use App\Helper\Common;
8 use App\Helper\Translate; 8 use App\Helper\Translate;
9 use App\Http\Logic\Bside\BaseLogic; 9 use App\Http\Logic\Bside\BaseLogic;
  10 +use App\Models\Com\NoticeLog;
10 use App\Models\News\News; 11 use App\Models\News\News;
11 use App\Models\Product\Keyword; 12 use App\Models\Product\Keyword;
12 use App\Models\Product\KeywordRelated; 13 use App\Models\Product\KeywordRelated;
@@ -129,17 +130,12 @@ class KeywordLogic extends BaseLogic @@ -129,17 +130,12 @@ class KeywordLogic extends BaseLogic
129 } 130 }
130 131
131 /** 132 /**
132 - * @remark :批量添加数据  
133 - * @name :batchAdd  
134 - * @author :lyh  
135 - * @method :post  
136 - * @time :2023/8/28 14:03 133 + * 批量添加关键词任务, 异步处理
  134 + * @return array
  135 + * @throws BsideGlobalException
  136 + * @throws \App\Exceptions\AsideGlobalException
137 */ 137 */
138 public function batchAdd(){ 138 public function batchAdd(){
139 - $route_array = Translate::tran($this->param['title'], 'en');  
140 - if (empty($route_array)) {  
141 - $this->fail('路由生成失败,请稍后重试!');  
142 - }  
143 try { 139 try {
144 foreach ($this->param['title'] as $k=>$v){ 140 foreach ($this->param['title'] as $k=>$v){
145 if(empty($v)){ 141 if(empty($v)){
@@ -152,19 +148,43 @@ class KeywordLogic extends BaseLogic @@ -152,19 +148,43 @@ class KeywordLogic extends BaseLogic
152 $param['created_at'] = date('Y-m-d H:i:s'); 148 $param['created_at'] = date('Y-m-d H:i:s');
153 $param['updated_at'] = $param['created_at']; 149 $param['updated_at'] = $param['created_at'];
154 $param['title'] = $v; 150 $param['title'] = $v;
155 - $id = $this->model->insertGetId($param);  
156 - $route = RouteMap::setRoute($route_array[$k], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);  
157 -// $this->curlDelRoute(['new_route'=>$route]);  
158 - $this->model->edit(['route'=>$route],['id'=>$id]); 151 + $this->model->insertGetId($param);
159 } 152 }
160 } 153 }
  154 + NoticeLog::createLog(NoticeLog::TYPE_INIT_KEYWORD, ['project_id' => $this->user['project_id']]);
161 }catch (\Exception $e){ 155 }catch (\Exception $e){
162 - $this->fail('error'); 156 + $this->fail('创建任务添加关键词任务失败,请稍后重试!');
163 } 157 }
164 return $this->success(); 158 return $this->success();
165 } 159 }
166 160
167 /** 161 /**
  162 + * @remark :
  163 + * @name :specialRouteCheck
  164 + * @author :lyh
  165 + * @method :post
  166 + * @time :2024/1/6 14:50
  167 + */
  168 + public function specialRouteCheck($title)
  169 + {
  170 + if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $title)){
  171 + $title = Translate::tran($title, 'en');
  172 + }
  173 + $suffix = '-tag';
  174 + $i = 1;
  175 + $sign = generateRoute($title);
  176 + $route = $sign . $suffix;
  177 + resetRoute:
  178 + $log = RouteMap::getRouteInfo($route, $this->user['project_id']);
  179 + if ($log) {
  180 + $route = $sign .'-'.$i.$suffix;
  181 + $i++;
  182 + goto resetRoute;
  183 + }
  184 + return $route;
  185 + }
  186 +
  187 + /**
168 * @remark :删除标签 188 * @remark :删除标签
169 * @name :keywordDelete 189 * @name :keywordDelete
170 * @author :lyh 190 * @author :lyh
@@ -175,7 +175,7 @@ class ProductLogic extends BaseLogic @@ -175,7 +175,7 @@ class ProductLogic extends BaseLogic
175 $v['values'] = json_encode($v['values']); 175 $v['values'] = json_encode($v['values']);
176 }elseif ($v['type'] == 4){ 176 }elseif ($v['type'] == 4){
177 foreach ($v['values'] as $k1=>$v1){ 177 foreach ($v['values'] as $k1=>$v1){
178 - $v1 = str_replace_url($v1); 178 + $v1['url'] = str_replace_url($v1['url']);
179 $v['values'][$k1] = $v1; 179 $v['values'][$k1] = $v1;
180 } 180 }
181 $v['values'] = json_encode($v['values']); 181 $v['values'] = json_encode($v['values']);
@@ -12,7 +12,7 @@ class NoticeLog extends Model @@ -12,7 +12,7 @@ class NoticeLog extends Model
12 const TYPE_PROJECT = 'project'; 12 const TYPE_PROJECT = 'project';
13 const TYPE_RANK_DATA = 'rank_data'; 13 const TYPE_RANK_DATA = 'rank_data';
14 const TYPE_INIT_PROJECT = 'init_project'; 14 const TYPE_INIT_PROJECT = 'init_project';
15 - 15 + const TYPE_INIT_KEYWORD = 'init_keyword';
16 const STATUS_PENDING = 0; 16 const STATUS_PENDING = 0;
17 const STATUS_SUCCESS = 1; 17 const STATUS_SUCCESS = 1;
18 const STATUS_FAIL = 2; 18 const STATUS_FAIL = 2;
@@ -9,4 +9,6 @@ class OnlineCheck extends Base @@ -9,4 +9,6 @@ class OnlineCheck extends Base
9 //设置关联表名 9 //设置关联表名
10 protected $table = 'gl_project_online_check'; 10 protected $table = 'gl_project_online_check';
11 11
  12 + const STATUS_ONLINE_FALSE = 0;
  13 + const STATUS_ONLINE_TRUE = 1;
12 } 14 }
@@ -22,8 +22,8 @@ class Project extends Base @@ -22,8 +22,8 @@ class Project extends Base
22 const STATUS_ONE = 1;//审核通过 22 const STATUS_ONE = 1;//审核通过
23 const TYPE_ZERO = 0;//初始导入项目 23 const TYPE_ZERO = 0;//初始导入项目
24 const TYPE_ONE = 1;//建站中 24 const TYPE_ONE = 1;//建站中
25 - const TYPE_TWO = 2;//建站完成  
26 - const TYPE_THREE = 3;//建站完成(推广) 25 + const TYPE_TWO = 2;//建站完成(推广)
  26 + const TYPE_THREE = 3;//建站完成
27 const TYPE_FOUR = 4;//推广续费 27 const TYPE_FOUR = 4;//推广续费
28 const TYPE_FIVE = 5;//未续费网站 28 const TYPE_FIVE = 5;//未续费网站
29 const TYPE_SIX = 6;//特殊推广项目 29 const TYPE_SIX = 6;//特殊推广项目
@@ -202,6 +202,16 @@ class Project extends Base @@ -202,6 +202,16 @@ class Project extends Base
202 return self::hasOne(After::class, 'project_id', 'id'); 202 return self::hasOne(After::class, 'project_id', 'id');
203 } 203 }
204 204
  205 + /**
  206 + * 域名
  207 + * @return \Illuminate\Database\Eloquent\Relations\HasOne
  208 + * @author zbj
  209 + */
  210 + public function domainInfo()
  211 + {
  212 + return self::hasOne(\App\Models\Domain\DomainInfo::class, 'project_id', 'project_id')->select('project_id', 'domain');;
  213 + }
  214 +
205 public function setLevelAttribute($value) 215 public function setLevelAttribute($value)
206 { 216 {
207 $this->attributes['level'] = Arr::arrToSet($value); 217 $this->attributes['level'] = Arr::arrToSet($value);
@@ -284,24 +294,15 @@ class Project extends Base @@ -284,24 +294,15 @@ class Project extends Base
284 */ 294 */
285 public static function getProjectByDomain($domain) 295 public static function getProjectByDomain($domain)
286 { 296 {
287 - $cache_key = 'project_' . $domain;  
288 - $data = Cache::get($cache_key);  
289 - if (!$data) { 297 + $domain = parse_url($domain);
  298 + $domain = $domain['host'] ?? $domain;
290 //是否测试域名 299 //是否测试域名
291 $project_id = DeployBuild::where('test_domain', $domain)->value('project_id'); 300 $project_id = DeployBuild::where('test_domain', $domain)->value('project_id');
292 //是否正式域名 301 //是否正式域名
293 if (!$project_id) { 302 if (!$project_id) {
294 - $project_id = DeployOptimize::where('domain', $domain)->value('project_id');  
295 - }  
296 - if (!$project_id) {  
297 - return [];  
298 - }  
299 - $data = self::find($project_id);  
300 - if ($data) {  
301 - Cache::put($cache_key, $data);  
302 - } 303 + $project_id = \App\Models\Domain\DomainInfo::where('domain', $domain)->value('project_id');
303 } 304 }
304 - return $data; 305 + return self::find($project_id ?: 0);
305 } 306 }
306 307
307 /** 308 /**
@@ -60,6 +60,12 @@ return [ @@ -60,6 +60,12 @@ return [
60 'via' => \App\Factory\LogFormatterFactory::class, 60 'via' => \App\Factory\LogFormatterFactory::class,
61 'prefix' => 'bside', 61 'prefix' => 'bside',
62 ], 62 ],
  63 + //自定义引流日志
  64 + 'traffic' => [
  65 + 'driver' => 'custom',
  66 + 'via' => \App\Factory\LogFormatterFactory::class,
  67 + 'prefix' => 'traffic',
  68 + ],
63 'wechatside' => [ 69 'wechatside' => [
64 'driver' => 'custom', 70 'driver' => 'custom',
65 'via' => \App\Factory\LogFormatterFactory::class, 71 'via' => \App\Factory\LogFormatterFactory::class,
@@ -19,3 +19,5 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { @@ -19,3 +19,5 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
19 }); 19 });
20 20
21 Route::any('traffic_visit', [\App\Http\Controllers\Api\NoticeController::class, 'trafficVisit'])->name('api.traffic_visit'); 21 Route::any('traffic_visit', [\App\Http\Controllers\Api\NoticeController::class, 'trafficVisit'])->name('api.traffic_visit');
  22 +Route::get('optimize_project_list', [\App\Http\Controllers\Api\PrivateController::class, 'optimizeProjectList'])->name('api.optimize_project_list');
  23 +Route::get('get_project_route', [\App\Http\Controllers\Api\PrivateController::class, 'getProjectRoute'])->name('api.get_project_route');