DownloadProject.php
16.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
<?php
/**
* @remark :
* @name :CountProject.php
* @author :lyh
* @method :post
* @time :2024/9/26 14:19
*/
namespace App\Console\Commands\LyhTest;
use App\Helper\Common;
use App\Models\Com\V6WeeklyReport;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Product;
use App\Models\ProjectAssociation\ProjectAssociation;
use App\Models\RouteMap\RouteMap;
use App\Models\Workchat\MessagePush;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class DownloadProject extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'downloads_products';
/**
* The console command description.
*
* @var string
*/
protected $description = '导出项目数据';
public function handle(){
$v6WeekModel = new V6WeeklyReport();
$lists = $v6WeekModel->list([],'id',['*'],'desc',100);
echo date('Y-m-d H:i:s') . 'start' . PHP_EOL;
foreach ($lists as $data){
$this->workChatMessage($data,$data['project_id']);
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
return true;
}
public function downloadProduct()
{
$product = new Product();
// $filed = ['id', 'project_id', 'title' ,'thumb' , 'route' ,'intro','content',
// 'category_id', 'status','seo_mate'];
$filed = ['id','title'];
$this->order = 'sort';
$lists = $product->list(['status'=>1],'id',$filed);
if(!empty($lists)){
// $cate_data = $this->getCategoryList();//分类
foreach ($lists as $k => $v){
echo date('Y-m-d H:i:s') . '产品id:'.$v['id'] . PHP_EOL;
// $v['url'] = 'https://www.autsikinta.com/' . getRouteMap(RouteMap::SOURCE_PRODUCT,$v['id']);
// $v['category_id_text'] = $this->categoryName($v['id'],$cate_data);
// //ToDo::处理图片及文件
// if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
// $v['images'] = getImageUrl($v['thumb']['url']);
// }else{
// $v['images'] = '';
// }
$lists[$k] = $v;
}
}
return $lists;
}
public function categoryName($product_id,$data){
$cateRelatedModel = new CategoryRelated();
$category_id = $cateRelatedModel->where('product_id',$product_id)->pluck('cate_id')->toArray();
$category_name = '';
if(!empty($category_id) && !empty($data)){
foreach ($category_id as $v){
if(isset($data[$v])){
$category_name .= $data[$v].',';
}
}
$category_name = trim($category_name,',');
}
return $category_name;
}
/**
* @remark :获取所有分类
* @name :getCategoryList
* @author :lyh
* @method :post
* @time :2023/9/14 13:56
*/
public function getCategoryList(){
$data = Common::get_user_cache('product_category',1225);
if(empty($data)){
$categoryModel = new Category();
$data = [];
$cateList = $categoryModel->list(['project_id'=>1225],['id','title']);
if(!empty($cateList)){
foreach ($cateList as $value){
$data[$value['id']] = $value['title'];
}
}
Common::set_user_cache($data,'product_category',1225);
}
return $data;
}
// public function exportData($data){
// // 创建一个新的 Excel 电子表格实例
// $spreadsheet = new Spreadsheet();
// $sheet = $spreadsheet->getActiveSheet();
// // 添加表头
// $sheet->setCellValue('A1', '浏览时间');
// $sheet->setCellValue('B1', '访客来源');
// $sheet->setCellValue('C1', '访客入路页面');
// $sheet->setCellValue('D1', '终端');
// $sheet->setCellValue('E1', '国家ip');
// $sheet->setCellValue('F1', '深度访问页数');
// $rowCount = 2;
// foreach ($data as $v) {
// $sheet->setCellValue('A' . $rowCount, $v['created_at']);
// $sheet->setCellValue('B' . $rowCount, $v['referrer_url']);
// $sheet->setCellValue('C' . $rowCount, $v['url']);
// $sheet->setCellValue('D' . $rowCount, $v['device_text']);
// $sheet->setCellValue('E' . $rowCount, $v['ip']);
// $sheet->setCellValue('F' . $rowCount, $v['depth']);
// $rowCount++;
// }
// // 创建一个新的 Excel Writer 对象
// $writer = new Xlsx($spreadsheet);
// $filename = time().'.xlsx';
// // 设置导出文件的保存路径和文件名
// $filePath = public_path('upload/excel/'.$filename);
// // 导出 Excel 文件
// $writer->save($filePath);
// echo date('Y-m-d H:i:s') . 'file_link:'.url('upload/excel/'.$filename) . PHP_EOL;
// // 返回导出文件的响应
// return ['file_link'=>url('upload/excel/'.$filename)];
// }
public function exportData($data){
// 创建一个新的 Excel 电子表格实例
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 添加表头
$sheet->setCellValue('A1', '产品名称');
// $sheet->setCellValue('B1', '产品短描述');
// $sheet->setCellValue('C1', '产品内容');
// $sheet->setCellValue('D1', '产品路由');
// $sheet->setCellValue('E1', '产品分类');
// $sheet->setCellValue('F1', '产品状态');
// $sheet->setCellValue('G1', '产品主图');
// $sheet->setCellValue('H1', '产品seo_title');
// $sheet->setCellValue('I1', '产品seo_keyword');
// $sheet->setCellValue('J1', '产品seo_title');
$rowCount = 2;
foreach ($data as $v) {
$sheet->setCellValue('A' . $rowCount, $v['title']);
// $sheet->setCellValue('B' . $rowCount, $v['intro']);
// $sheet->setCellValue('C' . $rowCount, $v['content']);
// $sheet->setCellValue('D' . $rowCount, $v['url']);
// $sheet->setCellValue('E' . $rowCount, $v['category_id_text']);
// $sheet->setCellValue('F' . $rowCount, '发布中');
// $sheet->setCellValue('G' . $rowCount, $v['images']);
// $sheet->setCellValue('H' . $rowCount, $v['seo_mate']['title']);
// $sheet->setCellValue('I' . $rowCount, $v['seo_mate']['keyword']);
// $sheet->setCellValue('J' . $rowCount, $v['seo_mate']['description']);
$rowCount++;
}
// 创建一个新的 Excel Writer 对象
$writer = new Xlsx($spreadsheet);
$filename = time().'.xlsx';
// 设置导出文件的保存路径和文件名
$filePath = public_path('upload/excel/'.$filename);
// 导出 Excel 文件
$writer->save($filePath);
echo date('Y-m-d H:i:s') . 'file_link:'.url('upload/excel/'.$filename) . PHP_EOL;
// 返回导出文件的响应
return ['file_link'=>url('upload/excel/'.$filename)];
}
// public function downloadItem($filed = ['id','depth','created_at','referrer_url','url','device_port','country','ip']){
// $visitModel = new Visit();
// $page = 1;
// $pageSize = 3000;
// $lists = $visitModel->lists(['updated_date'=>['between',['2025-02-01','2025-02-31']]],$page,$pageSize,'id',$filed);
// foreach ($lists as $v){
// $customer_visit_id[] = $v['id'];
// }
// $itemModel = new VisitItem();
// $itemList = $itemModel->list(['customer_visit_id'=>['in',$customer_visit_id]],['customer_visit_id','url']);
// foreach ($lists as $key => $value){
// $sub = [];
// foreach ($itemList as $sonValue){
// if($value['id'] == $sonValue['customer_visit_id']){
// $sub[] = $sonValue;
// }
// }
// $value['sub'] = $sub;
// $lists[$key] = $value;
// }
// return $lists;
// }
public function workChatMessage($data,$project_id){
$data['main_lang_id'] = 8;
$arr = [];
$content = '';
$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'],true);
arsort($data['inquiry_country']);
$data['inquiry_country'] = array_slice($data['inquiry_country'], 0, 4, true);
$country = '';
foreach ($data['inquiry_country'] as $k => $v){
$country .= $k.',';
};
$country = trim($country,',');
if(!empty($country)){
$content1 .= '询盘主要来源于'.$country.'等国家地区';
}
}
$content1 .= '如有高质量客户,请您密切关注与跟进;';
}
if(!empty($content1)){
$arr[] = $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($data['main_lang_id'] == 8){
$title = 'Yandex';
}else{
$title = '谷歌';
}
if(!empty($data['google_indexed_num'])){
$content2 .= $title.'收录量:'.$data['google_indexed_num'].'条,';
}
if(!empty($data['google_links_num'])){
//获取上一次的外链数
$latestRecord = V6WeeklyReport::where(['project_id'=>$project_id])->orderBy('id', 'desc')->first();
if(!empty($latestRecord)){
if($latestRecord['google_links_num'] != $data['google_links_num']){
$content2 .= '外链量:'.$data['google_links_num'].'条,';
}
}else{
$content2 .= '外链量:'.$data['google_links_num'].'条,';
}
}
if(!empty($data['keyword_home_num']) || !empty($data['keyword_three_num']) || !empty($data['keyword_five_num']) || !empty($data['keyword_ten_num'])){
$content2 .= $title.'搜索排名';
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 .= '全球搜建议用户持续分析、选择、添加企业、产品、服务等相关关键词进行优化和监控,以覆盖更多相关排名和流量;';
}
if(!empty($content2)){
$arr[] = $content2;
}
$content3 = '';
if(!empty($data['product_num']) || !empty($data['news_num']) || !empty($data['week_product_num']) || !empty($data['week_news_num'])){
if(!empty($data['product_num']) || !empty($data['news_num'])){
$content3 .= '项目截止目前';
if(!empty($data['product_num'])){
$content3 .= '发布产品:'.$data['product_num'].'条,';
}
if(!empty($data['news_num'])){
$content3 .= '发布新闻:'.$data['news_num'].'条。';
}
}
if(!empty($data['week_product_num']) || !empty($data['week_news_num'])){
$content3 .= '本周新增';
if(!empty($data['week_product_num'])){
$content3 .= '产品:'.$data['week_product_num'].'条,';
}
if(!empty($data['week_news_num'])){
$content3 .= '新闻:'.$data['week_news_num'].'条。';
}
}
$content3 .= '全球搜建议用户保持网站内容的持续更新与完善,可参考谷歌关于创建实用、可靠、以用户为中心的内容的相关建议:https://developers.google.com/search/docs/fundamentals/creating-helpful-content?hl=zh-cn;';
}
if(!empty($content3)){
$arr[] = $content3;
}
$content4 = '';
if(!empty($data['main_update_num'])){
$content4 .= '网站加载速度维护及主站页面更新'.$data['main_update_num'].'次。';
}
if(!empty($data['aggregation_update_num'])){
$content4 .= '聚合页主站页面更新'.$data['aggregation_update_num'].'次。';
}
if(!empty($data['aggregation_update_num'])){
$content4 .= '聚合页主站页面更新'.$data['aggregation_update_num'].'次。';
}
if(!empty($data['minor_update_num'])){
$content4 .= '小语种站页面更新'.$data['minor_update_num'].'次。';
}
if(!empty($data['aggregation_minor_update_num'])){
$content4 .= '聚合页小语种站页面'.$data['aggregation_minor_update_num'].'次。';
}
if(!empty($content4)){
$content4 = '本周主要优化工作包括:TDK、H标签、Img标签等优化设置排查与进一步完善,Sitemap更新与网页收录提交,外链新增与排查。'.$content4;
}
if(!empty($content4)){
$arr[] = $content4;
}
if(empty($arr)){
return true;
}
foreach ($arr as $key => $val){
$content .= ($key+1).','.$val.PHP_EOL;
}
$timestamp = strtotime('tomorrow 9:00 AM');
$tomorrowNineAM = date('Y-m-d H:i:s', $timestamp);
if(empty($content)){
return true;
}
$tips = 'Tips:'.PHP_EOL.'1、全球搜V6.0系统提供网页TDK、H标签、Img标签等用户自定义编辑接口且辅以AI创作工具,用户可进一步对相关优化设置进行精细化优化与调整;'.PHP_EOL.'2、全球搜V6.0系统提供小语种页面精准校对翻译功能,用户可进一步对已翻译小语种页面进行人工翻译校对;'.PHP_EOL.'3、全球搜V6.0系统支持绑定Facebook、LinkedIn、X(原Twitter)等社媒账号,可一键同步转发网站上发布的产品和新闻至社媒账号动态,建议用户用起来哦;'.PHP_EOL.'4、如用户有较丰富的企业、产品、服务相关视频素材,全球搜建议用户及时创建YouTube主页,并在YouTube和网站相关网页上同步发布视频;';
$param = [
'project_id'=>$project_id,
'friend_id'=>17667,
'type'=>MessagePush::TYPE_WEEK,
'content'=>"【全球搜V6.0周报】--项目id:$project_id".PHP_EOL.$content.PHP_EOL.$tips,
'ref_ids'=>'',
'send_time'=>$tomorrowNineAM,
'status'=>0,
];
//写入一条推送消息 自动消费
$messagePushModel = new MessagePush();
$messagePushModel->add($param);
echo date('Y-m-d H:i:s') . '数据:'. $content . PHP_EOL;
return true;
}
}