GetVipRuleController.class.php
3.77 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
117
118
119
120
121
122
123
124
<?php
/**
* Created by PhpStorm.
* User: zhoutao
* Date: 2017/12/21
* Time: 下午6:06
*/
namespace Apicp\Controller\Pay;
use Common\Common\Order;
use VcySDK\CyPay;
use VcySDK\Service;
class GetVipRuleController extends AbstractController
{
protected $needCheckThePayment = false;
/**
* 规则类型与UC支付类型映射
*/
const RULE_TYPE_MAPPING_ORDER_TYPE = [
// 购买员圈应用
1 => 4,
// 购买空间
2 => 6,
// 购买流量
3 => 6,
// 扩充人数
4 => 5,
];
/**
* 支付状态:待支付
*/
const ORDER_STATUS_WAIT_PAY = 1;
/**
* 是否存在待支付订单:不存在
*/
const ORDER_WAIT_PAY_NO = 1;
/**
* 是否存在待支付订单:存在
*/
const ORDER_WAIT_PAY_YES = 2;
/**
* 规则类型:扩充人数
*/
const PAY_RULE_ADD_USER = 4;
/**
* GetVipRule
* @author tangxingguo
* @desc 获取付费规则,返回结果说明:该返回数据格式仅针对提交了rule_type的情况
* @param Int rule_type 规则类型(1=续费;2=空间容量;3=流量;4=扩充人数)
* @return array
* array(
* 'is_wait_pay' => 1, // 是否存在待支付订单(1=无;2=有)
* 'product_id' => '008474BE7F00000175505861C25D23D2', // 产品类型
* 'product_name' => '扩充人数', // 产品名称
* 'current_people' => 100, // 当前应用授权使用人数
* 'order_id' => '045EA0FC7F0000011C8D0FD226E592F3', // 待支付订单ID
* 'expire_time' => 1521561599000, // 当前生效订单失效期,扩充人数时有值
* 'rule' => array( // 付费规则
* array(
* 'networkRule' => array(
* 'price' => 8800,
* 'network' => 107374182400,
* 'unit' => 'G',
* )
* )
* )
* );
*/
public function index()
{
// 请求数据
$postData = I('post.');
// 规则
$sdk = new CyPay(Service::instance());
$rule = $sdk->getVipRule();
if (isset($postData['rule_type'])) {
// 同类待支付订单确认
$orderMap = self::RULE_TYPE_MAPPING_ORDER_TYPE;
$orderServ = &Order::instance();
// 获取当前应用授权使用人数
$allow_users = $orderServ->GetAllowUserTotal(['plIdentifier' => 'yuanquan']);
$orderList = $orderServ->fetchOrderList([
'ordPayStatus' => self::ORDER_STATUS_WAIT_PAY,
'ordType' => $orderMap[$postData['rule_type']],
]);
// 扩充人数,需要获取当前生效订单有效期限
if ($postData['rule_type'] == self::PAY_RULE_ADD_USER) {
// 可使用订单列表(包括正在生效的订单)
$list = $orderServ->fetchValidOrderList(['ordType' => 4]);
// 获取当前生效订单的失效时间
if (isset($list['total']) && $list['total'] > 0) {
$orderInfo = reset($list['list']);
$oauEnd = $orderInfo['oauEnd'];
}
}
$this->_result = [
'is_wait_pay' => $orderList['total'] > 0 ? self::ORDER_WAIT_PAY_YES : self::ORDER_WAIT_PAY_NO,
'product_id' => $orderList['total'] > 0 ? $orderList['list'][0]['prId'] : '',
'product_name' => $orderList['total'] > 0 ? $orderList['list'][0]['ordTitle'] : '',
'current_people' => intval($allow_users['memberTotal']),
'order_id' => $orderList['total'] > 0 ? $orderList['list'][0]['ordId'] : '',
'expire_time' => isset($oauEnd) ? $oauEnd : 0,
'rule' => $rule,
];
return true;
}
$this->_result = $rule;
}
}