Compare commits

9 Commits

Author SHA1 Message Date
xm
49ce3c40e5 1 2026-06-10 15:07:57 +08:00
xm
97db34f141 1、拆分门店、服务商角色及调整对应订单计算算法
2、推荐人关系列表增加删除标记,方便后期数据硕源
2026-06-05 17:31:19 +08:00
xm
48ae0ddfe6 优化分红金额计算业务 2026-06-02 15:11:00 +08:00
xm
5b3506fa00 商品增加分享图业务 2026-06-01 17:05:28 +08:00
xm
471927ccfc 商品订单增加配送时间业务 2026-06-01 11:34:04 +08:00
xm
2f1c95401f 优化商品股东分红批量更新业务 2026-05-30 17:28:53 +08:00
xm
3a874e84f5 Merge branch 'glt_xm' into dev_xm
# Conflicts:
#	src/main/java/com/gxwebsoft/shop/service/impl/ShopFlashSaleActivityServiceImpl.java
#	src/main/java/com/gxwebsoft/shop/vo/ShopFlashSaleActivityVO.java
2026-05-30 15:46:26 +08:00
xm
e511df0f8b 优化秒杀活动用户下单能力业务 2026-05-30 14:46:44 +08:00
xm
dd889dd7a2 1、增加股东/合伙人分红功能
2、优化原有订单分销算法,去掉原有股东分红制
3、优化收益明细查询业务
4、优化订单分佣解冻业务
2026-05-30 10:55:32 +08:00
29 changed files with 642 additions and 346 deletions

View File

@@ -103,7 +103,8 @@ public class MybatisPlusConfig {
"shop_dealer_user", "shop_dealer_user",
"shop_dealer_order", "shop_dealer_order",
"shop_dealer_referee", "shop_dealer_referee",
"shop_store_rider" "shop_store_rider",
"shop_goods_profit"
).contains(tableName); ).contains(tableName);
} }
}; };

View File

