xuhy
2025-04-18 800a7e19d1c16aa20443ffdc6d68a9e0da0bbd68
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package com.ruoyi.user.controller;
 
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.admin.api.entity.Prize;
import com.ruoyi.admin.api.feignClient.AdminClient;
import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.GlobalException;
import com.ruoyi.common.core.utils.GaoDeMapUtil;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.vo.CityInfoVO;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.api.entity.Order;
import com.ruoyi.order.api.entity.ServeRecord;
import com.ruoyi.order.api.feignClient.OrderClient;
import com.ruoyi.order.api.feignClient.ServeRecordClient;
import com.ruoyi.system.api.model.LoginUserInfo;
import com.ruoyi.user.entity.RecoveryServe;
import com.ruoyi.user.entity.RecoveryServePrice;
import com.ruoyi.user.request.OrderRequest;
import com.ruoyi.user.service.OrderService;
import com.ruoyi.user.service.RecoveryServePriceService;
import com.ruoyi.user.service.RecoveryServeService;
import com.ruoyi.user.service.UserService;
import com.ruoyi.user.vo.OrderDetailVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.kafka.KafkaProperties;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
 
/**
 * <p>
 * 订单管理 前端控制器
 * </p>
 *
 * @author hjl
 * @since 2024-06-07
 */
@RestController
@RequestMapping("/order")
@Api(tags = {"用户端-订单"})
public class OrderController {
 
    @Resource
    private RecoveryServeService recoveryServeService;
    @Resource
    private RecoveryServePriceService recoveryServePriceService;
    @Resource
    private AdminClient adminClient;
    @Resource
    private TokenService tokenService;
    @Resource
    private OrderClient orderClient;
    @Resource
    private OrderService orderService;
    @Resource
    private ServeRecordClient serveRecordClient;
 
