Payment.php 3.62 KB
<?php

namespace Shopping;

use LibModels\Web\Home\OrderData;
use LibModels\Web\Product\PayData;
use Plugin\Helpers;
use WebPlugin\Cache;
use WebPlugin\Pay\Banks;
use WebPlugin\Pay\PayFactory;
use WebPlugin\Pay\Reqparams;
use WebPlugin\Pay\Rspparams;
use WebPlugin\Pay\weixin\lib\WxPayApi;
use WebPlugin\Pay\weixin\lib\WxPayConfig;
use WebPlugin\Pay\weixin\lib\WxPayNativePay;
use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;

/**
 * 支付有关方法 改版
 * @copyright 2016/5/22 14:19 xiaoxiao<xiaoxiao.hao@yoho.cn>
 */
class PaymentModel
{
    protected static $code = array(
            'code' => 500,
            'message' => '支付失败'
        );
    // 存储的UID键名
    const SESSION_UID_KEY = 'payUserid';

    public static function procOrderData($payResult)
    {
        do {
            if (empty($payResult->orderCode)) {
                self::$code['message'] = '未查到订单信息,订单状态更新失败!';
                break;
            }
            $orderCode = $payResult->orderCode;
            $uid = '';
            if (USE_CACHE) {
                // 通过订单号,从缓存记录中获取uid
                $uid = Cache::get(self::SESSION_UID_KEY . $orderCode);
            }
            $orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode);
            if (empty($orderInfo['data'])) {
                self::$code['message'] = '未查到订单信息,订单状态更新失败!';
                break;
            }

            $orderData = $orderInfo['data'];
            $amount = $orderData['payment_amount'];

            if ($orderData['is_cancel'] === 'Y') {
                // 给用户发送短信
                PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
                self::$code['code'] = 417;
                self::$code['message'] = '支付成功,但订单已取消,需联系客服!';
                break;
            }

//            if ($orderData['payment_status'] === 'N') {
//                logup::info(
//                    '用户支付成功,同步地址返回,查询订单状态为未付款,有可能异步地址还未即时更新状态',
//                    array('payResult' => $payResult, 'orderData' => $orderData)
//                );
//            }

            // 支付金额与订单金额不一致
            if (round($amount, 2) !== round($payResult->totalFee, 2)) {
                self::$code['code'] = 415;
                self::$code['message'] = '支付金额与订单金额不一致,订单状态更新失败!';
                break;
            }

            self::$code['code'] = 200;
            self::$code['message'] = '支付成功,请等待发货';
            self::$code['data'] = array(
                'pay' => $amount,
                'orderNum' => $orderData['order_code'],
                'checkOrderUrl' => Helpers::url('/home/orders/detail', array('orderCode' => $orderData['order_code'])),
                'payMode' => ($orderData['payment_type'] == 1 ? '在线支付' : '货到付款'),
                'currency' => $orderData['yoho_give_coin'],
                'yohoCoinUrl' => Helpers::url('/help', array('category_id' => 87)),
                'ordersUrl' => Helpers::url('/home/orders'),
                'returnGoodsUrl' => Helpers::url('/help', array('category_id' => 121)),
                'vipSum' => $amount,
                'vipUrl' => Helpers::url('/help', array('category_id' => 91)),
                'returnHomeUrl' => Helpers::url('/')
            );

        } while (false);

        return self::$code;
    }
}