|
@@ -0,0 +1,68 @@
|
|
|
+package com.caimei.controller;
|
|
|
+
|
|
|
+import com.caimei.model.ResponseJson;
|
|
|
+import com.caimei.model.dto.CartDto;
|
|
|
+import com.caimei.service.ShoppingCartService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Description
|
|
|
+ *
|
|
|
+ * @author : plf
|
|
|
+ * @date : 2021/3/23
|
|
|
+ */
|
|
|
+@Api(tags = "购物车")
|
|
|
+@RestController
|
|
|
+@RequestMapping("/shopping")
|
|
|
+public class ShoppingCartApi {
|
|
|
+ private ShoppingCartService shoppingCartService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public void setShoppingCartService(ShoppingCartService shoppingCartService) {
|
|
|
+ this.shoppingCartService = shoppingCartService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加入购物车
|
|
|
+ */
|
|
|
+ @ApiOperation("加入购物车")
|
|
|
+ @PostMapping("/add/cart")
|
|
|
+ public synchronized ResponseJson<Integer> addShoppingCart(@RequestBody CartDto cart) {
|
|
|
+ if (cart.getUserId() == null || cart.getProductId() == null || cart.getProductCount() == null) {
|
|
|
+ return ResponseJson.error("参数异常", null);
|
|
|
+ }
|
|
|
+ return shoppingCartService.addShoppingCart(cart);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 统计购物车数量
|
|
|
+ */
|
|
|
+ @ApiOperation("统计购物车数量")
|
|
|
+ @ApiImplicitParam(name = "userId", value = "机构用户id", required = true)
|
|
|
+ @PostMapping("/quantity")
|
|
|
+ public ResponseJson<Integer> getCartQuantity(Integer userId) {
|
|
|
+ if (userId == null) {
|
|
|
+ return ResponseJson.error("参数异常", null);
|
|
|
+ }
|
|
|
+ return shoppingCartService.getCartQuantity(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 购物车数据
|
|
|
+ */
|
|
|
+ @ApiOperation("购物车数据")
|
|
|
+ @ApiImplicitParam(name = "userId", value = "机构用户id", required = true)
|
|
|
+ @GetMapping("/info")
|
|
|
+ public ResponseJson<Map<String, Object>> shoppingInfo(Integer userId) {
|
|
|
+ if (userId == null) {
|
|
|
+ return ResponseJson.error("参数异常", null);
|
|
|
+ }
|
|
|
+ return shoppingCartService.shoppingInfo(userId);
|
|
|
+ }
|
|
|
+}
|