RedInfoController.class.php
2.31 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
<?php
/**
* 【业绩比拼-手机端】红包详情
* RedInfoController.class.php
*
* User: daijun
* Date: 2017-11-04
*/
namespace Api\Controller\Red;
use Common\Service\PacketrecordService;
use VcySDK\Enterprise;
class RedInfoController extends \Api\Controller\AbstractController
{
public function Index_get()
{
// 红包记录ID
$rid = I('get.rid', 0, 'intval');
if (empty($rid)) {
// 数据验证
E('_EMPTY_RED_RECORD_ID');
}
if (empty($this->uid)) {
// 判断是否外部人员
E('_EMPTY_USER_ID');
}
// 实例化红包记录表
$record_service = new PacketrecordService();
// 红包记录详情
$detail = $record_service->get_by_conds([
'rid' => $rid, // 红包记录id
'uid' => $this->uid, // 用户uid
'packet_status' => PacketrecordService::PACKET_STATUS_SUCCESS // 红包状态:领取成功
]);
if (empty($detail)) {
// 红包记录不存在
E('_ERR_RED_RECORD_DATA');
}
// 获取企业名称与logo
$enterpriseSDK = new Enterprise(\VcySDK\Service::instance());
// 获取企业详情
$ep_detail = $enterpriseSDK->detail();
$result = [
'red_type' => intval($detail['p_type']),
'username' => strval($detail['username']),
'ep_name' => $ep_detail['epName'],
'ep_logo' => $ep_detail['corpSquareLogo'],
'user_money' => sprintf("%.2f", $detail['rand_money'] / 100),
];
// 如果是随机比例红包类型
if (PacketrecordService::RED_PACKET_RAND == $detail['p_type']) {
// 查询当前活动领取成功的红包记录数
$total = $record_service->count_by_conds(
[
'ac_id' => $detail['ac_id'], // 同一个活动
'p_type' => $detail['p_type'], // 相同的红包类型
'packet_status' => PacketrecordService::PACKET_STATUS_SUCCESS // 红包状态:领取成功
]
);
$result['total'] = $total;
} else {
// 如果是其他红包
$result['total'] = 0;
}
$this->_result = $result;
return true;
}
}