Просмотр исходного кода

Merge branch 'release_toaliyun_real_20230315' of https://git.malls.iformall.com/server/formallProject into release_toaliyun_real_20230315

release_toaliyun_real
lin 3 лет назад
Родитель
Сommit
c49fcafd73
11 измененных файлов: 278 добавлений и 90 удалений
  1. +3
    -1
      mallinkService/src/main/java/com/iformall/enums/EnumFlowKey.java
  2. +6
    -0
      mallinkService/src/main/java/com/iformall/mapper/WxCardInfoMapper.java
  3. +9
    -0
      mallinkService/src/main/java/com/iformall/service/WxCardInfoService.java
  4. +2
    -0
      mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java
  5. +2
    -0
      mallinkService/src/main/java/com/iformall/service/WxRefundOrderService.java
  6. +35
    -2
      mallinkService/src/main/java/com/iformall/service/impl/WxCardInfoServiceImpl.java
  7. +24
    -31
      mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java
  8. +1
    -4
      mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java
  9. +13
    -1
      mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java
  10. +167
    -51
      mallinkService/src/main/java/com/iformall/service/impl/WxRefundOrderServiceImpl.java
  11. +16
    -0
      mallinkService/src/main/resources/mapper/WxCardInfoMapper.xml

+ 3
- 1
mallinkService/src/main/java/com/iformall/enums/EnumFlowKey.java Просмотреть файл

