package com.yami.shop.api.controller.cdn;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.google.common.reflect.TypeToken;
|
import com.google.gson.Gson;
|
import com.yami.shop.bean.model.*;
|
import com.yami.shop.bean.param.*;
|
import com.yami.shop.common.bean.HuaWeiOss;
|
import com.yami.shop.common.config.Constant;
|
import com.yami.shop.common.enums.WalletEnum;
|
import com.yami.shop.common.i18n.I18nMessage;
|
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.service.*;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameters;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.validation.Valid;
|
import java.lang.reflect.Type;
|
import java.math.BigDecimal;
|
import java.math.BigInteger;
|
import java.security.MessageDigest;
|
import java.security.NoSuchAlgorithmException;
|
import java.time.LocalDateTime;
|
import java.util.*;
|
import java.util.regex.Pattern;
|
|
@RestController
|
@RequestMapping("/cdn/myWallet")
|
@Tag(name = "钱包相关")
|
public class CdnMyWalletController {
|
@Autowired
|
private CdnUserWalletService cdnUserWalletService;
|
@Autowired
|
private CdnFlowService cdnFlowService;
|
@Autowired
|
private UserService userService;
|
@Autowired
|
private CdnUserRechargeService cdnUserRechargeService;
|
@Autowired
|
private CdnUserBankService cdnUserBankService;
|
@Autowired
|
private CdnConfigService cdnConfigService;
|
@Autowired
|
private SysConfigService sysConfigService;
|
@Autowired
|
private CdnWithdrawalService cdnWithdrawalService;
|
@Autowired
|
private CdnWalletService cdnWalletService;
|
@Autowired
|
private CdnFlownameService cdnFlownameService;
|
@Autowired
|
private CdnTeamRelationService cdnTeamRelationService;
|
|
|
private static final Pattern NUMERIC_PATTERN = Pattern.compile("\\d+");
|
|
@GetMapping("/getWalletDetail")
|
@Operation(summary = "查看明细", description = "查看明细")
|
@Parameters({
|
@Parameter(name = "userId", description = "用户id"),
|
@Parameter(name = "page", description = "当前页"),
|
@Parameter(name = "pageSize", description = "每页条数"),
|
@Parameter(name = "walletId", description = "币种id 8流量 9金牛豆 10 幸运池 11积分")
|
})
|
public ServerResponseEntity<CdnUserWalletParam> getWalletDetail(@RequestParam(name = "userId") String userId,
|
@RequestParam(name = "page") Integer page,
|
@RequestParam(name = "pageSize") Integer pageSize,
|
@RequestParam(name = "walletId") Integer walletId) {
|
CdnUserWallet cdnUserWallet = cdnUserWalletService.getOne(Wrappers.<CdnUserWallet>lambdaQuery()
|
.eq(CdnUserWallet::getUserId, userId)
|
.eq(CdnUserWallet::getWalletId, walletId));
|
Page<CdnFlow> p = new Page<>(page, pageSize);
|
IPage<CdnFlow> flows = cdnFlowService.page(p, Wrappers.lambdaQuery(CdnFlow.class)
|
.eq(CdnFlow::getUserId, userId)
|
.eq(CdnFlow::getWalletId, walletId)
|
.eq(CdnFlow::getDelStatus, 0)
|
.orderByDesc(CdnFlow::getCreateTime)
|
.orderByAsc(CdnFlow::getId));
|
if (!flows.getRecords().isEmpty()) {
|
for (CdnFlow flow : flows.getRecords()) {
|
CdnFlowname cdnFlowname = cdnFlownameService.getOne(Wrappers.<CdnFlowname>lambdaQuery().eq(CdnFlowname::getId, flow.getFlownameId()));
|
flow.setFlowname(cdnFlowname != null ? cdnFlowname.getName() : "无");
|
}
|
}
|
CdnUserWalletParam userWalletParam = new CdnUserWalletParam();
|
userWalletParam.setBalance(cdnUserWallet.getMoney());
|
userWalletParam.setFlows(flows);
|
return ServerResponseEntity.success(userWalletParam);
|
}
|
|
@GetMapping("/isPayPassword")
|
@Operation(summary = "查看是否设置支付密码", description = "查看是否设置支付密码")
|
public ServerResponseEntity<Boolean> isPayPassword(@RequestParam(name = "userId") String userId) {
|
User user = userService.getById(userId);
|
if (user.getPayPassword() == null || user.getPayPassword().equals("")) {
|
return ServerResponseEntity.success(false);
|
}
|
return ServerResponseEntity.success(true);
|
}
|
|
@PostMapping("/setPayPassword")
|
@Operation(summary = "设置支付密码", description = "设置支付密码")
|
public ServerResponseEntity setPayPassword(@RequestBody PayPasswordParam setPayPasswordParam) {
|
if (setPayPasswordParam.getPayPassword().length() > 6) {
|
return ServerResponseEntity.showFailMsg("密码格式错误");
|
}
|
User user = userService.getById(setPayPasswordParam.getUserId());
|
if (user != null) {
|
if (user.getPayPassword() == null) {
|
String ppw = encryptWithMD5(setPayPasswordParam.getPayPassword());
|
user.setPayPassword(ppw);
|
userService.updateById(user);
|
return ServerResponseEntity.success();
|
}
|
String ppw = encryptWithMD5(setPayPasswordParam.getPayPassword());
|
if (user.getPayPassword().equals(ppw)) {
|
return ServerResponseEntity.showFailMsg("不能与原密码一致");
|
}
|
user.setPayPassword(ppw);
|
userService.updateById(user);
|
} else {
|
return ServerResponseEntity.showFailMsg("用户不存在");
|
}
|
return ServerResponseEntity.success();
|
}
|
|
@PostMapping("/modifyPayPassword")
|
@Operation(summary = "修改支付密码", description = "修改支付密码")
|
public ServerResponseEntity modifyPayPassword(@Valid @RequestBody SetPayPasswordParam payPasswordParam) {
|
if (payPasswordParam.getOldPayPassword().length() > 6 || !isNumericPayPassword(payPasswordParam.getOldPayPassword())) {
|
return ServerResponseEntity.showFailMsg("旧密码格式错误");
|
}
|
if (payPasswordParam.getNewPayPassword().length() > 6 || !isNumericPayPassword(payPasswordParam.getNewPayPassword())) {
|
return ServerResponseEntity.showFailMsg("新密码格式错误");
|
}
|
if (!payPasswordParam.getConfirmPayPassword().equals(payPasswordParam.getNewPayPassword())) {
|
return ServerResponseEntity.showFailMsg("密码和确认密码不一致");
|
}
|
if (payPasswordParam.getOldPayPassword().equals(payPasswordParam.getNewPayPassword())) {
|
return ServerResponseEntity.showFailMsg("新密码不能与旧密码一致");
|
}
|
User user = userService.getById(payPasswordParam.getUserId());
|
if (user != null) {
|
if (user.getPayPassword() == null) {
|
return ServerResponseEntity.showFailMsg("支付密码还未设置,不能修改");
|
}
|
String old = encryptWithMD5(payPasswordParam.getOldPayPassword());
|
if (!old.equals(user.getPayPassword())) {
|
return ServerResponseEntity.showFailMsg("旧密码输入错误");
|
}
|
String ppw = encryptWithMD5(payPasswordParam.getNewPayPassword());
|
user.setPayPassword(ppw);
|
userService.updateById(user);
|
} else {
|
return ServerResponseEntity.showFailMsg("用户不存在");
|
}
|
return ServerResponseEntity.success();
|
}
|
@PostMapping("/pay/vaildPwd")
|
@Operation(summary = "校验支付密码", description = "校验支付密码")
|
public ServerResponseEntity vaildPayPassword(@RequestBody PayPasswordParam setPayPasswordParam) {
|
if (setPayPasswordParam.getPayPassword().length() > 6) {
|
return ServerResponseEntity.showFailMsg("密码格式错误");
|
}
|
User user = userService.getById(setPayPasswordParam.getUserId());
|
if (user != null) {
|
if (user.getPayPassword() == null) {
|
return ServerResponseEntity.showFailMsg("支付密码还未设置,请先设置支付密码");
|
}
|
|
String ppw = encryptWithMD5(setPayPasswordParam.getPayPassword());
|
if (user.getPayPassword().equals(ppw)) {
|
return ServerResponseEntity.success("密码验证成功");
|
}
|
} else {
|
return ServerResponseEntity.showFailMsg("用户不存在");
|
}
|
return ServerResponseEntity.showFailMsg("支付密码错误");
|
}
|
|
@PostMapping("/transferAccounts")
|
@Operation(summary = "转账", description = "转账")
|
public ServerResponseEntity transferAccounts(@RequestBody CdnTransFerAccountParam cdnTransFerAccountParam) {
|
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
|
List<CdnFlow> cdnFlow = cdnFlowService.list(
|
Wrappers.<CdnFlow>lambdaQuery()
|
.eq(CdnFlow::getUserId, cdnTransFerAccountParam.getUserId())
|
.like(CdnFlow::getMemo, "转账")
|
.eq(CdnFlow::getDelStatus, 0)
|
.between(CdnFlow::getCreateTime, thirtyMinutesAgo, now));
|
if (!cdnFlow.isEmpty()){
|
return ServerResponseEntity.showFailMsg("1分钟内只能转账一次");
|
}
|
String wallet = cdnConfigService.selectValueByName("transferAccounts");
|
Double transferService = Double.parseDouble(cdnConfigService.selectValueByName("transferAccounts_service"));
|
if (wallet != null && !wallet.equals("")) {
|
boolean found = false;
|
String[] wallets = wallet.split(",");
|
for (String s :wallets){
|
if (s.equals(cdnTransFerAccountParam.getWalletId() + "")) {
|
found = true;
|
break;
|
}
|
}
|
if (!found){
|
return ServerResponseEntity.showFailMsg("该钱包不可转账!");
|
}
|
}
|
User u = userService.getUserByUserId(cdnTransFerAccountParam.getUserId());
|
if (u.getZhuanzhang() != 1) return ServerResponseEntity.showFailMsg("不可转账,请联系客服");
|
String ppw = encryptWithMD5(cdnTransFerAccountParam.getPayPassword());
|
User user = userService.getById(cdnTransFerAccountParam.getUserId());
|
if (user.getPayPassword() == null) {
|
return ServerResponseEntity.showFailMsg("请先设置支付密码");
|
}
|
if (!ppw.equals(user.getPayPassword())) {
|
return ServerResponseEntity.showFailMsg("支付密码错误");
|
}
|
CdnUserWallet cdnUserWallet = cdnUserWalletService.getOne(Wrappers.<CdnUserWallet>lambdaQuery()
|
.eq(CdnUserWallet::getUserId, cdnTransFerAccountParam.getUserId())
|
.eq(CdnUserWallet::getWalletId, cdnTransFerAccountParam.getWalletId()));
|
BigDecimal service = BigDecimal.valueOf(transferService);
|
if (cdnUserWallet != null) {
|
if (cdnUserWallet.getMoney().compareTo(cdnTransFerAccountParam.getAmount()) < 0) {
|
return ServerResponseEntity.showFailMsg("余额不足");
|
}
|
User payeeUser = userService.getOne(Wrappers.<User>lambdaQuery().eq(User::getUserMobile, cdnTransFerAccountParam.getMobile()));
|
if (payeeUser == null) {
|
return ServerResponseEntity.showFailMsg("收款人不存在");
|
}
|
if (payeeUser.getUserId().equals(cdnTransFerAccountParam.getUserId())) {
|
return ServerResponseEntity.showFailMsg("不能给自己转账");
|
}
|
//转账人
|
CdnTeamRelation cdnTeamRelations = cdnTeamRelationService.geteamRelationByUserId(cdnTransFerAccountParam.getUserId());
|
if(cdnTeamRelations != null){
|
if(cdnTeamRelations.getPids() != null && cdnTeamRelations.getPids().indexOf(payeeUser.getUserId()) > -1){// 转账人的上级 包含 收款人的用户Id
|
// 执行转账逻辑
|
Boolean b = cdnFlowService.executeTransferAccounts(cdnTransFerAccountParam.getUserId(), cdnTransFerAccountParam.getWalletId(), cdnTransFerAccountParam.getAmount(), payeeUser.getUserId());
|
if (b) {
|
return ServerResponseEntity.success();
|
}
|
}else{
|
//收款人
|
CdnTeamRelation CdnTeamRelation = cdnTeamRelationService.geteamRelationByUserId(payeeUser.getUserId());
|
if (CdnTeamRelation == null) {
|
return ServerResponseEntity.showFailMsg("转账失败");
|
}else {
|
if(CdnTeamRelation.getPids() != null && CdnTeamRelation.getPids().indexOf(cdnTransFerAccountParam.getUserId()) > -1){// 收款人的上级 包含 转账人的用户Id
|
// 执行转账逻辑
|
Boolean b = cdnFlowService.executeTransferAccounts(cdnTransFerAccountParam.getUserId(), cdnTransFerAccountParam.getWalletId(), cdnTransFerAccountParam.getAmount(), payeeUser.getUserId());
|
if (b) {
|
return ServerResponseEntity.success();
|
}
|
}else {
|
return ServerResponseEntity.showFailMsg("非上下级一条线的用户不能转账!");
|
}
|
}
|
}
|
}else{
|
return ServerResponseEntity.showFailMsg("转账失败!");
|
}
|
}
|
return ServerResponseEntity.showFailMsg("转账失败");
|
}
|
|
@PostMapping("/transfer")
|
@Operation(summary = "划转", description = "划转")
|
public ServerResponseEntity transfer(@RequestBody CdnTransFerParam cdnTransFerParam) {
|
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
|
List<CdnFlow> cdnFlow = cdnFlowService.list(
|
Wrappers.<CdnFlow>lambdaQuery()
|
.eq(CdnFlow::getUserId, cdnTransFerParam.getUserId())
|
.like(CdnFlow::getMemo, "划转")
|
.eq(CdnFlow::getDelStatus, 0)
|
.between(CdnFlow::getCreateTime, thirtyMinutesAgo, now));
|
if (!cdnFlow.isEmpty()){
|
return ServerResponseEntity.showFailMsg("1分钟内只能划转一次");
|
}
|
User u = userService.getUserByUserId(cdnTransFerParam.getUserId());
|
if (u.getHuazhuan() != 1) return ServerResponseEntity.showFailMsg("不可划转,请联系客服");
|
String ppw = encryptWithMD5(cdnTransFerParam.getPayPassword());
|
User user = userService.getById(cdnTransFerParam.getUserId());
|
if (user.getPayPassword() == null) {
|
return ServerResponseEntity.showFailMsg("请先设置支付密码");
|
}
|
if (!ppw.equals(user.getPayPassword())) {
|
return ServerResponseEntity.showFailMsg("支付密码错误");
|
}
|
CdnUserWallet cdnUserWallet = cdnUserWalletService.getOne(Wrappers.<CdnUserWallet>lambdaQuery()
|
.eq(CdnUserWallet::getUserId, cdnTransFerParam.getUserId())
|
.eq(CdnUserWallet::getWalletId, cdnTransFerParam.getWalletId()));
|
if (cdnUserWallet != null) {
|
if (cdnUserWallet.getMoney().compareTo(cdnTransFerParam.getAmount()) < 0) {
|
return ServerResponseEntity.showFailMsg("余额不足");
|
}
|
// 执行划转逻辑
|
Boolean b = cdnFlowService.executeTransfer(cdnTransFerParam.getUserId(), cdnTransFerParam.getWalletId(), cdnTransFerParam.getAmount(), cdnTransFerParam.getTransFerWalletId());
|
if (b) {
|
return ServerResponseEntity.success();
|
}
|
}
|
return ServerResponseEntity.showFailMsg("划转失败");
|
}
|
|
|
@PostMapping("/cash")
|
@Operation(summary = "兑现幸运池", description = "兑现幸运池")
|
public ServerResponseEntity cash(@RequestBody CdnTransFerParam cdnTransFerParam) {
|
if(StringUtils.isBlank(cdnTransFerParam.getUserId())){
|
return ServerResponseEntity.showFailMsg("用户Id不能为空!");
|
}
|
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
|
List<CdnFlow> cdnFlow = cdnFlowService.list(
|
Wrappers.<CdnFlow>lambdaQuery()
|
.eq(CdnFlow::getUserId, cdnTransFerParam.getUserId())
|
.like(CdnFlow::getMemo, "兑换")
|
.eq(CdnFlow::getDelStatus, 0)
|
.between(CdnFlow::getCreateTime, thirtyMinutesAgo, now));
|
if (!cdnFlow.isEmpty()){
|
return ServerResponseEntity.showFailMsg("1分钟内只能兑换一次");
|
}
|
User u = userService.getUserByUserId(cdnTransFerParam.getUserId());
|
if (u.getHuazhuan() != 1) return ServerResponseEntity.showFailMsg("不可兑换,请联系客服");
|
String ppw = encryptWithMD5(cdnTransFerParam.getPayPassword());
|
User user = userService.getById(cdnTransFerParam.getUserId());
|
if (user.getPayPassword() == null) {
|
return ServerResponseEntity.showFailMsg("请先设置支付密码");
|
}
|
if (!ppw.equals(user.getPayPassword())) {
|
return ServerResponseEntity.showFailMsg("支付密码错误");
|
}
|
CdnUserWallet cdnUserWallet = cdnUserWalletService.getOne(Wrappers.<CdnUserWallet>lambdaQuery()
|
.eq(CdnUserWallet::getUserId, cdnTransFerParam.getUserId())
|
.eq(CdnUserWallet::getWalletId, cdnTransFerParam.getWalletId()));
|
if (cdnUserWallet != null) {
|
if (cdnUserWallet.getMoney().compareTo(cdnTransFerParam.getAmount()) < 0) {
|
return ServerResponseEntity.showFailMsg("金牛豆不足");
|
}
|
// 执行兑换逻辑
|
cdnTransFerParam.setTransFerWalletId(WalletEnum.LUCKPOOL.value());
|
String msg = cdnFlowService.cash(cdnTransFerParam.getUserId(), cdnTransFerParam.getWalletId(), cdnTransFerParam.getAmount(), cdnTransFerParam.getTransFerWalletId());
|
if(ResponseEnum.OK.getMsg().equals(msg)){
|
return ServerResponseEntity.success(ResponseEnum.OK.getMsg());
|
}else {
|
return ServerResponseEntity.showFailMsg(msg);
|
}
|
}
|
return ServerResponseEntity.showFailMsg("兑换失败");
|
}
|
|
@GetMapping("/getRechargeQrCode")
|
@Operation(summary = "获取充值二维码", description = "获取充值二维码")
|
public ServerResponseEntity<RechargeParam> getRechargeQrCode() {
|
RechargeParam rechargeParam = new RechargeParam();
|
Object rechargeimg = cdnConfigService.selectValueByName("rechargeimg");
|
HuaWeiOss aliOss = sysConfigService.getSysConfigObject(Constant.HUAWEI_OBS_CONFIG, HuaWeiOss.class);
|
if (aliOss != null) {
|
String bucketName = aliOss.getBucketName();//shjw2024
|
String endpoint = aliOss.getEndpoint(); //https://oss-cn-shanghai.aliyuncs.com
|
String pre = endpoint.substring(0, 8);
|
String fix = endpoint.substring(8);
|
String path = pre + bucketName + "." + fix;
|
String img = rechargeimg.toString();
|
rechargeParam.setImg(path + "/" + img);
|
}
|
String moneyArr = cdnConfigService.selectValueByName("money_arr");
|
Gson gson = new Gson();
|
Type type = new TypeToken<Map<String, String>>(){}.getType();
|
|
try {
|
Map<String, String> map = gson.fromJson(moneyArr, type);
|
List<String> moneyList = new ArrayList<>(map.values());
|
rechargeParam.setMoneyArr(moneyList);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
String rechageHour = cdnConfigService.selectValueByName("rechage_hour");
|
rechargeParam.setRechageHour(rechageHour);
|
return ServerResponseEntity.success(rechargeParam);
|
}
|
|
@PostMapping("/recharge")
|
@Operation(summary = "充值", description = "充值")
|
public ServerResponseEntity recharge(@RequestBody CdnUserRecharge cdnUserRecharge) {
|
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
|
CdnUserRecharge cdnUserRecharge1 = cdnUserRechargeService.getOne(
|
Wrappers.<CdnUserRecharge>lambdaQuery()
|
.eq(CdnUserRecharge::getUserId, cdnUserRecharge.getUserId())
|
.eq(CdnUserRecharge::getStatus, 0)
|
.between(CdnUserRecharge::getCreateTime, thirtyMinutesAgo, now));
|
if (cdnUserRecharge1 != null){
|
return ServerResponseEntity.showFailMsg("1分钟内只能充值一次");
|
}
|
String rechageHour = cdnConfigService.selectValueByName("rechage_hour");
|
// 获取今天的日期
|
LocalDateTime today = LocalDateTime.now();
|
Integer hour = today.getHour();
|
String[] parts = rechageHour.split("-"); // 使用 - 分割字符串
|
String startHour = parts[0]; // 截取起始小时
|
String endHour = parts[1]; // 截取结束小时
|
if (hour <= Integer.parseInt(startHour) || hour > Integer.parseInt(endHour)) {
|
return ServerResponseEntity.showFailMsg("充值时间限制" + rechageHour);
|
}
|
// String moneyArr = cdnConfigService.selectValueByName("money_arr"); //{"0":"2000","1":"6000","2":"15000","3":"150000"}
|
// Gson gson = new Gson();
|
// Type type = new TypeToken<Map<String, String>>(){}.getType();
|
// try {
|
// Map<String, String> map = gson.fromJson(moneyArr, type);
|
// List<String> moneyList = new ArrayList<>(map.values());
|
// if (!moneyList.contains(cdnUserRecharge.getMoney().toString())) {
|
// return ServerResponseEntity.showFailMsg("充值金额错误");
|
// }
|
// } catch (Exception e) {
|
// e.printStackTrace();
|
// }
|
|
cdnUserRecharge.setCreateTime(new Date());
|
cdnUserRechargeService.save(cdnUserRecharge);
|
return ServerResponseEntity.success();
|
}
|
@GetMapping("/getUserBank")
|
@Operation(summary = "获取银行卡列表", description = "获取银行卡列表")
|
public ServerResponseEntity<List<CdnUserBank>> getUserBank(@RequestParam("userId") String userId) {
|
return ServerResponseEntity.success(cdnUserBankService.list(Wrappers.<CdnUserBank>lambdaQuery().eq(CdnUserBank::getUserId, userId)));
|
}
|
|
@PostMapping("/deleteUserBank")
|
@Operation(summary = "删除用户银行卡信息", description = "删除用户银行卡信息")
|
public ServerResponseEntity<String> deleteUserBank(@RequestBody CdnUserBank bank) {
|
Integer num = cdnUserBankService.deleteUserBank(bank);
|
if(num > 0){
|
return ServerResponseEntity.success();
|
}
|
return ServerResponseEntity.showFailMsg(I18nMessage.getMessage("删除银行卡信息失败!"));
|
}
|
|
@PostMapping("/updateUserBank")
|
@Operation(summary = "修改用户银行卡信息", description = "修改用户银行卡信息")
|
public ServerResponseEntity<String> updateUserBank(@RequestBody CdnUserBank bank) {
|
Boolean flag = cdnUserBankService.updateById(bank);
|
if(flag){
|
return ServerResponseEntity.success();
|
}
|
return ServerResponseEntity.showFailMsg(I18nMessage.getMessage("修改银行卡信息失败!"));
|
}
|
|
@PostMapping("/withdrawal")
|
@Operation(summary = "提现", description = "提现")
|
@Transactional(rollbackFor = Exception.class)
|
public ServerResponseEntity withdrawal(@RequestBody CdnWithdrawal cdnWithdrawal) {
|
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime thirtyMinutesAgo = now.minusMinutes(1);
|
CdnWithdrawal cdnWithdrawal1 = cdnWithdrawalService.getOne(
|
Wrappers.<CdnWithdrawal>lambdaQuery()
|
.eq(CdnWithdrawal::getUserId, cdnWithdrawal.getUserId())
|
.eq(CdnWithdrawal::getStatus, 0)
|
.between(CdnWithdrawal::getCreateTime, thirtyMinutesAgo, now));
|
if (cdnWithdrawal1 != null){
|
return ServerResponseEntity.showFailMsg("1分钟内只能提现一次");
|
}
|
return cdnWithdrawalService.executeWithdrawal(cdnWithdrawal);
|
}
|
|
@GetMapping("/getWithdrawal")
|
@Operation(summary = "获取提现配置", description = "获取提现配置")
|
public ServerResponseEntity<CdnWithdrawalConfigParam> getUserWithdrawal() {
|
CdnWithdrawalConfigParam cdnWithdrawalConfigParam = new CdnWithdrawalConfigParam();
|
cdnWithdrawalConfigParam.setWithdrawalService(cdnConfigService.selectValueByName("withdrawal_service"));
|
cdnWithdrawalConfigParam.setWithdrawalThreshold(cdnConfigService.selectValueByName("withdrawal_threshold"));
|
cdnWithdrawalConfigParam.setWithdrawalTitle(cdnConfigService.selectValueByName("withdrawal_title"));
|
cdnWithdrawalConfigParam.setWithdrawDay(cdnConfigService.selectValueByName("withdraw_day"));
|
// 获取今天的日期
|
LocalDateTime today = LocalDateTime.now();
|
// 获取今天是周几
|
Integer dayOfWeek = today.getDayOfMonth();
|
if (!dayOfWeek.equals(Integer.parseInt(cdnWithdrawalConfigParam.getWithdrawDay()))) {
|
cdnWithdrawalConfigParam.setIsDraw(false);
|
}else{
|
cdnWithdrawalConfigParam.setIsDraw(true);
|
}
|
cdnWithdrawalConfigParam.setWithdrawalDay(cdnConfigService.selectValueByName("withdrawal_day"));
|
cdnWithdrawalConfigParam.setWithdrawHour(cdnConfigService.selectValueByName("withdraw_hour"));
|
cdnWithdrawalConfigParam.setWithdrawalBluePointPoundage(cdnConfigService.selectValueByName("withdrawal_bluePoint_poundage"));
|
return ServerResponseEntity.success(cdnWithdrawalConfigParam);
|
}
|
|
@GetMapping("/getConvertConfig")
|
@Operation(summary = "获取划转配置", description = "获取划转配置")
|
public ServerResponseEntity<CdnConvertConfigParam> getConvertConfig() {
|
CdnConvertConfigParam cdnConvertConfigParam = new CdnConvertConfigParam();
|
String convert = cdnConfigService.selectValueByName("convert");
|
if(!StringUtils.isEmpty(convert)){
|
String[] converts = convert.split(",");
|
Map<String,String> convertMap = new HashMap<>();
|
for (String c : converts){
|
CdnWallet cw = cdnWalletService.getOne(Wrappers.lambdaQuery(CdnWallet.class).eq(CdnWallet::getId, Integer.parseInt(c)));
|
convertMap.put(c,cw.getName());
|
}
|
cdnConvertConfigParam.setConvert(convertMap);
|
}
|
String convertReceive = cdnConfigService.selectValueByName("convert_receive");
|
String[] convertReceives = convertReceive.split(",");
|
Map<String,String> convertReceiveMap = new HashMap<>();
|
for (String c : convertReceives){
|
CdnWallet cw = cdnWalletService.getOne(Wrappers.lambdaQuery(CdnWallet.class).eq(CdnWallet::getId, Integer.parseInt(c)));
|
convertReceiveMap.put(c,cw.getName());
|
}
|
cdnConvertConfigParam.setConvertReceive(convertReceiveMap);
|
String convertPoundage = cdnConfigService.selectValueByName("convert_poundage");
|
cdnConvertConfigParam.setConvertPoundage(convertPoundage);
|
String transferReceive = cdnConfigService.selectValueByName("transferAccounts");
|
String[] transfer = transferReceive.split(",");
|
Map<String,String> transferMap = new HashMap<>();
|
for (String c : transfer){
|
CdnWallet cw = cdnWalletService.getOne(Wrappers.lambdaQuery(CdnWallet.class).eq(CdnWallet::getId, Integer.parseInt(c)));
|
transferMap.put(c,cw.getName());
|
}
|
cdnConvertConfigParam.setTransferList(transferMap);
|
|
String transferService = cdnConfigService.selectValueByName("transferAccounts_service");
|
cdnConvertConfigParam.setTransferPoundage(transferService);
|
return ServerResponseEntity.success(cdnConvertConfigParam);
|
}
|
|
|
@GetMapping("/getWalletLog")
|
@Operation(summary = "获取用户提现记录", description = "获取用户提现记录")
|
public ServerResponseEntity<List<CdnWithdrawal>> getUserWalletLog(@RequestParam String userId) {
|
List<CdnWithdrawal> cdnWithdrawalList = cdnWithdrawalService.list(Wrappers.lambdaQuery(CdnWithdrawal.class)
|
.eq(CdnWithdrawal::getUserId, userId)
|
.orderByDesc(CdnWithdrawal::getCreateTime));
|
return ServerResponseEntity.success(cdnWithdrawalList);
|
}
|
|
@GetMapping("/getWalletLogPage")
|
@Operation(summary = "分页获取用户提现记录", description = "获取用户提现记录")
|
public ServerResponseEntity<IPage<CdnWithdrawal>> getUserWalletLog(@RequestParam Integer page,@RequestParam Integer pageSize,@RequestParam String userId) {
|
PageParam<CdnWithdrawal> param = new PageParam<>();
|
param.setCurrent(page);
|
param.setSize(pageSize);
|
LambdaQueryWrapper<CdnWithdrawal> wrapper = new LambdaQueryWrapper<>(CdnWithdrawal.class);
|
wrapper.orderByDesc(CdnWithdrawal::getCreateTime);
|
wrapper.eq(CdnWithdrawal::getUserId, userId);
|
PageParam<CdnWithdrawal> page1 = cdnWithdrawalService.page(param, wrapper);
|
if (!page1.getRecords().isEmpty()) {
|
for (CdnWithdrawal cdnWithdrawal1 : page1.getRecords()) {
|
CdnUserWallet info = userService.getInfo(cdnWithdrawal1.getUserId(), cdnWithdrawal1.getWalletId());
|
if (info != null) {
|
cdnWithdrawal1.setNickName(info.getNickName());
|
cdnWithdrawal1.setMobile(info.getMobile());
|
cdnWithdrawal1.setWalletName(info.getWalletName());
|
}
|
CdnUserBank cdnUserBank = cdnUserBankService.getById(cdnWithdrawal1.getUserBankId());
|
if (cdnUserBank != null) {
|
cdnWithdrawal1.setBankCode(cdnUserBank.getBankcode());
|
cdnWithdrawal1.setBank(cdnUserBank.getBank());
|
cdnWithdrawal1.setType(cdnUserBank.getType());
|
cdnWithdrawal1.setRealName(cdnUserBank.getName());
|
}
|
}
|
}
|
return ServerResponseEntity.success(page1);
|
}
|
|
@GetMapping("/getUserStatus")
|
@Operation(summary = "获取用户 提现/划转/转账 状态", description = "获取用户 提现/划转/转账 状态")
|
public ServerResponseEntity<User> getUserStatus(@RequestParam String userId) {
|
return ServerResponseEntity.success(userService.getById(userId));
|
}
|
|
@GetMapping("/getBankConfig")
|
@Operation(summary = "获取银行卡配置", description = "获取银行卡配置")
|
public ServerResponseEntity<CdnBankConfigParam> getUserConfigBank() {
|
String bankName = cdnConfigService.selectValueByName("bank_name");
|
String bankCode = cdnConfigService.selectValueByName("bank_code");
|
String companyName = cdnConfigService.selectValueByName("company_name");
|
CdnBankConfigParam cdnBankConfigParam = new CdnBankConfigParam(bankName, bankCode, companyName);
|
return ServerResponseEntity.success(cdnBankConfigParam);
|
}
|
|
@GetMapping("/getRechargeLog")
|
@Operation(summary = "获取用户充值记录", description = "获取用户充值记录")
|
public ServerResponseEntity<List<CdnUserRecharge>> getUserRechargeLog(@RequestParam String userId) {
|
List<CdnUserRecharge> cdnUserRechargeList = cdnUserRechargeService.list(Wrappers.lambdaQuery(CdnUserRecharge.class)
|
.eq(CdnUserRecharge::getUserId, userId).orderByDesc(CdnUserRecharge::getCreateTime));
|
return ServerResponseEntity.success(cdnUserRechargeList);
|
}
|
|
/**
|
* 验证支付密码是否为纯数字。
|
*
|
* @param payPassword 待验证的支付密码字符串
|
* @return 如果支付密码为纯数字则返回true,否则返回false
|
*/
|
public static boolean isNumericPayPassword(String payPassword) {
|
return NUMERIC_PATTERN.matcher(payPassword).matches();
|
}
|
|
// 支付密码加密
|
public static String encryptWithMD5(String password) {
|
try {
|
// 创建一个MD5的消息摘要对象
|
MessageDigest md = MessageDigest.getInstance("MD5");
|
|
// 将密码转换为字节数组并进行MD5摘要
|
byte[] messageDigest = md.digest(password.getBytes());
|
|
// 将摘要转换为16进制字符串
|
BigInteger no = new BigInteger(1, messageDigest);
|
String hashtext = no.toString(16);
|
|
// 补齐长度到32位
|
while (hashtext.length() < 32) {
|
hashtext = "0" + hashtext;
|
}
|
|
return hashtext;
|
} catch (NoSuchAlgorithmException e) {
|
throw new RuntimeException("MD5 hashing algorithm not found", e);
|
}
|
}
|
}
|