Browse Source

[结算对账][修改][添加信息、查询、导出]

release_toaliyun_real
gongbiao 6 years ago
parent
commit
c67593b113
8 changed files with 262 additions and 118 deletions
  1. +11
    -10
      mallinkService/src/main/java/com/iformall/domain/po/WxMerchantSubsidy.java
  2. +0
    -1
      mallinkService/src/main/java/com/iformall/domain/vo/WxMerchantSubsidyVo.java
  3. +78
    -40
      mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java
  4. +73
    -24
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java
  5. +1
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxMerchantSubsidyServiceImpl.java
  6. +55
    -19
      mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java
  7. +43
    -22
      mallinkService/src/main/resources/mapper/WxMerchantSubsidyMapper.xml
  8. +1
    -1
      mallinkService/src/main/resources/mapper/WxOrderMapper.xml

+ 11
- 10
mallinkService/src/main/java/com/iformall/domain/po/WxMerchantSubsidy.java View File

@@ -54,17 +54,15 @@ public class WxMerchantSubsidy extends BaseEntity {
private Integer receiverPayment;

@TableField(exist = false)
@Excel(name="本次消费(元)",width = 20,orderNum = "5")
@io.swagger.annotations.ApiModelProperty(value="订单金额",name="orderPaymentStr")
private String orderPaymentStr;

@TableField(exist = false)
@Excel(name="商户应收(元)",width = 20,orderNum = "6")
@io.swagger.annotations.ApiModelProperty(value="接收金额(包含通道费)",name="receiverPaymentStr")
private String receiverPaymentStr;

@TableField(exist = false)
@Excel(name="补贴(元)",width = 20,orderNum = "7")
@Excel(name = "承付金额(元)", width = 20, orderNum = "6")
@io.swagger.annotations.ApiModelProperty(value="补贴额(包含通道费)",name="subsidyStr")
private String subsidyStr;

@@ -76,11 +74,11 @@ public class WxMerchantSubsidy extends BaseEntity {
@io.swagger.annotations.ApiModelProperty(value="线上补贴额/实收补贴额(通道费扣除)",name="realSubsidy")
private Integer realSubsidy;

@Excel(name="补贴状态",width = 20,orderNum = "8",replace = { "未补贴_0", "已自动补贴_1","已手工补贴_2"})
@Excel(name = "结算状态", width = 20, orderNum = "7", replace = {"未结算_0", "已结算_1", "已结算_2"})
@io.swagger.annotations.ApiModelProperty(value="状态(0:未补贴, 1:已补贴, 2:已手工补贴)",name="status")
private Integer status;

@Excel(name="交易时间",width = 20,orderNum = "4",format="yyyy-MM-dd HH:mm")
@Excel(name = "交易时间", width = 20, orderNum = "5", format = "yyyy-MM-dd HH:mm")
@io.swagger.annotations.ApiModelProperty(value="创建时间",name="createDate")
private Date createDate;

@@ -102,8 +100,9 @@ public class WxMerchantSubsidy extends BaseEntity {
@TableField(exist = false)
protected String statusStr;

@io.swagger.annotations.ApiModelProperty(value="是否冻结",name="freeze")
private Integer freeze;
@Excel(name = "冻结状态", width = 20, orderNum = "8", replace = {"冻结中_1", "正常_0"})
@io.swagger.annotations.ApiModelProperty(value = "是否冻结", name = "freeze")
private Integer freeze;

public String getOrderPaymentStr() {

@@ -127,9 +126,11 @@ public class WxMerchantSubsidy extends BaseEntity {
return subsidyStr;
}

@io.swagger.annotations.ApiModelProperty(value = "结算类型1微信结算2自主结算", name = "type")
@Excel(name = "结算类型", width = 20, orderNum = "4", replace = {"自主结算_1", "微信结算_2"})
@io.swagger.annotations.ApiModelProperty(value = "结算类型1自主结算2微信结算", name = "type")
private Integer type;

@io.swagger.annotations.ApiModelProperty(value = "结算来源0补贴1卡消费2券核销3砍价核销4拼团核销5收银分账", name = "source")
private Integer source;
@Excel(name = "结算来源", width = 20, orderNum = "3", replace = {"补贴_0", "卡消费_1", "券核销_2", "砍价核销_3", "拼团核销_4", , "收银分账_5"})
@io.swagger.annotations.ApiModelProperty(value = "结算来源0补贴1卡消费2券核销3砍价核销4拼团核销5收银分账", name = "source")
private Integer source;
}

+ 0
- 1
mallinkService/src/main/java/com/iformall/domain/vo/WxMerchantSubsidyVo.java View File

@@ -13,7 +13,6 @@ public class WxMerchantSubsidyVo extends WxMerchantSubsidy {
@io.swagger.annotations.ApiModelProperty(value="封面图",name="coverImg")
private String coverImg;

@Excel(name="活动名称",width = 20,orderNum = "3")
@io.swagger.annotations.ApiModelProperty(value="券名称",name="title")
private String title;
@io.swagger.annotations.ApiModelProperty(value="副标题",name="subTitle")


+ 78
- 40
mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java View File

@@ -34,34 +34,34 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

@Autowired
@Autowired
WxCardSpendMapper wxCardSpendMapper;

@Autowired
@Autowired
WxCardInfoMapper wxCardInfoMapper;

@Autowired
@Autowired
WxCouponMapper wxCouponMapper;

@Autowired
@Autowired
WxMerchantMapper wxMerchantMapper;

@Autowired
@Autowired
WxMerchantSubsidyMapper wxMerchantSubsidyMapper;

@Autowired
@Autowired
WxCouponMerchantMapper wxCouponMerchantMapper;

@Autowired
@Autowired
WxPayAccountMapper payAccountMapper;

@Autowired
@Autowired
WxOrderMapper wxOrderMapper;

@Autowired
@Autowired
WxCouponOrderMapper wxCouponOrderMapper;

@Autowired
@Autowired
WxProfitSharingOrderService profitSharingOrderService;

@Autowired
@@ -73,7 +73,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
@Autowired
WxScoreRulesService wxScoreRulesService;

@Override
@Override
public WxCouponMerchant checkMerchantInCoupon(WxCardInfo cardInfo, Long merchantId) {
WxCouponMerchant couponMerchant = null;
WxCouponMerchant couponMerchantQ = new WxCouponMerchant();
@@ -89,12 +89,12 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
return couponMerchant;
}

@Override
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant) {
Date curDate = new Date();
final IdWorker idWorker = IdWorker.get();
// 1. get card info
Date curDate = new Date();
final IdWorker idWorker = IdWorker.get();
// 1. get card info
WxCardInfo cardInfo = wxCardInfoMapper.selectById(record.getCardId());
if (cardInfo == null) {
logger.error("card not found: " + record.getCardId());
@@ -129,8 +129,8 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate(), false);
Integer real_payment = payment - iChargeFee;
Integer remain_real_pament = cardInfo.getRemainingShareFeeAmount() - real_payment;
Integer remaingAmount = cardInfo.getRemainingAmount()-record.getDeductionAmount();
if(remaingAmount.equals(0)) {
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;
@@ -193,7 +193,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
}

// 7.2 update coupon card status
if(cardInfo.getRemainingAmount().equals(0)) {
if (cardInfo.getRemainingAmount().equals(0)) {
if (cardFinished(curDate, cardInfo)) {
return new ResultData(ErrorCode.DB_FAIL.getCode(), "couponOrder status 更新出错!");
}
@@ -202,9 +202,9 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
// 8. 补贴
// 补贴额 = 商城补贴总额/卡券面额 * 抵扣额(本次支付额)
Double subsidyFeeD = 1.0 * record.getDeductionAmount() * coupon.getSubsidyNum() / cardInfo.getAmount();
Integer subsidyFee = subsidyFeeD.intValue();
Integer subsidyFee = subsidyFeeD.intValue();
logger.info("补贴额: " + subsidyFee);
if(subsidyFee > 0) {
if (cardInfo.getSaleAmount().equals(0) || subsidyFee > 0) {
// 有补贴时入库
int iSubChargeFee = PayUtils.getPayRate(subsidyFee, payAccount.getRate(), false);
Integer realSubsidyFee = subsidyFee - iSubChargeFee;
@@ -224,13 +224,16 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) {
// 立减领券
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode());
} else if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) {
} else if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) {
// 转账倒现金
} else {
// 未补贴
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode());
}

merchantSubsidy.setType(EnumMerchantSubsidyType.MANUAL.getCode());
merchantSubsidy.setSource(EnumMerchantSubsidySource.CARD.getCode());

merchantSubsidy.setCreateDate(curDate);
merchantSubsidy.setUpdateDate(curDate);
try {
@@ -250,10 +253,23 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
if (ErrorCode.PROFIT_SHARING_NUM_UP_LIMIT.getCode() == e.getErrorCode()) {
// 分账已到20次限制,后面只记录,无法分账
logger.error("分账已到20次限制,后面只记录,无法分账");
try {
creteMerchantSubsidy(record, curDate, idWorker, coupon, payment);
} catch (Exception ex) {
logger.error("分账已到20次限制,记录到结算表失败");
}
} else {
throw new MallinkException(e.getErrorCode(), e.getMessage());
}
}
} else {
if (cardInfo.getSaleAmount() > 0) {
try {
creteMerchantSubsidy(record, curDate, idWorker, coupon, payment);
} catch (Exception ex) {
logger.error("记录到结算表失败");
}
}
}

// 成长值
@@ -286,8 +302,30 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
return new ResultData(record);
}

public void creteMerchantSubsidy(WxCardSpend record, Date curDate, IdWorker idWorker, WxCoupon coupon, Integer payment) {
WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy();
merchantSubsidy.setId(idWorker.nextId());
merchantSubsidy.setTenantId(record.getTenantId());
merchantSubsidy.setOrderId(record.getOrderId());
merchantSubsidy.setOrderType(EnumOrderType.PREPAIDCARD.getCode());
merchantSubsidy.setMerchantId(record.getMerchantId());
merchantSubsidy.setCouponOrderId(record.getCardId());
merchantSubsidy.setCouponType(coupon.getType());
merchantSubsidy.setOrderPayment(record.getPayment());
merchantSubsidy.setReceiverPayment(record.getPayment());
merchantSubsidy.setRealPayment(record.getRealPayment());
merchantSubsidy.setSubsidy(payment);
merchantSubsidy.setRealSubsidy(payment);
merchantSubsidy.setCreateDate(curDate);
merchantSubsidy.setUpdateDate(curDate);
merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode());
merchantSubsidy.setSource(EnumMerchantSubsidySource.CARD.getCode());
wxMerchantSubsidyMapper.insert(merchantSubsidy);
}

