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