Selaa lähdekoodia

余额支付打通

shish 6 vuotta sitten
vanhempi
commit
26d8a89aca
2 muutettua tiedostoa jossa 16 lisäystä ja 11 poistoa
  1. 13 10
      app/client/controllers/OrderController.php
  2. 3 1
      common/services/xhPayToolService.php

+ 13 - 10
app/client/controllers/OrderController.php

@@ -43,14 +43,14 @@ class OrderController extends BaseController
 		}
 		//确认是否要配送的商品
 		$needSend = isset($goodsInfo['needSend']) && $goodsInfo['needSend'] == 1 ? 1 : 0;
-
+		
 		$post['userId'] = $this->userId;
 		$user = $this->user;
 		$post['bookName'] = isset($user['userName']) ? $user['userName'] : '';
 		$bookMobile = isset($post['bookMobile']) && !empty($post['bookMobile']) && stringUtil::isMobile($post['bookMobile']) ? $post['bookMobile'] : '';
 		$bookMobile = empty($bookMobile) && isset($user['mobile']) && !empty($user['mobile']) ? $user['mobile'] : $bookMobile;
 		$post['bookMobile'] = $bookMobile;
-
+		
 		$post['payWay'] = $this->isWx == true ? 0 : 1;
 		$defaultShopId = MerchantService::getDefaultShopId($this->merchant);
 		if (empty($defaultShopId)) {
@@ -107,7 +107,6 @@ class OrderController extends BaseController
 		
 		$post['prePrice'] = $prePrice;
 		$post['actPrice'] = $actPrice;
-		dd($post);
 		$order = OrderService::addOrder($post);
 		$orderId = $order['id'];
 		$orderSn = $order['orderSn'];
@@ -156,10 +155,14 @@ class OrderController extends BaseController
 		$typeList = configDict::getConfig('capitalType');
 		$capitalType = $typeList['xhOrder']['id'];
 		$totalFee = $order['actPrice'];
-		xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
-		util::success(['discountAmount' => 9.9, 'discountType' => 0]);
+		$sourceType = 0;
+		$discountData = OrderService::getDiscountPrice(['price' => $totalFee, 'sourceType' => $sourceType, 'couponId' => $couponId, 'userId' => $this->userId]);
+		$actPrice = $discountData['price'];
+		$respond = xhPayToolService::balancePay($orderSn, $actPrice, $capitalType, $couponId);
+		$balance = isset($respond['balance']) ? $respond['balance'] : 0;
+		util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'balance' => $balance]);
 	}
-	
+
 	//获取商城下单要用的微信支付和小程序支付参数 shish 2019.21.3
 	public function actionWxPay()
 	{
@@ -401,15 +404,15 @@ class OrderController extends BaseController
 			//直接将支付宝的html返回给前端
 			echo $result;
 		} elseif ($payWay == 2) {
-			//验证支付密码是否正确
+			//余额支付,验证支付密码是否正确
 			$payPassword = isset($post['payPassword']) ? $post['payPassword'] : 0;
 			$user = UserService::getUserInfo($this->userId, false);
 			UserService::validPayPassword($payPassword, $user);
 			$typeList = configDict::getConfig('capitalType');
 			$capitalType = $typeList['xhOrder']['id'];
-			$totalFee = $order['actPrice'];
-			xhPayToolService::balancePay($orderSn, $totalFee, $capitalType, $couponId);
-			util::success(['discountAmount' => 9.9, 'discountType' => 0]);
+			$respond = xhPayToolService::balancePay($orderSn, $actPrice, $capitalType, $couponId);
+			$balance = isset($respond['balance']) ? $respond['balance'] : 0;
+			util::success(['discountAmount' => $discountData['discountAmount'], 'discountType' => $discountData['discountType'], 'orderSn' => $orderSn, 'orderId' => $orderId, 'balance' => $balance]);
 		} else {
 			util::fail('无效的支付方式');
 		}

+ 3 - 1
common/services/xhPayToolService.php

@@ -68,7 +68,7 @@ class xhPayToolService
 			
 			//使用优惠券
 			CouponClass::useCoupon($couponId);
-
+			
 			$typeList = configDict::getConfig('capitalType');//流水类型列表
 			switch ($capitalType) {
 				case $typeList['xhOrder']['id']://购买商品
@@ -283,6 +283,8 @@ class xhPayToolService
 			
 			$transaction->commit();
 			
+			return ['balance' => $remainBalance];
+			
 		} catch (Exception $e) {
 			$transaction->rollBack();
 			util::fail('支付没有成功');