作者 lyh

gx

  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 UpgradeCount 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 + $projectModel = new Project();
  37 + $list = $projectModel->list(['is_upgrade'=>1,'delete_status'=>0]);
  38 + foreach ($list as $v) {
  39 + ProjectServer::useProject($v['id']);
  40 + $this->count($v['id']);
  41 + DB::disconnect('custom_mysql');
  42 + }
  43 + return true;
  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){
  54 + $list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date')
  55 + ->groupBy('updated_date')->get()->toArray();
  56 + $project = new Project();
  57 + $projectInfo = $project->read(['id'=>$project_id]);
  58 + if(!empty($list)){
  59 + $arr = [];
  60 + foreach ($list as $k=>$v){
  61 + if($v['updated_date'] == date('Y-m-d')){
  62 + continue;
  63 + }
  64 + $v = (array)$v;
  65 + echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL;
  66 + $count = new Count();
  67 + $arr['project_id'] = $project_id;
  68 + $arr['date'] = $v['updated_date'];
  69 + $arr['pv_num'] = $this->pv_num($v['updated_date']);
  70 + $arr['ip_num'] = $this->ip_num($v['updated_date']);
  71 + $arr['inquiry_num'] = $this->inquiry_num($v['updated_date']);
  72 + //服务达标天数
  73 + $arr['compliance_day'] = $projectInfo['finish_remain_day'];
  74 + //剩余服务时常
  75 + $arr['service_day'] = $projectInfo['remain_day'];
  76 + $arr['country'] = json_encode([]);
  77 + //查询当天数据是否存在 存在则更新
  78 + $info = $count->read(['date'=>$v['updated_date'],'project_id'=>$project_id]);
  79 + if($info === false){
  80 + $arr['created_at'] = $v['updated_date'].' 01:00:00';
  81 + $arr['updated_at'] = $v['updated_date'].' 01:00:00';
  82 + $count->insert($arr);
  83 + }else{
  84 + $count->edit($arr,['id'=>$info['id']]);
  85 + }
  86 + }
  87 + }
  88 + echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
  89 + }
  90 +
  91 + /**
  92 + * @remark :询盘数量
  93 + * @name :inquiry_num
  94 + * @author :lyh
  95 + * @method :post
  96 + * @time :2024/1/8 9:24
  97 + */
  98 + public function inquiry_num($day){
  99 + $count = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->where('is_inquiry',1)->count();
  100 + return $count;
  101 + }
  102 +
  103 + /**
  104 + * @name :(统计pv)pv_num
  105 + * @author :lyh
  106 + * @method :post
  107 + * @time :2023/6/14 15:40
  108 + */
  109 + public function pv_num($day){
  110 + //$pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $day)->count();
  111 + $pv = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->sum('depth');
  112 + return $pv;
  113 + }
  114 +
  115 + /**
  116 + * @name :(统计ip)ip_num
  117 + * @author :lyh
  118 + * @method :post
  119 + * @time :2023/6/14 15:40
  120 + */
  121 + public function ip_num($day){
  122 + $ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->count();
  123 + return $ip;
  124 + }
  125 +
  126 +
  127 +
  128 +}