luodangjia
2025-01-17 2a4f0972408e27b8ef7afdc3a9195e301e06deb4
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
229
package com.ruoyi.order.controller;
 
 
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.account.api.model.UserAddress;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.model.Order;
import com.ruoyi.order.model.RefundPass;
import com.ruoyi.order.service.OrderService;
import com.ruoyi.order.service.RefundPassService;
import com.ruoyi.order.util.ExpressDeliveryUtil;
import com.ruoyi.order.util.vo.MapTrackKD100Vo;
import com.ruoyi.order.util.vo.QueryKD100ListVo;
import com.ruoyi.order.vo.*;
import com.ruoyi.other.api.domain.SystemConfig;
import com.ruoyi.other.api.feignClient.SystemConfigClient;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-21
 */
@RestController
@RequestMapping("/refund-pass")
public class RefundPassController extends BaseController {
 
 
    @Resource
    private RefundPassService refundPassService;
    
    @Resource
    private TokenService tokenService;
    
    @Resource
    private OrderService orderService;
    
    @Resource
    private RedisTemplate redisTemplate;
    
    @Resource
    private SystemConfigClient systemConfigClient;
    
    
    @ResponseBody
    @PostMapping("/applyRefundPass")
    @ApiOperation(value = "售后申请", tags = {"我的订单-个人中心-小程序"})
    public R applyRefundPass(@RequestBody ApplyRefundPass applyRefundPass){
        return refundPassService.applyRefundPass(applyRefundPass);
    }
    
