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

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

View File

@ -6,6 +6,7 @@ import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.annotation.PostConstruct;
@ -18,6 +19,7 @@ import javax.annotation.PostConstruct;
@EnableTransactionManagement
@MapperScan("com.czg.service.market.mapper")
@EnableDubbo
@EnableScheduling
@Slf4j
public class MarketApplication {
public static void main(String[] args) {

View File

@ -17,7 +17,6 @@ public class AAMarketTasks {
// 分销延时发放
//每天0时0分0秒 执行
@Scheduled(fixedRate = 30000)
public void distributionTask() {
distributionTask.deliver();

View File

@ -18,12 +18,17 @@ import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderInfoService;
import com.czg.service.market.enums.OrderStatusEnums;
import com.czg.utils.FunUtils;
import com.itextpdf.styledxmlparser.jsoup.helper.DataUtil;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.time.LocalDateTime;
/**
* 分销定时任务
*
@ -44,15 +49,22 @@ public class DistributionTask {
private OrderInfoService orderInfoService;
@DubboReference
private ShopInfoService shopInfoService;
@DubboReference
private ShopUserService shopUserService;
/**
* 生日有礼奖励发放
* AAMarketTasks 统一调用位置
*/
// @Scheduled(cron = "0 0 0 * * ?")
@Scheduled(fixedRate = 30000)
public void deliver() {
distributionFlowService.list(new QueryWrapper().ge(MkDistributionFlow::getDeliverTime, DateUtil.date())
LocalDateTime localDateTime = DateUtil.date().toLocalDateTime();
distributionFlowService.list(new QueryWrapper()
.eq(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.PENDING.getCode())).forEach(item -> {
if (item.getDeliverTime() != null && item.getDeliverTime().isAfter(localDateTime)) {
return;
}
FunUtils.safeRunVoid(() -> {
log.info("开始处理延时分账, id: {}, orderNo: {}, 类型: {}", item.getId(), item.getOrderNo(), item.getType());
@ -64,9 +76,12 @@ public class DistributionTask {
if (CollUtil.newArrayList(OrderStatusEnums.REFUND.getCode(), OrderStatusEnums.REFUNDING.getCode(), OrderStatusEnums.PART_REFUND.getCode()).contains(orderInfo.getStatus())) {
log.warn("订单已退款, 订单号: {}", item.getOrderNo());
item.setStatus(TableValueConstant.DistributionFlow.Status.REFUND.getCode());
}else {
} else {
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
distributionUserService.updateShopInfoAmount(orderInfo.getShopId(), item.getRewardAmount(), orderInfo.getId());
ShopUser shopUser = shopUserService.getById(item.getDistributionUserId());
distributionUserService.updateIncome(item.getRewardAmount().negate(), item.getRewardAmount(), BigDecimal.ZERO,
item.getDistributionUserId(), shopUser.getUserId(), item.getShopId(), item.getLevel());
distributionUserService.updateShopInfoAmount(orderInfo.getShopId(), item.getRewardAmount().negate(), orderInfo.getId(), TableValueConstant.DistributionAmountFlow.Type.SUB, "分销扣减");
}
distributionFlowService.updateById(item);
});

View File

@ -113,4 +113,5 @@ public class MkDistributionFlow implements Serializable {
private BigDecimal commission;
private BigDecimal parentCommission;
private LocalDateTime deliverTime;
private Long userId;
}

View File

@ -1,6 +1,7 @@
package com.czg.market.service;
import com.czg.account.entity.UserInfo;
import com.czg.constant.TableValueConstant;
import com.czg.market.dto.MkDistributionUserDTO;
import com.czg.market.dto.MkDistributionWithdrawFlowDTO;
import com.czg.market.entity.MkDistributionUser;
@ -113,7 +114,9 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
*/
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);
/**
* 发放分销奖励

View File

@ -45,6 +45,7 @@ public interface TableValueConstant {
@Getter
enum Type {
MANUAL_RECHARGE("manual_recharge", "手动充值"),
REFUND("refund", "退款"),
SUB("sub", "系统扣减"),
OPEN("open", "分销员购买"),
MANUAL_SUB("manual_sub", "手动扣减"),

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();
}