luodangjia
2024-12-10 ee7ce5d1cbf80bee0a15c1e5bc5eaa30858d812b
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package com.hollywood.applet.controller;
import java.time.LocalDateTime;
 
 
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hollywood.applet.dto.Vip;
import com.hollywood.applet.dto.VipPayDto;
import com.hollywood.applet.service.TConfigService;
import com.hollywood.applet.service.TUserService;
import com.hollywood.applet.service.TVipConfigService;
import com.hollywood.applet.utils.LoginInfoUtil;
import com.hollywood.common.basic.ApiResult;
import com.hollywood.common.model.TConfig;
import com.hollywood.common.model.TUser;
import com.hollywood.common.model.TVipConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.math.BigInteger;
 
/**
 * <p>
 * 会员设置 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2024-02-29
 */
@Api(tags = "会员设置")
@RestController
@RequestMapping("/tVipConfig")
public class TVipConfigController {
 
    private final TVipConfigService vipConfigService;
    @Autowired
    private LoginInfoUtil loginInfoUtil;
    @Autowired
    private TUserService userService;
    @Autowired
    private TVipConfigService configService;
 
    @Autowired
    private TConfigService tConfigService;
 
 
    @Autowired
    public TVipConfigController(TVipConfigService vipConfigService) {
        this.vipConfigService = vipConfigService;
    }
 
    /**
     * 获取会员配置
     */
    @ApiOperation(value = "获取会员配置")
    @GetMapping(value = "/getById")
    public ApiResult<TVipConfig> getById() {
        return ApiResult.success(vipConfigService.getById(1));
    }
 
    /**
     * 编辑会员配置
     */
    @ApiOperation(value = "编辑会员配置")
    @PostMapping(value = "/updateById")
    public ApiResult updateById(@RequestBody TVipConfig vipConfig) {
        vipConfig.setId(1L);
        return ApiResult.success(vipConfigService.updateById(vipConfig));
    }
 
    @ApiOperation(value = "个人中心-会员信息")
    @PostMapping(value = "/vipinfo")
    public ApiResult<Vip> vipinfo() {
        Long userId = loginInfoUtil.getUserId();
        TUser byId = userService.getById(userId);
        TConfig byId1 = tConfigService.getById(2);
        BigDecimal money= (byId.getHasPay() ==null ? BigDecimal.valueOf(0) : byId.getHasPay());
 
        String vipJson;
        TVipConfig one = configService.getOne(null);
        if (byId.getVipType()==1){
            vipJson=one.getPersonVipLevel();
        }else if (byId.getVipType()==2){
            vipJson=one.getEnterpriseVipLevel();
        }else {
            Vip vip =new Vip();
            return ApiResult.success(vip);
        }
 
        JSONObject jsonObject = JSON.parseObject(vipJson);
 
        // 从 JSON 中获取各个值并转换为 BigDecimal 类型
        BigDecimal money1 = new BigDecimal(jsonObject.getString("money1"));
        BigDecimal money2 = new BigDecimal(jsonObject.getString("money2"));
        BigDecimal money3 = new BigDecimal(jsonObject.getString("money3"));
        BigDecimal money4 = new BigDecimal(jsonObject.getString("money4"));
        BigDecimal money5 = new BigDecimal(jsonObject.getString("money5"));
 
        // 组合为 BigDecimal 数组
        BigDecimal[] moneyArray = { money1, money2, money3, money4, money5 };
        Integer level = 0;
        BigDecimal needPay = null;
        BigDecimal total = null;
        for (int i = 0; i < moneyArray.length; i++) {
            BigDecimal bigDecimal = moneyArray[i];
            if (money.compareTo(bigDecimal)<0){
                    needPay= bigDecimal.subtract(money);
                    total = bigDecimal;
                    level = i;
                    break;
            }
        }
        Vip vip = new Vip();
        vip.setVipEndTime(byId.getEndTime()==null?null:byId.getEndTime());
        vip.setVipType(byId.getVipType());
        vip.setConfig(byId1);
        vip.setNeedPayToUp(needPay);
        vip.setLevel(level);
        vip.setTotal(total);
        return ApiResult.success(vip);
 
    }
 
 
    @ApiOperation(value = "购买会员操作")
    @PostMapping(value = "/pay")
    public ApiResult updateById(@RequestBody VipPayDto vipPayDto) throws Exception {
        TVipConfig byId = vipConfigService.getById(1);
        BigDecimal money = BigDecimal.ZERO;
        switch (vipPayDto.getType()){
            case 1: money =byId.getPersonalVipCost();break;
            case 2: money = byId.getPersonalVipRenew();break;
            case 3: money = byId.getEnterpriseVipCost();break;
            case 4: money = byId.getEnterpriseVipRenew();break;
        }
        Long userId = loginInfoUtil.getUserId();
        return vipConfigService.pay(userId,money,vipPayDto.getMonth(),vipPayDto.getPayType(),vipPayDto.getType());
    }
//    @ApiOperation(value = "查询还差多少升级下一会员")
//    @PostMapping(value = "/viplevel")
//    public ApiResult viplevel(){
//        Long userId = loginInfoUtil.getUserId();
//        TUser byId = userService.getById(userId);
 
//
//
//    }
 
 
 
 
}