AdminSendController.class.php
2.74 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
<?php
/**
* 【销售活动-后台】管理员定向红包
*
* author xtong
*/
namespace Apicp\Controller\Red;
use Com\PackageValidate;
use Common\Service\ActivityService;
use Common\Service\PacketrecordService;
class AdminSendController extends \Apicp\Controller\AbstractController
{
/**
* 接收参数
* comment_id int 必填 回帖ID
* red_money string 必填 定向红包金额
*
* @return bool
*/
public function Index_post()
{
// 验证规则
$rules = [
'comment_id' => 'require',
'red_money' => 'require|between:1,2000',
];
$msg = [
'comment_id.require' => L('_ERR_COMMENT_ID_EMPTY'),
'red_money.require' => L('_ERR_RED_FEE'),
'red_money.between' => L('_ERR_RED_FEE'),
];
// 验证数据
$validate = new PackageValidate($rules, $msg, array_keys($rules));
$postData = $validate->postData;
// 验证红包金额两位小数
if (!preg_match('/^[0-9]+(.[0-9]{1,2})?$/', $postData['red_money'])) {
E('_ERR_RED_FEE');
}
// 根据评论ID获取评论详情与活动详情
$cmt_and_ac_info = $this->get_ac_info_by_comment_id($postData['comment_id']);
// 活动未开启红包
if (ActivityService::RED_CLOSE == $cmt_and_ac_info['activity_info']['is_red_open']) {
E('_ERR_RED_NOT_OPEN');
}
// 发定向红包
$packetrecord_s = new PacketrecordService();
$red_params = [
'ac_id' => $cmt_and_ac_info['activity_info']['ac_id'],
'p_type' => PacketrecordService::RED_PACKET_VIP,
'uid' => $cmt_and_ac_info['comment_info']['uid'],
'comment_id' => $cmt_and_ac_info['comment_info']['comment_id'],
'price' => $postData['red_money'],
'send_uname' => $this->_login->user['eaRealname'],
'send_phone' => $this->_login->user['eaMobile']
];
$red_data = $packetrecord_s->get_red_record($red_params);
// 推送红包消息
$red_msg_params = [
'comment_id' => $cmt_and_ac_info['comment_info']['comment_id'],
'rid' => $red_data['rid'],
'ac_id' => $cmt_and_ac_info['activity_info']['ac_id'],
'subject' => $cmt_and_ac_info['activity_info']['subject'],
'give_time' => $red_data['give_time'],
'uids' => $cmt_and_ac_info['comment_info']['uid'],
'rand_money' => $postData['red_money'] * 100
];
if (!empty($red_data['rid'])) {
// 给用户发消息【获得定向红包】
$packetrecord_s->send_msg($red_msg_params, PacketrecordService::MSG_GET_VIP_REDPACKET);
}
return true;
}
}