| @@ -0,0 +1,2 @@ | |||
| ALTER TABLE `wx_order` | |||
| CHANGE COLUMN `real_payment` `real_payment` int(11) NULL COMMENT '实际支付金额'; | |||
| @@ -220,38 +220,7 @@ public class WxCouponOrderController extends BaseController { | |||
| 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); | |||
| } | |||
| } | |||
| @@ -22,6 +22,8 @@ import org.springframework.web.bind.annotation.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| import java.math.BigDecimal; | |||
| import java.util.Date; | |||
| import java.util.HashMap; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| @@ -57,7 +59,13 @@ public class WxMicroPayController extends BaseController { | |||
| @Autowired | |||
| private WxCUserBasicInfoService wxCUserBasicInfoService; | |||
| @ApiOperation(value = "付款码支付订单", notes = "params:{\"authCode\":\"String\",\"totalFee\":\"实际支付金额\", ,\"totalPay\":\"总支付金额\"},\n" + | |||
| @Autowired | |||
| private WxCUserService wxCUserService; | |||
| @Autowired | |||
| private PosCouponOrderVerifyService posCouponOrderVerifyService; | |||
| @ApiOperation(value = "付款码支付订单", notes = "params:{\"authCode\":\"String\",\"totalFee\":\"支付金额\"},\n" + | |||
| "注意:\n" + | |||
| "提醒1:提交支付请求后微信会同步返回支付结果。当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果;当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒);\n" + | |||
| "提醒2:在调用查询接口返回后,如果交易状况不明晰,请调用【撤销订单API】,此时如果交易失败则关闭订单,该单不能再支付成功;如果交易成功,则将扣款退回到用户账户。当撤销无返回或错误时,请再次调用。注意:请勿扣款后立即调用【撤销订单API】,建议至少15秒后再调用。撤销订单API需要双向证书。") | |||
| @@ -68,7 +76,6 @@ public class WxMicroPayController extends BaseController { | |||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||
| String authCode = paramMap.get("authCode"); | |||
| String totalFeeStr = paramMap.get("totalFee"); | |||
| String totalPayStr = paramMap.get("totalPay"); | |||
| if (StringUtils.isBlank(authCode)) { | |||
| logger.error("authCode不能为空"); | |||
| @@ -85,7 +92,7 @@ public class WxMicroPayController extends BaseController { | |||
| WxOrder order = null; | |||
| try { | |||
| order = wxOrderService.saveMicroPayOrder(user, totalFeeStr, totalPayStr); | |||
| order = wxOrderService.saveMicroPayOrder(user, totalFeeStr); | |||
| } catch (MallinkException e) { | |||
| logger.error("saveMicopayOrder 1" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -112,6 +119,120 @@ public class WxMicroPayController extends BaseController { | |||
| } | |||
| } | |||
| @ApiOperation(value = "付款码支付订单v2", notes = "params:{\"payPrice\":\"总支付金额\",\"cUserId\":\"会员ID\"},\n" + | |||
| "注意:\n" + | |||
| "提醒1:提交支付请求后微信会同步返回支付结果。当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果;当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒);\n" + | |||
| "提醒2:在调用查询接口返回后,如果交易状况不明晰,请调用【撤销订单API】,此时如果交易失败则关闭订单,该单不能再支付成功;如果交易成功,则将扣款退回到用户账户。当撤销无返回或错误时,请再次调用。注意:请勿扣款后立即调用【撤销订单API】,建议至少15秒后再调用。撤销订单API需要双向证书。") | |||
| @PostMapping("order_create_v2") | |||
| public ResultData saveMicopayOrderV2(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { | |||
| logger.info("saveMicopayOrderV2: " + paramMap.toString()); | |||
| 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); | |||
| } | |||
| 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(Long.valueOf(cUserIdStr)); | |||
| if (cUser == null) { | |||
| logger.error("cUser不存在: " + cUserIdStr); | |||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| String ipStr = IPUtil.getIpAddr(request); | |||
| BigDecimal payPrice = new BigDecimal(payPriceStr); | |||
| payPrice.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | |||
| int payment = payPrice.multiply(new BigDecimal(100)).intValue(); | |||
| WxOrder order = null; | |||
| try { | |||
| order = wxOrderService.saveMicroPayOrderV2(user, cUser, payment); | |||
| } catch (MallinkException e) { | |||
| logger.error("saveMicopayOrder 1" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error("saveMicopayOrder 2" + e.getMessage()); | |||
| return new ResultData(ErrorCode.ORDER_IS_FAIL, e.getMessage()); | |||
| } | |||
| List<WxCouponOrderCVo> avaList = wxCouponOrderService.queryMicroPayCouponOrder(user, cUser, payment); | |||
| Map retMap = new HashMap(); | |||
| if (order != null) { | |||
| retMap.put("order", order); | |||
| } | |||
| if (avaList.size() > 0) { | |||
| retMap.put("avaList", avaList); | |||
| } | |||
| return new ResultData(retMap); | |||
| } | |||
| @ApiOperation(value = "付款码支付订单", notes = "params:{\"orderId\":\"订单\",\"authCode\":\"String\",\"payment\":\"支付金额\"},\n" + | |||
| "注意:\n" + | |||
| "提醒1:提交支付请求后微信会同步返回支付结果。当返回结果为“系统错误”时,商户系统等待5秒后调用【查询订单API】,查询支付实际交易结果;当返回结果为“USERPAYING”时,商户系统可设置间隔时间(建议10秒)重新查询支付结果,直到支付成功或超时(建议30秒);\n" + | |||
| "提醒2:在调用查询接口返回后,如果交易状况不明晰,请调用【撤销订单API】,此时如果交易失败则关闭订单,该单不能再支付成功;如果交易成功,则将扣款退回到用户账户。当撤销无返回或错误时,请再次调用。注意:请勿扣款后立即调用【撤销订单API】,建议至少15秒后再调用。撤销订单API需要双向证书。") | |||
| @PostMapping("pay_order_create_v2") | |||
| public ResultData saveMicopayPayOrder(@RequestBody Map<String, String> paramMap, HttpServletRequest request) { | |||
| logger.info("saveMicopayPayOrder: " + paramMap.toString()); | |||
| WxMerchantBUser user = getUser(); | |||
| String orderIdStr = paramMap.get("orderId"); | |||
| String authCode = paramMap.get("authCode"); | |||
| String paymentStr = paramMap.get("payment"); | |||
| if (StringUtils.isBlank(orderIdStr)) { | |||
| logger.error("orderId不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| if (StringUtils.isBlank(authCode)) { | |||
| logger.error("authCode不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "authCode不能为空"); | |||
| } | |||
| if (StringUtils.isBlank(paymentStr)) { | |||
| logger.error("payment不能为空"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payment不能为空"); | |||
| } | |||
| String ipStr = IPUtil.getIpAddr(request); | |||
| WxOrder order = wxOrderService.getById(Long.valueOf(orderIdStr)); | |||
| if (order == null) { | |||
| logger.error("订单未找到" + orderIdStr); | |||
| return new ResultData(ErrorCode.ORDER_IS_FAIL); | |||
| } | |||
| WxPayOrder record = new WxPayOrder(); | |||
| record.setTenantId(user.getTenantId()); | |||
| record.setOrderId(order.getId()); | |||
| record.setAuthCode(authCode); | |||
| record.setPayAmount(Integer.valueOf(paymentStr)); | |||
| record.setIp(ipStr); | |||
| try { | |||
| return wxPayOrderService.createMicroPayOrder(user, record, EnumPayWay.PAY_WAY_WECHAT); | |||
| } catch (MallinkException e) { | |||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error("payment wechat, order create error, req 3: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation(value = "查询付款码支付订单", notes = "{\"payOrderId\":\"String\",\"orderId\":\"String\"}") | |||
| @PostMapping("order_query") | |||
| public ResultData queryMicopayOrder(@RequestBody Map<String, String> paramMap) { | |||
| @@ -267,12 +388,17 @@ public class WxMicroPayController extends BaseController { | |||
| } | |||
| } | |||
| @ApiOperation(value = "收银台核销券", notes = "{\"couponOrderId\":\"必填\",\"payPrice\":\"支付金额(分)\"}") | |||
| @ApiOperation(value = "收银台核销券", notes = "{\"orderId\":\"必填\",\"couponOrderId\":\"必填\",\"payPrice\":\"支付金额(分)\"}") | |||
| @PostMapping("userCouponOrderForMicroPay") | |||
| public ResultData userCouponOrderForMicroPay(@RequestBody Map<String, String> paramMap) { | |||
| logger.info("couponOrderController.verify:"+paramMap.toString()); | |||
| String orderIdStr = paramMap.get("orderId"); | |||
| String couponOrderIdStr = paramMap.get("couponOrderId"); | |||
| String payPriceStr = paramMap.get("payPrice"); | |||
| if (StringUtils.isBlank(orderIdStr)) { | |||
| logger.error("orderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| if (StringUtils.isBlank(couponOrderIdStr)) { | |||
| logger.error("couponOrderId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| @@ -281,22 +407,29 @@ public class WxMicroPayController extends BaseController { | |||
| logger.error("payPrice不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| Long couponOrderId = 0L; | |||
| Long couponOrderId = 0L, orderId = 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); | |||
| orderId = Long.valueOf(orderIdStr); | |||
| } catch (NumberFormatException e) { | |||
| couponOrderId = 0L; | |||
| orderId = 0L; | |||
| logger.error("couponOrderId参数不正确: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||
| } | |||
| WxCouponOrderCVo wxCouponOrderCVo = wxCouponOrderService.detailCUserVo(couponOrderIdStr); | |||
| WxOrder microOrder = wxOrderService.getById(orderId); | |||
| if (microOrder == null) { | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||
| } | |||
| if (wxCouponOrderCVo == 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())) { | |||
| @@ -327,10 +460,13 @@ public class WxMicroPayController extends BaseController { | |||
| 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); | |||
| remainPrice = wxCouponOrderService.microPayVerify(microOrder, wxCouponOrder, wxMerchantBUser, payPrice); | |||
| } catch (MallinkException e) { | |||
| logger.error("核销异常: " + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -20,6 +20,8 @@ public class PosCouponOrderVerify extends BaseEntity { | |||
| private Long couponOrderId; | |||
| @io.swagger.annotations.ApiModelProperty(value="POS订单ID",name="posOrderId") | |||
| private Long posOrderId; | |||
| @io.swagger.annotations.ApiModelProperty(value="状态,0-inside,1-POS",name="orderFrom") | |||
| private Integer orderFrom; | |||
| @io.swagger.annotations.ApiModelProperty(value="状态,0-使用中,1-禁用",name="state") | |||
| private Integer state; | |||
| @io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate") | |||
| @@ -93,8 +93,8 @@ public class WxOrder extends BaseEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="POS SN",name="posOrderCreateSn") | |||
| private String posOrderCreateSn; | |||
| @io.swagger.annotations.ApiModelProperty(value="总支付金额(分),收银台用券时使用",name="totalPayment") | |||
| private Integer totalPayment; | |||
| @io.swagger.annotations.ApiModelProperty(value="实际支付金额(分),收银台用券时使用",name="realPayment") | |||
| private Integer realPayment; | |||
| @TableField(exist = false) | |||
| protected List<Integer> statusS; | |||
| @@ -0,0 +1,38 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * @author Stormeye | |||
| */ | |||
| public enum EnumOrderFrom { | |||
| INSIDE(0,"内部使用"), | |||
| POS(1,"来源于POS") | |||
| ; | |||
| public static EnumOrderFrom getEnum(Integer code) { | |||
| for (EnumOrderFrom value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumOrderFrom(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -6,7 +6,8 @@ package com.iformall.enums; | |||
| public enum EnumPayFrom { | |||
| INSIDE_C(0, "C端支付"), | |||
| POS(1, "POS"); | |||
| POS(1, "POS"), | |||
| INSIDE_B(2, "B端支付"); | |||
| public static EnumPayFrom getEnum(Integer code) { | |||
| for (EnumPayFrom value : values()) { | |||
| @@ -5,6 +5,7 @@ import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCouponOrder; | |||
| import com.iformall.domain.po.WxMerchantBUser; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.vo.*; | |||
| import javax.servlet.http.HttpServletRequest; | |||
| @@ -196,6 +197,6 @@ public interface WxCouponOrderService { | |||
| */ | |||
| List<WxCouponOrderCVo> queryMicroPayCouponOrder(WxMerchantBUser user, WxCUser cUser, Integer price); | |||
| Integer microPayVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer price); | |||
| Integer microPayVerify(WxOrder microOrder, WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer price); | |||
| } | |||
| @@ -42,7 +42,16 @@ public interface WxOrderService { | |||
| * @param totalFeeStr | |||
| * @return 订单id | |||
| */ | |||
| WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr, String totalPayStr); | |||
| WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr); | |||
| /** | |||
| * 付款码支付v2 | |||
| * @param user | |||
| * @param cUser | |||
| * @param payment | |||
| * @return 订单id | |||
| */ | |||
| WxOrder saveMicroPayOrderV2(WxMerchantBUser user, WxCUser cUser, Integer payment); | |||
| /** | |||
| * 商户码-储值卡支付 | |||
| @@ -119,6 +119,12 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| @Autowired | |||
| WxMsgLimitService wxMsgLimitService; | |||
| @Autowired | |||
| PosCouponOrderVerifyMapper posCouponOrderVerifyMapper; | |||
| @Autowired | |||
| WxPayOrderMapper payOrderMapper; | |||
| @Override | |||
| public PageInfo<WxCouponOrder> listAsPage(WxCouponOrder record, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderMapper.findList(record)); | |||
| @@ -1057,7 +1063,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public Integer microPayVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer payPrice) { | |||
| public Integer microPayVerify(WxOrder microOrder, WxCouponOrder couponOrder, WxMerchantBUser bUser, Integer payPrice) { | |||
| // 1. 获取券信息 | |||
| WxCoupon wxCoupon = wxCouponMapper.selectById(couponOrder.getCouponId()); | |||
| @@ -1105,6 +1111,21 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_PRE_VERIFY); | |||
| } | |||
| } | |||
| // 1. insert posOrderId | |||
| PosCouponOrderVerify posCouponOrderVerify = new PosCouponOrderVerify(); | |||
| posCouponOrderVerify.setTenantId(couponOrder.getTenantId()); | |||
| posCouponOrderVerify.setCouponOrderId(couponOrder.getId()); | |||
| posCouponOrderVerify.setPosOrderId(microOrder.getId()); | |||
| posCouponOrderVerify.setOrderFrom(EnumOrderFrom.INSIDE.getCode()); | |||
| posCouponOrderVerify.setState(EnumEnableType.Enable.getCode()); | |||
| try { | |||
| posCouponOrderVerifyMapper.insert(posCouponOrderVerify); | |||
| } catch (Exception e) { | |||
| logger.error("db failed: couponOrder-" + couponOrder.getId() + ", e:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||
| } | |||
| int num = 0; | |||
| try { | |||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); //1核销 | |||
| @@ -1121,10 +1142,47 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num); | |||
| } | |||
| // 添加payOrder | |||
| WxPayOrder payOrder = new WxPayOrder() {{ | |||
| Date curDate = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| Long id = idWorker.nextId(); | |||
| setId(id); | |||
| setTenantId(microOrder.getTenantId()); | |||
| setCUserId(microOrder.getCUserId()); | |||
| setOrderId(microOrder.getId()); | |||
| setCreateTime(curDate); | |||
| setUpdateTime(curDate); | |||
| setPayTimeStart(curDate); | |||
| setPayTimeEnd(curDate); | |||
| setPayOrderNo(String.valueOf(id)); | |||
| setPayAmount(wxCoupon.getPrice()); | |||
| setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||
| setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| setShare(EnumPayShare.NO.getCode()); | |||
| setPayFrom(EnumPayFrom.INSIDE_B.getCode()); | |||
| }}; | |||
| try { | |||
| payOrderMapper.insert(payOrder); | |||
| } catch (Exception e) { | |||
| logger.error("payOrder error"); | |||
| } | |||
| Integer remainPrice = payPrice - wxCoupon.getPrice(); | |||
| if (remainPrice < 0) { | |||
| remainPrice = 0; | |||
| } | |||
| WxOrder updateOrder = new WxOrder(); | |||
| updateOrder.setId(microOrder.getId()); | |||
| updateOrder.setRealPayment(remainPrice); | |||
| wxOrderMapper.updateById(updateOrder); | |||
| // 成长值 | |||
| try { | |||
| WxOrder order = wxOrderMapper.selectById(couponOrder.getOrderId()); | |||
| wxScoreRulesService.addScore2(EnumScoreType.CONSUMPTION, order, wxCoupon.getBusiness()); | |||
| WxOrder orderByCoupon = wxOrderMapper.selectById(couponOrder.getOrderId()); | |||
| wxScoreRulesService.addScore2(EnumScoreType.CONSUMPTION, orderByCoupon, wxCoupon.getBusiness()); | |||
| } catch (Exception e) { | |||
| logger.error("成长值:" + e.getMessage()); | |||
| } | |||
| @@ -1150,10 +1208,6 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||
| logger.error("积分值:" + e.getMessage()); | |||
| } | |||
| Integer remainPrice = payPrice - wxCoupon.getPrice(); | |||
| if (remainPrice < 0) { | |||
| remainPrice = 0; | |||
| } | |||
| return remainPrice; | |||
| } | |||
| @@ -554,7 +554,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr, String totalPayStr) { | |||
| public WxOrder saveMicroPayOrder(WxMerchantBUser user, String totalFeeStr) { | |||
| // 检查用户 | |||
| if (user == null) { | |||
| logger.error("用户不存在"); | |||
| @@ -579,13 +579,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| BigDecimal totalFee = new BigDecimal(totalFeeStr); | |||
| totalFee.setScale(2, BigDecimal.ROUND_HALF_UP); // 第一个变量是小数位数,第二个变量是取舍方法(四舍五入) | |||
| Integer totalPayment = null; | |||
| 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(); | |||
| Long orderNumber = idWorker.nextId(); | |||
| @@ -601,7 +595,62 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| record.setProductId(user.getId()); | |||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | |||
| record.setPayment(payment); | |||
| record.setTotalPayment(totalPayment); | |||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
| record.setDetail(bodyStr); | |||
| record.setCreateDate(curr); | |||
| record.setUpdateDate(curr); | |||
| try { | |||
| // 保存订单 | |||
| wxOrderMapper.insert(record); | |||
| } catch (RuntimeException e) { | |||
| logger.error("保存订单:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.ORDER_SAVE_ERR); | |||
| } | |||
| return record; | |||
| } | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxOrder saveMicroPayOrderV2(WxMerchantBUser user, WxCUser cUser, Integer payment) { | |||
| // 检查用户 | |||
| if (user == null) { | |||
| logger.error("用户不存在"); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| // 检查商户 | |||
| WxMerchant wxMerchant = wxMerchantMapper.selectById(user.getMerchantId()); | |||
| if (wxMerchant == null) { | |||
| logger.error("商户不存在, merchantId: " + user.getMerchantId()); | |||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||
| } | |||
| if (wxMerchant.getStatus() == EnumMerchantStatus.NOT_VALID.getCode()) { | |||
| logger.error("商户已禁用, merchantId: " + user.getMerchantId()); | |||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); | |||
| } | |||
| WxOrder record = new WxOrder(); | |||
| Date curr = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| Long orderNumber = idWorker.nextId(); | |||
| // body | |||
| // tenant_id + merchant_id + title + subtitle | |||
| String bodyStr = "刷卡支付, 金额:" + payment; | |||
| record.setId(orderNumber); | |||
| record.setTenantId(user.getTenantId()); | |||
| record.setOrderNumber(orderNumber); | |||
| record.setType(EnumOrderType.MICROPAY.getCode()); | |||
| record.setProductId(user.getId()); | |||
| if (cUser != null) { | |||
| record.setCUserId(cUser.getId()); | |||
| } | |||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | |||
| record.setPayment(payment); | |||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||
| record.setDetail(bodyStr); | |||
| record.setCreateDate(curr); | |||