@@ -143,7 +143,8 @@ public class GltTicketIssueService {
//2.执行分销员分销、统计门店/服务商分销业务 //2.执行分销员分销、统计门店/服务商分销业务
dealerOrderSettlement.orderSettlement(orderNo); dealerOrderSettlement.orderSettlement(orderNo);
//3.执行平台分红业务 TODO 待开发 //3.执行平台分红业务
dealerOrderSettlement.partnerProfit(orderNo, tenantId);
//4.普通商品【非水票订单】如果是需要自配送的,则会同步生成派单信息 //4.普通商品【非水票订单】如果是需要自配送的,则会同步生成派单信息
gltTicketOrderService.dispatchOrder(orderNo, tenantId); gltTicketOrderService.dispatchOrder(orderNo, tenantId);

View File

@@ -8,8 +8,12 @@ import com.gxwebsoft.common.core.enums.ShopDealerCapitalUpdateEnum;
import com.gxwebsoft.common.core.enums.ShopDealerTypeEnum; import com.gxwebsoft.common.core.enums.ShopDealerTypeEnum;
import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.mapper.UserMapper; import com.gxwebsoft.common.system.mapper.UserMapper;
import com.gxwebsoft.common.system.redis.OrderNoUtils;
import com.gxwebsoft.glt.entity.GltTicketTemplate; import com.gxwebsoft.glt.entity.GltTicketTemplate;
import com.gxwebsoft.glt.service.GltTicketTemplateService; import com.gxwebsoft.glt.service.GltTicketTemplateService;
import com.gxwebsoft.glt.vo.UserRelationVO;
import com.gxwebsoft.shop.dto.ShopDealerSettlementDto;
import com.gxwebsoft.shop.dto.ShopDealerSettlementItemDto;
import com.gxwebsoft.shop.dto.ShopDealerUserReduceDto; import com.gxwebsoft.shop.dto.ShopDealerUserReduceDto;
import com.gxwebsoft.shop.entity.*; import com.gxwebsoft.shop.entity.*;
import com.gxwebsoft.shop.mapper.ShopDealerRefereeMapper; import com.gxwebsoft.shop.mapper.ShopDealerRefereeMapper;
@@ -17,6 +21,7 @@ import com.gxwebsoft.shop.mapper.ShopOrderMapper;
import com.gxwebsoft.shop.service.*; import com.gxwebsoft.shop.service.*;
import com.gxwebsoft.shop.util.UpstreamUserFinder; import com.gxwebsoft.shop.util.UpstreamUserFinder;
import com.gxwebsoft.shop.vo.ShopDealerRefereeVO; import com.gxwebsoft.shop.vo.ShopDealerRefereeVO;
import com.gxwebsoft.shop.vo.ShopGoodsProfitVO;
import com.gxwebsoft.shop.vo.ShopOrderGoodsVO; import com.gxwebsoft.shop.vo.ShopOrderGoodsVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
@@ -33,6 +38,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
/** /**
* 租户10584分销订单结算任务 * 租户10584分销订单结算任务
@@ -94,6 +100,12 @@ public class DealerOrderSettlement10584Task {
@Resource @Resource
private ShopDealerRefereeMapper shopDealerRefereeMapper; private ShopDealerRefereeMapper shopDealerRefereeMapper;
@Resource
private ShopGoodsProfitService shopGoodsProfitService;
@Resource
private OrderNoUtils orderNoUtils;
/** /**
* 每10秒执行一次。 * 每10秒执行一次。
*/ */
@@ -191,7 +203,7 @@ public class DealerOrderSettlement10584Task {
if (!claimOrderToSettle(order.getOrderId(), waterFormIds)) { if (!claimOrderToSettle(order.getOrderId(), waterFormIds)) {
return; return;
} }
settleOneOrderV2(order, level1ParentCache, shopRoleCache, totalDealerUser, dealerBasicSetting.level); settleOneOrderV2(order, dealerBasicSetting.level);
}); });
} catch (Exception e) { } catch (Exception e) {
log.error("订单结算失败,将回滚本订单并在下次任务重试 - orderId={}, orderNo={}", order.getOrderId(), order.getOrderNo(), e); log.error("订单结算失败,将回滚本订单并在下次任务重试 - orderId={}, orderNo={}", order.getOrderId(), order.getOrderNo(), e);
@@ -225,11 +237,73 @@ public class DealerOrderSettlement10584Task {
if (!claimOrderToSettleV2(order.getOrderId())) { if (!claimOrderToSettleV2(order.getOrderId())) {
return; return;
} }
settleOneOrderV2(order, level1ParentCache, shopRoleCache, totalDealerUser, dealerBasicSetting.level); settleOneOrderV2(order, dealerBasicSetting.level);
}); });
} }
} }
/**
* 股东/合伙人分红
* @param orderNo 订单号
* @return
*/
@Transactional
public Boolean partnerProfit(String orderNo, Integer tenantId){
//1.查询订单信息
ShopOrder shopOrder = shopOrderService.getByOrderNo(orderNo, tenantId);
if(shopOrder != null){
//2.查询订单号订单所有已开启分销的商品分润信息
List<ShopOrderGoodsVO> orderGoodsVOList = shopOrderMapper.getOrderGoodsInfo(orderNo);
if(CollectionUtils.isNotEmpty(orderGoodsVOList)){
//3.计算商品实付比例
BigDecimal rate = shopOrder.getPayPrice().divide(shopOrder.getTotalPrice(), 2, RoundingMode.HALF_UP);
//4.查询商品分红设定比例数据
List<Integer> goodsIdList = orderGoodsVOList.stream().map(ShopOrderGoodsVO::getGoodsId).distinct().collect(Collectors.toList());
List<ShopGoodsProfitVO> goodsProfitVOList = shopGoodsProfitService.getGoodsProfit(goodsIdList, 1);
if(CollectionUtils.isNotEmpty(goodsProfitVOList)){
List<ShopDealerSettlementItemDto> itemList = new ArrayList<>();
//5.按照商品分组分润信息
Map<Integer, List<ShopGoodsProfitVO>> goodsProfitMap = goodsProfitVOList.stream().collect(Collectors.groupingBy(ShopGoodsProfitVO::getGoodsId));
//6.遍历商品获取分红子项数据
orderGoodsVOList.forEach(orderGoodsVO ->{
List<ShopGoodsProfitVO> profitVOS = goodsProfitMap.get(orderGoodsVO.getGoodsId());
if(CollectionUtils.isNotEmpty(profitVOS)){
BigDecimal itemPrice = orderGoodsVO.getPrice().multiply(BigDecimal.valueOf(orderGoodsVO.getTotalNum()));
BigDecimal itemProfitPrice = itemPrice.multiply(rate).setScale(3, RoundingMode.HALF_UP);
profitVOS.forEach(profitVO ->{
ShopDealerSettlementItemDto itemDto = new ShopDealerSettlementItemDto();
String no = orderNoUtils.generate("C");
BigDecimal money = profitVO.getProfit().divide(BigDecimal.valueOf(100)).multiply(itemProfitPrice).setScale(3, RoundingMode.HALF_UP);
itemDto.setNo(no);
itemDto.setUserId(profitVO.getUserId());
itemDto.setMoney(money);
itemList.add(itemDto);
});
}
});
//7.存在分红子项数据,则批量结算
if(CollectionUtils.isNotEmpty(itemList)){
ShopDealerSettlementDto settlementDto = new ShopDealerSettlementDto();
settlementDto.setOrderNo(orderNo);
settlementDto.setToUserId(shopOrder.getUserId());
settlementDto.setTenantId(tenantId);
settlementDto.setItemList(itemList);
shopDealerUserService.orderProfit(settlementDto);
}
}
}
}
return Boolean.TRUE;
}
private List<ShopOrder> findUnsettledPaidOrders(Set<Integer> waterFormIds) { private List<ShopOrder> findUnsettledPaidOrders(Set<Integer> waterFormIds) {
// 租户10584约定 // 租户10584约定
// - 普通订单以发货为准deliveryStatus=20才结算 // - 普通订单以发货为准deliveryStatus=20才结算
@@ -355,8 +429,7 @@ public class DealerOrderSettlement10584Task {
log.info("订单结算完成 - orderId={}, orderNo={}, baseAmount={}", order.getOrderId(), order.getOrderNo(), baseAmount); log.info("订单结算完成 - orderId={}, orderNo={}, baseAmount={}", order.getOrderId(), order.getOrderNo(), baseAmount);
} }
private void settleOneOrderV2(ShopOrder order, Map<Integer, Integer> level1ParentCache, Map<Integer, Boolean> shopRoleCache, private void settleOneOrderV2(ShopOrder order, int dealerLevel) {
ShopDealerUser totalDealerUser, int dealerLevel) {
if (order.getUserId() == null || order.getOrderNo() == null) { if (order.getUserId() == null || order.getOrderNo() == null) {
throw new IllegalStateException("订单关键信息缺失,无法结算 - orderId=" + order.getOrderId()); throw new IllegalStateException("订单关键信息缺失,无法结算 - orderId=" + order.getOrderId());
} }
@@ -378,14 +451,10 @@ public class DealerOrderSettlement10584Task {
// 2) 门店分润上级:从下单用户开始逐级向上找,命中 ShopDealerUser.type=1 的最近两级(直推门店/间推门店)【只统计数据,不对分销账户进行处理, // 2) 门店分润上级:从下单用户开始逐级向上找,命中 ShopDealerUser.type=1 的最近两级(直推门店/间推门店)【只统计数据,不对分销账户进行处理,
// 已日结形式统计分销记录表shop_dealer_order 做对应一级二级管理津贴结算】 // 已日结形式统计分销记录表shop_dealer_order 做对应一级二级管理津贴结算】
ShopRoleCommission shopRoleCommission = settleShopRoleRefereeCommissionV2(order, rate, orderGoodsVOList, level1ParentCache, shopRoleCache); ShopRoleCommission shopRoleCommission = settleShopRoleRefereeCommissionV2(order, rate, orderGoodsVOList);
// 3) 分红:固定比率,每个订单都分 TODO 总分红未开发,还按原逻辑走 // 3) 写入分销订单记录(用于排查/统计;详细分佣以 ShopDealerCapital 为准)
int goodsQty = orderGoodsVOList.stream().mapToInt(ShopOrderGoodsVO::getTotalNum).sum(); createDealerOrderRecordV2(order, dealerRefereeCommission, shopRoleCommission);
TotalDealerCommission totalDealerCommission = settleTotalDealerCommissionV2(order, goodsQty, totalDealerUser);
// 4) 写入分销订单记录(用于排查/统计;详细分佣以 ShopDealerCapital 为准)
createDealerOrderRecordV2(order, dealerRefereeCommission, shopRoleCommission, totalDealerCommission);
log.info("订单结算完成 - orderId={}, orderNo={}, baseAmount={}", order.getOrderId(), order.getOrderNo(), payPrice); log.info("订单结算完成 - orderId={}, orderNo={}, baseAmount={}", order.getOrderId(), order.getOrderNo(), payPrice);
}else { }else {
@@ -521,13 +590,13 @@ public class DealerOrderSettlement10584Task {
//一级分销员存在(type = 0)且单项实付金额大于0及商品设置了一级分销比例/金额 //一级分销员存在(type = 0)且单项实付金额大于0及商品设置了一级分销比例/金额
if(finalDirectDealerId != null && itemRatePrice.compareTo(BigDecimal.ZERO) > 0 && firstMoney.compareTo(BigDecimal.ZERO) > 0){ if(finalDirectDealerId != null && itemRatePrice.compareTo(BigDecimal.ZERO) > 0 && firstMoney.compareTo(BigDecimal.ZERO) > 0){
BigDecimal one = calcMoneyByCommissionType(itemRatePrice, firstMoney, orderGoodsVO.getTotalNum(), 2, orderGoodsVO.getCommissionType()); BigDecimal one = calcMoneyByCommissionType(itemRatePrice, firstMoney, orderGoodsVO.getTotalNum(), 3, orderGoodsVO.getCommissionType());
directMoney.accumulateAndGet(one, BigDecimal::add); directMoney.accumulateAndGet(one, BigDecimal::add);
} }
//一级分销员存在(type = 0)且单项实付金额大于0及商品设置了一级分销比例/金额 //一级分销员存在(type = 0)且单项实付金额大于0及商品设置了一级分销比例/金额
if(finalSimpleDealerId != null && itemRatePrice.compareTo(BigDecimal.ZERO) > 0 && secondMoney.compareTo(BigDecimal.ZERO) > 0 ){ if(finalSimpleDealerId != null && itemRatePrice.compareTo(BigDecimal.ZERO) > 0 && secondMoney.compareTo(BigDecimal.ZERO) > 0 ){
BigDecimal two = calcMoneyByCommissionType(itemRatePrice, secondMoney, orderGoodsVO.getTotalNum(), 2, orderGoodsVO.getCommissionType()); BigDecimal two = calcMoneyByCommissionType(itemRatePrice, secondMoney, orderGoodsVO.getTotalNum(), 3, orderGoodsVO.getCommissionType());
simpleMoney.accumulateAndGet(two, BigDecimal::add); simpleMoney.accumulateAndGet(two, BigDecimal::add);
} }
}); });
@@ -643,28 +712,18 @@ public class DealerOrderSettlement10584Task {
return new ShopRoleCommission(shopRoleReferees.get(0), storeDirectMoney, shopRoleReferees.get(1), storeSimpleMoney); return new ShopRoleCommission(shopRoleReferees.get(0), storeDirectMoney, shopRoleReferees.get(1), storeSimpleMoney);
} }
private ShopRoleCommission settleShopRoleRefereeCommissionV2(ShopOrder order, BigDecimal rate, List<ShopOrderGoodsVO> orderGoodsVOList, Map<Integer, Integer> level1ParentCache, Map<Integer, Boolean> shopRoleCache) { private ShopRoleCommission settleShopRoleRefereeCommissionV2(ShopOrder order, BigDecimal rate, List<ShopOrderGoodsVO> orderGoodsVOList) {
List<Integer> shopRoleReferees = findFirstTwoShopRoleReferees(order.getUserId(), level1ParentCache, shopRoleCache); UserRelationVO userSuperior = shopDealerUserService.getUserSuperior(order.getUserId());
log.info("门店分润命中结果(type=1门店角色取前两级) - orderNo={}, buyerUserId={}, shopRoleReferees={}", Integer storeDirectUserId = userSuperior.getStoreUserId();
order.getOrderNo(), order.getUserId(), shopRoleReferees); Integer storeSimpleUserId = userSuperior.getServiceUserId();
if (shopRoleReferees.isEmpty()) {
if(storeDirectUserId == null && storeSimpleUserId == null){
return ShopRoleCommission.empty(); return ShopRoleCommission.empty();
} }
if(CollectionUtils.isNotEmpty(shopRoleReferees)){
Integer storeDirectUserId;
Integer storeSimpleUserId = null;
AtomicReference<BigDecimal> storeDirectMoney = new AtomicReference<>(BigDecimal.ZERO); AtomicReference<BigDecimal> storeDirectMoney = new AtomicReference<>(BigDecimal.ZERO);
AtomicReference<BigDecimal> storeSimpleMoney = new AtomicReference<>(BigDecimal.ZERO); AtomicReference<BigDecimal> storeSimpleMoney = new AtomicReference<>(BigDecimal.ZERO);
if(shopRoleReferees.size() == 1){
storeDirectUserId = shopRoleReferees.get(0);
}else {
storeDirectUserId = shopRoleReferees.get(0);
storeSimpleUserId = shopRoleReferees.get(1);
}
Integer finalStoreDirectUserId = storeDirectUserId; Integer finalStoreDirectUserId = storeDirectUserId;
Integer finalStoreSimpleUserId = storeSimpleUserId; Integer finalStoreSimpleUserId = storeSimpleUserId;
orderGoodsVOList.forEach(orderGoodsVO ->{ orderGoodsVOList.forEach(orderGoodsVO ->{
@@ -676,19 +735,16 @@ public class DealerOrderSettlement10584Task {
BigDecimal itemRatePrice = orderGoodsVO.getPrice().multiply(BigDecimal.valueOf(orderGoodsVO.getTotalNum())).multiply(rate); BigDecimal itemRatePrice = orderGoodsVO.getPrice().multiply(BigDecimal.valueOf(orderGoodsVO.getTotalNum())).multiply(rate);
if(finalStoreDirectUserId != null && itemRatePrice.compareTo(BigDecimal.ZERO) > 0){ if(finalStoreDirectUserId != null && itemRatePrice.compareTo(BigDecimal.ZERO) > 0){
BigDecimal one = calcMoneyByCommissionType(itemRatePrice, firstMoney, orderGoodsVO.getTotalNum(), 2, orderGoodsVO.getCommissionType()); BigDecimal one = calcMoneyByCommissionType(itemRatePrice, firstMoney, orderGoodsVO.getTotalNum(), 3, orderGoodsVO.getCommissionType());
storeDirectMoney.accumulateAndGet(one, BigDecimal::add); storeDirectMoney.accumulateAndGet(one, BigDecimal::add);
} }
if(finalStoreSimpleUserId != null && itemRatePrice.compareTo(BigDecimal.ZERO) > 0){ if(finalStoreSimpleUserId != null && itemRatePrice.compareTo(BigDecimal.ZERO) > 0){
BigDecimal two = calcMoneyByCommissionType(itemRatePrice, secondMoney, orderGoodsVO.getTotalNum(), 2, orderGoodsVO.getCommissionType()); BigDecimal two = calcMoneyByCommissionType(itemRatePrice, secondMoney, orderGoodsVO.getTotalNum(), 3, orderGoodsVO.getCommissionType());
storeSimpleMoney.accumulateAndGet(two, BigDecimal::add); storeSimpleMoney.accumulateAndGet(two, BigDecimal::add);
} }
}); });
return new ShopRoleCommission(storeDirectUserId, storeDirectMoney.get(), storeSimpleUserId, storeSimpleMoney.get()); return new ShopRoleCommission(storeDirectUserId, storeDirectMoney.get(), storeSimpleUserId, storeSimpleMoney.get());
}else {
return null;
}
} }
private TotalDealerCommission settleTotalDealerCommission( private TotalDealerCommission settleTotalDealerCommission(
@@ -1067,7 +1123,7 @@ public class DealerOrderSettlement10584Task {
* @param dealerRefereeCommission 一级、二级分销员分销数据 * @param dealerRefereeCommission 一级、二级分销员分销数据
* @param shopRoleCommission 门店/服务商一级、二级管理津贴数据 * @param shopRoleCommission 门店/服务商一级、二级管理津贴数据
*/ */
private void createDealerOrderRecordV2(ShopOrder order, DealerRefereeCommissionV2 dealerRefereeCommission, ShopRoleCommission shopRoleCommission, TotalDealerCommission totalDealerCommission) { private void createDealerOrderRecordV2(ShopOrder order, DealerRefereeCommissionV2 dealerRefereeCommission, ShopRoleCommission shopRoleCommission) {
// 幂等:同一订单只写一条(依赖 order_no + tenant_id 作为业务唯一) // 幂等:同一订单只写一条(依赖 order_no + tenant_id 作为业务唯一)
ShopDealerOrder existed = shopDealerOrderService.getOne( ShopDealerOrder existed = shopDealerOrderService.getOne(
new LambdaQueryWrapper<ShopDealerOrder>() new LambdaQueryWrapper<ShopDealerOrder>()
@@ -1141,7 +1197,7 @@ public class DealerOrderSettlement10584Task {
dealerOrder.setSettleTime(LocalDateTime.now()); dealerOrder.setSettleTime(LocalDateTime.now());
dealerOrder.setMonth(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM"))); dealerOrder.setMonth(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM")));
dealerOrder.setTenantId(TENANT_ID); dealerOrder.setTenantId(TENANT_ID);
dealerOrder.setComments(buildCommissionTraceCommentV2(dealerRefereeCommission, shopRoleCommission, totalDealerCommission)); dealerOrder.setComments(buildCommissionTraceCommentV2(dealerRefereeCommission, shopRoleCommission));
shopDealerOrderService.save(dealerOrder); shopDealerOrderService.save(dealerOrder);
} }
@@ -1163,8 +1219,7 @@ public class DealerOrderSettlement10584Task {
private String buildCommissionTraceCommentV2( private String buildCommissionTraceCommentV2(
DealerRefereeCommissionV2 dealerRefereeCommission, DealerRefereeCommissionV2 dealerRefereeCommission,
ShopRoleCommission shopRoleCommission, ShopRoleCommission shopRoleCommission
TotalDealerCommission totalDealerCommission
) { ) {
// 轻量“过程”留痕,方便排查;详细分佣以 ShopDealerCapital 为准。 // 轻量“过程”留痕,方便排查;详细分佣以 ShopDealerCapital 为准。
Integer direct = dealerRefereeCommission != null ? dealerRefereeCommission.directDealerId : null; Integer direct = dealerRefereeCommission != null ? dealerRefereeCommission.directDealerId : null;
@@ -1175,14 +1230,11 @@ public class DealerOrderSettlement10584Task {
BigDecimal storeDirectMoney = shopRoleCommission != null ? shopRoleCommission.storeDirectMoney : BigDecimal.ZERO; BigDecimal storeDirectMoney = shopRoleCommission != null ? shopRoleCommission.storeDirectMoney : BigDecimal.ZERO;
Integer storeSimpleUserId = shopRoleCommission != null ? shopRoleCommission.storeSimpleUserId : null; Integer storeSimpleUserId = shopRoleCommission != null ? shopRoleCommission.storeSimpleUserId : null;
BigDecimal storeSimpleMoney = shopRoleCommission != null ? shopRoleCommission.storeSimpleMoney : BigDecimal.ZERO; BigDecimal storeSimpleMoney = shopRoleCommission != null ? shopRoleCommission.storeSimpleMoney : BigDecimal.ZERO;
Integer userId = totalDealerCommission != null ? totalDealerCommission.userId : null;
BigDecimal money = totalDealerCommission != null ? totalDealerCommission.money : BigDecimal.ZERO;
return "direct=" + direct + ":" + directMoney return "direct=" + direct + ":" + directMoney
+ ",simple=" + simpleDealerId + ":" + simpleMoney + ",simple=" + simpleDealerId + ":" + simpleMoney
+ ",dividend1=" + storeDirectUserId + ":" + storeDirectMoney + ",dividend1=" + storeDirectUserId + ":" + storeDirectMoney
+ ",dividend2=" + storeSimpleUserId + ":" + storeSimpleMoney + ",dividend2=" + storeSimpleUserId + ":" + storeSimpleMoney;
+ ",totalDealer=" + userId + ":" + money;
} }
private BigDecimal getOrderBaseAmount(ShopOrder order) { private BigDecimal getOrderBaseAmount(ShopOrder order) {

View File

@@ -0,0 +1,16 @@
package com.gxwebsoft.glt.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class UserRelationVO {
@Schema(description = "当前用户ID")
private Integer userId;
@Schema(description = "上级门店ID")
private Integer storeUserId;
@Schema(description = "上级服务商ID")
private Integer serviceUserId;
}

View File

@@ -90,7 +90,7 @@ public class ShopDealerUserController extends BaseController {
@Operation(summary = "修改分销商用户记录表") @Operation(summary = "修改分销商用户记录表")
@PutMapping() @PutMapping()
public ApiResult<?> update(@RequestBody ShopDealerUser shopDealerUser) { public ApiResult<?> update(@RequestBody ShopDealerUser shopDealerUser) {
if (shopDealerUserService.updateById(shopDealerUser)) { if (shopDealerUserService.updateInfo(shopDealerUser)) {
return success("修改成功"); return success("修改成功");
} }
return fail("修改失败"); return fail("修改失败");

View File

@@ -3,13 +3,14 @@ package com.gxwebsoft.shop.controller;
import com.gxwebsoft.common.core.annotation.OperationLog; import com.gxwebsoft.common.core.annotation.OperationLog;
import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.shop.dto.ShopGoodsProfitUpdateDto;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.shop.entity.ShopGoodsProfit;
import com.gxwebsoft.shop.param.ShopGoodsProfitParam;
import com.gxwebsoft.shop.service.ShopGoodsProfitService; import com.gxwebsoft.shop.service.ShopGoodsProfitService;
import com.gxwebsoft.shop.vo.ShopGoodsProfitVO;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
@@ -29,65 +30,22 @@ public class ShopGoodsProfitController extends BaseController {
private ShopGoodsProfitService shopGoodsProfitService; private ShopGoodsProfitService shopGoodsProfitService;
// @PreAuthorize("hasAuthority('shop:shopGoodsProfit:list')") // @PreAuthorize("hasAuthority('shop:shopGoodsProfit:list')")
@Operation(summary = "分页查询商品分润设定") @Operation(summary = "通过商品、类型查询分润信息")
@GetMapping("/page") @GetMapping("/getByGoodsId")
public ApiResult<PageResult<ShopGoodsProfit>> page(ShopGoodsProfitParam param) { @Parameters({
// 使用关联查询 @Parameter(name = "goodsId", description = "商品ID", required = true, example = "10086"),
return success(shopGoodsProfitService.pageRel(param)); @Parameter(name = "type", description = "类型 1-分红 2-其他", required = true, example = "1")
} })
public ApiResult<List<ShopGoodsProfitVO>> getByGoodsId(@RequestParam("goodsId") Integer goodsId, @Param("type") Integer type) {
// @PreAuthorize("hasAuthority('shop:shopGoodsProfit:list')") return success(shopGoodsProfitService.getByGoodsId(goodsId, type));
@Operation(summary = "查询全部商品分润设定")
@GetMapping()
public ApiResult<List<ShopGoodsProfit>> list(ShopGoodsProfitParam param) {
// 使用关联查询
return success(shopGoodsProfitService.listRel(param));
}
// @PreAuthorize("hasAuthority('shop:shopGoodsProfit:list')")
@Operation(summary = "根据id查询商品分润设定")
@GetMapping("/{id}")
public ApiResult<ShopGoodsProfit> get(@PathVariable("id") Integer id) {
// 使用关联查询
return success(shopGoodsProfitService.getByIdRel(id));
}
// @PreAuthorize("hasAuthority('shop:shopGoodsProfit:save')")
@OperationLog
@Operation(summary = "添加商品分润设定")
@PostMapping()
public ApiResult<?> save(@RequestBody ShopGoodsProfit shopGoodsProfit) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
shopGoodsProfit.setUserId(loginUser.getUserId());
}
if (shopGoodsProfitService.save(shopGoodsProfit)) {
return success("添加成功");
}
return fail("添加失败");
} }
// @PreAuthorize("hasAuthority('shop:shopGoodsProfit:update')") // @PreAuthorize("hasAuthority('shop:shopGoodsProfit:update')")
@OperationLog @OperationLog
@Operation(summary = "修改商品分润设定") @Operation(summary = "根据商品ID修改商品分润设定")
@PutMapping() @PutMapping("/updateByGoodsId")
public ApiResult<?> update(@RequestBody ShopGoodsProfit shopGoodsProfit) { public ApiResult<Boolean> update(@RequestBody ShopGoodsProfitUpdateDto updateDto) {
if (shopGoodsProfitService.updateById(shopGoodsProfit)) { return success(shopGoodsProfitService.updateByGoodsId(updateDto));
return success("修改成功");
}
return fail("修改失败");
}
// @PreAuthorize("hasAuthority('shop:shopGoodsProfit:remove')")
@OperationLog
@Operation(summary = "删除商品分润设定")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (shopGoodsProfitService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
} }
} }

View File

@@ -1001,6 +1001,13 @@ public class ShopOrderController extends BaseController {
return success(Boolean.TRUE); return success(Boolean.TRUE);
} }
@Operation(summary = "分红结算", description = "分红结算")
@PutMapping("/partnerProfit")
public ApiResult<Boolean> partnerProfit(@RequestBody PaySuccessTaskDto taskDto){
dealerOrderSettlement.partnerProfit(taskDto.getOrderNo(), taskDto.getTenantId());
return success(Boolean.TRUE);
}
@Operation(summary = "更新订单支付状态", description = "用户支付成功后主动同步订单状态") @Operation(summary = "更新订单支付状态", description = "用户支付成功后主动同步订单状态")
@PutMapping("/payment-status") @PutMapping("/payment-status")
public ApiResult<?> updateOrderPaymentStatus(@RequestBody UpdatePaymentStatusRequest request) { public ApiResult<?> updateOrderPaymentStatus(@RequestBody UpdatePaymentStatusRequest request) {

View File

@@ -31,7 +31,7 @@
@Resource @Resource
private ShopUserAddressService shopUserAddressService; private ShopUserAddressService shopUserAddressService;
@PreAuthorize("hasAuthority('shop:shopUserAddress:list')") // @PreAuthorize("hasAuthority('shop:shopUserAddress:list')")
@Operation(summary = "分页查询收货地址") @Operation(summary = "分页查询收货地址")
@GetMapping("/page") @GetMapping("/page")
public ApiResult<PageResult<ShopUserAddress>> page(ShopUserAddressParam param) { public ApiResult<PageResult<ShopUserAddress>> page(ShopUserAddressParam param) {
@@ -39,7 +39,7 @@
return success(shopUserAddressService.pageRel(param)); return success(shopUserAddressService.pageRel(param));
} }
@PreAuthorize("hasAuthority('shop:shopUserAddress:list')") // @PreAuthorize("hasAuthority('shop:shopUserAddress:list')")
@Operation(summary = "查询全部收货地址") @Operation(summary = "查询全部收货地址")
@GetMapping() @GetMapping()
public ApiResult<List<ShopUserAddress>> list(ShopUserAddressParam param) { public ApiResult<List<ShopUserAddress>> list(ShopUserAddressParam param) {
@@ -48,7 +48,7 @@
return success(shopUserAddressService.listRel(param)); return success(shopUserAddressService.listRel(param));
} }
@PreAuthorize("hasAuthority('shop:shopUserAddress:list')") // @PreAuthorize("hasAuthority('shop:shopUserAddress:list')")
@Operation(summary = "根据id查询收货地址") @Operation(summary = "根据id查询收货地址")
@GetMapping("/{id}") @GetMapping("/{id}")
public ApiResult<ShopUserAddress> get(@PathVariable("id") Integer id) { public ApiResult<ShopUserAddress> get(@PathVariable("id") Integer id) {
@@ -56,7 +56,7 @@
return success(shopUserAddressService.getByIdRel(id)); return success(shopUserAddressService.getByIdRel(id));
} }
@PreAuthorize("hasAuthority('shop:shopUserAddress:save')") // @PreAuthorize("hasAuthority('shop:shopUserAddress:save')")
@OperationLog @OperationLog
@Operation(summary = "添加收货地址") @Operation(summary = "添加收货地址")
@PostMapping() @PostMapping()
@@ -75,7 +75,7 @@
return fail("添加失败"); return fail("添加失败");
} }
@PreAuthorize("hasAuthority('shop:shopUserAddress:update')") // @PreAuthorize("hasAuthority('shop:shopUserAddress:update')")
@OperationLog @OperationLog
@Operation(summary = "修改收货地址") @Operation(summary = "修改收货地址")
@PutMapping() @PutMapping()
@@ -83,7 +83,7 @@
return success(shopUserAddressService.updateInfo(shopUserAddress)); return success(shopUserAddressService.updateInfo(shopUserAddress));
} }
@PreAuthorize("hasAuthority('shop:shopUserAddress:remove')") // @PreAuthorize("hasAuthority('shop:shopUserAddress:remove')")
@OperationLog @OperationLog
@Operation(summary = "删除收货地址") @Operation(summary = "删除收货地址")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")

View File

@@ -6,6 +6,7 @@ import lombok.Data;
import javax.validation.Valid; import javax.validation.Valid;
import javax.validation.constraints.*; import javax.validation.constraints.*;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@@ -159,6 +160,9 @@ public class OrderCreateRequest {
@Schema(description = "秒杀活动ID") @Schema(description = "秒杀活动ID")
private Integer activityId; private Integer activityId;
@Schema(description = "配送时间")
private LocalDateTime sendTime;
@Schema(description = "订单商品列表") @Schema(description = "订单商品列表")
@Valid @Valid
@NotEmpty(message = "订单商品列表不能为空") @NotEmpty(message = "订单商品列表不能为空")
@@ -173,14 +177,14 @@ public class OrderCreateRequest {
@Schema(description = "秒杀活动ID") @Schema(description = "秒杀活动ID")
private Integer activityId; private Integer activityId;
@Schema(description = "商品ID", required = true) @Schema(description = "商品ID")
@NotNull(message = "商品ID不能为空") @NotNull(message = "商品ID不能为空")
private Integer goodsId; private Integer goodsId;
@Schema(description = "商品SKU ID") @Schema(description = "商品SKU ID")
private Integer skuId; private Integer skuId;
@Schema(description = "商品数量", required = true) @Schema(description = "商品数量")
@NotNull(message = "商品数量不能为空") @NotNull(message = "商品数量不能为空")
@Min(value = 1, message = "商品数量必须大于0") @Min(value = 1, message = "商品数量必须大于0")
private Integer quantity; private Integer quantity;

View File

@@ -20,9 +20,15 @@ public class ShopDealerSettlementDto {
@Schema(description = "资金流动类型 (10分销收入 11团队管理津贴收入 12分红收入 13现场推广收入 20提现支出 30转账支出 40转账收入 50佣金解冻 60配送奖励 70佣金退回【退单】)") @Schema(description = "资金流动类型 (10分销收入 11团队管理津贴收入 12分红收入 13现场推广收入 20提现支出 30转账支出 40转账收入 50佣金解冻 60配送奖励 70佣金退回【退单】)")
private Integer flowType; private Integer flowType;
@Schema(description = "订单号")
private String orderNo;
@Schema(description = "描述") @Schema(description = "描述")
private String comments; private String comments;
@Schema(description = "分销来源")
private Integer toUserId;
@Schema(description = "商城ID") @Schema(description = "商城ID")
private Integer tenantId; private Integer tenantId;

View File

@@ -0,0 +1,29 @@
package com.gxwebsoft.shop.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.NotEmpty;
import java.util.List;
/**
* 商品分润设定更新
*
* @author xm
* @since 2026-05-20 14:33:00
*/
@Data
public class ShopGoodsProfitUpdateDto {
@Schema(description = "商品ID")
@NotEmpty(message = "商品ID不能为空")
private Integer goodsId;
@Schema(description = "分润类型 1-股东分红 2-其他")
@NotEmpty(message = "分润类型不能为空!")
private Integer type;
@Schema(description = "变更明细")
private List<ShopGoodsProfitUpdateItemDto> itemList;
}

View File

@@ -0,0 +1,26 @@
package com.gxwebsoft.shop.dto;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
/**
* 商品分润设定更新
*
* @author xm
* @since 2026-05-20 14:33:00
*/
@Data
public class ShopGoodsProfitUpdateItemDto {
@Schema(description = "用户ID")
private Integer userId;
@Schema(description = "分佣比例 百分比")
private BigDecimal profit;
@Schema(description = "开启状态 0-未开启 1-开启")
private Integer status;
}

View File

@@ -1,11 +1,10 @@
package com.gxwebsoft.shop.entity; package com.gxwebsoft.shop.entity;
import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serializable; import java.io.Serializable;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
@@ -21,6 +20,7 @@ import lombok.EqualsAndHashCode;
@Data @Data
@EqualsAndHashCode(callSuper = false) @EqualsAndHashCode(callSuper = false)
@Schema(name = "ShopDealerReferee对象", description = "分销商推荐关系表") @Schema(name = "ShopDealerReferee对象", description = "分销商推荐关系表")
@TableName("shop_dealer_referee")
public class ShopDealerReferee implements Serializable { public class ShopDealerReferee implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@@ -69,6 +69,10 @@ public class ShopDealerReferee implements Serializable {
@Schema(description = "推荐关系层级(弃用)") @Schema(description = "推荐关系层级(弃用)")
private Integer level; private Integer level;
@Schema(description = "是否删除 0-未删 1-已删")
@TableLogic
private Integer deleted;
@Schema(description = "来源(如 goods_share)") @Schema(description = "来源(如 goods_share)")
// NOTE: 表 shop_dealer_referee 若未新增该字段,需要 exist=false避免 MyBatis-Plus 自动生成SQL时报 Unknown column。 // NOTE: 表 shop_dealer_referee 若未新增该字段,需要 exist=false避免 MyBatis-Plus 自动生成SQL时报 Unknown column。
@TableField(exist = false) @TableField(exist = false)

View File

@@ -29,7 +29,7 @@ public class ShopDealerUser implements Serializable {
@TableId(value = "id", type = IdType.AUTO) @TableId(value = "id", type = IdType.AUTO)
private Integer id; private Integer id;
@Schema(description = "0经销商,1企业也,2集团)") @Schema(description = "0-分销员 1-门店 2-服务商 3-合伙人")
private Integer type; private Integer type;
@Schema(description = "自增ID") @Schema(description = "自增ID")

View File

@@ -200,6 +200,9 @@ public class ShopGoods implements Serializable {
@Schema(description = "配送楼层步梯费(元)") @Schema(description = "配送楼层步梯费(元)")
private BigDecimal deliveryFee; private BigDecimal deliveryFee;
@Schema(description = "分享图")
private String shareImg;
@Schema(description = "租户id") @Schema(description = "租户id")
private Integer tenantId; private Integer tenantId;

View File

@@ -363,6 +363,9 @@ public class ShopOrder implements Serializable {
@Schema(description = "配送费(步梯配送特有)") @Schema(description = "配送费(步梯配送特有)")
private BigDecimal deliveryFee; private BigDecimal deliveryFee;
@Schema(description = "配送时间")
private LocalDateTime sendTime;
@Schema(description = "修改时间") @Schema(description = "修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime; private LocalDateTime updateTime;

View File

@@ -1,12 +1,7 @@
package com.gxwebsoft.shop.mapper; package com.gxwebsoft.shop.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.shop.entity.ShopGoodsProfit; import com.gxwebsoft.shop.entity.ShopGoodsProfit;
import com.gxwebsoft.shop.param.ShopGoodsProfitParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/** /**
* 商品分润设定Mapper * 商品分润设定Mapper
@@ -16,22 +11,4 @@ import java.util.List;
*/ */
public interface ShopGoodsProfitMapper extends BaseMapper<ShopGoodsProfit> { public interface ShopGoodsProfitMapper extends BaseMapper<ShopGoodsProfit> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<ShopGoodsProfit>
*/
List<ShopGoodsProfit> selectPageRel(@Param("page") IPage<ShopGoodsProfit> page,
@Param("param") ShopGoodsProfitParam param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<ShopGoodsProfit> selectListRel(@Param("param") ShopGoodsProfitParam param);
} }

View File

@@ -11,6 +11,7 @@
LEFT JOIN gxwebsoft_core.sys_user d ON a.to_user_id = d.user_id and d.deleted = 0 LEFT JOIN gxwebsoft_core.sys_user d ON a.to_user_id = d.user_id and d.deleted = 0
LEFT JOIN shop_order e ON a.order_no = e.order_no LEFT JOIN shop_order e ON a.order_no = e.order_no
<where> <where>
a.deleted = 0
<if test="param.id != null"> <if test="param.id != null">
AND a.id = #{param.id} AND a.id = #{param.id}
</if> </if>

View File

@@ -17,6 +17,7 @@
INNER JOIN gxwebsoft_core.sys_user d ON a.dealer_id = d.user_id AND d.deleted = 0 INNER JOIN gxwebsoft_core.sys_user d ON a.dealer_id = d.user_id AND d.deleted = 0
INNER JOIN gxwebsoft_core.sys_user u ON a.user_id = u.user_id AND u.deleted = 0 INNER JOIN gxwebsoft_core.sys_user u ON a.user_id = u.user_id AND u.deleted = 0
<where> <where>
a.deleted = 0
<if test="param.tenantId != null"> <if test="param.tenantId != null">
AND a.tenant_id = #{param.tenantId} AND a.tenant_id = #{param.tenantId}
</if> </if>
@@ -65,12 +66,11 @@
d.type simpleUserType d.type simpleUserType
FROM FROM
shop_dealer_referee a shop_dealer_referee a
LEFT JOIN shop_dealer_user b ON a.dealer_id = b.user_id LEFT JOIN shop_dealer_user b ON a.dealer_id = b.user_id AND b.deleted = 0
LEFT JOIN shop_dealer_referee c ON b.user_id = c.user_id LEFT JOIN shop_dealer_referee c ON b.user_id = c.user_id AND c.deleted = 0
LEFT JOIN shop_dealer_user d ON d.user_id = c.dealer_id LEFT JOIN shop_dealer_user d ON c.dealer_id = d.user_id and d.deleted = 0
WHERE WHERE
b.is_delete = 0 a.deleted = 0
and d.is_delete = 0
AND a.user_id = #{userId} AND a.user_id = #{userId}
</select> </select>

View File

@@ -2,62 +2,4 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gxwebsoft.shop.mapper.ShopGoodsProfitMapper"> <mapper namespace="com.gxwebsoft.shop.mapper.ShopGoodsProfitMapper">
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
FROM shop_goods_profit a
<where>
<if test="param.id != null">
AND a.id = #{param.id}
</if>
<if test="param.type != null">
AND a.type = #{param.type}
</if>
<if test="param.goodsId != null">
AND a.goods_id = #{param.goodsId}
</if>
<if test="param.userId != null">
AND a.user_id = #{param.userId}
</if>
<if test="param.profit != null">
AND a.profit = #{param.profit}
</if>
<if test="param.status != null">
AND a.status = #{param.status}
</if>
<if test="param.creator != null">
AND a.creator = #{param.creator}
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
<if test="param.updater != null">
AND a.updater = #{param.updater}
</if>
<if test="param.deleted != null">
AND a.deleted = #{param.deleted}
</if>
<if test="param.deleted == null">
AND a.deleted = 0
</if>
<if test="param.keywords != null">
AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
)
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.shop.entity.ShopGoodsProfit">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.shop.entity.ShopGoodsProfit">
<include refid="selectSql"></include>
</select>
</mapper> </mapper>

View File

@@ -1,13 +1,7 @@
package com.gxwebsoft.shop.param; package com.gxwebsoft.shop.param;
import java.math.BigDecimal;
import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode;
/** /**
* 商品分润设定查询参数 * 商品分润设定查询参数
@@ -16,46 +10,12 @@ import lombok.EqualsAndHashCode;
* @since 2026-05-20 14:33:00 * @since 2026-05-20 14:33:00
*/ */
@Data @Data
@EqualsAndHashCode(callSuper = false) public class ShopGoodsProfitParam {
@JsonInclude(JsonInclude.Include.NON_NULL)
@Schema(name = "ShopGoodsProfitParam对象", description = "商品分润设定查询参数")
public class ShopGoodsProfitParam extends BaseParam {
private static final long serialVersionUID = 1L;
@Schema(description = "主键ID")
@QueryField(type = QueryType.EQ)
private Integer id;
@Schema(description = "类型 1-股东分红 2-其他") @Schema(description = "类型 1-股东分红 2-其他")
@QueryField(type = QueryType.EQ)
private Integer type; private Integer type;
@Schema(description = "商品ID") @Schema(description = "商品ID")
@QueryField(type = QueryType.EQ)
private Integer goodsId; private Integer goodsId;
@Schema(description = "用户ID")
@QueryField(type = QueryType.EQ)
private Integer userId;
@Schema(description = "分佣比例 百分比")
@QueryField(type = QueryType.EQ)
private BigDecimal profit;
@Schema(description = "开启状态 0-未开启 1-开启")
@QueryField(type = QueryType.EQ)
private Integer status;
@Schema(description = "创建人")
@QueryField(type = QueryType.EQ)
private Integer creator;
@Schema(description = "更新人")
@QueryField(type = QueryType.EQ)
private Integer updater;
@Schema(description = "删除 0-未删 1-已删")
@QueryField(type = QueryType.EQ)
private Integer deleted;
} }

View File

@@ -94,7 +94,9 @@ public class OrderBusinessService {
ShopOrder shopOrder = buildShopOrder(request, loginUser); ShopOrder shopOrder = buildShopOrder(request, loginUser);
//3. 处理收货地址信息 //3. 处理收货地址信息
if(!(shopOrder.getOrderType() != null && shopOrder.getOrderType() == 2)){
processDeliveryAddress(shopOrder, request, loginUser); processDeliveryAddress(shopOrder, request, loginUser);
}
//4. 下单时校验配送范围(电子围栏) //4. 下单时校验配送范围(电子围栏)
validateDeliveryFenceIfNeeded(shopOrder, loginUser); validateDeliveryFenceIfNeeded(shopOrder, loginUser);
@@ -554,7 +556,9 @@ public class OrderBusinessService {
return; return;
} }
// 5. 如果用户没有任何收货地址,抛出异常 // 5. 如果用户没有任何收货地址,抛出异常
if(Arrays.asList(1, 3, 4).contains(shopOrder.getOrderType())){
throw new BusinessException("请先添加收货地址"); throw new BusinessException("请先添加收货地址");
}
} catch (BusinessException e) { } catch (BusinessException e) {
throw e; throw e;

View File

@@ -2,6 +2,7 @@ package com.gxwebsoft.shop.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.glt.vo.UserRelationVO;
import com.gxwebsoft.shop.dto.ShopDealerRefundDto; import com.gxwebsoft.shop.dto.ShopDealerRefundDto;
import com.gxwebsoft.shop.dto.ShopDealerSettlementDto; import com.gxwebsoft.shop.dto.ShopDealerSettlementDto;
import com.gxwebsoft.shop.dto.ShopDealerUserReduceDto; import com.gxwebsoft.shop.dto.ShopDealerUserReduceDto;
@@ -67,6 +68,16 @@ public interface ShopDealerUserService extends IService<ShopDealerUser> {
*/ */
Boolean settlementBatch(ShopDealerSettlementDto dto); Boolean settlementBatch(ShopDealerSettlementDto dto);
/**
* 订单分红变更冻结账户
* @param dto
* @return
*/
Boolean orderProfit(ShopDealerSettlementDto dto);
Boolean updateInfo(ShopDealerUser shopDealerUser);
/** /**
* 开启/关闭分销商用户核销权限 * 开启/关闭分销商用户核销权限
* @param id * @param id
@@ -74,4 +85,11 @@ public interface ShopDealerUserService extends IService<ShopDealerUser> {
*/ */
Boolean verifyEnable(Integer id); Boolean verifyEnable(Integer id);
/**
* 查询用户上级门店、上级服务商
* @param userId
* @return
*/
UserRelationVO getUserSuperior(Integer userId);
} }

View File

@@ -1,9 +1,9 @@
package com.gxwebsoft.shop.service; package com.gxwebsoft.shop.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.shop.dto.ShopGoodsProfitUpdateDto;
import com.gxwebsoft.shop.entity.ShopGoodsProfit; import com.gxwebsoft.shop.entity.ShopGoodsProfit;
import com.gxwebsoft.shop.param.ShopGoodsProfitParam; import com.gxwebsoft.shop.vo.ShopGoodsProfitVO;
import java.util.List; import java.util.List;
@@ -16,27 +16,26 @@ import java.util.List;
public interface ShopGoodsProfitService extends IService<ShopGoodsProfit> { public interface ShopGoodsProfitService extends IService<ShopGoodsProfit> {
/** /**
* 分页关联查询 * 通过商品、类型查询分润信息
* * @param goodsId
* @param param 查询参数 * @param type
* @return PageResult<ShopGoodsProfit> * @return
*/ */
PageResult<ShopGoodsProfit> pageRel(ShopGoodsProfitParam param); List<ShopGoodsProfitVO> getByGoodsId(Integer goodsId, Integer type);
/** /**
* 关联查询全部 * 查询启用状态的商品分润信息
* * @param goodsIdList 商品ID集合
* @param param 查询参数 * @param type 分润类型
* @return List<ShopGoodsProfit> * @return
*/ */
List<ShopGoodsProfit> listRel(ShopGoodsProfitParam param); List<ShopGoodsProfitVO> getGoodsProfit(List<Integer> goodsIdList, Integer type);
/** /**
* 根据id查询 * 根据商品ID修改商品分润设定
* * @param updateDto
* @param id 主键ID * @return
* @return ShopGoodsProfit
*/ */
ShopGoodsProfit getByIdRel(Integer id); Boolean updateByGoodsId(ShopGoodsProfitUpdateDto updateDto);
} }

View File

@@ -47,4 +47,5 @@ public interface ShopOrderGoodsService extends IService<ShopOrderGoods> {
* @return List<ShopOrderGoods> * @return List<ShopOrderGoods>
*/ */
List<ShopOrderGoods> getListByOrderIdIgnoreTenant(Integer orderId); List<ShopOrderGoods> getListByOrderIdIgnoreTenant(Integer orderId);
} }

View File

@@ -14,6 +14,7 @@ import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@@ -38,8 +39,12 @@ public class ShopActiveImageServiceImpl extends ServiceImpl<ShopActiveImageMappe
if(CollectionUtils.isNotEmpty(list)){ if(CollectionUtils.isNotEmpty(list)){
List<Integer> goodsIdList = list.stream().filter(shopActiveImage -> shopActiveImage.getGoodsId() != null).map(ShopActiveImage::getGoodsId) List<Integer> goodsIdList = list.stream().filter(shopActiveImage -> shopActiveImage.getGoodsId() != null).map(ShopActiveImage::getGoodsId)
.distinct().collect(Collectors.toList()); .distinct().collect(Collectors.toList());
List<ShopGoods> shopGoodsList = shopGoodsMapper.selectBatchIds(goodsIdList); List<ShopGoods> shopGoodsList = new ArrayList<>();
if(CollectionUtils.isNotEmpty(goodsIdList)){
shopGoodsList = shopGoodsMapper.selectBatchIds(goodsIdList);
}
List<ShopGoods> finalShopGoodsList = shopGoodsList;
list.forEach(shopActiveImage -> { list.forEach(shopActiveImage -> {
if(!StringUtils.isEmpty(shopActiveImage.getImgUrl())){ if(!StringUtils.isEmpty(shopActiveImage.getImgUrl())){
shopActiveImage.setImgUrlList(Arrays.asList(shopActiveImage.getImgUrl().split(","))); shopActiveImage.setImgUrlList(Arrays.asList(shopActiveImage.getImgUrl().split(",")));
@@ -47,7 +52,7 @@ public class ShopActiveImageServiceImpl extends ServiceImpl<ShopActiveImageMappe
//回显商品名称 //回显商品名称
if(shopActiveImage.getGoodsId() != null){ if(shopActiveImage.getGoodsId() != null){
ShopGoods shopGoods = shopGoodsList.stream().filter(goods -> shopActiveImage.getGoodsId().equals(goods.getGoodsId())).findFirst().orElse(null); ShopGoods shopGoods = finalShopGoodsList.stream().filter(goods -> shopActiveImage.getGoodsId().equals(goods.getGoodsId())).findFirst().orElse(null);
if(shopGoods != null){ if(shopGoods != null){
shopActiveImage.setGoodsName(shopGoods.getName()); shopActiveImage.setGoodsName(shopGoods.getName());
} }

View File

@@ -5,12 +5,15 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.enums.ShopDealerCapitalUpdateEnum; import com.gxwebsoft.common.core.enums.ShopDealerCapitalUpdateEnum;
import com.gxwebsoft.common.core.enums.ShopDealerTypeEnum; import com.gxwebsoft.common.core.enums.ShopDealerTypeEnum;
import com.gxwebsoft.common.core.exception.BusinessException;
import com.gxwebsoft.common.core.exception.enums.GlobalErrorCodeConstants;
import com.gxwebsoft.common.core.utils.LoginUserUtil; import com.gxwebsoft.common.core.utils.LoginUserUtil;
import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.mapper.UserMapper; import com.gxwebsoft.common.system.mapper.UserMapper;
import com.gxwebsoft.common.system.redis.OrderNoUtils; import com.gxwebsoft.common.system.redis.OrderNoUtils;
import com.gxwebsoft.glt.vo.UserRelationVO;
import com.gxwebsoft.shop.dto.ShopDealerRefundDto; import com.gxwebsoft.shop.dto.ShopDealerRefundDto;
import com.gxwebsoft.shop.dto.ShopDealerSettlementDto; import com.gxwebsoft.shop.dto.ShopDealerSettlementDto;
import com.gxwebsoft.shop.dto.ShopDealerSettlementItemDto; import com.gxwebsoft.shop.dto.ShopDealerSettlementItemDto;
@@ -19,11 +22,13 @@ import com.gxwebsoft.shop.entity.ShopDealerCapital;
import com.gxwebsoft.shop.entity.ShopDealerUser; import com.gxwebsoft.shop.entity.ShopDealerUser;
import com.gxwebsoft.shop.entity.ShopOrder; import com.gxwebsoft.shop.entity.ShopOrder;
import com.gxwebsoft.shop.mapper.ShopDealerCapitalMapper; import com.gxwebsoft.shop.mapper.ShopDealerCapitalMapper;
import com.gxwebsoft.shop.mapper.ShopDealerRefereeMapper;
import com.gxwebsoft.shop.mapper.ShopDealerUserMapper; import com.gxwebsoft.shop.mapper.ShopDealerUserMapper;
import com.gxwebsoft.shop.mapper.ShopOrderMapper; import com.gxwebsoft.shop.mapper.ShopOrderMapper;
import com.gxwebsoft.shop.param.ShopDealerUserParam; import com.gxwebsoft.shop.param.ShopDealerUserParam;
import com.gxwebsoft.shop.service.ShopDealerCapitalService; import com.gxwebsoft.shop.service.ShopDealerCapitalService;
import com.gxwebsoft.shop.service.ShopDealerUserService; import com.gxwebsoft.shop.service.ShopDealerUserService;
import com.gxwebsoft.shop.vo.ShopDealerRefereeVO;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -58,6 +63,8 @@ public class ShopDealerUserServiceImpl extends ServiceImpl<ShopDealerUserMapper,
private ShopOrderMapper shopOrderMapper; private ShopOrderMapper shopOrderMapper;
private ShopDealerRefereeMapper shopDealerRefereeMapper;
private static final int TENANT_ID = 10584; private static final int TENANT_ID = 10584;
@Override @Override
@@ -210,21 +217,18 @@ public class ShopDealerUserServiceImpl extends ServiceImpl<ShopDealerUserMapper,
List<Integer> userIdList = dealerCapitalList.stream().map(ShopDealerCapital::getUserId).distinct().collect(Collectors.toList()); List<Integer> userIdList = dealerCapitalList.stream().map(ShopDealerCapital::getUserId).distinct().collect(Collectors.toList());
List<ShopDealerUser> shopDealerUserList = lambdaQuery().in(ShopDealerUser::getUserId, userIdList).list(); List<ShopDealerUser> shopDealerUserList = lambdaQuery().in(ShopDealerUser::getUserId, userIdList).list();
List<ShopDealerCapital> updateCapitalList = new ArrayList<>();
List<ShopDealerCapital> newCapitalList = new ArrayList<>();
Map<Integer, List<ShopDealerCapital>> userCapitalMap = dealerCapitalList.stream().collect(Collectors.groupingBy(ShopDealerCapital::getUserId)); Map<Integer, List<ShopDealerCapital>> userCapitalMap = dealerCapitalList.stream().collect(Collectors.groupingBy(ShopDealerCapital::getUserId));
userCapitalMap.forEach((k, value) ->{ userCapitalMap.forEach((k, value) ->{
//5.4 查询是否存在待解冻订单数据 //5.4 查询是否存在待解冻订单数据
ShopDealerCapital userCapital = value.stream().filter(capital -> ShopDealerTypeEnum.FREEZE_ACCOUNT.getCode().equals(capital.getType()) && capital.getPaymentFlag() != null List<ShopDealerCapital> capitalList = value.stream().filter(capital -> ShopDealerTypeEnum.FREEZE_ACCOUNT.getCode().equals(capital.getType()) && capital.getPaymentFlag() != null
&& capital.getPaymentFlag() == 0).findFirst().orElse(null); && capital.getPaymentFlag() == 0).collect(Collectors.toList());
if(userCapital != null){ if(CollectionUtils.isNotEmpty(capitalList)){
//5.5 查询此订单是否已结算
ShopDealerCapital alreadyCapital = value.stream().filter(capital -> ShopDealerTypeEnum.DEFROST.getCode().equals(capital.getType())).findFirst().orElse(null);
if(alreadyCapital == null){
ShopDealerUser dealerUser = shopDealerUserList.stream().filter(shopDealerUser -> k.equals(shopDealerUser.getUserId())).findFirst().orElse(null); ShopDealerUser dealerUser = shopDealerUserList.stream().filter(shopDealerUser -> k.equals(shopDealerUser.getUserId())).findFirst().orElse(null);
//5.6 判断分销账户分销金额是否大于解冻金额 //5.6 判断分销账户分销金额是否大于解冻金额
BigDecimal freezeMoney = userCapital.getFreezeMoney(); BigDecimal freezeMoney = capitalList.stream().map(ShopDealerCapital::getFreezeMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
if(dealerUser != null && dealerUser.getFreezeMoney().compareTo(freezeMoney) >= 0){ if(dealerUser != null && dealerUser.getFreezeMoney().compareTo(freezeMoney) >= 0){
//5.7 账户解冻金额、可提现增加金额 //5.7 账户解冻金额、可提现增加金额
dealerUser.setFreezeMoney(dealerUser.getFreezeMoney().subtract(freezeMoney)); dealerUser.setFreezeMoney(dealerUser.getFreezeMoney().subtract(freezeMoney));
@@ -252,16 +256,28 @@ public class ShopDealerUserServiceImpl extends ServiceImpl<ShopDealerUserMapper,
if (loginUser != null) { if (loginUser != null) {
dealerCapital.setCreator(loginUser.getUserId()); dealerCapital.setCreator(loginUser.getUserId());
} }
shopDealerCapitalMapper.insert(dealerCapital); newCapitalList.add(dealerCapital);
userCapital.setPaymentFlag(1);
}
}
//5.6 更新冻结流水为已结算状态 capitalList.forEach(capital -> {
userCapital.setUpdateTime(now); capital.setPaymentFlag(1);
shopDealerCapitalMapper.updateById(userCapital); capital.setUpdateTime(now);
});
updateCapitalList.addAll(capitalList);
}
} }
}); });
//6.批量修改原待结算解冻订单为结算状态
if(CollectionUtils.isNotEmpty(updateCapitalList)){
shopDealerCapitalService.updateBatchById(updateCapitalList);
}
//7.批量新增结算记录
if(CollectionUtils.isNotEmpty(newCapitalList)){
shopDealerCapitalService.saveBatch(newCapitalList);
}
}else { }else {
log.error("未查询到待解冻订单信息:" + entity.getOrderNo()); log.error("未查询到待解冻订单信息:" + entity.getOrderNo());
} }
@@ -423,6 +439,80 @@ public class ShopDealerUserServiceImpl extends ServiceImpl<ShopDealerUserMapper,
return Boolean.TRUE; return Boolean.TRUE;
} }
@Override
public Boolean orderProfit(ShopDealerSettlementDto entity) {
if(entity != null && CollectionUtils.isNotEmpty(entity.getItemList())){
LocalDateTime now = LocalDateTime.now();
List<ShopDealerSettlementItemDto> itemList = entity.getItemList();
List<Integer> userIdList = itemList.stream().map(ShopDealerSettlementItemDto::getUserId).distinct().collect(Collectors.toList());
List<ShopDealerUser> shopDealerUserList = baseMapper.selectList(new LambdaQueryWrapper<ShopDealerUser>().select(ShopDealerUser::getId, ShopDealerUser::getUserId,
ShopDealerUser::getMoney, ShopDealerUser::getTotalMoney, ShopDealerUser::getFreezeMoney).in(ShopDealerUser::getUserId, userIdList));
List<ShopDealerUser> updateDealerUserList = new ArrayList<>();
List<ShopDealerCapital> capitalList = new ArrayList<>();
itemList.forEach(item ->{
ShopDealerUser dealerUser = shopDealerUserList.stream().filter(shopDealerUser -> item.getUserId().equals(shopDealerUser.getUserId())).findFirst().orElse(null);
if(dealerUser != null){
dealerUser.setFreezeMoney(dealerUser.getFreezeMoney().add(item.getMoney()));
dealerUser.setTotalMoney(dealerUser.getTotalMoney().add(item.getMoney()));
dealerUser.setUpdateTime(now);
updateDealerUserList.add(dealerUser);
ShopDealerCapital capital = BeanUtil.toBean(entity, ShopDealerCapital.class);
capital.setNo(item.getNo());
capital.setType(ShopDealerTypeEnum.FREEZE_ACCOUNT.getCode());
capital.setFlowType(ShopDealerCapitalUpdateEnum.DIVIDEND_INCOME.getType());
capital.setComments(ShopDealerCapitalUpdateEnum.DIVIDEND_INCOME.getDescription());
capital.setUserId(item.getUserId());
capital.setFreezeMoney(item.getMoney());
capital.setFreezeMoneyAfter(dealerUser.getFreezeMoney());
capital.setMoneyAfter(dealerUser.getMoney());
capital.setCreateTime(now);
capitalList.add(capital);
}
});
if(CollectionUtils.isNotEmpty(updateDealerUserList)){
updateBatchById(updateDealerUserList);
}
if(CollectionUtils.isNotEmpty(capitalList)){
shopDealerCapitalService.saveBatch(capitalList);
}
}
return Boolean.TRUE;
}
@Override
public Boolean updateInfo(ShopDealerUser entity) {
if(entity.getId() == null){
throw new RuntimeException("数据ID必传");
}
ShopDealerUser dealerUser = baseMapper.selectById(entity.getId());
if(dealerUser != null){
if(!dealerUser.getType().equals(entity.getType()) && Arrays.asList(1, 2).contains(entity.getType())){
UserRelationVO relationVO = getUserSuperior(dealerUser.getUserId());
if(entity.getType() == 1 && relationVO.getStoreUserId() != null){
throw new BusinessException("当前用户推荐关系已存在门店角色,不可升级为门店!");
}
if(entity.getType() == 2){
if(relationVO.getServiceUserId() != null){
throw new BusinessException("当前用户推荐关系已存在服务商角色,不可升级为服务商!");
}
if(relationVO.getStoreUserId() != null){
throw new BusinessException("当前用户推荐关系已存在门店角色,不可升级为服务商[等级限定]");
}
}
}
return baseMapper.updateById(entity) > 0;
}else {
throw new BusinessException(GlobalErrorCodeConstants.NOT_FOUND.getMsg());
}
}
@Override @Override
public Boolean verifyEnable(Integer id) { public Boolean verifyEnable(Integer id) {
ShopDealerUser dealerUser = baseMapper.selectById(id); ShopDealerUser dealerUser = baseMapper.selectById(id);
@@ -442,6 +532,70 @@ public class ShopDealerUserServiceImpl extends ServiceImpl<ShopDealerUserMapper,
return Boolean.TRUE; return Boolean.TRUE;
} }
@Override
public UserRelationVO getUserSuperior(Integer userId) {
UserRelationVO vo = new UserRelationVO();
vo.setUserId(userId);
// 1. 先找到当前用户的直接上级ID推荐人
Integer superiorId = getDirectSuperiorId(userId);
if (superiorId == null || superiorId == 0) {
return vo; // 无上级,直接返回
}
// 2. 逐级向上查找 门店(type=1) 和 服务商(type=2)
findStoreAndService(superiorId, vo);
return vo;
}
/**
* 1. 获取直接上级ID从推荐关系表
*/
private Integer getDirectSuperiorId(Integer userId) {
ShopDealerRefereeVO refereeVO = shopDealerRefereeMapper.getDealerIdByUserId(userId);
if(refereeVO != null && refereeVO.getDirectUserId() != null){
return refereeVO.getDirectUserId();
}
return null;
}
/**
* 2. 递归/逐级查找门店、服务商最多查5级防止死循环
*/
private void findStoreAndService(Integer currentUserId, UserRelationVO vo) {
int maxLevel = 10; // 限制最大层级,避免死循环
Integer tempUserId = currentUserId;
for (int i = 0; i < maxLevel; i++) {
if (tempUserId == null) break;
// 查询当前用户的等级类型
ShopDealerUser dealerUser = getOne(new LambdaQueryWrapper<ShopDealerUser>().eq(ShopDealerUser::getUserId, tempUserId));
if (dealerUser == null) break;
// 找到门店,且还没赋值
if (vo.getStoreUserId() == null && dealerUser.getType() == 1) {
vo.setStoreUserId(tempUserId);
}
// 找到服务商,且还没赋值
if (vo.getServiceUserId() == null && dealerUser.getType() == 2) {
vo.setServiceUserId(tempUserId);
}
// 都找到了,提前退出
if (vo.getStoreUserId() != null && vo.getServiceUserId() != null) {
break;
}
// 继续向上找上级
tempUserId = getDirectSuperiorId(tempUserId);
}
}
public ShopDealerUser getDealerUser(Integer userId){ public ShopDealerUser getDealerUser(Integer userId){
ShopDealerUser shopDealerUser = baseMapper.selectOne(new LambdaQueryWrapper<ShopDealerUser>().eq(ShopDealerUser::getUserId, userId)); ShopDealerUser shopDealerUser = baseMapper.selectOne(new LambdaQueryWrapper<ShopDealerUser>().eq(ShopDealerUser::getUserId, userId));
if(shopDealerUser == null){ if(shopDealerUser == null){

View File

@@ -1,16 +1,33 @@
package com.gxwebsoft.shop.service.impl; package com.gxwebsoft.shop.service.impl;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.exception.BusinessException;
import com.gxwebsoft.common.core.exception.enums.GlobalErrorCodeConstants;
import com.gxwebsoft.common.core.utils.LoginUserUtil;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.shop.dto.ShopGoodsProfitUpdateDto;
import com.gxwebsoft.shop.dto.ShopGoodsProfitUpdateItemDto;
import com.gxwebsoft.shop.entity.ShopDealerUser;
import com.gxwebsoft.shop.entity.ShopGoods;
import com.gxwebsoft.shop.entity.ShopGoodsProfit;
import com.gxwebsoft.shop.mapper.ShopDealerUserMapper;
import com.gxwebsoft.shop.mapper.ShopGoodsMapper;
import com.gxwebsoft.shop.mapper.ShopGoodsProfitMapper; import com.gxwebsoft.shop.mapper.ShopGoodsProfitMapper;
import com.gxwebsoft.shop.service.ShopGoodsProfitService; import com.gxwebsoft.shop.service.ShopGoodsProfitService;
import com.gxwebsoft.shop.entity.ShopGoodsProfit; import com.gxwebsoft.shop.vo.ShopGoodsProfitVO;
import com.gxwebsoft.shop.param.ShopGoodsProfitParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* 商品分润设定Service实现 * 商品分润设定Service实现
@@ -22,28 +39,101 @@ import java.util.List;
@AllArgsConstructor @AllArgsConstructor
public class ShopGoodsProfitServiceImpl extends ServiceImpl<ShopGoodsProfitMapper, ShopGoodsProfit> implements ShopGoodsProfitService { public class ShopGoodsProfitServiceImpl extends ServiceImpl<ShopGoodsProfitMapper, ShopGoodsProfit> implements ShopGoodsProfitService {
private ShopDealerUserMapper shopDealerUserMapper;
private ShopGoodsMapper shopGoodsMapper;
@Override @Override
public PageResult<ShopGoodsProfit> pageRel(ShopGoodsProfitParam param) { public List<ShopGoodsProfitVO> getByGoodsId(Integer goodsId, Integer type) {
PageParam<ShopGoodsProfit, ShopGoodsProfitParam> page = new PageParam<>(param); List<ShopGoodsProfit> list = lambdaQuery().select(ShopGoodsProfit::getId, ShopGoodsProfit::getGoodsId, ShopGoodsProfit::getUserId, ShopGoodsProfit::getProfit,
page.setDefaultOrder("sort_number asc, create_time desc"); ShopGoodsProfit::getStatus).eq(ShopGoodsProfit::getGoodsId, goodsId).eq(ShopGoodsProfit::getType, type).list();
List<ShopGoodsProfit> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal()); if(CollectionUtils.isNotEmpty(list)){
List<Integer> userIdList = list.stream().map(ShopGoodsProfit::getUserId).distinct().collect(Collectors.toList());
List<ShopDealerUser> shopDealerUserList = shopDealerUserMapper.selectList(new LambdaQueryWrapper<ShopDealerUser>().in(ShopDealerUser::getUserId, userIdList));
List<ShopGoodsProfitVO> shopGoodsProfitVOS = BeanUtil.copyToList(list, ShopGoodsProfitVO.class);
for(ShopGoodsProfitVO shopGoodsProfitVO : shopGoodsProfitVOS){
shopDealerUserList.stream().filter(shopDealerUser -> shopGoodsProfitVO.getUserId().equals(shopDealerUser.getUserId())).findFirst()
.ifPresent(shopDealerUser -> shopGoodsProfitVO.setUserName(shopDealerUser.getRealName()));
}
return shopGoodsProfitVOS;
}
return new ArrayList<>();
} }
@Override @Override
public List<ShopGoodsProfit> listRel(ShopGoodsProfitParam param) { public List<ShopGoodsProfitVO> getGoodsProfit(List<Integer> goodsIdList, Integer type) {
List<ShopGoodsProfit> list = baseMapper.selectListRel(param); List<ShopGoodsProfit> profitList = lambdaQuery().select(ShopGoodsProfit::getId, ShopGoodsProfit::getGoodsId, ShopGoodsProfit::getUserId, ShopGoodsProfit::getProfit,
// 排序 ShopGoodsProfit::getStatus).in(ShopGoodsProfit::getGoodsId, goodsIdList).eq(ShopGoodsProfit::getType, type).eq(ShopGoodsProfit::getStatus, 1).list();
PageParam<ShopGoodsProfit, ShopGoodsProfitParam> page = new PageParam<>(); if(CollectionUtils.isNotEmpty(profitList)){
page.setDefaultOrder("sort_number asc, create_time desc"); return BeanUtil.copyToList(profitList, ShopGoodsProfitVO.class);
return page.sortRecords(list); }
return new ArrayList<>();
} }
@Override @Override
public ShopGoodsProfit getByIdRel(Integer id) { public Boolean updateByGoodsId(ShopGoodsProfitUpdateDto entity) {
ShopGoodsProfitParam param = new ShopGoodsProfitParam(); User loginUser = LoginUserUtil.getLoginUser();
param.setId(id); if(loginUser == null){
return param.getOne(baseMapper.selectListRel(param)); throw new BusinessException(GlobalErrorCodeConstants.UNAUTHORIZED.getMsg());
}
List<ShopGoodsProfitUpdateItemDto> itemList = entity.getItemList();
LocalDateTime now = LocalDateTime.now();
if(CollectionUtils.isNotEmpty(itemList)){
//1.先检查传入的分润总和是否超过100
BigDecimal profitSum = itemList.stream().map(ShopGoodsProfitUpdateItemDto::getProfit).reduce(BigDecimal.ZERO, BigDecimal::add);
if(profitSum.compareTo(BigDecimal.valueOf(100)) > 0){
throw new BusinessException("股东分红比例总和不能超过100%");
}
//2.检查分润对象是否有重复
Map<Integer, List<ShopGoodsProfitUpdateItemDto>> userMap = itemList.stream().collect(Collectors.groupingBy(ShopGoodsProfitUpdateItemDto::getUserId)).entrySet().stream()
.filter(entry -> entry.getValue().size() > 1).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if(!userMap.isEmpty()){
String userIds = String.join(",", userMap.keySet().stream().map(String::valueOf).toList());
throw new BusinessException("用户:【" + userIds + "】存在多条分红数据,请修改后重新提交!");
}
//3.查询商品原有分润数据并做超100%管控
ShopGoods shopGoods = shopGoodsMapper.selectById(entity.getGoodsId());
if(shopGoods == null){
throw new BusinessException(GlobalErrorCodeConstants.NOT_FOUND.getMsg());
}
BigDecimal goodsOriginalProfit = shopGoods.getVerifyRate().add(shopGoods.getVerifyParentRate());
if(shopGoods.getCommissionType() == 20){
goodsOriginalProfit = goodsOriginalProfit.add(shopGoods.getFirstMoney()).add(shopGoods.getSecondMoney()).add(shopGoods.getFirstDividend())
.add(shopGoods.getSecondDividend()).add(shopGoods.getDeliveryMoney());
}
if(profitSum.add(goodsOriginalProfit).compareTo(BigDecimal.valueOf(100)) > 0){
throw new BusinessException("股东分红比例与商品原有分销比例加总不能超过100");
}
//4.查询有分润数据并删除
removeByGoodsId(entity.getGoodsId(), entity.getType(), loginUser.getUserId(), now);
//5.批量新增分润数据
List<ShopGoodsProfit> shopGoodsProfits = BeanUtil.copyToList(itemList, ShopGoodsProfit.class);
shopGoodsProfits.forEach(shopGoodsProfit -> {
shopGoodsProfit.setType(entity.getType());
shopGoodsProfit.setGoodsId(entity.getGoodsId());
shopGoodsProfit.setTenantId(loginUser.getTenantId());
shopGoodsProfit.setCreator(loginUser.getUserId());
shopGoodsProfit.setCreateTime(now);
});
saveBatch(shopGoodsProfits);
}else {
removeByGoodsId(entity.getGoodsId(), entity.getType(), loginUser.getUserId(), now);
}
return Boolean.TRUE;
}
private void removeByGoodsId(Integer goodsId, Integer type, Integer userId, LocalDateTime date){
LambdaUpdateWrapper<ShopGoodsProfit> updateWrapper = new LambdaUpdateWrapper<ShopGoodsProfit>().eq(ShopGoodsProfit::getGoodsId, goodsId).eq(ShopGoodsProfit::getType, type)
.set(ShopGoodsProfit::getUpdater, userId).set(ShopGoodsProfit::getUpdateTime, date).set(ShopGoodsProfit::getDeleted, 1);
update(updateWrapper);
} }
} }

View File

@@ -0,0 +1,35 @@
package com.gxwebsoft.shop.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
/**
* 商品分润设定
*
* @author xm
* @since 2026-05-20 14:33:00
*/
@Data
public class ShopGoodsProfitVO {
@Schema(description = "主键ID")
private Integer id;
@Schema(description = "商品ID")
private Integer goodsId;
@Schema(description = "用户ID")
private Integer userId;
@Schema(description = "用户名称")
private String userName;
@Schema(description = "分佣比例 百分比")
private BigDecimal profit;
@Schema(description = "开启状态 0-未开启 1-开启")
private Integer status;
}