Commit 0a169770 authored by xuxin's avatar xuxin

代码修改以及bug修复

parent b6f8a32c
......@@ -263,6 +263,9 @@ public class AccountController {
return paymentService.wechatPayCallback(tradno);
}
/**
* 使用微信进行账户充值成功后,微信会调用该接口
*/
@RequestMapping(path = "/0xwxcheckorderstatus/{tradno}/{chargeType}", method = RequestMethod.GET)
public UserPaymentDto wechatCheckOrderStatus(Principal principal, @PathVariable String tradno, @PathVariable int chargeType) {
return paymentService.wxCheckOrderStatus(tradno, chargeType);
......@@ -281,6 +284,9 @@ public class AccountController {
paymentService.alipaCallback(tradno);
}
/**
* 使用 支付宝 充值 成功后回调
*/
@RequestMapping(path = "/0xalicheckorderstatus/{tradno}/{chargeType}", method = RequestMethod.GET)
public UserPaymentDto alipayCheckOrderStatus(Principal principal, @PathVariable(required = false) String tradno, @PathVariable int chargeType) {
return paymentService.aliCheckOrderStatus(tradno, chargeType);
......@@ -292,7 +298,6 @@ public class AccountController {
*/
@RequestMapping(path = "/0xalipay/{amount}", method = RequestMethod.GET)
public void alipayPutOrder(HttpServletRequest request, HttpServletResponse response, @PathVariable int amount) throws Exception {
String by = request.getParameter("by");
String form = paymentService.alipayPutPayOrder(request.getUserPrincipal().getName(), amount, by);
response.setContentType("text/html;charset=utf-8");
......
......@@ -159,10 +159,8 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
public List<String> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception {
if (ipResourceRequestDto.getRegion() == null) {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
if (ipResourceRequestDto.getRegionCn() == null) {
// 1. 数据校验
if (ipResourceRequestDto.getRegion() == null || ipResourceRequestDto.getRegionCn() == null) {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
......@@ -171,6 +169,7 @@ public class IpResourceServiceImpl implements IpResourceService {
}
// 2. 计算 ip 单价信息
double newprice = 0;
if (!"own".equals(ipResourceRequestDto.getVendor())) {
Map<String, List<String>> priceList = ipOptionsRepository.findAll().get(0).getIpPlatForm();
......@@ -182,12 +181,15 @@ public class IpResourceServiceImpl implements IpResourceService {
newprice = "week".equals(ipResourceRequestDto.getUnit()) ? (Integer.valueOf(price) / 3) : Integer.valueOf(price);
}
// 3. 计算总共需要花费多少钱 并 校验账户余额 够不够扣费
IpChargeResultDto ipChargeResultDto = accountService.preChargeByMoney(username, newprice * ipResourceRequestDto.getAmount() * ipResourceRequestDto.getPeriod());
if (!ipChargeResultDto.isSuccess()) {
throw new ClientRequestException(AccountErrorCode.NOTENOUGHBALANCE);
}
// 生成随机密码
String password = StringUtils.isNotBlank(ipResourceRequestDto.getPassword()) ? ipResourceRequestDto.getPassword() : genRandom(3, 12);
List<IpResourceDto> ipResourceDtos = new ArrayList<>();
List<String> ipIds = new ArrayList<>();
......@@ -195,19 +197,22 @@ public class IpResourceServiceImpl implements IpResourceService {
IpResource ipResource = new IpResource();
ipResource.setPeriod(ipResourceRequestDto.getPeriod());
//充6送1
if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 6) {
ipResource.setPeriod(7);
} else if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 12) {
ipResource.setPeriod(14);
if (ipResourceRequestDto.getUnit().equals("month")) {
if (ipResourceRequestDto.getPeriod() == 6) {
ipResource.setPeriod(7);
}
if (ipResourceRequestDto.getPeriod() == 12) {
ipResource.setPeriod(14);
}
}
// 根据 ip 的 vendor 来封装部分的 ipResource 信息
if (ipResourceRequestDto.getVendor().equals("local")) {
ipResource.setAddr("本地Ip未使用");
ipResource.setIpType(IpType.LOCAL);
ipResource.setVendor(Vendor.valueOf(ipResourceRequestDto.getVendor()));
ipResource.setVendorCn("本地");
ipResource.setStatus(4);
ipResource.setUsername(USERNAME);
long validTime = 0;
if (ipResourceRequestDto.getUnit().equals("week")) {
......@@ -216,12 +221,10 @@ public class IpResourceServiceImpl implements IpResourceService {
validTime = Instant.now().atZone(ZoneOffset.UTC).plusMonths(ipResource.getPeriod()).toInstant().toEpochMilli();
}
ipResource.setValidTime(validTime);
ipResource.setUsername(USERNAME);
ipResource.setPort(port);
} else if (ipResourceRequestDto.getVendor().equals("own")) {
if (ipResourceRequestDto.getAddr() == null || ipResourceRequestDto.getAddr().isEmpty()) {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
if (StringUtils.isBlank(ipResourceRequestDto.getAddr().get(i))) {
if (ipResourceRequestDto.getAddr() == null || ipResourceRequestDto.getAddr().isEmpty() || StringUtils.isBlank(ipResourceRequestDto.getAddr().get(i))) {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
......@@ -252,18 +255,18 @@ public class IpResourceServiceImpl implements IpResourceService {
break;
}
ipResource.setStatus(6);
long validTime = 0;
if (ipResourceRequestDto.getUnit().equals("week")) {
ipResource.setValidTime(Instant.now().atZone(ZoneOffset.UTC).plusWeeks(ipResource.getPeriod()).toInstant().toEpochMilli());
validTime = Instant.now().atZone(ZoneOffset.UTC).plusWeeks(ipResource.getPeriod()).toInstant().toEpochMilli();
} else {
ipResource.setValidTime(Instant.now().atZone(ZoneOffset.UTC).plusMonths(ipResource.getPeriod()).toInstant().toEpochMilli());
validTime = Instant.now().atZone(ZoneOffset.UTC).plusMonths(ipResource.getPeriod()).toInstant().toEpochMilli();
}
ipResource.setValidTime(validTime);
ipResource.setUsername(USERNAME);
ipResource.setPort(port);
}
ipResource.setPurchasedTime(Instant.now().toEpochMilli());
if (account.getParent() != null) {
ipResource.setUserParent(account.getParent());
}
......@@ -279,6 +282,7 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResource.setHealthLockTimestamp(Instant.now().minusSeconds(60 * 20).toEpochMilli());
}
ipResource.setPurchasedTime(Instant.now().toEpochMilli());
ipResource.setRegionCn(ipResourceRequestDto.getRegionCn());
ipResource.setProtocol(protocol);
ipResource.setPassword(password);
......@@ -296,10 +300,13 @@ public class IpResourceServiceImpl implements IpResourceService {
}
if (!ipResourceRequestDto.getVendor().equals("own")) {
// 封装购买 ip 的费用 信息
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1, ipResourceRequestDto.getPayMethod());
// 用来记录购买与消费的操作 userbalance 与 费用明细 userprepaidbilling
accountService.chargeByMoney(username, newprice * ipChargeRequestDto.getAmount() * ipChargeRequestDto.getPeriod(), ipChargeRequestDto);
}
// 如果ip需要绑定店铺,则将店铺与ip绑定
if (ipResourceRequestDto.getShopId() != null) {
ShopRequestDto shopRequestDto = new ShopRequestDto();
shopRequestDto.setIpId(ipResourceDtos.get(0).getId());
......
......@@ -234,14 +234,14 @@ public class ShopServiceImpl implements ShopService {
ipAndShopService.unBindShop(username, shopRequestDto);
}
// 4. 删除当前店铺关联的所有的 usershop信息
// 4. 获取当前店铺关联的所有的 usershop信息 并删除数据库中 usershop信息
List<UserShop> userShops = userShopRepository.findByShopId(shopId);
boolean result = userShopRepository.deleteByShopId(shopId);
if (result) {
// 5. 删除当前店铺,并更新 account信息 todo
shopRepository.deleteById(shopId);
// 6. 更新 和店铺关联的所有的 account 的信息
List<UserShop> userShops = userShopRepository.findByShopId(shopId);
List<Account> accountList = accountRepository.findByNameIn(userShops.stream().map(UserShop::getUsername).collect(Collectors.toList()));
for (Account a : accountList) {
a.setShopCount(account.getShopCount() - 1);
......
......@@ -43,13 +43,17 @@ public class PaymentTask {
payment -> {
PaymentMethod paymentMethod = payment.getPaymentMethod();
try {
// 自动调用 微信或者支付宝的支付接口来确认 支付状态
/*
* 自动调用 微信或者支付宝的支付接口来确认 支付状态
* chargeType 取值范围为 0-4
* 此处设置为 100 仅仅只是为了避免 wxCheckOrderStatus() 方法中 chargeType == 0 相关代码块
*/
if (PaymentMethod.WECHAT.equals(paymentMethod)) {
paymentService.wxCheckOrderStatus(payment.getTradeNo());
paymentService.wxCheckOrderStatus(payment.getTradeNo(), 100);
}
if (PaymentMethod.ALIPAY.equals(paymentMethod)) {
paymentService.aliCheckOrderStatus(payment.getTradeNo());
paymentService.aliCheckOrderStatus(payment.getTradeNo(), 100);
}
} catch (Exception e) {
log.error("checkPayments", e);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment