作者 赵彬吉

update

@@ -146,8 +146,8 @@ class Count extends Command @@ -146,8 +146,8 @@ class Count extends Command
146 146
147 //加上其他询盘 147 //加上其他询盘
148 ProjectServer::useProject($project_id); 148 ProjectServer::useProject($project_id);
149 - $arr['inquiry_num'] += InquiryFormData::count();  
150 - $countryData = InquiryFormData::select("country",DB::raw('COUNT(*) as count'))->groupBy('country')->get()->toArray(); 149 + $arr['inquiry_num'] += InquiryFormData::getCount();
  150 + $countryData = InquiryFormData::getCountryCount();
151 foreach ($countryData as $v1){ 151 foreach ($countryData as $v1){
152 if(isset($countryArr[$v1['country']])){ 152 if(isset($countryArr[$v1['country']])){
153 $countryArr[$v1['country']] += $v1['count']; 153 $countryArr[$v1['country']] += $v1['count'];
@@ -108,10 +108,8 @@ class InquiryMonthlyCount extends Command @@ -108,10 +108,8 @@ class InquiryMonthlyCount extends Command
108 //加上其他询盘 108 //加上其他询盘
109 ProjectServer::useProject($project_id); 109 ProjectServer::useProject($project_id);
110 $arr['total'] += InquiryFormData::count(); 110 $arr['total'] += InquiryFormData::count();
111 - $arr['month_total'] += InquiryFormData::whereBetween('submit_at',[$startTime, $endTime])->count();  
112 - $countryData = InquiryFormData::whereBetween('submit_at',[$startTime, $endTime])  
113 - ->select("country",DB::raw('COUNT(*) as count'))  
114 - ->groupBy('country')->get()->toArray(); 111 + $arr['month_total'] += InquiryFormData::getCount([$startTime, $endTime]);
  112 + $countryData = InquiryFormData::getCountryCount([$startTime, $endTime]);
115 foreach ($countryData as $v1){ 113 foreach ($countryData as $v1){
116 if(isset($countryArr[$v1['country']])){ 114 if(isset($countryArr[$v1['country']])){
117 $countryArr[$v1['country']] += $v1['count']; 115 $countryArr[$v1['country']] += $v1['count'];
@@ -4,11 +4,14 @@ namespace App\Console\Commands; @@ -4,11 +4,14 @@ namespace App\Console\Commands;
4 4
5 5
6 6
  7 +use App\Helper\FormGlobalsoApi;
7 use App\Models\Domain\DomainInfo; 8 use App\Models\Domain\DomainInfo;
8 use App\Models\HomeCount\Count; 9 use App\Models\HomeCount\Count;
  10 +use App\Models\Inquiry\InquiryFormData;
9 use App\Models\Project\Project; 11 use App\Models\Project\Project;
10 use App\Services\ProjectServer; 12 use App\Services\ProjectServer;
11 use Illuminate\Console\Command; 13 use Illuminate\Console\Command;
  14 +use Illuminate\Database\Eloquent\Model;
12 use Illuminate\Support\Facades\DB; 15 use Illuminate\Support\Facades\DB;
13 use mysql_xdevapi\Exception; 16 use mysql_xdevapi\Exception;
14 17
@@ -56,12 +59,19 @@ class Test extends Command @@ -56,12 +59,19 @@ class Test extends Command
56 echo '未配置数据库' . PHP_EOL; 59 echo '未配置数据库' . PHP_EOL;
57 continue; 60 continue;
58 } 61 }
  62 + $test_domain = $project->deploy_build['test_domain'];
  63 + $domainInfo = new DomainInfo();
  64 + $info = $domainInfo->read(['id'=>$project->deploy_optimize['domain']]);
  65 + if($info !== false){
  66 + $test_domain = $info['domain'];
  67 + }
  68 +
59 try { 69 try {
60 - $list = Count::where('pv_num', 0)->get(); 70 + $list = Count::where('date', '2023-12-11')->where('project_id', $project->id)->get();
61 foreach ($list as $v){ 71 foreach ($list as $v){
62 - $v->pv_num = $this->pv_num($v['date']);  
63 - //ip统计  
64 - $v->ip_num = $this->ip_num($v['date']); 72 + $arr = $this->inquiry([],$test_domain, $v['id']);
  73 + $v->inquiry_num = $arr['inquiry_num'];
  74 + $v->country = $arr['country'];
65 $v->save(); 75 $v->save();
66 echo $v['date'] . ':' . $v->pv_num .':'. $v->ip_num . PHP_EOL; 76 echo $v['date'] . ':' . $v->pv_num .':'. $v->ip_num . PHP_EOL;
67 } 77 }
@@ -72,25 +82,40 @@ class Test extends Command @@ -72,25 +82,40 @@ class Test extends Command
72 echo "finish"; 82 echo "finish";
73 } 83 }
74 84
75 - /**  
76 - * @name :(统计pv)pv_num  
77 - * @author :lyh  
78 - * @method :post  
79 - * @time :2023/6/14 15:40  
80 - */  
81 - public function pv_num($yesterday){  
82 - $pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $yesterday)->count();  
83 - return $pv; 85 + public function inquiry($arr,$domain,$project_id){
  86 + $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
  87 + if($inquiry_list['status'] == 400){
  88 + $arr['inquiry_num'] = 0;
  89 + $countryArr = [];
  90 + }else{
  91 + $arr['inquiry_num'] = $inquiry_list['data']['total'];
  92 + //询盘国家统计
  93 + $countryData = $inquiry_list['data']['data'];
  94 + $countryArr = [];
  95 + foreach ($countryData as $v1){
  96 + if(isset($countryArr[$v1['country']])){
  97 + $countryArr[$v1['country']]++;
  98 + }else{
  99 + $countryArr[$v1['country']] = 1;
  100 + }
  101 + }
84 } 102 }
85 103
86 - /**  
87 - * @name :(统计ip)ip_num  
88 - * @author :lyh  
89 - * @method :post  
90 - * @time :2023/6/14 15:40  
91 - */  
92 - public function ip_num($yesterday){  
93 - $ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $yesterday)->count();  
94 - return $ip; 104 + //加上其他询盘
  105 + $arr['inquiry_num'] += InquiryFormData::getCount();
  106 + $countryData = InquiryFormData::getCountryCount();
  107 + foreach ($countryData as $v1){
  108 + if(isset($countryArr[$v1['country']])){
  109 + $countryArr[$v1['country']] += $v1['count'];
  110 + }else{
  111 + $countryArr[$v1['country']] = $v1['count'];
  112 + }
  113 + }
  114 +
  115 +
  116 + arsort($countryArr);
  117 + $top20 = array_slice($countryArr, 0, 20, true);
  118 + $arr['country'] = json_encode($top20);
  119 + return $arr;
95 } 120 }
96 } 121 }
@@ -86,11 +86,9 @@ class MonthCountLogic extends BaseLogic @@ -86,11 +86,9 @@ class MonthCountLogic extends BaseLogic
86 } 86 }
87 } 87 }
88 //加上其他询盘 88 //加上其他询盘
89 - $arr['total'] += InquiryFormData::count();  
90 - $arr['month_total'] += InquiryFormData::whereBetween('submit_at',[$startTime, $endTime])->count();  
91 - $countryData = InquiryFormData::whereBetween('submit_at',[$startTime, $endTime])  
92 - ->select("country",DB::raw('COUNT(*) as count'))  
93 - ->groupBy('country')->get()->toArray(); 89 + $arr['total'] += InquiryFormData::getCount();
  90 + $arr['month_total'] += InquiryFormData::getCount([$startTime, $endTime]);
  91 + $countryData = InquiryFormData::getCountryCount([$startTime, $endTime]);
