diff --git a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java index d9d7ee6c1..ce9ce1f21 100644 --- a/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java +++ b/mallinkPosApi/src/main/java/com/iformall/controller/PosController.java @@ -88,6 +88,7 @@ public class PosController extends BaseController { "\"order_operator_id\":\"string(必填)\"," + "\"mem_id\":\"string(选填)\"," + "\"mem_phone_number\":\"string(选填)\"," + + "\"card_id\":\"string(选填)\"," + "\"business_type\":\"string(0:核销1支付(必填)\"," + "\"order_amount\":\"string单位(分)(必填)\"," + "\"order_amount_left\":\"string单位(分)(必填)\"," + @@ -202,11 +203,22 @@ public class PosController extends BaseController { } } - @ApiOperation(value = "POS订单同步", notes = "支付成功/支付取消后订单同步") - @PostMapping("/posOrderSync") - @SystemControllerLog(description = "POS订单同步") - public Map posOrderSync(@RequestBody Map params) { - logger.info(params.toString()); + @ApiOperation(value = "消费卡支付", notes = "{" + + "\"dev_id\":\"string(必填)\"," + + "\"nonce_str\":\"string(必填)\"," + + "\"tenant_id\":\"string(必填)\"," + + "\"merchant_id\":\"string(必填)\"," + + "\"order_operation_id\":\"string(必填)\"," + + "\"business_type\":\"string(0:核销1支付(必填)\"," + + "\"order_number_of_platform\":\"string(必填)\"," + + "\"order_amount\":\"string单位(分)(选填)\"," + + "\"order_amount_left\":\"string单位(分)(选填)\"," + + "\"order_create_sn\":\"string单位(分)(必填)\"," + + "\"card_id\":\"string(必填)\"," + + "\"amount_paid_by_card\":\"string(必填)\"}") + @PostMapping("/cardPayPre") + @SystemControllerLog(description = "消费卡支付") + public Map cardPayPre(@RequestBody Map params) { JSONObject payContent = new JSONObject(); JSONObject retObj = new JSONObject(); @@ -220,31 +232,34 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retObj = posService.posOrderSync(params); + retObj = posService.cardPayPre(params); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } catch (MallinkException e) { return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage()); } catch (Exception e) { return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage()); } - - return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } - @ApiOperation(value = "消费卡支付", notes = "{" + + + @ApiOperation(value = "消费卡支付取消", notes = "{" + "\"dev_id\":\"string(必填)\"," + "\"nonce_str\":\"string(必填)\"," + "\"tenant_id\":\"string(必填)\"," + "\"merchant_id\":\"string(必填)\"," + "\"order_operation_id\":\"string(必填)\"," + - "\"business_type\":\"string(0:核销1支付(必填)\"," + "\"order_number_of_platform\":\"string(必填)\"," + "\"order_amount\":\"string单位(分)(选填)\"," + "\"order_amount_left\":\"string单位(分)(选填)\"," + "\"order_create_sn\":\"string单位(分)(必填)\"," + + "\"payment_info\":{" + "\"card_id\":\"string(必填)\"," + - "\"amount_paid_by_card\":\"string(必填)\"}") - @PostMapping("/cardPayPre") - @SystemControllerLog(description = "消费卡支付") - public Map cardPayPre(@RequestBody Map params) { + "\"card_spend_id\":\"string(必填)\"," + + "\"amount_paid_by_card\":\"string单位(分)(选填)\"," + + "\"amount_left_after_pay\":\"string单位(分)(选填)\"" + + "}}") + @PostMapping("/cardPayPreCancel") + @SystemControllerLog(description = "消费卡支付取消") + public Map cardPayPreCancel(@RequestBody Map params) { JSONObject payContent = new JSONObject(); JSONObject retObj = new JSONObject(); @@ -258,16 +273,17 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retObj = posService.cardPayPre(params); + retObj = posService.cardPayPreCancel(params); return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } catch (MallinkException e) { return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage()); } catch (Exception e) { - return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage()); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage()); } } - @ApiOperation(value = "消费卡支付取消", notes = "{" + + @ApiOperation(value = "POS订单同步", notes = "支付成功/支付取消后订单同步" + + "{" + "\"dev_id\":\"string(必填)\"," + "\"nonce_str\":\"string(必填)\"," + "\"tenant_id\":\"string(必填)\"," + @@ -279,10 +295,14 @@ public class PosController extends BaseController { "\"order_create_sn\":\"string单位(分)(必填)\"," + "\"payment_info\":{" + "\"card_id\":\"string(必填)\"," + - "\"card_spend_id\":\"string(必填)\"}") - @PostMapping("/cardPayPreCancel") - @SystemControllerLog(description = "消费卡支付取消") - public Map cardPayPreCancel(@RequestBody Map params) { + "\"card_spend_id\":\"string(必填)\"," + + "\"amount_paid_by_card\":\"string单位(分)(选填)\"," + + "\"amount_left_after_pay\":\"string单位(分)(选填)\"" + + "}}") + @PostMapping("/posOrderSync") + @SystemControllerLog(description = "POS订单同步") + public Map posOrderSync(@RequestBody Map params) { + logger.info(params.toString()); JSONObject payContent = new JSONObject(); JSONObject retObj = new JSONObject(); @@ -296,13 +316,14 @@ public class PosController extends BaseController { logger.info(WxPayConstant.RES_KEY + ": " + resKey); try { - retObj = posService.cardPayPreCancel(params); - return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); + retObj = posService.posOrderSync(params); } catch (MallinkException e) { return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", e.getErrorCode(), e.getMessage()); } catch (Exception e) { - return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",500, e.getMessage()); + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "", 500, e.getMessage()); } + + return buildReturnMap(retObj, resKey, WxPayConstant.RET_SUCCESS, "",null); } /** diff --git a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java index 14225ac7a..cefaae1b7 100644 --- a/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java +++ b/mallinkPosApi/src/main/java/com/iformall/service/impl/PosServiceImpl.java @@ -246,7 +246,8 @@ public class PosServiceImpl implements PosService { String memIdStr = params.get(WxPayConstant.MEM_ID); // 会员ID String memPhoneStr = params.get(WxPayConstant.MEM_PHONE); // 会员手机 - String orderAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单金额(单位:分) + String cardIdStr = params.get(WxPayConstant.CARD_ID); // 卡ID + String orderAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单金额(单位:分) String orderAmountLeftStr = params.get(WxPayConstant.ORDER_AMOUNT_LEFT); // POS订单金额(单位:分) if (StringUtils.isBlank(orderAmountStr)) { errParam(WxPayConstant.ORDER_AMOUNT); @@ -258,11 +259,29 @@ public class PosServiceImpl implements PosService { } else { dataMap.put(WxPayConstant.ORDER_AMOUNT_LEFT, orderAmountLeftStr); } - if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { - errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE); + + WxCUser user = null; + if (StringUtils.isNotBlank(cardIdStr)) { + Long cardId; + try { + cardId = Long.valueOf(cardIdStr); + } catch (NumberFormatException e) { + logger.error(e.getMessage()); + throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); + } + WxCouponOrder couponOrder = couponOrderMapper.selectByPrimaryKey(cardId); + if (couponOrder == null) { + throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); + } + user = cUserService.getById(couponOrder.getOwnerId()); + } else { + if (StringUtils.isBlank(memIdStr) && StringUtils.isBlank(memPhoneStr)) { + errParam2(WxPayConstant.MEM_ID, WxPayConstant.MEM_PHONE); + } + // 10. 获取会员信息 + user = getMemUser(tenantId, memIdStr, memPhoneStr); } - // 10. 获取会员信息 - WxCUser user = getMemUser(tenantId, memIdStr, memPhoneStr); + if (user == null) { logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); throw new MallinkException(ErrorCode.USER_NOT_MEMBER); @@ -1293,7 +1312,7 @@ public class PosServiceImpl implements PosService { creditHistory.setTenantId(couponOrderCVo.getTenantId()); creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); creditHistory.setCouponId(couponOrderCVo.getCouponId()); - creditHistory.setBusinessId(Long.valueOf(coupon.getBusiness())); + creditHistory.setBusinessId(coupon.getBusiness()); creditHistory.setSpend(couponOrderCVo.getCouponPrice()); //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 creditHistory.setMerchantId(merchantId); @@ -1309,6 +1328,32 @@ public class PosServiceImpl implements PosService { return 0; } + private int posAddCreditForPay(WxMerchant merchant, Long buUserId, Long memId, Integer payment) { + try { + //-------此处为【现金支付】记录增加积分操作------- + WxCreditHistory creditHistory = new WxCreditHistory(); + creditHistory.setOperatorType(EnumUserType.BUSER.getCode()); + creditHistory.setOperatorId(buUserId); + creditHistory.setCUserId(memId); + creditHistory.setCreateDate(new Date()); + creditHistory.setTenantId(merchant.getTenantId()); + creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); + creditHistory.setBusinessId(merchant.getBusinessId()); + creditHistory.setSpend(payment); + //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 + creditHistory.setMerchantId(merchant.getId()); + creditHistory = creditHistoryService.saveOrUpdate(creditHistory); + if (creditHistory.getCreditNum() != null) { + return creditHistory.getCreditNum(); + } else { + return 0; + } + } catch (Exception e) { + logger.error("核销积分值异常:" + e.getMessage()); + } + return 0; + } + /** * 核销回退 * @param couponOrderCVo @@ -1400,6 +1445,8 @@ public class PosServiceImpl implements PosService { String tenantId = params.get(WxPayConstant.TENANT_ID); // 租户ID String merchantIdStr = params.get(WxPayConstant.MERCHANT_ID); // 商户ID String buUserIdStr = params.get(WxPayConstant.BUSER_ID); // POS操作员ID + String memIdStr = params.get(WxPayConstant.MEM_ID); // 会员ID + String memPhoneStr = params.get(WxPayConstant.MEM_PHONE); // 会员手机 String sceneTypeStr = params.get(WxPayConstant.SCENE_TYPE); // 交易场景 String posOrderIdStr = params.get(WxPayConstant.POS_ORDER_ID); // POS订单ID String orderAmountStr = params.get(WxPayConstant.ORDER_AMOUNT); // POS订单总额(单位:分) @@ -1488,6 +1535,17 @@ public class PosServiceImpl implements PosService { logger.error("卡不存在: " + cardIdStr); throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); } + if (StringUtils.isNotBlank(memIdStr) || StringUtils.isNotBlank(memPhoneStr)) { + WxCUser cuUser = getMemUser(tenantId, memIdStr, memPhoneStr); + if (cuUser == null) { + logger.error(ErrorCode.USER_NOT_MEMBER.getMessage()); + throw new MallinkException(ErrorCode.USER_NOT_MEMBER); + } + if (couponOrder.getOwnerId().equals(cuUser.getId())) { + logger.error(ErrorCode.POS_CARD_OWNER_NOT_EQUAL.getMessage()); + throw new MallinkException(ErrorCode.POS_CARD_OWNER_NOT_EQUAL); + } + } WxCardInfo cardInfo = checkAndGetCardinfo(cardId, merchantId); @@ -1773,22 +1831,30 @@ public class PosServiceImpl implements PosService { WxMerchant merchant = checkAndGetMerchant(merchantId); // 3. check buUser WxMerchantBUser merchantBUser = checkAndGetMerchantUser(buUserId, merchantId); + // 4. 同步 if (posStatusStr.equalsIgnoreCase(WxPayConstant.NEU_ORDER_PAY)) { + // 4.1 支付同步 WxOrder order = createOrderByPos(merchantBUser, memId, posOrderId, posAmount.intValue(), orderTime); String payDetail = params.get(WxPayConstant.NEU_PAY_DETAIL); JSONObject payDetailObj = JSON.parseObject(payDetail); + PromotionCalc scoreCreditCalc = new PromotionCalc(); + scoreCreditCalc.setScore(0); + scoreCreditCalc.setCredit(0); JSONArray payDetailList = payDetailObj.getJSONArray(WxPayConstant.NEU_PAY_DETAIL_LIST); for (int i=0;i payDetailOne = new HashMap<>(); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_ID, posPayOrderId); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TIME, neuDateFormat.format(curDate)); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TYPE, posPaymentType); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_TYPE_DES, posPaymentTypeDes); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_PARAM, "{}"); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_STATUS, posPaymentStatus); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_OUT_NO, couponOrderId); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_AMOUNT, orderAmount); + payDetailOne.put(WxPayConstant.NEU_PAY_ORDER_OUT_TIME, neuDateFormat.format(curDate)); + + JSONArray payDetailList = new JSONArray(); + payDetailList.add(payDetailOne); + + Map reqObj = new HashMap<>(); + reqObj.put(WxPayConstant.NONCE_STR, "1"); + reqObj.put(WxPayConstant.DEV_ID, devId); + reqObj.put(WxPayConstant.NEU_TENANT_ID, tenantId); + reqObj.put(WxPayConstant.NEU_MERCHANT_ID, merchantId); + reqObj.put(WxPayConstant.NEU_BU_USER_ID, buUserId); + reqObj.put(WxPayConstant.NEU_MEM_ID, memId); + reqObj.put(WxPayConstant.NEU_MEM_PHONE, memPhone); + reqObj.put(WxPayConstant.NEU_ORDER_SCENE_TYPE, sceneType); + reqObj.put(WxPayConstant.NEU_ORDER_ID, posOrderId); + reqObj.put(WxPayConstant.NEU_ORDER_TIME, neuDateFormat.format(curDate)); + reqObj.put(WxPayConstant.NEU_ORDER_AMOUNT, orderAmount); + reqObj.put(WxPayConstant.NEU_ORDER_CREATE_SN, posSN); + reqObj.put(WxPayConstant.NEU_ORDER_STATUS, "0"); + JSONObject payDetail = new JSONObject(); + payDetail.put(WxPayConstant.NEU_PAY_DETAIL_LIST, JSON.toJSONString(payDetailList)); + reqObj.put(WxPayConstant.NEU_PAY_DETAIL, JSON.toJSONString(payDetail)); + boolean resSigned = sendAndRes("/posOrderSync", reqObj); + Assert.assertEquals(resSigned, true); + } + private boolean sendAndRes(String url, Map reqObj) throws Exception { reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); String reqJsonStr = JSONObject.toJSONString(reqObj); diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 447ffe4ed..110108b5b 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -249,6 +249,7 @@ public enum ErrorCode{ POS_COUPON_REFUND_ERROR(11107, "POS券包退款异常"), POS_CARD_PAY_NOT_CANCEL(11108, "卡支付无法取消"), POS_CARD_ONLY_SUPPORT_PAY(11109, "卡支付只支持支付"), + POS_CARD_OWNER_NOT_EQUAL(11110, "卡拥有者不对应"), POS_CMD_FAIL(11200, "POS命令错误"), diff --git a/mallinkService/src/main/java/com/iformall/domain/po/WxCreditHistory.java b/mallinkService/src/main/java/com/iformall/domain/po/WxCreditHistory.java index 1545a1983..86cc1c78f 100644 --- a/mallinkService/src/main/java/com/iformall/domain/po/WxCreditHistory.java +++ b/mallinkService/src/main/java/com/iformall/domain/po/WxCreditHistory.java @@ -64,7 +64,7 @@ public class WxCreditHistory extends BaseEntity { @io.swagger.annotations.ApiModelProperty(value="券ID(积分兑换券时生成)",name="couponId") private Long couponId; @io.swagger.annotations.ApiModelProperty(value="业态ID(计算新增积分时使用)",name="businessId") - private Long businessId; + private Integer businessId; @io.swagger.annotations.ApiModelProperty(value="花费",name="spend") private Integer spend; @io.swagger.annotations.ApiModelProperty(value="兑换用途",name="changePurpose") diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/PromotionCalc.java b/mallinkService/src/main/java/com/iformall/domain/vo/PromotionCalc.java index 90cc48427..99dd6bc5c 100644 --- a/mallinkService/src/main/java/com/iformall/domain/vo/PromotionCalc.java +++ b/mallinkService/src/main/java/com/iformall/domain/vo/PromotionCalc.java @@ -14,4 +14,9 @@ public class PromotionCalc extends BaseEntity { @io.swagger.annotations.ApiModelProperty(value="优惠后剩余金额",name="amountLeftAfterPay") Integer amountLeftAfterPay; + @io.swagger.annotations.ApiModelProperty(value="成长值",name="score") + Integer score; + @io.swagger.annotations.ApiModelProperty(value="积分",name="credit") + Integer credit; + } diff --git a/mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java b/mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java index 55b48fabd..ec9006260 100644 --- a/mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java +++ b/mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java @@ -3,6 +3,7 @@ package com.iformall.service; import com.github.pagehelper.PageInfo; import com.iformall.common.ResultData; import com.iformall.domain.po.*; +import com.iformall.domain.vo.PromotionCalc; import com.iformall.domain.vo.WxCardSpendVo; import com.iformall.exception.MallinkException; @@ -108,4 +109,5 @@ public interface WxCardSpendService { */ WxCardSpend cardSpendForPosPrePay(WxCardSpend record) throws MallinkException; WxCardInfo cardSpendForPosPrePayCancel(WxCardInfo cardInfo, WxCardSpend record) throws MallinkException; + WxCardSpend cardSpendForPosPay(PromotionCalc scoreCreditCalc, WxCardSpend record, WxMerchant merchant, WxMerchantBUser buUser) throws MallinkException; } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java index 73913731b..b8c3b8ae2 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java @@ -8,6 +8,7 @@ import com.iformall.common.Result; import com.iformall.common.ResultData; import com.iformall.domain.dto.WxSharingOrderDto; import com.iformall.domain.po.*; +import com.iformall.domain.vo.PromotionCalc; import com.iformall.domain.vo.WxCardSpendVo; import com.iformall.enums.*; import com.iformall.exception.MallinkException; @@ -265,8 +266,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { creditHistory.setCreateDate(new Date()); creditHistory.setTenantId(record.getTenantId()); creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); - creditHistory.setCouponId(coupon.getId()); - creditHistory.setBusinessId(Long.valueOf(coupon.getBusiness())); + creditHistory.setBusinessId(coupon.getBusiness()); creditHistory.setSpend(real_payment); //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 creditHistory.setMerchantId(record.getMerchantId()); @@ -546,10 +546,11 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { excelService.exportExcel(list, null, "卡消费记录", WxCardSpendVo.class, "卡消费记录.xlsx", response, false); } + @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) public WxCardSpend cardSpendForPosPrePay(WxCardSpend record) throws MallinkException { - Date curDate = new Date(); final IdWorker idWorker = IdWorker.get(); + Date curDate = new Date(); // 1. get card info WxCardInfo cardInfo = wxCardInfoMapper.selectByPrimaryKey(record.getCardId()); if (cardInfo == null) { @@ -646,6 +647,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { return record; } + @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) public WxCardInfo cardSpendForPosPrePayCancel(WxCardInfo cardInfo, WxCardSpend record) throws MallinkException { Date curDate = new Date(); @@ -663,11 +665,6 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { logger.error("card's coupon not found: " + cardInfo.getCouponId()); throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); } - if (coupon.getSubsidyNum() == null) { - String errMessage = "券补贴额未填写"; - logger.error(errMessage); - throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), errMessage); - } // 3. get pay account WxPayAccount payAccount = null; @@ -694,7 +691,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { updateCardInfo.setRemainingAmount(remaingAmount); updateCardInfo.setRemainingShareFeeAmount(remain_real_pament); updateCardInfo.setUpdateDate(curDate); - // 5.1 如果还是原价更改卡转赠状态 + // 5.1 如果还是原价, 卡可转增,且当前为不可转增,修改为可转增 if (cardInfo.getAmount().equals(remaingAmount) && cardInfo.getSupportTransfer().equals(EnumCouponTransfer.NO.getCode()) && coupon.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) { @@ -721,27 +718,39 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { return updateCardInfo; } + @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) - public WxCardSpend cardSpendForPosPay(WxCardSpend record) throws MallinkException { - Date curDate = new Date(); + public WxCardSpend cardSpendForPosPay(PromotionCalc scoreCreditCalc, WxCardSpend record, WxMerchant merchant, WxMerchantBUser buUser) throws MallinkException { final IdWorker idWorker = IdWorker.get(); - // 1. get card info + Date curDate = new Date(); + // 1. update card_spend + WxCardSpend updateCardSpend = new WxCardSpend(); + updateCardSpend.setPayStatus(EnumCardSpendStatus.NOT_PAY.getCode()); + updateCardSpend.setUpdateDate(curDate); + try { + wxCardSpendMapper.updateByPrimaryKeySelective(updateCardSpend); + } catch (Exception e) { + logger.error("card spend update error"); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "card spend 插入出错!"); + } + + // 2. update coupon card status WxCardInfo cardInfo = wxCardInfoMapper.selectByPrimaryKey(record.getCardId()); if (cardInfo == null) { logger.error("card not found: " + record.getCardId()); throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); } - // 2. coupon - Integer subsidyRate = 0; + if(cardInfo.getRemainingAmount().equals(0)) { + if (cardFinished(curDate, cardInfo)) { + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "couponOrder status 更新出错!"); + } + } + WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(cardInfo.getCouponId()); if (coupon == null) { logger.error("card's coupon not found: " + cardInfo.getCouponId()); throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); } - if (coupon.getSubsidyNum() == null) { - logger.error("卡补贴额未填写: " + cardInfo.getCouponId()); - throw new MallinkException(ErrorCode.CARD_SUBSIDY_NOT_SET); - } // 3. get pay account WxPayAccount payAccount = null; @@ -751,77 +760,10 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { payAccount = payAccountMapper.selectOne(payAccountQ); } catch (Exception e) { logger.error("获取payAccount error: " + record.getTenantId()); - throw new MallinkException(ErrorCode.SYS_MCH_NOT_FOUND); - } - - // 4. 扣减计算 - Double paymentD = 1.0 * cardInfo.getSaleAmount() * record.getDeductionAmount() / cardInfo.getAmount(); - Integer payment = paymentD.intValue(); - int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate()); - Integer real_payment = payment - iChargeFee; - Integer remain_real_pament = cardInfo.getRemainingShareFeeAmount() - real_payment; - Integer remaingAmount = cardInfo.getRemainingAmount()-record.getDeductionAmount(); - if (remaingAmount.equals(0)) { - // 最后一次支付时 - real_payment = Math.min(real_payment, cardInfo.getRemainingShareFeeAmount()); - remain_real_pament = cardInfo.getRemainingShareFeeAmount() - real_payment; - } - - // 5. card_spend - record.setTenantId(cardInfo.getTenantId()); - record.setPayment(payment); - record.setRealPayment(real_payment); - record.setCardBeforeAmount(cardInfo.getRemainingAmount()); - record.setCardRemainAmount(remaingAmount); - record.setCardBeforeRealAmount(cardInfo.getRemainingShareFeeAmount()); - record.setCardRemainRealAmount(remain_real_pament); - record.setPayStatus(EnumCardSpendStatus.NOT_PAY.getCode()); - record.setCreateDate(curDate); - record.setUpdateDate(curDate); - if (record.getId() == null) { - record.setId(idWorker.nextId()); - try { - wxCardSpendMapper.insertSelective(record); - } catch (Exception e) { - logger.error("card spend insert error"); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "卡消费插入出错"); - } - } else { - try { - wxCardSpendMapper.updateByPrimaryKeySelective(record); - } catch (Exception e) { - logger.error("card spend update error"); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "卡消费更新出错"); - } + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "获取payAccount失败"); } - // 7. update card info - WxCardInfo updateCardInfo = new WxCardInfo(); - updateCardInfo.setId(cardInfo.getId()); - updateCardInfo.setRemainingAmount(remaingAmount); - updateCardInfo.setRemainingShareFeeAmount(remain_real_pament); - updateCardInfo.setUpdateDate(curDate); - // 7.1 消费后,修改卡转赠状态 - if (cardInfo.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) { - updateCardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); - } - try { - wxCardInfoMapper.updateByPrimaryKeySelective(updateCardInfo); - } catch (Exception e) { - String errMessage = "消费卡信息更新出错: " + cardInfo.getId(); - logger.error(errMessage); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage); - } - // 7.2 update coupon card status - if(cardInfo.getRemainingAmount().equals(0)) { - if (cardFinished(curDate, cardInfo)) { - String errMessage = "消费卡信息更新出错: " + cardInfo.getId(); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage); - } - } - - /* - // 8. 补贴 + // 3. 补贴 // 补贴额 = 商城补贴总额/卡券面额 * 抵扣额(本次支付额) Double subsidyFeeD = 1.0 * record.getDeductionAmount() * coupon.getSubsidyNum() / cardInfo.getAmount(); Integer subsidyFee = subsidyFeeD.intValue(); @@ -833,14 +775,14 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); merchantSubsidy.setId(idWorker.nextId()); merchantSubsidy.setTenantId(record.getTenantId()); - /// merchantSubsidy.setOrderId(order.getId()); TODO + merchantSubsidy.setOrderId(record.getOrderId()); merchantSubsidy.setOrderType(EnumOrderType.PREPAIDCARD.getCode()); merchantSubsidy.setMerchantId(record.getMerchantId()); merchantSubsidy.setCouponOrderId(cardInfo.getId()); merchantSubsidy.setCouponType(EnumCouponType.CARD_MULTIMCH.getCode()); merchantSubsidy.setOrderPayment(record.getDeductionAmount()); - merchantSubsidy.setReceiverPayment(payment); - merchantSubsidy.setRealPayment(real_payment); + merchantSubsidy.setReceiverPayment(record.getPayment()); + merchantSubsidy.setRealPayment(record.getRealPayment()); merchantSubsidy.setSubsidy(subsidyFee); merchantSubsidy.setRealSubsidy(realSubsidyFee); if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { @@ -858,12 +800,10 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { try { wxMerchantSubsidyMapper.insertSelective(merchantSubsidy); } catch (Exception e) { - String errMessage = "商户补贴信息插入出错!"; - logger.error(errMessage); - throw new MallinkException(ErrorCode.DB_FAIL.getCode(), errMessage); + logger.error("merchantSubsidy info insert error"); + throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "merchantSubsidy info 插入出错!"); } } - */ // 9. 分账 try { @@ -878,37 +818,42 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { } } - /* // 成长值 try { - orderUpdate.setPayment(real_payment); - wxScoreRulesService.addScore2(EnumScoreType.CONSUMPTION, orderUpdate, coupon.getBusiness()); + WxOrder orderUpdate = new WxOrder(); + orderUpdate.setId(record.getOrderId()); + orderUpdate.setTenantId(record.getTenantId()); + orderUpdate.setCUserId(record.getOwnerId()); + orderUpdate.setPayment(record.getRealPayment()); + orderUpdate.setPaymentTime(record.getUpdateDate()); + orderUpdate.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); + int point = wxScoreRulesService.addScore2(EnumScoreType.CONSUMPTION, orderUpdate, coupon.getBusiness()); + scoreCreditCalc.setScore(scoreCreditCalc.getScore() + point); } catch (Exception e) { logger.error("成长值:" + e.getMessage()); } - */ - /* // 积分 try { //-------此处为【现金支付】记录增加积分操作------- WxCreditHistory creditHistory = new WxCreditHistory(); - creditHistory.setOperatorType(EnumUserType.CUSER.getCode()); - creditHistory.setOperatorId(record.getOwnerId()); + creditHistory.setOperatorType(EnumUserType.BUSER.getCode()); + creditHistory.setOperatorId(buUser.getId()); creditHistory.setCUserId(record.getOwnerId()); creditHistory.setCreateDate(new Date()); creditHistory.setTenantId(record.getTenantId()); creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); - creditHistory.setCouponId(coupon.getId()); - creditHistory.setBusinessId(Long.valueOf(coupon.getBusiness())); - creditHistory.setSpend(real_payment); + creditHistory.setBusinessId(merchant.getBusinessId()); + creditHistory.setSpend(record.getRealPayment()); //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 creditHistory.setMerchantId(record.getMerchantId()); - wxCreditHistoryService.saveOrUpdate(creditHistory); + creditHistory = wxCreditHistoryService.saveOrUpdate(creditHistory); + if (creditHistory != null) { + scoreCreditCalc.setCredit(scoreCreditCalc.getCredit() + creditHistory.getCreditNum()); + } } catch (Exception e) { logger.error("积分值:" + e.getMessage()); } - */ return record; } } diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java index f1fb15966..f2c0fd52f 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java @@ -376,7 +376,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { creditHistory.setTenantId(couponOrder.getTenantId()); creditHistory.setCreditType(EnumScoreType.CONSUMPTION.getCode()); creditHistory.setCouponId(wxCoupon.getId()); - creditHistory.setBusinessId(Long.valueOf(wxCoupon.getBusiness())); + creditHistory.setBusinessId(wxCoupon.getBusiness()); creditHistory.setSpend(couponOrder.getCouponPrice()); //如果券与商户一对一 则直接将消费商户更新为此商户 若一对多 则消费商户显示多商户 creditHistory.setMerchantId(bUser.getMerchantId()); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java index 4ce9ab5fa..8435ca599 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxCreditHistoryServiceImpl.java @@ -326,7 +326,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { Map creditMap = Maps.newHashMap(); if (wxMerchant != null && wxMerchant.getBusinessId() != null) { WxCreditHistory wxCreditHistory = new WxCreditHistory(); - wxCreditHistory.setBusinessId(Long.valueOf(wxMerchant.getBusinessId())); + wxCreditHistory.setBusinessId(wxMerchant.getBusinessId()); wxCreditHistory.setTenantId(tenantId); int credit; int creditNew = 0 ; diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java index 2f1eea986..8e9da9618 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -995,7 +995,7 @@ public class WxOrderServiceImpl implements WxOrderService { WxCouponChannel wxCouponChannel = wxCouponChannelMapper.selectByPrimaryKey(updateOrder.getCouponChannelId()); creditHistory.setCouponId(wxCouponChannel.getCouponId()); } - creditHistory.setBusinessId(Long.valueOf(wxMerchant.getBusinessId())); + creditHistory.setBusinessId(wxMerchant.getBusinessId()); creditHistory.setSpend(updateOrder.getPayment()); creditHistory.setMerchantId(wxMerchant.getId()); wxCreditHistoryService.saveOrUpdate(creditHistory);