InfoController.class.php
5.51 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 18/5/18
* Time: 10:15
*/
namespace Api\Controller\Course;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\Teacher;
use Common\Service\CourseArticleService;
use Common\Service\CourseItemService;
use Common\Service\PlanDoService;
use Common\Service\SignService;
class InfoController extends \Api\Controller\AbstractController
{
/**
* Info
* @author liyifei
* @desc 线下课程详情接口
* @param Int article_id:true 课程ID
* @return array 课程详情
array(
'article_id' => 123, // 课程ID
'article_title' => '好好学', // 课程标题
'cover_id' => 'b3ddbc502e307665f346cbd6e52cc10d', // 封面图片ID
'cover_url' => 'http://qy.vchangyi.org', // 封面图片地址
'start_time' => 12367890567, // 授课开始时间
'end_time' => 12367890567, // 授课结束时间
'credit' => 12, // 学分
'address' => '上海徐汇', // 授课地址
'content' => '介绍介绍课程', // 课程介绍
'is_notice' => 1, // 消息通知讲师(1=不开启,2=开启)
'class_hour' => 88.8, // 讲师授课课时
'is_reward' => 1, // 是否启用赞赏(1=不启用;2=启用)
'is_score' => 1, // 是否启用评分(1=不启用;2=启用)
'is_sign' => 1, // 是否启用签到(1=不启用;2=启用)
'sign_status' => 2, // 签到状态(1=未开始;2=正常;3=已过期)
'teacher' => array( // 讲师信息
'teacher_id' => 1, // 讲师ID
'uid' => '61EA54B27F00000156F7B12404511F16', // 内部讲师ID
'teacher_name' => '苏三', // 讲师姓名
'face_url' => '', // 头像
'title' => '金牌讲师', // 头衔
'remark' => 'xxx', // 介绍
),
'teacher_task_id' => 0, // 讲师授课任务ID(未设置任务时为0)
'task_name' => '第二季度任务', // 讲师授课任务名称
'score_avg' => 9.0, // 整体评分
'sign_qr_code' => '', // 签到二维码地址
'user_is_sign' => 1, // 人员是否已签到(1=未签到;2=已签到)
);
*/
public function Index_post()
{
// 验证规则
$rules = [
'article_id' => 'require|integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$article_id = $validate->postData['article_id'];
// 取课程
$articleServ = new CourseArticleService();
$article = $articleServ->get($article_id);
if (empty($article)) {
E('_ERR_ARTICLE_DATA_NOT_FOUND');
}
// 讲师信息
$teacherServ = &Teacher::instance();
$teacher = $teacherServ->getTeacherInfo($article['teacher_id']);
$article['teacher'] = $teacher;
// 授课任务名称
$task = $teacherServ->getTeackerTask($article['teacher_task_id']);
$article['task_name'] = isset($task['task_name']) ? $task['task_name'] : '';
// 整体评分
$itemServ = new CourseItemService();
$item_list = $itemServ->list_by_conds(['article_id' => $article_id]);
$user_total = 0;
$score_otal = 0;
foreach ($item_list as $item) {
$user_total += $item['user_total'];
$score_otal += $item['score_total'];
}
$article['score_avg'] = 0;
if ($user_total != 0) {
$article['score_avg'] = round($score_otal / $user_total, 1);
}
// 该课程是否可签到
if ($article['is_sign'] == Constant::COURSE_IS_SIGN_IS_TRUE) {
// 未开始
if (MILLI_TIME < $article['start_time']) {
$article['sign_status'] = Constant::SIGN_STATUS_IS_NOT_BEGINING;
}
// 正常
if (MILLI_TIME >= $article['start_time'] && MILLI_TIME <= $article['end_time']) {
$article['sign_status'] = Constant::SIGN_STATUS_IS_ONGOING;
}
// 已过期
if (MILLI_TIME > $article['end_time']) {
$article['sign_status'] = Constant::SIGN_STATUS_IS_END;
}
}else{
// 无需签到,则需查询是否已完成
$plan_do_serv = new PlanDoService();
// plan_do表数据
$plan_do_data = [
'pd_uid' => $this->uid,
'plan_id' => $article['plan_id'],
'ed_id' => $article['ed_id']
];
$plan_do = $plan_do_serv->get_by_conds($plan_do_data);
if (empty($plan_do)) {
// plan_do表中添加数据,标识已完成
$plan_do_serv->insert($plan_do_data);
}
}
// 若讲师本人查看,则返回签到二维码
if ($this->uid == $article['teacher']['uid']) {
$article['sign_qr_code'] = $articleServ->getSignQrcodeUrl($article_id);
}
// 人员是否已签到
$signServ = new SignService();
$sign = $signServ->get_by_conds(['sign_uid' => $this->uid, 'article_id' => $article_id]);
$article['user_is_sign'] = empty($sign) ? Constant::COURSE_IS_SIGN_IS_FALSE : Constant::COURSE_IS_SIGN_IS_TRUE;
$this->_result = $article;
}
}