无关风月
11 小时以前 16207f06b1aae069c05657c178855388a2bcf5b2
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
package com.dsh.guns.modular.system.controller.code;
 
import cn.hutool.core.collection.CollUtil;
import com.dsh.course.feignClient.account.AppUserClient;
import com.dsh.course.feignClient.account.VipPaymentClient;
import com.dsh.course.feignClient.account.model.QueryByNamePhone;
import com.dsh.course.feignClient.account.model.TAppUser;
import com.dsh.course.feignClient.activity.CouponClient;
import com.dsh.course.feignClient.activity.model.HuiminPayQuery;
import com.dsh.guns.core.base.controller.BaseController;
import com.dsh.guns.core.base.tips.SuccessTip;
import com.dsh.guns.modular.system.model.*;
import com.dsh.guns.modular.system.model.dto.VipPaymentDto;
import com.dsh.guns.modular.system.model.dto.VipRefundDto;
import com.dsh.guns.modular.system.model.vo.VipPaymentListVO;
import com.dsh.guns.modular.system.service.*;
import com.dsh.guns.modular.system.util.DateUtil;
import com.dsh.guns.modular.system.util.ExcelUtil;
import com.dsh.guns.modular.system.util.ResultUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author zhibing.pu
 * @Date 2023/8/1 14:02
 */
@Controller
@RequestMapping("/vipDetail")
public class TVipDetailController extends BaseController {
 
    @Autowired
    private IVipService vipService;
    @Autowired
    private CouponClient couponClient;
    @Autowired
    private IStoreService storeService;
    @Autowired
    private AppUserClient appUserClient;
    @Autowired
    private VipPaymentClient vipPaymentClient;
    @Autowired
    private ITSiteService siteService;
    @Autowired
    private TOperatorService operatorService;
    private String PREFIX = "/system/vipPayment/";
 
 
    /**
     * 跳转到优惠券管理首页
     */
    @RequestMapping("")
    public String index(Model model) {
        return PREFIX + "vip_payment.html";
    }
 
