作者 赵彬吉
@@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
9 9
10 namespace App\Console\Commands\DayCount; 10 namespace App\Console\Commands\DayCount;
11 11
  12 +use App\Models\Project\Project;
12 use App\Models\Visit\Visit; 13 use App\Models\Visit\Visit;
13 use App\Services\ProjectServer; 14 use App\Services\ProjectServer;
14 use Illuminate\Console\Command; 15 use Illuminate\Console\Command;
@@ -47,6 +48,8 @@ class UpgradeProjectCount extends Command @@ -47,6 +48,8 @@ class UpgradeProjectCount extends Command
47 public function count(){ 48 public function count(){
48 $list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date') 49 $list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date')
49 ->groupBy('updated_date')->get()->toArray(); 50 ->groupBy('updated_date')->get()->toArray();
  51 + $project = new Project();
  52 + $projectInfo = $project->read(['id'=>439]);
50 if(!empty($list)){ 53 if(!empty($list)){
51 $arr = []; 54 $arr = [];
52 foreach ($list as $k=>$v){ 55 foreach ($list as $k=>$v){
@@ -58,8 +61,20 @@ class UpgradeProjectCount extends Command @@ -58,8 +61,20 @@ class UpgradeProjectCount extends Command
58 $arr['pv_num'] = $this->pv_num($v['updated_date']); 61 $arr['pv_num'] = $this->pv_num($v['updated_date']);
59 $arr['ip_num'] = $this->ip_num($v['updated_date']); 62 $arr['ip_num'] = $this->ip_num($v['updated_date']);
60 $arr['inquiry_num'] = $this->inquiry_num($v['updated_date']); 63 $arr['inquiry_num'] = $this->inquiry_num($v['updated_date']);
  64 + //服务达标天数
  65 + $arr['compliance_day'] = $projectInfo['finish_remain_day'];
  66 + //剩余服务时常
  67 + $arr['service_day'] = $projectInfo['remain_day'];
61 $arr['country'] = '{"也门": 4, "印度": 3, "埃及": 4, "巴西": 1, "约旦": 2, "美国": 3, "伊拉克": 4, "利比亚": 2, "墨西哥": 5, "摩洛哥": 8, "新加坡": 1, "突尼斯": 3, "巴勒斯坦": 2, "巴基斯坦": 1, "罗马尼亚": 1, "非洲地区": 2, "马来西亚": 5, "印度尼西亚": 2, "沙特阿拉伯": 3, "阿尔及利亚": 2}'; 68 $arr['country'] = '{"也门": 4, "印度": 3, "埃及": 4, "巴西": 1, "约旦": 2, "美国": 3, "伊拉克": 4, "利比亚": 2, "墨西哥": 5, "摩洛哥": 8, "新加坡": 1, "突尼斯": 3, "巴勒斯坦": 2, "巴基斯坦": 1, "罗马尼亚": 1, "非洲地区": 2, "马来西亚": 5, "印度尼西亚": 2, "沙特阿拉伯": 3, "阿尔及利亚": 2}';
62 - echo date('Y-m-d H:i:s') . '数据:'.json_encode($arr) . PHP_EOL; 69 + //查询当天数据是否存在 存在则更新
  70 + $info = $count->read(['date'=>$v['updated_date']]);
  71 + if($info === false){
  72 + $arr['created_at'] = $v['updated_date'].' 01:00:00';
  73 + $arr['updated_at'] = $v['updated_date'].' 01:00:00';
  74 + $count->insert($arr);
  75 + }else{
  76 + $count->edit($arr,['id'=>$info['id']]);
  77 + }
63 } 78 }
64 } 79 }
65 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL; 80 echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
@@ -98,4 +113,7 @@ class UpgradeProjectCount extends Command @@ -98,4 +113,7 @@ class UpgradeProjectCount extends Command
98 $ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->count(); 113 $ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->count();
99 return $ip; 114 return $ip;
100 } 115 }
  116 +
  117 +
  118 +
