ScoreController.class.php
2.04 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
<?php
/**
* 【手机端】13-评价综合评分接口
* Created by PhpStorm.
* @author:wanghuan
* @date:2017-08-31
*/
namespace Api\Controller\Comment;
use Common\Service\CommentService;
use Common\Service\CommentOptionsService;
class ScoreController extends \Api\Controller\AbstractController
{
// 未评价
const UN_COMMENT = 0;
// 已评价
const COMMENT = 1;
/**
* 评价列表
*/
public function Index_post()
{
// 培训id
$ed_id = I('post.ed_id', 0, 'intval');
// 培训id为空
if (!$ed_id) {
E('_EMPTY_ED_ID');
}
// 培训详情
$this->get_education($ed_id);
// 实例化评论service
$comment_s = new CommentService();
// 评价查询条件
$cond['ed_id'] = $ed_id;
// 获取记录总数
$total = $comment_s->count_by_conds($cond);
// 当前登录用户是否已评价,默认未评价
$comment_status = self::UN_COMMENT;
// 查询条件
$user_comment_cond = [
'c_uid' => $this->uid,
'ed_id' => $ed_id
];
// 用户评价数据
$user_comment = $comment_s->get_by_conds($user_comment_cond);
// 用户评价数据不为空
if (!empty($user_comment)) {
// 已评
$comment_status = self::COMMENT;
}
// 实例化评价项service
$comment_options_s = new CommentOptionsService();
// 获取综合评分数据
$composite_score = $comment_options_s->get_composite_score($ed_id);
$options = [];
if (!empty($composite_score['options_score'])) {
$options = $composite_score['options_score'];
}
// 返回结果
$this->_result = [
'total_score' => intval($composite_score['total_score']),
'score' => round($composite_score['score'], 1),
'comment_status' => $comment_status,
'comment_num' => intval($total),
'options' => $options
];
}
}