提交支付2.0版本
This commit is contained in:
parent
0359e93c19
commit
5849bdf4c1
|
@ -13,6 +13,7 @@ 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.TCardVo;
|
||||
import net.maku.maku.vo.TPurchaseDetailsVO;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
@ -34,12 +35,13 @@ import java.util.List;
|
|||
public class TPurchaseDetailsController {
|
||||
private final TPurchaseDetailsService tPurchaseDetailsService;
|
||||
private final RedisCache redisCache;
|
||||
@GetMapping("/buy")
|
||||
@PostMapping("/buy")
|
||||
@Operation(summary = "购买")
|
||||
public Result<?> purchaseBook(HttpServletRequest request) {
|
||||
public Result<?> purchaseBook(HttpServletRequest request,@RequestBody TCardVo vo) {
|
||||
String token = request.getHeader("token");
|
||||
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
||||
boolean isPurchased = tPurchaseDetailsService.purchaseBook(entity);
|
||||
// boolean isPurchased = tPurchaseDetailsService.purchaseBook(entity);
|
||||
boolean isPurchased = tPurchaseDetailsService.purchaseBook(entity,vo);
|
||||
if (isPurchased) {
|
||||
return Result.ok("购买成功");
|
||||
} else {
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
package net.maku.maku.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -3,6 +3,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.TCardVo;
|
||||
import net.maku.maku.vo.TPurchaseDetailsVO;
|
||||
import net.maku.maku.query.TPurchaseDetailsQuery;
|
||||
import net.maku.maku.entity.TPurchaseDetailsEntity;
|
||||
|
@ -25,7 +26,10 @@ public interface TPurchaseDetailsService extends BaseService<TPurchaseDetailsEnt
|
|||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
// boolean purchaseBook(TUserEntity entity, TPurchaseDetailsVO vo);
|
||||
|
||||
boolean purchaseBook(TUserEntity entity);
|
||||
boolean purchaseBook(TUserEntity entity, TCardVo vo);
|
||||
|
||||
// boolean purchaseBook(TUserEntity entity);
|
||||
|
||||
}
|
|
@ -12,12 +12,14 @@ 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.TCardVo;
|
||||
import net.maku.maku.vo.TPurchaseDetailsVO;
|
||||
import net.maku.maku.dao.TPurchaseDetailsDao;
|
||||
import net.maku.maku.service.TPurchaseDetailsService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -29,7 +31,6 @@ import java.util.List;
|
|||
@Service
|
||||
@AllArgsConstructor
|
||||
public class TPurchaseDetailsServiceImpl extends BaseServiceImpl<TPurchaseDetailsDao, TPurchaseDetailsEntity> implements TPurchaseDetailsService {
|
||||
|
||||
private final TUserService tUserService;
|
||||
@Override
|
||||
public PageResult<TPurchaseDetailsVO> page(TPurchaseDetailsQuery query) {
|
||||
|
@ -65,21 +66,55 @@ public class TPurchaseDetailsServiceImpl extends BaseServiceImpl<TPurchaseDetail
|
|||
removeByIds(idList);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean purchaseBook(TUserEntity entity, TPurchaseDetailsVO vo) {
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean purchaseBook(TUserEntity entity) {
|
||||
public boolean purchaseBook(TUserEntity entity,TCardVo vo) {
|
||||
//查询数据库订单表
|
||||
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);
|
||||
List<TPurchaseDetailsEntity> list = baseMapper.selectList(
|
||||
wrapper.eq(TPurchaseDetailsEntity::getPurchaseId,entity.getId()));
|
||||
for (int i = 0; i < vo.getBooks().size(); i++){
|
||||
for(int j=0;j<list.size();j++){
|
||||
if(vo.getBooks().get(i).getBookId()==list.get(j).getBookId()){
|
||||
double price = list.get(j).getPrice();
|
||||
double count =list.get(j).getCount();
|
||||
double balance= entity.getBalance();
|
||||
if (balance>=price*count){
|
||||
double newBalance = balance-price*count;
|
||||
entity.setBalance(newBalance);
|
||||
tUserService.updateById(entity);
|
||||
removeById(list.get(j).getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// @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;
|
||||
// }
|
||||
// return true;}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package net.maku.maku.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TCardVo {
|
||||
private List<TPurchaseDetailsVO> books;
|
||||
}
|
|
@ -24,7 +24,9 @@ public class TPurchaseDetailsVO implements Serializable {
|
|||
|
||||
private Integer bookId;
|
||||
|
||||
private BigDecimal price;
|
||||
private double price;
|
||||
|
||||
private Integer count;
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user