分销订单退款
This commit is contained in:
parent
05fbdb0826
commit
74ae88c7fe
|
|
@ -1,6 +1,7 @@
|
||||||
package com.czg.market.service;
|
package com.czg.market.service;
|
||||||
|
|
||||||
import com.czg.account.entity.UserInfo;
|
import com.czg.account.entity.UserInfo;
|
||||||
|
import com.czg.constant.TableValueConstant;
|
||||||
import com.czg.market.dto.MkDistributionUserDTO;
|
import com.czg.market.dto.MkDistributionUserDTO;
|
||||||
import com.czg.market.dto.MkDistributionWithdrawFlowDTO;
|
import com.czg.market.dto.MkDistributionWithdrawFlowDTO;
|
||||||
import com.czg.market.entity.MkDistributionUser;
|
import com.czg.market.entity.MkDistributionUser;
|
||||||
|
|
@ -113,7 +114,9 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
|
||||||
*/
|
*/
|
||||||
void rechargeCallBack(Long shopId, BigDecimal amount, Long paymentId);
|
void rechargeCallBack(Long shopId, BigDecimal amount, Long paymentId);
|
||||||
|
|
||||||
BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId);
|
BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId, TableValueConstant.DistributionAmountFlow.Type type, String remark);
|
||||||
|
|
||||||
|
void refund(String orderNo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发放分销奖励
|
* 发放分销奖励
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ public interface TableValueConstant {
|
||||||
@Getter
|
@Getter
|
||||||
enum Type {
|
enum Type {
|
||||||
MANUAL_RECHARGE("manual_recharge", "手动充值"),
|
MANUAL_RECHARGE("manual_recharge", "手动充值"),
|
||||||
|
REFUND("refund", "退款"),
|
||||||
SUB("sub", "系统扣减"),
|
SUB("sub", "系统扣减"),
|
||||||
OPEN("open", "分销员购买"),
|
OPEN("open", "分销员购买"),
|
||||||
MANUAL_SUB("manual_sub", "手动扣减"),
|
MANUAL_SUB("manual_sub", "手动扣减"),
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@
|
||||||
distribution_amount = distribution_amount + #{amount}
|
distribution_amount = distribution_amount + #{amount}
|
||||||
</set>
|
</set>
|
||||||
where id = #{userId}
|
where id = #{userId}
|
||||||
and distribution_amount + #{amount} >= 0
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
|
|
@ -605,7 +605,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
distributionFlowService.save(mkDistributionFlow);
|
distributionFlowService.save(mkDistributionFlow);
|
||||||
log.info("即时分销开始");
|
log.info("即时分销开始");
|
||||||
try {
|
try {
|
||||||
updateShopInfoAmount(currentDistributionUser.getShopId(), rewardAmount, mkDistributionFlow.getId());
|
updateShopInfoAmount(currentDistributionUser.getShopId(), rewardAmount.negate(), mkDistributionFlow.getId(), TableValueConstant.DistributionAmountFlow.Type.SUB, "分销扣除");
|
||||||
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
updateIncome(BigDecimal.ZERO, rewardAmount, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
|
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
|
||||||
|
|
@ -620,15 +620,37 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId) {
|
public BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId, TableValueConstant.DistributionAmountFlow.Type type, String remark) {
|
||||||
BigDecimal finalAmount = shopInfoService.updateAmount(shopId, changeAmount.negate());
|
BigDecimal finalAmount = shopInfoService.updateAmount(shopId, changeAmount.negate());
|
||||||
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
distributionAmountFlowService.save(new MkDistributionAmountFlow()
|
||||||
.setType(TableValueConstant.DistributionAmountFlow.Type.SUB.getCode())
|
.setType(type.getCode())
|
||||||
.setShopId(shopId).setAmount(finalAmount).setChangeAmount(changeAmount).setSourceId(sourceId)
|
.setShopId(shopId).setAmount(finalAmount).setChangeAmount(changeAmount).setSourceId(sourceId)
|
||||||
.setRemark("分账扣除"));
|
.setRemark(remark));
|
||||||
return finalAmount;
|
return finalAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refund(String orderNo) {
|
||||||
|
distributionFlowService.list(new QueryWrapper().eq(MkDistributionFlow::getOrderNo, orderNo).ne(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.REFUND.getCode())).forEach(item -> {
|
||||||
|
MkDistributionFlow refundFlow = BeanUtil.copyProperties(item, MkDistributionFlow.class);
|
||||||
|
refundFlow.setStatus(TableValueConstant.DistributionFlow.Status.REFUND.getCode());
|
||||||
|
refundFlow.setSourceId(item.getId());
|
||||||
|
refundFlow.setId(null);
|
||||||
|
refundFlow.setCreateTime(DateUtil.date().toLocalDateTime());
|
||||||
|
refundFlow.setUpdateTime(DateUtil.date().toLocalDateTime());
|
||||||
|
if (TableValueConstant.DistributionFlow.Status.PENDING.getCode().equals(item.getStatus())) {
|
||||||
|
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
|
||||||
|
updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getSourceShopUserId(), item.getShopId(), item.getLevel());
|
||||||
|
distributionFlowService.updateById(item);
|
||||||
|
}else {
|
||||||
|
// 执行扣款
|
||||||
|
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getSourceShopUserId(), item.getShopId(), item.getLevel());
|
||||||
|
updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), item.getId(), TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退");
|
||||||
|
}
|
||||||
|
distributionFlowService.save(refundFlow);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void distribute(Long sourceId, String orderNo, BigDecimal amount, Long sourceUserId, Long shopId, String type) {
|
public void distribute(Long sourceId, String orderNo, BigDecimal amount, Long sourceUserId, Long shopId, String type) {
|
||||||
MkDistributionDeliver deliver = new MkDistributionDeliver().setSourceId(sourceId).setOrderNo(orderNo).setShopId(shopId).setType(type).setStatus("success");
|
MkDistributionDeliver deliver = new MkDistributionDeliver().setSourceId(sourceId).setOrderNo(orderNo).setShopId(shopId).setType(type).setStatus("success");
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,8 @@ public class PayServiceImpl implements PayService {
|
||||||
private MkShopRechargeDetailService shopRechargeDetailService;
|
private MkShopRechargeDetailService shopRechargeDetailService;
|
||||||
@Resource
|
@Resource
|
||||||
private TbMemberConfigService memberConfigService;
|
private TbMemberConfigService memberConfigService;
|
||||||
|
@Resource
|
||||||
|
private MkDistributionUserService distributionUserService;
|
||||||
|
|
||||||
private final BigDecimal MONEY_RATE = new BigDecimal("100");
|
private final BigDecimal MONEY_RATE = new BigDecimal("100");
|
||||||
|
|
||||||
|
|
@ -788,6 +790,9 @@ public class PayServiceImpl implements PayService {
|
||||||
if (!returnProMap.isEmpty()) {
|
if (!returnProMap.isEmpty()) {
|
||||||
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));
|
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 退款分销还原
|
||||||
|
distributionUserService.refund(orderInfo.getOrderNo());
|
||||||
return CzgResult.success();
|
return CzgResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue