phpcjl
2024-12-10 450d98429b33d4433fa4f24a62a47790391459f6
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
package com.ruoyi.order.controller;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.R;
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.vo.ApplyRefundPass;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.util.Arrays;
 
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-21
 */
@RestController
@RequestMapping("/refund-pass")
public class RefundPassController {
 
 
    @Resource
    private RefundPassService refundPassService;
    
    @Resource
    private TokenService tokenService;
    
    @Resource
    private OrderService orderService;
    
    
    @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"));
        one.setIdStr(one.getId().toString());
        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(Arrays.asList(2, 3).contains(refundPass.getStatus())){
            return R.fail("售后取消失败");
        }
//        refundPass.setDelFlag(1);
        refundPassService.removeById(id);
        order.setOrderStatus(4);
        orderService.updateById(order);
        return R.ok();
    }
    
    
    @ResponseBody
    @PutMapping("/deliverGoodsRefundPass/{id}/{code}")
    @ApiOperation(value = "售后已发货操作", tags = {"我的订单-个人中心-小程序"})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "售后数据id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "code", value = "快递单号", required = true, dataType = "string"),
    })
    public R deliverGoodsRefundPass(@PathVariable("id") Long id, @PathVariable("code") String code){
        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(4 != refundPass.getStatus()){
            return R.fail("操作失败");
        }
        refundPass.setStatus(5);
        refundPass.setCode(code);
        refundPassService.updateById(refundPass);
        return R.ok();
    }
    
}