基于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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许,不可做商业用途!
 *
 * 版权所有,侵权必究!
 */
package com.yami.shop.api.controller.cdn;
 
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.shop.bean.model.CdnFlow;
import com.yami.shop.bean.model.CdnUserWallet;
import com.yami.shop.bean.model.User;
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.common.util.PayUtil;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.CdnConfigService;
import com.yami.shop.service.CdnFlowService;
import com.yami.shop.service.CdnUserWalletService;
import com.yami.shop.service.UserService;
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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
 
/**
 * @author LGH
 */
@RestController
@RequestMapping("/cdn/userWaller")
@Tag(name = "用户钱包接口")
@AllArgsConstructor
public class CdnUserWalletController {
 
    @Resource
    private CdnFlowService cdnFlowService;
    @Resource
    private CdnUserWalletService cdnUserWalletService;
    @Resource
    private UserService userService;
    @Resource
    private CdnConfigService cdnConfigService;
 
    @GetMapping("/page")
    @Operation(summary = "分页查询用户钱包列表信息")
    public ServerResponseEntity<IPage<CdnUserWallet>> getCdnUserWalletPage(PageParam<CdnUserWallet> page,CdnUserWallet cdnUserWallet) {
        IPage<CdnUserWallet> userInvoicePage = cdnUserWalletService.getCdnUserWalletPage(page,cdnUserWallet );
        return ServerResponseEntity.success(userInvoicePage);
    }
 
    @GetMapping("/info/{id}")
    @Operation(summary = "通过用户钱包id查询用户钱包信息")
    @Parameter(name = "id", description = "用户钱包id" , required = true)
    public ServerResponseEntity<CdnUserWallet> getCdnUserWalletById(@PathVariable("id") Long id) {
        CdnUserWallet card = cdnUserWalletService.getById(id);
        return ServerResponseEntity.success(card);
    }
 
    @PostMapping("/getCdnUserWallets")
    @Operation(summary = "获取用户钱包信息")
    public ServerResponseEntity<List<CdnUserWallet>> getCdnUserWallets(@RequestBody  CdnUserWallet cdnUserWallet) {
        List<CdnUserWallet> list = cdnUserWalletService.getCdnUserWallets(cdnUserWallet);
        return ServerResponseEntity.success(list);
    }
    @PostMapping("/getCdnUserWallet")
    @Operation(summary = "获取用户钱包信息")
    public ServerResponseEntity<CdnUserWallet> getCdnUserWallet(@RequestBody  CdnUserWallet cdnUserWallet) {
        CdnUserWallet returnWallet = cdnUserWalletService.getCdnUserWallet(cdnUserWallet);
        return ServerResponseEntity.success(returnWallet);
    }
 
    @PostMapping("/exchange")
    @Operation(summary = "红积分兑换绿积分")
    public ServerResponseEntity<String> exchange(@RequestBody  CdnUserWallet cdnUserWallet) {
        String userId = cdnUserWallet.getUserId();
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
        List<CdnFlow> cdnFlow = cdnFlowService.list(Wrappers.<CdnFlow>lambdaQuery()
                        .eq(CdnFlow::getUserId, userId)
                        .eq(CdnFlow::getMemo, ResultMsg.RED_TRAN_GREEN)
                        .eq(CdnFlow::getDelStatus, 0)
                        .between(CdnFlow::getCreateTime, thirtyMinutesAgo, now));
        if (!cdnFlow.isEmpty()){
            return ServerResponseEntity.showFailMsg("1分钟内只能兑换一次");
        }
        if (cdnUserWallet.getPayPassword().length() > 6) {
            return ServerResponseEntity.showFailMsg("密码格式错误");
        }
        //校验支付密码
        User user = userService.getById(userId);
        if (user != null) {
            if (user.getPayPassword() == null) {
                return ServerResponseEntity.showFailMsg("支付密码还未设置,请先设置支付密码");
            }
            String ppw = PayUtil.encryptWithMD5(cdnUserWallet.getPayPassword());
            if (user.getPayPassword().equals(ppw)) {
                //转换
                if(null != cdnUserWallet.getMoney()){
                    String multiple = cdnConfigService.selectValueByName("withdrawal_multiple");
                    BigDecimal divide = cdnUserWallet.getMoney().divide(new BigDecimal(multiple));
                    if(divide.scale() <= 0 || divide.stripTrailingZeros().scale() <= 0){
//                String userId = "3";
                        String msg = cdnUserWalletService.exchange(cdnUserWallet,userId);
                        if(ResponseEnum.OK.getMsg().equals(msg)){
                            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
                        }else {
                            return ServerResponseEntity.showFailMsg(msg);
                        }
                    }else{
                        return ServerResponseEntity.showFailMsg(ResultMsg.ERROR_HUNDRED);
                    }
                }else{
                    return ServerResponseEntity.showFailMsg(ResultMsg.EXCHANGE_MONEYIS_EMPTY);
                }
            }else{
                return ServerResponseEntity.showFailMsg("支付密码错误");
            }
        } else {
            return ServerResponseEntity.showFailMsg("用户不存在");
        }
    }
 
    @PostMapping("/saveCdnUserWallet")
    @Operation(summary = "新增用户钱包信息")
    public ServerResponseEntity<String> saveCdnUserWallet(@RequestBody CdnUserWallet cdnUserWallet) {
        Integer num = cdnUserWalletService.saveCdnUserWallet(cdnUserWallet);
        if(num >0 ){
            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
        }else{
            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
        }
    }
 
    @PostMapping("/updateCdnUserWallet")
    @Operation(summary = "修改用户钱包信息")
    public ServerResponseEntity<String> updateCdnUserWallet(@RequestBody  CdnUserWallet cdnUserWallet) {
        Integer num = cdnUserWalletService.updateCdnUserWallet(cdnUserWallet);
        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> deleteCdnUserWalletById(@PathVariable("id") Long id) {
        Integer num = cdnUserWalletService.deleteCdnUserWallet(id);
        if(num >0 ){
            return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
        }else{
            return ServerResponseEntity.showFailMsg(ResponseEnum.ERROR.getMsg());
        }
    }
 
}