101 } 119 }
  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 + ProjectServer::useProject(439);
  39 + $this->count();
  40 + DB::disconnect('custom_mysql');
  41 + }
  42 +
  43 + /**
  44 + * @remark :日统计记录
  45 + * @name :count
  46 + * @author :lyh
  47 + * @method :post
  48 + * @time :2024/1/8 9:05
  49 + */
  50 + public function count(){
  51 + $list = DB::connection('custom_mysql')->table('gl_customer_visit')
  52 + ->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
  53 + ->groupBy('month')->get()->toArray();
  54 + foreach ($list as $k=>$v){
  55 + $v = (array)$v;
  56 + $monthCountModel = new MonthCount();
  57 + $info = $monthCountModel->read(['month'=>$v['month']]);
  58 + // 获取当月开始时间
  59 + $start = date('Y-m-01', strtotime($v['month']));
  60 + // 获取当月结束时间
  61 + $end = date('Y-m-t', strtotime($v['month']));
  62 + $arr['project_id'] = 439;
  63 + $inquiry_list = (new FormGlobalsoApi())->getInquiryList('www.cnzyl.com','',1,100000000);
  64 + //总数
  65 + $arr['total'] = $inquiry_list['data']['total'] ?? 0;
  66 + $arr['month'] = $v['month'];
  67 + $arr['country'] = '{"\u5c3c\u65e5\u5229\u4e9a":1,"\u5370\u5ea6\u5c3c\u897f\u4e9a":1,"\u4f0a\u6717":1}';
  68 + $arr = $this->pv_ip($arr,$start,$end);
  69 + $arr = $this->sourceCount($arr,$start,$end);
  70 + if($info === false){
  71 + $selectedDate = $start;
  72 + $firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
  73 + $arr['created_at'] = $firstDayOfNextMonth;
  74 + $arr['updated_at'] = $firstDayOfNextMonth;
  75 + $monthCountModel->insert($arr);
  76 + }else{
  77 + $monthCountModel->edit($arr,['id'=>$info['id']]);
  78 + }
  79 + }
  80 + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
  81 + }
  82 +
  83 + /**
  84 + * @remark :本月询盘总量
  85 + * @name :month_total
  86 + * @author :lyh
  87 + * @method :post
  88 + * @time :2024/1/8 11:02
  89 + */
  90 + public function pv_ip(&$arr,$start,$end){
  91 + $pv_ip = DB::table('gl_count')
  92 + ->where(['project_id'=>439])
  93 + ->where('date','>=',$start.' 00:00:00')
  94 + ->where('date','<=',$end.' 23:59:59')
  95 + ->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'))
  96 + ->first();
  97 + $arr['pv'] = $pv_ip->pv_num;
  98 + $arr['ip'] = $pv_ip->ip_num;
  99 + $arr['month_total'] = $pv_ip->inquiry_num;
  100 + if($arr['ip'] != 0){
  101 + $arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
  102 + }
  103 + return $arr;
  104 + }
  105 + /**
  106 + * @remark :来源访问前8
  107 + * @name :sourceCount
  108 + * @author :lyh
  109 + * @method :post
  110 + * @time :2023/6/30 16:14
  111 + */
  112 + public function sourceCount(&$arr,$startTime,$endTime){
  113 + //访问来源前10
  114 + $source = DB::connection('custom_mysql')->table('gl_customer_visit')
  115 + ->select('referrer_url', DB::raw('COUNT(*) as count'))
  116 + ->groupBy('referrer_url')
  117 + ->whereBetween('updated_date', [$startTime,$endTime])
  118 + ->orderByDesc('count')->limit(10)->get()->toArray();
  119 + $arr['source'] = json_encode($source);
  120 + //访问国家前15
  121 + $source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
  122 + ->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
  123 + ->groupBy('country')
  124 + ->whereBetween('updated_date', [$startTime,$endTime])
  125 + ->orderBy('ip','desc')->limit(15)->get()->toArray();
  126 + $arr['source_country'] = json_encode($source_country);
  127 + //受访界面前15
  128 + $referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
  129 + ->select('url',DB::raw('COUNT(*) as num'))
  130 + ->orderBy('num','desc')
  131 + ->whereBetween('updated_date', [$startTime,$endTime])
  132 + ->groupBy('url')
  133 + ->limit(15)->get()->toArray();
  134 + $arr['referrer_url'] = json_encode($referrer_url);
  135 + //访问端口
  136 + $referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
  137 + ->select('device_port',DB::raw('COUNT(*) as num'))
  138 + ->orderBy('num','desc')
  139 + ->whereBetween('updated_date', [$startTime,$endTime])
  140 + ->groupBy('device_port')
  141 + ->limit(15)->get()->toArray();
  142 + $arr['referrer_port'] = json_encode($referrer_port);
  143 + return $arr;
  144 + }
  145 +
  146 +}