SubmitOrderController.class.php
3.66 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
<?php
/**
* 提交订单接口
* Created by PhpStorm.
* User: yingcai
* Date: 2018/2/28
* Time: 上午10:43
*/
namespace Apicp\Controller\SaleOrder;
use Common\Common\Order;
class SubmitOrderController extends \Apicp\Controller\AbstractController
{
/**
* SubmitOrder
* @author houyingcai
* @desc 提交订单接口
* @param Int level:true:1 所属级别
* @param Int years:false:1 购买年限(购买业绩比拼应用和续费时为必填,扩充人数时为非必填)
* @param Int amount:true:10000 订单总金额(单位:分)
* @param Int is_read:true:1 是否阅读并同意签署服务协议(1=是,2=否)
* @param Int buy_type:true:1 购买类型(1=购买「业绩比拼」应用,2=扩充「业绩比拼」应用使用人数)
* @return array|bool 购买规则
array(
'order_id' => '008474BE7F00000175505861C25D23D2', // 订单ID
'order_desc' => '业绩比拼', // 订单内容
'total_price' => 10000, // 订单总金额(单位:元)
'order_sn' => '008474BE7F00000175505861C25D23D2', // 订单编号
'created' => 1517572194899, // 创建时间
'buy_content' => array(
'people_range' => 1000人及以下, // 人数范围
'years' => 1, // 购买年限
),
)
*/
public function Index_post()
{
$params = I('post.');
$level = intval($params['level']);
$amount = intval($params['amount']);
$years = intval($params['years']);
$buy_type = intval($params['buy_type']);
if (!$level) {
// 请选择购买级别
E('_EMPTY_SALE_BUY_LEVEL');
}
if (!$amount) {
// 订单金额不能为空
E('_EMPTY_SALE_ORDER_AMOUNT');
}
if (!$buy_type) {
// 订单类型不能不能为空
E('_EMPTY_SALE_ORDER_TYPE');
}
if (intval($params['is_read']) != 1) {
// 未阅读并同意签署服务协议
E('_ERR_READ_AGREEMENT_NOT');
}
$orderServ = &Order::instance();
$orderParams = [
'level' => $level,
'ordTotalPrice' => $amount,
'eaId' => $this->_login->user['eaId'],
// $buy_type 购买类型(1=购买「业绩比拼」应用,2=扩充「业绩比拼」应用使用人数)
'prCostKey' => $buy_type == 1 ? 'compete_app_rule' : 'compete_persons_rule',
];
// 购买的年限
if ($years) {
$orderParams['year'] = $years;
}
// 管理员手机号
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' => [
'people_range' => $buy_content['desc'],
'years' => $buy_content['year'],
],
];
return true;
}
}