RemindController.class.php
2.95 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
<?php
/**
* 【销售活动-后台】活动参与提醒接口
*
* User: WJY
* Date: 2017-11-06
*/
namespace Apicp\Controller\Activity;
use Common\Common\Helper;
use Common\Service\ActivityService;
use Common\Service\CommentService;
class RemindController extends \Apicp\Controller\AbstractController
{
/** @var ActivityService */
protected $activity_s;
/** @var CommentService */
protected $comment_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化活动信息表
$this->activity_s = new ActivityService();
// 实例化评论表
$this->comment_s = new CommentService();
return true;
}
public function Index_post()
{
$params = I('post.');
$this->remind_activity($params);
return true;
}
protected function remind_activity($param = [])
{
// 不合理性排除
if (empty($param['ac_id'])) {
E('_ERR_REMIND');
}
$activity = $this->activity_s->get($param['ac_id']);
// 获取活动状态 1:草稿,2:未开始,3:进行中,4:已结束,5:已终止
$status = $this->activity_s->activity_status($activity['activity_status'], $activity['begin_time'],
$activity['end_time']);
if (!in_array($status, [Helper::STATUS_NOT_START, Helper::STATUS_ING])) {
// 如果不是未开始和进行中的活动,则不能提醒
E('_ERR_ACTIVITY_REMIND_STATUS');
}
// 如果是个人通知
if (!empty($param['memId'])) {
$params = [
'uids' => $param['memId'],
'ac_id' => $param['ac_id'],
'subject' => $activity['subject'],
'begin_time' => $activity['begin_time'],
'end_time' => $activity['end_time'],
'content' => unserialize($activity['content']),
];
// 发送消息
$this->activity_s->send_msg($params, ActivityService::MSG_REMAIND_NO_JOIN_USERS);
}
// 如果是全部未参与通知
if (empty($param['memId'])) {
// 获取参与列表
$joinlist = $this->comment_s->list_join(['ac_id' => $param['ac_id']]);
// 获取未参与列表
$unjoinlist = $this->comment_s->count_unjoin(['ac_id' => $param['ac_id']], $joinlist);
$params = [
'uids' => $unjoinlist['unjoin_uids'],
'ac_id' => $param['ac_id'],
'subject' => $activity['subject'],
'begin_time' => $activity['begin_time'],
'end_time' => $activity['end_time'],
'content' => unserialize($activity['content']),
];
// 发送消息
$this->activity_s->send_msg($params, ActivityService::MSG_REMAIND_NO_JOIN_USERS);
}
return true;
}
}