@@ -39,7 +39,9 @@ public enum EnumFlowKey {
SETTLE(21,"结算单审批"),
BILL_FINISH(30,"商户账单完结审批"),
CASH_OUT(23,"商户提现审批")
CASH_OUT(23,"商户提现审批"),

CARD_ORDER_REFUND(31,"商户提现审批")
;

public static EnumFlowKey getEnum(Integer code) {


+ 6
- 0
mallinkService/src/main/java/com/iformall/mapper/WxCardInfoMapper.java Просмотреть файл

@@ -16,4 +16,10 @@ public interface WxCardInfoMapper extends CommonMapper<WxCardInfo, Long> {
void updateStatus(WxCardInfo wxCardInfo);

/**
* 修改面额
* @param cardInfo
* @return
*/
int updAmount(WxCardInfo cardInfo);
}

+ 9
- 0
mallinkService/src/main/java/com/iformall/service/WxCardInfoService.java Просмотреть файл

@@ -57,4 +57,13 @@ public interface WxCardInfoService {
PageInfo<WxCardTransferVo> listTransferAsPage(WxCardTransferInfo transferRecord, Integer pageIndex, Integer pageSize);

/**
*
* @param cardInfo
* @param amount 总面额变动值
* @param remainingAmount 剩余面额变动值
* @param remainingShareFeeAmount 分账余额变动值
*/
void updAmount(WxCardInfo cardInfo,Integer amount,Integer remainingAmount,Integer remainingShareFeeAmount);

}

+ 2
- 0
mallinkService/src/main/java/com/iformall/service/WxCardSpendService.java Просмотреть файл

@@ -34,6 +34,8 @@ public interface WxCardSpendService {
*/
ResultData createCardSpend(WxCardSpend record, WxOrder order, WxCouponMerchant couponMerchant);

void sendCardBalanceChange(WxCoupon coupon,WxCardSpend cardSpend);

/**
* 根据实体查询分页列表
*


+ 2
- 0
mallinkService/src/main/java/com/iformall/service/WxRefundOrderService.java Просмотреть файл

@@ -118,4 +118,6 @@ public interface WxRefundOrderService {

ResultData refundCardOrderSuccess(WxRefundOrder refundOrder,WxOrder wxOrder);

ResultData refundCardOrderFail(WxRefundOrder refundOrder,WxOrder wxOrder,String remark);

}

+ 35
- 2
mallinkService/src/main/java/com/iformall/service/impl/WxCardInfoServiceImpl.java Просмотреть файл

@@ -41,6 +41,8 @@ import com.iformall.utils.Constant;
import com.iformall.utils.RedisLock;

import org.apache.commons.beanutils.BeanUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@@ -60,6 +62,8 @@ import java.util.Map;

@Service
public class WxCardInfoServiceImpl implements WxCardInfoService {

private final Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
WxCardInfoMapper wxCardInfoMapper;
@@ -389,8 +393,37 @@ public class WxCardInfoServiceImpl implements WxCardInfoService {
pageInfo.setTotal(cardInfoPage.getTotal());
return pageInfo;
}
private List<WxCardTransferVo> toTransferVoList(List<WxCardTransferInfo> transferList,TenantEntity tenantEntity) {

@Override
public void updAmount(WxCardInfo cardInfo,Integer amount,Integer remainingAmount,Integer remainingShareFeeAmount) {
//此处需要加锁,防止并发设置
long time = System.currentTimeMillis() + RedisLock.TIMEOUT;
String timeStr = String.valueOf(time);
boolean cashsetlock = redisLock.lock("cardInfoLockAmountSet_"+cardInfo.getId(), timeStr);
if (cashsetlock) {
try {
WxCardInfo cardInfoUpd = new WxCardInfo();
cardInfoUpd.setId(cardInfo.getId());
cardInfoUpd.updateTenantInfo(cardInfo);
cardInfoUpd.setAmount(amount);
cardInfoUpd.setRemainingAmount(remainingAmount);
cardInfoUpd.setRemainingShareFeeAmount(remainingShareFeeAmount);
int i = wxCardInfoMapper.updAmount(cardInfo);
redisLock.unlock("cardInfoLockAmountSet_"+cardInfo.getId(), timeStr);
if(i != 1){
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"卡余额不足 error.");
}
}catch(Exception e) {
redisLock.unlock("cardInfoLockAmountSet_"+cardInfo.getId(), timeStr);
logger.error("updAmount error."+cardInfo.getId(),e);
throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"余额变动 error."+e.getMessage());
}finally {
redisLock.unlock("cardInfoLockAmountSet_"+cardInfo.getId(), timeStr);
}
}
}

private List<WxCardTransferVo> toTransferVoList(List<WxCardTransferInfo> transferList,TenantEntity tenantEntity) {
List<WxCardTransferVo> retList = new ArrayList<WxCardTransferVo>();
if (null != transferList && transferList.size() > 0 ) {
List<Long> userList = new ArrayList<>();


+ 24
- 31
mallinkService/src/main/java/com/iformall/service/impl/WxCardSpendServiceImpl.java Просмотреть файл

@@ -54,6 +54,9 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
@Autowired
WxCardSpendMapper wxCardSpendMapper;

@Autowired
WxCardInfoService wxCardInfoService;

@Autowired
WxCardInfoMapper wxCardInfoMapper;

@@ -211,25 +214,11 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
}

// 7. update card info
WxCardInfo updateCardInfo = new WxCardInfo();
updateCardInfo.setId(cardInfo.getId());
updateCardInfo.setRemainingAmount(remaingAmount);
updateCardInfo.setRemainingShareFeeAmount(remain_real_pament);
updateCardInfo.setUpdateDate(curDate);
wxCardInfoService.updAmount(cardInfo,null,0-record.getDeductionAmount(),0-real_payment);

cardInfo.setRemainingAmount(remaingAmount);
cardInfo.setRemainingShareFeeAmount(remain_real_pament);
cardInfo.setUpdateDate(curDate);
// 7.1、消费后修改卡转赠状态
// if (cardInfo.getSupportTransfer().equals(EnumCouponTransfer.YES.getCode())) {
// updateCardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode());
// cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode());
// }
try {
wxCardInfoMapper.updateById(updateCardInfo);
} catch (Exception e) {
logger.error("card info update error");
return new ResultData(ErrorCode.DB_FAIL.getCode(), "card info 更新出错!");
}

// 7.2 update coupon card status
if (cardInfo.getRemainingAmount().equals(0)) {
@@ -245,8 +234,6 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
logger.info("补贴额: " + subsidyFee);
if (cardInfo.getSaleAmount().equals(0) || subsidyFee > 0) {
// 有补贴时入库, 免费卡消费时, 或者有补贴金额时
int iSubChargeFee = PayUtils.getPayRate(subsidyFee, payAccount.getRealRate(), false);
Integer realSubsidyFee = subsidyFee - iSubChargeFee;
WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy();
merchantSubsidy.setId(idWorker.nextId());
merchantSubsidy.updateTenantInfo(record);
@@ -260,7 +247,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
merchantSubsidy.setReceiverPayment(payment);
merchantSubsidy.setRealPayment(real_payment);
merchantSubsidy.setSubsidy(subsidyFee);
merchantSubsidy.setRealSubsidy(realSubsidyFee);
merchantSubsidy.setRealSubsidy(subsidyFee);
if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) {
// 立减领券
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode());
@@ -302,7 +289,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
if (cardInfo.getSaleAmount() > 0) {
if (payment > 0) {
try {
creteMerchantSubsidy(record, curDate, idWorker, coupon, payment);
creteMerchantSubsidy(record, curDate, idWorker, coupon);
} catch (Exception ex) {
logger.error("记录到结算表失败");
}
@@ -357,11 +344,13 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
/**
* 卡余额变动订阅消息
*/
private void sendCardBalanceChange(WxCoupon coupon,WxCardSpend cardSpend){
@Override
public void sendCardBalanceChange(WxCoupon coupon,WxCardSpend cardSpend){
try {
if(cardSpend.getOwnerId() == null){
return;
}

WxCUser wcuQ = new WxCUser();
wcuQ.updateTenantInfo(coupon);
wcuQ.setUserId(cardSpend.getOwnerId());
@@ -384,11 +373,17 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {

Map<String,String> map = new HashMap<>();
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()));
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");

msg.setMsg(JSONObject.toJSONString(map));
@@ -399,7 +394,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();
merchantSubsidy.setId(idWorker.nextId());
merchantSubsidy.updateTenantInfo(record);
@@ -412,8 +407,8 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
merchantSubsidy.setOrderPayment(record.getPayment());
merchantSubsidy.setReceiverPayment(record.getPayment());
merchantSubsidy.setRealPayment(record.getRealPayment());
merchantSubsidy.setSubsidy(payment);
merchantSubsidy.setRealSubsidy(payment);
merchantSubsidy.setSubsidy(record.getPayment());
merchantSubsidy.setRealSubsidy(record.getRealPayment());
merchantSubsidy.setCreateDate(curDate);
merchantSubsidy.setUpdateDate(curDate);
merchantSubsidy.setType(EnumMerchantSubsidyType.WECHAT.getCode());
@@ -1232,8 +1227,6 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
logger.info("补贴额: " + subsidyFee);
if (subsidyFee > 0) {
// 有补贴时入库
int iSubChargeFee = PayUtils.getPayRate(subsidyFee, payAccount.getRealRate(), false);
Integer realSubsidyFee = subsidyFee - iSubChargeFee;
WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy();
merchantSubsidy.setId(idWorker.nextId());
merchantSubsidy.updateTenantInfo(record);
@@ -1247,7 +1240,7 @@ public class WxCardSpendServiceImpl implements WxCardSpendService {
merchantSubsidy.setReceiverPayment(record.getPayment());
merchantSubsidy.setRealPayment(record.getRealPayment());
merchantSubsidy.setSubsidy(subsidyFee);
merchantSubsidy.setRealSubsidy(realSubsidyFee);
merchantSubsidy.setRealSubsidy(subsidyFee);
if (coupon.getSubsidyType().equals(EnumCouponSubsidyType.WECHAT_COUPON.getCode())) {
// 立减领券
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.AUTO_SUBSIDIED.getCode());


+ 1
- 4
mallinkService/src/main/java/com/iformall/service/impl/WxCouponOrderServiceImpl.java Просмотреть файл

@@ -1996,9 +1996,6 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
return;
}
subsidyNum = subsidyNum * couponOrder.getCouponNumber();
// 新补贴入库
int iSubChargeFee = OrderHelper.getRealRateAmount(subsidyNum, payAccount);
Integer realSubsidyFee = subsidyNum - iSubChargeFee;

WxOrder order = wxOrderMapper.selectById(couponOrder.getOrderId(), couponOrder.getTenantId());
int iPriceChargeFee = OrderHelper.getRealRateAmount(order.getPayment(), payAccount);
@@ -2017,7 +2014,7 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService {
merchantSubsidy.setReceiverPayment(coupon.getSalePrice());
merchantSubsidy.setRealPayment(realPayment);
merchantSubsidy.setSubsidy(subsidyNum);
merchantSubsidy.setRealSubsidy(realSubsidyFee);
merchantSubsidy.setRealSubsidy(subsidyNum);
merchantSubsidy.setStatus(EnumMerchantSubsidyStatus.NOT_SUBSIDY.getCode());
merchantSubsidy.setCreateDate(new Date());
merchantSubsidy.setUpdateDate(new Date());


+ 13
- 1
mallinkService/src/main/java/com/iformall/service/impl/WxFlowServiceImpl.java Просмотреть файл

@@ -97,6 +97,8 @@ public class WxFlowServiceImpl implements WxFlowService {
@Autowired
private WxBillSettleService wxBillSettleService;
@Autowired
private WxRefundOrderService wxRefundOrderService;
@Autowired
@Qualifier("couponChannelRedisTemplate")
RedisTemplate<String, PageInfo<WxCouponChannelVo>> cdRedisTemplate;
@Autowired
@@ -467,7 +469,6 @@ public class WxFlowServiceImpl implements WxFlowService {
}else if (EnumFlowKey.CASH_OUT.getCode().equals(flowType)) {
String tenantId = (String)getVariableByKey(variables,"cashTenantId");
WxCashOut cashout = wxCashOutService.getById(Long.parseLong(businessId), tenantId);
//如果是提交审批
if (EnumRentContractAppStatus.APPLYING.getCode().intValue() == applyStatus.intValue()) {
cashout.setStatus(EnumCashOutStatus.AUDIOING.getCode());
@@ -492,6 +493,17 @@ public class WxFlowServiceImpl implements WxFlowService {
cashout.setUpdateDate(new Date());
wxCashOutService.rejectCashOut(cashout);
}
}else if(EnumFlowKey.CARD_ORDER_REFUND.getCode().equals(flowType)){
WxRefundOrder RefundOrder = wxRefundOrderService.getById(Long.parseLong(businessId));
// 审批完成
if (EnumRentContractAppStatus.FINISH.getCode().intValue() == applyStatus.intValue()) {
wxRefundOrderService.refundCardOrderSuccess(RefundOrder,null);
//如果是审批撤回,或者驳回,改回草稿状态
}else if (EnumRentContractAppStatus.SETBACK.getCode().intValue() == applyStatus.intValue()
|| EnumRentContractAppStatus.REJECT.getCode().intValue() == applyStatus.intValue()) {
String remark = (String)mapInfo.get("remark");
wxRefundOrderService.refundCardOrderFail(RefundOrder,null,remark);
}
}
}



+ 167
- 51
mallinkService/src/main/java/com/iformall/service/impl/WxRefundOrderServiceImpl.java Просмотреть файл

@@ -88,9 +88,6 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {

@Autowired
WxCUserMapper wxCUserMapper;

@Autowired
WxCardInfoMapper cardInfoMapper;
@Autowired
PayServiceFactory payServiceFactory;
@@ -98,6 +95,9 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {
@Autowired
WxBatchOrderMapper wxBatchOrderMapper;

@Autowired
WxCardInfoService wxCardInfoService;

@Autowired
WxCardInfoMapper wxCardInfoMapper;

@@ -107,9 +107,15 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {
@Autowired
WxMerchantSubsidyMapper wxMerchantSubsidyMapper;

@Autowired
WxCashOutService wxCashOutService;

@Autowired
private MqBaseProducer mqBaseProducer;

@Autowired
WxFlowService wxFlowService;

private boolean isMerchantOrder(WxOrder wxOrder, Long merchantId) {
if (wxOrder.getType().equals(EnumOrderType.COUPON.getCode())) {
@@ -314,7 +320,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {
updateCardInfo.setId(wxCouponOrder.getId());
updateCardInfo.setRemainingAmount(0);
try {
cardInfoMapper.updateById(updateCardInfo);
wxCardInfoMapper.updateById(updateCardInfo);
} catch (Exception e) {
logger.error("db failed: wxCardInfo-" + wxCouponOrder.getId() + ", e:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
@@ -954,7 +960,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {
updateCardInfo.setId(wxCouponOrder.getId());
updateCardInfo.setRemainingAmount(0);
try {
cardInfoMapper.updateById(updateCardInfo);
wxCardInfoMapper.updateById(updateCardInfo);
} catch (Exception e) {
logger.error("db failed: wxCardInfo-" + wxCouponOrder.getId() + ", e:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
@@ -1137,7 +1143,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {

WxRefundOrder record = new WxRefundOrder();
record.updateTenantInfo(wxOrder);
record.setPayOrderNo(String.valueOf(cardSend.getId()));//卡没有支付订单
record.setPayOrderNo(String.valueOf(cardSend.getId()));
record.setOrderId(wxOrder.getId());
record.setNotStatus(EnumRefundStatus.REFUND_FAIL.getCode());

@@ -1186,11 +1192,20 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {
try {
wxCardSpendMapper.updateById(cardSpendUpd);
} catch (Exception e) {
logger.error("卡退款订单修改出错: " + record.toString());
logger.error("卡退款订单修改出错: " + cardSpendUpd.toString());
throw new MallinkException(ErrorCode.DB_FAIL);
}

refundCardOrderSuccess(record,wxOrder);
boolean hasAudit = hasWorkFlow(cardSend);
if(hasAudit){
Map<String, Object> map = new HashMap<String, Object>();
map.put("businessId", String.valueOf(record.getId()));
map.put("businessType", EnumFlowKey.CARD_ORDER_REFUND.getCode());
map.put("phone", bUser.getPhone());
wxFlowService.start(map, bUser.getId(), bUser.getName(), bUser);
return new ResultData(Result.SUCCESS,"提交审批成功");
}else{
refundCardOrderSuccess(record,wxOrder);
}

return new ResultData();
}
@@ -1209,14 +1224,18 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {
logger.error("card not found: " + cardSend.getCardId());
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);
if(wxOrder == null){
wxOrder = wxOrderMapper.selectById(refundOrder.getOrderId(),refundOrder.getTenantId());
if (wxOrder == null) {
logger.error("交易订单不存在:" + cardSend.getOrderId());
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND);
}
}
WxPayAccount payAccount = wxPayAccountService.getByIdFromRedis(cAppInfo.getPayId());
if(payAccount == null){
throw new MallinkException(ErrorCode.API_KEY_NOT_FOUND);

WxCoupon coupon = wxCouponMapper.selectById(cardInfo.getCouponId(),cardInfo.getTenantId());
if (coupon == null) {
logger.error("card's coupon not found: " + cardInfo.getCouponId());
throw new MallinkException(ErrorCode.CARD_IS_NOT_FOUND);
}

Date currentDate = new Date();
@@ -1300,23 +1319,12 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {
throw new MallinkException(ErrorCode.DB_FAIL);
}

wxCardInfoService.updAmount(cardInfo,null,record.getDeductionAmount(),real_refund);

WxCardInfo updateCardInfo = new WxCardInfo();
updateCardInfo.setId(cardInfo.getId());
updateCardInfo.setRemainingAmount(remaingAmount);
updateCardInfo.setRemainingShareFeeAmount(remain_real_pament);
updateCardInfo.setUpdateDate(currentDate);
cardInfo.setRemainingAmount(remaingAmount);
cardInfo.setRemainingShareFeeAmount(remain_real_pament);
cardInfo.setUpdateDate(currentDate);

try {
wxCardInfoMapper.updateById(updateCardInfo);
} catch (Exception e) {
logger.error("card info update error");
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "card info 更新出错!");
}

if(record.getCardBeforeAmount().equals(0)){
if (wxCardSpendService.cardFinishedUsing(currentDate, cardInfo)) {
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "couponOrder status 更新出错!");
@@ -1330,35 +1338,66 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {
subsidyFee = subsidyD.intValue();

WxMerchantSubsidy merchantSubsidy = new WxMerchantSubsidy();
merchantSubsidy.setId(idWorker.nextId());
merchantSubsidy.updateTenantInfo(record);
merchantSubsidy.setOrderId(wxOrder.getId());
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);

//更新商户余额
Long merchantId = cardSend.getMerchantId();
WxMerchant merchant = wxMerchantMapper.selectById(merchantId);
wxCashOutService.addCashOut(merchant, 0-refund);
}

try {
@@ -1369,9 +1408,86 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService {
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "card spend 插入出错!");
}

wxCardSpendService.sendCardBalanceChange(coupon,record);

return new ResultData();
}

@Override
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public ResultData refundCardOrderFail(WxRefundOrder refundOrder, WxOrder wxOrder,String remark) {
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);
}
if(wxOrder == null){
wxOrder = wxOrderMapper.selectById(refundOrder.getOrderId(),refundOrder.getTenantId());
if (wxOrder == null) {
logger.error("交易订单不存在:" + cardSend.getOrderId());
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND);
}
}

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.setFailReason(remark);
// 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();
}

protected boolean hasWorkFlow(TenantEntity tenantEntity) {
WxFlowModel wxFlowModel = new WxFlowModel();
wxFlowModel.setFlowType(EnumFlowKey.CARD_ORDER_REFUND.getCode());
wxFlowModel.updateTenantInfo(tenantEntity);
List<WxFlowModel> flows = wxFlowService.getModelBybusiness(wxFlowModel);
if (null != flows && flows.size() > 0) {
return true;
}
return false;
}
}

+ 16
- 0
mallinkService/src/main/resources/mapper/WxCardInfoMapper.xml Просмотреть файл

@@ -151,5 +151,21 @@
<update id="updateStatus" parameterType="com.iformall.domain.po.WxCardInfo">
update wx_card_info set status=#{status},update_date=now() where id=#{id} and tenant_id = #{tenantId}
</update>

<update id="updAmount" parameterType="com.iformall.domain.po.WxCardInfo">
update wx_card_info set
<if test=" null != amount ">
`amount` = amount+#{amount},
</if>
<if test=" null != remainingAmount ">
`remaining_amount` = remaining_amount+#{remainingAmount},
</if>
<if test=" null != remainingShareFeeAmount ">
`remaining_share_fee_amount` = remaining_share_fee_amount+#{remainingShareFeeAmount},
</if>
,update_date=now()
where id=#{id} and tenant_id = #{tenantId}
and remaining_amount+#{remainingAmount} >= 0
</update>
</mapper>

Загрузка…
Отмена
Сохранить