...
|
...
|
@@ -14,7 +14,7 @@ use WebPlugin\Pay\weixin\lib\WxPayConfig; |
|
|
use WebPlugin\Pay\weixin\lib\WxPayNativePay;
|
|
|
use WebPlugin\Pay\weixin\lib\WxPayOrderQuery;
|
|
|
use WebPlugin\Pay\weixin\lib\WxPayUnifiedOrder;
|
|
|
use WebPlugin\PhpLog;
|
|
|
use WebPlugin\UdpLog;
|
|
|
|
|
|
/**
|
|
|
* 支付有关方法
|
...
|
...
|
@@ -26,18 +26,6 @@ use WebPlugin\PhpLog; |
|
|
*/
|
|
|
class PayModel
|
|
|
{
|
|
|
// 日志等级,2表示记录信息等级的日志
|
|
|
const LOG_LEVEL = 2;
|
|
|
// 支付方式有关接口调用日志
|
|
|
const PAYMENT_LIST_LOG = '/Data/logs/pc_pay/payment_list';
|
|
|
// 向ERP提交订单状态有关接口调用日志和更新订单状态有关接口调用日志
|
|
|
const ORDER_STATUS_LOG = '/Data/logs/pc_pay/order_status';
|
|
|
// 获取或者更新订单支付银行的接口调用日志
|
|
|
const ORDER_BANK_LOG = '/Data/logs/pc_pay/order_bank';
|
|
|
// 根据用户UID获取订单数有关接口调用日志
|
|
|
const ORDER_COUNT_LOG = '/Data/logs/pc_pay/order_count';
|
|
|
// 发送短信有关接口调用日志
|
|
|
const SEND_MESSAGE_LOG = '/Data/logs/pc_pay/send_message';
|
|
|
|
|
|
// 是否老用户订单数判断值
|
|
|
const OLD_USER_LIMIT = 1;
|
...
|
...
|
@@ -86,8 +74,8 @@ class PayModel |
|
|
break;
|
|
|
}
|
|
|
|
|
|
$result['deliveryType'] =isset($order['delivery_time']) ? $order['delivery_time'] : '';
|
|
|
|
|
|
$result['deliveryType'] = isset($order['delivery_time']) ? $order['delivery_time'] : '';
|
|
|
|
|
|
//统计成交的skn
|
|
|
$sknList = array();
|
|
|
$skuList = array();
|
...
|
...
|
@@ -111,13 +99,7 @@ class PayModel |
|
|
// 用户ID
|
|
|
$result['uid'] = $uid;
|
|
|
|
|
|
// 初始化日志
|
|
|
$log = new PhpLog(self::PAYMENT_LIST_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
// 获取支付途径列表
|
|
|
$log->LogInfo('===开始调用支付方式列表接口,接口方法为web.SpaceOrders.getPaymentList===');
|
|
|
$payTypes = PayData::getPaymentList();
|
|
|
$log->LogInfo('===结束调用支付方式列表接口,返回结果为===');
|
|
|
$log->LogInfo(var_export($payTypes, true));
|
|
|
|
|
|
$defaultPayType = 0;
|
|
|
$types = array();
|
...
|
...
|
@@ -148,45 +130,23 @@ class PayModel |
|
|
|
|
|
// 无需付款
|
|
|
if (isset($order["payment_amount"]) && $order["payment_amount"] == 0) {
|
|
|
// 初始化日志
|
|
|
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
$log->LogInfo('===[' . $orderCode . ']===');
|
|
|
|
|
|
// ERP提交订单状态
|
|
|
$log->LogInfo('===开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
|
|
|
$log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
|
|
|
$erpReturn = PayData::submitOrderStatus($orderCode, 0, '', '', 0, '', '', '');
|
|
|
$log->LogInfo('===结束调用ERP提交订单状态接口,返回结果为===');
|
|
|
$log->LogInfo(var_export($erpReturn, true));
|
|
|
|
|
|
// 更新订单的状态
|
|
|
$log->LogInfo('===开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
|
|
|
$log->LogInfo('===请求参数为orderId=' . $order['order_id'] . 'uid=' . $uid . '===');
|
|
|
$updateOrderStatus = PayData::updateOrderStatus($order['order_id'], $uid, 0, 'Y', '');
|
|
|
$log->LogInfo('===结束调用更新订单状态接口,返回结果为===');
|
|
|
$log->LogInfo(var_export($updateOrderStatus, true));
|
|
|
|
|
|
PayData::submitOrderStatus($orderCode, 0, '', '', 0, '', '', '');
|
|
|
PayData::updateOrderStatus($order['order_id'], $uid, 0, 'Y', '');
|
|
|
$result['notNeedPay'] = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
// 记录支付方式
|
|
|
// 初始化日志
|
|
|
$log = new PhpLog(self::ORDER_BANK_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
$log->LogInfo('===开始调用记录支付方式接口,接口方法为web.SpaceOrders.getOrderPayBank===');
|
|
|
$log->LogInfo('===请求参数为orderCode=' . $orderCode . '===');
|
|
|
$bankRecord = PayData::getBankByOrder($orderCode);
|
|
|
$log->LogInfo('===结束调用记录支付方式接口,返回结果为===');
|
|
|
$log->LogInfo(var_export($bankRecord, true));
|
|
|
|
|
|
if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) {
|
|
|
$payRecord = $bankRecord['data']['bankCode'];
|
|
|
} else {
|
|
|
$payCode = $order['payment'] ?: $defaultPayType;
|
|
|
}
|
|
|
else {
|
|
|
$payCode = $order['payment'] ? : $defaultPayType;
|
|
|
//记录app上的支付方式
|
|
|
$changeCodes = array(
|
|
|
19 => 21,// app上微信支付
|
|
|
22 => 21,// h5微信支付
|
|
|
19 => 21, // app上微信支付
|
|
|
22 => 21, // h5微信支付
|
|
|
18 => $defaultPayType// h5支付宝支付
|
|
|
);
|
|
|
$platformCode = isset($changeCodes[$payCode]) && $changeCodes[$payCode] ? $changeCodes[$payCode] : $payCode;
|
...
|
...
|
@@ -202,12 +162,7 @@ class PayModel |
|
|
|
|
|
// 是否是老用户(用于订单统计)
|
|
|
$orderCount = 0;
|
|
|
// 初始化日志
|
|
|
$log = new PhpLog(self::ORDER_COUNT_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
$log->LogInfo('===开始调用查询用户订单数接口,接口方法为web.SpaceOrders.getOrderCountByUid===');
|
|
|
$orders = PayData::getOrderCountByUid($uid);
|
|
|
$log->LogInfo('===结束调用查询用户订单数接口,返回结果为===');
|
|
|
$log->LogInfo(var_export($orders, true));
|
|
|
|
|
|
if (isset($orders['data']) && !empty($orders['data'])) {
|
|
|
$orderCount = $orders['data']['total'];
|
...
|
...
|
@@ -220,8 +175,8 @@ class PayModel |
|
|
$result['orderGoods'] = $order['order_goods'];
|
|
|
// 订单商品数(用于订单统计)
|
|
|
$result['ordersGoodsNums'] = count($order['order_goods']);
|
|
|
|
|
|
} while (false);
|
|
|
}
|
|
|
while (false);
|
|
|
|
|
|
return $result;
|
|
|
}
|
...
|
...
|
@@ -253,7 +208,6 @@ class PayModel |
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 获取支付有关信息
|
|
|
*
|
...
|
...
|
@@ -344,7 +298,8 @@ class PayModel |
|
|
$bankCode = ($paymentParameter != 'platform' ? $paymentParameter : '');
|
|
|
if (isset($bankRecord['data']['bankCode']) && !empty($bankRecord['data']['bankCode'])) {
|
|
|
$bankPayRecord = PayData::updateOrderPayBank($orderCode, $payId, $bankCode);
|
|
|
} else {
|
|
|
}
|
|
|
else {
|
|
|
$bankPayRecord = PayData::setOrderPayBank($orderCode, $payId, $bankCode);
|
|
|
}
|
|
|
if (!isset($bankPayRecord['code']) || $bankPayRecord['code'] != 200) {
|
...
|
...
|
@@ -357,11 +312,13 @@ class PayModel |
|
|
//直接跳转到支付界面
|
|
|
$result['go'] = true;
|
|
|
$result['payUrl'] = $reqPars['pay_url'] . '?' . $reqPars['pars'];
|
|
|
} else {
|
|
|
}
|
|
|
else {
|
|
|
//如果是post,去form提交
|
|
|
$result = array('reqPars' => $reqPars);
|
|
|
}
|
|
|
} while (false);
|
|
|
}
|
|
|
while (false);
|
|
|
|
|
|
return $result;
|
|
|
}
|
...
|
...
|
@@ -388,7 +345,6 @@ class PayModel |
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 处理微信支付
|
|
|
*
|
...
|
...
|
@@ -402,11 +358,10 @@ class PayModel |
|
|
|
|
|
do {
|
|
|
// 初始化日志
|
|
|
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
$log->LogInfo('=====[' . $orderCode . ']===开始生成微信支付二维码========');
|
|
|
UdpLog::info('【支付】开始生成微信支付二维码', 'orderCode:' . $orderCode);
|
|
|
|
|
|
if (empty($orderCode)) {
|
|
|
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,订单号为空========');
|
|
|
UdpLog::info('【支付】微信支付时,订单号为空', 'orderCode:' . $orderCode);
|
|
|
$result['error'] = true;
|
|
|
$result['message'] = '订单号不能为空';
|
|
|
break;
|
...
|
...
|
@@ -415,19 +370,19 @@ class PayModel |
|
|
/* 判断订单信息是否存在 */
|
|
|
$orderDetail = OrderData::getOrderDetail($uid, $orderCode);
|
|
|
if (!isset($orderDetail['data']) || empty($orderDetail['data'])) {
|
|
|
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,订单信息未查到========');
|
|
|
UdpLog::info('【支付】微信支付时,订单信息未查到', 'orderInfo:' . json_encode($orderDetail));
|
|
|
$result['error'] = true;
|
|
|
$result['message'] = '没有找到该订单';
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/*$wechatqrcode = new Service(array('id' => $paymentCode));
|
|
|
$reqPars = $wechatqrcode->pay(array('order_code'=>$orderCode));
|
|
|
if (empty($reqPars)) {
|
|
|
$result['error'] = true;
|
|
|
$result['message'] = '支付系统繁忙,请稍后再试';
|
|
|
break;
|
|
|
}*/
|
|
|
/* $wechatqrcode = new Service(array('id' => $paymentCode));
|
|
|
$reqPars = $wechatqrcode->pay(array('order_code'=>$orderCode));
|
|
|
if (empty($reqPars)) {
|
|
|
$result['error'] = true;
|
|
|
$result['message'] = '支付系统繁忙,请稍后再试';
|
|
|
break;
|
|
|
} */
|
|
|
|
|
|
//统一下单
|
|
|
$totalFee = strval($orderDetail['data']['payment_amount'] * 100);
|
...
|
...
|
@@ -442,8 +397,7 @@ class PayModel |
|
|
$input->SetProduct_id($orderCode);
|
|
|
$notify = new WxPayNativePay();
|
|
|
$payResult = $notify->GetPayUrl($input);
|
|
|
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,微信统一下单的返回结果为:========');
|
|
|
$log->LogInfo(var_export($payResult, true));
|
|
|
UdpLog::info('【支付】微信支付时,微信统一下单的返回结果为', 'orderCode:' . $orderCode . 'result:' . var_export($payResult, true));
|
|
|
|
|
|
$orderData = $orderDetail['data'];
|
|
|
$firstGoods = current($orderData['order_goods']);
|
...
|
...
|
@@ -457,10 +411,9 @@ class PayModel |
|
|
'choosePayUrl' => Helpers::url('/shopping/pay', array('order_code' => $orderData['order_code'])),
|
|
|
'qrcodeUrl' => $payResult['code_url'] // 'http://paysdk.weixin.qq.com/example/qrcode.php?data=' . $result['code_url']
|
|
|
);
|
|
|
|
|
|
} while (false);
|
|
|
$log->LogInfo('=====[' . $orderCode . ']===微信支付时,处理微信支付的结果为:========');
|
|
|
$log->LogInfo(var_export($result, true));
|
|
|
}
|
|
|
while (false);
|
|
|
UdpLog::info('【支付】微信支付结果', var_export($result, true));
|
|
|
|
|
|
return $result;
|
|
|
}
|
...
|
...
|
@@ -485,26 +438,26 @@ class PayModel |
|
|
}
|
|
|
|
|
|
// 初始化日志
|
|
|
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
$log->LogInfo('=====[' . $orderCode . ']===开始查询微信扫码支付状态========');
|
|
|
UdpLog::info('【支付】开始查询微信扫码支付状态', 'orderCode:' . $orderCode);
|
|
|
|
|
|
// 组装微信支付的订单号
|
|
|
$tradeNo = 'YOHOBuy_' . $orderCode;
|
|
|
$input = new WxPayOrderQuery();
|
|
|
$input->SetOut_trade_no($tradeNo);
|
|
|
$payResult = WxPayApi::orderQuery($input);
|
|
|
$log->LogInfo(var_export($payResult, true));
|
|
|
UdpLog::info('【支付】微信扫码支付返回', 'payResult:' . var_export($payResult, true));
|
|
|
|
|
|
if (isset($payResult['trade_state']) && $payResult['trade_state'] === 'SUCCESS') {
|
|
|
$log->LogInfo('====[' . $orderCode . ']====微信扫码支付成功========');
|
|
|
UdpLog::info('【支付】微信扫码支付成功');
|
|
|
$result = array(
|
|
|
'code' => '200',
|
|
|
'message' => 'success'
|
|
|
);
|
|
|
}
|
|
|
|
|
|
$log->LogInfo('====[' . $orderCode . ']====微信扫码支付失败========');
|
|
|
} while (false);
|
|
|
UdpLog::info('【支付】微信扫码支付失败');
|
|
|
}
|
|
|
while (false);
|
|
|
|
|
|
return $result;
|
|
|
}
|
...
|
...
|
@@ -526,17 +479,12 @@ class PayModel |
|
|
|
|
|
do {
|
|
|
// 初始化日志
|
|
|
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
$log->LogInfo('========[' . $payResult->orderCode . ']========');
|
|
|
$log->LogInfo(var_export($payResult, true));
|
|
|
UdpLog::info('【支付】订单支付后续处理','orderCode:'.$payResult->orderCode.'payResult:'.var_export($payResult, true));
|
|
|
|
|
|
$log->LogInfo('==[' . $payResult->orderCode . ']=开始调用获取订单详情方式接口,接口方法为app.SpaceOrders.detail===');
|
|
|
$orderInfo = OrderData::getOrderDetail($uid, $payResult->orderCode);
|
|
|
$log->LogInfo('==[' . $payResult->orderCode . ']=结束调用获取订单详情方式接口,返回结果为===');
|
|
|
$log->LogInfo(var_export($orderInfo, true));
|
|
|
|
|
|
if (!isset($orderInfo['data']) || empty($orderInfo['data'])) {
|
|
|
$log->LogInfo('==[' . $payResult->orderCode . ']=订单支付失败,未获取到订单详情信息===');
|
|
|
UdpLog::info('【支付】订单支付后续处理,未查询到订单信息','orderCode:'.$payResult->orderCode);
|
|
|
break;
|
|
|
}
|
|
|
|
...
|
...
|
@@ -549,12 +497,7 @@ class PayModel |
|
|
if ($orderData['is_cancel'] === 'Y' && $paymentStatus === 'N') {
|
|
|
// 给用户发送短信
|
|
|
// 初始化日志
|
|
|
$log = new PhpLog(self::SEND_MESSAGE_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
$log->LogInfo('===[' . $orderCode . ']===');
|
|
|
$log->LogInfo('==[' . $orderCode . ']=开始调用订单取消时给用户发短信接口,接口方法为app.message.sendMsg===');
|
|
|
$messageReturn = PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
|
|
|
$log->LogInfo('==[' . $orderCode . ']=结束调用给用户发短信接口,返回结果为===');
|
|
|
$log->LogInfo(var_export($messageReturn, true));
|
|
|
PayData::sendMessage($orderData['mobile'], 'error_sms', '支付成功,但订单已取消,订单号为' . $orderCode);
|
|
|
|
|
|
$result['code'] = 417;
|
|
|
$result['message'] = '支付成功,但订单已取消,需联系客服';
|
...
|
...
|
@@ -563,8 +506,7 @@ class PayModel |
|
|
|
|
|
// 支付金额与订单金额不一致
|
|
|
if (round($amount, 2) != round($payResult->totalFee, 2)) {
|
|
|
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
$log->LogInfo('==[' . $orderCode . ']=订单支付失败,支付金额与订单金额不一致===');
|
|
|
UdpLog::info('【支付】订单支付后续处理,订单支付金额不一致','orderCode:'.$orderCode.'account:'.round($amount, 2).'payfee:'.round($payResult->totalFee, 2));
|
|
|
$result['code'] = 415;
|
|
|
$result['message'] = '支付金额与订单金额不一致';
|
|
|
break;
|
...
|
...
|
@@ -577,24 +519,11 @@ class PayModel |
|
|
$bankName = $payResult->bankName;
|
|
|
$bankCode = $payResult->bankCode;
|
|
|
|
|
|
// 初始化日志
|
|
|
$log = new PhpLog(self::ORDER_STATUS_LOG, 'PRC', self::LOG_LEVEL);
|
|
|
$log->LogInfo('===[' . $orderCode . ']===');
|
|
|
|
|
|
$log->LogInfo('==[' . $orderCode . ']=开始调用ERP提交订单状态接口,接口方法为web.SpaceOrders.submitOrderStatus===');
|
|
|
$log->LogInfo('==[' . $orderCode . ']=请求参数为orderCode=' . $orderCode . '===');
|
|
|
// ERP提交订单状态
|
|
|
$erpReturn = PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo);
|
|
|
$log->LogInfo('==[' . $orderCode . ']=结束调用ERP提交订单状态接口,返回结果为===');
|
|
|
$log->LogInfo(var_export($erpReturn, true));
|
|
|
PayData::submitOrderStatus($orderCode, $payment, $bankName, $bankCode, $amount, $payOrderCode, $tradeNo, $bankBillNo);
|
|
|
|
|
|
$log->LogInfo('==[' . $orderCode . ']=开始调用更新订单状态接口,接口方法为web.SpaceOrders.updatePaymentStatus===');
|
|
|
$log->LogInfo('==[' . $orderCode . ']=请求参数为orderId=' . $orderData['order_id'] . 'uid=' . $uid . '===');
|
|
|
// 更新订单的状态
|
|
|
$updateOrderStatus = PayData::updateOrderStatus($orderData['order_id'], $uid, $payment, 'Y', $bankCode);
|
|
|
$log->LogInfo('==[' . $orderCode . ']=结束调用更新订单状态接口,返回结果为===');
|
|
|
$log->LogInfo(var_export($updateOrderStatus, true));
|
|
|
$log->LogInfo('==[' . $orderCode . ']=订单支付成功,请等待发货===');
|
|
|
|
|
|
$result['code'] = 200;
|
|
|
$result['message'] = '支付成功,请等待发货';
|
...
|
...
|
@@ -611,8 +540,10 @@ class PayModel |
|
|
'vipUrl' => Helpers::url('/help', array('category_id' => 91)),
|
|
|
'returnHomeUrl' => Helpers::url('/')
|
|
|
);
|
|
|
} while (false);
|
|
|
}
|
|
|
while (false);
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
|
|
|
|
|
} |
...
|
...
|
|