作者 赵彬吉

update

@@ -5,6 +5,7 @@ namespace App\Console\Commands\DayCount; @@ -5,6 +5,7 @@ namespace App\Console\Commands\DayCount;
5 use App\Helper\Common; 5 use App\Helper\Common;
6 use App\Helper\FormGlobalsoApi; 6 use App\Helper\FormGlobalsoApi;
7 use App\Models\Domain\DomainInfo; 7 use App\Models\Domain\DomainInfo;
  8 +use App\Models\Inquiry\InquiryOther;
8 use App\Models\Project\DeployBuild; 9 use App\Models\Project\DeployBuild;
9 use App\Models\Project\DeployOptimize; 10 use App\Models\Project\DeployOptimize;
10 use App\Models\Project\Project; 11 use App\Models\Project\Project;
@@ -80,7 +81,7 @@ class Count extends Command @@ -80,7 +81,7 @@ class Count extends Command
80 $arr['created_at'] = date('Y-m-d H:i:s'); 81 $arr['created_at'] = date('Y-m-d H:i:s');
81 $arr['updated_at'] = date('Y-m-d H:i:s'); 82 $arr['updated_at'] = date('Y-m-d H:i:s');
82 //询盘统计 83 //询盘统计
83 - $arr = $this->inquiry($arr,$v['test_domain']); 84 + $arr = $this->inquiry($arr,$v['test_domain'], $v['id']);
84 echo date('Y-m-d H:i:s') . json_encode($arr) . '->' . PHP_EOL; 85 echo date('Y-m-d H:i:s') . json_encode($arr) . '->' . PHP_EOL;
85 $data[] = $arr; 86 $data[] = $arr;
86 } 87 }
@@ -124,11 +125,11 @@ class Count extends Command @@ -124,11 +125,11 @@ class Count extends Command
124 * @method :post 125 * @method :post
125 * @time :2023/6/14 15:44 126 * @time :2023/6/14 15:44
126 */ 127 */
127 - public function inquiry($arr,$domain){ 128 + public function inquiry($arr,$domain,$project_id){
128 $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000); 129 $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
129 if($inquiry_list['status'] == self::STATUS_ERROR){ 130 if($inquiry_list['status'] == self::STATUS_ERROR){
130 $arr['inquiry_num'] = 0; 131 $arr['inquiry_num'] = 0;
131 - $arr['country'] = json_encode([]); 132 + $countryArr = [];
132 }else{ 133 }else{
133 $arr['inquiry_num'] = $inquiry_list['data']['total']; 134 $arr['inquiry_num'] = $inquiry_list['data']['total'];
134 //询盘国家统计 135 //询盘国家统计
@@ -138,13 +139,27 @@ class Count extends Command @@ -138,13 +139,27 @@ class Count extends Command
138 if(isset($countryArr[$v1['country']])){ 139 if(isset($countryArr[$v1['country']])){
139 $countryArr[$v1['country']]++; 140 $countryArr[$v1['country']]++;
140 }else{ 141 }else{
141 - $countryArr[$v1['country']] = 0; 142 + $countryArr[$v1['country']] = 1;
  143 + }
142 } 144 }
143 } 145 }
  146 +
  147 + //加上其他询盘
  148 + ProjectServer::useProject($project_id);
  149 + $arr['inquiry_num'] = InquiryOther::count();
  150 + $countryData = InquiryOther::select("country",DB::raw('COUNT(*) as count'))->groupBy('country')->get()->toArray();
  151 + foreach ($countryData as $v1){
  152 + if(isset($countryArr[$v1['country']])){
  153 + $countryArr[$v1['country']] += $v1['count'];
  154 + }else{
  155 + $countryArr[$v1['country']] = $v1['count'];
  156 + }
  157 + }
  158 +
  159 +
