作者 赵彬吉
@@ -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';
@@ -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'))
@@ -153,9 +153,12 @@ class HtmlCollect extends Command @@ -153,9 +153,12 @@ class HtmlCollect extends Command
153 case 'blog': 153 case 'blog':
154 $source = RouteMap::SOURCE_BLOG; 154 $source = RouteMap::SOURCE_BLOG;
155 break; 155 break;
156 - default: 156 + case 'post':
157 $source = RouteMap::SOURCE_PRODUCT; 157 $source = RouteMap::SOURCE_PRODUCT;
158 break; 158 break;
  159 + default:
  160 + $source = RouteMap::SOURCE_MODULE;
  161 + break;
159 } 162 }
160 163
161 $complete = false; 164 $complete = false;
@@ -155,9 +155,12 @@ class HtmlLanguageCollect extends Command @@ -155,9 +155,12 @@ class HtmlLanguageCollect extends Command
155 case 'blog': 155 case 'blog':
156 $source = RouteMap::SOURCE_BLOG; 156 $source = RouteMap::SOURCE_BLOG;
157 break; 157 break;
158 - default: 158 + case 'post':
159 $source = RouteMap::SOURCE_PRODUCT; 159 $source = RouteMap::SOURCE_PRODUCT;
160 break; 160 break;
  161 + default:
  162 + $source = RouteMap::SOURCE_MODULE;
  163 + break;
161 } 164 }
162 165
163 $complete = false; 166 $complete = false;
@@ -10,6 +10,9 @@ use App\Models\Collect\CollectSource; @@ -10,6 +10,9 @@ use App\Models\Collect\CollectSource;
10 use App\Models\Collect\CollectTask; 10 use App\Models\Collect\CollectTask;
11 use App\Models\Com\UpdateLog; 11 use App\Models\Com\UpdateLog;
12 use App\Models\Com\UpdateOldInfo; 12 use App\Models\Com\UpdateOldInfo;
  13 +use App\Models\CustomModule\CustomModule;
  14 +use App\Models\CustomModule\CustomModuleCategory;
  15 +use App\Models\CustomModule\CustomModuleContent;
13 use App\Models\News\News; 16 use App\Models\News\News;
14 use App\Models\News\NewsCategory; 17 use App\Models\News\NewsCategory;
15 use App\Models\Product\Category; 18 use App\Models\Product\Category;
@@ -187,6 +190,7 @@ class ProjectUpdate extends Command @@ -187,6 +190,7 @@ class ProjectUpdate extends Command
187 if (isset($data['code']) && $data['code'] == 200) { 190 if (isset($data['code']) && $data['code'] == 200) {
188 $phones = $data['data']['phones'] ?? ''; 191 $phones = $data['data']['phones'] ?? '';
189 $emails = $data['data']['emails'] ?? ''; 192 $emails = $data['data']['emails'] ?? '';
  193 + $custom_types = $data['data']['customposttypes'] ?? '';
190 194
191 $model = new WebSettingReceiving(); 195 $model = new WebSettingReceiving();
192 if ($phones) { 196 if ($phones) {
@@ -229,6 +233,25 @@ class ProjectUpdate extends Command @@ -229,6 +233,25 @@ class ProjectUpdate extends Command
229 } 233 }
230 } 234 }
231 } 235 }
  236 + if ($custom_types) {
  237 + $custom_model = new CustomModule();
  238 + foreach ($custom_types as $v_custom) {
  239 + try {
  240 + $custom_info = $custom_model->read(['route' => $v_custom]);
  241 + if (!$custom_info) {
  242 + $custom_model->add([
  243 + 'name' => $v_custom,
  244 + 'project_id' => $project_id,
  245 + 'route' => $v_custom
  246 + ]);
  247 + }
  248 + UpdateLog::createLog($project_id, $v_custom, $task->api_url);
  249 + } catch (\Exception $e) {
  250 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  251 + continue;
  252 + }
  253 + }
  254 + }