    /**
     * 获取 会员权益使用明细列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public List<VipPaymentListVO> list(String appUserName
            , String phone, String vipName
            , Integer isRefund
            , String time
            ) {
        VipPaymentDto vipPaymentDto = new VipPaymentDto();
        if (StringUtils.hasLength(vipName)){
            List<Integer> vipIds = vipService.lambdaQuery().like(Vip::getVipName, vipName)
                    .list().stream().map(Vip::getId).collect(Collectors.toList());
            if (vipIds.isEmpty()){
                vipIds.add(-1);
            }
            vipPaymentDto.setVipIds(vipIds);
        }
        if (StringUtils.hasLength(phone)){
            QueryByNamePhone queryByNamePhone = new QueryByNamePhone();
            queryByNamePhone.setPhone( phone);
            List<Integer> userIds = appUserClient.queryByNamePhone(queryByNamePhone).stream().map(TAppUser::getId)
                    .collect(Collectors.toList());
 
            vipPaymentDto.setUserIds(userIds);
        }
        if (StringUtils.hasLength(appUserName)){
            QueryByNamePhone queryByNamePhone = new QueryByNamePhone();
            queryByNamePhone.setName( appUserName);
            List<Integer> userIds = appUserClient.queryByNamePhone(queryByNamePhone).stream().map(TAppUser::getId)
                    .collect(Collectors.toList());
            if (vipPaymentDto.getUserIds()!=null){
                // 取交集
                vipPaymentDto.setUserIds(vipPaymentDto.getUserIds().stream().filter(userIds::contains).collect(Collectors.toList()));
            }else{
                vipPaymentDto.setUserIds(userIds);
            }
        }
        if (StringUtils.hasLength(appUserName)|| StringUtils.hasLength(phone)){
            if (vipPaymentDto.getUserIds().isEmpty()){
                List<Integer> userIds = vipPaymentDto.getUserIds();
                userIds.add(-1);
                vipPaymentDto.setUserIds(userIds);
            }
        }
        vipPaymentDto.setIsRefund(isRefund);
        if (StringUtils.hasLength(time)){
            String stareTime = null;
            String endTime = null;
            stareTime = time.split(" - ")[0] + " 00:00:00";
            endTime = time.split(" - ")[1] + " 23:59:59";
            vipPaymentDto.setStartTime(stareTime);
            vipPaymentDto.setEndTime(endTime);
        }
        QueryByNamePhone queryByNamePhone = new QueryByNamePhone();
        List<TAppUser> tAppUsers = appUserClient.queryByNamePhone(queryByNamePhone);
        List<Vip> vipList = vipService.list();
        List<VipPaymentListVO> res =vipPaymentClient.vipPayment(vipPaymentDto);
        for (VipPaymentListVO re : res) {
            Vip vip = vipList.stream().filter(e -> e.getId().equals(re.getVipId())).findFirst().orElse(null);
            if (vip!=null){
                re.setVipName(vip.getVipName());
                Integer timeType = vip.getTimeType();
                Integer time1 = vip.getTime();
                switch (timeType){
                    case 1:
                        re.setVipTime(time1 + "天");
                        break;
                    case 2:
                        re.setVipTime(time1 + "月");
                        break;
                    case 3:
                        re.setVipTime(time1 + "年");
                        break;
                }
            }
            re.setAmountValue("¥"+re.getAmount().toString());
            TAppUser appUser = tAppUsers.stream().filter(e -> e.getId().equals(re.getAppUserId())).findFirst().orElse(null);
            if (appUser!=null){
                re.setAppUserName(appUser.getName());
                re.setAppUserPhone(appUser.getName());
            }
        }
        return res;
    }
    /**
     * 导出会员卡订单
     * @param
     */
    @GetMapping("/export")
    public void exportData(String appUserName
            , String phone, String vipName
            , Integer isRefund
            , String time, HttpServletResponse response) {
        VipPaymentDto vipPaymentDto = new VipPaymentDto();
        if (StringUtils.hasLength(vipName)){
            List<Integer> vipIds = vipService.lambdaQuery().like(Vip::getVipName, vipName)
                    .list().stream().map(Vip::getId).collect(Collectors.toList());
            if (vipIds.isEmpty()){
                vipIds.add(-1);
            }
            vipPaymentDto.setVipIds(vipIds);
        }
        if (StringUtils.hasLength(phone)){
            QueryByNamePhone queryByNamePhone = new QueryByNamePhone();
            queryByNamePhone.setPhone( phone);
            List<Integer> userIds = appUserClient.queryByNamePhone(queryByNamePhone).stream().map(TAppUser::getId)
                    .collect(Collectors.toList());
 
            vipPaymentDto.setUserIds(userIds);
        }
        if (StringUtils.hasLength(appUserName)){
            QueryByNamePhone queryByNamePhone = new QueryByNamePhone();
            queryByNamePhone.setName( appUserName);
            List<Integer> userIds = appUserClient.queryByNamePhone(queryByNamePhone).stream().map(TAppUser::getId)
                    .collect(Collectors.toList());
            if (vipPaymentDto.getUserIds()!=null){
                // 取交集
                vipPaymentDto.setUserIds(vipPaymentDto.getUserIds().stream().filter(userIds::contains).collect(Collectors.toList()));
            }else{
                vipPaymentDto.setUserIds(userIds);
            }
        }
        if (StringUtils.hasLength(appUserName)|| StringUtils.hasLength(phone)){
            if (vipPaymentDto.getUserIds().isEmpty()){
                List<Integer> userIds = vipPaymentDto.getUserIds();
                userIds.add(-1);
                vipPaymentDto.setUserIds(userIds);
            }
        }
        vipPaymentDto.setIsRefund(isRefund);
        if (StringUtils.hasLength(time)){
            String stareTime = null;
            String endTime = null;
            stareTime = time.split(" - ")[0] + " 00:00:00";
            endTime = time.split(" - ")[1] + " 23:59:59";
            vipPaymentDto.setStartTime(stareTime);
            vipPaymentDto.setEndTime(endTime);
        }
        QueryByNamePhone queryByNamePhone = new QueryByNamePhone();
        List<TAppUser> tAppUsers = appUserClient.queryByNamePhone(queryByNamePhone);
        List<Vip> vipList = vipService.list();
        List<VipPaymentListVO> res =vipPaymentClient.vipPayment(vipPaymentDto);
        for (VipPaymentListVO re : res) {
            Vip vip = vipList.stream().filter(e -> e.getId().equals(re.getVipId())).findFirst().orElse(null);
            if (vip!=null){
                re.setVipName(vip.getVipName());
                Integer timeType = vip.getTimeType();
                Integer time1 = vip.getTime();
                switch (timeType){
                    case 1:
                        re.setVipTime(time1 + "天");
                        break;
                    case 2:
                        re.setVipTime(time1 + "月");
                        break;
                    case 3:
                        re.setVipTime(time1 + "年");
                        break;
                }
            }
            re.setAmountValue("¥"+re.getAmount().toString());
            TAppUser appUser = tAppUsers.stream().filter(e -> e.getId().equals(re.getAppUserId())).findFirst().orElse(null);
            if (appUser!=null){
                re.setAppUserName(appUser.getName());
                re.setAppUserPhone(appUser.getName());
            }
        }
 
        String[] titleArr = {"订单编号", "用户姓名", "联系电话", "会员卡名称", "时长", "金额", "下单时间", "是否退费", "备注"};
        String[][] values = new String[res.size()][];
        for (int i = 0; i < res.size(); i++) {
            VipPaymentListVO vipPaymentListVO = res.get(i);
            values[i] = new String[titleArr.length];
            values[i][0] = vipPaymentListVO.getCode();
            values[i][1] = vipPaymentListVO.getAppUserName();
            values[i][2] = vipPaymentListVO.getAppUserPhone();
            values[i][3] = vipPaymentListVO.getVipName();
            values[i][4] = vipPaymentListVO.getVipTime();
            values[i][5] = vipPaymentListVO.getAmountValue();
            values[i][6] = DateUtil.format(vipPaymentListVO.getInsertTime(), "yyyy-MM-dd HH:mm:ss");
            values[i][7] = vipPaymentListVO.getIsRefund() == 1 ? "是" : "否";
            values[i][8] = vipPaymentListVO.getRemark().toString();
        }
        try {
            HSSFWorkbook wb = ExcelUtil.getHSSFWorkbook("会员卡订单", titleArr, values, null);
            ExcelUtil.setResponseHeader(response, "会员卡订单.xls");
            OutputStream os = response.getOutputStream();
            wb.write(os);
            os.flush();
            os.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 退费
     */
    @RequestMapping(value = "/refund")
    @ResponseBody
    public Object list(@RequestBody VipRefundDto vipRefundDto) {
        String code =vipPaymentClient.refund(vipRefundDto);
        if (code!=null&& code.equals("200")){
            return ResultUtil.success();
        }else{
            return ResultUtil.error("退费失败");
        }
    }
 
 
}