Compare commits
No commits in common. "06f3fc385cd566ab0a544daed7a495e8cfc09dbb" and "7ef5265f919453693948fbb8a0604f7b4f98f50c" have entirely different histories.
06f3fc385c
...
7ef5265f91
|
@ -13,7 +13,6 @@ 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;
|
||||
|
@ -35,13 +34,12 @@ import java.util.List;
|
|||
public class TPurchaseDetailsController {
|
||||
private final TPurchaseDetailsService tPurchaseDetailsService;
|
||||
private final RedisCache redisCache;
|
||||
@PostMapping("/buy")
|
||||
@GetMapping("/buy")
|
||||
@Operation(summary = "购买")
|
||||
public Result<?> purchaseBook(HttpServletRequest request,@RequestBody TCardVo vo) {
|
||||
public Result<?> purchaseBook(HttpServletRequest request) {
|
||||
String token = request.getHeader("token");
|
||||
TUserEntity entity = (TUserEntity) redisCache.get(token);
|
||||
// boolean isPurchased = tPurchaseDetailsService.purchaseBook(entity);
|
||||
boolean isPurchased = tPurchaseDetailsService.purchaseBook(entity,vo);
|
||||
boolean isPurchased = tPurchaseDetailsService.purchaseBook(entity);
|
||||
if (isPurchased) {
|
||||
return Result.ok("购买成功");
|
||||
} else {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package net.maku.maku.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -3,7 +3,6 @@ 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;
|
||||
|
@ -26,10 +25,7 @@ public interface TPurchaseDetailsService extends BaseService<TPurchaseDetailsEnt
|
|||
|
||||
void delete(List<Long> idList);
|
||||
|
||||
// boolean purchaseBook(TUserEntity entity, TPurchaseDetailsVO vo);
|
||||
|
||||
boolean purchaseBook(TUserEntity entity, TCardVo vo);
|
||||
|
||||
// boolean purchaseBook(TUserEntity entity);
|
||||
boolean purchaseBook(TUserEntity entity);
|
||||
|
||||
}
|
|
@ -12,14 +12,12 @@ 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;
|
||||
|
||||
/**
|
||||
|
@ -31,6 +29,7 @@ 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) {
|
||||
|
@ -66,55 +65,21 @@ public class TPurchaseDetailsServiceImpl extends BaseServiceImpl<TPurchaseDetail
|
|||
removeByIds(idList);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public boolean purchaseBook(TUserEntity entity, TPurchaseDetailsVO vo) {
|
||||
//
|
||||
// return false;
|
||||
// }
|
||||
|
||||
@Override
|
||||
public boolean purchaseBook(TUserEntity entity,TCardVo vo) {
|
||||
//查询数据库订单表
|
||||
public boolean purchaseBook(TUserEntity entity) {
|
||||
LambdaQueryWrapper<TPurchaseDetailsEntity> wrapper = new LambdaQueryWrapper<>();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// @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;}
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
package net.maku.maku.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class TCardVo {
|
||||
private List<TPurchaseDetailsVO> books;
|
||||
}
|
|
@ -24,9 +24,7 @@ public class TPurchaseDetailsVO implements Serializable {
|
|||
|
||||
private Integer bookId;
|
||||
|
||||
private double price;
|
||||
|
||||
private Integer count;
|
||||
private BigDecimal price;
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user