充值改造
This commit is contained in:
@@ -3,23 +3,39 @@ package com.czg.service.market.service.impl;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
|
||||
import com.czg.account.entity.ShopUser;
|
||||
import com.czg.account.service.MemberPointsService;
|
||||
import com.czg.account.service.ShopUserService;
|
||||
import com.czg.enums.ShopUserFlowBizEnum;
|
||||
import com.czg.exception.CzgException;
|
||||
import com.czg.market.dto.CouponInfoDTO;
|
||||
import com.czg.market.dto.MkRewardCouponDTO;
|
||||
import com.czg.market.dto.MkShopRechargeDTO;
|
||||
import com.czg.market.dto.MkShopRechargeDetailDTO;
|
||||
import com.czg.market.entity.MkShopRechargeDetail;
|
||||
import com.czg.market.entity.ShopCoupon;
|
||||
import com.czg.market.service.MkShopCouponRecordService;
|
||||
import com.czg.market.service.MkShopRechargeDetailService;
|
||||
import com.czg.market.service.ShopCouponService;
|
||||
import com.czg.market.vo.CouponInfoVO;
|
||||
import com.czg.market.vo.MkShopRechargeDetailVO;
|
||||
import com.czg.market.vo.MkShopRechargeVO;
|
||||
import com.czg.order.entity.OrderInfo;
|
||||
import com.czg.service.market.enums.OrderStatusEnums;
|
||||
import com.czg.utils.AssertUtil;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import com.czg.market.entity.MkShopRecharge;
|
||||
import com.czg.market.service.MkShopRechargeService;
|
||||
import com.czg.service.market.mapper.MkShopRechargeMapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboReference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -32,12 +48,19 @@ import java.util.stream.Collectors;
|
||||
* @author zs
|
||||
* @since 2025-09-16
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper, MkShopRecharge> implements MkShopRechargeService{
|
||||
@Resource
|
||||
private MkShopRechargeDetailService shopRechargeDetailService;
|
||||
@Resource
|
||||
private ShopCouponService shopCouponService;
|
||||
@DubboReference
|
||||
private ShopUserService shopUserService;
|
||||
@DubboReference
|
||||
private MemberPointsService memberPointsService;
|
||||
@Resource
|
||||
private MkShopCouponRecordService shopCouponRecordService;
|
||||
|
||||
@Override
|
||||
public MkShopRechargeVO detail(Long shopId) {
|
||||
@@ -95,4 +118,64 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
|
||||
}
|
||||
return updateById(shopRecharge);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal checkRecharge(Long mainShopId, Long shopId, Long userId, Long rechargeDetailId, BigDecimal money) {
|
||||
MkShopRechargeVO rechargeVO = detail(mainShopId);
|
||||
if ("part".equals(rechargeVO.getUseType()) && !rechargeVO.getShopIdList().contains(shopId)) {
|
||||
throw new CzgException("充值失败 该店铺不在充值店铺列表");
|
||||
}
|
||||
|
||||
if (rechargeDetailId == null) {
|
||||
if (rechargeVO.getIsCustom() == 0) {
|
||||
throw new CzgException("未开启自定义充值金额");
|
||||
}
|
||||
return money;
|
||||
}else {
|
||||
MkShopRechargeDetail rechargeDetail = shopRechargeDetailService.getOne(new QueryWrapper().eq(MkShopRechargeDetail::getShopRechargeId, rechargeVO.getId()).eq(MkShopRechargeDetail::getId, rechargeDetailId));
|
||||
AssertUtil.isNull(rechargeDetail, "充值金额不存在");
|
||||
return rechargeDetail.getAmount();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void recharge(Long shopId, Long shopUserId, Long relatedId, BigDecimal amount, Long paymentId, String payType, ShopUserFlowBizEnum bizEnum) {
|
||||
log.info("充值回调, 用户id: {}, 金额: {}, 关联id: {}", shopUserId, amount, relatedId);
|
||||
ShopUser shopUser = shopUserService.getById(shopUserId);
|
||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
|
||||
.setId(shopUserId)
|
||||
.setType(1)
|
||||
.setBizEnum(bizEnum)
|
||||
.setRelationId(paymentId);
|
||||
// 标准充值
|
||||
if (relatedId != null) {
|
||||
MkShopRechargeDetail rechargeDetail = shopRechargeDetailService.getById(relatedId);
|
||||
shopUserMoneyEditDTO.setMoney(rechargeDetail.getAmount().add(rechargeDetail.getRewardAmount()));
|
||||
// 发放积分
|
||||
if (rechargeDetail.getRewardPoints() != null) {
|
||||
memberPointsService.addPoints(shopUserId, rechargeDetail.getRewardPoints(), "会员消费送积分", null);
|
||||
}
|
||||
|
||||
// 发放优惠券
|
||||
if (StrUtil.isNotBlank(rechargeDetail.getCouponInfoList())) {
|
||||
JSONArray.parseArray(rechargeDetail.getCouponInfoList()).toJavaList(CouponInfoDTO.class).forEach(item -> {
|
||||
shopCouponRecordService.grant(shopId, new MkRewardCouponDTO().setCouponId(item.getId())
|
||||
.setNum(item.getNum())
|
||||
.setUserId(shopUser.getUserId())
|
||||
.setShopId(shopId));
|
||||
});
|
||||
}
|
||||
// 自定义金额
|
||||
}else {
|
||||
shopUserMoneyEditDTO.setMoney(amount.divide(new BigDecimal(100), 2, RoundingMode.DOWN));
|
||||
}
|
||||
|
||||
|
||||
//TODO 以前的会员活动
|
||||
// activateService.giveActivate(shopUser, new BigDecimal(czgCallBackDto.getAmount()).divide(new BigDecimal(100), 2, RoundingMode.DOWN),
|
||||
// payment.getRelatedId(), flowId);
|
||||
//更新会员余额 并生成流水
|
||||
shopUserService.updateMoney(shopUserMoneyEditDTO);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user