144 arsort($countryArr); 160 arsort($countryArr);
145 $top20 = array_slice($countryArr, 0, 20, true); 161 $top20 = array_slice($countryArr, 0, 20, true);
146 $arr['country'] = json_encode($top20); 162 $arr['country'] = json_encode($top20);
147 - }  
148 return $arr; 163 return $arr;
149 } 164 }
150 165
@@ -4,6 +4,7 @@ namespace App\Console\Commands\MonthlyCount; @@ -4,6 +4,7 @@ namespace App\Console\Commands\MonthlyCount;
4 4
5 use App\Helper\FormGlobalsoApi; 5 use App\Helper\FormGlobalsoApi;
6 use App\Models\Domain\DomainInfo; 6 use App\Models\Domain\DomainInfo;
  7 +use App\Models\Inquiry\InquiryOther;
7 use App\Models\Project\Project; 8 use App\Models\Project\Project;
8 use App\Services\ProjectServer; 9 use App\Services\ProjectServer;
9 use Carbon\Carbon; 10 use Carbon\Carbon;
@@ -54,12 +55,12 @@ class InquiryMonthlyCount extends Command @@ -54,12 +55,12 @@ class InquiryMonthlyCount extends Command
54 if(!empty($value['domain'])){ 55 if(!empty($value['domain'])){
55 $info = $domainInfo->read(['id'=>$value['domain']]); 56 $info = $domainInfo->read(['id'=>$value['domain']]);
56 if($info !== false){ 57 if($info !== false){
57 - $value['test_domain'] = $value['domain']; 58 + $value['test_domain'] = $info['domain'];
58 } 59 }
59 } 60 }
60 $arr = []; 61 $arr = [];
61 //按月统计询盘记录 62 //按月统计询盘记录
62 - $arr = $this->inquiryCount($arr,$startTime,$endTime,$value['test_domain']); 63 + $arr = $this->inquiryCount($arr,$startTime,$endTime,$value['test_domain'],$value['project_id']);
63 $arr = $this->flowCount($arr,$startTime,$endTime,$value['project_id']); 64 $arr = $this->flowCount($arr,$startTime,$endTime,$value['project_id']);
64 ProjectServer::useProject($value['project_id']); 65 ProjectServer::useProject($value['project_id']);
65 $arr = $this->sourceCount($arr,$value['test_domain'],$startTime,$endTime); 66 $arr = $this->sourceCount($arr,$value['test_domain'],$startTime,$endTime);
@@ -83,7 +84,7 @@ class InquiryMonthlyCount extends Command @@ -83,7 +84,7 @@ class InquiryMonthlyCount extends Command
83 * @method :post 84 * @method :post
84 * @time :2023/6/30 14:29 85 * @time :2023/6/30 14:29
85 */ 86 */
86 - public function inquiryCount(&$arr,&$startTime,&$endTime,$domain){ 87 + public function inquiryCount(&$arr,&$startTime,&$endTime,$domain,$project_id){
87 $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000); 88 $inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
88 //总数 89 //总数
89 $arr['total'] = $inquiry_list['data']['total'] ?? 0; 90 $arr['total'] = $inquiry_list['data']['total'] ?? 0;
@@ -96,17 +97,32 @@ class InquiryMonthlyCount extends Command @@ -96,17 +97,32 @@ class InquiryMonthlyCount extends Command
96 foreach ($data as $v){ 97 foreach ($data as $v){
97 if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){ 98 if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){
98 $arr['month_total']++; 99 $arr['month_total']++;
99 - }  
100 if(isset($countryArr[$v['country']])){ 100 if(isset($countryArr[$v['country']])){
101 $countryArr[$v['country']]++; 101 $countryArr[$v['country']]++;
102 }else{ 102 }else{
103 - $countryArr[$v['country']] = 0; 103 + $countryArr[$v['country']] = 1;
  104 + }
  105 + }
  106 + }
  107 + }
  108 + //加上其他询盘
  109 + ProjectServer::useProject($project_id);
  110 + $arr['total'] += InquiryOther::count();
  111 + $arr['month_total'] += InquiryOther::whereBetween('submit_time',[$startTime, $endTime])->count();
  112 + $countryData = InquiryOther::whereBetween('submit_time',[$startTime, $endTime])
  113 + ->select("country",DB::raw('COUNT(*) as count'))
  114 + ->groupBy('country')->get()->toArray();
  115 + foreach ($countryData as $v1){
  116 + if(isset($countryArr[$v1['country']])){
  117 + $countryArr[$v1['country']] += $v1['count'];
  118 + }else{
  119 + $countryArr[$v1['country']] = $v1['count'];
104 } 120 }
105 } 121 }
  122 +
