forked from kuafuRace/phprap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplyController.php
More file actions
executable file
·165 lines (116 loc) · 4.4 KB
/
Copy pathApplyController.php
File metadata and controls
executable file
·165 lines (116 loc) · 4.4 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
<?php
namespace app\controllers\home;
use Yii;
use yii\web\Response;
use app\models\Project;
use app\models\Apply;
use app\models\apply\CreateApply;
use app\models\apply\UpdateApply;
use app\models\member\CreateMember;
class ApplyController extends PublicController
{
public function actionIndex()
{
$params = Yii::$app->request->queryParams;
$params['check_status'] = Apply::CHECK_STATUS;
$params['order_by'] = 'id desc';
$model = Apply::findModel()->search($params);
return $this->display('index', ['apply' => $model]);
}
/**
* 添加申请
* @return string
*/
public function actionCreate($project_id)
{
$request = Yii::$app->request;
$model = CreateApply::findModel();
$project = Project::findModel(['encode_id' => $project_id]);
if($request->isPost) {
Yii::$app->response->format = Response::FORMAT_JSON;
$model->project_id = $project->id;
if ($model->store()) {
return ['status' => 'success', 'message' => '申请成功,请耐心等待项目创建人审核'];
}
return ['status' => 'error', 'message' => $model->getErrorMessage(), 'label' => $model->getErrorLabel()];
}
return $this->display('create', ['apply' => $model, 'project' => $project]);
}
/**
* 通过申请
* @return string
*/
public function actionPass($id)
{
$request = Yii::$app->request;
$model = UpdateApply::findModel($id);
if($request->isPost) {
Yii::$app->response->format = Response::FORMAT_JSON;
// 开启事务
$transaction = Yii::$app->db->beginTransaction();
if(!$model->load($request->post())) {
return ['status' => 'error', 'message' => '加载数据失败','model' => 'UpdateApply'];
}
$model->status = Apply::PASS_STATUS;
if(!$model->store()){
$transaction->rollBack();
return ['status' => 'error', 'message' => $model->getErrorMessage(), 'label' => $model->getErrorLabel()];
}
// 向项目成员表插入数据
$member = CreateMember::findModel();
$member->project_id = $model->project_id;
$member->user_id = $model->user_id;
$member->join_type = $member::INITIATIVE_JOIN_TYPE;
$member->project_rule = 'look';
$member->env_rule = 'look';
$member->module_rule = 'look';
$member->api_rule = 'look';
$member->member_rule = 'look';
if(!$member->store()){
$transaction->rollBack();
return ['status' => 'error', 'message' => $member->getErrorMessage(), 'label' => $member->getErrorLabel()];
}
// 事务提交
$transaction->commit();
return ['status' => 'success', 'message' => '操作成功'];
}
return $this->display('check', ['apply' => $model]);
}
/**
* 拒绝申请
* @return string
*/
public function actionRefuse($id)
{
$request = Yii::$app->request;
$model = UpdateApply::findModel($id);
if($request->isPost) {
Yii::$app->response->format = Response::FORMAT_JSON;
// 开启事务
$transaction = Yii::$app->db->beginTransaction();
if(!$model->load($request->post())) {
return ['status' => 'error', 'message' => '加载数据失败','model' => 'UpdateApply'];
}
$model->status = Apply::REFUSE_STATUS;
if(!$model->store()){
$transaction->rollBack();
return ['status' => 'error', 'message' => $model->getErrorMessage(), 'label' => $model->getErrorLabel()];
}
// 事务提交
$transaction->commit();
return ['status' => 'success', 'message' => '操作成功'];
}
return $this->display('check', ['apply' => $model]);
}
/**
* 获取申请数量
* @return array
* @throws \Exception
*/
public function actionNotify()
{
Yii::$app->response->format = Response::FORMAT_JSON;
$apply = Apply::findModel()->search(['check_status' => Apply::CHECK_STATUS]);
return ['count' => $apply->count];
}
}