EditController.class.php
7.99 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
<?php
/**
* 【调研中心-后台】10_编辑调研
* EditController.class.php
* CreateBy:dj
* Date:2017-03-06
*/
namespace Apicp\Controller\Questionnaire;
use Common\Common\AttachOperation;
use Common\Common\StudyMap;
use Common\Common\TaskCenter;
use Common\Common\Train;
use Common\Service\BaseinfoService;
use Common\Service\QuestionService;
use Common\Service\RightService;
class EditController extends \Apicp\Controller\AbstractController
{
/** @var BaseinfoService */
protected $_baseinfo_s;
/** @var QuestionService */
protected $_question_s;
/** @var RightService */
protected $_right_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 调研基本信息表
$this->_baseinfo_s = new BaseinfoService();
// 调研问题信息表
$this->_question_s = new QuestionService();
// 可见范围信息表
$this->_right_s = new RightService();
return true;
}
/**
* @return bool
* @throws \VcySDK\Exception
*/
public function Index_post()
{
// 获取参数
$data = I('post.');
$qu_id = rintval($data['qu_id']);
if (empty($qu_id)) {
E('_EMPTY_BASEINFO_ID');
}
// 【对接任务】0907新增任务中心使用判断
$taskCenter = &TaskCenter::instance();
// 查询调研是否被任务模块使用
$used_ids = $taskCenter->checkAppDataUsed($qu_id);
if (!empty($used_ids)) {
E('_ERR_QUESTIONNAIRE_USED_TASK_EDIT');
}
// 查询调研是否被线下培训模块使用
$train = &Train::instance();
$train_used_ids = $train->checkUsing($qu_id);
if (!empty($train_used_ids)) {
E('_ERR_QUESTIONNAIRE_USED_TRAIN_EDIT');
}
// 查询是否被学习地图模块使用
if (StudyMap::checkAppDataUsed([$qu_id])) {
E('_ERR_QUESTIONNAIRE_USED_MAP_EDIT');
}
// 调研类型:常规类型、任务类、线下培训、学习地图
$qu_types = [
BaseinfoService::ROUTINE_TYPE,
BaseinfoService::TASK_TYPE,
BaseinfoService::OFF_LINE_TYPE,
BaseinfoService::OTHER_TYPE
];
if (!in_array($data['qu_type'], $qu_types)) {
E('_EMPTY_QU_TYPE');
}
// 非常规类型:任务类型或者线下培训类型
if (BaseinfoService::ROUTINE_TYPE != $data['qu_type']) {
// 跳转编辑新类型
$this->new_type($qu_id, $data);
return true;
}
$base_data = $this->_baseinfo_s->checkData($data);
// 验证并组装基本信息
if (!$base_data) {
return false;
}
// 验证问题信息
if (!$this->_question_s->checkData($data['q_list'])) {
return false;
}
// 获取应参与总人数
$involved_total = $this->_right_s->user_count($data);
if (empty($involved_total)) {
E('_ERR_RIGHT_SAVE_FALI');
}
// 全部人数
$base_data['involved_total'] = $involved_total;
// 已填写人数
$base_data['involved_num'] = 0;
try {
// 开始事务
$this->_baseinfo_s->start_trans();
// 修改基本信息
$this->_baseinfo_s->update($qu_id, $base_data);
// 删除之前存入的问题信息
$this->_question_s->delete_by_conds(['qu_id' => $qu_id]);
// 组装问题信息表入库数据
list($qc_data, $attach_ids) = $this->_question_s->create_data($qu_id, $data['q_list']);
// 插入问题信息表
$this->_question_s->insert_all($qc_data);
// 非全员可见
if (is_numeric($data['is_all']) && $data['is_all'] == BaseinfoService::IS_ALL_NO) {
// 删除之前的权限记录
$this->_right_s->delete_by_conds(['qu_id' => $qu_id]);
// 验证并组装权限表入库数据
$qx_data = $this->_right_s->create_data($qu_id, $data['right']);
// 插入权限表信息
$this->_right_s->insert_all($qx_data);
}
// 调研状态:预发布、发布
if (BaseinfoService::PRE_PUBLISH_STATUS == $base_data['release_status']
|| BaseinfoService::PUBLISH_STATUS == $base_data['release_status']) {
$cron_params = [
'type' => 1, // 0:添加 1:修改
'qu_id' => $qu_id
];
// 添加定时任务
$this->_baseinfo_s->cron_add($cron_params);
}
// 调研状态:已发布、进行中
if (BaseinfoService::PUBLISH_STATUS == $base_data['release_status'] &&
BaseinfoService::NOCTICE_YES == $base_data['is_notice']) {
// 如果为发布状态,则推送消息给用户
$data = $this->_baseinfo_s->get($qu_id);
$this->_baseinfo_s->sendmsg_release($data);
}
// 提交事务
$this->_baseinfo_s->commit();
} catch (\Think\Exception $e) {
\Think\Log::record($e);
// 事务回滚
$this->_set_error($e->getMessage(), $e->getCode());
$this->_baseinfo_s->rollback();
} catch (\Exception $e) {
\Think\Log::record($e);
$this->_set_error($e->getMessage(), $e->getCode());
// 事务回滚
$this->_baseinfo_s->rollback();
}
// 附件处理
if (!empty($attach_ids)) {
$attach_serv = new AttachOperation();
$attach_serv->update_attach(
APP_DIR,
'baseinfo',
$qu_id,
['attach_ids' => $attach_ids]
);
}
return true;
}
/**
* 编辑新类型处理
*
* @param int $qu_id 调研ID
* @param array $data 调研基本信息
*
* @return array|bool
*
* @throws \VcySDK\Exception
*/
protected function new_type($qu_id = 0, $data = [])
{
// 验证并组装基本信息
$base_data = $this->_baseinfo_s->check_BaseInfoData($data);
// 验证问题信息
$this->_question_s->checkData($data['q_list']);
try {
// 开始事务
$this->_baseinfo_s->start_trans();
// 修改基本信息
$this->_baseinfo_s->update($qu_id, $base_data);
// 删除之前存入的问题信息
$this->_question_s->delete_by_conds(['qu_id' => $qu_id]);
// 组装问题信息表入库数据
list($qc_data, $attach_ids) = $this->_question_s->create_data($qu_id, $data['q_list']);
// 插入问题信息表
$this->_question_s->insert_all($qc_data);
// 提交事务
$this->_baseinfo_s->commit();
} catch (\Think\Exception $e) {
\Think\Log::record($e);
// 事务回滚
$this->_set_error($e->getMessage(), $e->getCode());
$this->_baseinfo_s->rollback();
} catch (\Exception $e) {
\Think\Log::record($e);
$this->_set_error($e->getMessage(), $e->getCode());
// 事务回滚
$this->_baseinfo_s->rollback();
}
// 附件处理
if (!empty($attach_ids)) {
$attach_serv = new AttachOperation();
$attach_serv->update_attach(
APP_DIR,
'baseinfo',
$qu_id,
['attach_ids' => $attach_ids]
);
}
return true;
}
}