DetailController.class.php
4.83 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
<?php
/**
* 【手机端】02-培训详情接口
* Created by PhpStorm.
* @author:wanghuan
* @date:2017-08-29
*/
namespace Api\Controller\Education;
use Common\Service\EducationService;
use Common\Service\CategoryService;
use Common\Service\PlanService;
use Common\Service\RightUsersService;
class DetailController extends \Api\Controller\AbstractController
{
/** @var EducationService */
protected $edu_s;
/** @var CategoryService */
protected $cate_s;
/** @var PlanService */
protected $plan_s;
/** @var RightUsersService */
protected $right_users_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化培训service
$this->edu_s = new EducationService();
// 实例化培训分类service
$this->cate_s = new CategoryService();
// 实例化培训计划service
$this->plan_s = new PlanService();
// 实例化员工名单service
$this->right_users_s = new RightUsersService();
return true;
}
/**
* 培训详情
*/
public function Index_post()
{
// 培训id
$ed_id = I('post.ed_id', 0, 'intval');
// 培训id为空
if (!$ed_id) {
E('_EMPTY_ED_ID');
}
// 培训详情
$education = $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');
}
// 培训分类为禁用状态
if (CategoryService::CATEGORY_CLOSE == $education['ca_status']) {
E('_ERR_CATE_CLOSE');
}
// 数据格式化
$education = $this->format_data($education);
// 培训安排查询条件
$cond['ed_id'] = $ed_id;
// 分页
$page_option = null;
// 排序
$order_option['plan_order'] = 'ASC';
// 返回字段
$fields = 'plan_id, plan_name, plan_order';
// 培训安排列表
$plan_list = $this->plan_s->list_by_conds($cond, $page_option, $order_option, $fields);
$plans = [];
if (!empty($plan_list)) {
// 培训安排数据格式化
foreach ($plan_list as $key => $val) {
$plans[$key] = [
'plan_id' => intval($val['plan_id']),
'plan_name' => $val['plan_name']
];
}
}
// 返回结果追加培训安排列表数据
if ($education) {
$education['plans'] = $plans;
}
// 返回结果
$this->_result = $education;
}
/**
* 格式化培训数据
*
* @param array $education 待格式化数据
*
* @return array 格式化后数据
*/
protected function format_data($education)
{
// 培训分类id
$ca_id = $education['ca_id'];
// 分类详情
$category = $this->cate_s->get($ca_id);
// 分类名称
$ca_name = '';
if (!empty($category)) {
$ca_name = $category['ca_name'];
}
// 员工名单查询条件
$cond = [
'ed_id' => $education['ed_id'],
'ru_uid' => $this->uid
];
// 查询用户报名数据
$right_users = $this->right_users_s->get_by_conds($cond);
// 用户报名状态
$sign_up_status = $this->right_users_s->get_sign_up_status($education, $right_users);
// 培训进行状态
$ed_show_status = $this->edu_s->get_ed_status($education);
// 返回格式化数据
return [
'ed_id' => intval($education['ed_id']),
'ed_name' => $education['ed_name'],
'ca_name' => $ca_name,
'ed_cover_url' => CategoryService::format_cover($education['ed_cover_id']),
'ed_begin_time' => $education['ed_begin_time'],
'ed_end_time' => $education['ed_end_time'],
'ed_address' => $education['ed_address'],
'ed_introductions' => $education['ed_introductions'],
'ed_is_sign_up' => intval($education['ed_is_sign_up']),
'ed_sign_deadline' => $education['ed_sign_deadline'],
'ed_is_charge' => intval($education['ed_is_charge']),
'ed_charge_type' => intval($education['ed_charge_type']),
'ed_charge_score' => intval($education['ed_charge_score']),
'ed_is_check' => intval($education['ed_is_check']),
'ed_status' => intval($ed_show_status),
'sign_up_status' => $sign_up_status
];
}
}