liujie
2025-06-09 bd404b89f646ac645f2e54c543eb1d4efe291b62
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/TAppUserVipDetailServiceImpl.java
@@ -22,7 +22,7 @@
/**
 * <p>
 *  服务实现类
 * 服务实现类
 * </p>
 *
 * @author luodangjia
@@ -30,49 +30,36 @@
 */
@Service
public class TAppUserVipDetailServiceImpl extends ServiceImpl<TAppUserVipDetailMapper, TAppUserVipDetail> implements TAppUserVipDetailService {
    @Resource
    private VipClient vipClient;
    @Resource
    private OtherClient otherClient;
    @Resource
    private TAppCouponService appCouponService;
    @Resource
    private TAppUserVipDetailService tAppUserVipDetailService;
    @Override
    public void giveVipCoupun(Long appUserId, Integer vipId,Long recordId,Integer monthNum) {
        //如果不包含,则更新sendNum,并且赠送优惠卷
        TAppUserVipDetail byId = tAppUserVipDetailService.getById(recordId);
        if (byId.getStartTime().plusMonths(byId.getSendMonth()).toLocalDate().compareTo(LocalDate.now())==0&&LocalDate.now().isBefore(byId.getEndTime().toLocalDate())){
            byId.setSendMonth(byId.getSendMonth()+1);
        //给这个用户发放对应vip的优惠卷以及充电次数加满
            List<SendCouponDto> javaList = JSON.parseArray(byId.getCouponIds()).toJavaList(SendCouponDto.class);
            for (SendCouponDto sendCouponDto : javaList) {
                Integer number = sendCouponDto.getNumber();
                for (Integer i = 0; i < number; i++) {
                    R<TCoupon> couponById = otherClient.getCouponById(sendCouponDto.getId());
                    TCoupon coupon = couponById.getData();
                    //将该优惠卷添加到用户优惠卷中
                    TAppCoupon tAppCoupon = new TAppCoupon();
                    tAppCoupon.setAppUserId(appUserId);
                    tAppCoupon.setCouponId(sendCouponDto.getId());
                    if (coupon.getValidityPeriodMode() == 1) {
                        tAppCoupon.setEndTime(coupon.getEndTime());
                    } else {
                        tAppCoupon.setEndTime(LocalDateTime.now().plusDays(coupon.getDays()));
                    }
                    tAppCoupon.setWaysToObtain(4);
                    tAppCoupon.setStatus(1);
                    tAppCoupon.setCouponJson(JSON.toJSONString(coupon));
                    appCouponService.save(tAppCoupon);
                }
                }
            }
        byId.setChargeNum(byId.getSendChargeNum());
        tAppUserVipDetailService.updateById(byId);
        }
   @Resource
   private VipClient vipClient;
   @Resource
   private OtherClient otherClient;
   @Resource
   private TAppCouponService appCouponService;
   @Resource
   private TAppUserVipDetailService tAppUserVipDetailService;
   @Override
   public void giveVipCoupun(TAppUserVipDetail recentDetail) {
      Integer vipType = recentDetail.getVipType();
      Integer sendMonth = recentDetail.getSendMonth();
      //月卡
      if(1 == vipType && 1 == sendMonth){
         return;
      }
      //季卡
      if(2 == vipType && 3 == sendMonth){
         return;
      }
      //年卡
      if(3 == vipType && 12 == sendMonth){
         return;
      }
      recentDetail.setSendMonth(sendMonth + 1);
      recentDetail.setChargeNum(recentDetail.getSendChargeNum());
      recentDetail.setMonthEndTime(LocalDateTime.now().plusMonths(1));
      tAppUserVipDetailService.updateById(recentDetail);
   }
}