SubmitOrderController.class.php
2.84 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
<?php
/**
* Created by PhpStorm.
* User: yingcai
* Date: 2018/2/1
* Time: 下午4:47
*/
namespace Apicp\Controller\LiveOrder;
use Common\Common\Order;
class SubmitOrderController extends AbstractController
{
/**
* SubmitOrder
* @author houyingcai
* @desc 提交购买并发人数订单接口
* @param Int nums:true:100 购买数量
* @param Int is_read:true:1 是否阅读并同意签署服务协议(1=是,2=否)
* @return array|bool 商品信息
array(
'order_id' => 123, // 订单ID
'order_desc' => '员圈直播', // 订单内容
'total_price' => 24518, // 订单总金额(单位:元)
'order_sn' => '20180117170840644', // 订单编号
'created' => 1517486261770, // 创建时间
'buy_content' => array( // 购买内容
'nums' => 100, // 购买人数
'years' => 1, // 购买年数
),
)
*/
public function Index_post()
{
$params = I('post.');
$nums = intval($params['nums']);
// 购买数量不能为0
if (!$nums) {
E('_ERR_LIVE_BUY_CONCURRENT_NUMS');
}
// 未阅读并同意签署服务协议
if (intval($params['is_read']) != 1) {
E('_ERR_READ_AGREEMENT_NOT');
}
$orderServ = &Order::instance();
// 获取购买并发人数规则
$result = $orderServ->fetchProductRule(['prCostKey' => 'live_cast_rule']);
$rule = json_decode($result['prCostValue'], true);
// 计算所需金额(单位:分)
$amount = $rule['price'] * $nums;
$orderParams = [
'num' => $nums,
'ordTotalPrice' => $amount,
'eaId' => $this->_login->user['eaId'],
'prCostKey' => 'live_cast_rule',
];
if (!empty($this->_login->user['eaMobile'])) {
$orderParams['eaMobile'] = $this->_login->user['eaMobile'];
}
if (!empty($this->_login->user['eaRealname'])) {
$orderParams['eaRealname'] = $this->_login->user['eaRealname'];
}
$orderDetail = $orderServ->addOrder($orderParams);
// 购买内容
$buy_content = json_decode($orderDetail['ordContent'], true);
// 返回参数
$this->_result = [
'order_id' => $orderDetail['ordId'],
'order_desc' => $orderDetail['ordTitle'],
'total_price' => $orderDetail['ordTotalPrice'],
'order_sn' => $orderDetail['ordCode'],
'created' => $orderDetail['ordCreated'],
'buy_content' => [
'nums' => $buy_content['personAmount'],
'years' => $buy_content['year'],
],
];
return true;
}
}