| @@ -65,18 +65,12 @@ public class WxOrderController extends BaseController { | |||
| WxCUser user = getUser(); | |||
| try { | |||
| WxOrder order = null; | |||
| WxCoupon coupon = wxCouponService.getById(couponId); | |||
| if (coupon == null) { | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| if (wxOrderService.checkCouponIsFree(coupon)) { | |||
| // 免费券 | |||
| order = wxOrderService.saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId()); | |||
| } else { | |||
| // 有价券 | |||
| order = wxOrderService.saveNoFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), isPress, orderSaveDto.getOrderGroupId(), orderSaveDto.getFormId()); | |||
| } | |||
| WxOrder order = wxOrderService.saveOrderForCoupon(user, coupon, orderSaveDto, isPress); | |||
| return new ResultData(order); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -131,7 +131,7 @@ public class WxPayOrderController extends BaseController { | |||
| } | |||
| } else if (status.equals(EnumPayStatus.PAY_STATUS_FAIL.getCode())) { | |||
| // 有价券支付失败 | |||
| wxPayOrderService.handlePayOrderStatusUpdate(payOrder, EnumPayStatus.PAY_STATUS_FAIL.getCode()); | |||
| wxPayOrderService.handlePayOrderFail(payOrder, EnumPayStatus.PAY_STATUS_FAIL.getCode()); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "支付状态更新成功"); | |||
| } catch (MallinkException e) { | |||
| @@ -2,6 +2,7 @@ package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.OrderSaveDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.vo.WxOrderCouponPressVo; | |||
| import com.iformall.domain.vo.WxOrderCouponVo; | |||
| @@ -148,6 +149,15 @@ public interface WxOrderService { | |||
| void updateOrderGroupStatusByCouponChannelId(Long id, String tenantId, Integer code); | |||
| /** | |||
| * 下订单 | |||
| * @param user | |||
| * @param coupon | |||
| * @return | |||
| */ | |||
| WxOrder saveOrderForCoupon(WxCUser user, WxCoupon coupon, OrderSaveDto orderSaveDto, boolean isPress); | |||
| void sendOrderSuccessActionMsg(WxOrder updateOrder); | |||
| /** | |||
| * 订单处理 | |||
| * 1. 检查coupon是否免费 | |||
| @@ -80,7 +80,7 @@ public interface WxPayOrderService { | |||
| * | |||
| * @param record | |||
| */ | |||
| void handlePayOrderStatusUpdate(WxPayOrder record, int status); | |||
| void handlePayOrderFail(WxPayOrder record, int status); | |||
| /** | |||
| * 支付状态处理(免费券) | |||
| @@ -160,12 +160,20 @@ public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||
| }).collect(Collectors.toList()); | |||
| // 已成功订单,用户领取couponOrder | |||
| for (WxOrder temp : list) { | |||
| // 下订单成功 | |||
| try { | |||
| wxOrderService.couponOrderSuccess(temp); | |||
| } catch (Exception e) { | |||
| logger.error("创建COUPON_ORDER失败", e); | |||
| throw new MallinkException(ErrorCode.ORDER_GROUP_COOPERATING_FAILD); | |||
| } | |||
| // 下订单完成,发送内部消息 | |||
| try { | |||
| wxOrderService.sendOrderSuccessActionMsg(temp); | |||
| } catch (Exception e) { | |||
| logger.error("内部消息发送失败: " + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.MSG_INSIDE_ERROR); | |||
| } | |||
| } | |||
| // 拼团成功后,取消待支付订单 | |||
| wxOrder.setOrderStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING_UNPAID.getCode()); | |||
| @@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.dto.OrderSaveDto; | |||
| import com.iformall.domain.dto.WxSharingOrderDto; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.domain.po.msg.FmInsideOrderSuccessMsg; | |||
| @@ -651,7 +652,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| updateT.setUpdateDate(currentDate); | |||
| int ret = 0; | |||
| try { | |||
| wxOrderMapper.updateByPrimaryKeySelective(updateT); | |||
| ret = wxOrderMapper.updateByPrimaryKeySelective(updateT); | |||
| } catch (Exception e) { | |||
| logger.error("订单更新失败:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||
| @@ -665,13 +666,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| } | |||
| // 下订单完成,发送内部消息 | |||
| try { | |||
| sendInsideOrderSuccessMsg(updateOrder, coupon, user); | |||
| } catch (Exception e) { | |||
| logger.error("内部消息发送失败: " + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.MSG_INSIDE_ERROR); | |||
| } | |||
| return ret; | |||
| } | |||
| @@ -685,6 +680,27 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| mqBaseProducer.sendMessage(orderSuccess, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| } | |||
| @Override | |||
| public void sendOrderSuccessActionMsg(WxOrder updateOrder) { | |||
| // 检查券相关 | |||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(updateOrder.getProductId()); | |||
| if (coupon == null) { | |||
| logger.error("券不存在, couponId: " + updateOrder.getProductId()); | |||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| if (coupon.getStatus() == EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()) { | |||
| logger.error("券已下架, couponId: " + updateOrder.getProductId()); | |||
| throw new MallinkException(ErrorCode.COUPON_IS_TAKE_OFF); | |||
| } | |||
| // 检查用户 | |||
| WxCUser user = wxCUserMapper.selectByPrimaryKey(updateOrder.getcUserId()); | |||
| if (user == null) { | |||
| logger.error("用户不存在, userId: " + updateOrder.getcUserId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| sendInsideOrderSuccessMsg(updateOrder, coupon, user); | |||
| } | |||
| /** | |||
| * 下订单后操作 | |||
| * @param updateOrder | |||
| @@ -1148,6 +1164,28 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| wxOrderMapper.updateStatusByPressCouponId(updateOrder); | |||
| } | |||
| @Override | |||
| public WxOrder saveOrderForCoupon(WxCUser user, WxCoupon coupon, OrderSaveDto orderSaveDto, boolean isPress) { | |||
| WxOrder order = null; | |||
| if (checkCouponIsFree(coupon)) { | |||
| // 免费券 | |||
| order = saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId()); | |||
| if(order != null) { | |||
| // 6. 下订单完成,发送内部消息 | |||
| try { | |||
| sendInsideOrderSuccessMsg(order, coupon, user); | |||
| } catch (Exception e) { | |||
| logger.error("内部消息发送失败: " + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.MSG_INSIDE_ERROR); | |||
| } | |||
| } | |||
| } else { | |||
| // 有价券 | |||
| order = saveNoFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), isPress, orderSaveDto.getOrderGroupId(), orderSaveDto.getFormId()); | |||
| } | |||
| return order; | |||
| } | |||
| @Override | |||
| public boolean checkCouponIsFree(WxCoupon coupon) { | |||
| return coupon.getSalePrice() == 0; | |||
| @@ -1200,14 +1238,6 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| logger.error("couponOrder失败:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| } | |||
| // 6. 下订单完成,发送内部消息 | |||
| try { | |||
| sendInsideOrderSuccessMsg(record, coupon, user); | |||
| } catch (Exception e) { | |||
| logger.error("内部消息发送失败: " + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.MSG_INSIDE_ERROR); | |||
| } | |||
| return record; | |||
| } | |||
| @@ -1209,6 +1209,13 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新"); | |||
| } | |||
| // 下订单完成,发送内部消息 | |||
| try { | |||
| wxOrderService.sendOrderSuccessActionMsg(order); | |||
| } catch (Exception e) { | |||
| logger.error("内部消息发送失败: " + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.MSG_INSIDE_ERROR); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| @@ -1344,7 +1351,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void handlePayOrderStatusUpdate(WxPayOrder record, int status) { | |||
| public void handlePayOrderFail(WxPayOrder record, int status) { | |||
| // 判断支付状态 | |||
| if (record.getPayOrderStatus() == EnumPayStatus.PAY_STATUS_WAIT.getCode()) { | |||
| logger.error("pay handle, payOrder " + record.getPayOrderNo() + | |||
| @@ -1367,6 +1374,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| if (order.getPayment() > 0) { | |||
| // 订单金额不为0时, 支付订单未创建, 返回异常 | |||
| if (!(record.getId() > 0)) { | |||
| logger.error("支付订单未创建, 订单ID:" + order.getId()); | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); | |||
| } | |||
| } | |||
| @@ -1422,8 +1430,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| // 修改订单状态 | |||
| if (record.getPayOrderStatus() == EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) { | |||
| /* | |||
| try { | |||
| int _count = wxOrderService.couponOrderSuccess(order); | |||
| if (_count > 1) { | |||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||
| @@ -1432,6 +1440,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新"); | |||
| } | |||
| */ | |||
| } else if (record.getPayOrderStatus() == EnumPayStatus.PAY_STATUS_CANCEL.getCode()) { | |||
| try { | |||
| int _count = wxOrderService.updateOrderStatus(order, EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL); | |||