|
|
@@ -1,19 +1,24 @@
|
|
|
package org.dromara.product.controller.mini;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.dromara.common.core.domain.R;
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.dromara.common.satoken.utils.LoginHelper;
|
|
|
+import org.dromara.product.domain.ProductShoppingCart;
|
|
|
import org.dromara.product.domain.bo.PcProductBo;
|
|
|
import org.dromara.product.domain.bo.ProductBaseBo;
|
|
|
+import org.dromara.product.domain.bo.ProductShoppingCartBo;
|
|
|
import org.dromara.product.domain.vo.PcProductVo;
|
|
|
import org.dromara.product.domain.vo.ProductBaseVo;
|
|
|
import org.dromara.product.service.IProductBaseService;
|
|
|
+import org.dromara.product.service.IProductShoppingCartService;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* 首页
|
|
|
@@ -30,6 +35,9 @@ public class MiniProductController {
|
|
|
//商品
|
|
|
private final IProductBaseService productBaseService;
|
|
|
|
|
|
+ //购物车
|
|
|
+ private final IProductShoppingCartService productShoppingCartService;
|
|
|
+
|
|
|
/**
|
|
|
* 获取客户商品池的商品
|
|
|
*/
|
|
|
@@ -57,4 +65,81 @@ public class MiniProductController {
|
|
|
public R<ProductBaseVo> getProductDetail(@PathVariable Long productId) {
|
|
|
return R.ok(productBaseService.queryById(productId));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * mini将商品添加到购物车
|
|
|
+ */
|
|
|
+ @PostMapping("/addProductShoppingCart")
|
|
|
+ public R addProductShoppingCart(@RequestBody ProductShoppingCartBo bo) {
|
|
|
+ Long userId = LoginHelper.getUserId();
|
|
|
+ //校验是否存在库存和商品是否上架
|
|
|
+ ProductBaseVo productBaseVo = productBaseService.queryById(bo.getProductId());
|
|
|
+ if (!Objects.equals(productBaseVo.getProductStatus(), 1)) {
|
|
|
+ return R.fail("商品已下架");
|
|
|
+ }
|
|
|
+ if (productBaseVo.getTotalInventory() - bo.getProductNum() < 0) {
|
|
|
+ return R.fail("商品库存不足");
|
|
|
+ }
|
|
|
+ //查看是否存在同一个商品
|
|
|
+ ProductShoppingCart one = productShoppingCartService.getOne(Wrappers.lambdaQuery(ProductShoppingCart.class)
|
|
|
+ .eq(ProductShoppingCart::getUserId, userId)
|
|
|
+ .eq(ProductShoppingCart::getProductId, bo.getProductId())
|
|
|
+ );
|
|
|
+ if (one != null) {
|
|
|
+ one.setProductNum(one.getProductNum() + bo.getProductNum());
|
|
|
+ productShoppingCartService.updateById(one);
|
|
|
+ return R.ok();
|
|
|
+ } else {
|
|
|
+ bo.setUserId(userId);
|
|
|
+ productShoppingCartService.insertByBo(bo);
|
|
|
+ }
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * mini更新购物车商品数量
|
|
|
+ * */
|
|
|
+ @PostMapping("/updateProductShoppingCart")
|
|
|
+ public R updateProductShoppingCart(@RequestBody ProductShoppingCartBo bo) {
|
|
|
+ productShoppingCartService.update(Wrappers.lambdaUpdate(ProductShoppingCart.class)
|
|
|
+ .eq(ProductShoppingCart::getUserId, LoginHelper.getUserId())
|
|
|
+ .eq(ProductShoppingCart::getProductId, bo.getProductId())
|
|
|
+ .set(ProductShoppingCart::getProductNum, bo.getProductNum())
|
|
|
+ );
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * mini删除购物车商品
|
|
|
+ */
|
|
|
+ @DeleteMapping("/deleteProductShoppingCart/{ids}")
|
|
|
+ public R deleteProductShoppingCart(@PathVariable Long[] ids) {
|
|
|
+ productShoppingCartService.removeByIds(Arrays.asList(ids));
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * mini查询购物车的商品
|
|
|
+ */
|
|
|
+ @GetMapping("/getProductShoppingCartPage")
|
|
|
+ public TableDataInfo<PcProductVo> getProductShoppingCartPage(String id, PageQuery pageQuery) {
|
|
|
+ return productBaseService.getProductShoppingCartPage(id, LoginHelper.getUserId(), pageQuery);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * mini获取购物车商品未失效的商品数量
|
|
|
+ */
|
|
|
+ @GetMapping("/getProductShoppingCartCount")
|
|
|
+ public R getProductShoppingCartCount() {
|
|
|
+ return R.ok(productBaseService.getProductShoppingCartCount(LoginHelper.getUserId(), 0));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ *mini 协议供货商品列表
|
|
|
+ */
|
|
|
+ @GetMapping("/getAgreementSupplyProductPage")
|
|
|
+ public TableDataInfo<PcProductVo> getProtocolProductsPage(PcProductBo bo, PageQuery pageQuery) {
|
|
|
+ bo.setCustomerId(LoginHelper.getLoginUser().getCustomerId());
|
|
|
+ return productBaseService.getProtocolProductsPage(bo, pageQuery);
|
|
|
+ }
|
|
|
}
|