WeekProject.php
9.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?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\ProjectAssociation\ProjectAssociation;
use App\Models\RankData\ExternalLinks;
use App\Models\RankData\RankData;
use App\Models\RankData\RankWeek;
use App\Models\Workchat\MessagePush;
use App\Services\ProjectServer;
use Carbon\Carbon;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
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");
// 格式化为日期时间字符串
$data['start_date'] = $startOfLastWeekFormatted = date('Y-m-d', $startOfLastWeek);
$data['end_date'] = $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;
$data['week_product_num'] = $productModel->counts(['status'=>1,'created_at'=>['between',[$startOfLastWeek,$endOfLastWeek]]]) ?? 0;
$newsModel = new News();
$data['news_num'] = $newsModel->counts(['status'=>1]) ?? 0;
$data['week_news_num'] = $newsModel->counts(['status'=>1,'created_at'=>['between',[$startOfLastWeek,$endOfLastWeek]]]) ?? 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;
}
/**
* @remark :推送消息
* @name :workChatMessage
* @author :lyh
* @method :post
* @time :2025/2/26 10:15
*/
public function workChatMessage($data,$project_id){
//项目是否有绑定群
$friend_id = ProjectAssociation::where('project_id', $project_id)
->where('status', ProjectAssociation::STATUS_NORMAL)
->where('binding_app', ProjectAssociation::ENTERPRISE_WECHAT)
->value('friend_id');
if(!$friend_id){
echo date('Y-m-d H:i:s') . '没有绑定企微群:'.$project_id . PHP_EOL;
return false;
}
$content1 = '';
if(!empty($data['inquiry_total'])){
$content1 .= '项目共计已收到询盘 '.$data['inquiry_total'].'条,';
if(!empty($data['week_inquiry_total'])){
$content1 .= '本周新收 '.$data['week_inquiry_total'].' 封询盘。';
}
if(!empty($data['inquiry_country'])){
$data['inquiry_country'] = json_decode($data['inquiry_country']);
arsort($data);
$data['inquiry_country'] = array_slice($data, 0, 4, true);
$country = '';
foreach ($data['inquiry_country'] as $k => $v){
$country .= $k.'、';
};
trim($country,'、');
$content1 = '询盘主要来源于'.$country.'等国家地区';
}
$content1 .= '如有高质量客户,请您密切关注与跟进;';
}
$content2 = '';
if(!empty($data['google_indexed_num']) || !empty($data['google_links_num']) || !empty($data['keyword_home_num']) || !empty($data['keyword_three_num']) || !empty($data['keyword_five_num']) || !empty($data['keyword_ten_num']) || !empty($data['daily_average_num'])){
$content2 .= '项目截止目前';
if(!empty($data['google_indexed_num'])){
$content2 .= '谷歌收录量:'.$data['google_indexed_num'].'条,';
}
if(!empty($data['google_links_num'])){
$content2 .= '外链量:'.$data['google_links_num'].'条,';
}
if(!empty($data['keyword_home_num'])){
$content2 .= '谷歌搜索排名首页关键词数量为:'.$data['keyword_home_num'].'个,';
}
if(!empty($data['keyword_three_num'])){
$content2 .= '前三页关键词数量为:'.$data['keyword_three_num'].'个,';
}
if(!empty($data['keyword_five_num'])){
$content2 .= '前五页关键词数量为:'.$data['keyword_five_num'].'个,';
}
if(!empty($data['keyword_ten_num'])){
$content2 .= '前十页关键词数量为:'.$data['keyword_ten_num'].'个,';
}
if(!empty($data['daily_average_num'])){
$content2 .= '本周日均访客量:'.$data['daily_average_num'].'+。';
}
$content2 .= '全球搜建议用户持续分析、选择、添加企业、产品、服务等相关关键词进行优化和监控,以覆盖更多相关排名和流量;';
}
$content3 = '';
if(!empty($data['product_num']) || !empty($data['news_num']) || !empty($data['week_product_num']) || !empty($data['week_news_num'])){
}
$param = [
'project_id'=>$project_id,
'friend_id'=>$friend_id,
'type'=>MessagePush::TYPE_WEEK,
'content'=>'',
];
//写入一条推送消息 自动消费
$messagePushModel = new MessagePush();
}
}