    @GetMapping("/orderList")
    @ApiOperation(value = "订单列表", tags = {"用户端-订单"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "状态(-1:全部;0:派单中;1:待上门;2:待完工;3:已完结;4:已取消;5:已改派)", name = "state", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "页码", name = "pageNum", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "条数", name = "pageSize", dataType = "Integer", required = true)
    })
    public R<IPage<Order>> orderList(@RequestParam Integer state,
                                     @RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        IPage<Order> data = orderClient.orderListByUser(loginUser.getUserid(), state, pageNum, pageSize).getData();
        List<Integer> ids = data.getRecords().stream().map(Order::getServeId).collect(Collectors.toList());
        if (!ids.isEmpty()) {
            List<RecoveryServe> serveList = recoveryServeService.lambdaQuery()
                    .in(RecoveryServe::getId, ids).eq(RecoveryServe::getIsDelete, 0).list();
            Map<Integer, String> map = serveList.stream().collect(Collectors.toMap(RecoveryServe::getId,
                    mw -> Optional.ofNullable(mw.getCover()).orElse("")));
            for (Order order : data.getRecords()) {
 
                Integer serveId = order.getServeId();
                order.setCover(map.get(serveId));
            }
        }
        return R.ok(data);
    }
 
    @GetMapping("/estimate")
    @ApiOperation(value = "在线评估", tags = {"用户端-订单"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "回收服务id", name = "orderId", dataType = "Integer", required = true),
            @ApiImplicitParam(value = "所在城市code", name = "city", dataType = "String")
    })
    public R<BigDecimal> estimate(@RequestParam String orderId, String city) {
        Order order = orderClient.detail(orderId).getData();
//        RecoveryServe recoveryServe = recoveryServeService.lambdaQuery()
//                .eq(RecoveryServe::getId, order.getServeId())
//                .eq(RecoveryServe::getIsDelete, 0).one();
//        BigDecimal money = recoveryServe.getDefaultPrice();
//        if (StringUtils.isNotBlank(city)) {
//            CityInfoVO info = GaoDeMapUtil.getAddressInfo(city).getDatas();
//            RecoveryServePrice price = recoveryServePriceService.lambdaQuery()
//                    .eq(RecoveryServePrice::getRecoveryServeId, recoveryServe.getId())
//                    .eq(RecoveryServePrice::getCity, info.getCode())
//                    .eq(RecoveryServePrice::getIsDelete, Constants.ZERO).one();
//            if (null != price) {
//                money = price.getRecoveryPrice();
//            }
//        }
        return R.ok(order.getServePrice());
    }
 
    @GetMapping("/detail")
    @ApiOperation(value = "订单详情", tags = {"用户端-订单"})
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单id", name = "orderId", dataType = "Integer", required = true)
    })
    public R<OrderDetailVO> detail(@RequestParam String orderId) {
        Order order = orderClient.detail(orderId).getData();
        if (null == order) {
            throw new GlobalException("订单不存在或已删除!");
        }
        OrderDetailVO orderDetail = new OrderDetailVO(order);
        if (Constants.THREE.equals(order.getState())) {
            ServeRecord serveRecord = serveRecordClient.serveRecordByOrderId(orderId).getData();
            if (null != serveRecord) {
                orderDetail.setPhoto(serveRecord.getPhoto());
            }
        }
        R<String> workPic = adminClient.getWorkPic(order.getServerId());
        orderDetail.setWorkPic(workPic.getMsg());
        return R.ok(orderDetail);
    }
 
    /**
     * 获取奖品列表
     *
     * @return 奖品列表
     */
    @GetMapping("/prizeList")
    @ApiOperation(value = "获取奖品列表", tags = {"用户端-订单"})
    public R<List<Prize>> prizeList(@RequestParam("serveId") String serveId) {
        return R.ok(adminClient.prizeList(Integer.valueOf(serveId)).getData());
    }
 
    /**
     * 抽奖获取津贴
     *
     * @return 奖品列表
     */
    @GetMapping("/allowance")
    @ApiOperation(value = "抽奖获取津贴", tags = {"用户端-订单"})
    public R<Object> obtainAllowance(@RequestParam("serveId") String serveId) {
        return R.ok(orderService.obtainAllowance(adminClient.prizeList(Integer.valueOf(serveId)).getData()));
    }
 
    /**
     * 抽奖获取津贴
     *
     * @return 奖品列表
     */
    @GetMapping("/allowanceMoney")
    @ApiOperation(value = "补充订单津贴金额", tags = {"用户端-订单"})
    public R<Object> allowanceMoney(@RequestParam("orderId") String orderId, @RequestParam("prizeId") String prizeId) {
        Prize data = adminClient.prizeDetail(prizeId).getData();
        if (null == data) {
            return R.fail(adminClient.prizeDetail(prizeId).getMsg());
        }
        String prizeMoney;
        if (data.getPrizeName().contains(Constants.SUBSIDY_MONEY)) {
            prizeMoney = data.getPrizeName().substring(Constants.ONE);
        } else {
            prizeMoney = "0";
        }
        return R.ok(orderClient.supplementAllowance(orderId, prizeMoney).getData());
    }
 
    @PostMapping("/orderEstimate")
    @ApiOperation(value = "下单评估,生成预订单信息", tags = {"用户端-订单"})
    public R<String> orderEstimate(@RequestBody OrderRequest orderRequest) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        String result = orderService.orderEstimate(orderRequest, loginUser.getUserid());
        return R.ok(result, "");
    }
 
    @PostMapping("/placeOrder")
    @ApiOperation(value = "用户下单", tags = {"用户端-订单"})
    public R<String> placeOrder(@RequestBody OrderRequest orderRequest) {
        LoginUserInfo loginUser = tokenService.getLoginUserByUser();
        if (null == loginUser) {
            return R.loginExpire("登录失效!");
        }
        Boolean result = orderService.placeOrder(orderRequest, loginUser.getUserid());
        return result ? R.ok() : R.fail();
    }
 
    /**
     * 领取补贴金
     *
     */
    @GetMapping("/receivingSubsidies")
    @ApiOperation(value = "领取补贴金", tags = {"用户端-订单-领取补贴金[2.0]"})
    public R<Object> receivingSubsidies(@RequestParam("serveId") String serveId,@RequestParam("orderId") String orderId) {
        // 查询补贴金
        RecoveryServe recoveryServe = recoveryServeService.getById(serveId);
        if (Objects.isNull(recoveryServe)) {
            return R.fail("该服务不存在!");
        }
        orderClient.receiving(orderId,recoveryServe.getRecycleSubsidy());
        return R.ok();
    }
 
}