Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
0f9707597d
|
|
@ -28,6 +28,7 @@ import com.github.pagehelper.PageInfo;
|
|||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
|
|
@ -35,6 +36,7 @@ import java.math.BigDecimal;
|
|||
import java.time.LocalTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 优惠券 服务层实现。
|
||||
|
|
@ -42,6 +44,7 @@ import java.util.*;
|
|||
* @author ww
|
||||
* @since 2025-02-17
|
||||
*/
|
||||
@Slf4j
|
||||
@DubboService
|
||||
public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCoupon> implements ShopCouponService {
|
||||
|
||||
|
|
@ -144,6 +147,24 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
|
|||
|
||||
@Override
|
||||
public Boolean use(List<Long> ids, Long shopUserId, Long orderId) {
|
||||
List<ShopActivateCouponRecord> records = couponRecordService.listByIds(ids);
|
||||
if (records.isEmpty()) {
|
||||
log.error("优惠券使用失败,订单Id:{}", orderId);
|
||||
return false;
|
||||
}
|
||||
// 使用流来统计 couponId 出现的次数
|
||||
Map<Long, Long> couponIdCountMap = records.stream()
|
||||
.collect(Collectors.groupingBy(ShopActivateCouponRecord::getCouponId,
|
||||
Collectors.counting()
|
||||
));
|
||||
couponIdCountMap.forEach((couponId, count) -> {
|
||||
ShopCoupon tbShopCoupon = getById(couponId);
|
||||
tbShopCoupon.setUseNumber(tbShopCoupon.getUseNumber() + count.intValue());
|
||||
ShopCoupon coupon1 = new ShopCoupon();
|
||||
coupon1.setId(couponId);
|
||||
coupon1.setUseNumber(tbShopCoupon.getUseNumber());
|
||||
updateById(coupon1);
|
||||
});
|
||||
return couponRecordService.updateChain()
|
||||
.set(ShopActivateCouponRecord::getStatus, 1)
|
||||
.set(ShopActivateCouponRecord::getTargetId, orderId)
|
||||
|
|
|
|||
|
|
@ -524,7 +524,17 @@ public class PayServiceImpl implements PayService {
|
|||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(shopUser.getShopId(), shopUserMoneyEditDTO);
|
||||
userFlowService.updateRefund(inFlow.getId(), refPayParam.getRefAmount());
|
||||
if (giftFlow != null) {
|
||||
if (giftFlow != null && (giftFlow.getAmount().subtract(refPayParam.getRefAmount())).compareTo(BigDecimal.ZERO) > 0) {
|
||||
ShopUserMoneyEditDTO giftFlowEdit = new ShopUserMoneyEditDTO()
|
||||
.setId(shopUser.getId())
|
||||
.setMoney(giftFlow.getAmount())
|
||||
.setType(0)
|
||||
.setRemark("退款")
|
||||
.setBizEnum(ShopUserFlowBizEnum.RECHARGE_REFUND)
|
||||
.setRelationId(refPaymentId)
|
||||
.setRechargeId(giftFlow.getId());
|
||||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(shopUser.getShopId(), giftFlowEdit);
|
||||
userFlowService.updateRefund(giftFlow.getId(), giftFlow.getAmount());
|
||||
}
|
||||
//移除优惠券
|
||||
|
|
|
|||
Loading…
Reference in New Issue