JoinListController.class.php
2.81 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
<?php
/**
* 【销售活动-后台】后台参与情况列表
*
* author xtong
*/
namespace Apicp\Controller\Activity;
use Com\PackageValidate;
use Common\Service\ActivityService;
use Common\Service\CommentService;
class JoinListController extends \Apicp\Controller\AbstractController
{
// 参与列表类型:已参与
const TYPE_JOIN_LIST = 2;
// 参与列表类型:未参与
const TYPE_UNJOIN_LIST = 1;
public function Index_post()
{
// 验证规则
$rules = [
'ac_id' => 'require',
'is_join' => 'require|between:1,2',
];
$msg = [
'ac_id.require' => L('_EMPTY_ACTIVITY_ID'),
'is_join.require' => L('_ERR_JOIN_STATUS_PARAMS'),
'is_join.between' => L('_ERR_JOIN_STATUS_PARAMS'),
];
// 验证数据
$validate = new PackageValidate($rules, $msg, array_keys($rules));
$postData = $validate->postData;
$params = I('post.');
// 查询活动详情
$activity_s = new ActivityService();
$activity_info = $activity_s->get($postData['ac_id']);
if (empty($activity_info)) {
// 只开启审核未开启红包,存在活动被删除的情况
E('_ERR_ACTIVITY_NOT_FOUND');
}
$comment_s = new CommentService();
$list = [];
$total = [];
$join_num = $comment_s->count_join($params);
// 已参与人员信息分页查询
$join_list = $comment_s->list_join($params);
// 已参与列表
if (self::TYPE_JOIN_LIST == $postData['is_join'] && !empty($join_num)) {
$list = $join_list;
$total = $join_num;
}
// 获取未参与人数与未参与uid数组
$unjoin_result = $comment_s->count_unjoin($params, $join_list);
$unjoin_num = $unjoin_result['unjoin_num'];
if (self::TYPE_UNJOIN_LIST == $postData['is_join'] && !empty($unjoin_num)) {
// 未参与人员信息分页查询
$unjoin_list = $comment_s->list_unjoin($params, $unjoin_result['unjoin_uids']);
$list = $unjoin_list;
$total = $unjoin_num;
}
if ($activity_info['join_total'] != ($join_num + $unjoin_num)) {
// 更新已参与和应参与人数
$activity_s->update($postData['ac_id'], ['join_num' => $join_num, 'join_total' => $join_num + $unjoin_num]);
}
$this->_result = [
'join_num' => $join_num,
'unjoin_num' => $unjoin_num,
'total' => $total,
'limit' => !empty($params['page']) ? intval($params['page']) : CommentService::DEFAULT_PAGE,
'page' => !empty($params['limit']) ? intval($params['limit']) : CommentService::DEFAULT_LIMIT,
'list' => $list
];
return true;
}
}