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.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;
|
||||||
|
@ -35,13 +34,12 @@ 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;
|
||||||
@PostMapping("/buy")
|
@GetMapping("/buy")
|
||||||
@Operation(summary = "购买")
|
@Operation(summary = "购买")
|
||||||
public Result<?> purchaseBook(HttpServletRequest request,@RequestBody TCardVo vo) {
|
public Result<?> purchaseBook(HttpServletRequest request) {
|
||||||
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,7 +1,9 @@
|
||||||
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,7 +3,6 @@ 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;
|
||||||
|
@ -26,10 +25,7 @@ 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, 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.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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +29,7 @@ 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) {
|
||||||
|
@ -66,55 +65,21 @@ 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,TCardVo vo) {
|
public boolean purchaseBook(TUserEntity entity) {
|
||||||
//查询数据库订单表
|
|
||||||
LambdaQueryWrapper<TPurchaseDetailsEntity> wrapper = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<TPurchaseDetailsEntity> wrapper = new LambdaQueryWrapper<>();
|
||||||
List<TPurchaseDetailsEntity> list = baseMapper.selectList(
|
wrapper.eq(TPurchaseDetailsEntity::getPurchaseId,entity.getId());
|
||||||
wrapper.eq(TPurchaseDetailsEntity::getPurchaseId,entity.getId()));
|
TPurchaseDetailsEntity one =getOne(wrapper);
|
||||||
for (int i = 0; i < vo.getBooks().size(); i++){
|
double price = one.getPrice();
|
||||||
for(int j=0;j<list.size();j++){
|
double count =one.getCount();
|
||||||
if(vo.getBooks().get(i).getBookId()==list.get(j).getBookId()){
|
double balance= entity.getBalance();
|
||||||
double price = list.get(j).getPrice();
|
if (balance>=price*count){
|
||||||
double count =list.get(j).getCount();
|
double newBalance = balance-price*count;
|
||||||
double balance= entity.getBalance();
|
entity.setBalance(newBalance);
|
||||||
if (balance>=price*count){
|
tUserService.updateById(entity);
|
||||||
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;}
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -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 Integer bookId;
|
||||||
|
|
||||||
private double price;
|
private BigDecimal price;
|
||||||
|
|
||||||
private Integer count;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user