From 4c1d0bfb23e229c86e463c2f4b01ea6b3dfeedd8 Mon Sep 17 00:00:00 2001 From: liaozetao Date: Tue, 11 Jul 2023 18:04:55 +0800 Subject: [PATCH] =?UTF-8?q?H5=E5=8E=BB=E9=99=A4APP=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/constant/ApplicationConstant.java | 44 ++++---- .../accompany/common/constant/Constant.java | 1 + .../common/exception/ApiException.java | 4 + .../enums/withdraw/WithdrawAccountEnum.java | 36 ------- .../withdraw/WithdrawUserAccountService.java | 22 ++++ .../impl/WithdrawAccountDtlServiceImpl.java | 22 ++-- .../impl/WithdrawUserAccountServiceImpl.java | 100 +++++++++++++++++- .../vo/withdraw/WithdrawUserAccountVo.java | 33 ++++++ .../WithdrawUserAccountController.java | 40 ++++++- .../PasswordAuthenticationProvider.java | 10 +- 10 files changed, 238 insertions(+), 74 deletions(-) delete mode 100644 accompany-business/accompany-business-service/src/main/java/com/accompany/business/enums/withdraw/WithdrawAccountEnum.java create mode 100644 accompany-business/accompany-business-service/src/main/java/com/accompany/business/vo/withdraw/WithdrawUserAccountVo.java diff --git a/accompany-base/accompany-common/src/main/java/com/accompany/common/constant/ApplicationConstant.java b/accompany-base/accompany-common/src/main/java/com/accompany/common/constant/ApplicationConstant.java index 9b91dc87f..d81d95a09 100644 --- a/accompany-base/accompany-common/src/main/java/com/accompany/common/constant/ApplicationConstant.java +++ b/accompany-base/accompany-common/src/main/java/com/accompany/common/constant/ApplicationConstant.java @@ -18,32 +18,34 @@ public class ApplicationConstant { public static final String DEFAULT_CHARSET = "UTF-8"; - public static class PublicParameters { - public static final String SIGN = "pub_sign"; - public static final String PUB_UID = "pub_uid"; - public static final String UID = "uid"; - public static final String TIMESTAMP = "pub_timestamp"; - public static final String TICKET = "ticket"; - public static final String PUB_TICKET = "pub_ticket"; - public static final String APP_VERSION = "appVersion"; + public static class PublicParameters { + public static final String SIGN = "pub_sign"; + public static final String PUB_UID = "pub_uid"; + public static final String UID = "uid"; + public static final String TIMESTAMP = "pub_timestamp"; + public static final String TICKET = "ticket"; + public static final String PUB_TICKET = "pub_ticket"; + public static final String APP_VERSION = "appVersion"; public static final String APP = "app"; public static final String DEVICE_ID = "deviceId"; public static final String MODEL = "model"; public static final String OS_VERSION = "osVersion"; - public static final String OS = "os"; - public static final String OS_ANDROID = "android"; - public static final String OS_IOS = "ios"; - public static final String APP_CHANNEL = "channel"; + public static final String OS = "os"; + public static final String OS_ANDROID = "android"; + public static final String OS_IOS = "ios"; + public static final String APP_CHANNEL = "channel"; - public static final String H5_TOKEN = "h5_token"; - public static final String CLIENT = "client"; - } + public static final String H5_TOKEN = "h5_token"; + public static final String CLIENT = "client"; - /** - * 公参名 - */ - public static final List PUBLIC_PARAMTER_NAMES = Arrays - .asList(new String[]{"pub_sign", "pub_uid", "pub_ticket", "appVersion", "appVersionCode", "channel", "deviceId", "ispType", "model", "netType", "os", - "osVersion", "app", "ticket", "client"}); + public static final String H5 = "h5"; + } + + /** + * 公参名 + */ + public static final List PUBLIC_PARAMTER_NAMES = Arrays + .asList(new String[]{"pub_sign", "pub_uid", "pub_ticket", "appVersion", "appVersionCode", "channel", "deviceId", "ispType", "model", "netType", "os", + "osVersion", "app", "ticket", "client"}); } diff --git a/accompany-base/accompany-common/src/main/java/com/accompany/common/constant/Constant.java b/accompany-base/accompany-common/src/main/java/com/accompany/common/constant/Constant.java index cbdb96133..d8f47ecbd 100644 --- a/accompany-base/accompany-common/src/main/java/com/accompany/common/constant/Constant.java +++ b/accompany-base/accompany-common/src/main/java/com/accompany/common/constant/Constant.java @@ -2716,6 +2716,7 @@ public class Constant { public static final String ANDROID = "android"; public static final String ALL = "all"; public static final String NONE = "none"; + } public static class RankingType { diff --git a/accompany-base/accompany-common/src/main/java/com/accompany/common/exception/ApiException.java b/accompany-base/accompany-common/src/main/java/com/accompany/common/exception/ApiException.java index 09faff1dd..dd5a6fc99 100644 --- a/accompany-base/accompany-common/src/main/java/com/accompany/common/exception/ApiException.java +++ b/accompany-base/accompany-common/src/main/java/com/accompany/common/exception/ApiException.java @@ -12,6 +12,10 @@ public class ApiException extends RuntimeException { this(status.value(), status.getReasonPhrase()); } + public ApiException(String message) { + this(BusiStatus.SERVERERROR.value(), message); + } + public ApiException(int responseCode, String message) { super(message); this.responseCode = responseCode; diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/enums/withdraw/WithdrawAccountEnum.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/enums/withdraw/WithdrawAccountEnum.java deleted file mode 100644 index 63e316e5a..000000000 --- a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/enums/withdraw/WithdrawAccountEnum.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.accompany.business.enums.withdraw; - -import com.accompany.business.constant.withdraw.WithdrawAccountTypeConstant; - -/** - * @author: liaozetao - * @date: 2023/7/11 12:08 - * @description: - */ -public enum WithdrawAccountEnum { - - CHINA_UNION_PAY("中国大陆银联", WithdrawAccountTypeConstant.CHINA_UNION_PAY), - - MAY_BANK("马来西亚银行", WithdrawAccountTypeConstant.MAY_BANK), - - BANK_OF_SINGAPORE("新加坡银行", WithdrawAccountTypeConstant.BANK_OF_SINGAPORE), - - OTHER("其它账户", WithdrawAccountTypeConstant.ORDER_ACCOUNT); - - private final String name; - - private final Integer value; - - WithdrawAccountEnum(String name, Integer value) { - this.name = name; - this.value = value; - } - - public String getName() { - return name; - } - - public Integer getValue() { - return value; - } -} diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/WithdrawUserAccountService.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/WithdrawUserAccountService.java index 164266698..788893ce6 100644 --- a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/WithdrawUserAccountService.java +++ b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/WithdrawUserAccountService.java @@ -1,8 +1,12 @@ package com.accompany.business.service.withdraw; import com.accompany.business.model.withdraw.WithdrawUserAccount; +import com.accompany.business.vo.withdraw.WithdrawUserAccountVo; import com.baomidou.mybatisplus.extension.service.IService; +import java.math.BigDecimal; +import java.util.List; + /** * @author: liaozetao * @date: 2023/7/7 14:54 @@ -16,4 +20,22 @@ public interface WithdrawUserAccountService extends IService accountList(Long uid); + + /** + * 汇率计算 + * + * @param uid + * @param accountType + * @param goldNum + * @return + */ + BigDecimal calculate(Long uid, Integer accountType, Integer goldNum); } diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/impl/WithdrawAccountDtlServiceImpl.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/impl/WithdrawAccountDtlServiceImpl.java index e84c073bb..d9f3f59d3 100644 --- a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/impl/WithdrawAccountDtlServiceImpl.java +++ b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/impl/WithdrawAccountDtlServiceImpl.java @@ -1,7 +1,7 @@ package com.accompany.business.service.withdraw.impl; import cn.hutool.core.collection.CollectionUtil; -import com.accompany.business.enums.withdraw.WithdrawAccountEnum; +import com.accompany.business.constant.withdraw.WithdrawAccountTypeConstant; import com.accompany.business.model.withdraw.WithdrawAccountDtl; import com.accompany.business.model.withdraw.WithdrawUserAccount; import com.accompany.business.mybatismapper.withdraw.WithdrawAccountDtlMapper; @@ -16,7 +16,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.function.Function; @@ -31,6 +30,9 @@ import java.util.stream.Collectors; @Service public class WithdrawAccountDtlServiceImpl extends ServiceImpl implements WithdrawAccountDtlService { + @Autowired + private WithdrawAccountDtlService withdrawAccountDtlService; + @Autowired private WithdrawUserAccountService withdrawUserAccountService; @@ -38,17 +40,23 @@ public class WithdrawAccountDtlServiceImpl extends ServiceImpl getAccounts(Long uid) { List userAccounts = withdrawUserAccountService.list(Wrappers.lambdaQuery() .eq(WithdrawUserAccount::getUid, uid) - .in(WithdrawUserAccount::getAccountType, Arrays.stream(WithdrawAccountEnum.values()).map(WithdrawAccountEnum::getValue).collect(Collectors.toList()))); + .in(WithdrawUserAccount::getAccountType, + WithdrawAccountTypeConstant.ORDER_ACCOUNT, + WithdrawAccountTypeConstant.CHINA_UNION_PAY, + WithdrawAccountTypeConstant.MAY_BANK, + WithdrawAccountTypeConstant.BANK_OF_SINGAPORE + )); Map accountMap = null; if (CollectionUtil.isNotEmpty(userAccounts)) { accountMap = userAccounts.stream().collect(Collectors.toMap(WithdrawUserAccount::getAccountType, Function.identity(), (v1, v2) -> v1)); } List accounts = new ArrayList<>(); - for (WithdrawAccountEnum withdrawAccount : WithdrawAccountEnum.values()) { - Integer accountType = withdrawAccount.getValue(); + List accountDtls = withdrawAccountDtlService.list(); + for (WithdrawAccountDtl accountDtl : accountDtls) { + Integer accountType = accountDtl.getAccountType(); WithdrawAccountDtlVo account = new WithdrawAccountDtlVo(); - account.setAccountName(withdrawAccount.getName()); - account.setAccountType(withdrawAccount.getValue()); + account.setAccountName(accountDtl.getAccountName()); + account.setAccountType(accountType); account.setIsBind(accountMap != null && accountMap.containsKey(accountType) ? Constant.Yes1No0.YES : Constant.Yes1No0.NO); accounts.add(account); } diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/impl/WithdrawUserAccountServiceImpl.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/impl/WithdrawUserAccountServiceImpl.java index 93708f30d..23b02ca81 100644 --- a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/impl/WithdrawUserAccountServiceImpl.java +++ b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/withdraw/impl/WithdrawUserAccountServiceImpl.java @@ -1,14 +1,27 @@ package com.accompany.business.service.withdraw.impl; -import com.accompany.business.constant.withdraw.WithdrawAccountTypeConstant; +import cn.hutool.core.collection.CollectionUtil; +import com.accompany.business.model.withdraw.ExchangeRate; +import com.accompany.business.model.withdraw.WithdrawAccountDtl; +import com.accompany.business.model.withdraw.WithdrawConfig; import com.accompany.business.model.withdraw.WithdrawUserAccount; import com.accompany.business.mybatismapper.withdraw.WithdrawUserAccountMapper; +import com.accompany.business.service.withdraw.ExchangeRateService; +import com.accompany.business.service.withdraw.WithdrawAccountDtlService; +import com.accompany.business.service.withdraw.WithdrawConfigService; import com.accompany.business.service.withdraw.WithdrawUserAccountService; +import com.accompany.business.vo.withdraw.WithdrawUserAccountVo; +import com.accompany.common.constant.Constant; +import com.accompany.common.exception.ApiException; +import com.accompany.common.status.BusiStatus; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.util.Date; +import java.math.BigDecimal; +import java.util.*; /** * @author: liaozetao @@ -19,13 +32,96 @@ import java.util.Date; @Service public class WithdrawUserAccountServiceImpl extends ServiceImpl implements WithdrawUserAccountService { + @Autowired + private WithdrawConfigService withdrawConfigService; + + @Autowired + private ExchangeRateService exchangeRateService; + + @Autowired + private WithdrawAccountDtlService withdrawAccountDtlService; + + @Autowired + private WithdrawUserAccountService withdrawUserAccountService; + @Override public void saveAccount(WithdrawUserAccount account) { Date now = new Date(); Long id = account.getId(); if (id != null) { account.setUpdateTime(now); + } else { + Long uid = account.getUid(); + Integer accountType = account.getAccountType(); + int count = count(Wrappers.lambdaQuery() + .eq(WithdrawUserAccount::getUid, uid) + .eq(WithdrawUserAccount::getAccountType, accountType)); + if (count > 0) { + throw new ApiException(BusiStatus.SERVERERROR.value(), "该提现方式已添加"); + } } saveOrUpdate(account); } + + @Override + public List accountList(Long uid) { + List accountDtls = withdrawAccountDtlService.list(); + List userAccounts = list(Wrappers.lambdaQuery() + .eq(WithdrawUserAccount::getUid, uid)); + List accounts = new ArrayList<>(); + if (CollectionUtil.isNotEmpty(userAccounts)) { + for (WithdrawUserAccount userAccount : userAccounts) { + Integer accountType = userAccount.getAccountType(); + WithdrawUserAccountVo account = new WithdrawUserAccountVo(); + account.setAccountType(accountType); + if (CollectionUtil.isNotEmpty(accountDtls)) { + Optional any = accountDtls.stream().filter(v -> v.getAccountType().equals(accountType)).findAny(); + if (any.isPresent()) { + WithdrawAccountDtl withdrawAccountDtl = any.get(); + account.setAccountName(withdrawAccountDtl.getAccountName()); + account.setCurrencyType(withdrawAccountDtl.getCurrencyType()); + } + } + accounts.add(account); + } + } + return accounts; + } + + @Override + public BigDecimal calculate(Long uid, Integer accountType, Integer goldNum) { + List configs = withdrawConfigService.list(Wrappers.lambdaQuery() + .eq(WithdrawConfig::getIsEnabled, Constant.Yes1No0.YES)); + if (CollectionUtil.isEmpty(configs)) { + return BigDecimal.ZERO; + } + int count = withdrawUserAccountService.count(Wrappers.lambdaQuery() + .eq(WithdrawUserAccount::getUid, uid) + .eq(WithdrawUserAccount::getAccountType, accountType)); + if (count == 0) { + throw new ApiException("非法账户"); + } + List accountDtls = withdrawAccountDtlService.list(Wrappers.lambdaQuery() + .eq(WithdrawAccountDtl::getAccountType, accountType)); + if (CollectionUtil.isEmpty(accountDtls)) { + return BigDecimal.ZERO; + } + WithdrawAccountDtl withdrawAccountDtl = accountDtls.get(0); + String currencyType = withdrawAccountDtl.getCurrencyType(); + List exchangeRates = exchangeRateService.list(Wrappers.lambdaQuery() + .eq(ExchangeRate::getCurrency, currencyType)); + WithdrawConfig withdrawConfig = configs.get(0); + ExchangeRate exchangeRate = exchangeRates.get(0); + BigDecimal rate = exchangeRate.getRate(); + //提现手续费 + BigDecimal handlingRate = withdrawConfig.getChargeRate(); + //扣除手续费后的金币 + BigDecimal afterGoldNum = new BigDecimal(goldNum).subtract(new BigDecimal(goldNum).multiply(handlingRate.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP))); + //金币:美元 = 1:1000 + BigDecimal dollarAmount = afterGoldNum.divide(new BigDecimal(1000), 2, BigDecimal.ROUND_HALF_UP); + //美元乘于汇率 + BigDecimal amount = dollarAmount.multiply(rate); + log.info("rate : {}, handlingRate : {}, afterGoldNum : {}, dollarAmount : {}, amount : {}", rate, handlingRate, afterGoldNum, dollarAmount, amount); + return amount; + } } diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/vo/withdraw/WithdrawUserAccountVo.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/vo/withdraw/WithdrawUserAccountVo.java new file mode 100644 index 000000000..28988d42f --- /dev/null +++ b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/vo/withdraw/WithdrawUserAccountVo.java @@ -0,0 +1,33 @@ +package com.accompany.business.vo.withdraw; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author: liaozetao + * @date: 2023/7/11 16:59 + * @description: + */ +@Data +@ApiModel +public class WithdrawUserAccountVo { + + /** + * 账户名称 + */ + @ApiModelProperty("账户名称") + private String accountName; + + /** + * 币种 + */ + @ApiModelProperty("币种") + private String currencyType; + + /** + * 账户类型 + */ + @ApiModelProperty("账户类型") + private Integer accountType; +} diff --git a/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/withdraw/WithdrawUserAccountController.java b/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/withdraw/WithdrawUserAccountController.java index 7f6f5bfcf..60d306f3d 100644 --- a/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/withdraw/WithdrawUserAccountController.java +++ b/accompany-business/accompany-business-web/src/main/java/com/accompany/business/controller/withdraw/WithdrawUserAccountController.java @@ -2,14 +2,15 @@ package com.accompany.business.controller.withdraw; import com.accompany.business.model.withdraw.WithdrawUserAccount; import com.accompany.business.service.withdraw.WithdrawUserAccountService; +import com.accompany.business.vo.withdraw.WithdrawUserAccountVo; import com.accompany.common.result.BusiResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.math.BigDecimal; +import java.util.List; /** * @author: liaozetao @@ -33,7 +34,36 @@ public class WithdrawUserAccountController { @ApiOperation("保存") @PostMapping("save") public BusiResult save(@RequestBody WithdrawUserAccount account) { - + withdrawUserAccountService.saveAccount(account); return BusiResult.success(); } + + /** + * 列表 + * + * @param uid + * @return + */ + @ApiOperation("列表") + @GetMapping("list") + public BusiResult> accountList(@RequestParam("uid") Long uid) { + return BusiResult.success(withdrawUserAccountService.accountList(uid)); + } + + /** + * 汇率计算 + * + * @param uid + * @param accountType + * @param goldNum + * @return + */ + @ApiOperation("汇率计算") + @GetMapping("calculate") + public BusiResult calculate(@RequestParam("uid") Long uid, @RequestParam("accountType") Integer accountType, @RequestParam("goldNum") Integer goldNum) { + BigDecimal amount = withdrawUserAccountService.calculate(uid, accountType, goldNum); + return BusiResult.success(); + } + + } diff --git a/accompany-oauth2/accompany-oauth2-service/src/main/java/com/accompany/oauth2/support/password/PasswordAuthenticationProvider.java b/accompany-oauth2/accompany-oauth2-service/src/main/java/com/accompany/oauth2/support/password/PasswordAuthenticationProvider.java index 2fdac055d..0452b4f5e 100644 --- a/accompany-oauth2/accompany-oauth2-service/src/main/java/com/accompany/oauth2/support/password/PasswordAuthenticationProvider.java +++ b/accompany-oauth2/accompany-oauth2-service/src/main/java/com/accompany/oauth2/support/password/PasswordAuthenticationProvider.java @@ -1,5 +1,6 @@ package com.accompany.oauth2.support.password; +import com.accompany.common.constant.ApplicationConstant; import com.accompany.common.constant.Constant; import com.accompany.common.device.DeviceInfo; import com.accompany.common.redis.RedisKey; @@ -84,9 +85,12 @@ public class PasswordAuthenticationProvider implements AuthenticationProvider { loginTypeEnum = LoginTypeEnum.PASSWORD; } // 低于1.5版本不能进行登录 - String limitAppVersion = sysConfService.getDefaultSysConfValueById(Constant.SysConfId.APP_VERSION_LIMIT, Constant.LOWEST_VERSION_FOR_USE); - if (deviceInfo.getAppVersion() == null || AppVersionUtil.compareVersion(deviceInfo.getAppVersion(), limitAppVersion) < 0) { - throw new CustomOAuth2Exception(CustomOAuth2Exception.APP_VERSION_TOO_OLD, OAuthStatus.APP_VERSION_TOO_OLD.getReasonPhrase()); + String client = deviceInfo.getClient(); + if (!ApplicationConstant.PublicParameters.H5.equals(client)) { + String limitAppVersion = sysConfService.getDefaultSysConfValueById(Constant.SysConfId.APP_VERSION_LIMIT, Constant.LOWEST_VERSION_FOR_USE); + if (deviceInfo.getAppVersion() == null || AppVersionUtil.compareVersion(deviceInfo.getAppVersion(), limitAppVersion) < 0) { + throw new CustomOAuth2Exception(CustomOAuth2Exception.APP_VERSION_TOO_OLD, OAuthStatus.APP_VERSION_TOO_OLD.getReasonPhrase()); + } } if (phoneBlackService.checkIsNeedIntercept(username)) { throw new CustomOAuth2Exception(CustomOAuth2Exception.PHONE_BE_INTERCEPTED,