|
@@ -1,19 +1,31 @@
|
|
package com.yonge.cooleshow.portal.controller;
|
|
package com.yonge.cooleshow.portal.controller;
|
|
|
|
|
|
|
|
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
|
|
|
|
+import com.yonge.cooleshow.common.enums.CacheNameEnum;
|
|
import com.yonge.cooleshow.mall.common.api.CommonResult;
|
|
import com.yonge.cooleshow.mall.common.api.CommonResult;
|
|
|
|
+import com.yonge.cooleshow.mall.common.enums.OrderCacheEnum;
|
|
import com.yonge.cooleshow.mbg.model.OmsCartItem;
|
|
import com.yonge.cooleshow.mbg.model.OmsCartItem;
|
|
import com.yonge.cooleshow.portal.domain.CartProduct;
|
|
import com.yonge.cooleshow.portal.domain.CartProduct;
|
|
import com.yonge.cooleshow.portal.domain.CartPromotionItem;
|
|
import com.yonge.cooleshow.portal.domain.CartPromotionItem;
|
|
|
|
+import com.yonge.cooleshow.portal.dto.OrderPayRes;
|
|
import com.yonge.cooleshow.portal.service.OmsCartItemService;
|
|
import com.yonge.cooleshow.portal.service.OmsCartItemService;
|
|
import com.yonge.cooleshow.portal.service.UmsMemberService;
|
|
import com.yonge.cooleshow.portal.service.UmsMemberService;
|
|
|
|
+import com.yonge.toolset.base.exception.BizException;
|
|
import com.yonge.toolset.base.util.StringUtil;
|
|
import com.yonge.toolset.base.util.StringUtil;
|
|
|
|
+import com.yonge.toolset.payment.util.DistributedLock;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
+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.stereotype.Controller;
|
|
import org.springframework.stereotype.Controller;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
+
|
|
|
|
+import static com.yonge.cooleshow.mall.common.api.CommonResult.failed;
|
|
|
|
+import static com.yonge.cooleshow.mall.common.enums.OrderCacheEnum.LOCK_STOCK_MALL;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 购物车管理Controller
|
|
* 购物车管理Controller
|
|
@@ -28,15 +40,34 @@ public class OmsCartItemController {
|
|
@Autowired
|
|
@Autowired
|
|
private UmsMemberService memberService;
|
|
private UmsMemberService memberService;
|
|
|
|
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedissonClient redissonClient;
|
|
|
|
+
|
|
@ApiOperation("添加商品到购物车")
|
|
@ApiOperation("添加商品到购物车")
|
|
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
|
@RequestMapping(value = "/add", method = RequestMethod.POST)
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public CommonResult<OmsCartItem> add(@RequestBody OmsCartItem cartItem) {
|
|
public CommonResult<OmsCartItem> add(@RequestBody OmsCartItem cartItem) {
|
|
- OmsCartItem omsCartItem = cartItemService.add(cartItem);
|
|
|
|
- if (omsCartItem != null) {
|
|
|
|
- return CommonResult.success(omsCartItem);
|
|
|
|
|
|
+
|
|
|
|
+ RLock lock = redissonClient.getLock(OrderCacheEnum.LOCK_STOCK_MALL.getRedisKey(cartItem.getProductSkuId()));
|
|
|
|
+ try {
|
|
|
|
+ boolean b = lock.tryLock(60, TimeUnit.SECONDS);
|
|
|
|
+ if (b) {
|
|
|
|
+ OmsCartItem omsCartItem = cartItemService.add(cartItem);
|
|
|
|
+ return CommonResult.success(omsCartItem);
|
|
|
|
+ }
|
|
|
|
+ return failed("请求超时");
|
|
|
|
+ } catch (BizException e) {
|
|
|
|
+ return failed(e.getMessage());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return failed("请求超时");
|
|
|
|
+ } finally {
|
|
|
|
+ if (lock.getHoldCount()>0) {
|
|
|
|
+ lock.unlock();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return CommonResult.failed();
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation("获取当前会员的购物车列表")
|
|
@ApiOperation("获取当前会员的购物车列表")
|
|
@@ -62,11 +93,28 @@ public class OmsCartItemController {
|
|
@ResponseBody
|
|
@ResponseBody
|
|
public CommonResult updateQuantity(@RequestParam Long id,
|
|
public CommonResult updateQuantity(@RequestParam Long id,
|
|
@RequestParam Integer quantity) {
|
|
@RequestParam Integer quantity) {
|
|
- int count = cartItemService.updateQuantity(id, memberService.getCurrentMember().getId(), quantity);
|
|
|
|
- if (count > 0) {
|
|
|
|
- return CommonResult.success(count);
|
|
|
|
|
|
+
|
|
|
|
+ OmsCartItem omsCartItem = cartItemService.get(id);
|
|
|
|
+
|
|
|
|
+ RLock lock = redissonClient.getLock(OrderCacheEnum.LOCK_STOCK_MALL.getRedisKey(omsCartItem.getProductSkuId()));
|
|
|
|
+ try {
|
|
|
|
+ boolean b = lock.tryLock(60, TimeUnit.SECONDS);
|
|
|
|
+ if (b) {
|
|
|
|
+ int i = cartItemService.updateQuantity(id, memberService.getCurrentMember().getId(), quantity);
|
|
|
|
+ return CommonResult.success(i);
|
|
|
|
+ }
|
|
|
|
+ return failed("请求超时");
|
|
|
|
+ } catch (BizException e) {
|
|
|
|
+ return failed(e.getMessage());
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return failed("请求超时");
|
|
|
|
+ } finally {
|
|
|
|
+ if (lock.getHoldCount()>0) {
|
|
|
|
+ lock.unlock();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return CommonResult.failed();
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation("获取购物车中指定商品的规格,用于重选规格")
|
|
@ApiOperation("获取购物车中指定商品的规格,用于重选规格")
|
|
@@ -85,7 +133,7 @@ public class OmsCartItemController {
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
return CommonResult.success(count);
|
|
return CommonResult.success(count);
|
|
}
|
|
}
|
|
- return CommonResult.failed();
|
|
|
|
|
|
+ return failed();
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation("删除购物车中的指定商品")
|
|
@ApiOperation("删除购物车中的指定商品")
|
|
@@ -97,7 +145,7 @@ public class OmsCartItemController {
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
return CommonResult.success(count);
|
|
return CommonResult.success(count);
|
|
}
|
|
}
|
|
- return CommonResult.failed();
|
|
|
|
|
|
+ return failed();
|
|
}
|
|
}
|
|
|
|
|
|
@ApiOperation("清空当前会员的购物车")
|
|
@ApiOperation("清空当前会员的购物车")
|
|
@@ -108,6 +156,6 @@ public class OmsCartItemController {
|
|
if (count > 0) {
|
|
if (count > 0) {
|
|
return CommonResult.success(count);
|
|
return CommonResult.success(count);
|
|
}
|
|
}
|
|
- return CommonResult.failed();
|
|
|
|
|
|
+ return failed();
|
|
}
|
|
}
|
|
}
|
|
}
|