ProjectLogic.php
11.8 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
<?php
namespace App\Http\Logic\Aside\Project;
use App\Helper\Arr;
use App\Helper\FormGlobalsoApi;
use App\Http\Logic\Aside\BaseLogic;
use App\Http\Logic\Aside\Manage\ManageLogic;
use App\Models\Blog\Blog;
use App\Models\Channel\Channel;
use App\Models\Channel\User;
use App\Models\Channel\Zone;
use App\Models\Devops\ServerConfig;
use App\Models\Inquiry\InquirySet;
use App\Models\Manage\Manage;
use App\Models\News\News;
use App\Models\Product\Product;
use App\Models\Project\DeployBuild;
use App\Models\Project\DeployOptimize;
use App\Models\Project\Payment;
use App\Models\Project\Project;
use App\Models\Task\Task;
use App\Utils\EncryptUtils;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
/**
* Class ProjectLogic
* @package App\Http\Logic\Aside\Project
* @author zbj
* @date 2023/4/26
*/
class ProjectLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Project();
}
public function getList(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20)
{
parent::setWith(['payment', 'deploy_build', 'deploy_optimize','online_check']);
$list = parent::getList($map, $sort, ['id', 'title', 'channel', 'type', 'created_at'], $limit);
foreach ($list['list'] as &$item){
$item = [
'id' => $item['id'],
'title' => $item['title'],
'channel' => Channel::getChannelText($item['channel']['user_id'] ?? 0),
'key' => $item['deploy_build']['keyword_num'] ?? 0,
'day' => $item['deploy_build']['service_duration'] ?? 0,
'amount' => $item['payment']['amount'] ?? 0,
'build_leader' => (new ManageLogic)->getCacheName($item['deploy_build']['leader_mid'] ?? 0), //组长
'build_manager' => (new ManageLogic)->getCacheName($item['deploy_build']['manager_mid'] ?? 0), //项目经理
'build_designer' => (new ManageLogic)->getCacheName($item['deploy_build']['designer_mid'] ?? 0), //设计师
'build_tech' => (new ManageLogic)->getCacheName($item['deploy_build']['tech_mid'] ?? 0), //技术助理
'optimize_manager' => (new ManageLogic)->getCacheName($item['deploy_optimize']['manager_mid'] ?? 0), //优化服务经理
'optimize_optimist' => (new ManageLogic)->getCacheName($item['deploy_optimize']['optimist_mid'] ?? 0), //优化师
'optimize_assist' => (new ManageLogic)->getCacheName($item['deploy_optimize']['assist_mid'] ?? 0), //优化助理
'optimize_tech' => (new ManageLogic)->getCacheName($item['deploy_optimize']['tech_mid'] ?? 0), //售后技术
'type' => $item['type'],
'test_domain' => $item['deploy_build']['test_domain'] ?? 0,
'plan' => $item['deploy_build']['plan'] ?? 0,
'domain' => $item['deploy_optimize']['domain'] ?? 0,
'created_at' => date('Y年m月d日', strtotime($item['created_at'])),
'autologin_code' => $this->getAutoLoginCode($item['id']),
'product_num' => Product::getNumByProjectId($item['id']),
'keyword_num' => $item['deploy_build']['keyword_num'] ?? 0,
'article_num' => Blog::getNumByProjectId($item['id']) + News::getNumByProjectId($item['id']),
'task_finish_num' => Task::getNumByProjectId($item['id'], Task::STATUS_DOWN),
'task_pending_num' => Task::getNumByProjectId($item['id'], [Task::STATUS_DONGING, Task::STATUS_WAIT]),
'optimist_status'=>$item['online_check']['optimist_status'] ?? 0,
'qa_status'=>$item['online_check']['qa_status'] ?? 0,
];
}
return $list;
}
/**
* @remark :自动登录加密
* @name :getAutoLoginCode
* @author :lyh
* @method :post
* @time :2023/8/7 9:47
*/
public function getAutoLoginCode($project_id){
$encrypt = new EncryptUtils();
return $encrypt->authcode(json_encode(['project_id' => $project_id]), 'ENCODE', 'autologin', 3600);
// $param = http_build_query(['code' => $code]);
// return env('B_URL') . '/autologin?' . $param;
}
public function getInfo($id)
{
parent::setWith(['payment', 'deploy_build', 'deploy_optimize', 'online_check']); //删除缓存要添加带with的cache_key
return parent::getInfo($id);
}
/**
* @remark :获取当前数据详情
* @name :getProjectInfo
* @author :lyh
* @method :post
* @time :2023/7/28 17:11
*/
public function getProjectInfo($id){
$info = $this->model->with('payment')->with('deploy_build')
->with('deploy_optimize')->with('online_check')->where(['id'=>$id])->first();
if(isset($info['online_check']['created_manage_id']) && !empty($info['online_check']['created_manage_id'])){
$info['online_check']['name'] = (new ManageLogic)->getCacheName($info['online_check']['created_manage_id']);
}
if(isset($info['serve_id']) && !empty($info['serve_id'])){
$info['serve_id_name'] = (new ServerConfig())->read(['id'=>$info['serve_id']])['title'];
}
if(isset($info['mysql_id']) && !empty($info['mysql_id'])){
$info['mysql_id_name'] = (new ServerConfig())->read(['id'=>$info['mysql_id']])['title'];
}
if($info['extend_type'] != 0){
$info['type'] = $info['extend_type'];
}
return $this->success($info);
}
public function save($param){
if(!empty($param['deploy_optimize']['domain'])){
$param['deploy_optimize']['domain'] = checkDomain($param['deploy_optimize']['domain']);
if(!$param['deploy_optimize']['domain']){
$this->fail('正式域名格式不正确');
}
}
DB::beginTransaction();
try {
if(!empty($param['payment']['amount'])) unset($param['payment']['amount']);
if(!empty($param['deploy_build']['test_domain'])) unset($param['deploy_build']['test_domain']);
if(!empty($param['deploy_build']['plan'])) unset($param['deploy_build']['plan']);
if(!empty($param['deploy_optimize']['api_no'])) unset($param['deploy_optimize']['api_no']);
if($param['type'] == 6){
$param['extend_type'] == 6;
unset($param['type']);
}
$res = parent::save($param);
$param['id'] = $res['id'];
$this->savePayment($param);
$this->saveDeployBuild($param);
$this->saveDeployOptimize($param);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
errorLog('项目保存失败', $param, $e);
$this->fail('保存失败');
}
return $this->success();
}
/**
* 保存付款续费
* @author zbj
* @date 2023/4/26
*/
protected function savePayment($param){
if(empty($param['payment'])){
return true;
}
$data = $param['payment'];
$data['project_id'] = $param['id'];
$data['id'] = Payment::where('project_id', $param['id'])->value('id');
// Arr::forget($data, ['amount']);
return (new PaymentLogic)->save($data);
}
/**
* 保存建站部署
* @author zbj
* @date 2023/4/26
*/
protected function saveDeployBuild($param){
if(empty($param['deploy_build'])){
return true;
}
$data = $param['deploy_build'];
$data['project_id'] = $param['id'];
$data['id'] = DeployBuild::where('project_id', $param['id'])->value('id');
// Arr::forget($data, ['test_domain', 'plan']);
return (new DeployBuildLogic)->save($data);
}
/**
* 保存优化部署
* @author zbj
* @date 2023/4/26
*/
protected function saveDeployOptimize($param){
if(empty($param['deploy_optimize'])){
return true;
}
$data = $param['deploy_optimize'];
$data['project_id'] = $param['id'];
$data['id'] = DeployOptimize::where('project_id', $param['id'])->value('id');
// Arr::forget($data, ['api_no']);
return (new DeployOptimizeLogic)->save($data);
}
public function clearCache($id)
{
parent::clearCache($id);
parent::setWith(['payment', 'deploy_build', 'deploy_optimize', 'online_check']);
parent::clearCache($id);
}
/**
* 保存询盘通知设置
* @author zbj
* @date 2023/5/17
*/
public function saveInquirySet($param)
{
$project = $this->getCacheInfo($param['project_id']);
//同步到接口
$domain = parse_url($project['deploy_optimize']['domain'])['host'];
$emails = Arr::arrToSet($param['emails']??'', 'trim');
$phones = Arr::arrToSet($param['phones']??'', 'trim');
$form_globalso_api = new FormGlobalsoApi();
$res = $form_globalso_api->setInquiry($domain, $emails, $phones);
if (!$res) {
$this->fail('保存失败');
}
if ($res['status'] != 200) {
$this->fail($res['message'] ?? '保存失败');
}
//保存
$set = InquirySet::where('project_id', $param['project_id'])->first();
if (!$set) {
$set = new InquirySet();
}
$set->project_id = $param['project_id'];
$set->emails = $emails;
$set->phones = $phones;
$set->save();
return $this->success();
}
public function dataSource(){
$data = [];
$data['level'] = $this->model::levelMap();
$data['type'] = $this->model::typeMap();
$data['special'] = $this->model::specialMap();
$data['plan'] = $this->model::planMap();
return $data;
}
public function channelSource($param){
switch ($param['type']){
case 1:
return Zone::pluck('title', 'id')->toArray();
case 2:
return Channel::where('zone_id', $param['zone_id']??0)->pluck('alias', 'id')->toArray();
case 3:
return User::where('channel_id', $param['channel_id']??0)->pluck('name', 'id')->toArray();
}
return [];
}
public function sync($param){
$num = Cache::get('project_' . date('Ymd'), 1);
$title = date('Ymd') . '-' . $num . '-' . $param['company_name'];
if($param['type'] == 4){
$title .= '【推广续费】';
}
$data = [
'title' => $title,
'company' => $param['company_name'],
'lead_name' => $param['principal_name'],
'mobile' => $param['principal_mobile'],
'qq' => $param['customer_qq'],
'channel' => Channel::getProjectChannel($param['company_id'], $param['username_sales']),
'requirement' => $param['remark'],
'cooperate_date' => date('Y-m-d', $param['create_time']),
'deploy_build' => [
'service_duration' => $param['id'],
'plan' => [$param['plan_marketing']]
],
'deploy_optimize' => [
'api_no' => $param['id']
],
'payment' => [
'amount' => $param['plan_price'],
'contract' => $param['files'],
'bill' => $param['images'],
],
];
DB::beginTransaction();
try {
$res = parent::save($data);
$data['id'] = $res['id'];
$this->savePayment($data);
$this->saveDeployBuild($data);
$this->saveDeployOptimize($data);
DB::commit();
Cache::put('project_' . date('Ymd'), $num + 1, 24 * 60 * 60);
}catch (\Exception $e){
DB::rollBack();
errorLog('项目同步失败', $data, $e);
$this->fail('同步失败');
}
}
}