| @@ -223,6 +223,8 @@ public enum ErrorCode{ | |||||
| COUPON_HANDSEL_VERIFY(4010, "商户发券异常"), | COUPON_HANDSEL_VERIFY(4010, "商户发券异常"), | ||||
| COUPON_MANJIAN_USE_PRICE_NO_ALLOW_(4011, "满减券金额不符合条件"), | COUPON_MANJIAN_USE_PRICE_NO_ALLOW_(4011, "满减券金额不符合条件"), | ||||
| COUPON_ORDER_TYPE_NOT_SUPPORTED(4012, "券类型不支持"), | COUPON_ORDER_TYPE_NOT_SUPPORTED(4012, "券类型不支持"), | ||||
| COUPON_ORDER_SEND_ERROR(4013, "券包发卷失败"), | |||||
| COUPON_ORDER_DATE_ERROR(4014, "券包数据异常"), | |||||
| /** | /** | ||||
| * 商品 | * 商品 | ||||
| @@ -21,7 +21,8 @@ public enum EnumPayWay { | |||||
| PAY_WAY_NOT_UNPAY_BATCH_SEND(96, "后台批量发券,无需支付",null,null,null), | PAY_WAY_NOT_UNPAY_BATCH_SEND(96, "后台批量发券,无需支付",null,null,null), | ||||
| PAY_WAY_NOT_UNPAY_TRADE(97, "交易发券,无需支付",null,null,null), | PAY_WAY_NOT_UNPAY_TRADE(97, "交易发券,无需支付",null,null,null), | ||||
| PAY_WAY_NOT_UNPAY_PASSWD(98, "根据卡密兑换卡,无需支付",null,null,null), | PAY_WAY_NOT_UNPAY_PASSWD(98, "根据卡密兑换卡,无需支付",null,null,null), | ||||
| PAY_WAY_NOT_UNPAY_CREDIT(99, "积分兑换券,无需支付",null,null,null) | |||||
| PAY_WAY_NOT_UNPAY_CREDIT(99, "积分兑换券,无需支付",null,null,null), | |||||
| PAY_WAY_NOT_UNPAY_GIFTLIST(100, "卷包兑换券,无需支付",null,null,null) | |||||
| ; | ; | ||||
| public static EnumPayWay getEnum(Integer code) { | public static EnumPayWay getEnum(Integer code) { | ||||
| @@ -91,7 +91,7 @@ public interface WxOrderService { | |||||
| * @param updateOrder | * @param updateOrder | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| int couponOrderSuccess(WxOrder updateOrder); | |||||
| WxCouponOrder couponOrderSuccess(WxOrder updateOrder); | |||||
| /** | /** | ||||
| * microPayOrderSuccess 刷卡支付成功 | * microPayOrderSuccess 刷卡支付成功 | ||||
| @@ -1290,20 +1290,22 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| throw new MallinkException(ErrorCode.COUPON_IS_NOT_FREE.getCode(), coupon.getTitle() + ErrorCode.COUPON_IS_NOT_FREE.getMessage()); | throw new MallinkException(ErrorCode.COUPON_IS_NOT_FREE.getCode(), coupon.getTitle() + ErrorCode.COUPON_IS_NOT_FREE.getMessage()); | ||||
| } | } | ||||
| if (Objects.nonNull(wxCouponSendVo) && Objects.equals(EnumCouponSendSendType.MERCHANT.getCode(), wxCouponSendVo.getSendType())) { | |||||
| // 商户注券减库存操作 | |||||
| try { | |||||
| stockMerchantReduce(user, coupon, couponIdStr, wxCouponSendVo); | |||||
| }catch(Exception e) { | |||||
| throw new MallinkException(ErrorCode.COUPON_STOCK_ERR.getCode(), e.getMessage()); | |||||
| } | |||||
| } else { | |||||
| // 减库存操作 | |||||
| try { | |||||
| stockReduce(false,user, coupon, couponIdStr,1); | |||||
| }catch(Exception e) { | |||||
| throw new MallinkException(ErrorCode.COUPON_STOCK_ERR.getCode(), e.getMessage()); | |||||
| } | |||||
| if(!EnumPayWay.PAY_WAY_NOT_UNPAY_GIFTLIST.equals(payWay)){ | |||||
| if (Objects.nonNull(wxCouponSendVo) && Objects.equals(EnumCouponSendSendType.MERCHANT.getCode(), wxCouponSendVo.getSendType())) { | |||||
| // 商户注券减库存操作 | |||||
| try { | |||||
| stockMerchantReduce(user, coupon, couponIdStr, wxCouponSendVo); | |||||
| }catch(Exception e) { | |||||
| throw new MallinkException(ErrorCode.COUPON_STOCK_ERR.getCode(), e.getMessage()); | |||||
| } | |||||
| } else { | |||||
| // 减库存操作 | |||||
| try { | |||||
| stockReduce(false,user, coupon, couponIdStr,1); | |||||
| }catch(Exception e) { | |||||
| throw new MallinkException(ErrorCode.COUPON_STOCK_ERR.getCode(), e.getMessage()); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| int payment = coupon.getSalePrice(); | int payment = coupon.getSalePrice(); | ||||
| @@ -1355,7 +1357,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public int couponOrderSuccess(WxOrder updateOrder) { | |||||
| public WxCouponOrder couponOrderSuccess(WxOrder updateOrder) { | |||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| // 检查券相关 | // 检查券相关 | ||||
| WxCoupon coupon = wxCouponMapper.selectById(updateOrder.getProductId(),updateOrder.getTenantId()); | WxCoupon coupon = wxCouponMapper.selectById(updateOrder.getProductId(),updateOrder.getTenantId()); | ||||
| @@ -1392,14 +1394,11 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| // 创建couponOrder | // 创建couponOrder | ||||
| try { | try { | ||||
| createCouponOrder(updateOrder, user, coupon, null,null,null,null); | |||||
| return createCouponOrder(updateOrder, user, coupon, null,null,null,null); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("创建券包:" + e.getMessage()); | logger.error("创建券包:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | ||||
| } | } | ||||
| return ret; | |||||
| } | } | ||||
| private void sendInsideOrderSuccessMsg(WxOrder updateOrder, WxCoupon coupon, WxCUserBasicInfo user) { | private void sendInsideOrderSuccessMsg(WxOrder updateOrder, WxCoupon coupon, WxCUserBasicInfo user) { | ||||
| @@ -896,14 +896,15 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| } else { | } else { | ||||
| // 普通券, 修改订单状态 | // 普通券, 修改订单状态 | ||||
| try { | try { | ||||
| wxOrderService.couponOrderSuccess(order); | |||||
| WxCouponOrder couponOrder = wxOrderService.couponOrderSuccess(order); | |||||
| orderFactory.getOrderAdapterService(record.getComposeOrder()).doOthersAfterPaySuccess(order, record,couponOrder); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新"); | throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新"); | ||||
| } | } | ||||
| orderFactory.getOrderAdapterService(record.getComposeOrder()).doOthersAfterPaySuccess(order, record); | |||||
| // 下订单完成,发送内部消息 | // 下订单完成,发送内部消息 | ||||
| try { | try { | ||||
| wxOrderService.sendOrderSuccessActionMsg(order); | wxOrderService.sendOrderSuccessActionMsg(order); | ||||
| @@ -3,10 +3,7 @@ package com.iformall.service.order; | |||||
| import java.util.List; | import java.util.List; | ||||
| import com.iformall.domain.dto.OrderComposeSaveDto; | import com.iformall.domain.dto.OrderComposeSaveDto; | ||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxOrder; | |||||
| import com.iformall.domain.po.WxPayOrder; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.enums.EnumPayWay; | import com.iformall.enums.EnumPayWay; | ||||
| import com.iformall.service.order.entity.WxComposeChildOrderPrice; | import com.iformall.service.order.entity.WxComposeChildOrderPrice; | ||||
| import com.iformall.service.order.entity.WxComposeOrder; | import com.iformall.service.order.entity.WxComposeOrder; | ||||
| @@ -71,5 +68,5 @@ public interface OrderAdapterService { | |||||
| * @param order | * @param order | ||||
| * @param record | * @param record | ||||
| */ | */ | ||||
| void doOthersAfterPaySuccess(WxOrder order,WxPayOrder record); | |||||
| void doOthersAfterPaySuccess(WxOrder order, WxPayOrder record, WxCouponOrder couponOrder); | |||||
| } | } | ||||
| @@ -3,15 +3,12 @@ package com.iformall.service.order.impl; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.List; | import java.util.List; | ||||
| import com.iformall.domain.po.*; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Propagation; | import org.springframework.transaction.annotation.Propagation; | ||||
| import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
| import com.iformall.domain.dto.OrderComposeSaveDto; | import com.iformall.domain.dto.OrderComposeSaveDto; | ||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxOrder; | |||||
| import com.iformall.domain.po.WxPayOrder; | |||||
| import com.iformall.enums.EnumComposeOrder; | import com.iformall.enums.EnumComposeOrder; | ||||
| import com.iformall.enums.EnumOrderShopingType; | import com.iformall.enums.EnumOrderShopingType; | ||||
| import com.iformall.enums.EnumPayWay; | import com.iformall.enums.EnumPayWay; | ||||
| @@ -87,7 +84,7 @@ public class SingleOrderAdapterService implements OrderAdapterService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void doOthersAfterPaySuccess(WxOrder order, WxPayOrder record) { | |||||
| public void doOthersAfterPaySuccess(WxOrder order, WxPayOrder record, WxCouponOrder couponOrder) { | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -4,6 +4,8 @@ import java.util.ArrayList; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.List; | import java.util.List; | ||||
| import com.iformall.mapper.WxCouponMapper; | |||||
| import com.iformall.mapper.WxCouponOrderMapper; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Propagation; | import org.springframework.transaction.annotation.Propagation; | ||||
| @@ -38,6 +40,13 @@ public abstract class BaseBatchOrderAdapterService implements OrderAdapterServic | |||||
| WxBatchOrderMapper wxBatchOrderMapper; | WxBatchOrderMapper wxBatchOrderMapper; | ||||
| @Autowired | @Autowired | ||||
| WxOrderMapper wxOrderMapper; | WxOrderMapper wxOrderMapper; | ||||
| @Autowired | |||||
| WxCouponOrderMapper wxCouponOrderMapper; | |||||
| @Autowired | |||||
| WxCouponMapper wxCouponMapper; | |||||
| @Autowired | |||||
| WxOrderService wxOrderService; | |||||
| @Override | @Override | ||||
| public WxComposeChildOrderPrice getChildCouponOrderPrice(OrderComposeSaveDto orderdto,WxCoupon coupon,boolean isPress,Long orderGroupId,Integer couponNumber) { | public WxComposeChildOrderPrice getChildCouponOrderPrice(OrderComposeSaveDto orderdto,WxCoupon coupon,boolean isPress,Long orderGroupId,Integer couponNumber) { | ||||
| @@ -1,16 +1,24 @@ | |||||
| package com.iformall.service.order.impl.batch; | package com.iformall.service.order.impl.batch; | ||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| import java.util.Objects; | |||||
| import com.aliyun.openservices.shade.com.alibaba.fastjson.JSON; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.IdWorker; | |||||
| import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import com.iformall.domain.vo.WxCouponSendVo; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.exception.MallinkException; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import org.springframework.transaction.annotation.Propagation; | import org.springframework.transaction.annotation.Propagation; | ||||
| import org.springframework.transaction.annotation.Transactional; | import org.springframework.transaction.annotation.Transactional; | ||||
| import com.iformall.domain.dto.OrderComposeSaveDto; | import com.iformall.domain.dto.OrderComposeSaveDto; | ||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxOrder; | |||||
| import com.iformall.domain.po.WxPayOrder; | |||||
| import com.iformall.enums.EnumComposeOrder; | |||||
| import com.iformall.enums.EnumPayWay; | |||||
| import com.iformall.service.order.entity.WxComposeOrder; | import com.iformall.service.order.entity.WxComposeOrder; | ||||
| /** | /** | ||||
| * 券包批量下单 | * 券包批量下单 | ||||
| @@ -19,6 +27,8 @@ import com.iformall.service.order.entity.WxComposeOrder; | |||||
| */ | */ | ||||
| @Service | @Service | ||||
| public class CouponPackageOrderAdapterService extends BaseBatchOrderAdapterService { | public class CouponPackageOrderAdapterService extends BaseBatchOrderAdapterService { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| @Override | @Override | ||||
| @@ -47,9 +57,54 @@ public class CouponPackageOrderAdapterService extends BaseBatchOrderAdapterServi | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void doOthersAfterPaySuccess(WxOrder order, WxPayOrder record) { | |||||
| //手动核销发券 | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public void doOthersAfterPaySuccess(WxOrder order, WxPayOrder record, WxCouponOrder couponOrder) { | |||||
| WxCoupon wxCoupon = wxCouponMapper.selectById(couponOrder.getCouponId(), couponOrder.getTenantId()); | |||||
| if (wxCoupon == null || !EnumCouponType.COUPON_GIFT.getCode().equals(wxCoupon.getType())) { | |||||
| logger.error("券包: coupon-" + wxCoupon.getId() + "不存在" + "couponOrder-" + couponOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); | |||||
| } | |||||
| if (StringUtils.isBlank(wxCoupon.getGiftList())){ | |||||
| logger.error("券包: coupon-" + wxCoupon.getId() + "数据异常" + "couponOrder-" + couponOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_DATE_ERROR); | |||||
| } | |||||
| if (couponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode()) { | |||||
| logger.error("已过期: couponOrder-" + couponOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME); | |||||
| } | |||||
| if (couponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()) { | |||||
| logger.error("已退款: couponOrder-" + couponOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); | |||||
| } | |||||
| if (couponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) { | |||||
| logger.error("已经核销过的券: couponOrder-" + couponOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); | |||||
| } | |||||
| if (couponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.POS_PRE_VERIFY.getCode()) { | |||||
| logger.error("券已被预核销: couponOrder-" + couponOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_PRE_VERIFY); | |||||
| } | |||||
| //核销券包 | |||||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); //1核销 | |||||
| couponOrder.setVerifyType(EnumCouponVerifyType.VERIFY_C.getCode()); | |||||
| couponOrder.setUpdateDate(new Date()); | |||||
| int num = wxCouponOrderMapper.updateVerifyCouponOrder(couponOrder); | |||||
| if (num != 1) { | |||||
| throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num); | |||||
| } | |||||
| try { | |||||
| List<Long> longs = JSON.parseArray(wxCoupon.getGiftList(), Long.class); | |||||
| //发券包子券 | |||||
| for (Long couponId:longs) { | |||||
| wxOrderService.sendFreeCouponToUser(couponOrder.getCUserId(),couponOrder,couponId,null,EnumPayWay.PAY_WAY_NOT_UNPAY_GIFTLIST,null,null); | |||||
| } | |||||
| } catch (MallinkException e) { | |||||
| throw e; | |||||
| } catch (Exception e){ | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SEND_ERROR.getCode(), couponOrder.getCouponName() + ErrorCode.COUPON_ORDER_SEND_ERROR.getMessage() ); | |||||
| } | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -3,13 +3,10 @@ package com.iformall.service.order.impl.batch; | |||||
| import java.util.List; | import java.util.List; | ||||
| import com.iformall.domain.po.*; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import com.iformall.domain.dto.OrderComposeSaveDto; | import com.iformall.domain.dto.OrderComposeSaveDto; | ||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxOrder; | |||||
| import com.iformall.domain.po.WxPayOrder; | |||||
| import com.iformall.enums.EnumComposeOrder; | import com.iformall.enums.EnumComposeOrder; | ||||
| import com.iformall.enums.EnumPayWay; | import com.iformall.enums.EnumPayWay; | ||||
| import com.iformall.service.order.entity.WxComposeOrder; | import com.iformall.service.order.entity.WxComposeOrder; | ||||
| @@ -44,7 +41,7 @@ public class MulityNumberOneOrderBatchOrderAdapterService extends BaseBatchOrder | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void doOthersAfterPaySuccess(WxOrder order, WxPayOrder record) { | |||||
| public void doOthersAfterPaySuccess(WxOrder order, WxPayOrder record, WxCouponOrder couponOrder) { | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -2,13 +2,10 @@ package com.iformall.service.order.impl.batch; | |||||
| import java.util.List; | import java.util.List; | ||||
| import com.iformall.domain.po.*; | |||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import com.iformall.domain.dto.OrderComposeSaveDto; | import com.iformall.domain.dto.OrderComposeSaveDto; | ||||
| import com.iformall.domain.po.WxCUserBasicInfo; | |||||
| import com.iformall.domain.po.WxCoupon; | |||||
| import com.iformall.domain.po.WxOrder; | |||||
| import com.iformall.domain.po.WxPayOrder; | |||||
| import com.iformall.enums.EnumComposeOrder; | import com.iformall.enums.EnumComposeOrder; | ||||
| import com.iformall.enums.EnumPayWay; | import com.iformall.enums.EnumPayWay; | ||||
| import com.iformall.service.order.entity.WxComposeOrder; | import com.iformall.service.order.entity.WxComposeOrder; | ||||
| @@ -43,7 +40,7 @@ public class OneNumberOneOrderBatchOrderAdapterService extends BaseBatchOrderAda | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void doOthersAfterPaySuccess(WxOrder order, WxPayOrder record) { | |||||
| public void doOthersAfterPaySuccess(WxOrder order, WxPayOrder record, WxCouponOrder couponOrder) { | |||||
| } | } | ||||