/**
* 卡已用完
*
* @param curDate
* @param cardInfo
* @return
@@ -315,7 +353,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {

@Override
public List<Map<String, Object>> sumCardSpendForMerchant(WxCardSpendVo record) {
return wxCardSpendMapper.sumCardSpendVoForMerchant(record);
return wxCardSpendMapper.sumCardSpendVoForMerchant(record);
}

@Override
@@ -333,7 +371,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
if (record.getId() == null) {
//record.setId(UUID.randomUUID().toString().replaceAll("-", ""));
final IdWorker idWorker = IdWorker.get();
record.setId(idWorker.nextId());
record.setId(idWorker.nextId());
wxCardSpendMapper.insert(record);
} else {
wxCardSpendMapper.updateById(record);
@@ -344,7 +382,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
public void update(WxCardSpend record) {
// 1. 检查符合条件的卡消费记录是否已支付
List<WxCardSpend> cardSpends = wxCardSpendMapper.findList(record);
if (cardSpends.stream().anyMatch((cs->(!cs.getPayStatus().equals(EnumCardSpendStatus.NOT_PAY.getCode()))))){
if (cardSpends.stream().anyMatch((cs -> (!cs.getPayStatus().equals(EnumCardSpendStatus.NOT_PAY.getCode()))))) {
throw new MallinkException(ErrorCode.CARD_SPEND_IS_PAID);
}
// 2. 更新支付状态
@@ -363,11 +401,11 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
logger.error("微信分账: " + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), e.getMessage());
}
if(cardInfo != null) {
if (cardInfo.getRemainingAmount().equals(cardInfo.getAmount())){
if (cardInfo != null) {
if (cardInfo.getRemainingAmount().equals(cardInfo.getAmount())) {
logger.error("请用订单退款接口: ");
throw new MallinkException(ErrorCode.CARD_IS_NOT_COST);
} else if(cardInfo.getRemainingAmount() > 0){
} else if (cardInfo.getRemainingAmount() > 0) {
// 卡已消费, 余额不为0
int remainShareFeeAmount = cardInfo.getRemainingShareFeeAmount();
try {
@@ -409,7 +447,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public void shareForCardPay(String tenantId, Long cardId, Long orderId, Long cardSpendId) {
// 微信已分账检查次数
// 微信已分账检查次数
int psNum = 0;
try {
WxCardSpend cardSpendQ = new WxCardSpend();
@@ -457,7 +495,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
shareOrder.setTransactionId(cardInfo.getTransactionId());
shareOrder.setShareAmount(cardSpend.getRealPayment());
ResultData resultData = profitSharingOrderService.createSharingOrder(shareOrder);
if(resultData.code != Result.SUCCESS) {
if (resultData.code != Result.SUCCESS) {
// 分账异常
logger.error(resultData.message);
throw new MallinkException(resultData.code, resultData.message);
@@ -473,7 +511,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
}


if(cardSpend.getCardRemainAmount().equals(0)
if (cardSpend.getCardRemainAmount().equals(0)
|| psNum == 20) {
// 卡余额为0,或者卡已分账20次,发起分账完结
if (cardSpend.getCardRemainRealAmount() > 0) {
@@ -492,9 +530,9 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
}



/**
* 卡分账完结
*
* @param cardInfo
* @param shareOrder
*/
@@ -538,9 +576,9 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
shareOrder.setOrderId(cardSpend.getId());
shareOrder.setPayAmount(0);
shareOrder.setOrderId(cardSpend.getId());
if(cardInfo.getRateAmount() != null) {
if (cardInfo.getRateAmount() != null) {
// 分账实际金额 = 分账实际剩余金额 + 通道费差
shareOrder.setShareAmount(cardInfo.getRemainingShareFeeAmount()+cardInfo.getRateAmount());
shareOrder.setShareAmount(cardInfo.getRemainingShareFeeAmount() + cardInfo.getRateAmount());
} else {
shareOrder.setShareAmount(cardInfo.getRemainingShareFeeAmount());
}
@@ -610,7 +648,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate(), false);
Integer real_payment = payment - iChargeFee;
Integer remain_real_pament = cardInfo.getRemainingShareFeeAmount() - real_payment;
Integer remaingAmount = cardInfo.getRemainingAmount()-record.getDeductionAmount();
Integer remaingAmount = cardInfo.getRemainingAmount() - record.getDeductionAmount();
if (remaingAmount.equals(0)) {
// 最后一次支付时
real_payment = Math.min(real_payment, cardInfo.getRemainingShareFeeAmount());
@@ -691,7 +729,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
int iChargeFee = PayUtils.getPayRate(payment, payAccount.getRate(), false);
Integer real_payment = payment - iChargeFee;
Integer remain_real_pament = cardInfo.getRemainingShareFeeAmount() + real_payment;
Integer remaingAmount = cardInfo.getRemainingAmount()+record.getDeductionAmount();
Integer remaingAmount = cardInfo.getRemainingAmount() + record.getDeductionAmount();

// 5.、update card info
WxCardInfo updateCardInfo = new WxCardInfo();
@@ -750,7 +788,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
logger.error("card not found: " + record.getCardId());
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND);
}
if(cardInfo.getRemainingAmount().equals(0)) {
if (cardInfo.getRemainingAmount().equals(0)) {
if (cardFinished(curDate, cardInfo)) {
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "couponOrder status 更新出错!");
}
@@ -778,9 +816,9 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
// 3. 补贴
// 补贴额 = 商城补贴总额/卡券面额 * 抵扣额(本次支付额)
Double subsidyFeeD = 1.0 * record.getDeductionAmount() * coupon.getSubsidyNum() / cardInfo.getAmount();
Integer subsidyFee = subsidyFeeD.intValue();
Integer subsidyFee = subsidyFeeD.intValue();
logger.info("补贴额: " + subsidyFee);
if(subsidyFee > 0) {
if (subsidyFee > 0) {
// 有补贴时入库
int iSubChargeFee = PayUtils.getPayRate(subsidyFee, payAccount.getRate(), false);
Integer realSubsidyFee = subsidyFee - iSubChargeFee;
@@ -800,7 +838,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) {
// 立减领券
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode());
} else if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) {
} else if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_MCHPAY.getCode())) {
// 转账倒现金
} else {
// 未补贴
@@ -822,7 +860,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
shareForCardPay(record.getTenantId(), record.getCardId(), record.getOrderId(), record.getId());
} catch (MallinkException e) {
logger.error(e.getMessage());
if(ErrorCode.PROFIT_SHARING_NUM_UP_LIMIT.getCode() == e.getErrorCode()) {
if (ErrorCode.PROFIT_SHARING_NUM_UP_LIMIT.getCode() == e.getErrorCode()) {
// 分账已到20次限制,后面只记录,无法分账
logger.error("分账已到20次限制,后面只记录,无法分账");
} else {


+ 73
- 24
mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java View File

@@ -200,7 +200,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
else
list = wxCouponOrderMapper.findListOfOrderedByDate(dateMap);
//logger.info("find " + list.size() + " coupon order from " + /startDate + " to " + new Date());
resultMap.put("amount", list.stream().mapToInt(p->p.getCouponPrice()).sum());
resultMap.put("amount", list.stream().mapToInt(p -> p.getCouponPrice()).sum());
resultMap.put("orderCount", list.size());
} else {
if (isVerified)
@@ -214,7 +214,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
@Override
public PageInfo<WxCouponOrderCVo> listCUserVoAsPage(WxCouponOrder record, Integer pageIndex, Integer pageSize) {

return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderMapper.findListOfCUser(record));
return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderMapper.findListOfCUser(record));
}

@Override
@@ -263,7 +263,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {

@Override
public ResultData listAdminAsPage(WxCouponOrderBVo wxCouponOrderBVo, Integer pageIndex, Integer pageSize) {
PageInfo<WxCouponOrderBVo> pageInfo= PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderMapper.findListOfAdmin(wxCouponOrderBVo));
PageInfo<WxCouponOrderBVo> pageInfo = PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderMapper.findListOfAdmin(wxCouponOrderBVo));
return new ResultData(pageInfo);
}

