修改超市库存接口
This commit is contained in:
1 parent
cd5b5d1907
commit
5e454dfa0c
3 files changed
+39
-5
No files matched your search
+11
@@ -75,4 +75,15 @@ public interface RemoteSupermarketSpuService {
|
||||
*/
|
||||
@PostMapping("/supermarketSpu/app/selectListAll")
|
||||
R getSupermarketSpu(@RequestBody SupermarketSpuQueryDTO supermarketSpuQueryDTO);
|
||||
|
||||
|
||||
/**
|
||||
* 购物车效验库存
|
||||
* @param spuId
|
||||
* @param incrCount 扣减数量,正数负数都行
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/supermarketSpu/app/checkSpuStock")
|
||||
R checkSpuStock(@RequestParam(value ="spuId")Long spuId,@RequestParam("incrCount")Integer incrCount);
|
||||
|
||||
}
|
||||
+14
@@ -28,6 +28,7 @@ import org.springframework.http.HttpHeaders;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -216,5 +217,18 @@ public class SupermarketSpuController {
|
||||
return R.ok(supermarketSpuService.getSupermarketSpuAppDetailById(id));
|
||||
}
|
||||
|
||||
@GetMapping("/app/checkSpuStock")
|
||||
@SysLog("购物车效验库存")
|
||||
@Transactional
|
||||
public R checkSpuStock(@RequestParam(value ="spuId")Long spuId,@RequestParam("incrCount")Integer incrCount) {
|
||||
SupermarketSpuEntity spu= supermarketSpuService.getById(spuId);
|
||||
if (spu == null) {
|
||||
R.failed("商品不存在");
|
||||
}
|
||||
if (spu.getStock()<Math.abs(incrCount)){
|
||||
return R.failed("库存不足");
|
||||
}
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
}
|
||||
+14
-5
@@ -124,12 +124,21 @@ public class SupermarketSpuServiceImpl extends ServiceImpl<SupermarketSpuMapper,
|
||||
public R updateSpuStock(SupermarketSpuUpdateStockReqDTO updateStockReqDTO) {
|
||||
// 更新 SKU 库存
|
||||
updateStockReqDTO.getItems().forEach(item -> {
|
||||
int i = baseMapper.updateStock(item.getId(), item.getIncrCount());
|
||||
if (item.getIncrCount() <= 0) {
|
||||
if (i == 0) {
|
||||
R.failed("商品库存不足");
|
||||
}
|
||||
// 查询当前库存
|
||||
SupermarketSpuEntity spu = baseMapper.selectById(item.getId());
|
||||
if (spu == null) {
|
||||
R.failed(spu.getProductName()+"商品不存在");
|
||||
}
|
||||
// 检查库存是否足够
|
||||
if (item.getIncrCount() < 0 && Math.abs(item.getIncrCount()) > spu.getStock()) {
|
||||
R.failed(spu.getProductName()+"库存不足,无法完成操作");
|
||||
}
|
||||
int i = baseMapper.updateStock(item.getId(), item.getIncrCount());
|
||||
// if (item.getIncrCount() <= 0) {
|
||||
// if (i == 0) {
|
||||
// R.failed("商品库存不足");
|
||||
// }
|
||||
// }
|
||||
});
|
||||
|
||||
return R.ok();
|
||||
|
||||
Reference in new issue
Block a user