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