作者 赵彬吉

update

... ... @@ -146,8 +146,8 @@ class Count extends Command
//加上其他询盘
ProjectServer::useProject($project_id);
$arr['inquiry_num'] += InquiryFormData::count();
$countryData = InquiryFormData::select("country",DB::raw('COUNT(*) as count'))->groupBy('country')->get()->toArray();
$arr['inquiry_num'] += InquiryFormData::getCount();
$countryData = InquiryFormData::getCountryCount();
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
... ...
... ... @@ -108,10 +108,8 @@ class InquiryMonthlyCount extends Command
//加上其他询盘
ProjectServer::useProject($project_id);
$arr['total'] += InquiryFormData::count();
$arr['month_total'] += InquiryFormData::whereBetween('submit_at',[$startTime, $endTime])->count();
$countryData = InquiryFormData::whereBetween('submit_at',[$startTime, $endTime])
->select("country",DB::raw('COUNT(*) as count'))
->groupBy('country')->get()->toArray();
$arr['month_total'] += InquiryFormData::getCount([$startTime, $endTime]);
$countryData = InquiryFormData::getCountryCount([$startTime, $endTime]);
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
... ...
... ... @@ -4,11 +4,14 @@ namespace App\Console\Commands;
use App\Helper\FormGlobalsoApi;
use App\Models\Domain\DomainInfo;
use App\Models\HomeCount\Count;
use App\Models\Inquiry\InquiryFormData;
use App\Models\Project\Project;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use mysql_xdevapi\Exception;
... ... @@ -56,12 +59,19 @@ class Test extends Command
echo '未配置数据库' . PHP_EOL;
continue;
}
$test_domain = $project->deploy_build['test_domain'];
$domainInfo = new DomainInfo();
$info = $domainInfo->read(['id'=>$project->deploy_optimize['domain']]);
if($info !== false){
$test_domain = $info['domain'];
}
try {
$list = Count::where('pv_num', 0)->get();
$list = Count::where('date', '2023-12-11')->where('project_id', $project->id)->get();
foreach ($list as $v){
$v->pv_num = $this->pv_num($v['date']);
//ip统计
$v->ip_num = $this->ip_num($v['date']);
$arr = $this->inquiry([],$test_domain, $v['id']);
$v->inquiry_num = $arr['inquiry_num'];
$v->country = $arr['country'];
$v->save();
echo $v['date'] . ':' . $v->pv_num .':'. $v->ip_num . PHP_EOL;
}
... ... @@ -72,25 +82,40 @@ class Test extends Command
echo "finish";
}
/**
* @name :(统计pv)pv_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function pv_num($yesterday){
$pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $yesterday)->count();
return $pv;
public function inquiry($arr,$domain,$project_id){
$inquiry_list = (new FormGlobalsoApi())->getInquiryList($domain,'',1,100000000);
if($inquiry_list['status'] == 400){
$arr['inquiry_num'] = 0;
$countryArr = [];
}else{
$arr['inquiry_num'] = $inquiry_list['data']['total'];
//询盘国家统计
$countryData = $inquiry_list['data']['data'];
$countryArr = [];
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']]++;
}else{
$countryArr[$v1['country']] = 1;
}
}
}
/**
* @name :(统计ip)ip_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function ip_num($yesterday){
$ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $yesterday)->count();
return $ip;
//加上其他询盘
$arr['inquiry_num'] += InquiryFormData::getCount();
$countryData = InquiryFormData::getCountryCount();
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;
}
}
... ...
... ... @@ -86,11 +86,9 @@ class MonthCountLogic extends BaseLogic
}
}
//加上其他询盘
$arr['total'] += InquiryFormData::count();
$arr['month_total'] += InquiryFormData::whereBetween('submit_at',[$startTime, $endTime])->count();
$countryData = InquiryFormData::whereBetween('submit_at',[$startTime, $endTime])
->select("country",DB::raw('COUNT(*) as count'))
->groupBy('country')->get()->toArray();
$arr['total'] += InquiryFormData::getCount();
$arr['month_total'] += InquiryFormData::getCount([$startTime, $endTime]);
$countryData = InquiryFormData::getCountryCount([$startTime, $endTime]);
foreach ($countryData as $v1){
if(isset($countryArr[$v1['country']])){
$countryArr[$v1['country']] += $v1['count'];
... ...
... ... @@ -4,6 +4,7 @@ namespace App\Models\Inquiry;
use App\Models\Base;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
/**
* Class InquiryFormData
... ... @@ -26,4 +27,32 @@ class InquiryFormData extends Base
{
return json_decode($value, true);
}
/**
* 非默认表单的数量统计
* @author zbj
* @date 2023/12/12
*/
public static function getCount($submit_at = []){
return self::leftjoin('gl_inquiry_form', 'gl_inquiry_form.id', '=', 'gl_inquiry_form_data.form_id')
->where('gl_inquiry_form.is_default', 0)
->when($submit_at, function ($query, $submit_at) {
$query->whereBetween('submit_at',[$submit_at[0], $submit_at[1]]);
})
->count();
}
/**
* 非默认表单的国家统计
* @author zbj
* @date 2023/12/12
*/
public static function getCountryCount($submit_at = []){
return self::leftjoin('gl_inquiry_form', 'gl_inquiry_form.id', '=', 'gl_inquiry_form_data.form_id')
->where('gl_inquiry_form.is_default', 0)
->when($submit_at, function ($query, $submit_at) {
$query->whereBetween('submit_at',[$submit_at[0], $submit_at[1]]);
})
->select("country",DB::raw('COUNT(*) as count'))->groupBy('country')->get()->toArray();
}
}
... ...