AddController.class.php
3.31 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
<?php
/**
* 【手机端】09-提交评价接口
* Created by PhpStorm.
* @author:wanghuan
* @date:2017-08-31
*/
namespace Api\Controller\Comment;
use Common\Service\CommentService;
use Common\Service\CommentScoreService;
use Common\Service\CompositeScoreService;
use Common\Service\RightUsersService;
class AddController extends \Api\Controller\AbstractController
{
/** @var CommentService */
protected $comment_s;
/** @var CommentScoreService */
protected $comment_score_s;
/** @var CompositeScoreService */
protected $composite_score_s;
/** @var RightUsersService */
protected $right_users_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化评论service
$this->comment_s = new CommentService();
// 实例化评论得分项service
$this->comment_score_s = new CommentScoreService();
// 实例化评价项综合评分service
$this->composite_score_s = new CompositeScoreService();
// 实例化员工名单service
$this->right_users_s = new RightUsersService();
return true;
}
/**
* 评价
*/
public function Index_post()
{
// 接收post参数
$params = I('post.');
// 培训id
$ed_id = $params['ed_id'];
// 培训id为空
if (!$ed_id) {
E('_EMPTY_ED_ID');
}
// 培训详情
$this->get_education($ed_id);
// 适用范围查询条件
$right_cond = [
'ru_uid' => $this->uid,
'ed_id' => $ed_id
];
// 查询当前员工适用范围数据
$user_right = $this->right_users_s->get_by_conds($right_cond);
// 当前员工不在适用范围
if (empty($user_right)) {
E('_ERR_ED_NO_RIGHT');
}
// 各评分项评分
$options = $params['options'];
// 各评分项评分数据为空
if (empty($options)) {
E('_EMPTY_COMMENT_OPTIONS');
}
// 当前登录用户id
$params['uid'] = $this->uid;
$cond = [
'ed_id' => $ed_id,
'c_uid' => $this->uid
];
$comment = $this->comment_s->get_by_conds($cond);
if (!empty($comment)) {
E('_ERR_COMMENT_EXIST');
}
try {
$this->comment_s->start_trans();
// 新增评价
$c_id = $this->comment_s->add($params);
// 各评分项待新增数据
$score_data = [];
foreach ($options as $key => $val) {
$score_data[$key] = [
'cs_score' => $val['cs_score'],
'ed_id' => $ed_id,
'c_id' => $c_id,
'option_id' => intval($val['option_id'])
];
}
// 新增评价各项得分
$this->comment_score_s->insert_all($score_data);
// 新增或更新综合评分数据
$this->composite_score_s->update_composite_score($ed_id);
$this->comment_s->commit();
} catch (\Exception $e) {
$this->comment_s->rollback();
E('_ERR_COMMENT_FAIL');
return false;
}
return true;
}
}