| @@ -0,0 +1,2 @@ | |||||
| ALTER TABLE `wx_order` | |||||
| ADD COLUMN `total_payment` int(11) NULL COMMENT '总支付金额'; | |||||
| @@ -1,9 +1,11 @@ | |||||
| package com.iformall.controller; | package com.iformall.controller; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.annotation.AuthIgnore; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.Result; | import com.iformall.common.Result; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxCUser; | |||||
| import com.iformall.domain.po.WxCUserBasicInfo; | import com.iformall.domain.po.WxCUserBasicInfo; | ||||
| import com.iformall.domain.po.WxCouponOrder; | import com.iformall.domain.po.WxCouponOrder; | ||||
| import com.iformall.domain.po.WxMerchantBUser; | import com.iformall.domain.po.WxMerchantBUser; | ||||
| @@ -11,6 +13,7 @@ import com.iformall.domain.vo.WxCouponOrderCVo; | |||||
| import com.iformall.enums.EnumCreditLockedStatus; | import com.iformall.enums.EnumCreditLockedStatus; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.WxCUserBasicInfoService; | import com.iformall.service.WxCUserBasicInfoService; | ||||
| import com.iformall.service.WxCUserService; | |||||
| import com.iformall.service.WxCouponOrderService; | import com.iformall.service.WxCouponOrderService; | ||||
| import com.iformall.service.WxMerchantBUserService; | import com.iformall.service.WxMerchantBUserService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| @@ -23,7 +26,10 @@ import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import java.math.BigDecimal; | |||||
| import java.util.Date; | import java.util.Date; | ||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| @RestController | @RestController | ||||
| @@ -41,6 +47,9 @@ public class WxCouponOrderController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | private WxCUserBasicInfoService wxCUserBasicInfoService; | ||||
| @Autowired | |||||
| private WxCUserService wxCUserService; | |||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @@ -210,4 +219,39 @@ public class WxCouponOrderController extends BaseController { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @ApiOperation(value = "获取C端用户可用券", notes = "{\"cUserId\":\"必填\",\"payPrice\":\"支付金额\"}") | |||||
| @PostMapping("getAvailCouponOrder") | |||||
| public ResultData getAvailCouponOrder(@RequestBody Map<String, String> paramMap) { | |||||
| WxMerchantBUser user = getUser(); | |||||
| String cUserIdStr = paramMap.get("cUserId"); | |||||
| String payPriceStr = paramMap.get("payPrice"); | |||||
| if (StringUtils.isBlank(cUserIdStr)) { | |||||
| logger.error("cUserId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| if (StringUtils.isBlank(payPriceStr)) { | |||||
| logger.error("payPriceStr不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| BigDecimal totalFee = new BigDecimal(payPriceStr); | |||||
| totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | |||||
| Integer payPrice = totalFee.multiply(new BigDecimal(100)).intValue(); | |||||
| Long cUserId = 0L; | |||||
| try { | |||||
| cUserId = Long.valueOf(cUserIdStr); | |||||
| } catch (NumberFormatException e) { | |||||
| cUserId = 0L; | |||||
| logger.error("cUserId参数不正确: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_CLASSCAST_ERROR); | |||||
| } | |||||
| WxCUser cUser = wxCUserService.getById(cUserId); | |||||
| List<WxCouponOrderCVo> avaList = wxCouponOrderService.queryMicroPayCouponOrder(user, cUser, payPrice); | |||||
| return new ResultData(avaList); | |||||
| } | |||||
| } | } | ||||
| @@ -4,9 +4,8 @@ package com.iformall.controller; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumOrderType; | |||||
| import com.iformall.enums.EnumPayType; | |||||
| import com.iformall.enums.EnumPayWay; | |||||
| import com.iformall.domain.vo.WxCouponOrderCVo; | |||||
| import com.iformall.enums.*; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.IPUtil; | import com.iformall.utils.IPUtil; | ||||
| @@ -21,6 +20,8 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import java.math.BigDecimal; | |||||
| import java.util.Date; | |||||
| import java.util.Map; | import java.util.Map; | ||||
| /** | /** | ||||
| @@ -50,7 +51,13 @@ public class WxMicroPayController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| WxAppinfoService wxAppinfoService; | WxAppinfoService wxAppinfoService; | ||||
| @ApiOperation(value = "付款码支付订单", notes = "params:{\"authCode\":\"String\",\"totalFee\":\"String\"},\n" + | |||||
| @Autowired | |||||
| WxCouponOrderService wxCouponOrderService; | |||||
| @Autowired | |||||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||||
| @ApiOperation(value = "付款码支付订单", notes = "params:{\"authCode\":\"String\",\"totalFee\":\"实际支付金额\", ,\"totalPay\":\"总支付金额\"},\n" + | |||||
| "注意:\n" + | "注意:\n" + | ||||
| "提醒1:提交支付请求后微信会同步返回支付结果。当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果;当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒);\n" + | "提醒1:提交支付请求后微信会同步返回支付结果。当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果;当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒);\n" + | ||||
| "提醒2:在调用查询接口返回后,如果交易状况不明晰,请调用【撤销订单API】,此时如果交易失败则关闭订单,该单不能再支付成功;如果交易成功,则将扣款退回到用户账户。当撤销无返回或错误时,请再次调用。注意:请勿扣款后立即调用【撤销订单API】,建议至少15秒后再调用。撤销订单API需要双向证书。") | "提醒2:在调用查询接口返回后,如果交易状况不明晰,请调用【撤销订单API】,此时如果交易失败则关闭订单,该单不能再支付成功;如果交易成功,则将扣款退回到用户账户。当撤销无返回或错误时,请再次调用。注意:请勿扣款后立即调用【撤销订单API】,建议至少15秒后再调用。撤销订单API需要双向证书。") | ||||
| @@ -61,6 +68,7 @@ public class WxMicroPayController extends BaseController { | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | ||||
| String authCode = paramMap.get("authCode"); | String authCode = paramMap.get("authCode"); | ||||
| String totalFeeStr = paramMap.get("totalFee"); | String totalFeeStr = paramMap.get("totalFee"); | ||||
| String totalPayStr = paramMap.get("totalPay"); | |||||
| if (StringUtils.isBlank(authCode)) { | if (StringUtils.isBlank(authCode)) { | ||||
| logger.error("authCode不能为空"); | logger.error("authCode不能为空"); | ||||
| @@ -77,7 +85,7 @@ public class WxMicroPayController extends BaseController { | |||||
| WxOrder order = null; | WxOrder order = null; | ||||
| try { | try { | ||||
| order = wxOrderService.saveMicroPayOrder(user, totalFeeStr); | |||||
| order = wxOrderService.saveMicroPayOrder(user, totalFeeStr, totalPayStr); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("saveMicopayOrder 1" + e.getMessage()); | logger.error("saveMicopayOrder 1" + e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| @@ -258,4 +266,85 @@ public class WxMicroPayController extends BaseController { | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR); | return new ResultData(ErrorCode.REFUND_ORDER_ERROR); | ||||
| } | } | ||||
| } | } | ||||
| @ApiOperation(value = "收银台核销券", notes = "{\"couponOrderId\":\"必填\",\"payPrice\":\"支付金额(分)\"}") | |||||
| @PostMapping("userCouponOrderForMicroPay") | |||||
| public ResultData userCouponOrderForMicroPay(@RequestBody Map<String, String> paramMap) { | |||||
| logger.info("couponOrderController.verify:"+paramMap.toString()); | |||||
| String couponOrderIdStr = paramMap.get("couponOrderId"); | |||||
| String payPriceStr = paramMap.get("payPrice"); | |||||
| if (StringUtils.isBlank(couponOrderIdStr)) { | |||||
| logger.error("couponOrderId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| if (StringUtils.isBlank(payPriceStr)) { | |||||
| logger.error("payPrice不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| Long couponOrderId = 0L; | |||||
| BigDecimal totalFee = new BigDecimal(payPriceStr); | |||||
| totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | |||||
| Integer payPrice = totalFee.multiply(new BigDecimal(100)).intValue(); | |||||
| try { | |||||
| couponOrderId = Long.valueOf(couponOrderIdStr); | |||||
| } catch (NumberFormatException e) { | |||||
| couponOrderId = 0L; | |||||
| logger.error("couponOrderId参数不正确: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| WxCouponOrderCVo wxCouponOrderCVo = wxCouponOrderService.detailCUserVo(couponOrderIdStr); | |||||
| if (wxCouponOrderCVo == null) | |||||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||||
| WxCUserBasicInfo wxCUserBasicInfo = wxCUserBasicInfoService.getById(wxCouponOrderCVo.getcUserId()); | |||||
| if (wxCUserBasicInfo != null && EnumCreditLockedStatus.CLOSE.getCode().equals(wxCUserBasicInfo.getStatus())) { | |||||
| return new ResultData(ErrorCode.MEMBER_IS_LOCKED); | |||||
| } | |||||
| if (wxCouponOrderCVo.getValidStartDate() != null && wxCouponOrderCVo.getValidEndDate() != null ) { | |||||
| Date now = new Date(); | |||||
| if (wxCouponOrderCVo.getValidStartDate().getTime() > now.getTime()) { | |||||
| logger.error("此券有效期未开始:" + couponOrderIdStr); | |||||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_EARLIER_THAN_VALIDDATE); | |||||
| } | |||||
| if (wxCouponOrderCVo.getValidEndDate().getTime() < now.getTime()) { | |||||
| logger.error("此券有效期已结束:" + couponOrderIdStr); | |||||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_LATER_THAN_VALIDDATE); | |||||
| } | |||||
| } | |||||
| WxCouponOrder wxCouponOrder = wxCouponOrderService.getById(couponOrderId); | |||||
| if (wxCouponOrder == null) { | |||||
| logger.error("券ID不存在:" + couponOrderId); | |||||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_NULL); | |||||
| } | |||||
| WxMerchantBUser wxMerchantBUser = wxMerchantBUserService.getById(getUser().getId()); | |||||
| if (wxMerchantBUser == null) { | |||||
| logger.error("核销员ID不存在:" + getUser().getId()); | |||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), "核销员ID不存在或者无权限"); | |||||
| } | |||||
| wxMerchantBUser.setBuserId(getBuserId()); | |||||
| WxCouponOrder couponOrder = null; | |||||
| Integer remainPrice = payPrice; | |||||
| try { | |||||
| remainPrice = wxCouponOrderService.microPayVerify(wxCouponOrder, wxMerchantBUser, payPrice); | |||||
| } 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.VERIFY_ERROR, e.getMessage()); | |||||
| } | |||||
| if(couponOrder != null) { | |||||
| wxCouponOrderService.sendInsideCouponVerifyMsg(couponOrder.getTenantId(), couponOrderId, wxMerchantBUser.getId()); | |||||
| } | |||||
| Double remainPriceD = Double.valueOf(remainPrice); | |||||
| String remainPriceStr = String.format("%.2f", remainPriceD); | |||||
| return new ResultData(remainPrice); | |||||
| } | |||||
| } | } | ||||
| @@ -197,6 +197,8 @@ public enum ErrorCode{ | |||||
| COUPON_ORDER_IS_PRE_VERIFY(4008, "卡券已被预核销"), | COUPON_ORDER_IS_PRE_VERIFY(4008, "卡券已被预核销"), | ||||
| COUPON_SEND_LIMIT_VERIFY(4009, "商户购券数错误"), | COUPON_SEND_LIMIT_VERIFY(4009, "商户购券数错误"), | ||||
| COUPON_HANDSEL_VERIFY(4010, "商户发券异常"), | COUPON_HANDSEL_VERIFY(4010, "商户发券异常"), | ||||
| COUPON_MANJIAN_USE_PRICE_NO_ALLOW_(4011, "满减券金额不符合条件"), | |||||
| COUPON_ORDER_TYPE_NOT_SUPPORTED(4012, "券类型不支持"), | |||||
| /** | /** | ||||
| * 卡 | * 卡 | ||||
| @@ -93,6 +93,9 @@ public class WxOrder extends BaseEntity { | |||||
| @io.swagger.annotations.ApiModelProperty(value="POS SN",name="posOrderCreateSn") | @io.swagger.annotations.ApiModelProperty(value="POS SN",name="posOrderCreateSn") | ||||
| private String posOrderCreateSn; | private String posOrderCreateSn; | ||||
| @io.swagger.annotations.ApiModelProperty(value="总支付金额(分),收银台用券时使用",name="totalPayment") | |||||
| private Integer totalPayment; | |||||
| @TableField(exist = false) | @TableField(exist = false) | ||||
| protected List<Integer> statusS; | protected List<Integer> statusS; | ||||
| @@ -2,6 +2,7 @@ package com.iformall.service; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.iformall.common.ResultData; | import com.iformall.common.ResultData; | ||||
| import com.iformall.domain.po.WxCUser; | |||||
| import com.iformall.domain.po.WxCouponOrder; | import com.iformall.domain.po.WxCouponOrder; | ||||
| import com.iformall.domain.po.WxMerchantBUser; | import com.iformall.domain.po.WxMerchantBUser; | ||||
| import com.iformall.domain.vo.*; | import com.iformall.domain.vo.*; | ||||
| @@ -189,4 +190,12 @@ public interface WxCouponOrderService { | |||||
| ResultData queryCardStatus(WxCouponOrder wxCouponOrder); | ResultData queryCardStatus(WxCouponOrder wxCouponOrder); | ||||
| void exportData(WxCouponOrderBVo wxCouponOrder, HttpServletRequest request, HttpServletResponse response); | void exportData(WxCouponOrderBVo wxCouponOrder, HttpServletRequest request, HttpServletResponse response); | ||||
| /** | |||||
| * B端-收银台-支持优惠券 | |||||
| */ | |||||
| List<WxCouponOrderCVo> queryMicroPayCouponOrder(WxMerchantBUser user, WxCUser cUser, Integer price); | |||||
| Integer microPayVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer price); | |||||
| } | } | ||||
| @@ -42,7 +42,7 @@ public interface WxOrderService { | |||||
| * @param totalFeeStr | * @param totalFeeStr | ||||
| * @return 订单id | * @return 订单id | ||||
| */ | */ | ||||
| WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr); | |||||
| WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr, String totalPayStr); | |||||
| /** | /** | ||||
| * 商户码-储值卡支付 | * 商户码-储值卡支付 | ||||
| @@ -37,6 +37,7 @@ import java.math.BigDecimal; | |||||
| import java.text.ParseException; | import java.text.ParseException; | ||||
| import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
| import java.util.*; | import java.util.*; | ||||
| import java.util.stream.Collectors; | |||||
| @Service | @Service | ||||
| public class WxCouponOrderServiceImpl implements WxCouponOrderService { | public class WxCouponOrderServiceImpl implements WxCouponOrderService { | ||||
| @@ -1034,4 +1035,126 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| wxCardTransferInfoMapper.insert(wxCardTransferInfo); | wxCardTransferInfoMapper.insert(wxCardTransferInfo); | ||||
| } | } | ||||
| @Override | |||||
| public List<WxCouponOrderCVo> queryMicroPayCouponOrder(WxMerchantBUser user, WxCUser cUser, Integer payPrice) { | |||||
| Map<String, Object> coQ = new HashMap<>(); | |||||
| coQ.put("tenantId", user.getTenantId()); | |||||
| coQ.put("cUserId", user.getId()); | |||||
| coQ.put("merchantId", user.getMerchantId()); | |||||
| List<WxCouponOrderCVo> avaCoList = wxCouponOrderMapper.findAvailCouponOrder(coQ); | |||||
| List<WxCouponOrderCVo> avaCouponOrderList = avaCoList.stream().filter(couponOrderCVo -> { | |||||
| if (couponOrderCVo.getType().equals(EnumCouponType.COUPON_MANJIAN.getCode())) { | |||||
| if (payPrice > couponOrderCVo.getUsePrice()) { | |||||
| return true; | |||||
| } | |||||
| } else { | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| }).collect(Collectors.toList()); | |||||
| return avaCouponOrderList; | |||||
| } | |||||
| @Override | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public Integer microPayVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer payPrice) { | |||||
| // 1. 获取券信息 | |||||
| WxCoupon wxCoupon = wxCouponMapper.selectById(couponOrder.getCouponId()); | |||||
| if (wxCoupon == null) { | |||||
| logger.error("券: coupon-" + wxCoupon.getId() + "不存在" + "couponOrder-" + couponOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_NULL); | |||||
| } | |||||
| if (!(wxCoupon.getType().equals(EnumCouponType.COUPON_MANJIAN.getCode()) || | |||||
| wxCoupon.getType().equals(EnumCouponType.COUPON_DAIJIN.getCode()) || | |||||
| wxCoupon.getType().equals(EnumCouponType.COUPON_MULTIMCH.getCode()))) { | |||||
| logger.error("收银台不支持此券类型: " + wxCoupon.getType()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_TYPE_NOT_SUPPORTED); | |||||
| } | |||||
| // 2. 检查适用门店 | |||||
| WxCouponMerchant wxCouponMerchant = new WxCouponMerchant(); | |||||
| wxCouponMerchant.setProductId(wxCoupon.getId()); | |||||
| wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); | |||||
| List<WxCouponMerchant> couponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant); | |||||
| if (!couponMerchantList.stream().anyMatch(cm -> cm.getMerchantId().equals(bUser.getMerchantId()))) { | |||||
| logger.error("券: coupon-" + wxCoupon.getId() + "核销: couponMerchantId-" + bUser.getMerchantId()); | |||||
| throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL); | |||||
| } | |||||
| // 3. 券包状态检查 | |||||
| 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); | |||||
| } | |||||
| if (couponOrder.getCouponType().equals(EnumCouponType.COUPON_MANJIAN.getCode())) { | |||||
| if (payPrice < wxCoupon.getUsePrice()) { | |||||
| logger.error("券达不到满减条件: couponOrder-" + couponOrder.getId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_PRE_VERIFY); | |||||
| } | |||||
| } | |||||
| int num = 0; | |||||
| try { | |||||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); //1核销 | |||||
| couponOrder.setBUserId(bUser.getId()); | |||||
| couponOrder.setVerifyType(EnumCouponVerifyType.VERIFY_B.getCode()); | |||||
| couponOrder.setUpdateDate(new Date()); | |||||
| num = wxCouponOrderMapper.updateVerifyCouponOrder(couponOrder); | |||||
| } catch (Exception e) { | |||||
| logger.error("db failed: couponOrder-" + couponOrder.getId() + ", e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||||
| } | |||||
| if (num != 1) { | |||||
| logger.error("核销异常:updatete num " + num); | |||||
| throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num); | |||||
| } | |||||
| // 成长值 | |||||
| try { | |||||
| WxOrder order = wxOrderMapper.selectById(couponOrder.getOrderId()); | |||||
| wxScoreRulesService.addScore2(EnumScoreType.CONSUMPTION, order, wxCoupon.getBusiness()); | |||||
| } catch (Exception e) { | |||||
| logger.error("成长值:" + e.getMessage()); | |||||
| } | |||||
| // 积分 | |||||
| try { | |||||
| //-------此处为【现金支付】记录增加积分操作------- | |||||
| WxCreditHistory creditHistory = new WxCreditHistory(); | |||||
| creditHistory.setOperatorType(EnumUserType.BUSER.getCode()); | |||||
| creditHistory.setOperatorId(bUser.getId()); | |||||
| creditHistory.setCUserId(couponOrder.getcUserId()); | |||||
| creditHistory.setCreateDate(new Date()); | |||||
| creditHistory.setTenantId(couponOrder.getTenantId()); | |||||
| creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); | |||||
| creditHistory.setCouponId(wxCoupon.getId()); | |||||
| creditHistory.setBusinessId(wxCoupon.getBusiness()); | |||||
| creditHistory.setSpend(couponOrder.getCouponPrice()); | |||||
| //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 | |||||
| creditHistory.setMerchantId(bUser.getMerchantId()); | |||||
| creditHistory.setBuserId(bUser.getBuserId()); | |||||
| wxCreditHistoryService.saveOrUpdate(creditHistory); | |||||
| } catch (Exception e) { | |||||
| logger.error("积分值:" + e.getMessage()); | |||||
| } | |||||
| Integer remainPrice = payPrice - wxCoupon.getPrice(); | |||||
| if (remainPrice < 0) { | |||||
| remainPrice = 0; | |||||
| } | |||||
| return remainPrice; | |||||
| } | |||||
| } | } | ||||
| @@ -18,6 +18,7 @@ import com.iformall.mapper.*; | |||||
| import com.iformall.mq.MqBaseProducer; | import com.iformall.mq.MqBaseProducer; | ||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.*; | import com.iformall.utils.*; | ||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -553,7 +554,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 WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr) { | |||||
| public WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr, String totalPayStr) { | |||||
| // 检查用户 | // 检查用户 | ||||
| if (user == null) { | if (user == null) { | ||||
| logger.error("用户不存在"); | logger.error("用户不存在"); | ||||
| @@ -578,7 +579,13 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| BigDecimal totalFee = new BigDecimal(totalFeeStr); | BigDecimal totalFee = new BigDecimal(totalFeeStr); | ||||
| totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | ||||
| Integer totalPayment = null; | |||||
| int payment = totalFee.multiply(new BigDecimal(100)).intValue(); | int payment = totalFee.multiply(new BigDecimal(100)).intValue(); | ||||
| if (StringUtils.isNotBlank(totalFeeStr)) { | |||||
| BigDecimal totalPay = new BigDecimal(totalPayStr); | |||||
| totalPay.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | |||||
| totalPayment = totalPay.multiply(new BigDecimal(100)).intValue(); | |||||
| } | |||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| Long orderNumber = idWorker.nextId(); | Long orderNumber = idWorker.nextId(); | ||||
| @@ -594,6 +601,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| record.setProductId(user.getId()); | record.setProductId(user.getId()); | ||||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | ||||
| record.setPayment(payment); | record.setPayment(payment); | ||||
| record.setTotalPayment(totalPayment); | |||||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | ||||
| record.setDetail(bodyStr); | record.setDetail(bodyStr); | ||||
| record.setCreateDate(curr); | record.setCreateDate(curr); | ||||
| @@ -21,12 +21,13 @@ | |||||
| <result column="press_current_value" jdbcType="INTEGER" property="pressCurrentValue"/> | <result column="press_current_value" jdbcType="INTEGER" property="pressCurrentValue"/> | ||||
| <result column="order_group_id" jdbcType="BIGINT" property="orderGroupId"/> | <result column="order_group_id" jdbcType="BIGINT" property="orderGroupId"/> | ||||
| <result column="form_id" jdbcType="VARCHAR" property="formId"/> | <result column="form_id" jdbcType="VARCHAR" property="formId"/> | ||||
| <result column="total_payment" jdbcType="INTEGER" property="totalPayment"/> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`order_number`,`tenant_id`,`c_user_id`,`coupon_channel_id`,`product_id`,`type`,`payment_type`,`payment`,`payment_time`,`order_status`,`create_date`,`update_date`,`detail`, | `id`,`order_number`,`tenant_id`,`c_user_id`,`coupon_channel_id`,`product_id`,`type`,`payment_type`,`payment`,`payment_time`,`order_status`,`create_date`,`update_date`,`detail`, | ||||
| `press_end_date`,`press_current_num`,`press_current_value`,`order_group_id`,`form_id` | |||||
| `press_end_date`,`press_current_num`,`press_current_value`,`order_group_id`,`form_id`,`total_payment` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||