106 arsort($countryArr); 123 arsort($countryArr);
107 $top20 = array_slice($countryArr, 0, 15, true); 124 $top20 = array_slice($countryArr, 0, 15, true);
108 $arr['country'] = json_encode($top20); 125 $arr['country'] = json_encode($top20);
109 - }  
110 return $arr; 126 return $arr;
111 } 127 }
112 128
@@ -22,7 +22,12 @@ class InquiryController extends BaseController @@ -22,7 +22,12 @@ class InquiryController extends BaseController
22 22
23 public function index(InquiryLogic $logic) 23 public function index(InquiryLogic $logic)
24 { 24 {
  25 + if(($this->param['type']??'') == 'other'){
  26 + $data = $logic->getOtherList();
  27 + }else{
25 $data = $logic->getApiList(); 28 $data = $logic->getApiList();
  29 + }
  30 +
26 return $this->success($data); 31 return $this->success($data);
27 } 32 }
28 33
@@ -32,7 +37,12 @@ class InquiryController extends BaseController @@ -32,7 +37,12 @@ class InquiryController extends BaseController
32 ],[ 37 ],[
33 'id.required' => 'ID不能为空' 38 'id.required' => 'ID不能为空'
34 ]); 39 ]);
  40 + if(($this->param['type']??'') == 'other'){
  41 + $data = $logic->getOtherInfo($this->param['id']);
  42 + }else{
35 $data = $logic->getInfo($this->param['id']); 43 $data = $logic->getInfo($this->param['id']);
  44 + }
  45 +
36 return $this->success($data); 46 return $this->success($data);
37 } 47 }
38 48
@@ -43,8 +53,12 @@ class InquiryController extends BaseController @@ -43,8 +53,12 @@ class InquiryController extends BaseController
43 ],[ 53 ],[
44 'ids.required' => 'ID不能为空' 54 'ids.required' => 'ID不能为空'
45 ]); 55 ]);
46 - 56 + if(($this->param['type']??'') == 'other'){
  57 + $logic->deleteOther($this->param['ids']);
  58 + }else{
47 $logic->delete($this->param['ids']); 59 $logic->delete($this->param['ids']);
  60 + }
  61 +
