“mitao”
2025-12-22 7ce3c22d4bf8fae793379fed1ca22c05e822ce7e
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
package com.ruoyi.web.controller.api;
 
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.RefundAuditDto;
import com.ruoyi.system.export.TPhysicalGoodsImport;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.BigGiftPackageQuery;
import com.ruoyi.system.service.TAppUserService;
import com.ruoyi.system.service.TBigGiftPackageOrderService;
import com.ruoyi.system.service.TBigGiftPackageService;
import com.ruoyi.system.service.TRefundApplicationService;
import com.ruoyi.system.vo.TRefundApplicationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
 
/**
 * <p>
 * 退款申请 前端控制器
 * </p>
 *
 * @author xiaochen
 * @since 2025-12-08
 */
@RestController
@RequestMapping("/t-refund-application")
@Api(tags = "(嘉视达)退款申请")
public class TRefundApplicationController {
    private final TRefundApplicationService tRefundApplicationService;
    private final TokenService tokenService;
    private final TBigGiftPackageOrderService tBigGiftPackageOrderService;
    private final TAppUserService tAppUserService;
    private final TBigGiftPackageService tBigGiftPackageService;
 
    public TRefundApplicationController(TRefundApplicationService tRefundApplicationService, TokenService tokenService, TBigGiftPackageOrderService tBigGiftPackageOrderService, TAppUserService tAppUserService, TBigGiftPackageService tBigGiftPackageService) {
        this.tRefundApplicationService = tRefundApplicationService;
        this.tokenService = tokenService;
        this.tBigGiftPackageOrderService = tBigGiftPackageOrderService;
        this.tAppUserService = tAppUserService;
        this.tBigGiftPackageService = tBigGiftPackageService;
    }
 
 
    @ApiOperation(value = "退款申请列表")
    @PostMapping(value = "/pageRefundList")
    public R<Page<TBigGiftPackageOrder>> pageRefundList(@RequestBody BigGiftPackageQuery query) {
        Page<TBigGiftPackageOrder> page = tRefundApplicationService.pageRefundList(query);
        return R.ok(page);
    }
 
 
    @ApiOperation(value = "退款申请详情")
    @GetMapping(value = "/refundDetail/{id}")
    public R<TRefundApplicationVo> refundDetail(@PathVariable Integer id) {
        TRefundApplication refundApplication = tRefundApplicationService.getById(id);
        TRefundApplicationVo vo = new TRefundApplicationVo();
        vo.setId(refundApplication.getId());
        vo.setBigGiftPackageOrderId(refundApplication.getBigGiftPackageOrderId());
 
        // 订单信息
        TBigGiftPackageOrder order = tBigGiftPackageOrderService.getById(refundApplication.getBigGiftPackageOrderId());
        vo.setCode(order.getCode());
        vo.setCreateTime(order.getCreateTime());
        vo.setOrderPrice(order.getOrderPrice());
 
        // 用户信息
        TAppUser appUser = tAppUserService.getById(order.getAppUserId());
        vo.setUserName(appUser.getName());
        vo.setPhone(appUser.getPhone());
 
 
        // 商品信息
        TBigGiftPackage tBigGiftPackage = tBigGiftPackageService.getById(order.getBigGiftPackageId());
        vo.setBigGiftPackageName(tBigGiftPackage.getName());
        vo.setBigGiftPackageCover(tBigGiftPackage.getCoverImage());
        vo.setBigGiftPackagePrice(tBigGiftPackage.getTotalPrice());
        vo.setBigGiftPackageIntro(tBigGiftPackage.getIntroduction());
 
        // 销量
        long count = tBigGiftPackageOrderService.count(new LambdaQueryWrapper<TBigGiftPackageOrder>().eq(TBigGiftPackageOrder::getBigGiftPackageId, order.getBigGiftPackageId()).ne(TBigGiftPackageOrder::getStatus, 5));
        vo.setBigGiftPackageSales((int)count);
 
        // 支付信息
        vo.setStatus(order.getStatus());
        vo.setOrderAmount(order.getOrderPrice());
        vo.setFinalPayment(order.getFinalPayment());
        vo.setPaidTime(order.getFinalPaymentTime());
        vo.setRemark(order.getRemark());
 
        // 退款信息
        vo.setRefundReason(refundApplication.getRefundReason());
        vo.setVoucherPicture(refundApplication.getVoucherPicture());
        vo.setRefundStatus(refundApplication.getStatus());
 
        // 审核信息
        vo.setAuditRemark(refundApplication.getAuditRemark());
        vo.setAuditTime(refundApplication.getAuditTime());
        return R.ok(vo);
    }
 
    @ApiOperation(value = "退款申请删除")
    @DeleteMapping(value = "/delete/{id}")
    @Log(title = "退款申请-删除", businessType = BusinessType.DELETE)
    public R<String> delete(@PathVariable Integer id) {
        TRefundApplication refundApplication = tRefundApplicationService.getById(id);
        refundApplication.setDelFlag(1);
        tRefundApplicationService.updateById(refundApplication);
        return R.ok();
    }
 
    @ApiOperation(value = "退款申请审核")
    @PostMapping(value = "/refundAudit")
    @Log(title = "退款申请-审核", businessType = BusinessType.UPDATE)
    public R<String> refundAudit(@RequestBody RefundAuditDto dto) {
        TRefundApplication refundApplication = tRefundApplicationService.getById(dto.getId());
        refundApplication.setStatus(dto.getAuditStatus());
        refundApplication.setAuditTime(LocalDateTime.now());
        refundApplication.setAuditRemark(dto.getAuditRemark());
        Long userId = tokenService.getLoginUser().getUserId();
        refundApplication.setAuditUserId(userId);
        boolean b = tRefundApplicationService.updateById(refundApplication);
        if (b && dto.getAuditStatus()==2) {
            Integer bigGiftPackageOrderId = refundApplication.getBigGiftPackageOrderId();
            TBigGiftPackageOrder tBigGiftPackageOrder = tBigGiftPackageOrderService.getById(bigGiftPackageOrderId);
            tBigGiftPackageOrder.setStatus(5);
            tBigGiftPackageOrderService.updateById(tBigGiftPackageOrder);
        }
        return R.ok("操作成功");
    }
 
 
    @ApiOperation(value = "退款申请导出")
    @PostMapping(value = "/export")
    @Log(title = "退款申请-导出", businessType = BusinessType.EXPORT)
    public void exportRegistration(@RequestBody BigGiftPackageQuery query){
 
        List<TBigGiftPackageOrder> list = tRefundApplicationService.pageRefundExportList(query);
 
 
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TBigGiftPackageOrder.class, list);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        ServletOutputStream outputStream = null;
        try {
            String fileName = URLEncoder.encode("退款申请导出信息.xls", "utf-8");
            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
            response.setHeader("Pragma", "no-cache");
            response.setHeader("Cache-Control", "no-cache");
            outputStream = response.getOutputStream();
            workbook.write(outputStream);
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                outputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
 
}