@@ -319,8 +319,8 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
WxCouponMerchant wxCouponMerchant = new WxCouponMerchant();
wxCouponMerchant.setProductId(wxCoupon.getId());
wxCouponMerchant.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode());
List<WxCouponMerchant> couponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant);
if (!couponMerchantList.stream().anyMatch(cm->cm.getMerchantId().equals(bUser.getMerchantId()))){
List<WxCouponMerchant> couponMerchantList = wxCouponMerchantMapper.findList(wxCouponMerchant);
if (!couponMerchantList.stream().anyMatch(cm -> cm.getMerchantId().equals(bUser.getMerchantId()))) {
logger.error("券: coupon-" + wxCoupon.getId() + "核销: couponMerchantId-" + bUser.getMerchantId());
throw new MallinkException(ErrorCode.VERIFY_COUPON_ORDER_MERCHANT_IS_NULL);
}
@@ -353,7 +353,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
logger.error("db failed: couponOrder-" + couponOrder.getId() + ", e:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
}
if(num != 1) {
if (num != 1) {
logger.error("核销异常:updatete num " + num);
throw new MallinkException(ErrorCode.VERIFY_ERROR.getCode(), "updatete num " + num);
}
@@ -402,11 +402,25 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {

@Override
public void actionAfterVerify(WxCouponOrder couponOrder, WxMerchantBUser bUser) {
try {
// 核销分账
shareAfterVerify(couponOrder, bUser.getMerchantId());
} catch (Exception e) {
logger.error(e.getMessage());

WxPayAccount wxPayAccountQuery = new WxPayAccount();
wxPayAccountQuery.setTenantId(couponOrder.getTenantId());
WxPayAccount wxPayAccount = wxPayAccountMapper.selectOne(new QueryWrapper<>(wxPayAccountQuery));
if (wxPayAccount != null && wxPayAccount.getShare().equals(EnumPayShare.NO.getCode())) {
try {
// 核销记账
recordAfterVerified(couponOrder, bUser.getMerchantId());
} catch (Exception e) {
logger.info("核销记账失败");
logger.error(e.getMessage());
}
} else {
try {
// 核销分账
shareAfterVerify(couponOrder, bUser.getMerchantId());
} catch (Exception e) {
logger.error(e.getMessage());
}
}

try {
@@ -429,8 +443,43 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
try {
sendVerifyMsg(couponOrder, bUser, bSentCoupon);
} catch (Exception e) {
logger.error("核销发送消息发生错误:"+e.getMessage());
logger.error("核销发送消息发生错误:" + e.getMessage());
}
}

public void recordAfterVerified(WxCouponOrder couponOrder, Long merchantId) {
WxCoupon wxCoupon = wxCouponMapper.selectById(couponOrder.getCouponId());
WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy();
if (couponOrder.getCouponType().equals(EnumCouponType.COUPON_PRESS.getCode())
&& couponOrder.getCouponPrice().equals(wxCoupon.getSalePrice())) {
//砍价
merchantSubsidy.setSource(EnumMerchantSubsidySource.PRESS.getCode());
} else if (couponOrder.getCouponType().equals(EnumCouponType.COUPON_GROUP.getCode())
&& couponOrder.getCouponPrice().equals(wxCoupon.getSalePrice())) {
//拼团
merchantSubsidy.setSource(EnumMerchantSubsidySource.GROUP.getCode());
} else {
//券
merchantSubsidy.setSource(EnumMerchantSubsidySource.COUPON.getCode());
}
final IdWorker idWorker = IdWorker.get();
Date curDate = new Date();
merchantSubsidy.setId(idWorker.nextId());
merchantSubsidy.setTenantId(couponOrder.getTenantId());
merchantSubsidy.setOrderId(couponOrder.getOrderId());
merchantSubsidy.setOrderType(EnumOrderType.COUPON.getCode());
merchantSubsidy.setMerchantId(merchantId);
merchantSubsidy.setCouponOrderId(couponOrder.getId());
merchantSubsidy.setCouponType(couponOrder.getCouponType());
merchantSubsidy.setOrderPayment(couponOrder.getSalePrice());
merchantSubsidy.setReceiverPayment(couponOrder.getSalePrice());
merchantSubsidy.setRealPayment(couponOrder.getSalePrice());
merchantSubsidy.setSubsidy(couponOrder.getSalePrice());
merchantSubsidy.setRealSubsidy(couponOrder.getSalePrice());
merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode());
merchantSubsidy.setCreateDate(curDate);
merchantSubsidy.setUpdateDate(curDate);
wxMerchantSubsidyMapper.insert(merchantSubsidy);
}

@Override
@@ -477,8 +526,8 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
WxCouponMerchant couponMerchant;
try {
couponMerchant = wxCouponMerchantMapper.selectOne(new QueryWrapper(couponMerchantQ));
}catch (Exception e) {
logger.error("查找所属卡券商户错误: " + "CouponId:" + couponMerchantQ.getProductId(), " merchantId:" + merchantId );
} catch (Exception e) {
logger.error("查找所属卡券商户错误: " + "CouponId:" + couponMerchantQ.getProductId(), " merchantId:" + merchantId);
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR);
}

@@ -491,7 +540,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
WxCoupon coupon;
try {
coupon = wxCouponMapper.selectById(couponOrder.getCouponId());
}catch (Exception e) {
} catch (Exception e) {
logger.error("查找卡券错误: " + "CouponId:" + couponMerchantQ.getProductId());
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR);
}
@@ -623,7 +672,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
}

// 7. 公众号消息
if(StringUtils.isNotBlank(user.getMpAppId()) &&
if (StringUtils.isNotBlank(user.getMpAppId()) &&
StringUtils.isNotBlank(user.getMpOpenId()) &&
user.getMpSubscribe().equals(EnumUserIsSubscribe.YES.getCode())) {
// 已关注公众号
@@ -640,15 +689,15 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
String formId = null;
Date curDate = new Date();
Date dateAfter7Day = DateUtils.getHourTimeAfter(7, order.getCreateDate());
if(StringUtils.isNotBlank(order.getFormId()) && curDate.before(dateAfter7Day)
if (StringUtils.isNotBlank(order.getFormId()) && curDate.before(dateAfter7Day)
&& !order.getFormId().equalsIgnoreCase("undefined")) {
formId = order.getFormId();
}

// 6. get payOrder info
int formType = EnumMsgLimitType.WEAPP_FORMID.getCode();
if(StringUtils.isBlank(order.getFormId()) || order.getFormId().equalsIgnoreCase("undefined")) {
if(order.getPayment() > 0) {
if (StringUtils.isBlank(order.getFormId()) || order.getFormId().equalsIgnoreCase("undefined")) {
if (order.getPayment() > 0) {
// formId为空,获取prepayId
WxPayOrder payOrder = null;
WxPayOrder payOrderQ = new WxPayOrder();
@@ -675,7 +724,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
}
}

if(StringUtils.isBlank(formId)) {
if (StringUtils.isBlank(formId)) {
logger.error("无可用formId, 不能发小程序模板消息");
return;
}
@@ -688,7 +737,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
msgLimit.setTenantId(user.getTenantId());
msgLimit.setType(formType);
msgLimit.setLimitId(formId);
if(wxMsgLimitService.checkIsLimit(msgLimit)) {
if (wxMsgLimitService.checkIsLimit(msgLimit)) {
// 已达到限制条件,不发消息了
logger.error("已达到限制条件,不发小程序模板消息了: " + user.getId());
return;
@@ -730,7 +779,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
));

try {
mqBaseProducer.sendMessage(mpAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode());
mqBaseProducer.sendMessage(mpAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
} catch (Exception e) {
logger.error("核销-公众号-模板消息发送失败: " + e.getMessage());
throw new MallinkException(ErrorCode.MP_TEMPLATE_SEND_FAILED);
@@ -742,7 +791,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
authQ.setAuthorizerAppid(user.getAppId());
authQ.setTenantId(user.getTenantId());
WxAuthorizerInfo weappInfo = authorizerInfoMapper.findMp(authQ);
if(weappInfo != null) {
if (weappInfo != null) {
AppUniformMsg appUniformMsg = new AppUniformMsg();
appUniformMsg.setMsgType(EnumMsgRecordType.SMART_APP_UNIFORM.getCode());
appUniformMsg.setAppId(user.getAppId());
@@ -758,7 +807,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
user.getNickName()
));
try {
mqBaseProducer.sendMessage(appUniformMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(),EnumMsgMqKey.DEFAULT.getCode());
mqBaseProducer.sendMessage(appUniformMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode());
} catch (Exception e) {
logger.error("核销-公众号-模板消息发送失败: " + e.getMessage());
throw new MallinkException(ErrorCode.UNIFORM_SEND_FAILED);


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxMerchantSubsidyServiceImpl.java View File

@@ -77,7 +77,7 @@ public class WxMerchantSubsidyServiceImpl implements WxMerchantSubsidyService {
@Override
public void exportData(WxMerchantSubsidy wxMerchantSubsidy, HttpServletRequest request, HttpServletResponse response) {
List<WxMerchantSubsidyVo> list = wxMerchantSubsidyMapper.findVoList(wxMerchantSubsidy);
excelService.exportExcel(list, null, "补贴记录", WxMerchantSubsidyVo.class, "补贴记录.xlsx", response, false);
excelService.exportExcel(list, null, "结算记录", WxMerchantSubsidyVo.class, "结算记录.xlsx", response, false);
}




+ 55
- 19
mallinkService/src/main/java/com/iformall/service/impl/WxPayOrderServiceImpl.java View File

@@ -76,6 +76,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService {
@Autowired
WxOrderGroupService wxOrderGroupService;

@Autowired
WxMerchantSubsidyMapper wxMerchantSubsidyMapper;

JSONObject errorMap = JSON.parseObject("{" +
"\"NOAUTH\":{\"detail\":\"商户无此接口权限\",\"reason\":\"商户未开通此接口权限\",\"resolution\":\"请商户前往申请此接口权限\"}," +
@@ -686,9 +688,9 @@ public class WxPayOrderServiceImpl implements WxPayOrderService {
public ResultData payOrderQuery(WxPayOrder record) {

try {
if (StringUtils.isBlank(record.getPayOrderNo()))
if (StringUtils.isBlank(record.getPayOrderNo())) {
record.setPayOrderNo(String.valueOf(record.getId()));
}
WxPayOrder payOrder = wxPayOrderMapper.selectById(record.getId());
if (payOrder != null) {
record.setPayOrderStatus(payOrder.getPayOrderStatus());
@@ -1333,27 +1335,59 @@ public class WxPayOrderServiceImpl implements WxPayOrderService {
}
logger.info("订单刷卡发券 结束");

// 延迟10秒后分账
new Thread(() -> {
String tenantId = record.getTenantId();
Long orderId = record.getOrderId();
Long payOrderId = record.getId();
if (record.getShare().equals(EnumPayShare.NO.getCode())) {
//结算记录
try {
Thread.currentThread().sleep(10000);
createMerchantSubsidy(record, order, curDate);
} catch (Exception e) {
logger.error("sleep error: " + e.getMessage());
logger.error("收银台结算记录失败,{}", e.getMessage());
}
} else {
// 延迟10秒后分账
new Thread(() -> {
String tenantId = record.getTenantId();
Long orderId = record.getOrderId();
Long payOrderId = record.getId();
try {
Thread.currentThread().sleep(10000);
} catch (Exception e) {
logger.error("sleep error: " + e.getMessage());
}

// 支付分账
logger.info("订单分账开始: orderId: {}, payOrderId: {}", orderId, payOrderId);
try {
wxOrderService.shareForMicroPay(tenantId, orderId, payOrderId);
} catch (MallinkException e) {
logger.error("订单分账失败: orderId: {}, payOrderId: {}", orderId, payOrderId);
logger.error("订单分账失败: " + e.getMessage());
}
logger.info("订单分账结束: orderId: {}, payOrderId: {}", orderId, payOrderId);
}).start();
// 支付分账
logger.info("订单分账开始: orderId: {}, payOrderId: {}", orderId, payOrderId);
try {
wxOrderService.shareForMicroPay(tenantId, orderId, payOrderId);
} catch (MallinkException e) {
logger.error("订单分账失败: orderId: {}, payOrderId: {}", orderId, payOrderId);
logger.error("订单分账失败: " + e.getMessage());
}
logger.info("订单分账结束: orderId: {}, payOrderId: {}", orderId, payOrderId);
}).start();
}
}

public void createMerchantSubsidy(WxPayOrder record, WxOrder order, Date curDate) {
final IdWorker idWorker = IdWorker.get();
WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy();
merchantSubsidy.setId(idWorker.nextId());
merchantSubsidy.setTenantId(record.getTenantId());
merchantSubsidy.setOrderId(record.getOrderId());
merchantSubsidy.setOrderType(EnumOrderType.NATIVEPAY.getCode());
WxMerchantBUser wxMerchantBUser = wxMerchantBUserMapper.selectById(order.getProductId());
merchantSubsidy.setMerchantId(wxMerchantBUser.getMerchantId());
merchantSubsidy.setCouponOrderId(0L);
merchantSubsidy.setCouponType(0);
merchantSubsidy.setOrderPayment(record.getPayAmount());
merchantSubsidy.setReceiverPayment(record.getPayAmount());
merchantSubsidy.setRealPayment(record.getPayAmount());
merchantSubsidy.setSubsidy(record.getPayAmount());
merchantSubsidy.setRealSubsidy(record.getPayAmount());
merchantSubsidy.setCreateDate(curDate);
merchantSubsidy.setUpdateDate(curDate);
merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode());
merchantSubsidy.setSource(EnumMerchantSubsidySource.CASHIER.getCode());
wxMerchantSubsidyMapper.insert(merchantSubsidy);
}

@Override
@@ -1539,4 +1573,6 @@ public class WxPayOrderServiceImpl implements WxPayOrderService {
public void deleteById(Long id) {
wxPayOrderMapper.deleteById(id);
}


}

+ 43
- 22
mallinkService/src/main/resources/mapper/WxMerchantSubsidyMapper.xml View File

@@ -17,11 +17,13 @@
<result column="create_date" jdbcType="TIMESTAMP" property="createDate" />
<result column="update_date" jdbcType="TIMESTAMP" property="updateDate" />
<result column="freeze" property="freeze" />
<result column="type" property="type"/>
<result column="source" property="source"/>

</resultMap>
<sql id="allColumns">
`id`,`order_id`,`order_type`,`merchant_id`,`coupon_order_id`,`coupon_type`,`order_payment`,`receiver_payment`,`real_payment`,`subsidy`,`real_subsidy`,`status`,`create_date`,`update_date`,freeze
`id`,`order_id`,`order_type`,`merchant_id`,`coupon_order_id`,`coupon_type`,`order_payment`,`receiver_payment`,`real_payment`,`subsidy`,`real_subsidy`,`status`,`create_date`,`update_date`,freeze,type,source
</sql>

<sql id="dynamicWhereConditions">
@@ -74,6 +76,14 @@
<if test=" null != startdate and null!=enddate">
and `create_date` between #{startdate} and #{enddate}
</if>
<if test=" null != type">
and `type` = #{type}
</if>
<if test=" null != source">
and `source` = #{source}
</if>
<if test=" null != statusS ">
and `status` in
<foreach collection="statusS" index="index" item="sItem" open="(" separator="," close=")">
@@ -140,6 +150,11 @@
<result column="nick_name" jdbcType="VARCHAR" property="nickName" />
<result column="phone" jdbcType="VARCHAR" property="phone" />
<result column="freeze" property="freeze" />
<result column="source" property="source"/>
<result column="type" property="type"/>
</resultMap>

<sql id="allVoColumns">
@@ -218,28 +233,34 @@
</sql>

<select id="findVoList" parameterType="com.iformall.domain.vo.WxMerchantSubsidyVo" resultMap="VoBaseResultMap">
select * from
(
select <include refid="allVoColumns" />
from wx_merchant_subsidy ms
left join wx_coupon_order co on co.id = ms.coupon_order_id
left join wx_coupon c on c.id = co.coupon_id
left join wx_merchant m on m.id = ms.merchant_id
left join wx_card_spend cs on cs.order_id = ms.order_id
left join wx_c_user cu on cu.id = cs.owner_id
where ms.order_type = 3
union
select <include refid="allVoColumns" />
from wx_merchant_subsidy ms
left join wx_coupon_order co on co.id = ms.coupon_order_id
left join wx_coupon c on c.id = co.coupon_id
left join wx_merchant m on m.id = ms.merchant_id
left join wx_order o on o.id = ms.order_id
left join wx_c_user cu on cu.id = o.c_user_id
where ms.order_type = 0
) t
select ms.id,ms.order_id,m.name,ms.source,ms.type,
ms.create_date,ms.subsidy,ms.real_subsidy,ms.status,ms.freeze
from wx_merchant_subsidy ms left join wx_merchant m on ms.merchant_id=m.id
where 1=1
<include refid="dynamicVoWhereConditions" />
<if test=" null != tenantId ">
and ms.`tenant_id` = #{tenantId}
</if>
<if test=" null != orderId ">
and ms.`order_id` = #{orderId}
</if>
<if test=" null != merchantId ">
and ms.`merchant_id` = #{merchantId}
</if>
<if test=" null != source ">
and ms.`source` = #{source}
</if>
<if test=" null != type ">
and ms.`type` = #{type}
</if>
<if test=" null != status ">
and ms.`status` = #{status}
</if>
<if test=" null != freeze ">
and ms.`freeze` = #{freeze}
</if>
<if test=" null != startdate and null!=enddate">
and ms.`create_date` between #{startdate} and #{enddate}
</if>
</select>

<select id="sumVoList" parameterType="com.iformall.domain.vo.WxMerchantSubsidyVo" resultType="hashmap">


+ 1
- 1
mallinkService/src/main/resources/mapper/WxOrderMapper.xml View File

@@ -561,7 +561,7 @@
where o.tenant_id=#{tenantId} and c.type!=100 and o.order_status in(0,1,2,3,4,5)
union all
select o.id,o.order_number,o.tenant_id,o.product_id,o.payment,
case o.order_status when 6 then 0 when 7 then 1
case o.order_status when 6 then 0 when 7 then 0
when 8 then 2 when 9 then 2 else o.order_status end order_status,
c.title,cubi.`name` c_user_name,cubi.phone,o.create_date,3 attribute from wx_order o
left join wx_c_user_basic_info cubi on o.c_user_id=cubi.id


Loading…
Cancel
Save