BaseLogic.php
4.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
namespace App\Http\Logic\Bside;
use App\Enums\Common\Common;
use App\Exceptions\BsideGlobalException;
use App\Http\Logic\Logic;
use App\Models\Com\UpdateNotify;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteDelete;
use Illuminate\Support\Facades\Cache;
/**
* @notes: 逻辑层基类 控制器调用 统一返回 统一抛出异常
*/
class BaseLogic extends Logic
{
protected $requestAll;
protected $param;
protected $request;
protected $user;
protected $project;
protected $side = Common::B;
public function __construct()
{
$this->request = request();
$this->requestAll = $this->getParam();
$this->user = Cache::get(request()->header('token'));
if(!empty($this->user)){
$this->project = $this->getProjectInfo();
}
}
/**
* @remark :获取项目详情
* @name :getProjectInfo
* @author :lyh
* @method :post
* @time :2023/8/31 15:11
*/
public function getProjectInfo(){
$info = Cache::get('user-'.$this->user['project_id']);
if($info === false){
$projectModel = new Project();
$info = $projectModel->with('payment')->with('deploy_build')
->with('deploy_optimize')->with('online_check')->where(['id'=>$this->user['project_id']])->first();
if($info['extend_type'] != 0){
$info['type'] = $info['extend_type'];
}
Cache::add('user-'.$this->user['project_id'],$info);
}
return $this->success($info);
}
/**
* @remark :请求参数处理
* @name :getParam
* @author :lyh
* @method :post
* @time :2023/6/17 16:34
*/
public function getParam(){
$requestAll = $this->request->all();
foreach ($requestAll as $k => $v){
if(is_array($v)){
continue;
}else{
if(empty($v) && ($v == null)){
unset($requestAll[$k]);
}
}
}
return $this->success($requestAll);
}
/**
* 列表
* @param array $map
* @param array $sort
* @param array $columns
* @param int $limit
* @return array
* @author zbj
* @date 2023/4/13
*/
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
$map[] = ['project_id' => $this->user['project_id']];
return parent::getList($map, $sort, $columns, $limit);
}
/**
* @param $id
* @return mixed
* @author zbj
* @date 2023/4/15
*/
public function getCacheInfo($id)
{
$info = parent::getCacheInfo($id);
if ($info && $info['project_id'] != $this->user['project_id']) {
$info = null;
}
return $info;
}
/**
* 保存
* @param $param
* @return array
* @throws BsideGlobalException
* @author zbj
* @date 2023/4/13
*/
public function save($param)
{
$param['project_id'] = $this->user['project_id'];
return parent::save($param);
}
/**
* 批量删除
* @param $ids
* @param array $map
* @return array
* @author zbj
* @date 2023/4/13
*/
public function delete($ids, $map = [])
{
$map[] = ['project_id' => $this->user['project_id']];
return parent::delete($ids, $map);
}
/**
* @name :(通知更新)projectUrl
* @author :lyh
* @method :post
* @time :2023/6/6 14:09
*/
function updateNotify($data)
{
$updateNotifyModel = new UpdateNotify();
if($data['route'] != 'all'){
$info = $updateNotifyModel->read(['project_id'=>$data['project_id'],'route'=>$data['route'],'status'=>1]);
if($info === false){
$param = [
'project_id'=>$data['project_id'],
'type'=>$data['type'],
'route'=>$data['route'],
];
$updateNotifyModel->add($param);
}
//单页面直接通知更新
$url = $this->user['domain'].'api/delHtml/?project_id='.$this->user['project_id'].'&route='.$data['route'];
}else{
$url = $this->user['domain'].'api/webInfo/?type=clear_website';
}
curlGet($url);
return $this->success();
}
/**
* @remark :删除和编辑路由时生成一条记录
* @name :setRouteDeleteSave
* @author :lyh
* @method :post
* @time :2023/9/7 9:38
*/
public function setRouteDeleteSave($param){
$routeDeleteModel = new RouteDelete();
$data = [
'project_id'=>$this->user['project_id'],
'source'=>$param['source'],
'created_at'=>date('Y-m-d H:i:s'),
'route'=>$param['route'],
];
$routeDeleteModel->insert($data);
return $this->success();
}
}