Pay.php 2.26 KB
<?php

use Action\WebAction;
use Shopping\PayModel;
use WebPlugin\Helpers;
use LibModels\Web\Home\UserData;
/**
 * 支付相关的控制器
 * 
 * @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(true);
        if (!$uid) {
            $this->go( Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN))) );
        }
        // 将用户UID存入session中以便支付成功回调使用
        $this->setSession(self::SESSION_UID_KEY, $uid);

        // 订单号
        $orderCode = $this->get('order_code', $this->get('ordercode'));

        //支付宝快捷支付
        $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 = PayModel::getPayTypeData($uid, $orderCode);
        //不存在订单时
        if (isset($data['noOrder'])) {
            $this->helpJsRedirect('没有找到该订单');
        }

        $view = 'index';
        // 无需付款时
        if (isset($data['notNeedPay'])) {
            $view = 'notneedpay';
        }
        // 是货到付款时
        if (isset($data['finish'])) {
            $view = 'cashondelivery';
        }
        
        // 用户名
        $UserData = UserData::getUserInfo($uid);
        $data['userName'] = isset($UserData['code']) && $UserData['code'] === 200 ? $UserData['data']['profile_name'] : $this->_uname;

        $this->setSimpleHeader();
        $this->_view->display($view, array(
            'shoppingpay' =>$data,
            'pinyou' => array(
                'orderNum' => $data['orderNum'],
                'count' => $data['count'],
                'productList' => $data['pinyouGoods']
            ),
            'payPage' => true
        ));
    }

}