Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
2025-10-30 15:55:49 +08:00
14 changed files with 81 additions and 25 deletions

View File

@@ -10,7 +10,6 @@
distribution_amount = distribution_amount + #{amount}
</set>
where id = #{userId}
and distribution_amount + #{amount} >= 0
</update>
</mapper>

View File

@@ -17,6 +17,6 @@ import java.util.List;
*/
public interface MkDistributionFlowMapper extends BaseMapper<MkDistributionFlow> {
List<MkDistributionFlowVO> pageInfo(Long shopId, LocalDateTime startTime, LocalDateTime endTime, String status, String key, Long id, String type);
BigDecimal totalAmount(Long shopId, LocalDateTime startTime, LocalDateTime endTime, String status, String key, Long id, String type);
List<MkDistributionFlowVO> pageInfo(Long shopId, LocalDateTime startTime, LocalDateTime endTime, String status, String key, Long id, String type, Long userId);
BigDecimal totalAmount(Long shopId, LocalDateTime startTime, LocalDateTime endTime, String status, String key, Long id, String type, Long userId);
}

View File

@@ -18,6 +18,7 @@ import com.czg.market.service.MkDistributionAmountFlowService;
import com.czg.service.market.mapper.MkDistributionAmountFlowMapper;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Map;
@@ -59,12 +60,12 @@ public class MkDistributionAmountFlowServiceImpl extends ServiceImpl<MkDistribut
Page<MkDistributionAmountFlowVO> pageInfo = pageAs(PageUtil.buildPage(), queryWrapper.orderBy(MkDistributionAmountFlow::getCreateTime, false), MkDistributionAmountFlowVO.class);
Map<String, Object> map = BeanUtil.beanToMap(pageInfo);
map.put("totalRecharge", getOne(new QueryWrapper().eq(MkDistributionAmountFlow::getShopId, shopId)
map.put("totalRecharge", getOneAs(new QueryWrapper().eq(MkDistributionAmountFlow::getShopId, shopId)
.in(MkDistributionAmountFlow::getType, TableValueConstant.DistributionAmountFlow.Type.MANUAL_RECHARGE.getCode(), TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode())
.select("sum(change_amount)")));
map.put("totalSub", getOne(new QueryWrapper().eq(MkDistributionAmountFlow::getShopId, shopId)
.select("sum(change_amount)"), BigDecimal.class));
map.put("totalSub", getOneAs(new QueryWrapper().eq(MkDistributionAmountFlow::getShopId, shopId)
.in(MkDistributionAmountFlow::getType, TableValueConstant.DistributionAmountFlow.Type.SUB.getCode(), TableValueConstant.DistributionAmountFlow.Type.MANUAL_SUB.getCode())
.select("sum(change_amount)")));
.select("sum(change_amount)"), BigDecimal.class));
return map;
}
@@ -102,11 +103,11 @@ public class MkDistributionAmountFlowServiceImpl extends ServiceImpl<MkDistribut
Page<MkDistributionAmountFlowVO> pageInfo = pageAs(PageUtil.buildPage(), queryWrapper.orderBy(MkDistributionAmountFlow::getCreateTime, false), MkDistributionAmountFlowVO.class);
Map<String, Object> map = BeanUtil.beanToMap(pageInfo);
map.put("totalAmount", getOne(new QueryWrapper().eq(MkDistributionAmountFlow::getShopId, shopId)
.in(MkDistributionAmountFlow::getType, TableValueConstant.DistributionAmountFlow.Type.MANUAL_RECHARGE.getCode(), TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode())
.select("sum(change_amount)")));
map.put("totalAmount", getOneAs(new QueryWrapper().eq(MkDistributionAmountFlow::getShopId, shopId)
.in(MkDistributionAmountFlow::getType, TableValueConstant.DistributionAmountFlow.Type.OPEN.getCode())
.select("sum(change_amount)"), BigDecimal.class));
map.put("totalCount", count(new QueryWrapper().eq(MkDistributionAmountFlow::getShopId, shopId)
.in(MkDistributionAmountFlow::getType, TableValueConstant.DistributionAmountFlow.Type.SUB.getCode(), TableValueConstant.DistributionAmountFlow.Type.MANUAL_SUB.getCode())));
.in(MkDistributionAmountFlow::getType, TableValueConstant.DistributionAmountFlow.Type.OPEN.getCode())));
return map;
}

View File

