作者 赵彬吉

update

... ... @@ -5,6 +5,7 @@ namespace App\Console\Commands\DayCount;
use App\Helper\Common;
use App\Helper\FormGlobalsoApi;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryOther;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Project;
... ... @@ -80,7 +81,7 @@ class Count extends Command
$arr['created_at'] = date('Y-m-d H:i:s');
$arr['updated_at'] = date('Y-m-d H:i:s');
//询盘统计
$arr = $this->inquiry($arr,$v['test_domain']);
$arr = $this->inquiry($arr,$v['test_domain'], $v['id']);
echo date('Y-m-d H:i:s') . json_encode($arr) . '->' . PHP_EOL;
$data[] = $arr;
}
... ... @@ -124,11 +125,11 @@ class Count extends Command
* @method :post
* @time :2023/6/14 15:44
*/
public function inquiry($arr,$domain){
public function inquiry($arr,$domain,$project_id){
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
if($inquiry_list['status'] == self::STATUS_ERROR){
$arr['inquiry_num'] = 0;
$arr['country'] = json_encode([]);
$countryArr = [];
}else{
$arr['inquiry_num'] = $inquiry_list['data']['total'];
//询盘国家统计
... ... @@ -138,13 +139,27 @@ class Count extends Command
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']]++;
}else{
$countryArr[$v1['country']] = 0;
$countryArr[$v1['country']] = 1;
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 20, true);
$arr['country'] = json_encode($top20);
}
//加上其他询盘
ProjectServer::useProject($project_id);
$arr['inquiry_num'] = InquiryOther::count();
$countryData = InquiryOther::select("country",DB::raw('COUNT(*) as count'))->groupBy('country')->get()->toArray();
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
}else{
$countryArr[$v1['country']] = $v1['count'];
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 20, true);
$arr['country'] = json_encode($top20);
return $arr;
}
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Console\Commands\MonthlyCount;
use App\Helper\FormGlobalsoApi;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryOther;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Carbon\Carbon;
... ... @@ -54,12 +55,12 @@ class InquiryMonthlyCount extends Command
if(!empty($value['domain'])){
$info = $domainInfo->read(['id'=>$value['domain']]);
if($info !== false){
$value['test_domain'] = $value['domain'];
$value['test_domain'] = $info['domain'];
}
}
$arr = [];
//按月统计询盘记录
$arr = $this->inquiryCount($arr,$startTime,$endTime,$value['test_domain']);
$arr = $this->inquiryCount($arr,$startTime,$endTime,$value['test_domain'],$value['project_id']);
$arr = $this->flowCount($arr,$startTime,$endTime,$value['project_id']);
ProjectServer::useProject($value['project_id']);
$arr = $this->sourceCount($arr,$value['test_domain'],$startTime,$endTime);
... ... @@ -83,7 +84,7 @@ class InquiryMonthlyCount extends Command
* @method :post
* @time :2023/6/30 14:29
*/
public function inquiryCount(&$arr,&$startTime,&$endTime,$domain){
public function inquiryCount(&$arr,&$startTime,&$endTime,$domain,$project_id){
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
//总数
$arr['total'] = $inquiry_list['data']['total'] ?? 0;
... ... @@ -96,17 +97,32 @@ class InquiryMonthlyCount extends Command
foreach ($data as $v){
if(($startTime.' 00:00:00' <= $v['submit_time']) && $v['submit_time'] <= $endTime.' 23:59:59'){
$arr['month_total']++;
if(isset($countryArr[$v['country']])){
$countryArr[$v['country']]++;
}else{
$countryArr[$v['country']] = 1;
}
}
if(isset($countryArr[$v['country']])){
$countryArr[$v['country']]++;
}else{
$countryArr[$v['country']] = 0;
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 15, true);
$arr['country'] = json_encode($top20);
}
//加上其他询盘
ProjectServer::useProject($project_id);
$arr['total'] += InquiryOther::count();
$arr['month_total'] += InquiryOther::whereBetween('submit_time',[$startTime, $endTime])->count();
$countryData = InquiryOther::whereBetween('submit_time',[$startTime, $endTime])
->select("country",DB::raw('COUNT(*) as count'))
->groupBy('country')->get()->toArray();
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
}else{
$countryArr[$v1['country']] = $v1['count'];
}
}
arsort($countryArr);
$top20 = array_slice($countryArr, 0, 15, true);
$arr['country'] = json_encode($top20);
return $arr;
}
... ...
... ... @@ -22,7 +22,12 @@ class InquiryController extends BaseController
public function index(InquiryLogic $logic)
{
$data = $logic->getApiList();
if(($this->param['type']??'') == 'other'){
$data = $logic->getOtherList();
}else{
$data = $logic->getApiList();
}
return $this->success($data);
}
... ... @@ -32,7 +37,12 @@ class InquiryController extends BaseController
],[
'id.required' => 'ID不能为空'
]);
$data = $logic->getInfo($this->param['id']);
if(($this->param['type']??'') == 'other'){
$data = $logic->getOtherInfo($this->param['id']);
}else{
$data = $logic->getInfo($this->param['id']);
}
return $this->success($data);
}
... ... @@ -43,8 +53,12 @@ class InquiryController extends BaseController
],[
'ids.required' => 'ID不能为空'
]);
if(($this->param['type']??'') == 'other'){
$logic->deleteOther($this->param['ids']);
}else{
$logic->delete($this->param['ids']);
}
$logic->delete($this->param['ids']);
return $this->success();
}
... ... @@ -58,22 +72,32 @@ class InquiryController extends BaseController
*/
public function export(InquiryLogic $logic)
{
$data = $logic->getApiList(true);
if(($this->param['type']??'') == 'other'){
$data = $logic->getOtherList(true);
$map = [
'submit_time' => '询盘发送时间',
'email' => '邮箱',
'ip_address' => '访问国家/地区(IP)',
'referer' => '发送页面',
];
}else{
$data = $logic->getApiList(true);
$map = [
'submit_time' => '询盘发送时间',
'name' => '姓名',
'email' => '邮箱',
'phone' => '电话',
'ip_address' => '访问国家/地区(IP)',
'refer' => '发送页面',
'message' => '询盘内容',
];
}
$data = $data['list'] ?? [];
foreach ($data as &$item){
$item['ip_address'] = "{$item['country']}({$item['ip']})";
}
$map = [
'submit_time' => '询盘发送时间',
'name' => '姓名',
'email' => '邮箱',
'phone' => '电话',
'ip_address' => '访问国家/地区(IP)',
'refer' => '发送页面',
'message' => '询盘内容',
];
//生成文件,发送到客户端
$table = new BatchExportService("询盘数据导出");
$file = $table->head($map)->data($data)->save();
... ...
... ... @@ -8,6 +8,9 @@ use App\Helper\Translate;
use App\Http\Logic\Aside\Project\ProjectLogic;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryOther;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
/**
* Class InquiryLogic
... ... @@ -53,6 +56,23 @@ class InquiryLogic extends BaseLogic
return $this->success($data);
}
public function getOtherList($export = false){
$page_size = $export ? 1000 : 20;
$search = $this->request['search'] ?: '';
$page = $this->request['page'] ?: 1;
$map = [];
if($search){
$map['email'] = ['like','%'.$search.'%'];
}
ProjectServer::useProject($this->user['project_id']);
$data = (new InquiryOther())->lists($map,$page,$page_size,'id',
['id', 'email', 'ip', 'country', 'domain', DB::raw('referer as refer'), DB::raw('status as read_status'), 'submit_time']
);
return $this->success($data);
}
public function getInfo($id)
{
$project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
... ... @@ -69,6 +89,15 @@ class InquiryLogic extends BaseLogic
return $this->success(['trans_message' => $trans_message]);
}
public function getOtherInfo($id){
//修改状态为已读
if($this->request['read_status']){
ProjectServer::useProject($this->user['project_id']);
(new InquiryOther())->edit(['status' => 1], ['id' => $id]);
}
return $this->success(['trans_message' => '']);
}
public function delete($ids, $map = [])
{
$project = (new ProjectLogic())->getProjectInfo($this->user['project_id']);
... ... @@ -81,6 +110,16 @@ class InquiryLogic extends BaseLogic
return $this->success();
}
public function deleteOther($ids, $map = [])
{
$ids = array_filter(Arr::splitFilterToArray($ids), 'intval');
if(!$ids){
$this->fail('ID不能为空');
}
ProjectServer::useProject($this->user['project_id']);
(new InquiryOther())->del(['id'=>['in',$ids]]);
return $this->success();
}
... ...
<?php
namespace App\Models\Inquiry;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Class InquiryOther
* @package App\Models\Inquiry
* @author zbj
* @date 2023/11/29
*/
class InquiryOther extends Base
{
use SoftDeletes;
//连接数据库
protected $connection = 'custom_mysql';
protected $table = 'gl_inquiry_other';
}
... ...