DomainInfoController.php
5.3 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
<?php
namespace App\Http\Controllers\Aside\Domain;
use App\Enums\Common\Code;
use App\Exceptions\AsideGlobalException;
use App\Exceptions\BsideGlobalException;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\Domain\DomainInfoLogic;
use App\Http\Requests\Aside\Domain\DomainInfoRequest;
use App\Models\Aside\Domain\DomainInfo;
use App\Models\Aside\Domain\DomainInfoLog;
use Illuminate\Http\JsonResponse;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
/**
* Class DomainInfoController
* @package App\Http\Controllers\Aside 域名管理
*/
class DomainInfoController extends BaseController
{
/**
* 域名列表
* @param int $deleted
* @return JsonResponse
*/
public function lists()
{
$domainModel = new DomainInfo();
if(isset($this->map['domain']) && !empty($this->map['domain'])){
$this->map['domain'] = ['like','%'.$this->map['domain'],'%'];
}
$lists = $domainModel->lists($this->map,$this->page,$this->row,$this->order);
return $this->response('success', Code::SUCCESS, $lists);
}
/**
* @remark :保存域名
* @name :save
* @author :lyh
* @method :post
* @time :2023/8/1 15:36
*/
public function save(DomainInfoLogic $domainInfoLogic)
{
$this->verifyParam();
$domainInfoLogic->saveDomain();
$this->response('success');
}
/**
* @remark :验证字段
* @name :verifyParam
* @author :lyh
* @method :post
* @time :2023/8/1 15:32
*/
public function verifyParam(){
$this->request->validate([
'domain'=>'required',
'remark'=>'required',
'belong_to'=>'required',
'project_id'=>'required'
],[
'domain.required' => 'domain不能为空',
'remark.required' => '备注不能为空',
'belong_to.required' => '域名不能为空',
'project_id.required' => '所属项目不能为空'
]);
return true;
}
/**
* @remark :获取项目列表
* @name :getProject
* @author :lyh
* @method :post
* @time :2023/8/1 16:14
*/
public function getProject(DomainInfoLogic $domainInfoLogic){
$lists = $domainInfoLogic->getProjectList($this->map);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :获取详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/8/1 16:14
*/
public function info(DomainInfoLogic $domainInfoLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'id不能为空',
]);
$info = $domainInfoLogic->infoDomain();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :修改状态
* @name :status
* @author :lyh
* @method :post
* @time :2023/8/1 15:47
*/
public function status(DomainInfoLogic $domainInfoLogic){
$this->request->validate([
'id'=>'required',
'status'=>'required'
],[
'id.required' => 'id不能为空',
'status.required' => 'id不能为空'
]);
$domainInfoLogic->editDomainStatus();
$this->response('success');
}
/**
* @remark :删除域名
* @name :del
* @author :lyh
* @method :post
* @time :2023/8/1 15:38
*/
public function del(DomainInfoLogic $domainInfoLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'id不能为空',
]);
$domainInfoLogic->delDomain();
$this->response('success');
}
/**
* @remark :导出数据
* @name :exportData
* @author :lyh
* @method :post
* @time :2023/8/1 16:45
*/
public function exportData(){
$domainModel = new DomainInfo();
$lists = $domainModel->list($this->map);
// 创建一个新的 Excel 电子表格实例
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
// 添加表头
$sheet->setCellValue('A1', 'ID');
$sheet->setCellValue('B1', 'Name');
$sheet->setCellValue('C1', 'domain');
$sheet->setCellValue('D1', 'belong_to');
$sheet->setCellValue('E1', 'status');
$rowCount = 2;
foreach ($lists as $v) {
$sheet->setCellValue('A' . $rowCount, $v['id']);
$sheet->setCellValue('B' . $rowCount, $v['domain']);
$sheet->setCellValue('C' . $rowCount, $v['domain']);
$sheet->setCellValue('D' . $rowCount, $v['belong_to']);
$sheet->setCellValue('E' . $rowCount, $v['status']);
$rowCount++;
}
// 创建一个新的 Excel Writer 对象
$writer = new Xlsx($spreadsheet);
// 设置导出文件的保存路径和文件名
$filePath = public_path('upload/excel/'.time().'.xlsx');;
// 导出 Excel 文件
$writer->save($filePath);
// 返回导出文件的响应
return response()->download($filePath)->deleteFileAfterSend(true);
}
}