WeekProject.php
5.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
/**
* @remark :
* @name :WeekProject.php
* @author :lyh
* @method :post
* @time :2024/12/3 9:48
*/
namespace App\Console\Commands\ProjectWeeklyReport;
use App\Models\Blog\Blog;
use App\Models\Com\Notify;
use App\Models\Com\V6WeeklyReport;
use App\Models\HomeCount\Count;
use App\Models\News\News;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Models\RankData\ExternalLinks;
use App\Models\RankData\RankData;
use App\Models\RankData\RankWeek;
use App\Services\ProjectServer;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class WeekProject extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'week_project';
/**
* The console command description.
*
* @var string
*/
protected $description = 'V6.0周报';
/**
* @remark :
* @name :handle
* @author :lyh
* @method :post
* @time :2024/12/3 10:01
*/
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['delete_status'=>0,'type'=>['in',[1,2,3,4,6]]],'id',['id','title']);
foreach ($list as $k => $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
$this->weekData($v);
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end:' . PHP_EOL;
}
/**
* @remark :统计数据
* @name :weekData
* @author :lyh
* @method :post
* @time :2024/12/3 10:03
*/
public function weekData($value){
echo date('Y-m-d H:i:s') . '项目名称:'.$value['title'] . PHP_EOL;
$data = [
'project_id'=>$value['id'],
'title'=>$value['title'],
];
// 上一周的开始时间(周一 00:00:00)
$startOfLastWeek = strtotime("last week monday");
// 上一周的结束时间(周日 23:59:59)
$endOfLastWeek = strtotime("last week sunday 23:59:59");
// 格式化为日期时间字符串
$startOfLastWeekFormatted = date('Y-m-d', $startOfLastWeek);
$endOfLastWeekFormatted = date('Y-m-d', $endOfLastWeek);
$countModel = new Count();
$startOfLastWeekFormattedInfo = $countModel->read(['date'=>$startOfLastWeekFormatted,'project_id'=>$value['id']],['inquiry_num','country']);
$endOfLastWeekFormattedInfo = $countModel->read(['date'=>$endOfLastWeekFormatted,'project_id'=>$value['id']],['inquiry_num','country']);
$data['inquiry_total'] = $endOfLastWeekFormattedInfo['inquiry_num'] ?? 0;//询盘数量
$data['inquiry_country'] = $endOfLastWeekFormattedInfo['country'] ?? json_encode([]);
$data['week_inquiry_total'] = ($endOfLastWeekFormattedInfo['inquiry_num'] ?? 0) - ($startOfLastWeekFormattedInfo['inquiry_num'] ?? 0);
$rankDataModel = new RankData();
$rankInfo = $rankDataModel->read(['project_id'=>$value['id'],'lang'=>''],['first_num','first_page_num','first_three_pages_num','first_five_pages_num','first_ten_pages_num','indexed_pages_num']);
$data['google_indexed_num'] = $rankInfo['indexed_pages_num'] ?? 0;
$externalLinksModel = new ExternalLinks();
$linkInfo = $externalLinksModel->read(['project_id'=>$value['id']],['total']);
$data['google_links_num'] = $linkInfo['total'] ?? 0;
$data['keyword_home_num'] = $rankInfo['first_page_num'] ?? 0;
$data['keyword_three_num'] = $rankInfo['first_three_pages_num'] ?? 0;
$data['keyword_five_num'] = $rankInfo['first_five_pages_num'] ?? 0;
$data['keyword_ten_num'] = $rankInfo['first_ten_pages_num'] ?? 0;
$productModel = new Product();
$data['product_num'] = $productModel->counts(['status'=>1]) ?? 0;
$newsModel = new News();
$data['news_num'] = $newsModel->counts(['status'=>1]) ?? 0;
$blogModel = new Blog();
$data['blog_num'] = $blogModel->counts(['status'=>1]) ?? 0;
$notifyModel = new Notify();
$data['main_update_num'] = $notifyModel->counts(['type'=>1,'route'=>1,'project_id'=>$value['id']]) ?? 0;
$data['aggregation_update_num'] = $notifyModel->counts(['type'=>1,'route'=>4,'project_id'=>$value['id']]) ?? 0;
$data['minor_update_num'] = $notifyModel->counts(['type'=>2,'route'=>1,'project_id'=>$value['id']]) ?? 0;
$data['aggregation_minor_update_num'] = $notifyModel->counts(['type'=>2,'route'=>4,'project_id'=>$value['id']]) ?? 0;
//日均访问量
$data['daily_average_num'] = 0;
$pv_num_count = $countModel->where('project_id',$value['id'])->whereBetween('date', [$startOfLastWeekFormatted,$endOfLastWeekFormatted])->sum('pv_num');
echo date('Y-m-d H:i:s') . 'pv总量:'.$pv_num_count . PHP_EOL;
if($pv_num_count != 0){
$data['daily_average_num'] = round($pv_num_count / 7,2);
}
$v6WeeklyReportModel = new V6WeeklyReport();
$v6WeeklyReportModel->add($data);
return true;
}
}