浏览代码

取消订单 退款 优惠券为未使用

bihs 2 周之前
父节点
当前提交
52c99a2d54

+ 16 - 8
qmjszx-admin/src/main/java/beilv/web/controller/carinformation/CardAppController.java

@@ -38,6 +38,7 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.StringRedisTemplate;
 import org.springframework.stereotype.Controller;
@@ -97,6 +98,7 @@ public class CardAppController extends BaseController {
 
     /**
      * 新增充值记录(已废弃,请使用 addOrderLog)
+     *
      * @deprecated 使用 addOrderLog 替代
      */
     @Deprecated
@@ -117,7 +119,7 @@ public class CardAppController extends BaseController {
      * - orderType="cansai": 参赛订单
      * - orderType="menpiao": 门票订单
      * - 其他类型...
-     * 
+     * <p>
      * 如果是微信支付,会自动调用微信统一下单接口并返回支付参数
      */
     @PostMapping("/addOrderLog")
@@ -156,7 +158,7 @@ public class CardAppController extends BaseController {
             if (!validateOrder(vipCardLog)) {
                 return AjaxResult.error("订单验证失败");
             }
-            
+
             //只有微信支付才开启订单定时任务
             if ("weChart".equals(vipCardLog.getPaymentType())) {
                 //开启订单的定时任务, 超过设定的时间则设置为取消订单
@@ -172,7 +174,7 @@ public class CardAppController extends BaseController {
 
         //写入订单表
         AjaxResult result = insertVipCardLog(vipCardLog, uuid);
-        
+
         // 如果是微信支付,自动调用微信统一下单接口
         if ("weChart".equals(vipCardLog.getPaymentType()) && result.isSuccess()) {
             try {
@@ -183,7 +185,7 @@ public class CardAppController extends BaseController {
                 appPayParam.setTotalPrice(vipCardLog.getOriginalPrice());
                 appPayParam.setPayPrice(vipCardLog.getPracticalMoney());
                 appPayParam.setDescription(getOrderDescription(vipCardLog.getOrderType()));
-                
+
                 // 调用微信统一下单
                 AjaxResult payResult = payController.unifiedOrder(appPayParam);
                 if (payResult.isSuccess()) {
@@ -201,7 +203,7 @@ public class CardAppController extends BaseController {
                 return AjaxResult.error("调用微信统一下单异常: " + e.getMessage());
             }
         }
-        
+
         // 非微信支付直接返回订单创建结果
         return result;
     }
@@ -307,9 +309,13 @@ public class CardAppController extends BaseController {
         startPage();
         List<CarInformation> list = carInformationService.selectCarInformationList(carInformation);
         //查询会员等级
-        String vipLevel = vipCardService.selectVipCardByUserId(carInformation.getUserId()).getVipLevel();
+        String vipLevel = null;
+        VipCard vipCard = vipCardService.selectVipCardByUserId(carInformation.getUserId());
+        if (ObjectUtils.isNotEmpty(vipCard)) {
+            vipLevel = vipCard.getVipLevel();
+        }
         //查询会员折扣
-        BigDecimal coefficient = BigDecimal.valueOf(Double.parseDouble(StringUtils.isEmpty(configService.selectConfigByKey(vipLevel)) ? "1" : configService.selectConfigByKey(vipLevel)));
+        BigDecimal coefficient = BigDecimal.valueOf(Double.parseDouble(StringUtils.isEmpty(vipLevel) ? "1" : configService.selectConfigByKey(vipLevel)));
         list.forEach(carInformation1 -> carInformation1.setMemberPrice(carInformation1.getOriginalPrice().multiply(coefficient).setScale(2, RoundingMode.HALF_UP)));
         return AjaxResult.success(getDataTable(list).getRows());
     }
@@ -318,7 +324,9 @@ public class CardAppController extends BaseController {
     @ResponseBody
     public AjaxResult getVipCardInfo(@RequestBody VipCardLog vipCardLog) {
         VipCard vipCard = vipCardService.selectVipCardByUserId(vipCardLog.getUserId());
-        vipCard.setVipLevel(DictUtils.getDictLabel("vip_level", vipCard.getVipLevel()));
+        if (ObjectUtils.isNotEmpty(vipCard)) {
+            vipCard.setVipLevel(DictUtils.getDictLabel("vip_level", vipCard.getVipLevel()));
+        }
         return AjaxResult.success(vipCard);
     }
 

+ 8 - 3
qmjszx-admin/src/main/java/beilv/web/controller/stadium/StadiumController.java

@@ -17,10 +17,12 @@ import beilv.stadium.domain.StadiumBO;
 import beilv.stadium.service.IStadiumService;
 import beilv.system.domain.SysNotice;
 import beilv.system.service.ISysConfigService;
+import beilv.vipCard.domain.VipCard;
 import beilv.vipCard.service.IVipCardService;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
 import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang3.ObjectUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -59,10 +61,13 @@ public class StadiumController extends BaseController {
         Map<String, String> competitionType = DictUtils.getDictCacheToMap("competition_type");
         Map<String, String> competitionState = DictUtils.getDictCacheToMap("competition_state");
 
-
-        String vipLevel = vipCardService.selectVipCardByUserId(competition.getUserId()).getVipLevel();
+        String vipLevel = null;
+        VipCard vipCard = vipCardService.selectVipCardByUserId(competition.getUserId());
+        if (ObjectUtils.isNotEmpty(vipCard)) {
+            vipLevel = vipCard.getVipLevel();
+        }
         //查询会员折扣
-        BigDecimal coefficient = BigDecimal.valueOf(Double.parseDouble(StringUtils.isEmpty(configService.selectConfigByKey(vipLevel))? "1" : configService.selectConfigByKey(vipLevel)));
+        BigDecimal coefficient = BigDecimal.valueOf(Double.parseDouble(StringUtils.isEmpty(vipLevel)? "1" : configService.selectConfigByKey(vipLevel)));
         list.forEach(competition1 -> {
             competition1.setCompetitionPrice(new PriceOptions(competition1.getCompetitionExpense(), coefficient));
             competition1.setViewingPrice(new PriceOptions(competition1.getViewingTicket(), coefficient));

+ 2 - 2
qmjszx-admin/src/main/resources/application.yml

@@ -164,9 +164,9 @@ wx:
     publicKeyId: PUB_KEY_ID_0117303822532025111100191793000600
     appSecret: 228a6905484fbf9c3e571962c92c7e7e
     # 异步通知地址(必需)
-    notifyUrl: http://q8c22982.natappfree.cc/app/pay/notify
+    notifyUrl: http://p9d766c9.natappfree.cc/app/pay/notify
     # 退款异步通知地址
-    refundNotifyUrl: http://q8c22982.natappfree.cc/app/notify/refund
+    refundNotifyUrl: http://p9d766c9.natappfree.cc/app/notify/refund
 # 海康获取直播视频流配置
 hik:
   appKey: "28356728"

+ 6 - 4
qmjszx-admin/src/main/resources/templates/voucher/member/water.html

@@ -37,19 +37,21 @@
                 },
                 {
                     field: 'username',
-                    title: '用户名称',
-                    visible: false
+                    title: '用户名称'
                 },
                 {
                     field: 'voucherName',
-                    title: '代金券名称',
-                    visible: false
+                    title: '代金券名称'
                 },
                 {
                     field: 'voucherPrice',
                     title: '代金券金额'
                 },
                 {
+                    field: 'instantDiscount',
+                    title: '满多少金额立减'
+                },
+                {
                     field: 'validityTime',
                     title: '有效期',
                     formatter: function(value, row, index) {

+ 38 - 21
qmjszx-business/src/main/java/beilv/vipCardLog/service/impl/VipCardLogServiceImpl.java

@@ -24,6 +24,7 @@ import beilv.vipCardLog.domain.VipCardLog;
 import beilv.vipCardLog.mapper.VipCardLogMapper;
 import beilv.vipCardLog.service.IVipCardLogService;
 import beilv.voucher.domain.BeilvVoucherMember;
+import beilv.voucher.mapper.BeilvVoucherMemberMapper;
 import org.apache.commons.collections4.MapUtils;
 import org.checkerframework.checker.units.qual.A;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -77,6 +78,9 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
     @Autowired
     private StringRedisTemplate stringRedisTemplate;
 
+    @Autowired
+    private BeilvVoucherMemberMapper beilvVoucherMemberMapper;
+
     /**
      * 查询充值记录
      *
@@ -175,7 +179,7 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
      * 充值回调
      *
      * @param vipCardLog 订单请求信息
-     * @param orderInfo 原订单信息
+     * @param orderInfo  原订单信息
      * @return
      */
     private void charging(VipCardLog vipCardLog, VipCardLog orderInfo) {
@@ -189,20 +193,20 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
             String vipCardId;
             if (null == vipCard) {
                 //true 没有会员卡; 新增会员卡, 并且设置本次充值金额
-                vipCardId = vipCardService.insertVipCard(new VipCard(Long.parseLong(orderInfo.getUserId()), orderInfo.getPracticalMoney(), BigDecimal.ZERO));
+                vipCardId = vipCardService.insertVipCard(new VipCard(Long.parseLong(orderInfo.getUserId()), orderInfo.getOriginalPrice(), BigDecimal.ZERO));
             } else {
                 balance = vipCard.getBalance();
                 vipCardId = vipCard.getId();
                 //false 有会员卡,
-                vipCardService.updateVipCard(new VipCard(Long.parseLong(orderInfo.getUserId()), orderInfo.getPracticalMoney().add(vipCard.getBalance()).setScale(2, RoundingMode.HALF_UP), vipCard.getScore()));
+                vipCardService.updateVipCard(new VipCard(Long.parseLong(orderInfo.getUserId()), orderInfo.getOriginalPrice().add(vipCard.getBalance()).setScale(2, RoundingMode.HALF_UP), vipCard.getScore()));
             }
             //设定支付时间
             vipCardLog.setPaymentTime(DateUtils.getNowDate());
             //写入会员卡流水
-            insertAmountLog(new VipCardAmountLog(orderInfo.getUserId(), vipCardId, orderInfo.getId(), balance, orderInfo.getPracticalMoney(),"1"));
+            insertAmountLog(new VipCardAmountLog(orderInfo.getUserId(), vipCardId, orderInfo.getId(), balance, orderInfo.getOriginalPrice(), "1"));
 
             //支付成功移除定时任务
-            stringRedisTemplate.delete(ORDER_QUEUE+orderInfo.getId());
+            stringRedisTemplate.delete(ORDER_QUEUE + orderInfo.getId());
         } else if ("payment_status_cancelled".equals(vipCardLog.getPaymentStatus())) {
             //如果是取消, 设置支付状态为取消支付
             vipCardLog.setCancellationTime(DateUtils.getNowDate());
@@ -231,7 +235,7 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
                 userMembershipCardService.insertUserMembershipCard(new UserMembershipCard(orderInfo.getUserId(), vipCardLog.getId(), carInformation.getTotalNumber(), "0", "3", DateUtils.getNowDate(), orderInfo.getBusId()));
             }
 
-            if("yueqiu".equals(orderType)){
+            if ("yueqiu".equals(orderType)) {
                 //如果是约球订单
                 AdmissionTicket admissionTicket = new AdmissionTicket();
                 admissionTicket.setId(orderInfo.getBusId());
@@ -260,8 +264,8 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
     public AjaxResult refundById(VipCardLog vipCardLog, boolean isOnline, boolean executeUpdate) {
 
 
-        if(StringUtils.isEmpty(vipCardLog.getId())){
-           return AjaxResult.error("订单编号不能为空!");
+        if (StringUtils.isEmpty(vipCardLog.getId())) {
+            return AjaxResult.error("订单编号不能为空!");
         }
 
         //拉去订单信息
@@ -367,6 +371,8 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
             }
             //计算退款金额
             refundPrice = refundPrice.add(orderInfo.getPracticalMoney());
+        } else if ("chongzhi".equals(orderInfo.getOrderType())) {
+            refundPrice = orderInfo.getPracticalMoney();
         }
 
         vipCardLog.setRefundPrice(refundPrice);
@@ -374,7 +380,7 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
 
         // executeUpdate=true 时才执行更新操作(包括订单状态、会员卡余额、次卡次数等)
         if (executeUpdate) {
-            if("vipCard".equals(orderInfo.getPaymentType())){
+            if ("vipCard".equals(orderInfo.getPaymentType())) {
                 //查询会员卡信息
                 VipCard vipCard = vipCardService.selectVipCardById(orderInfo.getPaymentId());
                 //写入会员卡流水
@@ -390,6 +396,14 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
                 userMembershipCard.setRemainingNumber(userMembershipCard.getRemainingNumber() + refundSum);
                 //更新次卡信息
                 userMembershipCardService.updateUserMembershipCard(userMembershipCard);
+            } else if ("chongzhi".equals(orderInfo.getOrderType())) {
+                VipCard vipCard = vipCardService.selectVipCardByUserId(orderInfo.getUserId());
+                // 检查余额是否足够退款
+                if (vipCard.getBalance().compareTo(orderInfo.getOriginalPrice()) < 0) {
+                    return AjaxResult.error("会员卡余额不足,无法完成退款,请前往柜台联系客服!");
+                }
+                vipCard.setBalance(vipCard.getBalance().subtract(orderInfo.getOriginalPrice()));
+                vipCardService.updateVipCard(vipCard);
             }
 
             vipCardLog.setRefundTime(DateUtils.getNowDate());
@@ -403,12 +417,15 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
                 admissionTicket.setAdmissionTicketStatus("0");
                 ticketService.updateBeilvAdmissionTicket(admissionTicket);
             }
-
+            //如果使用了优惠券,释放优惠券
+            if (StringUtils.isNotEmpty(orderInfo.getVoucherId())) {
+                beilvVoucherMemberMapper.updateBeilvVoucherMember(new BeilvVoucherMember(Long.parseLong(orderInfo.getVoucherId()), "1"));
+            }
             return AjaxResult.success("退款成功!");
         }
 
         // executeUpdate=false 时只返回计算结果,不更新任何状态
-        if ("weChart".equals(orderInfo.getPaymentType())){
+        if ("weChart".equals(orderInfo.getPaymentType())) {
             return AjaxResult.success(orderInfo);
         }
         return AjaxResult.success("退款金额计算成功!");
@@ -424,10 +441,10 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
 
         List<Map<String, Object>> maps = vipCardLogMapper.selectYueQiuList(vipCardLog);
 
-        maps.forEach(map->{
-            map.put("orderTypeLabel", MapUtils.getString(orderType, MapUtils.getString(map,"orderType")));
-            map.put("paymentStatusLabel", MapUtils.getString(paymentStatus, MapUtils.getString(map,"paymentStatus")));
-            map.put("paymentTypeLabel", MapUtils.getString(paymentType, MapUtils.getString(map,"paymentType")));
+        maps.forEach(map -> {
+            map.put("orderTypeLabel", MapUtils.getString(orderType, MapUtils.getString(map, "orderType")));
+            map.put("paymentStatusLabel", MapUtils.getString(paymentStatus, MapUtils.getString(map, "paymentStatus")));
+            map.put("paymentTypeLabel", MapUtils.getString(paymentType, MapUtils.getString(map, "paymentType")));
             map.put("createTime", MapUtils.getString(map, "createTime").replace("T", " "));
             map.put("paymentTime", MapUtils.getString(map, "paymentTime").replace("T", " "));
         });
@@ -442,11 +459,11 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
         Map<String, String> competitionState = DictUtils.getDictCacheToMap("competition_state");
         Map<String, String> paymentStatus = DictUtils.getDictCacheToMap("payment_status");
 
-        maps.forEach(map->{
-            map.put("orderTypeLabel", MapUtils.getString(orderType, MapUtils.getString(map,"orderType")));
-            map.put("paymentTypeLabel", MapUtils.getString(paymentType, MapUtils.getString(map,"paymentType")));
-            map.put("competitionStateLabel", MapUtils.getString(competitionState, MapUtils.getString(map,"competitionState")));
-            map.put("paymentStatusLabel", MapUtils.getString(paymentStatus, MapUtils.getString(map,"paymentStatus")));
+        maps.forEach(map -> {
+            map.put("orderTypeLabel", MapUtils.getString(orderType, MapUtils.getString(map, "orderType")));
+            map.put("paymentTypeLabel", MapUtils.getString(paymentType, MapUtils.getString(map, "paymentType")));
+            map.put("competitionStateLabel", MapUtils.getString(competitionState, MapUtils.getString(map, "competitionState")));
+            map.put("paymentStatusLabel", MapUtils.getString(paymentStatus, MapUtils.getString(map, "paymentStatus")));
             map.put("publishTime", MapUtils.getString(map, "publishTime").replace("T", " "));
             map.put("applyEndTime", MapUtils.getString(map, "applyEndTime").replace("T", " "));
             map.put("applyStartTime", MapUtils.getString(map, "applyStartTime").replace("T", " "));
@@ -456,7 +473,7 @@ public class VipCardLogServiceImpl implements IVipCardLogService {
         return maps;
     }
 
-    public void insertAmountLog(VipCardAmountLog vipCardAmountLog){
+    public void insertAmountLog(VipCardAmountLog vipCardAmountLog) {
         amountLogMapper.insertVipCardAmountLog(vipCardAmountLog);
     }
 }

+ 4 - 1
qmjszx-business/src/main/resources/mapper/vipCardLog/VipCardLogMapper.xml

@@ -21,11 +21,12 @@
         <result property="memberPrice" column="member_price"/>
         <result property="paymentId" column="payment_id"/>
         <result property="voucherPrice" column="voucher_price"/>
+        <result property="voucherId" column="voucher_id"/>
     </resultMap>
 
     <sql id="selectVipCardLogVo">
         select a.id, a.user_id, a.bus_id, a.order_type, a.payment_status, a.create_time, a.payment_type, a.payment_time, a.cancellation_time,
-               a.verify_time, a.refund_time, a.practical_money, a.original_price, a.member_price, a.payment_id, a.voucher_price from beilv_vip_card_log a
+               a.verify_time, a.refund_time, a.practical_money, a.original_price, a.member_price, a.payment_id, a.voucher_price,a.voucher_id from beilv_vip_card_log a
     </sql>
 
     <select id="selectVipCardLogList" parameterType="VipCardLog" resultMap="VipCardLogResult">
@@ -76,6 +77,7 @@
             <if test="paymentId != null">payment_id,</if>
             <if test="competitionName != null">competition_name,</if>
             <if test="competitionMobile != null">competition_mobile,</if>
+            <if test="voucherId != null and voucherId != ''">voucher_id,</if>
             <if test="voucherPrice != null">voucher_price,</if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -96,6 +98,7 @@
             <if test="paymentId != null">#{paymentId},</if>
             <if test="competitionName != null">#{competitionName},</if>
             <if test="competitionMobile != null">#{competitionMobile},</if>
+            <if test="voucherId != null and voucherId != ''">#{voucherId},</if>
             <if test="voucherPrice != null">#{voucherPrice},</if>
         </trim>
     </insert>

+ 15 - 13
qmjszx-pay/src/main/java/beilv/wx/pay/service/IWxPayService.java

@@ -11,20 +11,16 @@ import beilv.system.domain.SysMember;
 import beilv.system.service.ISysMemberService;
 import beilv.vipCardLog.domain.VipCardLog;
 import beilv.vipCardLog.service.IVipCardLogService;
+import beilv.voucher.domain.BeilvVoucherMember;
+import beilv.voucher.mapper.BeilvVoucherMemberMapper;
 import beilv.wx.pay.config.WxPayProperties;
 import beilv.wx.pay.domain.vo.AppPayParam;
 import beilv.wx.pay.domain.vo.AppRefundParam;
 import com.github.binarywang.wxpay.bean.notify.SignatureHeader;
-import com.github.binarywang.wxpay.bean.notify.WxPayNotifyV3Response;
 import com.github.binarywang.wxpay.bean.notify.WxPayNotifyV3Result;
 import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyV3Result;
-import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryRequest;
-import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryV3Request;
 import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request;
 import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderV3Request;
-import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
-import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
-import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryV3Result;
 import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result;
 import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderV3Result.JsapiResult;
 import com.github.binarywang.wxpay.bean.result.enums.TradeTypeEnum;
@@ -33,11 +29,9 @@ import com.github.binarywang.wxpay.exception.WxPayException;
 import com.github.binarywang.wxpay.service.WxPayService;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.lang3.ObjectUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.StringRedisTemplate;
-import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 
 import javax.servlet.http.HttpServletRequest;
@@ -45,8 +39,6 @@ import java.math.BigDecimal;
 import java.math.RoundingMode;
 import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.Set;
-import java.util.UUID;
 
 @Slf4j
 @Service
@@ -69,7 +61,8 @@ public class IWxPayService {
     private StringRedisTemplate redisTemplate;
     @Autowired
     private IVipCardLogService vipCardLogService;
-
+    @Autowired
+    private BeilvVoucherMemberMapper beilvVoucherMemberMapper;
     private WxPayService wxService;
 
 
@@ -335,7 +328,7 @@ public class IWxPayService {
         request.setReason(param.getReason());
         WxPayRefundV3Request.Amount amount = new WxPayRefundV3Request.Amount();
         //原订单实际支付金额(单位:分)
-        amount.setTotal(yuanToFen(param.getTotalPrice()));
+        amount.setTotal(yuanToFen(param.getRefundAmount()));
         //退款金额(单位:分)
         amount.setRefund(yuanToFen(param.getRefundAmount()));
         //货币类型,默认 "CNY"
@@ -515,7 +508,11 @@ public class IWxPayService {
                         } else {
                             log.warn("订单 {} 不存在", orderId);
                         }
-
+                        //如果使用了优惠券,释放优惠券
+                        VipCardLog orderInfo = vipCardLogService.selectVipCardLogById(orderId);
+                        if (StringUtils.isNotEmpty(orderInfo.getVoucherId())) {
+                            beilvVoucherMemberMapper.updateBeilvVoucherMember(new BeilvVoucherMember(Long.parseLong(orderInfo.getVoucherId()), "1"));
+                        }
                         // 从延迟队列中移除订单
                         redisTemplate.opsForZSet().remove(ORDER_DELAY_QUEUE_PREFIX + "orders", orderId);
                         log.info("超时订单 {} 处理完成", orderId);
@@ -539,6 +536,11 @@ public class IWxPayService {
         StoreOrder order = storeOrderMapper.selectStoreOrderByOrderId(orderId);
         order.setStatus(3); // 3表示已取消
         order.setUpdateTime(new Date());
+        //如果使用了优惠券,释放优惠券
+        VipCardLog orderInfo = vipCardLogService.selectVipCardLogById(orderId);
+        if (StringUtils.isNotEmpty(orderInfo.getVoucherId())) {
+            beilvVoucherMemberMapper.updateBeilvVoucherMember(new BeilvVoucherMember(Long.parseLong(orderInfo.getVoucherId()), "1"));
+        }
         return storeOrderMapper.updateStoreOrder(order);
     }