作者 lyh

gx

@@ -3,8 +3,10 @@ @@ -3,8 +3,10 @@
3 namespace App\Console\Commands\MonthlyCount; 3 namespace App\Console\Commands\MonthlyCount;
4 4
5 use App\Helper\FormGlobalsoApi; 5 use App\Helper\FormGlobalsoApi;
  6 +use App\Models\Project\DeployBuild;
6 use Carbon\Carbon; 7 use Carbon\Carbon;
7 use Illuminate\Console\Command; 8 use Illuminate\Console\Command;
  9 +use Illuminate\Support\Facades\DB;
8 10
9 class InquiryMonthlyCount extends Command 11 class InquiryMonthlyCount extends Command
10 { 12 {
@@ -32,40 +34,71 @@ class InquiryMonthlyCount extends Command @@ -32,40 +34,71 @@ class InquiryMonthlyCount extends Command
32 * @time :2023/6/30 9:32 34 * @time :2023/6/30 9:32
33 */ 35 */
34 public function handle(){ 36 public function handle(){
35 - //统计数据  
36 - $arr = []; 37 + $deployModel = new DeployBuild();
  38 + $list = $deployModel->list();
37 // 获取上个月的开始时间 39 // 获取上个月的开始时间
38 $startTime = Carbon::now()->subMonth()->startOfMonth(); 40 $startTime = Carbon::now()->subMonth()->startOfMonth();
39 // 获取上个月的结束时间 41 // 获取上个月的结束时间
40 $endTime = Carbon::now()->subMonth()->endOfMonth(); 42 $endTime = Carbon::now()->subMonth()->endOfMonth();
  43 + foreach ($list as $value){
  44 + //按月统计询盘记录
  45 + $this->inquiryCount($startTime,$endTime,$value['test_domain'],$value['project_id']);
  46 + }
41 } 47 }
42 48
43 /** 49 /**
44 - * @param $arr  
45 * @param $domain 50 * @param $domain
46 - * @name :(询盘统计)inquiry 51 + * @param $project_id
  52 + * @remark :询盘按月统计
  53 + * @name :inquiryCount
47 * @author :lyh 54 * @author :lyh
48 * @method :post 55 * @method :post
49 - * @time :2023/6/14 15:44 56 + * @time :2023/6/30 14:29
50 */ 57 */
51 - public function inquiry($arr,$domain){ 58 + public function inquiryCount($startTime,$endTime,$domain,$project_id){
  59 + //TODO::上线后注释
  60 + $domain = 'https://demomark.globalso.com/';
  61 + $arr = [];
52 $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000); 62 $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
53 - $arr['count'] = $inquiry_list['data']['total'];  
54 - //询盘国家统计  
55 - $countryData = $inquiry_list['data']['data']; 63 + //总数
  64 + $arr['total'] = $inquiry_list['data']['total'];
  65 + //数据详情
  66 + $data = $inquiry_list['data']['data'];
  67 + $arr['month_total'] = 0;
56 $countryArr = []; 68 $countryArr = [];
57 - foreach ($countryData as $v1){  
58 - if(isset($countryArr[$v1['country']])){  
59 - $countryArr[$v1['country']]++; 69 + foreach ($data as $v){
  70 + if(($startTime <= $v['submit_time']) && $v['submit_time'] <= $endTime){
  71 + $arr['month_total']++;
  72 + }
  73 + if(isset($countryArr[$v['country']])){
  74 + $countryArr[$v['country']]++;
60 }else{ 75 }else{
61 - $countryArr[$v1['country']] = 0; 76 + $countryArr[$v['country']] = 0;
62 } 77 }
63 } 78 }
  79 + // 获取当前日期时间
  80 + $arr['month'] = Carbon::now()->subMonth()->format('Y-m');
64 arsort($countryArr); 81 arsort($countryArr);
65 - $top20 = array_slice($countryArr, 0, 20, true); 82 + $top20 = array_slice($countryArr, 0, 15, true);
66 $arr['country'] = json_encode($top20); 83 $arr['country'] = json_encode($top20);
67 -  
68 - return $arr; 84 + $arr['created_at'] = date('Y-m-d H:i:s');
  85 + $arr['updated_at'] = date('Y-m-d H:i:s');
  86 + $arr['project_id'] = $project_id;
  87 + DB::table('gl_inquiry_month_count')->insert($arr);
69 } 88 }
70 89
  90 + /**
  91 + * @remark :流量统计
  92 + * @name :flowCount
  93 + * @author :lyh
  94 + * @method :post
  95 + * @time :2023/6/30 14:31
  96 + */
  97 + public function flowCount($startTime,$endTime,$project_id){
  98 + DB::table('gl_count')
  99 + ->where(['project_id'=>$project_id])
  100 + ->where('date','>=',$startTime)
  101 + ->where('date','<=',$endTime)
  102 + ->sum('pv_num');
  103 + }
71 } 104 }
@@ -178,7 +178,7 @@ class ComController extends BaseController @@ -178,7 +178,7 @@ class ComController extends BaseController
178 $arr['updated_at'] = date('Y-m-d H:i:s'); 178 $arr['updated_at'] = date('Y-m-d H:i:s');
179 $arr['project_id'] = 1; 179 $arr['project_id'] = 1;
180 DB::table('gl_inquiry_month_count')->insert($arr); 180 DB::table('gl_inquiry_month_count')->insert($arr);
181 - $this->response('success',Code::SUCCESS,$inquiry_list); 181 + $this->response('success',Code::SUCCESS,$startTime);
182 } 182 }
183 183
184 /** 184 /**