| @@ -169,6 +169,100 @@ public class WxOrderController extends BaseController { | |||||
| } | } | ||||
| } | } | ||||
| WxCUser user = getUser(); | |||||
| try { | |||||
| WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId, isPress, orderGroupId, formId); | |||||
| return new ResultData(order); | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.ORDER_IS_FAIL, e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\",\"formId\":\"String\"}") | |||||
| @PostMapping("save_new") | |||||
| public ResultData saveOrderNew(@RequestBody Map<String, String> paramMap) { | |||||
| logger.info("OrderSave: " + paramMap.toString()); | |||||
| //Assert.notNull(wxOrders.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| String couponChannelIdStr = paramMap.get("couponChannelId"); | |||||
| String couponIdStr = paramMap.get("couponId"); | |||||
| String pressStr = paramMap.get("press"); | |||||
| String orderGroupIdStr = paramMap.get("orderGroupId"); | |||||
| String formId = paramMap.get("formId"); | |||||
| if (StringUtils.isBlank(couponChannelIdStr)) { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); | |||||
| } | |||||
| Long couponChannelId = 0L, couponId = 0L, orderGroupId = null; | |||||
| boolean isPress = false; | |||||
| if (StringUtils.isNotBlank(couponChannelIdStr)) { | |||||
| try { | |||||
| couponChannelId = Long.valueOf(couponChannelIdStr); | |||||
| } catch (NumberFormatException e) { | |||||
| logger.error("couponChannelId convert error, " + couponChannelIdStr + ", e:" + e.getMessage()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponChannelId: " + couponChannelIdStr + ", e:" + e.getMessage()); | |||||
| } | |||||
| WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannelId); | |||||
| if (wxCouponChannel == null) { | |||||
| logger.error("couponChannelId convert error, " + couponChannelIdStr); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); | |||||
| } | |||||
| if (wxCouponChannel.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { | |||||
| Date now = new Date(); | |||||
| if (wxCouponChannel.getBeginTime().getTime() > now.getTime()) { | |||||
| logger.error("此券活动未开始:" + couponChannelIdStr); | |||||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_NOT_STARTED); | |||||
| } | |||||
| if (wxCouponChannel.getEndTime().getTime() < now.getTime()) { | |||||
| logger.error("此券活动已结束:" + couponChannelIdStr); | |||||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_END); | |||||
| } | |||||
| } | |||||
| if (wxCouponChannel.getStatus() == EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) { | |||||
| logger.error("此券已下架:" + couponChannelIdStr); | |||||
| return new ResultData(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); | |||||
| } | |||||
| if (StringUtils.isBlank(couponIdStr)) { | |||||
| couponId = wxCouponChannel.getCouponId(); | |||||
| } | |||||
| } | |||||
| if (couponId <= 0 && !StringUtils.isBlank(couponIdStr)) { | |||||
| try { | |||||
| couponId = Long.valueOf(couponIdStr); | |||||
| } catch (NumberFormatException e) { | |||||
| logger.error("couponId convert error, " + couponIdStr + ", e:" + e.getMessage()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponId: " + couponIdStr + ", e:" + e.getMessage()); | |||||
| } | |||||
| } | |||||
| if (couponId <= 0) { | |||||
| logger.error("couponChannelId或者couponId不能为空"); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId或者couponId不能为空"); | |||||
| } | |||||
| if(pressStr != null) { | |||||
| try{ | |||||
| isPress = Boolean.valueOf(pressStr); | |||||
| } catch (Exception e) { | |||||
| logger.error("press转换失败"); | |||||
| } | |||||
| } | |||||
| if (orderGroupIdStr != null) { | |||||
| try { | |||||
| orderGroupId = Long.valueOf(orderGroupIdStr); | |||||
| } catch (Exception e) { | |||||
| logger.error("orderGroupId转换失败"); | |||||
| } | |||||
| } | |||||
| WxCUser user = getUser(); | WxCUser user = getUser(); | ||||
| try { | try { | ||||
| //WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId, isPress, orderGroupId, formId); | //WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId, isPress, orderGroupId, formId); | ||||
| @@ -113,7 +113,7 @@ public class WxPayOrderController extends BaseController { | |||||
| WxOrder order = null; | WxOrder order = null; | ||||
| try { | try { | ||||
| /*if(status.equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) && !payOrderIdStr.equals("0")) { | |||||
| if(status.equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) && !payOrderIdStr.equals("0")) { | |||||
| // 前端提示支付成功, 不作为支付成功标志,只检查支付订单状态 | // 前端提示支付成功, 不作为支付成功标志,只检查支付订单状态 | ||||
| // 有价券不走update, callback更新 | // 有价券不走update, callback更新 | ||||
| payOrder = wxPayOrderService.getById(payOrderId); | payOrder = wxPayOrderService.getById(payOrderId); | ||||
| @@ -131,7 +131,54 @@ public class WxPayOrderController extends BaseController { | |||||
| } else if (status.equals(EnumPayStatus.PAY_STATUS_FAIL.getCode())) { | } else if (status.equals(EnumPayStatus.PAY_STATUS_FAIL.getCode())) { | ||||
| wxPayOrderService.handlePayOrderStatusUpdate(payOrder, 2); | wxPayOrderService.handlePayOrderStatusUpdate(payOrder, 2); | ||||
| } | } | ||||
| }*/ | |||||
| } | |||||
| return new ResultData(Result.SUCCESS, "支付状态更新成功"); | |||||
| } catch (MallinkException e) { | |||||
| logger.error("支付状态更新失败2: " + payOrder.toString() + ", e:" + e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error("支付状态更新失败3: " + payOrder.toString() + ", e:" + e.getMessage()); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "支付状态更新失败3: " + payOrder.toString() + ", e:" + e.getMessage()); | |||||
| } | |||||
| } | |||||
| @ApiOperation(value = "更新支付订单状态", notes = "{\"payOrderId\":\"string\",\"orderId\":\"string\",\"status\":integer,\"reason\":\"string\"}") | |||||
| @PostMapping("/updatePayOrder_new") | |||||
| public ResultData updatePayOrderNew(@RequestBody Map<String, Object> paramMap) { | |||||
| logger.info("/api/pay/updatePayOrder" + paramMap.toString()); | |||||
| String payOrderIdStr = (String) paramMap.get("payOrderId"); | |||||
| String orderIdStr = (String) paramMap.get("orderId"); | |||||
| String reasonStr = (String) paramMap.get("reason"); | |||||
| Integer status = (Integer) paramMap.get("status"); | |||||
| if (StringUtils.isBlank(orderIdStr)) { | |||||
| logger.info("orderId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||||
| } | |||||
| Long payOrderId = 0L, orderId = 0L; | |||||
| try { | |||||
| orderId = Long.valueOf(orderIdStr); | |||||
| } catch (NumberFormatException e) { | |||||
| logger.error("orderId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId参数不正确"); | |||||
| } | |||||
| if (!StringUtils.isBlank(payOrderIdStr)) { | |||||
| try { | |||||
| payOrderId = Long.valueOf(payOrderIdStr); | |||||
| } catch (NumberFormatException e) { | |||||
| logger.error("payOrderId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payOrderId参数不正确"); | |||||
| } | |||||
| } | |||||
| WxPayOrder payOrder = new WxPayOrder(); | |||||
| payOrder.setId(payOrderId); | |||||
| payOrder.setOrderId(orderId); | |||||
| payOrder.setPayOrderStatus(status); | |||||
| payOrder.setFailReason(reasonStr); | |||||
| WxOrder order = null; | |||||
| try { | |||||
| //支付成功 | //支付成功 | ||||
| if (status.equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) { | if (status.equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) { | ||||
| //有价券 | //有价券 | ||||
| @@ -147,7 +194,6 @@ public class WxPayOrderController extends BaseController { | |||||
| } | } | ||||
| } else { | } else { | ||||
| //免费券 | //免费券 | ||||
| //wxPayOrderService.handlePayOrderStatusUpdate(payOrder, EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||||
| wxPayOrderService.handlePayOrderStatusUpdateFree(payOrder); | wxPayOrderService.handlePayOrderStatusUpdateFree(payOrder); | ||||
| } | } | ||||
| } else if (status.equals(EnumPayStatus.PAY_STATUS_FAIL.getCode())){ | } else if (status.equals(EnumPayStatus.PAY_STATUS_FAIL.getCode())){ | ||||
| @@ -1444,6 +1444,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| } | } | ||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId) { | public WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId) { | ||||
| // 1. check user info and coupon info | // 1. check user info and coupon info | ||||
| // 2. 减库存 | // 2. 减库存 | ||||
| @@ -1451,6 +1452,12 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| // 4. 积分券 -- 扣减积分 | // 4. 积分券 -- 扣减积分 | ||||
| // 10. coupon order | // 10. coupon order | ||||
| // 11. 生成完成后一系列操作 | // 11. 生成完成后一系列操作 | ||||
| if (coupon.getType() == EnumCouponType.COUPON_CREDIT.getCode() || coupon.getType() == EnumCouponType.COUPON_CREDIT_PARK.getCode()) { | |||||
| //若用户剩余积分比积分售价低则不能支付 | |||||
| if (user.getCredit() == null || user.getCredit() < coupon.getCreditPrice()) { | |||||
| throw new MallinkException(ErrorCode.CREDIT_NOT_ENOUGH); | |||||
| } | |||||
| } | |||||
| String couponIdStr = String.valueOf(coupon.getId()); | String couponIdStr = String.valueOf(coupon.getId()); | ||||
| // 减库存操作 | // 减库存操作 | ||||
| stockReduce(user, coupon, couponIdStr); | stockReduce(user, coupon, couponIdStr); | ||||
| @@ -1472,33 +1479,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| record.setCouponChannelId(couponChannelId); | record.setCouponChannelId(couponChannelId); | ||||
| record.setProductId(coupon.getId()); | record.setProductId(coupon.getId()); | ||||
| //当积分券或者积分停车券时 则进行积分支付 | //当积分券或者积分停车券时 则进行积分支付 | ||||
| if (coupon.getType() == EnumCouponType.COUPON_CREDIT.getCode() || coupon.getType() == EnumCouponType.COUPON_CREDIT_PARK.getCode()) { | |||||
| //若用户剩余积分比积分售价低则不能支付 | |||||
| if (user.getCredit() == null || user.getCredit() < coupon.getCreditPrice()) { | |||||
| throw new MallinkException(ErrorCode.CREDIT_NOT_ENOUGH); | |||||
| } | |||||
| //-------此处为【积分支付】记录增加积分操作------- | |||||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||||
| //记录操作人类型 操作人id | |||||
| if (user.getOperatorType() == EnumUserType.MALLUSER.getCode()) { | |||||
| creditHistory.setOperatorType(EnumUserType.MALLUSER.getCode()); | |||||
| creditHistory.setOperatorId(user.getOperatorId()); | |||||
| } else { | |||||
| creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||||
| creditHistory.setOperatorId(user.getId()); | |||||
| } | |||||
| creditHistory.setCreditNum(coupon.getCreditPrice()); | |||||
| creditHistory.setCUserId(user.getId()); | |||||
| creditHistory.setTenantId(user.getTenantId()); | |||||
| creditHistory.setCreditType(EnumScoreType.CHANGE_CREDIT.getCode()); | |||||
| creditHistory.setCouponId(coupon.getId()); | |||||
| //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 | |||||
| setMerchantId(coupon, creditHistory); | |||||
| wxCreditHistoryService.saveOrUpdate(creditHistory); | |||||
| record.setType(EnumOrderType.CREDIT.getCode()); | |||||
| } else { | |||||
| record.setType(EnumOrderType.COUPON.getCode()); | |||||
| } | |||||
| creditPay(user, coupon, record); | |||||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | ||||
| record.setcUserId(user.getId()); | record.setcUserId(user.getId()); | ||||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | ||||
| @@ -1528,7 +1509,35 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| } | } | ||||
| return record; | return record; | ||||
| } | } | ||||
| private void creditPay(WxCUser user, WxCoupon coupon, WxOrder record) { | |||||
| if (coupon.getType() == EnumCouponType.COUPON_CREDIT.getCode() || coupon.getType() == EnumCouponType.COUPON_CREDIT_PARK.getCode()) { | |||||
| //-------此处为【积分支付】记录增加积分操作------- | |||||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||||
| //记录操作人类型 操作人id | |||||
| if (user.getOperatorType() == EnumUserType.MALLUSER.getCode()) { | |||||
| creditHistory.setOperatorType(EnumUserType.MALLUSER.getCode()); | |||||
| creditHistory.setOperatorId(user.getOperatorId()); | |||||
| } else { | |||||
| creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); | |||||
| creditHistory.setOperatorId(user.getId()); | |||||
| } | |||||
| creditHistory.setCreditNum(coupon.getCreditPrice()); | |||||
| creditHistory.setCUserId(user.getId()); | |||||
| creditHistory.setTenantId(user.getTenantId()); | |||||
| creditHistory.setCreditType(EnumScoreType.CHANGE_CREDIT.getCode()); | |||||
| creditHistory.setCouponId(coupon.getId()); | |||||
| //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 | |||||
| setMerchantId(coupon, creditHistory); | |||||
| wxCreditHistoryService.saveOrUpdate(creditHistory); | |||||
| record.setType(EnumOrderType.CREDIT.getCode()); | |||||
| } else { | |||||
| record.setType(EnumOrderType.COUPON.getCode()); | |||||
| } | |||||
| } | |||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public WxOrder saveNoFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId) { | public WxOrder saveNoFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, boolean isPress, Long orderGroupId, String formId) { | ||||
| // 1. check user info and coupon info | // 1. check user info and coupon info | ||||
| // 2. save order | // 2. save order | ||||