94 foreach ($countryData as $v1){ 92 foreach ($countryData as $v1){
95 if(isset($countryArr[$v1['country']])){ 93 if(isset($countryArr[$v1['country']])){
96 $countryArr[$v1['country']] += $v1['count']; 94 $countryArr[$v1['country']] += $v1['count'];
@@ -4,6 +4,7 @@ namespace App\Models\Inquiry; @@ -4,6 +4,7 @@ namespace App\Models\Inquiry;
4 4
5 use App\Models\Base; 5 use App\Models\Base;
6 use Illuminate\Database\Eloquent\SoftDeletes; 6 use Illuminate\Database\Eloquent\SoftDeletes;
  7 +use Illuminate\Support\Facades\DB;
7 8
8 /** 9 /**
9 * Class InquiryFormData 10 * Class InquiryFormData
@@ -26,4 +27,32 @@ class InquiryFormData extends Base @@ -26,4 +27,32 @@ class InquiryFormData extends Base
26 { 27 {
27 return json_decode($value, true); 28 return json_decode($value, true);
28 } 29 }
  30 +
  31 + /**
  32 + * 非默认表单的数量统计
  33 + * @author zbj
  34 + * @date 2023/12/12
  35 + */
  36 + public static function getCount($submit_at = []){
  37 + return self::leftjoin('gl_inquiry_form', 'gl_inquiry_form.id', '=', 'gl_inquiry_form_data.form_id')
  38 + ->where('gl_inquiry_form.is_default', 0)
  39 + ->when($submit_at, function ($query, $submit_at) {
  40 + $query->whereBetween('submit_at',[$submit_at[0], $submit_at[1]]);
  41 + })
  42 + ->count();
  43 + }
  44 +
  45 + /**
  46 + * 非默认表单的国家统计
  47 + * @author zbj
  48 + * @date 2023/12/12
  49 + */
  50 + public static function getCountryCount($submit_at = []){
  51 + return self::leftjoin('gl_inquiry_form', 'gl_inquiry_form.id', '=', 'gl_inquiry_form_data.form_id')
  52 + ->where('gl_inquiry_form.is_default', 0)
  53 + ->when($submit_at, function ($query, $submit_at) {
  54 + $query->whereBetween('submit_at',[$submit_at[0], $submit_at[1]]);
  55 + })
  56 + ->select("country",DB::raw('COUNT(*) as count'))->groupBy('country')->get()->toArray();
  57 + }
29 } 58 }