|
|
@@ -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());
|
|
|
}
|
|
|
}
|