无关风月
11 小时以前 28a60b0977d66b75fb9a2c3306840bc18ec271f6
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
package com.dsh.account.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dsh.account.entity.RechargeRecords;
import com.dsh.account.entity.TAppUser;
import com.dsh.account.entity.VipPayment;
import com.dsh.account.model.IncomeQuery;
import com.dsh.account.model.dto.VipPaymentDto;
import com.dsh.account.model.dto.VipRefundDto;
import com.dsh.account.model.query.RechargeRecordsQuery;
import com.dsh.account.model.vo.RechargeRecordsVO;
import com.dsh.account.model.vo.VipPaymentListVO;
import com.dsh.account.service.*;
import io.swagger.models.auth.In;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
 
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * 充值记录控制器
 */
@RestController
@RequestMapping("")
public class FinanceController {
    @Autowired
    private RechargeRecordsService rechargeRecordsService;
    @Autowired
    private IVipPaymentService vipPaymentService;
    @Autowired
    private TAppUserService appUserService;
 
 
    /**
     * 充值记录列表数据
     */
    @ResponseBody
    @RequestMapping("/finance/rechargeList")
    public List<RechargeRecordsVO> rechargeList(@RequestBody RechargeRecordsQuery query) {
        List<RechargeRecordsVO> rechargeRecordsVOS = rechargeRecordsService.rechargeList(query);
        for (RechargeRecordsVO rechargeRecordsVO : rechargeRecordsVOS) {
            TAppUser byId = appUserService.getById(rechargeRecordsVO.getAppUserId());
            if (byId == null) continue;
            Date vipEndTime = byId.getVipEndTime();
            if (vipEndTime == null) {
                rechargeRecordsVO.setType(2);
                continue;
            }
            if (rechargeRecordsVO.getPayTime().after(vipEndTime)) {
                rechargeRecordsVO.setType(2);
            } else {
                rechargeRecordsVO.setType(1);
            }
        }
        return rechargeRecordsVOS;
    }
 
    /**
     * 数据统计-充值记录列表数据
     */
    @ResponseBody
    @RequestMapping("/finance/rechargeList1")
    public List<RechargeRecords> rechargeList1(@RequestBody RechargeRecordsQuery query) {
        List<RechargeRecords> payStatus = rechargeRecordsService.list(new QueryWrapper<RechargeRecords>().eq("payStatus", 2));
        for (RechargeRecords list : payStatus) {
            TAppUser byId = appUserService.getById(list.getAppUserId());
            Integer addUserId = byId.getAddUserId();
 
        }
        return payStatus;
    }
 
    /**
     * 加入会员列表数据
     */
    @ResponseBody
    @RequestMapping("/finance/vipPaymentList")
    public List<VipPayment> registrationList(@RequestBody IncomeQuery query) {
        return rechargeRecordsService.listAll(query);
    }
    /**
     * 退费
     */
    @ResponseBody
    @RequestMapping("/finance/refund")
    public String refund(@RequestBody VipRefundDto vipRefundDto) throws ParseException {
        VipPayment vipPayment = vipPaymentService.getById(vipRefundDto.getId());
        if (vipPayment==null){
            return "500";
        }
        Integer appUserId = vipPayment.getAppUserId();
        TAppUser appUser = appUserService.getById(appUserId);
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date parse = simpleDateFormat.parse(vipRefundDto.getEndTime() + " 00:00:00");
        appUser.setVipEndTime( parse);
        if (parse.before(new Date())){
            appUser.setIsVip(0);
        }
        appUserService.updateById(appUser);
        vipPayment.setState(3);
        vipPaymentService.updateById(vipPayment);
        return "200";
    }
 
    @ResponseBody
    @PostMapping("/finance/vipPayment")
    List<VipPaymentListVO> vipPayment(@RequestBody VipPaymentDto vipPaymentDto){
        List<VipPaymentListVO> vipPaymentListVOS = new ArrayList<>();
 
        List<Integer> payStatus = new ArrayList<>();
        payStatus.add(2);
        LambdaQueryWrapper<VipPayment> vipPaymentLambdaQueryWrapper = new LambdaQueryWrapper<>();
        vipPaymentLambdaQueryWrapper.in(vipPaymentDto.getUserIds()!=null&&!vipPaymentDto.getUserIds().isEmpty(),VipPayment::getAppUserId, vipPaymentDto.getUserIds());
        vipPaymentLambdaQueryWrapper.in(vipPaymentDto.getVipIds()!=null&&!vipPaymentDto.getVipIds().isEmpty(),VipPayment::getVipId, vipPaymentDto.getVipIds());
        vipPaymentLambdaQueryWrapper.in(VipPayment::getPayStatus,payStatus);
        vipPaymentLambdaQueryWrapper.ge(StringUtils.hasLength(vipPaymentDto.getStartTime()), VipPayment::getInsertTime, vipPaymentDto.getStartTime());
        vipPaymentLambdaQueryWrapper.le(StringUtils.hasLength(vipPaymentDto.getEndTime()), VipPayment::getInsertTime, vipPaymentDto.getEndTime());
        if (vipPaymentDto.getIsRefund()!=null&&vipPaymentDto.getIsRefund()==1){
            payStatus.add(3);
        }
        List<VipPayment> list = vipPaymentService.list(vipPaymentLambdaQueryWrapper);
        // 使用 Stream + 手动拷贝提升性能和可读性(或使用 MapStruct)
        vipPaymentListVOS = list.stream().map(vipDetail -> {
                VipPaymentListVO vo = new VipPaymentListVO();
            BeanUtils.copyProperties(vipDetail,vo); // 注意参数顺序是否正确
            return vo;
        }).collect(Collectors.toList());
        for (VipPaymentListVO vipPaymentListVO : vipPaymentListVOS) {
            if (vipPaymentListVO.getPayStatus()==2){
                vipPaymentListVO.setIsRefund(0);
            }else {
                vipPaymentListVO.setIsRefund(1);
            }
        }
        return vipPaymentListVOS;
    }
}