作者 zhl

Merge remote-tracking branch 'origin/master' into zhl

<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
*/
namespace App\Console\Commands\DayCount;
use App\Models\Project\Project;
use App\Models\Visit\Visit;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeProjectCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_count';
/**
* The console command description.
*
* @var string
*/
protected $description = '升级项目统计';
public function handle(){
ProjectServer::useProject(439);
$this->count();
DB::disconnect('custom_mysql');
}
/**
* @remark :日统计记录
* @name :count
* @author :lyh
* @method :post
* @time :2024/1/8 9:05
*/
public function count(){
$list = DB::connection('custom_mysql')->table('gl_customer_visit')->select('updated_date')
->groupBy('updated_date')->get()->toArray();
$project = new Project();
$projectInfo = $project->read(['id'=>439]);
if(!empty($list)){
$arr = [];
foreach ($list as $k=>$v){
$v = (array)$v;
echo date('Y-m-d H:i:s') . '时间:'.$v['updated_date'] . PHP_EOL;
$count = new Count();
$arr['project_id'] = 439;
$arr['date'] = $v['updated_date'];
$arr['pv_num'] = $this->pv_num($v['updated_date']);
$arr['ip_num'] = $this->ip_num($v['updated_date']);
$arr['inquiry_num'] = $this->inquiry_num($v['updated_date']);
//服务达标天数
$arr['compliance_day'] = $projectInfo['finish_remain_day'];
//剩余服务时常
$arr['service_day'] = $projectInfo['remain_day'];
$arr['country'] = '{"也门": 4, "印度": 3, "埃及": 4, "巴西": 1, "约旦": 2, "美国": 3, "伊拉克": 4, "利比亚": 2, "墨西哥": 5, "摩洛哥": 8, "新加坡": 1, "突尼斯": 3, "巴勒斯坦": 2, "巴基斯坦": 1, "罗马尼亚": 1, "非洲地区": 2, "马来西亚": 5, "印度尼西亚": 2, "沙特阿拉伯": 3, "阿尔及利亚": 2}';
//查询当天数据是否存在 存在则更新
$info = $count->read(['date'=>$v['updated_date']]);
if($info === false){
$arr['created_at'] = $v['updated_date'].' 01:00:00';
$arr['updated_at'] = $v['updated_date'].' 01:00:00';
$count->insert($arr);
}else{
$count->edit($arr,['id'=>$info['id']]);
}
}
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :询盘数量
* @name :inquiry_num
* @author :lyh
* @method :post
* @time :2024/1/8 9:24
*/
public function inquiry_num($day){
$count = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->where('is_inquiry',1)->count();
return $count;
}
/**
* @name :(统计pv)pv_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function pv_num($day){
$pv = DB::connection('custom_mysql')->table('gl_customer_visit_item')->whereDate('updated_date', $day)->count();
return $pv;
}
/**
* @name :(统计ip)ip_num
* @author :lyh
* @method :post
* @time :2023/6/14 15:40
*/
public function ip_num($day){
$ip = DB::connection('custom_mysql')->table('gl_customer_visit')->whereDate('updated_date', $day)->count();
return $ip;
}
}
... ...
<?php
/**
* @remark :
* @name :UpgradeProjectCount.php
* @author :lyh
* @method :post
* @time :2024/1/8 9:03
*/
namespace App\Console\Commands\MonthlyCount;
use App\Helper\FormGlobalsoApi;
use App\Models\HomeCount\MonthCount;
use App\Models\Project\Project;
use App\Models\Visit\Visit;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Models\HomeCount\Count;
class UpgradeProjectCount extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'upgrade_month_count';
/**
* The console command description.
*
* @var string
*/
protected $description = '升级项目统计';
public function handle(){
ProjectServer::useProject(439);
$this->count();
DB::disconnect('custom_mysql');
}
/**
* @remark :日统计记录
* @name :count
* @author :lyh
* @method :post
* @time :2024/1/8 9:05
*/
public function count(){
$list = DB::connection('custom_mysql')->table('gl_customer_visit')
->select(DB::raw('DATE_FORMAT(updated_date, "%Y-%m") as month'))
->groupBy('month')->get()->toArray();
foreach ($list as $k=>$v){
$v = (array)$v;
$monthCountModel = new MonthCount();
$info = $monthCountModel->read(['month'=>$v['month']]);
// 获取当月开始时间
$start = date('Y-m-01', strtotime($v['month']));
// 获取当月结束时间
$end = date('Y-m-t', strtotime($v['month']));
$arr['project_id'] = 439;
$inquiry_list = (new FormGlobalsoApi())->getInquiryList('www.cnzyl.com','',1,100000000);
//总数
$arr['total'] = $inquiry_list['data']['total'] ?? 0;
$arr['month'] = $v['month'];
$arr['country'] = '{"\u5c3c\u65e5\u5229\u4e9a":1,"\u5370\u5ea6\u5c3c\u897f\u4e9a":1,"\u4f0a\u6717":1}';
$arr = $this->pv_ip($arr,$start,$end);
$arr = $this->sourceCount($arr,$start,$end);
if($info === false){
$selectedDate = $start;
$firstDayOfNextMonth = date('Y-m-01 01:00:00', strtotime("$selectedDate +1 month"));
$arr['created_at'] = $firstDayOfNextMonth;
$arr['updated_at'] = $firstDayOfNextMonth;
$monthCountModel->insert($arr);
}else{
$monthCountModel->edit($arr,['id'=>$info['id']]);
}
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :本月询盘总量
* @name :month_total
* @author :lyh
* @method :post
* @time :2024/1/8 11:02
*/
public function pv_ip(&$arr,$start,$end){
$pv_ip = DB::table('gl_count')
->where(['project_id'=>439])
->where('date','>=',$start.' 00:00:00')
->where('date','<=',$end.' 23:59:59')
->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'),DB::raw('SUM(inquiry_num) as inquiry_num'))
->first();
$arr['pv'] = $pv_ip->pv_num;
$arr['ip'] = $pv_ip->ip_num;
$arr['month_total'] = $pv_ip->inquiry_num;
if($arr['ip'] != 0){
$arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 10,2);
}
return $arr;
}
/**
* @remark :来源访问前8
* @name :sourceCount
* @author :lyh
* @method :post
* @time :2023/6/30 16:14
*/
public function sourceCount(&$arr,$startTime,$endTime){
//访问来源前10
$source = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('referrer_url', DB::raw('COUNT(*) as count'))
->groupBy('referrer_url')
->whereBetween('updated_date', [$startTime,$endTime])
->orderByDesc('count')->limit(10)->get()->toArray();
$arr['source'] = json_encode($source);
//访问国家前15
$source_country = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
->groupBy('country')
->whereBetween('updated_date', [$startTime,$endTime])
->orderBy('ip','desc')->limit(15)->get()->toArray();
$arr['source_country'] = json_encode($source_country);
//受访界面前15
$referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('url',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('url')
->limit(15)->get()->toArray();
$arr['referrer_url'] = json_encode($referrer_url);
//访问端口
$referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('device_port',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('device_port')
->limit(15)->get()->toArray();
$arr['referrer_port'] = json_encode($referrer_port);
return $arr;
}
}
... ...
... ... @@ -51,14 +51,15 @@ class UpdateRoute extends Command
*/
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['id'=>290]);
$list = $projectModel->list(['id'=>51]);
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
// $this->getProduct();
$this->setProductKeyword();
// $this->setProductKeyword();
// $this->getRouteMap();
// $this->getProductCategory();
$this->delRouteMap();
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
... ... @@ -225,4 +226,11 @@ class UpdateRoute extends Command
return true;
}
public function delRouteMap(){
$productKeywordModel = new Keyword();
$list = $productKeywordModel->list();
foreach ($list as $k=>$v){
RouteMap::setRoute($v['route'],'product_keyword',$v['id'],51);
}
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace App\Helper;
use App\Models\Project\Project;
use App\Utils\HttpUtils;
use GuzzleHttp\Exception\GuzzleException;
... ... @@ -51,6 +52,8 @@ class FormGlobalsoApi
*/
public function getInquiryList($domain, $search = '', $page = 1, $page_size = 20)
{
$project = Project::getProjectByDomain($domain);
$is_upgrade = $project['is_upgrade'] ??0;
$api_url = $this->url . '/api/external-interface/6a1bd159b1fd60af';
$params = [
... ... @@ -58,7 +61,7 @@ class FormGlobalsoApi
'domain' => $domain,
'limit' => $page_size,
'page' => $page,
'source' => '1,3' //来源类型 新项目用1,3
'source' => $is_upgrade ? '1,2,3,4' : '1,3' //来源类型 新项目用1,3
];
if($search){
$params['name'] = $search;
... ...
... ... @@ -114,7 +114,7 @@ class KeywordController extends BaseController
'title.max' => '批量操作不能超过1000条数据'
]);
$logic->batchAdd();
$this->response('success');
$this->response('路由生成中,请稍后刷新查看');
}
/**
... ...
... ... @@ -154,7 +154,6 @@ class KeywordLogic extends BaseLogic
$param['title'] = $v;
$id = $this->model->insertGetId($param);
$route = RouteMap::setRoute($route_array[$k], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
// $this->curlDelRoute(['new_route'=>$route]);
$this->model->edit(['route'=>$route],['id'=>$id]);
}
}
... ...
... ... @@ -12,7 +12,7 @@ class NoticeLog extends Model
const TYPE_PROJECT = 'project';
const TYPE_RANK_DATA = 'rank_data';
const TYPE_INIT_PROJECT = 'init_project';
const TYPE_INIT_KEYWORD = 'init_keyword';
const STATUS_PENDING = 0;
const STATUS_SUCCESS = 1;
const STATUS_FAIL = 2;
... ...
... ... @@ -284,24 +284,15 @@ class Project extends Base
*/
public static function getProjectByDomain($domain)
{
$cache_key = 'project_' . $domain;
$data = Cache::get($cache_key);
if (!$data) {
$domain = parse_url($domain);
$domain = $domain['host'] ?? $domain;
//是否测试域名
$project_id = DeployBuild::where('test_domain', $domain)->value('project_id');
//是否正式域名
if (!$project_id) {
$project_id = DeployOptimize::where('domain', $domain)->value('project_id');
$project_id = \App\Models\Domain\DomainInfo::where('domain', $domain)->value('project_id');
}
if (!$project_id) {
return [];
}
$data = self::find($project_id);
if ($data) {
Cache::put($cache_key, $data);
}
}
return $data;
return self::find($project_id ?: 0);
}
/**
... ...