RenewLogic.php
5.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
<?php
/**
* @remark :
* @name :RenewLogic.php
* @author :lyh
* @method :post
* @time :2023/8/11 17:29
*/
namespace App\Http\Logic\Aside\Project;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Project\DeployBuild;
use App\Models\Project\Project;
use App\Models\Project\ProjectRenew;
use App\Models\Project\RenewLog;
use Illuminate\Support\Facades\DB;
class RenewLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new ProjectRenew();
}
/**
* @remark :续费单记录列表
* @name :renewLog
* @author :lyh
* @method :post
* @time :2023/8/11 17:30
*/
public function renewListsLog($map,$page,$row,$order,$field = ['*']){
$lists = $this->model->lists($map,$page,$row,$order,$field);
if(!empty($lists['list'])){
$projectModel = new Project();
foreach ($lists['list'] as $k => $v){
$v['plan'] = Project::planMap()[$v['plan']];
$v['project_name'] = $projectModel->getProjectName($v['project_id']);
$lists['list'][$k] = $v;
}
}
return $this->success($lists);
}
/**
* @remark :根据主键获取续费单详情
* @name :renewRead
* @author :lyh
* @method :post
* @time :2023/8/14 9:12
*/
public function renewRead(){
$info = $this->model->read(['id'=>$this->param['id']]);
if($info === false){
$this->fail('当前数据不存在或者被删除');
}
return $this->success($info);
}
/**
* @remark :关联续费单
* @name :editProjectRenew
* @author :lyh
* @method :post
* @time :2023/9/19 10:21
*/
public function editProjectRenew(){
if($this->param['renew_id'] != 0){
//获取续费单详情
$info = $this->model->read(['id'=>$this->param['renew_id']]);
if($info === false){
$this->fail('当前续费单不存在');
}
if($info['project_id'] != 0){
$this->fail('当前续费单已关联项目,请重新选择');
}
}
DB::beginTransaction();
try {
$this->model->edit(['project_id'=>$this->param['id'],'operator_id'=>$this->manager['id']],['id'=>$this->param['renew_id']]);
$param = $this->param;
$param['api_no'] = $info['api_no'] ?? 0;
$this->saveLog($param);
$this->updateProject($this->param['id'],$this->param['type']);
$this->updateProjectBuild($this->param['id'],$this->param['service_duration'],$this->param['plan']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
/**
* @remark :编辑续费单状态
* @name :editStatus
* @author :lyh
* @method :post
* @time :2023/9/19 15:50
*/
public function editStatus(){
$rs = $this->model->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
/**
* @remark :关联续费单生成一条日志
* @name :saveLog
* @author :lyh
* @method :post
* @time :2023/9/27 16:29
*/
public function saveLog($param){
$data = [
'renew_id'=>$param['renew_id'],
'service_duration'=>$param['service_duration'],
'plan'=>$param['plan'],
'old_plan'=>$param['old_plan'],
'type'=>$param['type'],
'old_type'=>$param['old_type'],
'amount'=>$param['amount'],
'api_no'=>$param['api_no'],
'project_id'=>$param['id'],
'operator_id'=>$this->manager['id'],
'remark'=>$param['remark'] ?? ''
];
$renewLogModel = new RenewLog();
return $renewLogModel->add($data);
}
/**
* @remark :更新项目部署信息
* @name :updateProjectBuild
* @author :lyh
* @method :post
* @time :2023/9/27 16:32
*/
public function updateProjectBuild($id,$service_duration,$plan){
$deployBuild = new DeployBuild();
return $deployBuild->edit(
[
'service_duration'=>DB::raw('service_duration + ' . $service_duration),
'plan'=>$plan
],
[
'project_id'=>$id
]);
}
/**
* @remark :更新项目
* @name :updateProject
* @author :lyh
* @method :post
* @time :2023/9/27 16:35
*/
public function updateProject($id,$type){
$project = new Project();
return $project->edit([
'extend_type'=>0,
'type'=>$type,
'site_status'=>0
],[
'id'=>$id
]);
}
}