基于mall4j产品的二开项目后端
lee
2024-12-18 921461a3f906d74403aeb6a27051deb77eca10fc
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
/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许,不可做商业用途!
 *
 * 版权所有,侵权必究!
 */
package com.yami.shop.api.controller;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.MarsSales;
import com.yami.shop.bean.model.MarsTranOrder;
import com.yami.shop.bean.vo.mars.MarsSalesVo;
import com.yami.shop.common.constants.DictConstant;
import com.yami.shop.common.constants.ResultMsg;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.CdnConfigService;
import com.yami.shop.service.CdnUserWalletService;
import com.yami.shop.service.MarsSalesService;
import com.yami.shop.service.MarsTranOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.List;
 
/**
 * @author LGH
 */
@RestController
@RequestMapping("/p/sales")
@Tag(name = "寄售(售卖)接口")
@AllArgsConstructor
public class MarsSalesController {
 
    @Resource
    private MarsSalesService marsSalesService;
    @Resource
    private CdnUserWalletService cdnUserWalletService;
    @Resource
    private CdnConfigService cdnConfigService;
    @Resource
    private MarsTranOrderService marsTranOrderService;
 
    @GetMapping("/page")
    @Operation(summary = "分页查询在线寄售(售卖)列表信息")
    public ServerResponseEntity<IPage<MarsSalesVo>> page(PageParam<MarsSales> page, MarsSalesVo marsSales) {
        IPage<MarsSalesVo> returnPage = marsSalesService.getPage(page,marsSales);
        return ServerResponseEntity.success(returnPage);
    }
 
    @GetMapping("/getMarsSalesPage")
    @Operation(summary = "分页查询寄售(售卖)列表信息")
    public ServerResponseEntity<IPage<MarsSales>> getMarsSalesPage(PageParam<MarsSales> page,MarsSales marsSales) {
        IPage<MarsSales> userInvoicePage = marsSalesService.getMarsSalesPage(page,marsSales );
        return ServerResponseEntity.success(userInvoicePage);
    }
 
    @GetMapping("/info/{id}")
    @Operation(summary = "通过寄售(售卖)id查询寄售(售卖)信息")
    @Parameter(name = "id", description = "寄售(售卖)id" , required = true)
    public ServerResponseEntity<MarsSales> getMarsSalesById(@PathVariable("id") Long id) {
        MarsSales card = marsSalesService.getById(id);
        return ServerResponseEntity.success(card);
    }
 
    @PostMapping("/getMarsSaless")
    @Operation(summary = "获取寄售(售卖)信息")
    public ServerResponseEntity<List<MarsSales>> getMarsSaless(@RequestBody  MarsSales marsSales) {
        List<MarsSales> list = marsSalesService.getMarsSaless(marsSales);
        return ServerResponseEntity.success(list);
    }
 
    @PostMapping("/saveMarsSales")
    @Operation(summary = "新增寄售(售卖)信息")
    public ServerResponseEntity<String> saveMarsSales(@RequestBody MarsSales marsSales) {
        String tranFee = cdnConfigService.selectValueByName(DictConstant.TRAN_FEE);
        String maxTranNum = cdnConfigService.selectValueByName(DictConstant.MAX_TRAN_NUM);
        String userId = SecurityUtils.getUser().getUserId();
        marsSales.setSalesUerId(userId);
        String msg = cdnUserWalletService.checkRedMoney(marsSales);
        if(ResponseEnum.OK.getMsg().equals(msg)){
            marsSales.setProductRealPrice(marsSales.getProductPrice().multiply
                    ((new BigDecimal(DictConstant.CONSTANT_1).subtract(new BigDecimal(tranFee)))).setScale(2, RoundingMode.HALF_UP));
            marsSales.setResiTranPrice(marsSales.getProductRealPrice());
            marsSales.setResiTranNum(new BigDecimal(maxTranNum));
            Integer num = marsSalesService.saveMarsSales(marsSales);
            if(num > 0 ){
                return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
            }else{
                return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
            }
        }else{
            return ServerResponseEntity.showFailMsg(msg);
        }
    }
 
    @PostMapping("/cancelMarsSales")
    @Operation(summary = "售卖人取消寄售(售卖)信息")
    public ServerResponseEntity<String> cancelMarsSales(@RequestBody MarsSales marsSales) {
        MarsTranOrder marsTranOrder = new MarsTranOrder();
        marsTranOrder.setProductId(String.valueOf(marsSales.getId()));
        List<String> statusList = new ArrayList<>();
        statusList.add(DictConstant.ORDER_STATUS_1);
        statusList.add(DictConstant.ORDER_STATUS_2);
        statusList.add(DictConstant.ORDER_STATUS_3);
        statusList.add(DictConstant.ORDER_STATUS_4);
        statusList.add(DictConstant.ORDER_STATUS_6);
        List<MarsTranOrder> orders = marsTranOrderService.getMarsTranOrders(marsTranOrder);
        if(null != orders && orders.size() > 0){
            return ServerResponseEntity.showFailMsg(ResultMsg.BUSSINESS_BEING);
        }
        marsSales.setProductStatus(DictConstant.PRODUCT_STATUS_5);
        Integer num = marsSalesService.updateMarsSales(marsSales);
        if(num >0 ){
            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
        }else{
            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
        }
    }
 
    @PostMapping("/updateMarsSales")
    @Operation(summary = "修改寄售(售卖)信息")
    public ServerResponseEntity<String> updateMarsSales(@RequestBody  MarsSales marsSales) {
        Integer num = marsSalesService.updateMarsSales(marsSales);
        if(num >0 ){
            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
        }else{
            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
        }
    }
 
    @GetMapping("/delete/{id}")
    @Operation(summary = "通过寄售流水id查询寄售信息")
    @Parameter(name = "id", description = "寄售id" , required = true)
    public ServerResponseEntity<String> deleteMarsSalesById(@PathVariable("id") Long id) {
        Integer num = marsSalesService.deleteMarsSales(id);
        if(num >0 ){
            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
        }else{
            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
        }
    }
 
}