PublishController.class.php
3.21 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
<?php
/**
* 【销售活动-后台】活动立即发布接口
*
* User: WJY
* Date: 2017-11-02
*/
namespace Apicp\Controller\Activity;
use Common\Model\ActivityModel;
use Common\Service\ActivityService;
class PublishController extends \Apicp\Controller\AbstractController
{
public function Index_post()
{
$params = I('post.');
$ac_id = $this->publish_activity($params);
$this->_result = [
'ac_id' => $ac_id,
];
return true;
}
/**
* 立即发布活动
*
* @param array $reqData 请求数据
*
* @return bool
*/
public function publish_activity($reqData)
{
$activity_s = new ActivityService();
$ac_id = intval($reqData['ac_id']);
// 活动ID存在性判断
if (empty($ac_id)) {
E('_ERR_AC_ID_EMPTY');
}
// 活动详情
$activity = $activity_s->get($ac_id);
// 活动存在性判断
if (empty($activity)) {
E('_ERR_ARTICLE_NOT_FOUND');
}
// 活动开始时间是否小于当前时间
if ($activity['begin_time'] <= MILLI_TIME) {
E('_ERR_ACTIVITY_OVERDUE');
}
$data = [
'last_time' => MILLI_TIME,
'publish_time' => MILLI_TIME,
'activity_status' => ActivityService::ACTIVITY_PUBLISH
];
$activity_s->update($ac_id, $data);
if (ActivityService::RED_OPENED == $activity['is_red_open']) {
// 开启红包,获取红包配置信息
$packet = $activity_s->get_by_conds(['ac_id' => $ac_id]);
$packet['rule_list'] = unserialize($packet['red_content']);
// 是否为随机比例红包
if (ActivityService::RAND_PRO_RED == $packet['type']) {
// 生成随机比例红包记录
$activity_s->create_packet_record($ac_id, $packet['id'], $packet['rule_list'],
$packet['red_base_num']);
}
}
//【发送消息】开启发送消息时则发送消息
if (ActivityModel::NOTICE_ON == $activity['is_notice']) {
// 组装发送消息的数据
$params = [
'ac_id' => $ac_id,
'subject' => $activity['subject'],
'content' => unserialize($activity['content']),
'begin_time' => $activity['begin_time'],
'end_time' => $activity['end_time'],
];
// 如果不是全公司则需要组装权限范围
if (ActivityService::IS_ALL != $activity['is_all']) {
$data = $activity_s->count_unjoin(['ac_id' => $ac_id], []);
$uids = $data['unjoin_uids'];
$params['uids'] = $uids;
if (!empty($uids)) {
// 发送消息
$activity_s->send_msg($params, ActivityService::MSG_ACTIVITY_PUBLISH);
}
} else {
// 权限为全公司
$params['is_all'] = $activity['is_all'];
// 发送消息
$activity_s->send_msg($params, ActivityService::MSG_ACTIVITY_PUBLISH);
}
}
return true;
}
}