提交支付2.0版本
This commit is contained in:
parent
82df411a6d
commit
0359e93c19
|
@ -8,6 +8,6 @@ auth:
|
|||
- /swagger-ui.html
|
||||
- /swagger-ui/**
|
||||
- /doc.html
|
||||
- /maku/t_user/**
|
||||
- /maku/**
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.maku.maku.controller;
|
|||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.common.utils.Result;
|
||||
|
@ -30,8 +31,6 @@ import java.util.List;
|
|||
public class TPurchaseController {
|
||||
private final TPurchaseService tPurchaseService;
|
||||
|
||||
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
@PreAuthorize("hasAuthority('maku:t_purchase:page')")
|
||||
|
|
|
@ -2,11 +2,15 @@ package net.maku.maku.controller;
|
|||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.AllArgsConstructor;
|
||||
import net.maku.framework.common.cache.RedisCache;
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.common.utils.Result;
|
||||
import net.maku.maku.convert.TPurchaseDetailsConvert;
|
||||
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
||||
import net.maku.maku.entity.TPurchaseEntity;
|
||||
import net.maku.maku.entity.TUserEntity;
|
||||
import net.maku.maku.service.TPurchaseDetailsService;
|
||||
import net.maku.maku.query.TPurchaseDetailsQuery;
|
||||
import net.maku.maku.vo.TPurchaseDetailsVO;
|
||||
|
@ -29,6 +33,19 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
public class TPurchaseDetailsController {
|
||||
private final TPurchaseDetailsService tPurchaseDetailsService;
|
||||
private final RedisCache redisCache;
|
||||
@GetMapping("/buy")
|
||||
@Operation(summary = "购买")
|
||||
public Result<?> purchaseBook(HttpServletRequest request) {
|
||||
String token = request.getHeader("token");
|
||||
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
||||
boolean isPurchased = tPurchaseDetailsService.purchaseBook(entity);
|
||||
if (isPurchased) {
|
||||
return Result.ok("购买成功");
|
||||
} else {
|
||||
return Result.error("余额不足,请充值");
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("page")
|
||||
@Operation(summary = "分页")
|
||||
|
|
|
@ -54,8 +54,14 @@ public class TUserController {
|
|||
if (existingUser != null) {
|
||||
return ResponseEntity.badRequest().body(Result.error("用户名已存在"));
|
||||
} else {
|
||||
//明文注册
|
||||
tUserService.save(entity);
|
||||
return ResponseEntity.ok(Result.ok("注册成功"));
|
||||
//加密注册
|
||||
// String encryptedPassword = passwordEncoder.passwordEncoder().encode(entity.getPassword());
|
||||
// entity.setPassword(encryptedPassword);
|
||||
// tUserService.save(entity);
|
||||
// return ResponseEntity.ok(Result.ok("注册成功"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,15 +69,30 @@ public class TUserController {
|
|||
@PostMapping("/login")
|
||||
@Operation(summary = "登录")
|
||||
public Result<String> login(@RequestBody TUserEntity entity){
|
||||
//加密登录
|
||||
// TUserEntity entity1 = tUserService.findByUsername(entity.getUsername());
|
||||
// if (entity1 != null) {
|
||||
// // 验证密码是否匹配
|
||||
// boolean isMatch = passwordEncoder.passwordEncoder().matches(entity.getPassword(), entity1.getPassword());
|
||||
// if (isMatch) {
|
||||
// String token = UUID.randomUUID().toString();
|
||||
// redisCache.set(token, entity1);
|
||||
// return Result.ok(token);
|
||||
// } else {
|
||||
// return Result.error("密码错误");
|
||||
// }
|
||||
// }else {
|
||||
// return Result.error("用户不存在");
|
||||
// }
|
||||
|
||||
//明文登录
|
||||
TUserEntity entity1 = tUserService.login(entity);
|
||||
// 验证密码是否匹配
|
||||
boolean isMatch = passwordEncoder.passwordEncoder().matches(entity1.getPassword(), entity.getPassword());
|
||||
if (isMatch) {
|
||||
if(entity1 != null) {
|
||||
String token = UUID.randomUUID().toString();
|
||||
redisCache.set(token, entity1);
|
||||
return Result.ok(token);
|
||||
} else {
|
||||
return Result.error("密码错误");
|
||||
}else {
|
||||
return Result.error("用户名不存在");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,7 +122,7 @@ public class TUserController {
|
|||
String orderId = payConfig.generateOrderId();
|
||||
boolean paymentResult = payConfig.callPaymentService(balance);
|
||||
if (paymentResult) {
|
||||
int money = entity.getBalance();
|
||||
double money = entity.getBalance();
|
||||
entity.setBalance(money + balance);
|
||||
tUserService.updateById(entity);
|
||||
return Result.ok(orderId+"支付成功");
|
||||
|
|
|
@ -22,6 +22,8 @@ public class TPurchaseDetailsEntity {
|
|||
|
||||
private Integer bookId;
|
||||
|
||||
private BigDecimal price;
|
||||
private double price;
|
||||
|
||||
private double count;
|
||||
|
||||
}
|
|
@ -25,7 +25,7 @@ public class TUserEntity {
|
|||
|
||||
private String avatar;
|
||||
|
||||
private int balance;
|
||||
private double balance;
|
||||
|
||||
private Integer status;
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.maku.maku.service;
|
|||
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.mybatis.service.BaseService;
|
||||
import net.maku.maku.entity.TUserEntity;
|
||||
import net.maku.maku.vo.TPurchaseDetailsVO;
|
||||
import net.maku.maku.query.TPurchaseDetailsQuery;
|
||||
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
||||
|
@ -23,4 +24,8 @@ public interface TPurchaseDetailsService extends BaseService<TPurchaseDetailsEnt
|
|||
void update(TPurchaseDetailsVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
|
||||
boolean purchaseBook(TUserEntity entity);
|
||||
|
||||
}
|
|
@ -2,6 +2,8 @@ package net.maku.maku.service;
|
|||
|
||||
import net.maku.framework.common.utils.PageResult;
|
||||
import net.maku.framework.mybatis.service.BaseService;
|
||||
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
||||
import net.maku.maku.entity.TUserEntity;
|
||||
import net.maku.maku.vo.TPurchaseVO;
|
||||
import net.maku.maku.query.TPurchaseQuery;
|
||||
import net.maku.maku.entity.TPurchaseEntity;
|
||||
|
@ -23,4 +25,6 @@ public interface TPurchaseService extends BaseService<TPurchaseEntity> {
|
|||
void update(TPurchaseVO vo);
|
||||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
|
||||
}
|
|
@ -28,5 +28,6 @@ public interface TUserService extends BaseService<TUserEntity> {
|
|||
|
||||
TUserVO updateUser(TUserVO vo);
|
||||
|
||||
TUserEntity findByUsername(String username);
|
||||
|
||||
}
|
|
@ -9,7 +9,9 @@ import net.maku.framework.common.utils.PageResult;
|
|||
import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
||||
import net.maku.maku.convert.TPurchaseDetailsConvert;
|
||||
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
||||
import net.maku.maku.entity.TUserEntity;
|
||||
import net.maku.maku.query.TPurchaseDetailsQuery;
|
||||
import net.maku.maku.service.TUserService;
|
||||
import net.maku.maku.vo.TPurchaseDetailsVO;
|
||||
import net.maku.maku.dao.TPurchaseDetailsDao;
|
||||
import net.maku.maku.service.TPurchaseDetailsService;
|
||||
|
@ -28,6 +30,7 @@ import java.util.List;
|
|||
@AllArgsConstructor
|
||||
public class TPurchaseDetailsServiceImpl extends BaseServiceImpl<TPurchaseDetailsDao, TPurchaseDetailsEntity> implements TPurchaseDetailsService {
|
||||
|
||||
private final TUserService tUserService;
|
||||
@Override
|
||||
public PageResult<TPurchaseDetailsVO> page(TPurchaseDetailsQuery query) {
|
||||
IPage<TPurchaseDetailsEntity> page = baseMapper.selectPage(getPage(query), getWrapper(query));
|
||||
|
@ -62,4 +65,21 @@ public class TPurchaseDetailsServiceImpl extends BaseServiceImpl<TPurchaseDetail
|
|||
removeByIds(idList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean purchaseBook(TUserEntity entity) {
|
||||
LambdaQueryWrapper<TPurchaseDetailsEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(TPurchaseDetailsEntity::getPurchaseId,entity.getId());
|
||||
TPurchaseDetailsEntity one =getOne(wrapper);
|
||||
double price = one.getPrice();
|
||||
double count =one.getCount();
|
||||
double balance= entity.getBalance();
|
||||
if (balance>=price*count){
|
||||
double newBalance = balance-price*count;
|
||||
entity.setBalance(newBalance);
|
||||
tUserService.updateById(entity);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,6 +10,7 @@ import net.maku.framework.mybatis.service.impl.BaseServiceImpl;
|
|||
import net.maku.maku.convert.TPurchaseConvert;
|
||||
import net.maku.maku.entity.TPurchaseEntity;
|
||||
import net.maku.maku.query.TPurchaseQuery;
|
||||
import net.maku.maku.service.TUserService;
|
||||
import net.maku.maku.vo.TPurchaseVO;
|
||||
import net.maku.maku.dao.TPurchaseDao;
|
||||
import net.maku.maku.service.TPurchaseService;
|
||||
|
|
|
@ -83,7 +83,16 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
|
|||
return vo;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TUserEntity findByUsername(String username) {
|
||||
LambdaQueryWrapper<TUserEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(TUserEntity::getUsername,username);
|
||||
TUserEntity one = getOne(wrapper);
|
||||
if(ObjectUtils.isNotNull(one)) {
|
||||
return one;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -3,6 +3,8 @@ spring:
|
|||
redis:
|
||||
database: 0
|
||||
host: localhost
|
||||
port: 6379
|
||||
password: 123456
|
||||
#timeout: 6000ms # 连接超时时长(毫秒)
|
||||
datasource:
|
||||
dynamic:
|
||||
|
|
Loading…
Reference in New Issue
Block a user