master
parent
d422211f70
commit
7364acd5bb
|
@ -1,5 +1,6 @@
|
|||
package com.bwie.goods.controller;
|
||||
|
||||
import com.bwie.common.config.RedissonConfig;
|
||||
import com.bwie.common.constants.TokenConstants;
|
||||
import com.bwie.common.domain.Cart;
|
||||
import com.bwie.common.domain.Middle;
|
||||
|
@ -13,12 +14,15 @@ import com.bwie.common.utils.JwtUtils;
|
|||
import com.bwie.goods.feign.UserFeign;
|
||||
import com.bwie.goods.service.CartService;
|
||||
import com.bwie.goods.service.MiddleService;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("cart")
|
||||
|
@ -30,33 +34,37 @@ public class CartController {
|
|||
private MiddleService middleService;
|
||||
@Autowired
|
||||
private UserFeign userFeign;
|
||||
@Autowired
|
||||
private RedissonClient RedissonClient;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
@PostMapping("addCart")
|
||||
public Result addCart(@RequestBody CartAddReq req){
|
||||
public Result addCart(@RequestBody CartAddReq req) {
|
||||
Middle middle = middleService.selectById(req.getId());
|
||||
if (middle.getSeckillNum()<=0){
|
||||
if (middle.getSeckillNum() <= 0) {
|
||||
throw new AllException("库存不足");
|
||||
}else {
|
||||
} else {
|
||||
int i = cartService.addCart(req);
|
||||
return i>0?Result.success("","添加成功"):Result.error("添加失败");
|
||||
return i > 0 ? Result.success("", "添加成功") : Result.error("添加失败");
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("findList")
|
||||
public Result findList(){
|
||||
public Result findList() {
|
||||
List<CartResp> list = cartService.findList();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
@PostMapping("pay")
|
||||
public Result pay(@RequestBody CartPayReq req){
|
||||
public Result pay(@RequestBody CartPayReq req) {
|
||||
String token = request.getHeader(TokenConstants.TOKEN);
|
||||
String userId = JwtUtils.getUserId(token);
|
||||
Result<UserResp> byId = userFeign.findById(userId);
|
||||
UserResp userResp = byId.getData();
|
||||
BigDecimal userMoney = userResp.getUserMoney();
|
||||
if (userMoney.compareTo(req.getSumPrice())==-1){
|
||||
if (userMoney.compareTo(req.getSumPrice()) == -1) {
|
||||
throw new AllException("余额不足");
|
||||
}
|
||||
int pay = cartService.pay(req);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
from t_seckill
|
||||
<where>
|
||||
<if test="seckillName!=null and seckillName!=''">
|
||||
and instr(seckillName,#{seckillName})
|
||||
and instr(seckill_Name,#{seckillName})
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
|
Loading…
Reference in New Issue