@@ -45,7 +45,7 @@ public class MkDistributionFlowServiceImpl extends ServiceImpl<MkDistributionFlo
@Override
public Map<String, Object> pageInfo(Long shopId, LocalDateTime startTime, LocalDateTime endTime, String key, String status, Long id) {
PageHelper.startPage(PageUtil.buildPageHelp());
List<MkDistributionFlowVO> list = mapper.pageInfo(shopId, startTime, endTime, status, key, id, null);
List<MkDistributionFlowVO> list = mapper.pageInfo(shopId, startTime, endTime, status, key, id, null, null);
Page<MkDistributionFlowVO> page = PageUtil.convert(new PageInfo<>(list));
Map<String, Object> map = BeanUtil.beanToMap(page);
map.put("successAmount", getOneAs(new QueryWrapper().eq(MkDistributionFlow::getShopId, shopId)
@@ -66,11 +66,11 @@ public class MkDistributionFlowServiceImpl extends ServiceImpl<MkDistributionFlo
}
PageHelper.startPage(PageUtil.buildPageHelp());
List<MkDistributionFlowVO> list = mapper.pageInfo(shopId, StrUtil.isBlank(startTime) ? null : DateUtil.parseLocalDateTime(startTime),
StrUtil.isBlank(endTime) ? null : DateUtil.parseLocalDateTime(endTime), status,null, shopUserInfo == null ? null : shopUserInfo.getId(), null);
StrUtil.isBlank(endTime) ? null : DateUtil.parseLocalDateTime(endTime), status,null, shopUserInfo == null ? null : shopUserInfo.getId(), null, userId);
Page<MkDistributionFlowVO> page = PageUtil.convert(new PageInfo<>(list));
Map<String, Object> map = BeanUtil.beanToMap(page);
map.put("totalAmount", mapper.totalAmount(shopId, StrUtil.isBlank(startTime) ? null : DateUtil.parseLocalDateTime(startTime),
StrUtil.isBlank(endTime) ? null : DateUtil.parseLocalDateTime(endTime), status,null, shopUserInfo == null ? null : shopUserInfo.getId(), null));
StrUtil.isBlank(endTime) ? null : DateUtil.parseLocalDateTime(endTime), status,null, shopUserInfo == null ? null : shopUserInfo.getId(), null, userId));
return map;
}
}

View File

@@ -594,6 +594,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
ShopUser shopUser = shopUserService.getById(currentDistributionUser.getId());
MkDistributionFlow mkDistributionFlow = new MkDistributionFlow().setShopUserId(currentDistributionUser.getId())
.setShopId(currentDistributionUser.getShopId()).setDistributionUserId(currentDistributionUser.getId())
.setUserId(shopUser.getUserId())
.setNickName(shopUser.getNickName()).setSourceShopUserId(orderSourceShopUser.getId()).setSourceNickName(orderSourceShopUser.getNickName())
.setCommission(finalCommission).setParentCommission(parentLevel != null ? parentLevel.getLevelOneCommission() : null)
.setLevelId(currentDistributionUser.getDistributionLevelId()).setLevel(currentLevel == 1 ? 1 : 2).setOrderNo(orderNo)
@@ -605,10 +606,11 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
distributionFlowService.save(mkDistributionFlow);
log.info("即时分销开始");
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);
} catch (Exception e) {
mkDistributionFlow.setStatus(TableValueConstant.DistributionFlow.Status.PENDING.getCode());
updateIncome(rewardAmount, BigDecimal.ZERO, BigDecimal.ZERO, currentDistributionUser.getId(), shopUser.getUserId(), shopUser.getMainShopId(), currentLevel == 1 ? 1 : 2);
distributionFlowService.updateById(mkDistributionFlow);
}
}else {
@@ -620,15 +622,37 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
}
@Override
public BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId) {
BigDecimal finalAmount = shopInfoService.updateAmount(shopId, changeAmount.negate());
public BigDecimal updateShopInfoAmount(Long shopId, BigDecimal changeAmount, Long sourceId, TableValueConstant.DistributionAmountFlow.Type type, String remark) {
BigDecimal finalAmount = shopInfoService.updateAmount(shopId, changeAmount);
distributionAmountFlowService.save(new MkDistributionAmountFlow()
.setType(TableValueConstant.DistributionAmountFlow.Type.SUB.getCode())
.setType(type.getCode())
.setShopId(shopId).setAmount(finalAmount).setChangeAmount(changeAmount).setSourceId(sourceId)
.setRemark("分账扣除"));
.setRemark(remark));
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
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");

View File

@@ -35,6 +35,9 @@
<if test="id != null">
and d.id=#{id}
</if>
<if test="userId != null">
and d.user_id=#{userId}
</if>
<if test="type != null and type != ''">
and a.type=#{type}
</if>
@@ -70,5 +73,8 @@
<if test="type != null and type != ''">
and a.type=#{type}
</if>
<if test="userId != null">
and d.user_id=#{userId}
</if>
</select>
</mapper>

View File

@@ -1066,7 +1066,7 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
// 分销员升级等级
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
// 分销奖励
distributionUserService.distribute(orderInfo.getId(), payment.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order");
distributionUserService.distribute(orderInfo.getId(), orderInfo.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order");
} else if ("memberIn".equals(payment.getPayType()) || "free".equals(payment.getPayType())) {
boolean isFree = "free".equals(payment.getPayType());
ShopUser shopUser = shopUserService.getById(payment.getSourceId());

View File

@@ -114,6 +114,8 @@ public class PayServiceImpl implements PayService {
private MkShopRechargeDetailService shopRechargeDetailService;
@Resource
private TbMemberConfigService memberConfigService;
@Resource
private MkDistributionUserService distributionUserService;
private final BigDecimal MONEY_RATE = new BigDecimal("100");
@@ -788,6 +790,9 @@ public class PayServiceImpl implements PayService {
if (!returnProMap.isEmpty()) {
rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));
}
// 退款分销还原
distributionUserService.refund(orderInfo.getOrderNo());
return CzgResult.success();
}