Преглед на файлове

康年堂需求115:释放优惠券占用,解决使用优惠卷后金额计算bug

csy преди 1 ден
родител
ревизия
753d419487

+ 5 - 0
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreOrderScrmMapper.java

@@ -11,6 +11,7 @@ import com.fs.api.vo.OrderListVO;
 import com.fs.company.param.CompanyStatisticsParam;
 import com.fs.course.dto.FsOrderDeliveryNoteDTO;
 import com.fs.his.domain.FsStoreOrder;
+import com.fs.his.domain.FsStorePayment;
 import com.fs.his.dto.FsStoreOrderAmountScrmStatsQueryDto;
 import com.fs.his.vo.FsStoreOrderAmountScrmStatsVo;
 import com.fs.his.vo.FsStoreOrderExcelVO;
@@ -1423,4 +1424,8 @@ public interface FsStoreOrderScrmMapper
 
     @Select("SELECT * FROM fs_store_order_scrm WHERE create_time >= DATE_SUB(NOW(), INTERVAL 30 MINUTE) and status = 0")
     List<FsStoreOrderScrm> selectBankOrder();
+
+    List<FsStoreOrderScrm> getEligibleOrderCoupons(@Param("userId")long userId, @Param("packageId")long packageId);
+
+    List<FsStorePayment> getFsStorePayMentScrm(@Param("orderCodes")List<Long> orderCodes);
 }

+ 60 - 2
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreOrderScrmServiceImpl.java

@@ -3,6 +3,7 @@ package com.fs.hisStore.service.impl;
 import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
 import cn.binarywang.wx.miniapp.bean.shop.request.shipping.*;
 import cn.binarywang.wx.miniapp.bean.shop.response.WxMaOrderShippingInfoGetResponse;
+import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.date.DateTime;
 import cn.binarywang.wx.miniapp.api.WxMaService;
 import cn.hutool.core.net.URLDecoder;
@@ -68,6 +69,7 @@ import com.fs.his.mapper.*;
 import com.fs.his.param.FsStoreOrderSalesParam;
 import com.fs.his.param.FsUserAddIntegralTemplateParam;
 import com.fs.his.service.IFsPrescribeService;
+import com.fs.his.service.IFsStoreOrderService;
 import com.fs.his.service.IFsUserIntegralLogsService;
 import com.fs.his.service.IFsUserWatchService;
 import com.fs.his.utils.ConfigUtil;
@@ -93,8 +95,10 @@ import com.fs.hisapi.param.CreateOrderParam;
 import com.fs.hisapi.param.RecipeDetailParam;
 import com.fs.hisapi.service.HisApiService;
 import com.fs.huifuPay.domain.HuiFuCreateOrder;
+import com.fs.huifuPay.domain.HuiFuQueryOrderResult;
 import com.fs.huifuPay.domain.HuiFuRefundResult;
 import com.fs.huifuPay.domain.HuifuCreateOrderResult;
+import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayQueryRequest;
 import com.fs.huifuPay.sdk.opps.core.request.V2TradePaymentScanpayRefundRequest;
 import com.fs.huifuPay.sdk.opps.core.utils.HuiFuUtils;
 import com.fs.huifuPay.service.HuiFuService;
@@ -1603,8 +1607,62 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         return fsStoreOrderMapper.selectFsStoreOrderTuiListVO(userId);
     }
 
+    /**
+     * 释放优惠券信息
+     * @param userId
+     * @param packageId
+     */
+    private void releaseCoupon(long userId,long packageId){
+        //当用户再次点击立即购买时,首先查询当前用户(user_id)下此时当前订单状态是否为(0待支付),
+        //当前是否为套餐(1),套餐id是多少,且优惠券id不能为空
+        List<FsStoreOrderScrm> eligibleOrderCoupons = fsStoreOrderMapper.getEligibleOrderCoupons(userId,packageId);
+        List<Long> orderCode = eligibleOrderCoupons.stream().filter(Objects::isNull).map(FsStoreOrderScrm::getId).collect(Collectors.toList());
+        List<FsStorePayment> fsStorePaymentList;
+        if (CollectionUtil.isNotEmpty(orderCode)) {
+            fsStorePaymentList = fsStoreOrderMapper.getFsStorePayMentScrm(orderCode);
+            //得到符合条件的订单后,查询汇付是否回调成功
+            List<HuiFuQueryOrderResult> queryOrderResultList = null;
+            //如果支付明细里面没有,直接取消eligibleOrderCoupons以前的未支付订单
+            if (CollectionUtil.isNotEmpty(fsStorePaymentList)){
+                for (int i = 0; i < fsStorePaymentList.size(); i++) {
+                    FsStorePayment fsStorePayment = fsStorePaymentList.get(i);
+                    if (fsStorePayment.getPayMode().equals("hf")) {
+                        V2TradePaymentScanpayQueryRequest request = new V2TradePaymentScanpayQueryRequest();
+                        request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(fsStorePayment.getCreateTime()));
+                        request.setOrgHfSeqId(fsStorePayment.getTradeNo());
+                        request.setAppId(fsStorePayment.getAppId());
+                        HuiFuQueryOrderResult queryOrderResult = null;
+                        try {
+                            queryOrderResult = huiFuService.queryOrder(request);
+                            queryOrderResultList.add(queryOrderResult);
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                        //释放优惠券信息
+                        if (!queryOrderResult.getTrans_stat().equals("S")) {
+                            eligibleOrderCoupons.forEach(n->{
+                                if (n.getId().equals(fsStorePayment.getBusinessId())){
+                                    cancelOrder(n.getId());
+                                    logger.info("优惠券释放成功");
+                                }
+                            });
+                        }
+                    }
+                }
+                logger.info("汇付返回" + queryOrderResultList);
+            }else {
+                eligibleOrderCoupons.forEach(n->{
+                    cancelOrder(n.getId());
+                    logger.info("优惠券释放成功");
+                });
+            }
+        }
+    }
+
+
     @Override
     public R confirmPackageOrder(long uid, FsStoreConfirmPackageIdOrderParam param) {
+        this.releaseCoupon(uid,param.getPackageId());
         FsUserAddressScrm address = userAddressMapper.selectFsUserAddressByDefaultAddress(uid);
         FsStoreProductPackageScrm storeProductPackage = productPackageService.selectFsStoreProductPackageById(param.getPackageId());
         // 由于套餐制单前面有生成oderkey,并且要取修改的价格,所以这里判断,如果有传就用传的orderkey,如果没有就生成(代表走的是直接购买)
@@ -1729,7 +1787,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
             if (param.getCouponUserId() != null) {
                 FsStoreCouponUserScrm couponUser = couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
                 if (couponUser != null && couponUser.getStatus() == 0) {
-                    if (couponUser.getUseMinPrice().compareTo(storeProductPackage.getPayMoney()) == -1) {
+                    if (couponUser.getUseMinPrice().compareTo(storeProductPackage.getPayMoney()) <= 0) {
                         //
                         totalMoney = totalMoney.subtract(couponUser.getCouponPrice());
                         storeOrder.setCouponId(couponUser.getId());
@@ -2958,7 +3016,7 @@ public class FsStoreOrderScrmServiceImpl implements IFsStoreOrderScrmService {
         if (param.getCouponUserId() != null) {
             FsStoreCouponUserScrm couponUser = couponUserService.selectFsStoreCouponUserById(param.getCouponUserId());
             if (couponUser != null && couponUser.getStatus() == 0) {
-                if (couponUser.getUseMinPrice().compareTo(storeProductPackage.getPayMoney()) == -1) {
+                if (couponUser.getUseMinPrice().compareTo(storeProductPackage.getPayMoney()) <= 0) {
                     totalMoney = totalMoney.subtract(couponUser.getCouponPrice());
                 }
             }

+ 27 - 1
fs-service/src/main/resources/mapper/hisStore/FsStoreOrderScrmMapper.xml

@@ -2129,5 +2129,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             #{item.id}
         </foreach>
     </update>
-
+    <select id="getEligibleOrderCoupons" resultType="com.fs.hisStore.domain.FsStoreOrderScrm">
+        SELECT * FROM fs_store_order_scrm
+        WHERE user_id = #{userId}
+          AND `status` = 0
+          AND is_package = 1
+          AND package_id = #{packageId}
+          AND coupon_id IS NOT NULL
+    </select>
+    <select id="getEligibleOrderCoupons" resultType="com.fs.hisStore.domain.FsStoreOrderScrm">
+        SELECT * FROM fs_store_order_scrm
+        WHERE user_id = #{userId}
+          AND `status` = 0
+          AND is_package = 1
+          AND package_id = #{packageId}
+          AND coupon_id IS NOT NULL
+    </select>
+    <select id="getFsStorePayMentScrm" resultType="com.fs.his.domain.FsStorePayment">
+        select * from fs_store_payment_scrm
+        <where>
+            <if test="orderCodes != null and orderCodes.size > 0">
+                business_order_id in
+                <foreach collection="orderCodes" item="orderCode" open="(" close=")" separator=",">
+                    #{orderCode}
+                </foreach>
+            </if>
+        </where>
+    </select>
 </mapper>

+ 2 - 2
fs-user-app/src/main/java/com/fs/app/controller/store/CouponScrmController.java

@@ -128,8 +128,8 @@ public class CouponScrmController extends AppBaseController {
         try {
             param.setUserId(Long.parseLong(getUserId()));
             List<FsStoreCouponUserScrm> list=fsStoreCouponUserService.selectFsStoreCouponUserListByEnable(param);
-            list=list.stream().filter(s->(s.getCouponPrice().compareTo(param.getUseMinPrice())==-1 )).collect(Collectors.toList());
-            list=list.stream().filter(s->(s.getUseMinPrice().compareTo(param.getUseMinPrice())==-1 )).collect(Collectors.toList());
+            list=list.stream().filter(s->(s.getCouponPrice().compareTo(param.getUseMinPrice()) <= 0 )).collect(Collectors.toList());
+            list=list.stream().filter(s->(s.getUseMinPrice().compareTo(param.getUseMinPrice()) <= 0 )).collect(Collectors.toList());
             return R.ok().put("data",list);
         } catch (Exception e){
             return R.error("操作异常");