作者 张关杰

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into bate

@@ -33,8 +33,9 @@ class UpgradeProjectCount extends Command @@ -33,8 +33,9 @@ class UpgradeProjectCount extends Command
33 protected $description = '升级项目统计'; 33 protected $description = '升级项目统计';
34 34
35 public function handle(){ 35 public function handle(){
36 - ProjectServer::useProject(439);  
37 - $this->count(); 36 + $project_id = 555;
  37 + ProjectServer::useProject($project_id);
  38 + $this->count($project_id);
38 DB::disconnect('custom_mysql'); 39 DB::disconnect('custom_mysql');
39 } 40 }
40 41
@@ -45,18 +46,18 @@ class UpgradeProjectCount extends Command @@ -45,18 +46,18 @@ class UpgradeProjectCount extends Command
45 * @method :post 46 * @method :post
46 * @time :2024/1/8 9:05 47 * @time :2024/1/8 9:05
47 */ 48 */
48 - public function count(){ 49 + public function count($project_id){
49 $list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date') 50 $list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date')
50 ->groupBy('updated_date')->get()->toArray(); 51 ->groupBy('updated_date')->get()->toArray();
51 $project = new Project(); 52 $project = new Project();
52 - $projectInfo = $project->read(['id'=>439]); 53 + $projectInfo = $project->read(['id'=>$project_id]);
53 if(!empty($list)){ 54 if(!empty($list)){
54 $arr = []; 55 $arr = [];
55 foreach ($list as $k=>$v){ 56 foreach ($list as $k=>$v){
56 $v = (array)$v; 57 $v = (array)$v;
57 echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL; 58 echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL;
58 $count = new Count(); 59 $count = new Count();
59 - $arr['project_id'] = 439; 60 + $arr['project_id'] = $project_id;
60 $arr['date'] = $v['updated_date']; 61 $arr['date'] = $v['updated_date'];
61 $arr['pv_num'] = $this->pv_num($v['updated_date']); 62 $arr['pv_num'] = $this->pv_num($v['updated_date']);
62 $arr['ip_num'] = $this->ip_num($v['updated_date']); 63 $arr['ip_num'] = $this->ip_num($v['updated_date']);
@@ -65,9 +66,9 @@ class UpgradeProjectCount extends Command @@ -65,9 +66,9 @@ class UpgradeProjectCount extends Command
65 $arr['compliance_day'] = $projectInfo['finish_remain_day']; 66 $arr['compliance_day'] = $projectInfo['finish_remain_day'];
66 //剩余服务时常 67 //剩余服务时常
67 $arr['service_day'] = $projectInfo['remain_day']; 68 $arr['service_day'] = $projectInfo['remain_day'];
68 - $arr['country'] = '{"也门": 4, "印度": 3, "埃及": 4, "巴西": 1, "约旦": 2, "美国": 3, "伊拉克": 4, "利比亚": 2, "墨西哥": 5, "摩洛哥": 8, "新加坡": 1, "突尼斯": 3, "巴勒斯坦": 2, "巴基斯坦": 1, "罗马尼亚": 1, "非洲地区": 2, "马来西亚": 5, "印度尼西亚": 2, "沙特阿拉伯": 3, "阿尔及利亚": 2}'; 69 + $arr['country'] = json_encode([]);
69 //查询当天数据是否存在 存在则更新 70 //查询当天数据是否存在 存在则更新
70 - $info = $count->read(['date'=>$v['updated_date']]); 71 + $info = $count->read(['date'=>$v['updated_date'],'project_id'=>$project_id]);
71 if($info === false){ 72 if($info === false){
72 $arr['created_at'] = $v['updated_date'].' 01:00:00'; 73 $arr['created_at'] = $v['updated_date'].' 01:00:00';
73 $arr['updated_at'] = $v['updated_date'].' 01:00:00'; 74 $arr['updated_at'] = $v['updated_date'].' 01:00:00';
@@ -2,21 +2,17 @@ @@ -2,21 +2,17 @@
2 2
3 namespace App\Console\Commands; 3 namespace App\Console\Commands;
4 4
5 -use App\Http\Logic\Aside\Project\ProjectLogic;  
6 use App\Models\Com\NoticeLog; 5 use App\Models\Com\NoticeLog;
7 use App\Models\Product\Keyword; 6 use App\Models\Product\Keyword;
8 -use App\Models\Project\Project;  
9 use App\Models\RouteMap\RouteMap; 7 use App\Models\RouteMap\RouteMap;
10 use App\Services\ProjectServer; 8 use App\Services\ProjectServer;
11 use Illuminate\Console\Command; 9 use Illuminate\Console\Command;
12 use Illuminate\Support\Facades\DB; 10 use Illuminate\Support\Facades\DB;
  11 +use Illuminate\Support\Facades\Redis;
13 12
14 /** 13 /**
15 - * 初始化项目  
16 - * Class InitProject 14 + * Class InitKeyword
17 * @package App\Console\Commands 15 * @package App\Console\Commands
18 - * @author zbj  
19 - * @date 2023/10/8  
20 */ 16 */
21 class InitKeyword extends Command 17 class InitKeyword extends Command
22 { 18 {
@@ -50,29 +46,79 @@ class InitKeyword extends Command @@ -50,29 +46,79 @@ class InitKeyword extends Command
50 public function handle() 46 public function handle()
51 { 47 {
52 while (true){ 48 while (true){
53 - $list = NoticeLog::where('type', NoticeLog::TYPE_INIT_KEYWORD)->where('status', NoticeLog::STATUS_PENDING)->get();  
54 - if(!empty($list)){  
55 - foreach ($list as $item){  
56 - echo 'start:' . $item['data']['project_id'] . PHP_EOL;  
57 - ProjectServer::useProject($item['data']['project_id']);  
58 - $keywordModel = new Keyword();  
59 - $list = $keywordModel->list(['route'=>'']);  
60 - echo 'start:' . json_encode($list) . PHP_EOL;  
61 - foreach ($list as $v){  
62 - $route = RouteMap::setRoute($v['title'],RouteMap::SOURCE_PRODUCT_KEYWORD,$v['id'],$item['data']['project_id']);  
63 - if(empty($route)){  
64 - $keywordModel->del(['id'=>$v['id']]);  
65 - continue;  
66 - }  
67 - $keywordModel->edit(['route'=>$route],['id'=>$v['id']]);  
68 - }  
69 - $item->status = NoticeLog::STATUS_SUCCESS;  
70 - $item->save();  
71 - DB::disconnect('custom_mysql');  
72 - } 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());
73 } 60 }
74 sleep(2); 61 sleep(2);
75 } 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;
76 } 114 }
77 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 + }
78 } 124 }
@@ -35,8 +35,10 @@ class UpgradeProjectCount extends Command @@ -35,8 +35,10 @@ class UpgradeProjectCount extends Command
35 protected $description = '升级项目统计'; 35 protected $description = '升级项目统计';
36 36
37 public function handle(){ 37 public function handle(){
38 - ProjectServer::useProject(439);  
39 - $this->count(); 38 + $project_id = 555;
  39 + $url = 'www.sincoherenaesthetics.com';
  40 + ProjectServer::useProject($project_id);
  41 + $this->count($project_id,$url);
40 42
41 DB::disconnect('custom_mysql'); 43 DB::disconnect('custom_mysql');
42 } 44 }
@@ -48,35 +50,36 @@ class UpgradeProjectCount extends Command @@ -48,35 +50,36 @@ class UpgradeProjectCount extends Command
48 * @method :post 50 * @method :post
49 * @time :2024/1/8 9:05 51 * @time :2024/1/8 9:05
50 */ 52 */
51 - public function count(){ 53 + public function count($project_id,$url){
52 $list = DB::connection('custom_mysql')->table('gl_customer_visit') 54 $list = DB::connection('custom_mysql')->table('gl_customer_visit')
53 ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month')) 55 ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
54 ->groupBy('month')->get()->toArray(); 56 ->groupBy('month')->get()->toArray();
55 foreach ($list as $k=>$v){ 57 foreach ($list as $k=>$v){
56 $v = (array)$v; 58 $v = (array)$v;
57 $monthCountModel = new MonthCount(); 59 $monthCountModel = new MonthCount();
58 - $info = $monthCountModel->read(['month'=>$v['month']]); 60 + $info = $monthCountModel->read(['month'=>$v['month'],'project_id'=>$project_id]);
59 // 获取当月开始时间 61 // 获取当月开始时间
60 $start = date('Y-m-01', strtotime($v['month'])); 62 $start = date('Y-m-01', strtotime($v['month']));
61 // 获取当月结束时间 63 // 获取当月结束时间
62 $end = date('Y-m-t', strtotime($v['month'])); 64 $end = date('Y-m-t', strtotime($v['month']));
63 - $arr['project_id'] = 439;  
64 - $res = $this->inquiry('www.cnzyl.com',$v['month']); 65 + $arr['project_id'] = $project_id;
  66 + $res = $this->inquiry($url,$v['month']);
65 $arr['month_total'] = 0; 67 $arr['month_total'] = 0;
66 if(isset($res['data']['count'])){ 68 if(isset($res['data']['count'])){
67 $arr['month_total'] = $res['data']['count']; 69 $arr['month_total'] = $res['data']['count'];
68 } 70 }
69 if(isset($res['data']['data'])){ 71 if(isset($res['data']['data'])){
70 - $arr['country'] = $res['data']['data']; 72 + $arr['country'] = json_encode($res['data']['data']);
71 } 73 }
72 $arr['month'] = $v['month']; 74 $arr['month'] = $v['month'];
73 - $arr = $this->pv_ip($arr,$start,$end); 75 + $arr = $this->pv_ip($arr,$start,$end,$project_id);
74 $arr = $this->sourceCount($arr,$start,$end); 76 $arr = $this->sourceCount($arr,$start,$end);
75 if($info === false){ 77 if($info === false){
76 $selectedDate = $start; 78 $selectedDate = $start;
77 $firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month")); 79 $firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
78 $arr['created_at'] = $firstDayOfNextMonth; 80 $arr['created_at'] = $firstDayOfNextMonth;
79 $arr['updated_at'] = $firstDayOfNextMonth; 81 $arr['updated_at'] = $firstDayOfNextMonth;
  82 +// echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL;
80 $monthCountModel->insert($arr); 83 $monthCountModel->insert($arr);
81 }else{ 84 }else{
82 $monthCountModel->edit($arr,['id'=>$info['id']]); 85 $monthCountModel->edit($arr,['id'=>$info['id']]);
@@ -92,9 +95,9 @@ class UpgradeProjectCount extends Command @@ -92,9 +95,9 @@ class UpgradeProjectCount extends Command
92 * @method :post 95 * @method :post
93 * @time :2024/1/8 11:02 96 * @time :2024/1/8 11:02
94 */ 97 */
95 - public function pv_ip(&$arr,$start,$end){ 98 + public function pv_ip(&$arr,$start,$end,$project_id){
96 $pv_ip = DB::table('gl_count') 99 $pv_ip = DB::table('gl_count')
97 - ->where(['project_id'=>439]) 100 + ->where(['project_id'=>$project_id])
98 ->where('date','>=',$start.' 00:00:00') 101 ->where('date','>=',$start.' 00:00:00')
99 ->where('date','<=',$end.' 23:59:59') 102 ->where('date','<=',$end.' 23:59:59')
100 ->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')) 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'))
@@ -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,60 +146,71 @@ class WebTraffic extends Command @@ -143,60 +146,71 @@ class WebTraffic extends Command
143 */ 146 */
144 public function handle() 147 public function handle()
145 { 148 {
146 - $type = $this->argument('type'); 149 + try {
  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 - $need_project = [];  
155 - foreach ($chunk as $project) {  
156 - //随机引流间隔  
157 - $res_sjjg = $this->get_rand($this->sjjg);  
158 - if ($res_sjjg == 1) {  
159 - continue; 154 + $page = 1;
  155 + while (true){
  156 + $project_list = $this->getProjectList($type, $page);
  157 + if(!$project_list){
  158 + break;
160 } 159 }
  160 + $need_project = [];
  161 + foreach ($project_list as $project) {
  162 + //随机引流间隔
  163 + $res_sjjg = $this->get_rand($this->sjjg);
  164 + if ($res_sjjg == 1) {
  165 + continue;
  166 + }
161 167
162 - $project_urls = $this->getProductUrls($project['project_id']);  
163 - $project_urls['home'] = $project['domain'];  
164 - //随机访问页面  
165 - $project['visit_urls'] = $this->getVisitUrls($project_urls);  
166 - //随机客户端  
167 - $project['device_port'] = $this->get_rand($this->yddzb);  
168 - $project['user_agent'] = $project['device_port'] == 1 ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua); 168 + $project_urls = $this->getProductUrls($project['project_id']);
  169 + $project_urls['home'] = $project['domain'];
  170 + //随机访问页面
  171 + $project['visit_urls'] = $this->getVisitUrls($project_urls);
  172 + //随机客户端
  173 + $project['device_port'] = $this->get_rand($this->yddzb);
  174 + $project['user_agent'] = $project['device_port'] == 1 ? Arr::random($this->pc_ua) : Arr::random($this->mobile_ua);
169 175
170 - $need_project[] = $project;  
171 - }  
172 -  
173 - //随机访问ip  
174 - $ips = $this->getIpAreas(count($need_project));  
175 - //最多10层深度  
176 - $client = new Client(['verify' => false]);  
177 - for ($j = 0; $j < 10; $j++) { 176 + $need_project[] = $project;
  177 + }
  178 + //随机访问ip
  179 + $ips = $this->getIpAreas(count($need_project));
  180 + //最多10层深度
  181 + $client = new Client(['verify' => false]);
178 for ($j = 0; $j < 10; $j++) { 182 for ($j = 0; $j < 10; $j++) {
179 - //并发请求  
180 - $promises = [];  
181 - foreach ($need_project as $project_key => $project) {  
182 - if (empty($project['visit_urls'][$j])) {  
183 - continue; 183 + for ($j = 0; $j < 10; $j++) {
  184 + //并发请求
  185 + $promises = [];
  186 + foreach ($need_project as $project_key => $project) {
  187 + if (empty($project['visit_urls'][$j])) {
  188 + continue;
  189 + }
  190 +
  191 + $data = [
  192 + 'ip' => $ips[$project_key]['ip'],
  193 + 'referrer_url' => $this->getReferer($ips[$project_key]['ip_area']),
  194 + 'url' => $project['visit_urls'][$j],
  195 + 'device_port' => $project['device_port'],
  196 + 'domain' => $project['domain'],
  197 + ];
  198 + Log::channel('traffic')->info('traffic project_id:' . $project['project_id'], $data);
  199 + $promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]);
184 } 200 }
185 201
186 - $data = [  
187 - 'ip' => $ips[$project_key]['ip'],  
188 - 'referer' => $this->getReferer($ips[$project_key]['ip_area']),  
189 - 'url' => $project['visit_urls'][$j],  
190 - 'device_port' => $this->get_rand($this->yddzb)  
191 - ];  
192 - $promises[] = $client->postAsync($project['domain'] . 'api/customerVisit', ['form_params' => $data]); 202 + if($promises){
  203 + Utils::settle($promises)->wait();
  204 + //每个深度随机等待
  205 + sleep(rand(2, 10));
  206 + }
193 } 207 }
194 - Utils::settle($promises)->wait();  
195 -  
196 - //每个深度随机等待  
197 - sleep(rand(2, 10));  
198 } 208 }
  209 +
  210 + $page++;
199 } 211 }
  212 + }catch (\Exception $e){
  213 + Log::channel('traffic')->error($e->getMessage());
200 } 214 }
201 } 215 }
202 216
@@ -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 - ]  
226 - ]; 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'] . '/',
  270 + ];
  271 + }
  272 +
  273 + return $data;
227 } 274 }
228 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号执行月统计转发询盘记录
@@ -7,8 +7,13 @@ @@ -7,8 +7,13 @@
7 */ 7 */
8 namespace App\Http\Controllers\Api; 8 namespace App\Http\Controllers\Api;
9 9
  10 +use App\Models\Domain\DomainInfo;
  11 +use App\Models\Product\Category;
  12 +use App\Models\Product\Product;
10 use App\Models\Project\OnlineCheck; 13 use App\Models\Project\OnlineCheck;
11 use App\Models\Project\Project; 14 use App\Models\Project\Project;
  15 +use App\Models\RouteMap\RouteMap;
  16 +use App\Services\ProjectServer;
12 use Illuminate\Http\Request; 17 use Illuminate\Http\Request;
13 18
14 /** 19 /**
@@ -35,4 +40,60 @@ class PrivateController extends BaseController @@ -35,4 +40,60 @@ class PrivateController extends BaseController
35 ->toArray(); 40 ->toArray();
36 return $this->success($result); 41 return $this->success($result);
37 } 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 + }
38 } 99 }
@@ -100,11 +100,11 @@ class KeywordController extends BaseController @@ -100,11 +100,11 @@ class KeywordController extends BaseController
100 } 100 }
101 101
102 /** 102 /**
103 - * @remark :批量添加  
104 - * @name :batchAdd  
105 - * @author :lyh  
106 - * @method :post  
107 - * @time :2023/8/28 14:25 103 + * 批量添加关键词
  104 + * FIXME 添加通知, 异步处理任务
  105 + * @param KeywordLogic $logic
  106 + * @throws \App\Exceptions\AsideGlobalException
  107 + * @throws \App\Exceptions\BsideGlobalException
108 */ 108 */
109 public function batchAdd(KeywordLogic $logic){ 109 public function batchAdd(KeywordLogic $logic){
110 $this->request->validate([ 110 $this->request->validate([
@@ -115,7 +115,7 @@ class KeywordController extends BaseController @@ -115,7 +115,7 @@ class KeywordController extends BaseController
115 'title.max' => '批量操作不能超过1000条数据' 115 'title.max' => '批量操作不能超过1000条数据'
116 ]); 116 ]);
117 $logic->batchAdd(); 117 $logic->batchAdd();
118 - $this->response('路由生成中,请稍后刷新查看'); 118 + $this->response('关键词后台异步添加中,请稍后刷新查看!');
119 } 119 }
120 120
121 /** 121 /**
@@ -130,11 +130,10 @@ class KeywordLogic extends BaseLogic @@ -130,11 +130,10 @@ class KeywordLogic extends BaseLogic
130 } 130 }
131 131
132 /** 132 /**
133 - * @remark :批量添加数据  
134 - * @name :batchAdd  
135 - * @author :lyh  
136 - * @method :post  
137 - * @time :2023/8/28 14:03 133 + * 批量添加关键词任务, 异步处理
  134 + * @return array
  135 + * @throws BsideGlobalException
  136 + * @throws \App\Exceptions\AsideGlobalException
138 */ 137 */
139 public function batchAdd(){ 138 public function batchAdd(){
140 try { 139 try {
@@ -154,7 +153,7 @@ class KeywordLogic extends BaseLogic @@ -154,7 +153,7 @@ class KeywordLogic extends BaseLogic
154 } 153 }
155 NoticeLog::createLog(NoticeLog::TYPE_INIT_KEYWORD, ['project_id' => $this->user['project_id']]); 154 NoticeLog::createLog(NoticeLog::TYPE_INIT_KEYWORD, ['project_id' => $this->user['project_id']]);
156 }catch (\Exception $e){ 155 }catch (\Exception $e){
157 - $this->fail('error'); 156 + $this->fail('创建任务添加关键词任务失败,请稍后重试!');
158 } 157 }
159 return $this->success(); 158 return $this->success();
160 } 159 }
@@ -275,6 +275,15 @@ class ProductLogic extends BaseLogic @@ -275,6 +275,15 @@ class ProductLogic extends BaseLogic
275 $param['gallery'] = Arr::a2s([]); 275 $param['gallery'] = Arr::a2s([]);
276 $param['thumb'] = Arr::a2s([]); 276 $param['thumb'] = Arr::a2s([]);
277 } 277 }
  278 + if(isset($param['video']) && !empty($param['video'])){
  279 + foreach ($param['video'] as $k => $v){
  280 + $v = str_replace_url($v);
  281 + $param['video'][$k] = $v;
  282 + }
  283 + $param['video'] = Arr::a2s($param['video'] ?? []);
  284 + }else{
  285 + $param['video'] = Arr::a2s([]);
  286 + }
278 $param['attrs'] = Arr::a2s($param['attrs'] ?? []); 287 $param['attrs'] = Arr::a2s($param['attrs'] ?? []);
279 $param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? ''); 288 $param['attr_id'] = Arr::arrToSet($param['attr_id'] ?? '');
280 if(isset($param['keyword_id']) && !empty($param['keyword_id'])){ 289 if(isset($param['keyword_id']) && !empty($param['keyword_id'])){
@@ -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);
@@ -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,4 +19,5 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) { @@ -19,4 +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');  
  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');