Pay.php
4.01 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
125
126
127
128
129
130
131
132
133
<?php
use Action\WebAction;
use Shopping\PaymentModel;
use WebPlugin\Helpers;
use LibModels\Web\Home\UserData;
use WebPlugin\Cache;
use Home\IndexModel;
/**
* 支付相关的控制器
*
* @name PayController
* @package shopping
* @copyright yoho.inc
* @version 1.0 (2016-3-21 16:23:19)
* @author fei.hong <fei.hong@yoho.cn>
*/
class PayController extends WebAction
{
// 存储的UID键名
const SESSION_UID_KEY = 'payUserid';
/**
* 订单已完成,跳到支付
*/
public function indexAction()
{
/* 判断用户是否登录 */
$uid = $this->getUid();
if (!$uid) {
$this->go( Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN))) );
}
// 订单号
$orderCode = $this->get('order_code', $this->get('ordercode'));
if (USE_CACHE) {
// 将用户UID存入session中以便支付成功回调使用
$this->setSession(self::SESSION_UID_KEY, $uid);
Cache::set(self::SESSION_UID_KEY . $orderCode, $uid, 3600 * 10);
}
//支付宝快捷支付
$alipayToken = $this->getSession('alipay_user_token');
if (!empty($alipayToken)) {
$this->go(Helpers::url('/pay/index/index', array('order_code' => $orderCode, 'payment_type' => '2_platform')));
}
$data = PaymentModel::getPayTypeData($uid, $orderCode);
//不存在订单时
if (isset($data['noOrder'])) {
$this->helpJsRedirect('没有找到该订单');
}
$view = 'index';
// 无需付款时
if (isset($data['notNeedPay'])) {
$view = 'notneedpay';
}
// 是货到付款时
if (isset($data['finish'])) {
$view = 'cashondelivery';
$data['fraudTip'] = PaymentModel::getFraudTip();
}
// 用户名
$UserData = UserData::getUserInfo($uid);
$data['userName'] = isset($UserData['code']) && $UserData['code'] === 200 ? $UserData['data']['profile_name'] : $this->_uname;
$udid = $uid . $this->getUdid();
$channel = Helpers::getChannelNameByCookie();
$channelNum = 1;
switch ($channel) {
case 'boys':
$channelNum = 1;
break;
case 'girls':
$channelNum = 2;
break;
case 'kids':
$channelNum = 3;
break;
case 'lifestyle':
$channelNum = 4;
break;
default:
break;
}
$data['bestForYou'] = IndexModel::preferenceData($channelNum, $uid, $udid, '100004', 15);
$this->setSimpleHeader();
$this->_view->display($view, array(
'shoppingpay' =>$data,
'pinyou' => array(
'orderNum' => $data['orderNum'],
'count' => $data['count'],
'productList' => $data['pinyouGoods']
),
'criteo' => array(// criteo统计代码有关数据
'orderNum' => $data['orderNum'],
'items' => $data['orderGoods']
),
'payPage' => true,
'paySuccessPage' => true
));
}
/**
* 单击已完成支付按钮--发送一次支付确认
*/
public function sendPayAction()
{
$result = array('code' => 400, 'message' => '操作失败!');
if ($this->isAjax()) {
do {
$uid = $this->getUid();
$orderCode = $this->post('orderCode', 0);
$paymentId = $this->post('paymentId', 0);
if (empty($orderCode) || empty($uid) || empty($paymentId)) {
break;
}
$result = PaymentModel::sendPayConfirm($orderCode, $paymentId, $uid);
} while (false);
}
$this->echoJson($result);
}
}