|
|
@@ -0,0 +1,87 @@
|
|
|
+package com.cyksj.web.controller.shop;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
+import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.model.entity.YhShopGoodsSku;
|
|
|
+import com.cyksj.model.views.YhShopGoodsRateView;
|
|
|
+import com.cyksj.model.views.YhShopGoodsView;
|
|
|
+import com.cyksj.service.mange.CmsYhShopGoodsRateService;
|
|
|
+import com.cyksj.service.shop.YhShopGoodsSkuService;
|
|
|
+import com.ejlchina.searcher.BeanSearcher;
|
|
|
+import com.ejlchina.searcher.SearchResult;
|
|
|
+import com.ejlchina.searcher.util.MapUtils;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author zwhui
|
|
|
+ * @date 2023/9/14 17:28
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("/applets/shop")
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class ShopController {
|
|
|
+
|
|
|
+ private final BeanSearcher beanSearcher;
|
|
|
+
|
|
|
+ private final YhShopGoodsSkuService yhShopGoodsSkuService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增平台
|
|
|
+ */
|
|
|
+ @PostMapping("/post/goods")
|
|
|
+ public Result<Void> saveGoods(@RequestBody List<Long> goodsIds){
|
|
|
+ yhShopGoodsSkuService.saveGoods(goodsIds);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置店铺平台价格
|
|
|
+ */
|
|
|
+ @PutMapping("/put/goods")
|
|
|
+ public Result<Void> updShopGoodsRate(@RequestBody List<YhShopGoodsSku> goodsSkus){
|
|
|
+ goodsSkus.forEach(sku -> {
|
|
|
+ YhShopGoodsRateView.YhShopGoodsSkuRateView yhShopGoodsSkuRateView = beanSearcher.searchFirst(YhShopGoodsRateView.YhShopGoodsSkuRateView.class, MapUtils.builder().field(YhShopGoodsRateView.YhShopGoodsSkuRateView::getSkuId,sku.getSkuId()).build());
|
|
|
+ if (sku.getPrice().compareTo(yhShopGoodsSkuRateView.getMaxPrice()) > 0 || sku.getPrice().compareTo(yhShopGoodsSkuRateView.getMinPrice()) < 0){
|
|
|
+ throw BusinessRuntimeException.getInstance("价格不能超出区间范围");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ yhShopGoodsSkuService.saveOrUpdateBatch(goodsSkus);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上下架
|
|
|
+ */
|
|
|
+ @PutMapping("/put/goodsStatus/{goodsId}")
|
|
|
+ public Result<Void> updGoodsStatus(@PathVariable Long goodsId,Boolean status){
|
|
|
+ yhShopGoodsSkuService.update(Wrappers.lambdaUpdate(YhShopGoodsSku.class).eq(YhShopGoodsSku::getGoodsId,goodsId).set(YhShopGoodsSku::getStatus,status));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除平台
|
|
|
+ */
|
|
|
+ @PutMapping("/del/goods/{goodsId}")
|
|
|
+ public Result<Void> updGoodsStatus(@PathVariable Long goodsId){
|
|
|
+ yhShopGoodsSkuService.update(Wrappers.lambdaUpdate(YhShopGoodsSku.class).eq(YhShopGoodsSku::getGoodsId,goodsId).set(YhShopGoodsSku::getDeleted,false));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询平台
|
|
|
+ */
|
|
|
+ @GetMapping("/get/goods")
|
|
|
+ public Result<SearchResult<YhShopGoodsView>> goodsList(){
|
|
|
+ SearchResult<YhShopGoodsView> search = beanSearcher.search(YhShopGoodsView.class, MapUtils.builder().build());
|
|
|
+ search.getDataList().forEach(e -> e.setList(beanSearcher.searchList(YhShopGoodsView.YhShopGoodsSkuView.class,MapUtils.builder().field(YhShopGoodsView.YhShopGoodsSkuView::getGoodsId,e.getId()).build())));
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
+}
|