Pu Zhibing
2024-10-08 52d18b0c747f12c64c9f9b36acb1b5e25f131e0c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.ruoyi.account.service.impl;
 
import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.dto.SendCouponDto;
import com.ruoyi.account.api.model.TAppCoupon;
import com.ruoyi.account.api.model.TAppUserVipDetail;
import com.ruoyi.account.mapper.TAppUserVipDetailMapper;
 
import com.ruoyi.account.service.TAppCouponService;
import com.ruoyi.account.service.TAppUserVipDetailService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.TCoupon;
import com.ruoyi.other.api.feignClient.OtherClient;
import com.ruoyi.other.api.feignClient.VipClient;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author luodangjia
 * @since 2024-08-08
 */
@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);
        }
 
}