Browse Source

Merge remote-tracking branch 'origin/master_saas' into master_saas

zouxuan 3 years ago
parent
commit
0c23b043f7

+ 25 - 16
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -1085,18 +1085,22 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             }
         }
 
+
+        // 余额支付
+        BigDecimal amount =  BigDecimal.ZERO;
+        BigDecimal balance = BigDecimal.ZERO;
+
         if (StringUtils.isNotEmpty(model.getOldOrderNo())) {
             StudentPaymentOrder orderByOrderNo = studentPaymentOrderService.findOrderByOrderNo(model.getOldOrderNo());
             if (orderByOrderNo == null) {
                 throw new BizException("未找到原订单");
             }
+            amount = orderByOrderNo.getActualAmount();
+            balance = orderByOrderNo.getBalancePaymentAmount();
             // 已有订单,先关单
             orderByOrderNo.setStatus(CLOSE);
             orderByOrderNo.setMemo("关闭订单");
             studentPaymentOrderService.update(orderByOrderNo);
-            if (orderByOrderNo.getBalancePaymentAmount() != null && orderByOrderNo.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
-                sysUserCashAccountService.updateBalance(orderByOrderNo.getUserId(), orderByOrderNo.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "关闭订单");
-            }
             //退优惠券
             sysCouponCodeService.quit(orderByOrderNo.getCouponCodeId());
         }
@@ -1128,19 +1132,24 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         studentPaymentOrder.setVersion(studentPaymentOrder.getVersion());
 
         // 余额支付
-        BigDecimal amount = studentPaymentOrder.getActualAmount();
-        BigDecimal balance = BigDecimal.ZERO;
-        if (model.isUseBalance() && amount.compareTo(BigDecimal.ZERO) > 0) {
-            SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(model.getUserId());
-            if (userCashAccount == null) {
-                throw new BizException("用户账户不存在");
-            }
-            if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
-                balance = amount.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : amount;
-                amount = amount.subtract(balance);
+        if (model.isUseBalance() && studentPaymentOrder.getActualAmount().compareTo(BigDecimal.ZERO) > 0 ) {
+            if (!StringUtils.isEmpty(model.getOldOrderNo())) {
                 studentPaymentOrder.setActualAmount(amount);
                 studentPaymentOrder.setBalancePaymentAmount(balance);
-                sysUserCashAccountService.updateBalance(model.getUserId(), balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "商品销售");
+            } else {
+                SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(model.getUserId());
+                if (userCashAccount == null) {
+                    throw new BizException("用户账户不存在");
+                }
+                amount = studentPaymentOrder.getActualAmount();
+                if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
+                    balance = amount.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : amount;
+                    amount = amount.subtract(balance);
+                    studentPaymentOrder.setActualAmount(amount);
+                    studentPaymentOrder.setBalancePaymentAmount(balance);
+                    sysUserCashAccountService.updateBalance(model.getUserId(), balance.negate(),
+                                                            PlatformCashAccountDetailTypeEnum.PAY_FEE, "商品销售");
+                }
             }
         }
         studentPaymentOrderService.update(studentPaymentOrder);
@@ -1160,8 +1169,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         studentGoodsSellDao.insert(studentGoodsSell);
 
 
-        if (amount.compareTo(BigDecimal.ZERO) == 0) {
-            studentPaymentRouteOrderService.addRouteOrder(model.getOrderNo(), student.getOrganId(), balance);
+        if (studentPaymentOrder.getActualAmount().compareTo(BigDecimal.ZERO) == 0) {
+            studentPaymentRouteOrderService.addRouteOrder(model.getOrderNo(), student.getOrganId(), studentPaymentOrder.getBalancePaymentAmount());
             Map<String, String> notifyMap = new HashMap<>();
             notifyMap.put("tradeState", "1");
             notifyMap.put("balanceAmount",studentPaymentOrder.getBalancePaymentAmount() == null?"0":studentPaymentOrder.getBalancePaymentAmount().toString());

+ 2 - 1
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/dao/PortalOrderDao.java

@@ -3,6 +3,7 @@ package com.yonge.cooleshow.portal.dao;
 import com.yonge.cooleshow.mbg.model.OmsOrder;
 import com.yonge.cooleshow.mbg.model.OmsOrderItem;
 import com.yonge.cooleshow.portal.domain.OmsOrderDetail;
+import com.yonge.cooleshow.portal.domain.ProductStock;
 import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
@@ -38,7 +39,7 @@ public interface PortalOrderDao {
      */
     int releaseSkuStockLock(@Param("itemList") List<OmsOrderItem> orderItemList);
 
-    int releaseProductStockLock(@Param("itemList") List<OmsOrderItem> orderItemList);
+    int releaseProductStockLock(@Param("itemList") List<ProductStock> orderItemList);
 
     List<OmsOrder> listByAdapayNo(@Param("alapayNoList") List<String> alapayNoList, @Param("adapayNos") String adapayNos);
 }

+ 14 - 1
mec-mall/mall-portal/src/main/java/com/yonge/cooleshow/portal/service/impl/OmsPortalOrderServiceImpl.java

@@ -588,10 +588,23 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
             OmsOrderItemExample orderItemExample = new OmsOrderItemExample();
             orderItemExample.createCriteria().andOrderIdEqualTo(orderId);
             List<OmsOrderItem> orderItemList = orderItemMapper.selectByExample(orderItemExample);
+
             //解除订单商品库存锁定
             if (!CollectionUtils.isEmpty(orderItemList)) {
                 portalOrderDao.releaseSkuStockLock(orderItemList);
-                portalOrderDao.releaseProductStockLock(orderItemList);
+
+                List<ProductStock> productStockList = new ArrayList<>();
+                Map<Long, List<OmsOrderItem>> collect = orderItemList.stream()
+                                                                     .collect(Collectors.groupingBy(
+                                                                             OmsOrderItem::getProductId));
+                collect.forEach((k,v) -> {
+                    ProductStock productStock = new ProductStock();
+                    productStock.setProductId(k);
+                    productStock.setStock(v.size());
+                    productStockList.add(productStock);
+                });
+
+                portalOrderDao.releaseProductStockLock(productStockList);
             }
             //修改优惠券使用状态
             // updateCouponStatus(cancelOrder.getCouponId(), cancelOrder.getMemberId(), 0);

+ 1 - 1
mec-mall/mall-portal/src/main/resources/config/mybatis/PortalOrderDao.xml

@@ -97,7 +97,7 @@
         SET
         lock_stock = CASE id
         <foreach collection="itemList" item="item">
-            WHEN #{item.productId} THEN lock_stock - #{item.productQuantity}
+            WHEN #{item.productId} THEN lock_stock - #{item.stock}
         </foreach>
         END
         WHERE