    @ResponseBody
    @GetMapping("/getRefundPass/{orderId}")
    @ApiOperation(value = "获取售后详情", tags = {"我的订单-个人中心-小程序"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单id", required = true, dataType = "long"),
    })
    public R<RefundPass> getRefundPass(@PathVariable("orderId") Long orderId){
        Long userid = tokenService.getLoginUserApplet().getUserid();
        Order order = orderService.getById(orderId);
        if(!order.getAppUserId().equals(userid)){
            return R.fail("权限不足");
        }
        RefundPass one = refundPassService.getOne(new LambdaQueryWrapper<RefundPass>().eq(RefundPass::getOrderId, orderId)
                .eq(RefundPass::getDelFlag, 0).last(" order by create_time desc limit 0,1"));
        if(null == one){
            return R.fail("无效的售后数据");
        }
        one.setIdStr(one.getId().toString());
        one.setAddressJson(order.getAddressJson());
        if(StringUtils.isNotEmpty(one.getExpressResult())){
            MapTrackKD100Vo mapTrackKD100Vo = JSON.parseObject(one.getExpressResult(), MapTrackKD100Vo.class);
            List<QueryKD100ListVo> data = mapTrackKD100Vo.getData();
            one.setExpress(null != data && data.size() > 0 ? data.get(0).getContext() : "");
        }
        return R.ok(one);
    }
    
    
    @ResponseBody
    @PutMapping("/cancelRefundPass/{id}")
    @ApiOperation(value = "取消售后", tags = {"我的订单-个人中心-小程序"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "售后数据id", required = true, dataType = "long"),
    })
    public R cancelRefundPass(@PathVariable("id") Long id){
        RefundPass refundPass = refundPassService.getById(id);
        if(null == refundPass){
            return R.fail();
        }
        Long userid = tokenService.getLoginUserApplet().getUserid();
        Order order = orderService.getById(refundPass.getOrderId());
        if(!order.getAppUserId().equals(userid)){
            return R.fail("权限不足");
        }
        if(refundPass.getStatus().equals(2)){
            return R.fail("售后取消失败");
        }
        refundPass.setDelFlag(1);
        refundPassService.updateById(refundPass);
        order.setOrderStatus(order.getOldOrderStatus());
        orderService.updateById(order);
        return R.ok();
    }
    
    
    @ResponseBody
    @PostMapping("/deliverGoodsRefundPass")
    @ApiOperation(value = "售后已发货操作", tags = {"我的订单-个人中心-小程序"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "售后数据id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "code", value = "快递单号", required = true, dataType = "string"),
    })
    public R deliverGoodsRefundPass(@RequestBody DeliverGoodsRefundPass pass){
        RefundPass refundPass = refundPassService.getById(pass.getId());
        if(null == refundPass){
            return R.fail();
        }
        Long userid = tokenService.getLoginUserApplet().getUserid();
        Order order = orderService.getById(refundPass.getOrderId());
        if(!order.getAppUserId().equals(userid)){
            return R.fail("权限不足");
        }
        if(4 != refundPass.getStatus()){
            return R.fail("操作失败");
        }
        refundPass.setStatus(5);
        refundPass.setCode(pass.getCode());
        
        //添加查询快递信息队列
        //一小时后定时查询快递信息
        SystemConfig systemConfig = systemConfigClient.getSystemConfig(3).getData();
        JSONObject jsonObject = JSON.parseObject(systemConfig.getContent());
        Integer waitTime = jsonObject.getInteger("waitTime");
        redisTemplate.opsForZSet().add("order_refund_express", refundPass.getId(), LocalDateTime.now().plusHours(waitTime).toEpochSecond(ZoneOffset.UTC));
        
        JSONObject jsonObject1 = JSON.parseObject(pass.getCode());
        String com = jsonObject1.getString("com");
        String num = jsonObject1.getString("num");
        UserAddress userAddress = JSON.parseObject(order.getAddressJson(), UserAddress.class);
        MapTrackKD100Vo mapTrackKD100Vo = ExpressDeliveryUtil.kd100MapTrack(com, num, userAddress.getProvince() + userAddress.getCity(), order.getDeliverProvince() + order.getDeliverCity());
        refundPass.setExpressResult(JSON.toJSONString(mapTrackKD100Vo));
        refundPassService.updateById(refundPass);
        return R.ok();
    }
    
    
    
    @ResponseBody
    @GetMapping("/getOrderRefundPassList")
    @ApiOperation(value = "获取售后列表数据", tags = {"管理后台-售后管理", "门店后台-售后管理"})
    public R<PageInfo<OrderRefundPassList>> getOrderRefundPassList(OrderRefundPassListVo refundPassListVo){
        return R.ok(refundPassService.getOrderRefundPassList(refundPassListVo));
    }
 
 
    
    @ResponseBody
    @PostMapping("/authPassStatus")
    @ApiOperation(value = "审核售后", tags = {"管理后台-售后管理", "门店后台-售后管理"})
    public R authPassStatus(@RequestBody AuthPassStatus  authPassStatus){
        return refundPassService.authPassStatus(authPassStatus.getId(), authPassStatus.getStatus(), authPassStatus.getPassRemark());
    }
    
    
    @ResponseBody
    @PutMapping("/refundPassReceive/{id}")
    @ApiOperation(value = "售后确认收货操作", tags = {"管理后台-售后管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "售后数据id", required = true, dataType = "long"),
    })
    public R refundPassReceive(@PathVariable("id") Long id){
        return refundPassService.refundPassReceive(id);
    }
    
    
    
    @ResponseBody
    @GetMapping("/getRefundPassInfo/{id}")
    @ApiOperation(value = "获取售后数据详情", tags = {"管理后台-售后管理", "门店后台-售后管理"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "售后数据id", required = true, dataType = "long"),
    })
    public R<RefundPassInfo> getRefundPassInfo(@PathVariable("id") Long id){
        RefundPassInfo refundPassInfo = refundPassService.getRefundPassInfo(id);
        return R.ok(refundPassInfo);
    }
    
    
    
    /**
     * 获取订单快递明细
     * @param id
     * @return
     */
    @GetMapping("/getOrderExpress/{id}")
    @ApiOperation(value = "获取售后订单快递明细", tags = {"小程序-订单管理"})
    public R<MapTrackKD100Vo> getOrderExpress(@PathVariable("id") Long id){
        RefundPass refundPass = refundPassService.getById(id);
        String expressResult = refundPass.getExpressResult();
        if(StringUtils.isNotEmpty(expressResult)){
            MapTrackKD100Vo mapTrackKD100Vo = JSON.parseObject(expressResult, MapTrackKD100Vo.class);
            return R.ok(mapTrackKD100Vo);
        }
        return R.ok();
    }
    
}