| @@ -118,4 +118,6 @@ public interface WxRefundOrderService { | |||||
| ResultData refundCardOrderSuccess(WxRefundOrder refundOrder,WxOrder wxOrder); | ResultData refundCardOrderSuccess(WxRefundOrder refundOrder,WxOrder wxOrder); | ||||
| ResultData refundCardOrderFail(WxRefundOrder refundOrder,WxOrder wxOrder); | |||||
| } | } | ||||
| @@ -245,8 +245,6 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| logger.info("补贴额: " + subsidyFee); | logger.info("补贴额: " + subsidyFee); | ||||
| if (cardInfo.getSaleAmount().equals(0) || subsidyFee > 0) { | if (cardInfo.getSaleAmount().equals(0) || subsidyFee > 0) { | ||||
| // 有补贴时入库, 免费卡消费时, 或者有补贴金额时 | // 有补贴时入库, 免费卡消费时, 或者有补贴金额时 | ||||
| int iSubChargeFee = PayUtils.getPayRate(subsidyFee, payAccount.getRealRate(), false); | |||||
| Integer realSubsidyFee = subsidyFee - iSubChargeFee; | |||||
| WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | ||||
| merchantSubsidy.setId(idWorker.nextId()); | merchantSubsidy.setId(idWorker.nextId()); | ||||
| merchantSubsidy.updateTenantInfo(record); | merchantSubsidy.updateTenantInfo(record); | ||||
| @@ -260,7 +258,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| merchantSubsidy.setReceiverPayment(payment); | merchantSubsidy.setReceiverPayment(payment); | ||||
| merchantSubsidy.setRealPayment(real_payment); | merchantSubsidy.setRealPayment(real_payment); | ||||
| merchantSubsidy.setSubsidy(subsidyFee); | merchantSubsidy.setSubsidy(subsidyFee); | ||||
| merchantSubsidy.setRealSubsidy(realSubsidyFee); | |||||
| merchantSubsidy.setRealSubsidy(subsidyFee); | |||||
| if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { | if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { | ||||
| // 立减领券 | // 立减领券 | ||||
| merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode()); | merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode()); | ||||
| @@ -302,7 +300,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| if (cardInfo.getSaleAmount() > 0) { | if (cardInfo.getSaleAmount() > 0) { | ||||
| if (payment > 0) { | if (payment > 0) { | ||||
| try { | try { | ||||
| creteMerchantSubsidy(record, curDate, idWorker, coupon, payment); | |||||
| creteMerchantSubsidy(record, curDate, idWorker, coupon); | |||||
| } catch (Exception ex) { | } catch (Exception ex) { | ||||
| logger.error("记录到结算表失败"); | logger.error("记录到结算表失败"); | ||||
| } | } | ||||
| @@ -384,11 +382,17 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| Map<String,String> map = new HashMap<>(); | Map<String,String> map = new HashMap<>(); | ||||
| map.put("thing7",coupon.getTitle()); | map.put("thing7",coupon.getTitle()); | ||||
| map.put("amount1",cardSpend.getDeductionAmountStr()); | |||||
| map.put("amount2",cardSpend.getCardRemainAmountStr()); | |||||
| map.put("amount1",cardSpend.getDeductionAmountStr()+"元"); | |||||
| map.put("amount2",cardSpend.getCardRemainAmountStr()+"元"); | |||||
| map.put("date4",dateFormat.format(cardSpend.getCreateDate())); | map.put("date4",dateFormat.format(cardSpend.getCreateDate())); | ||||
| WxMerchant merchant = wxMerchantMapper.selectById(cardSpend.getMerchantId()); | |||||
| map.put("thing6","消费支出"); | |||||
| if(EnumPayType.PAY_PAYMENT.getCode().equals(cardSpend.getPayType())){ | |||||
| map.put("thing6","消费支出"); | |||||
| }else if(EnumPayType.PAY_B_REFUND.getCode().equals(cardSpend.getPayType())){ | |||||
| map.put("thing6","消费退款"); | |||||
| }else{ | |||||
| map.put("thing6","余额变动"); | |||||
| } | |||||
| map.put("goToPage","pages/index/index?type=ca"); | map.put("goToPage","pages/index/index?type=ca"); | ||||
| msg.setMsg(JSONObject.toJSONString(map)); | msg.setMsg(JSONObject.toJSONString(map)); | ||||
| @@ -399,7 +403,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| } | } | ||||
| } | } | ||||
| public void creteMerchantSubsidy(WxCardSpend record, Date curDate, IdWorker idWorker, WxCoupon coupon, Integer payment) { | |||||
| public void creteMerchantSubsidy(WxCardSpend record, Date curDate, IdWorker idWorker, WxCoupon coupon) { | |||||
| WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | ||||
| merchantSubsidy.setId(idWorker.nextId()); | merchantSubsidy.setId(idWorker.nextId()); | ||||
| merchantSubsidy.updateTenantInfo(record); | merchantSubsidy.updateTenantInfo(record); | ||||
| @@ -412,8 +416,8 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| merchantSubsidy.setOrderPayment(record.getPayment()); | merchantSubsidy.setOrderPayment(record.getPayment()); | ||||
| merchantSubsidy.setReceiverPayment(record.getPayment()); | merchantSubsidy.setReceiverPayment(record.getPayment()); | ||||
| merchantSubsidy.setRealPayment(record.getRealPayment()); | merchantSubsidy.setRealPayment(record.getRealPayment()); | ||||
| merchantSubsidy.setSubsidy(payment); | |||||
| merchantSubsidy.setRealSubsidy(payment); | |||||
| merchantSubsidy.setSubsidy(record.getPayment()); | |||||
| merchantSubsidy.setRealSubsidy(record.getRealPayment()); | |||||
| merchantSubsidy.setCreateDate(curDate); | merchantSubsidy.setCreateDate(curDate); | ||||
| merchantSubsidy.setUpdateDate(curDate); | merchantSubsidy.setUpdateDate(curDate); | ||||
| merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode()); | merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode()); | ||||
| @@ -1232,8 +1236,6 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| logger.info("补贴额: " + subsidyFee); | logger.info("补贴额: " + subsidyFee); | ||||
| if (subsidyFee > 0) { | if (subsidyFee > 0) { | ||||
| // 有补贴时入库 | // 有补贴时入库 | ||||
| int iSubChargeFee = PayUtils.getPayRate(subsidyFee, payAccount.getRealRate(), false); | |||||
| Integer realSubsidyFee = subsidyFee - iSubChargeFee; | |||||
| WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | ||||
| merchantSubsidy.setId(idWorker.nextId()); | merchantSubsidy.setId(idWorker.nextId()); | ||||
| merchantSubsidy.updateTenantInfo(record); | merchantSubsidy.updateTenantInfo(record); | ||||
| @@ -1247,7 +1249,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService { | |||||
| merchantSubsidy.setReceiverPayment(record.getPayment()); | merchantSubsidy.setReceiverPayment(record.getPayment()); | ||||
| merchantSubsidy.setRealPayment(record.getRealPayment()); | merchantSubsidy.setRealPayment(record.getRealPayment()); | ||||
| merchantSubsidy.setSubsidy(subsidyFee); | merchantSubsidy.setSubsidy(subsidyFee); | ||||
| merchantSubsidy.setRealSubsidy(realSubsidyFee); | |||||
| merchantSubsidy.setRealSubsidy(subsidyFee); | |||||
| if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { | if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) { | ||||
| // 立减领券 | // 立减领券 | ||||
| merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode()); | merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode()); | ||||
| @@ -1996,9 +1996,6 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| return; | return; | ||||
| } | } | ||||
| subsidyNum = subsidyNum * couponOrder.getCouponNumber(); | subsidyNum = subsidyNum * couponOrder.getCouponNumber(); | ||||
| // 新补贴入库 | |||||
| int iSubChargeFee = OrderHelper.getRealRateAmount(subsidyNum, payAccount); | |||||
| Integer realSubsidyFee = subsidyNum - iSubChargeFee; | |||||
| WxOrder order = wxOrderMapper.selectById(couponOrder.getOrderId(), couponOrder.getTenantId()); | WxOrder order = wxOrderMapper.selectById(couponOrder.getOrderId(), couponOrder.getTenantId()); | ||||
| int iPriceChargeFee = OrderHelper.getRealRateAmount(order.getPayment(), payAccount); | int iPriceChargeFee = OrderHelper.getRealRateAmount(order.getPayment(), payAccount); | ||||
| @@ -2017,7 +2014,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| merchantSubsidy.setReceiverPayment(coupon.getSalePrice()); | merchantSubsidy.setReceiverPayment(coupon.getSalePrice()); | ||||
| merchantSubsidy.setRealPayment(realPayment); | merchantSubsidy.setRealPayment(realPayment); | ||||
| merchantSubsidy.setSubsidy(subsidyNum); | merchantSubsidy.setSubsidy(subsidyNum); | ||||
| merchantSubsidy.setRealSubsidy(realSubsidyFee); | |||||
| merchantSubsidy.setRealSubsidy(subsidyNum); | |||||
| merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); | merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); | ||||
| merchantSubsidy.setCreateDate(new Date()); | merchantSubsidy.setCreateDate(new Date()); | ||||
| merchantSubsidy.setUpdateDate(new Date()); | merchantSubsidy.setUpdateDate(new Date()); | ||||
| @@ -1137,7 +1137,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| WxRefundOrder record = new WxRefundOrder(); | WxRefundOrder record = new WxRefundOrder(); | ||||
| record.updateTenantInfo(wxOrder); | record.updateTenantInfo(wxOrder); | ||||
| record.setPayOrderNo(String.valueOf(cardSend.getId()));//卡没有支付订单 | |||||
| record.setPayOrderNo(String.valueOf(cardSend.getId())); | |||||
| record.setOrderId(wxOrder.getId()); | record.setOrderId(wxOrder.getId()); | ||||
| record.setNotStatus(EnumRefundStatus.REFUND_FAIL.getCode()); | record.setNotStatus(EnumRefundStatus.REFUND_FAIL.getCode()); | ||||
| @@ -1210,15 +1210,6 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); | throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); | ||||
| } | } | ||||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfoFromRedis(cardInfo.getTenantId(), EnumAppPlat.WX); | |||||
| if(cAppInfo == null){ | |||||
| throw new MallinkException(ErrorCode.APP_ID_NOT_FOUND); | |||||
| } | |||||
| WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId()); | |||||
| if(payAccount == null){ | |||||
| throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND); | |||||
| } | |||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| WxCardSpend record = new WxCardSpend(); | WxCardSpend record = new WxCardSpend(); | ||||
| @@ -1330,35 +1321,61 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| subsidyFee = subsidyD.intValue(); | subsidyFee = subsidyD.intValue(); | ||||
| WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | ||||
| merchantSubsidy.setId(idWorker.nextId()); | |||||
| merchantSubsidy.updateTenantInfo(record); | merchantSubsidy.updateTenantInfo(record); | ||||
| merchantSubsidy.setOrderId(wxOrder.getId()); | merchantSubsidy.setOrderId(wxOrder.getId()); | ||||
| merchantSubsidy.setOrderType(EnumOrderType.PREPAIDCARD.getCode()); | merchantSubsidy.setOrderType(EnumOrderType.PREPAIDCARD.getCode()); | ||||
| WxMerchantSubsidy wxMerchantSubsidy = wxMerchantSubsidyMapper.selectOne(new QueryWrapper<>(merchantSubsidy)); | |||||
| if(wxMerchantSubsidy == null){ | |||||
| logger.error("未找到补贴数据 error"); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "未找到补贴数据 插入出错!"); | |||||
| merchantSubsidy.setMerchantId(record.getMerchantId()); | |||||
| merchantSubsidy.setBTenantId(record.getTenantId()); | |||||
| merchantSubsidy.setCouponOrderId(cardInfo.getId()); | |||||
| merchantSubsidy.setCouponType(EnumCouponType.CARD_MULTIMCH.getCode()); | |||||
| merchantSubsidy.setOrderPayment(0-record.getDeductionAmount()); | |||||
| merchantSubsidy.setReceiverPayment(0-refund); | |||||
| merchantSubsidy.setRealPayment(0-real_refund); | |||||
| merchantSubsidy.setSubsidy(0-subsidyFee); | |||||
| merchantSubsidy.setRealSubsidy(0-subsidyFee); | |||||
| merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); | |||||
| merchantSubsidy.setType(EnumMerchantSubsidyType.MANUAL.getCode()); | |||||
| merchantSubsidy.setSource(EnumMerchantSubsidySource.CARD.getCode()); | |||||
| //如果是有价卡,并且有补贴,则该记录不能显示在卡消费列表里面 | |||||
| if (cardInfo.getSaleAmount()>0 && subsidyFee > 0) { | |||||
| merchantSubsidy.setCardSpendListShow(0); | |||||
| } | } | ||||
| Double realSubsidyD = 1.0 * cardSend.getRealPayment() * refundFee / cardSend.getDeductionAmount(); | |||||
| Integer realSubsidyFee = realSubsidyD.intValue(); | |||||
| if(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode().equals(wxMerchantSubsidy.getStatus())){ | |||||
| wxMerchantSubsidy.setOrderPayment(wxMerchantSubsidy.getOrderPayment()-record.getDeductionAmount()); | |||||
| wxMerchantSubsidy.setReceiverPayment(wxMerchantSubsidy.getReceiverPayment()-refund); | |||||
| wxMerchantSubsidy.setRealPayment(wxMerchantSubsidy.getRealPayment()-real_refund); | |||||
| wxMerchantSubsidy.setSubsidy(wxMerchantSubsidy.getSubsidy()-subsidyFee); | |||||
| wxMerchantSubsidy.setRealSubsidy(wxMerchantSubsidy.getRealSubsidy()-realSubsidyFee); | |||||
| wxMerchantSubsidy.setUpdateDate(currentDate); | |||||
| try { | |||||
| wxMerchantSubsidyMapper.updateById(wxMerchantSubsidy); | |||||
| } catch (Exception e) { | |||||
| logger.error("退补贴数据 修改失败info update error"); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "merchantSubsidy info 修改出错!"); | |||||
| } | |||||
| }else{ | |||||
| logger.error("补贴数据已结算 无法退款 error"); | |||||
| throw new MallinkException(ErrorCode.SYS_METHOD_NOT_SUPPORT.getCode(), "补贴数据已结算"); | |||||
| merchantSubsidy.setCreateDate(currentDate); | |||||
| merchantSubsidy.setUpdateDate(currentDate); | |||||
| try { | |||||
| wxMerchantSubsidyMapper.insert(merchantSubsidy); | |||||
| } catch (Exception e) { | |||||
| logger.error("merchantSubsidy info insert error"); | |||||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "merchantSubsidy info 插入出错!"); | |||||
| } | } | ||||
| } | |||||
| if(refund > 0){ | |||||
| WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy(); | |||||
| merchantSubsidy.setId(idWorker.nextId()); | |||||
| merchantSubsidy.updateTenantInfo(record); | |||||
| merchantSubsidy.setOrderId(record.getOrderId()); | |||||
| merchantSubsidy.setOrderType(EnumOrderType.PREPAIDCARD.getCode()); | |||||
| merchantSubsidy.setMerchantId(record.getMerchantId()); | |||||
| merchantSubsidy.setBTenantId(record.getTenantId()); | |||||
| merchantSubsidy.setCouponOrderId(record.getCardId()); | |||||
| merchantSubsidy.setCouponType(EnumCouponType.CARD_MULTIMCH.getCode()); | |||||
| merchantSubsidy.setOrderPayment(0-record.getPayment()); | |||||
| merchantSubsidy.setReceiverPayment(0-record.getPayment()); | |||||
| merchantSubsidy.setRealPayment(0-record.getRealPayment()); | |||||
| merchantSubsidy.setSubsidy(0-record.getPayment()); | |||||
| merchantSubsidy.setRealSubsidy(0-record.getRealPayment()); | |||||
| merchantSubsidy.setCreateDate(currentDate); | |||||
| merchantSubsidy.setUpdateDate(currentDate); | |||||
| merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode()); | |||||
| merchantSubsidy.setSource(EnumMerchantSubsidySource.CARD.getCode()); | |||||
| merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode()); | |||||
| wxMerchantSubsidyMapper.insert(merchantSubsidy); | |||||
| } | } | ||||
| try { | try { | ||||
| @@ -1373,5 +1390,65 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @Override | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public ResultData refundCardOrderFail(WxRefundOrder refundOrder, WxOrder wxOrder) { | |||||
| Long cardSpendId = Long.parseLong(refundOrder.getPayOrderNo()); | |||||
| WxCardSpend cardSend = wxCardSpendMapper.selectById(cardSpendId); | |||||
| if(cardSend == null){ | |||||
| logger.error("付款订单未找到, e:"); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | |||||
| } | |||||
| WxCardInfo cardInfo = wxCardInfoMapper.selectById(cardSend.getCardId()); | |||||
| if (cardInfo == null) { | |||||
| logger.error("card not found: " + cardSend.getCardId()); | |||||
| throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND); | |||||
| } | |||||
| Date currentDate = new Date(); | |||||
| WxRefundOrder updateOrder = new WxRefundOrder(); | |||||
| updateOrder.setId(refundOrder.getId()); | |||||
| updateOrder.setOrderId(refundOrder.getOrderId()); | |||||
| updateOrder.setUpdateTime(currentDate); | |||||
| updateOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_FAIL.getCode()); | |||||
| // updateOrder.setTransactionId(transactionId); | |||||
| // updateOrder.setRefundId(record.getId().toString()); | |||||
| // 修改退款订单状态 | |||||
| try { | |||||
| int i = wxRefundOrderMapper.updateById(updateOrder); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||||
| } | |||||
| WxOrder refOrder = new WxOrder(); | |||||
| refOrder.setId(updateOrder.getId()); | |||||
| refOrder.updateTenantInfo(wxOrder); | |||||
| refOrder.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||||
| refOrder.setUpdateDate(currentDate); | |||||
| try { | |||||
| int i = wxOrderMapper.updateById(refOrder); | |||||
| } catch (Exception e) { | |||||
| logger.error("订单状态更新失败, e:" + e.getMessage(),e); | |||||
| throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||||
| } | |||||
| WxCardSpend cardSpendUpd = new WxCardSpend(); | |||||
| cardSpendUpd.setId(cardSend.getId()); | |||||
| cardSpendUpd.updateTenantInfo(cardSend); | |||||
| cardSpendUpd.setPayStatus(EnumCardSpendStatus.NOT_PAY.getCode()); | |||||
| cardSpendUpd.setUpdateDate(currentDate); | |||||
| try { | |||||
| wxCardSpendMapper.updateById(cardSpendUpd); | |||||
| } catch (Exception e) { | |||||
| logger.error("卡退款订单修改出错: " + cardSpendUpd.toString()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| return new ResultData(); | |||||
| } | |||||
| } | } | ||||