gongzuming
2024-09-19 a768dc3daa04d35fedfbe75c0a59b9b2545b85c4
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
package com.mzl.flower.web.customer;
 
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzl.flower.base.BaseController;
import com.mzl.flower.base.R;
import com.mzl.flower.base.ReturnDataDTO;
import com.mzl.flower.config.exception.ValidationException;
import com.mzl.flower.dto.request.payment.OrderEvaluateDTO;
import com.mzl.flower.dto.request.payment.OrderQueryDTO;
import com.mzl.flower.dto.response.payment.CustomerOrderCountDTO;
import com.mzl.flower.dto.response.payment.OrderDTO;
import com.mzl.flower.dto.response.payment.OrderItemListDTO;
import com.mzl.flower.dto.response.payment.OrderListDTO;
import com.mzl.flower.entity.payment.Order;
import com.mzl.flower.service.payment.OrderService;
import com.mzl.flower.service.payment.UserPaymentV3Service;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.util.List;
 
@RestController
@RequestMapping("/api/customer/order")
@Api(value = "订单管理-花店", tags = "订单管理-花店")
@Validated
@Slf4j
public class OrderCustomerController extends BaseController {
 
    @Autowired
    private OrderService orderService;
 
    @Autowired
    private UserPaymentV3Service paymentV3Service;
 
    @GetMapping("/list")
    @ApiOperation(value = "查询订单列表")
    public ResponseEntity<ReturnDataDTO<Page<OrderListDTO>>> selectOrderList(Page page, OrderQueryDTO dto){
        return returnData(R.SUCCESS.getCode(), orderService.selectCustomerOrderList(page, dto));
    }
 
    @GetMapping("/list/view")
    @ApiOperation(value = "订单详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<OrderDTO>> getOrderInfo(String id){
        return returnData(R.SUCCESS.getCode(), orderService.getOrderInfo(id));
    }
 
    @GetMapping("/item/list")
    @ApiOperation(value = "订单商品明细")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<List<OrderItemListDTO>>> getPtCuOrderItems(String id){
        return returnData(R.SUCCESS.getCode(), orderService.getPtCuOrderItems(id));
    }
 
    @GetMapping("/receive/confirm")
    @ApiOperation(value = "确认收货")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> confirmOrderReceive(String id){
        Order o = orderService.confirmOrderReceive(id);
        orderService.processAfterReceive(o);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @GetMapping("/payAgain")
    @ApiOperation(value = "重新支付")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query")
    })
    public ResponseEntity<ReturnDataDTO<?>> payAgain(String id){
        boolean f = paymentV3Service.checkOrderStatus(id, true);
        if(f){
            throw new ValidationException("订单不可再支付");
        }
        return returnData(R.SUCCESS.getCode(), paymentV3Service.payAgain(id));
    }
 
    @GetMapping(value = "/refund")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    @ApiOperation(value = "退款")
    public ResponseEntity<ReturnDataDTO> refundOrder(String id) {
        orderService.refundCheck(id);
        paymentV3Service.refundOrder(id);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    /*@GetMapping(value = "/refund/check")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    @ApiOperation(value = "查询退款")
    public ResponseEntity<ReturnDataDTO> refundQuery(String id) {
        return returnData(R.SUCCESS.getCode(), paymentV3Service.refundQuery(id));
    }*/
 
    @PostMapping("/evaluate")
    @ApiOperation(value = "评价")
    public ResponseEntity<ReturnDataDTO> evaluateOrder(@RequestBody OrderEvaluateDTO dto) {
        orderService.evaluateOrder(dto);
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @GetMapping(value = "/count/{status}")
    @ApiOperation(value = "订单数量")
    public ResponseEntity<ReturnDataDTO<Integer>> getMyOrderStatusCount(@PathVariable String status) {
        return returnData(R.SUCCESS.getCode(), orderService.getMyOrderStatusCount(status));
    }
 
    @GetMapping(value = "/statistics/count")
    @ApiOperation(value = "订单数量统计")
    public ResponseEntity<ReturnDataDTO<CustomerOrderCountDTO>> getCustomerOrderCount() {
        return returnData(R.SUCCESS.getCode(), orderService.getCustomerOrderCount());
    }
 
    @GetMapping(value = "/cancel")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    @ApiOperation(value = "取消订单")
    public ResponseEntity<ReturnDataDTO> cancelOrder(String id) {
        boolean f = paymentV3Service.checkOrderStatus(id);
        if(!f){
            paymentV3Service.cancelOrder(id);
        }
        return returnData(R.SUCCESS.getCode(), null);
    }
 
    @GetMapping(value = "/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "订单id", required = true, dataType = "String", paramType = "query"),
    })
    @ApiOperation(value = "删除订单")
    public ResponseEntity<ReturnDataDTO> deleteOrder(String id) {
        orderService.deleteOrder(id);
        return returnData(R.SUCCESS.getCode(), null);
    }
}