232 } else { 255 } else {
233 return true; 256 return true;
234 } 257 }
@@ -392,7 +415,7 @@ class ProjectUpdate extends Command @@ -392,7 +415,7 @@ class ProjectUpdate extends Command
392 $category_id = $logic->getCategory(array_column($category_arr, 'id')); 415 $category_id = $logic->getCategory(array_column($category_arr, 'id'));
393 } 416 }
394 //图片 417 //图片
395 - if (is_array($item['images'])) { 418 + if (is_array($item['images'] ?? '')) {
396 $image = $item['images'][0] ?? ''; 419 $image = $item['images'][0] ?? '';
397 } else { 420 } else {
398 $image = $item['images'] ?? ''; 421 $image = $item['images'] ?? '';
@@ -448,7 +471,7 @@ class ProjectUpdate extends Command @@ -448,7 +471,7 @@ class ProjectUpdate extends Command
448 } else { 471 } else {
449 return true; 472 return true;
450 } 473 }
451 - } else { 474 + } elseif ($api_type == 'page') {
452 //单页 475 //单页
453 $url = $api_url . '?' . http_build_query(['w' => 'page', 'page' => 1, 'pagesize' => 0]); 476 $url = $api_url . '?' . http_build_query(['w' => 'page', 'page' => 1, 'pagesize' => 0]);
454 $data = curl_c($url); 477 $data = curl_c($url);
@@ -510,6 +533,79 @@ class ProjectUpdate extends Command @@ -510,6 +533,79 @@ class ProjectUpdate extends Command
510 } else { 533 } else {
511 return true; 534 return true;
512 } 535 }
  536 + } else {
  537 + //自定义模块
  538 + $custom_model = new CustomModule();
  539 + $custom_info = $custom_model->read(['route' => $api_type]);
  540 + if ($custom_info) {
  541 + $url = $api_url . '?' . http_build_query(['w' => $api_type, 'page' => 1, 'pagesize' => 0]);
  542 + $data = curl_c($url);
  543 + if (isset($data['code']) && $data['code'] == 200) {
  544 + $category = $data['data']['category'] ?? [];
  545 + $this->category_custom_insert($project_id, $custom_info['id'], $category, 0);
  546 +
  547 + $count = $data['data']['count'] ?? 0;
  548 +
  549 + $total_page = ceil($count / $page_size);
  550 + for ($page = 1; $page <= $total_page; $page++) {
  551 + $url_page = $api_url . '?' . http_build_query(['w' => $api_type, 'page' => $page, 'pagesize' => $page_size]);
  552 + $data_page = curl_c($url_page);
  553 + if (isset($data_page['code']) && $data_page['code'] == 200) {
  554 + $items = $data_page['data']['data'] ?? [];
  555 +
  556 + $model = new CustomModuleContent();
  557 + $category_model = new CustomModuleCategory();
  558 +
  559 + foreach ($items as $item) {
  560 + $route = $this->get_url_route($item['url'] ?? '');
  561 + if ($route) {
  562 + //分类
  563 + $category_id = '';
  564 + if ($item['category'] ?? []) {
  565 + $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
  566 + $category_id = implode(',', array_column($category_arr, 'id'));
  567 + }
  568 + //名称去掉特殊符号
  569 + $item['title'] = $this->special2str($item['title'] ?? '');
  570 +
  571 + try {
  572 + $custom_content = $model->read(['route' => $route], 'id');
  573 + if (!$custom_content) {
  574 + $id = $model->insertGetId([
  575 + 'project_id' => $project_id,
  576 + 'name' => $item['title'],
  577 + 'module_id' => $custom_info['id'],
  578 + 'category_id' => $category_id,
  579 + 'content' => $item['content'] ?? '',
  580 + 'created_at' => $item['post_time'] ?? date('Y-m-d H:i:s'),
  581 + 'updated_at' => $item['post_time'] ?? date('Y-m-d H:i:s'),
  582 + 'is_upgrade' => 1,
  583 + 'six_read' => 1,
  584 + 'route' => $route
  585 + ]);
  586 + $this->set_map($route, RouteMap::SOURCE_MODULE, $id, $project_id);
  587 +
  588 + CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_MODULE, $id, $domain_arr['host'], $link_type, $language_list, $page_list);
  589 + } else {
  590 + $id = $custom_content['id'];
  591 + $model->edit([
  592 + 'name' => $item['title'],
  593 + 'category_id' => $category_id,
  594 + 'content' => $item['content'] ?? '',
  595 + ], ['id' => $id]);
  596 + }
  597 + } catch (\Exception $e) {
  598 + echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
  599 + continue;
  600 + }
  601 + }
  602 + }
  603 + }
  604 + }
  605 + } else {
  606 + return true;
  607 + }
  608 + }
513 } 609 }
514 } 610 }
515 //关闭数据库 611 //关闭数据库
@@ -595,7 +691,7 @@ class ProjectUpdate extends Command @@ -595,7 +691,7 @@ class ProjectUpdate extends Command
595 $parent_id = $parent['id']; 691 $parent_id = $parent['id'];
596 } 692 }
597 693
598 - if (!empty($item['children'])) { 694 + if (!empty($item['children'] ?? [])) {
599 $this->category_insert($project_id, $item['children'], $parent_id); 695 $this->category_insert($project_id, $item['children'], $parent_id);
600 } 696 }
601 } 697 }
@@ -629,13 +725,48 @@ class ProjectUpdate extends Command @@ -629,13 +725,48 @@ class ProjectUpdate extends Command
629 $parent_id = $parent['id']; 725 $parent_id = $parent['id'];
630 } 726 }
631 727
632 - if (!empty($item['children'])) { 728 + if (!empty($item['children'] ?? [])) {
633 $this->category_news_insert($project_id, $item['children'], $parent_id); 729 $this->category_news_insert($project_id, $item['children'], $parent_id);
634 } 730 }
635 } 731 }
636 } 732 }
637 } 733 }
638 734
  735 + //扩展模块多级分类入库
  736 + protected function category_custom_insert($project_id, $module_id, $items, $pid = 0)
  737 + {
  738 + $model = new CustomModuleCategory();
  739 + foreach ($items as $item) {
  740 + $route = $this->get_url_route($item['url'] ?? '');
  741 + if ($route) {
  742 + $parent = $model->read(['pid' => $pid, 'route' => $route], 'id');
  743 + if (!$parent) {
  744 + try {
  745 + $item['name'] = $this->special2str($item['name'] ?? '');
  746 + $parent_id = $model->addReturnId([
  747 + 'project_id' => $project_id,
  748 + 'module_id' => $module_id,
  749 + 'name' => $item['name'],
  750 + 'pid' => $pid,
  751 + 'original_id' => $item['id'],
  752 + 'route' => $route
  753 + ]);
  754 + $this->set_map($route, RouteMap::SOURCE_MODULE_CATE, $parent_id, $project_id);
  755 + } catch (\Exception $e) {
  756 + echo 'date:' . date('Y-m-d H:i:s') . ', category_custom_insert error: ' . $e->getMessage() . PHP_EOL;
  757 + continue;
  758 + }
  759 + } else {
  760 + $parent_id = $parent['id'];
  761 + }
  762 +
  763 + if (!empty($item['children'] ?? [])) {
  764 + $this->category_custom_insert($project_id, $module_id, $item['children'], $parent_id);
  765 + }
  766 + }
  767 + }
  768 + }
  769 +
639 //特殊字符转换 770 //特殊字符转换
640 protected function special2str($str) 771 protected function special2str($str)
641 { 772 {