无关风月
22 小时以前 4c9035836c18886883d3f69d8443c53d15b068fc
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package com.dsh.other.controller;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 
import com.dsh.other.entity.Protocol;
import com.dsh.other.entity.Store;
import com.dsh.other.feignclient.activity.CouponClient;
import com.dsh.other.feignclient.activity.model.Coupon;
import com.dsh.other.feignclient.activity.model.PointsMerchandise;
import com.dsh.other.model.*;
import com.dsh.other.service.IProtocolService;
import com.dsh.other.service.IVipService;
import com.dsh.other.service.StoreService;
import com.dsh.other.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author zhibing.pu
 * @Date 2023/8/1 14:02
 */
@Controller
@RequestMapping("/vip")
public class TVipController  {
 
    @Autowired
    private IVipService vipService;
    @Autowired
    private CouponClient couponClient;
    @Autowired
    private StoreService storeService;
 
 
 
    // APP查询所有上架的会员卡
    @ResponseBody
    @PostMapping("/listAll")
    public List<Vip> listAll() {
        List<Vip> list = vipService.lambdaQuery().eq(Vip::getStatus, 1).list();
        List<Coupon> coupons = couponClient.queryCouponAll();
        List<CouponCity> couponCityList = couponClient.queryAllCity();
        List<PointsMerchandise> pointsMerchandiseList = couponClient.queryAllPointGoods();
        List<CouponStore> storeList = couponClient.queryAllStore();
        List<Store> shopList = storeService.list();
        // 封装会员权益
        for (Vip vip : list) {
            List<CouponVipResp> couponVipRespList = new ArrayList<>();
            List<TicketVipResp> ticketVipRespList = new ArrayList<>();
            String couponJson = vip.getCouponJson();
            JSONArray couponJsonArray = JSONArray.parseArray(couponJson);
            for (Object o : couponJsonArray) {
                JSONObject couponJsonObject = (JSONObject) o;
                // 优惠券id
                Integer id = Integer.valueOf(couponJsonObject.getString("id"));
                // 优惠券数量
                Integer value = Integer.valueOf(couponJsonObject.getString("value"));
                Coupon coupon = coupons.stream().filter(e -> e.getId().equals(id)).findFirst().orElse(new Coupon());
                CouponVipResp couponVipResp = new CouponVipResp();
                couponVipResp.setId(coupon.getId());
                couponVipResp.setName(coupon.getName());
                couponVipResp.setType(coupon.getType());
                couponVipResp.setUseCondition(coupon.getUseScope());
                couponVipResp.setCount(value);
                switch (coupon.getUseScope()) {
                    case 1:
                        couponVipResp.setAvailable("全国通用");
                        break;
                    case 2:
                        couponVipResp.setAvailable("指定城市可用");
                        List<CouponCity> couponId = couponCityList.stream().filter(e -> e.getCouponId().equals(id))
                                .collect(Collectors.toList());
                        StringBuilder stringBuilder = new StringBuilder();
                        for (CouponCity couponCity : couponId) {
                            stringBuilder.append(couponCity.getCity());
                        }
                        couponVipResp.setCityOrStore(String.valueOf(stringBuilder));
                        break;
                    case 3:
                        couponVipResp.setAvailable("指定门店可用");
                        // 门店ids
                        List<Integer> storeIds = storeList.stream().filter(e -> e.getCouponId().equals(id))
                                .map(CouponStore::getStoreId).collect(Collectors.toList());
                        StringBuilder storeNames = new StringBuilder("");
 
                        if (!storeIds.isEmpty()) {
                            List<Store> stores = shopList.stream().filter(e -> storeIds.contains(e.getId())).collect(Collectors.toList());
                            for (Store store : stores) {
                                storeNames.append(store.getName()).append(",");
                            }
                            // 去除最后一位
                            StringBuilder res = storeNames.deleteCharAt(storeNames.length() - 1);
                            couponVipResp.setCityOrStore(res.toString());
                        } else {
                            couponVipResp.setCityOrStore("无可用门店");
                        }
                        break;
                    default:
                        break;
                }
                couponVipResp.setInstructionsForUse(coupon.getIllustrate());
                ConponJsonRuleModel ruleModel = new ConponJsonRuleModel();
                JSONObject jsonObject = JSON.parseObject(coupon.getContent());
                switch (coupon.getType()) {
                    case 1:
//                            满减券
                        Double num1 = jsonObject.getDouble("conditionalAmount");
                        Double num2 = jsonObject.getDouble("deductionAmount");
                        ruleModel.setConditionalAmount("满" + num1 + "可用");
                        ruleModel.setDeductionAmount("¥ " + num2);
                        ruleModel.setExperienceName("");
                        break;
                    case 2:
//                            代金券
                        Double jsonObjectDouble = jsonObject.getDouble("conditionalAmount");
                        ruleModel.setConditionalAmount("");
                        ruleModel.setDeductionAmount("¥ " + jsonObjectDouble);
                        ruleModel.setExperienceName("");
                        break;
                    case 3:
//                            体验券
                        ruleModel.setConditionalAmount("");
                        ruleModel.setDeductionAmount("");
                        ruleModel.setExperienceName(jsonObject.getString("experienceName"));
                        break;
                        case 4:
//                            抵扣券
                        ruleModel.setConditionalAmount("");
                        ruleModel.setDeductionAmount("");
                            PointsMerchandise pointsMerchandise = pointsMerchandiseList.stream().findFirst().orElse(null);
                            if (pointsMerchandise!=null){
                                ruleModel.setExperienceName(pointsMerchandise.getName());
                            }
                        break;
                    default:
                        break;
                }
                couponVipResp.setRuleModel(ruleModel);
 
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                couponVipResp.setEffectiveTime(simpleDateFormat.format(coupon.getEndTime()));
                couponVipResp.setStartTime(simpleDateFormat.format(coupon.getStartTime()));
                couponVipRespList.add(couponVipResp);
            }
            vip.setCouponList(couponVipRespList);
            String ticketJson = vip.getTicketJson();
            JSONArray ticketJsonArray = JSONArray.parseArray(ticketJson);
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
 
            for (Object o : ticketJsonArray) {
                JSONObject ticketJsonObject = (JSONObject) o;
                TicketVipResp ticketVipResp = new TicketVipResp();
                Integer count = ticketJsonObject.getInteger("count");
                ticketVipResp.setName(ticketJsonObject.getString("name"));
                ticketVipResp.setTime(ticketJsonObject.getInteger("time"));
                ticketVipResp.setCount(ticketJsonObject.getInteger("count"));
                ticketVipResp.setStartTime(simpleDateFormat.format(new Date()));
                Date date = new Date();
                // 给这个date加X天
                date.setTime(date.getTime() + ticketJsonObject.getInteger("time") * 24 * 60 * 60 * 1000);
                ticketVipResp.setEffectiveTime(simpleDateFormat.format(date));
                ticketVipRespList.add(ticketVipResp);
            }
            vip.setTicketList(ticketVipRespList);
        }
        return list;
    }
    @Autowired
    private IProtocolService protocolService;
    @ResponseBody
    @PostMapping("/getAgreement")
    public String getAgreement() {
        Protocol one = protocolService.lambdaQuery().eq(Protocol::getType, 6).one();
        if (one==null){
            Protocol protocol = new Protocol();
            protocol.setType(6);
            protocol.setContent("");
            protocol.setInsertTime(new Date());
            protocolService.save( protocol);
            return  "";
        }else{
            return one.getContent();
 
        }
    }
 
    @ResponseBody
    @PostMapping("/getVipByIds")
    public List<Vip> getVipByIds(@RequestBody String ids) {
        List<Vip> list = vipService.lambdaQuery().in(Vip::getId, Arrays.asList(ids.split(","))).list();
        return list;
    }
}