DownloadProject.php
6.9 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
<?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\Visit\Visit;
use App\Models\Visit\VisitItem;
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(){
echo date('Y-m-d H:i:s') . 'start' . PHP_EOL;
ProjectServer::useProject(535);
$this->model = new Visit();
$data = $this->importVisit();
dd($data);
DB::disconnect('custom_mysql');
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
return true;
}
/**
* @remark :导出明细
* @name :importVisit
* @author :lyh
* @method :post
* @time :2025/4/8 11:34
*/
public function importVisit()
{
$lists = $this->model->list();
if(!empty($lists) && !empty($lists['list'])){
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 $this->success($lists);
}
/**
* @remark :导出访问明细
* @name :exportData
* @author :lyh
* @method :post
* @time :2025/4/8 11:32
*/
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;
// }
}