| @@ -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<String, String> posOrderSync(@RequestBody Map<String, String> 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<String, String> cardPayPre(@RequestBody Map<String, String> 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<String, String> cardPayPre(@RequestBody Map<String, String> params) { | |||
| "\"card_spend_id\":\"string(必填)\"," + | |||
| "\"amount_paid_by_card\":\"string单位(分)(选填)\"," + | |||
| "\"amount_left_after_pay\":\"string单位(分)(选填)\"" + | |||
| "}}") | |||
| @PostMapping("/cardPayPreCancel") | |||
| @SystemControllerLog(description = "消费卡支付取消") | |||
| public Map<String, String> cardPayPreCancel(@RequestBody Map<String, String> 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<String, String> cardPayPreCancel(@RequestBody Map<String, String> params) { | |||
| "\"card_spend_id\":\"string(必填)\"," + | |||
| "\"amount_paid_by_card\":\"string单位(分)(选填)\"," + | |||
| "\"amount_left_after_pay\":\"string单位(分)(选填)\"" + | |||
| "}}") | |||
| @PostMapping("/posOrderSync") | |||
| @SystemControllerLog(description = "POS订单同步") | |||
| public Map<String, String> posOrderSync(@RequestBody Map<String, String> 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); | |||
| } | |||
| /** | |||
| @@ -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<payDetailList.size();i++) { | |||
| JSONObject payOrderObj = payDetailList.getJSONObject(i); | |||
| // ADD to wx_pay_order | |||
| String neuPayOrderType = payOrderObj.getString(WxPayConstant.NEU_PAY_ORDER_TYPE); | |||
| String neuPayOrderTypeStr = payOrderObj.getString(WxPayConstant.NEU_PAY_ORDER_TYPE); | |||
| String neuPayOrderIdStr = payOrderObj.getString(WxPayConstant.NEU_PAY_ORDER_ID); | |||
| String neuPaymentAmount = payOrderObj.getString(WxPayConstant.NEU_PAY_ORDER_AMOUNT); | |||
| String neuPaymentAmountStr = payOrderObj.getString(WxPayConstant.NEU_PAY_ORDER_AMOUNT); | |||
| String neuPayOrderTimeStr = payOrderObj.getString(WxPayConstant.NEU_PAY_ORDER_TIME); | |||
| String neuPayThirdNo = payOrderObj.getString(WxPayConstant.NEU_PAY_ORDER_OUT_NO); | |||
| Date neuPosPayOrderTime = null; | |||
| Integer neuPayOrderType, neuPaymentAmount; | |||
| try { | |||
| neuPosPayOrderTime = neuDateFormat.parse(neuPayOrderTimeStr); | |||
| neuPayOrderType = Integer.valueOf(neuPayOrderTypeStr); | |||
| neuPaymentAmount = Integer.valueOf(neuPaymentAmountStr); | |||
| } catch (ParseException e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); | |||
| @@ -1800,24 +1866,31 @@ public class PosServiceImpl implements PosService { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), e.getMessage()); | |||
| } | |||
| if (neuPayOrderType.equals(String.valueOf(EnumNeuPosPamentType.MEM_DISCOUNT.getCode()))) { | |||
| if (neuPayOrderType.equals(EnumNeuPosPamentType.MEM_DISCOUNT.getCode())) { | |||
| // 会员折扣 | |||
| WxPayOrder payOrder = payOrderFromMemDiscount(merchantBUser, order, memId, neuPayOrderId, neuPaymentAmount, neuPosPayOrderTime); | |||
| } else if (neuPayOrderType.equals(String.valueOf(EnumNeuPosPamentType.MEM_COUPON.getCode()))) { | |||
| } else if (neuPayOrderType.equals(EnumNeuPosPamentType.MEM_COUPON.getCode())) { | |||
| // 优惠券 | |||
| WxPayOrder payOrder = payOrderFromCouponVerify(merchantBUser, order, memId, iSceneType, | |||
| WxPayOrder payOrder = payOrderFromCouponVerify( | |||
| scoreCreditCalc, | |||
| merchantBUser, order, memId, iSceneType, | |||
| neuPayOrderId, neuPaymentAmount, neuPosPayOrderTime, neuPayThirdNo); | |||
| Long couponOrderId = Long.valueOf(neuPayThirdNo); | |||
| couponOrderService.sendInsideCouponVerifyMsg(tenantId, couponOrderId, merchantBUser.getId()); | |||
| } else if (neuPayOrderType.equals(String.valueOf(EnumNeuPosPamentType.MEM_CARD.getCode()))) { | |||
| // 预付卡, 不能退 | |||
| WxPayOrder payOrder = payOrderFromCard(merchantBUser, order, memId, neuPayOrderId, neuPaymentAmount, neuPosPayOrderTime, neuPayThirdNo); | |||
| } else if (neuPayOrderType.equals(EnumNeuPosPamentType.MEM_CARD.getCode())) { | |||
| // 预付卡 | |||
| WxPayOrder payOrder = payOrderFromCard( | |||
| scoreCreditCalc, | |||
| merchant, merchantBUser, order, memId, | |||
| neuPayOrderId, neuPaymentAmount, neuPosPayOrderTime, neuPayThirdNo); | |||
| } else { | |||
| logger.error("Not Support:\n" + JSON.toJSONString(payOrderObj)); | |||
| payOrderFromPos(scoreCreditCalc, | |||
| merchant, merchantBUser, order, memId, | |||
| neuPayOrderType, neuPayOrderId, neuPaymentAmount, neuPosPayOrderTime, neuPayThirdNo); | |||
| } | |||
| } | |||
| } else if (posStatusStr.equalsIgnoreCase(WxPayConstant.NEU_ORDER_REFUND)) { | |||
| // TODO | |||
| // 退款同步 | |||
| // add to wx_order | |||
| String refundDetail = params.get(WxPayConstant.NEU_REFUND_DETAIL); | |||
| JSONObject refundDetailObj = JSON.parseObject(refundDetail); | |||
| @@ -1855,9 +1928,8 @@ public class PosServiceImpl implements PosService { | |||
| */ | |||
| public WxPayOrder payOrderFromMemDiscount( | |||
| WxMerchantBUser merchantBUser, | |||
| WxOrder order, | |||
| Long memId, | |||
| Long posPayOrderId, String neuPaymentAmount, Date neuPosPayOrderTime) { | |||
| WxOrder order, Long memId, | |||
| Long posPayOrderId, Integer neuPaymentAmount, Date neuPosPayOrderTime) { | |||
| WxPayOrder payOrder = new WxPayOrder() {{ | |||
| Date curDate = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| @@ -1871,7 +1943,7 @@ public class PosServiceImpl implements PosService { | |||
| setPayTimeStart(curDate); | |||
| setPayTimeEnd(curDate); | |||
| setPayOrderNo(String.valueOf(id)); | |||
| setPayAmount(Integer.valueOf(neuPaymentAmount)); | |||
| setPayAmount(neuPaymentAmount); | |||
| setPayVendor(EnumPayWay.PAY_WAY_POS_NEU.getCode()); | |||
| setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| setShare(EnumPayShare.NO.getCode()); | |||
| @@ -1898,11 +1970,10 @@ public class PosServiceImpl implements PosService { | |||
| * @param neuPosPayOrderTime | |||
| */ | |||
| public WxPayOrder payOrderFromCouponVerify( | |||
| WxMerchantBUser merchantBUser, | |||
| WxOrder order, | |||
| Long memId, | |||
| Integer sceneType, | |||
| Long posPayOrderId, String neuPaymentAmount, Date neuPosPayOrderTime, String posPayOrderNo) { | |||
| PromotionCalc scoreCreditCalc, | |||
| WxMerchantBUser merchantBUser, WxOrder order, | |||
| Long memId, Integer sceneType, | |||
| Long posPayOrderId, Integer neuPaymentAmount, Date neuPosPayOrderTime, String posPayOrderNo) { | |||
| // 1. insert into PayOrder | |||
| WxPayOrder payOrder = new WxPayOrder() {{ | |||
| Date curDate = new Date(); | |||
| @@ -1918,7 +1989,7 @@ public class PosServiceImpl implements PosService { | |||
| setPayTimeStart(curDate); | |||
| setPayTimeEnd(curDate); | |||
| setPayOrderNo(String.valueOf(id)); | |||
| setPayAmount(Integer.valueOf(neuPaymentAmount)); | |||
| setPayAmount(neuPaymentAmount); | |||
| setPayVendor(EnumPayWay.PAY_WAY_POS_NEU.getCode()); | |||
| setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| setShare(EnumPayShare.NO.getCode()); | |||
| @@ -1948,6 +2019,7 @@ public class PosServiceImpl implements PosService { | |||
| try { | |||
| WxOrder scoreOrder = orderMapper.selectByPrimaryKey(couponOrderCVo.getOrderId()); | |||
| int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, scoreOrder, couponOrderCVo.getBusinessId()); | |||
| scoreCreditCalc.setScore(scoreCreditCalc.getScore() + point); | |||
| } catch (Exception e) { | |||
| logger.error("交易核销成长值异常:" + e.getMessage()); | |||
| } | |||
| @@ -1961,18 +2033,20 @@ public class PosServiceImpl implements PosService { | |||
| // 4. 积分 | |||
| try { | |||
| int credit = posAddCredit(couponOrderCVo, wxCoupon, merchantBUser.getMerchantId(), merchantBUser.getId()); | |||
| scoreCreditCalc.setCredit(scoreCreditCalc.getCredit() + credit); | |||
| } catch (Exception e) { | |||
| logger.error("交易核销积分异常:" + e.getMessage()); | |||
| } | |||
| // 3. 核销后处理 | |||
| couponOrderService.sendInsideCouponVerifyMsg(merchantBUser.getTenantId(), couponOrderId, merchantBUser.getId()); | |||
| } | |||
| // 3. 核销后处理 | |||
| couponOrderService.sendInsideCouponVerifyMsg(merchantBUser.getTenantId(), couponOrderId, merchantBUser.getId()); | |||
| return payOrder; | |||
| } | |||
| /** | |||
| * 支付订单-预付卡 | |||
| * @param merchantBUser | |||
| * @param merchant | |||
| * @param buUser | |||
| * @param order | |||
| * @param memId | |||
| * @param posPayOrderId | |||
| @@ -1981,17 +2055,17 @@ public class PosServiceImpl implements PosService { | |||
| * @param posPayOrderNo | |||
| */ | |||
| public WxPayOrder payOrderFromCard( | |||
| WxMerchantBUser merchantBUser, | |||
| WxOrder order, | |||
| Long memId, | |||
| Long posPayOrderId, String neuPaymentAmount, Date neuPosPayOrderTime, String posPayOrderNo) { | |||
| PromotionCalc scoreCreditCalc, | |||
| WxMerchant merchant, WxMerchantBUser buUser, | |||
| WxOrder order, Long memId, | |||
| Long posPayOrderId, Integer neuPaymentAmount, Date neuPosPayOrderTime, String posPayOrderNo) { | |||
| // 1. insert into PayOrder | |||
| WxPayOrder payOrder = new WxPayOrder() {{ | |||
| Date curDate = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| Long id = idWorker.nextId(); | |||
| setId(id); | |||
| setTenantId(merchantBUser.getTenantId()); | |||
| setTenantId(buUser.getTenantId()); | |||
| setCUserId(memId); | |||
| setOrderId(order.getId()); | |||
| setCreateTime(curDate); | |||
| @@ -1999,13 +2073,13 @@ public class PosServiceImpl implements PosService { | |||
| setPayTimeStart(curDate); | |||
| setPayTimeEnd(curDate); | |||
| setPayOrderNo(String.valueOf(id)); | |||
| setPayAmount(Integer.valueOf(neuPaymentAmount)); | |||
| setPayAmount(neuPaymentAmount); | |||
| setPayVendor(EnumPayWay.PAY_WAY_POS_NEU.getCode()); | |||
| setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| setShare(EnumPayShare.NO.getCode()); | |||
| setPosPayOrderId(posPayOrderId); | |||
| setPosPayOrderTime(neuPosPayOrderTime.getTime()); | |||
| setPosPaymentType(EnumNeuPosPamentType.MEM_DISCOUNT.getCode()); | |||
| setPosPaymentType(EnumNeuPosPamentType.MEM_CARD.getCode()); | |||
| setPosPayDes("POS富茂卡支付"); | |||
| setPosPayOrderNo(posPayOrderNo); | |||
| @@ -2015,8 +2089,87 @@ public class PosServiceImpl implements PosService { | |||
| logger.error("pay order insert error: " + payOrder.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| // 2. 卡支付 card spend | |||
| // 3。卡支付 后续 | |||
| // 2. 卡支付 | |||
| Long cardSpendId; | |||
| try { | |||
| cardSpendId = Long.valueOf(posPayOrderNo); | |||
| } catch (NumberFormatException e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR); | |||
| } | |||
| WxCardSpend cardSpend = cardSpendService.getById(cardSpendId); | |||
| cardSpendService.cardSpendForPosPay(scoreCreditCalc, cardSpend, merchant, buUser); | |||
| return payOrder; | |||
| } | |||
| /** | |||
| * 支付订单POS | |||
| * @param merchant | |||
| * @param buUser | |||
| * @param order | |||
| * @param memId | |||
| * @param neuPayOrderType | |||
| * @param neuPayOrderId | |||
| * @param neuPaymentAmount | |||
| * @param neuPosPayOrderTime | |||
| * @param neuPayThirdNo | |||
| * @return | |||
| */ | |||
| public WxPayOrder payOrderFromPos( | |||
| PromotionCalc scoreCreditCalc, | |||
| WxMerchant merchant, WxMerchantBUser buUser, WxOrder order, Long memId, | |||
| Integer neuPayOrderType, Long neuPayOrderId, Integer neuPaymentAmount, Date neuPosPayOrderTime, String neuPayThirdNo) | |||
| { | |||
| // 1. insert into PayOrder | |||
| WxPayOrder payOrder = new WxPayOrder() {{ | |||
| Date curDate = new Date(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| Long id = idWorker.nextId(); | |||
| setId(id); | |||
| setTenantId(buUser.getTenantId()); | |||
| setCUserId(memId); | |||
| setOrderId(order.getId()); | |||
| setCreateTime(curDate); | |||
| setUpdateTime(curDate); | |||
| setPayTimeStart(curDate); | |||
| setPayTimeEnd(curDate); | |||
| setPayOrderNo(String.valueOf(id)); | |||
| setPayAmount(neuPaymentAmount); | |||
| setPayVendor(EnumPayWay.PAY_WAY_POS_NEU.getCode()); | |||
| setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| setShare(EnumPayShare.NO.getCode()); | |||
| setPosPayOrderId(neuPayOrderId); | |||
| setPosPayOrderTime(neuPosPayOrderTime.getTime()); | |||
| setPosPaymentType(neuPayOrderType); | |||
| setPosPayDes("POS支付"); | |||
| setPosPayOrderNo(neuPayThirdNo); | |||
| }}; | |||
| int sqlRow = payOrderMapper.insertSelective(payOrder); | |||
| if (sqlRow != 1) { | |||
| logger.error("pay order insert error: " + payOrder.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| // 2. 积分, 成长值 | |||
| // 3. 成长值 | |||
| try { | |||
| WxOrder scoreOrder = orderMapper.selectByPrimaryKey(order.getId()); | |||
| scoreOrder.setPayment(neuPaymentAmount); | |||
| int point = scoreRulesService.addScore2(EnumScoreType.CONSUMPTION, scoreOrder, merchant.getBusinessId()); | |||
| scoreCreditCalc.setScore(scoreCreditCalc.getScore() + point); | |||
| } catch (Exception e) { | |||
| logger.error("交易核销成长值异常:" + e.getMessage()); | |||
| } | |||
| // 4. 积分 | |||
| try { | |||
| int credit = posAddCreditForPay(merchant, buUser.getId(), memId, neuPaymentAmount); | |||
| scoreCreditCalc.setCredit(scoreCreditCalc.getCredit() + credit); | |||
| } catch (Exception e) { | |||
| logger.error("交易核销积分异常:" + e.getMessage()); | |||
| } | |||
| return payOrder; | |||
| } | |||
| @@ -412,6 +412,57 @@ public class PosAppTest { | |||
| Assert.assertEquals(resSigned, true); | |||
| } | |||
| @Test | |||
| public void cardPaySyncTest() throws Exception { | |||
| String memId = "321178010928119808"; | |||
| String memPhone = "13910154397"; | |||
| String sceneType = "1"; // 支付 | |||
| String posOrderId = "2"; | |||
| String orderAmount = "1000"; | |||
| String posPayOrderId = "2"; | |||
| String posPaymentType = "4"; | |||
| String posPaymentTypeDes = "优惠券"; | |||
| String posPaymentStatus = "0"; | |||
| String couponOrderId = "321878223800205312"; | |||
| Date curDate = new Date(); | |||
| Map<String, String> 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<String, String> 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<String, String> reqObj) throws Exception { | |||
| reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); | |||
| String reqJsonStr = JSONObject.toJSONString(reqObj); | |||
| @@ -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命令错误"), | |||
| @@ -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") | |||
| @@ -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; | |||
| } | |||
| @@ -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; | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -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()); | |||
| @@ -326,7 +326,7 @@ public class WxCreditHistoryServiceImpl implements WxCreditHistoryService { | |||
| Map<String, Integer> 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 ; | |||
| @@ -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); | |||