Helius
2022-03-09 38179780b2f728abe6dd0e5aaa284c6ee6aa8380
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
package com.xcong.excoin.modules.otc.controller;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcong.excoin.common.LoginUserUtils;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.member.dao.MemberDao;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.otc.dao.OtcReturnMoneyDao;
import com.xcong.excoin.modules.otc.dto.*;
import com.xcong.excoin.modules.otc.service.OtcOrderService;
import com.xcong.excoin.modules.otc.vo.BuyOrderDetailVo;
import com.xcong.excoin.modules.otc.vo.OrderListVo;
import com.xcong.excoin.modules.otc.vo.SaleOrderDetailVo;
import com.xcong.excoin.modules.otc.vo.TeamVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
 
@Slf4j
@Validated
@RestController
@RequestMapping(value = "/api/otcOrder")
@RequiredArgsConstructor
@Api(value = "OtcOrderController", tags = "otc用户订单接口类")
public class OtcOrderController {
 
    private final OtcOrderService otcOrderService;
    private final OtcReturnMoneyDao otcReturnMoneyDao;
 
    @ApiOperation(value = "我要购买")
    @PostMapping(value = "/buy")
    public Result buy(@RequestBody OtcOrderAddDto orderAddDto) {
        return otcOrderService.buyOrder(orderAddDto);
    }
 
    @ApiOperation(value = "我要出售")
    @PostMapping(value = "/sale")
    public Result sale(@RequestBody OtcOrderAddDto orderAddDto) {
        return otcOrderService.saleOrder(orderAddDto);
    }
 
    @ApiOperation(value = "用户订单列表")
    @ApiResponses({
            @ApiResponse(code = 200, message = "success", response = OrderListVo.class)
    })
    @PostMapping(value = "/orderList")
    public Result orderList(@RequestBody OrderListDto orderListDto) {
        IPage<OrderListVo> page = otcOrderService.findOrderListInPage(orderListDto);
        return Result.ok(page.getRecords());
    }
 
    @ApiOperation(value = "买单 - 订单详情")
    @ApiResponses({
            @ApiResponse(code = 200, message = "success", response = BuyOrderDetailVo.class)
    })
    @GetMapping(value = "/buyOrderDetail/{id}")
    public Result buyOrderDetail(@PathVariable("id") Long id) {
        return otcOrderService.findBuyOrderDetail(id);
    }
 
    @ApiOperation(value = "卖单 - 订单详情")
    @ApiResponses({
            @ApiResponse(code = 200, message = "success", response = SaleOrderDetailVo.class)
    })
    @GetMapping(value = "/saleOrderDetail/{id}")
    public Result saleOrderDetail(@PathVariable("id") Long id) {
        return otcOrderService.findSaleOrderDetail(id);
    }
 
    @ApiOperation(value = "已付款,请放币")
    @PostMapping(value = "/hasPay")
    public Result hasPay(@RequestBody HasPayDto hasPayDto) {
        otcOrderService.hasPay(hasPayDto);
        return Result.ok("操作成功");
    }
 
    @ApiOperation(value = "确认收款")
    @PostMapping(value = "/finishOrder/{id}")
    public Result finishOrder(@PathVariable("id") Long id) {
        otcOrderService.finishOrder(id);
        return Result.ok("操作成功");
    }
 
    @ApiOperation(value = "取消订单")
    @PostMapping(value = "/cancelUserOrder/{id}")
    public Result cancelUserOrder(@PathVariable("id") Long id) {
        otcOrderService.cancelOrder(id);
        return Result.ok("操作成功");
    }
 
    @ApiOperation(value = "申诉")
    @PostMapping(value = "/orderApeal")
    public Result orderApeal(@RequestBody OrderApealDto orderApealDto) {
        return otcOrderService.orderApeal(orderApealDto);
    }
 
    @ApiOperation(value = "获取我的团队")
    @PostMapping(value = "/findTeamList")
    public Result teamList(@RequestBody TeamDto teamDto) {
        Page<TeamVo> page = new Page<>(teamDto.getPageNum(), teamDto.getPageSize());
 
        MemberEntity member = LoginUserUtils.getAppLoginUser();
        IPage<TeamVo> data = otcReturnMoneyDao.selectMyTeamAmountInPage(member.getInviteId(), member.getId(), page);
        BigDecimal totalAmount = otcReturnMoneyDao.selectTotalAmount(member.getId());
 
        Map<String, Object> result = new HashMap<>();
        result.put("totalCnt", data.getTotal());
        result.put("totalAmount", totalAmount == null ? BigDecimal.ZERO : totalAmount.setScale(4, BigDecimal.ROUND_DOWN));
        result.put("result", data.getRecords());
        return Result.ok(result);
    }
}