hejianhao
2026-08-28 cc31d303d12f9c7cd2c4574351b67db04069ae0d
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
package com.tcm.training.admin.member.controller;
 
import com.tcm.training.admin.common.ApiResponse;
import com.tcm.training.admin.common.PageResponse;
import com.tcm.training.admin.member.service.MemberPurchaseOrderAppService;
import com.tcm.training.admin.member.vo.MemberPurchaseOrderListItemVO;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
 
@Validated
@RestController
@RequestMapping({"/api/v1", "/api"})
public class MemberPurchaseOrderController {
 
    private final MemberPurchaseOrderAppService memberPurchaseOrderAppService;
 
    public MemberPurchaseOrderController(MemberPurchaseOrderAppService memberPurchaseOrderAppService) {
        this.memberPurchaseOrderAppService = memberPurchaseOrderAppService;
    }
 
    @GetMapping("/member/purchase-orders")
    public ApiResponse<PageResponse<MemberPurchaseOrderListItemVO>> page(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int pageSize,
            @RequestParam(required = false) String orderNo,
            @RequestParam(required = false) String userPhone,
            @RequestParam(required = false) String memberType,
            @RequestParam(required = false) String paymentMethod,
            @RequestParam(required = false) String status,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdFrom,
            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdTo) {
        return ApiResponse.ok(memberPurchaseOrderAppService.page(
                page, pageSize, orderNo, userPhone, memberType, paymentMethod, status, createdFrom, createdTo
        ));
    }
 
    @GetMapping("/member/purchase-orders/export")
    public void export(HttpServletResponse response,
                       @RequestParam(required = false) String orderNo,
                       @RequestParam(required = false) String userPhone,
                       @RequestParam(required = false) String memberType,
                       @RequestParam(required = false) String paymentMethod,
                       @RequestParam(required = false) String status,
                       @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdFrom,
                       @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime createdTo) throws IOException {
        memberPurchaseOrderAppService.export(orderNo, userPhone, memberType, paymentMethod, status, createdFrom, createdTo, response);
    }
 
    @PostMapping("/member/purchase-orders/{id}/refund")
    public ApiResponse<Void> refund(@PathVariable Long id) {
        memberPurchaseOrderAppService.refund(id);
        return ApiResponse.ok(null);
    }
 
    @DeleteMapping("/member/purchase-orders/{id}")
    public ApiResponse<Void> delete(@PathVariable Long id) {
        memberPurchaseOrderAppService.delete(id);
        return ApiResponse.ok(null);
    }
}