Merge remote-tracking branch 'origin/master'

This commit is contained in:
chc 2024-01-25 14:02:24 +08:00
commit f0a80338da
6 changed files with 106 additions and 18 deletions

View File

@ -96,7 +96,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
keys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId()));
int i = -orderItem.getNum();
values.add(Integer.toString(i));
setPromotionStock(keys, values, orderItem);
setPromotionStock(keys, values, orderItem, true);
}
List<Integer> stocks = cache.multiGet(keys);
@ -134,6 +134,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
keys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId()));
int i = orderItem.getNum();
values.add(Integer.toString(i));
setPromotionStock(keys, values, orderItem, false);
}
//批量脚本执行库存回退
Boolean skuResult = stringRedisTemplate.execute(quantityScript, keys, values.toArray());
@ -239,7 +240,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
* @param values 缓存value值
* @param sku 购物车信息
*/
private void setPromotionStock(List<String> keys, List<String> values, OrderItem sku) {
private void setPromotionStock(List<String> keys, List<String> values, OrderItem sku, boolean deduction) {
if (sku.getPromotionType() != null) {
//如果此促销有库存概念则计入
String[] skuPromotions = sku.getPromotionType().split(",");
@ -249,7 +250,7 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
.findFirst()
.ifPresent(promotionTypeEnum -> {
keys.add(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, sku.getPromotionId().split(",")[currentIndex], sku.getSkuId()));
int num = -sku.getNum();
int num = deduction ? -sku.getNum() : sku.getNum();
values.add(Integer.toString(num));
});
}
@ -371,6 +372,69 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
List<GoodsSku> goodsSkus = new ArrayList<>();
//sku库存key 集合
List<String> skuKeys = new ArrayList<>();
//促销商品
List<PromotionGoods> promotionGoods = new ArrayList<>();
//促销库存key 集合
List<String> promotionKey = new ArrayList<>();
//循环订单
for (OrderItem orderItem : order.getOrderItems()) {
skuKeys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId()));
GoodsSku goodsSku = new GoodsSku();
goodsSku.setId(orderItem.getSkuId());
goodsSku.setGoodsId(orderItem.getGoodsId());
//如果有促销信息
if (null != orderItem.getPromotionType() && null != orderItem.getPromotionId()) {
//如果促销有库存信息
String[] skuPromotions = orderItem.getPromotionType().split(",");
for (int i = 0; i < skuPromotions.length; i++) {
int currentIndex = i;
Arrays.stream(PromotionTypeEnum.haveStockPromotion).filter(promotionTypeEnum -> promotionTypeEnum.name().equals(skuPromotions[currentIndex]))
.findFirst()
.ifPresent(promotionTypeEnum -> {
//修改砍价商品库存
String promotionId = orderItem.getPromotionId().split(",")[currentIndex];
//修改砍价商品库存
if (promotionTypeEnum.equals(PromotionTypeEnum.KANJIA)) {
KanjiaActivity kanjiaActivity = kanjiaActivityService.getById(promotionId);
KanjiaActivityGoodsDTO kanjiaActivityGoodsDTO = kanjiaActivityGoodsService.getKanjiaGoodsDetail(kanjiaActivity.getKanjiaActivityGoodsId());
Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, promotionId, orderItem.getSkuId())).toString());
kanjiaActivityGoodsDTO.setStock(stock);
kanjiaActivityGoodsService.updateById(kanjiaActivityGoodsDTO);
//修改积分商品库存
} else if (promotionTypeEnum.equals(PromotionTypeEnum.POINTS_GOODS)) {
PointsGoodsVO pointsGoodsVO = pointsGoodsService.getPointsGoodsDetail(promotionId);
Integer stock = Integer.parseInt(cache.get(PromotionGoodsService.getPromotionGoodsStockCacheKey(promotionTypeEnum, promotionId, orderItem.getSkuId())).toString());
pointsGoodsVO.setActiveStock(stock);
pointsGoodsService.updateById(pointsGoodsVO);
} else {
PromotionGoodsSearchParams searchParams = new PromotionGoodsSearchParams();
searchParams.setPromotionType(promotionTypeEnum.name());
searchParams.setPromotionId(promotionId);
searchParams.setSkuId(orderItem.getSkuId());
PromotionGoods pGoods = promotionGoodsService.getPromotionsGoods(searchParams);
//记录需要更新的促销库存信息
promotionKey.add(
PromotionGoodsService.getPromotionGoodsStockCacheKey(
promotionTypeEnum,
promotionId, orderItem.getSkuId())
);
if (pGoods != null) {
promotionGoods.add(pGoods);
}
}
});
}
}
goodsSkus.add(goodsSku);
}
//循环订单
for (OrderItem orderItem : order.getOrderItems()) {
skuKeys.add(GoodsSkuService.getStockCacheKey(orderItem.getSkuId()));
@ -385,6 +449,16 @@ public class StockUpdateExecute implements OrderStatusChangeEvent {
for (int i = 0; i < skuStocks.size(); i++) {
goodsSkus.get(i).setQuantity(Convert.toInt(skuStocks.get(i).toString()));
}
//促销库存处理
if (!promotionKey.isEmpty()) {
List promotionStocks = cache.multiGet(promotionKey);
for (int i = 0; i < promotionKey.size(); i++) {
promotionGoods.get(i).setQuantity(Convert.toInt(promotionStocks.get(i).toString()));
Integer num = promotionGoods.get(i).getNum();
promotionGoods.get(i).setNum((num != null ? num : 0) + order.getOrder().getGoodsNum());
}
promotionGoodsService.updatePromotionGoodsStock(promotionGoods);
}
log.info("订单取消,库存还原:{}", goodsSkus);
//批量修改商品库存
goodsSkuService.updateGoodsStock(goodsSkus);

View File

@ -16,6 +16,7 @@ import cn.lili.modules.goods.entity.dos.Wholesale;
import cn.lili.modules.goods.entity.enums.GoodsAuthEnum;
import cn.lili.modules.goods.entity.enums.GoodsSalesModeEnum;
import cn.lili.modules.goods.entity.enums.GoodsStatusEnum;
import cn.lili.modules.goods.entity.enums.GoodsTypeEnum;
import cn.lili.modules.goods.service.GoodsSkuService;
import cn.lili.modules.goods.service.WholesaleService;
import cn.lili.modules.member.entity.dos.Member;
@ -568,7 +569,7 @@ public class CartServiceImpl implements CartService {
tradeDTO.setStoreRemark(tradeParams.getRemark());
tradeDTO.setParentOrderSn(tradeParams.getParentOrderSn());
//订单无收货地址校验
if (!tradeDTO.getCartTypeEnum().equals(CartTypeEnum.VIRTUAL) && tradeDTO.getStoreAddress() == null && tradeDTO.getMemberAddress() == null) {
if (tradeDTO.getStoreAddress() == null && tradeDTO.getMemberAddress() == null && !GoodsTypeEnum.VIRTUAL_GOODS.name().equals(tradeDTO.getCheckedSkuList().get(0).getGoodsSku().getGoodsType())) {
throw new ServiceException(ResultCode.MEMBER_ADDRESS_NOT_EXIST);
}
//构建交易

View File

@ -5,6 +5,7 @@ import cn.lili.common.utils.CurrencyUtil;
import cn.lili.common.utils.SnowFlake;
import cn.lili.common.vo.PageVO;
import cn.lili.modules.order.aftersale.entity.dos.AfterSale;
import cn.lili.modules.order.aftersale.service.AfterSaleService;
import cn.lili.modules.order.order.entity.dos.Order;
import cn.lili.modules.order.order.entity.dos.OrderItem;
import cn.lili.modules.order.order.entity.dos.StoreFlow;
@ -61,6 +62,8 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
@Autowired
private BillService billService;
@Autowired
private AfterSaleService afterSaleService;
/**
* 店铺订单支付流水
*
@ -119,15 +122,27 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
//分销佣金 =分销佣金/订单商品数量* 售后商品数量
storeFlow.setDistributionRebate(CurrencyUtil.mul(CurrencyUtil.div(payStoreFlow.getDistributionRebate(), payStoreFlow.getNum()), afterSale.getNum()));
//流水金额 = 支付最终结算金额
storeFlow.setFinalPrice(payStoreFlow.getBillPrice());
//最终结算金额 =实际退款金额
storeFlow.setBillPrice(afterSale.getActualRefundPrice());
storeFlow.setFinalPrice(afterSale.getActualRefundPrice());
//站点优惠券补贴返还金额=(站点优惠券补贴金额/购买商品数量)*退款商品数量
storeFlow.setSiteCouponCommission(CurrencyUtil.mul(CurrencyUtil.div(payStoreFlow.getSiteCouponCommission(), payStoreFlow.getNum()), afterSale.getNum()));
storeFlow.setSiteCouponCommission(CurrencyUtil.mul(CurrencyUtil.div(payStoreFlow.getSiteCouponCommission() == null ? 0 : payStoreFlow.getSiteCouponCommission(), payStoreFlow.getNum()), afterSale.getNum()));
//平台优惠券 使用金额
storeFlow.setSiteCouponPrice(payStoreFlow.getSiteCouponPrice());
//站点优惠券佣金比例
storeFlow.setSiteCouponPoint(payStoreFlow.getSiteCouponPoint());
// 退单结算金额 相当于付款结算金额反计算逻辑对平台收取的佣金分销收取的佣金进行返还对平台优惠券的补贴应该相加
// 由于退单的结算金额为正数所以需要将结算金额计算方式相较于付款结算金额计算方式进行反转
// 退款结算金额 = flowPrice(实际退款金额) + storeCouponCommission(getSiteCouponCommission) - platFormCommission(平台收取交易佣金) - distributionCommission(单品分销返现支出) ")
storeFlow.setBillPrice(
CurrencyUtil.add(
afterSale.getActualRefundPrice(),
storeFlow.getSiteCouponCommission(),
-storeFlow.getCommissionPrice(),
-storeFlow.getDistributionRebate()
)
);
//退款日志
RefundLog refundLog = refundLogService.queryByAfterSaleSn(afterSale.getSn());
//第三方流水单号
@ -137,6 +152,8 @@ public class StoreFlowServiceImpl extends ServiceImpl<StoreFlowMapper, StoreFlow
this.save(storeFlow);
}
@Override
public IPage<StoreFlow> getStoreFlow(StoreFlowQueryDTO storeFlowQueryDTO) {

File diff suppressed because one or more lines are too long

View File

@ -57,6 +57,6 @@ public interface BillMapper extends BaseMapper<Bill> {
",IFNULL(SUM( site_coupon_commission ),0) AS siteCouponRefundCommission" +
",IFNULL(SUM( kanjia_settlement_price ),0) AS kanjiaRefundSettlementPrice" +
",IFNULL(SUM( point_settlement_price ),0) AS pointRefundSettlementPrice" +
",IFNULL(SUM( final_price ),0) AS billPrice FROM li_store_flow ${ew.customSqlSegment}")
",IFNULL(SUM( bill_price ),0) AS billPrice FROM li_store_flow ${ew.customSqlSegment}")
Bill getRefundBill(@Param(Constants.WRAPPER) QueryWrapper<Bill> queryWrapper);
}

View File

@ -95,7 +95,6 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
//退款结算信息
Bill refundBill = this.baseMapper.getRefundBill(new QueryWrapper<Bill>().eq("store_id", storeId).eq("flow_type", FlowTypeEnum.REFUND.name()).between("create_time", startTime, endTime));
//店铺退款金额
Double refundPrice = 0D;
if (refundBill != null) {
//退单金额
bill.setRefundPrice(refundBill.getRefundPrice() != null ? refundBill.getRefundPrice() : 0D);
@ -109,8 +108,7 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
bill.setPointRefundSettlementPrice(refundBill.getPointRefundSettlementPrice() != null ? refundBill.getPointRefundSettlementPrice() : 0D);
//退单 砍价补贴返还
bill.setKanjiaRefundSettlementPrice(refundBill.getKanjiaRefundSettlementPrice() != null ? refundBill.getKanjiaRefundSettlementPrice() : 0D);
//退款金额=店铺最终退款结算金额
refundPrice = refundBill.getBillPrice() != null ? refundBill.getBillPrice() : 0D;
}
@ -119,7 +117,6 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
*/
Bill orderBill = this.baseMapper.getOrderBill(new QueryWrapper<Bill>().eq("store_id", storeId).eq("flow_type", FlowTypeEnum.PAY.name()).between("create_time", startTime, endTime));
//店铺入款结算金额
double orderPrice = 0D;
if (orderBill != null) {
//结算周期内订单付款总金额
@ -135,11 +132,9 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
//砍价商品结算价格
bill.setKanjiaSettlementPrice(orderBill.getKanjiaSettlementPrice() != null ? orderBill.getKanjiaSettlementPrice() : 0D);
//入款结算金额= 店铺支付结算金额 + 平台优惠券补贴 + 分销订单退还返现佣金返还+退单产生退还佣金金额
orderPrice = CurrencyUtil.add(orderBill.getBillPrice() == null ? 0 : orderBill.getBillPrice(), bill.getSiteCouponCommission() == null ? 0 : bill.getSiteCouponCommission(), bill.getDistributionRefundCommission() == null ? 0 : bill.getDistributionRefundCommission(), bill.getRefundCommissionPrice() == null ? 0 : bill.getRefundCommissionPrice());
}
//最终结算金额=入款结算金额-退款结算金额-退货平台优惠券补贴返还
Double finalPrice = CurrencyUtil.sub(orderPrice, refundPrice, bill.getSiteCouponRefundCommission() == null ? 0 : bill.getSiteCouponRefundCommission());
//最终结算金额=入款结算金额-退款结算金额
Double finalPrice = CurrencyUtil.sub(orderBill.getBillPrice(), refundBill.getBillPrice());
//店铺最终结算金额=最终结算金额
bill.setBillPrice(finalPrice);
@ -148,6 +143,7 @@ public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements Bi
}
/**
* 立即结算
*