48 return $this->success(); 62 return $this->success();
49 } 63 }
50 64
@@ -58,12 +72,16 @@ class InquiryController extends BaseController @@ -58,12 +72,16 @@ class InquiryController extends BaseController
58 */ 72 */
59 public function export(InquiryLogic $logic) 73 public function export(InquiryLogic $logic)
60 { 74 {
  75 + if(($this->param['type']??'') == 'other'){
  76 + $data = $logic->getOtherList(true);
  77 + $map = [
  78 + 'submit_time' => '询盘发送时间',
  79 + 'email' => '邮箱',
  80 + 'ip_address' => '访问国家/地区(IP)',
  81 + 'referer' => '发送页面',
  82 + ];
  83 + }else{
61 $data = $logic->getApiList(true); 84 $data = $logic->getApiList(true);
62 - $data = $data['list'] ?? [];  
63 - foreach ($data as &$item){  
64 - $item['ip_address'] = "{$item['country']}({$item['ip']})";  
65 - }  
66 -  
67 $map = [ 85 $map = [
68 'submit_time' => '询盘发送时间', 86 'submit_time' => '询盘发送时间',
69 'name' => '姓名', 87 'name' => '姓名',
@@ -73,6 +91,12 @@ class InquiryController extends BaseController @@ -73,6 +91,12 @@ class InquiryController extends BaseController
73 'refer' => '发送页面', 91 'refer' => '发送页面',
74 'message' => '询盘内容', 92 'message' => '询盘内容',
75 ]; 93 ];
  94 + }
  95 +
  96 + $data = $data['list'] ?? [];
  97 + foreach ($data as &$item){
  98 + $item['ip_address'] = "{$item['country']}({$item['ip']})";
  99 + }
76 100
77 //生成文件,发送到客户端 101 //生成文件,发送到客户端
78 $table = new BatchExportService("询盘数据导出"); 102 $table = new BatchExportService("询盘数据导出");
@@ -8,6 +8,9 @@ use App\Helper\Translate; @@ -8,6 +8,9 @@ use App\Helper\Translate;
8 use App\Http\Logic\Aside\Project\ProjectLogic; 8 use App\Http\Logic\Aside\Project\ProjectLogic;
9 use App\Http\Logic\Bside\BaseLogic; 9 use App\Http\Logic\Bside\BaseLogic;
10 use App\Models\Domain\DomainInfo; 10 use App\Models\Domain\DomainInfo;
  11 +use App\Models\Inquiry\InquiryOther;
  12 +use App\Services\ProjectServer;
  13 +use Illuminate\Support\Facades\DB;
11 14
12 /** 15 /**
13 * Class InquiryLogic 16 * Class InquiryLogic
@@ -53,6 +56,23 @@ class InquiryLogic extends BaseLogic @@ -53,6 +56,23 @@ class InquiryLogic extends BaseLogic
53 return $this->success($data); 56 return $this->success($data);
54 } 57 }
55 58
  59 + public function getOtherList($export = false){
  60 + $page_size = $export ? 1000 : 20;
  61 + $search = $this->request['search'] ?: '';
  62 + $page = $this->request['page'] ?: 1;
  63 + $map = [];
  64 + if($search){
  65 + $map['email'] = ['like','%'.$search.'%'];
  66 + }
  67 + ProjectServer::useProject($this->user['project_id']);
  68 +
  69 + $data = (new InquiryOther())->lists($map,$page,$page_size,'id',
  70 + ['id', 'email', 'ip', 'country', 'domain', DB::raw('referer as refer'), DB::raw('status as read_status'), 'submit_time']
  71 + );
  72 +
  73 + return $this->success($data);
  74 + }
  75 +
56 public function getInfo($id) 76 public function getInfo($id)
57 { 77 {
58 $project = (new ProjectLogic())->getProjectInfo($this->user['project_id']); 78 $project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
@@ -69,6 +89,15 @@ class InquiryLogic extends BaseLogic @@ -69,6 +89,15 @@ class InquiryLogic extends BaseLogic
69 return $this->success(['trans_message' => $trans_message]); 89 return $this->success(['trans_message' => $trans_message]);
70 } 90 }
71 91
  92 + public function getOtherInfo($id){
  93 + //修改状态为已读
  94 + if($this->request['read_status']){
  95 + ProjectServer::useProject($this->user['project_id']);
  96 + (new InquiryOther())->edit(['status' => 1], ['id' => $id]);
  97 + }
  98 + return $this->success(['trans_message' => '']);
  99 + }
  100 +
72 public function delete($ids, $map = []) 101 public function delete($ids, $map = [])
73 { 102 {
74 $project = (new ProjectLogic())->getProjectInfo($this->user['project_id']); 103 $project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
@@ -81,6 +110,16 @@ class InquiryLogic extends BaseLogic @@ -81,6 +110,16 @@ class InquiryLogic extends BaseLogic
81 return $this->success(); 110 return $this->success();
82 } 111 }
83 112
  113 + public function deleteOther($ids, $map = [])
  114 + {
  115 + $ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
  116 + if(!$ids){
  117 + $this->fail('ID不能为空');
  118 + }
  119 + ProjectServer::useProject($this->user['project_id']);
  120 + (new InquiryOther())->del(['id'=>['in',$ids]]);
  121 + return $this->success();
  122 + }
84 123
85 124
86 125
  1 +<?php
  2 +
  3 +namespace App\Models\Inquiry;
  4 +
  5 +use App\Models\Base;
  6 +use Illuminate\Database\Eloquent\SoftDeletes;
  7 +
  8 +/**
  9 + * Class InquiryOther
  10 + * @package App\Models\Inquiry
  11 + * @author zbj
  12 + * @date 2023/11/29
  13 + */
  14 +class InquiryOther extends Base
  15 +{
  16 + use SoftDeletes;
  17 +
  18 + //连接数据库
  19 + protected $connection = 'custom_mysql';
  20 +
  21 + protected $table = 'gl_inquiry_other';
  22 +}