|
|
@@ -1,4 +1,4 @@
|
|
|
-package com.cyksj.web.controller.manage.goods;
|
|
|
+package com.cyksj.web.controller.manage.goods.shop;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
@@ -82,14 +82,20 @@ public class CmsYhShopGoodsController {
|
|
|
* 设置店铺平台价格浮动比例
|
|
|
*/
|
|
|
@PutMapping("/put/shop/goods/rate")
|
|
|
- public Result<Void> updShopGoodsRate(@RequestBody GoodsDonShopRateReq req){
|
|
|
- if (req.getRate() != null){
|
|
|
- yhShopGoodsRateService.update(Wrappers.lambdaUpdate(YhShopGoodsRate.class).set(YhShopGoodsRate::getRate,req.getRate()));
|
|
|
- }else {
|
|
|
- req.getList().forEach(e -> {
|
|
|
- yhShopGoodsRateService.update(Wrappers.lambdaUpdate(YhShopGoodsRate.class).eq(YhShopGoodsRate::getSkuId,e.getSkuId()).set(YhShopGoodsRate::getRate,e.getRate()));
|
|
|
- });
|
|
|
- }
|
|
|
+ public Result<Void> updShopGoodsRate(@RequestBody GoodsDonShopRateReq req) {
|
|
|
+ req.getList().forEach(e -> {
|
|
|
+ YhShopGoodsRate one = yhShopGoodsRateService.getOne(Wrappers.lambdaQuery(YhShopGoodsRate.class)
|
|
|
+ .eq(YhShopGoodsRate::getSkuId, e.getSkuId()).last("limit 1"));
|
|
|
+ if (one == null) {
|
|
|
+ one = new YhShopGoodsRate();
|
|
|
+ one.setRate(e.getRate());
|
|
|
+ one.setGoodsId(e.getGoodsId());
|
|
|
+ one.setSkuId(e.getSkuId());
|
|
|
+ } else {
|
|
|
+ one.setRate(e.getRate());
|
|
|
+ }
|
|
|
+ yhShopGoodsRateService.saveOrUpdate(one);
|
|
|
+ });
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|
|
|
@@ -99,11 +105,17 @@ public class CmsYhShopGoodsController {
|
|
|
@PutMapping("/set/shop/goods/general/rate")
|
|
|
public Result<Void> setShopGoodsGeneralRate(@RequestBody GoodsDonShopRateReq req) {
|
|
|
Integer rate = req.getRate();
|
|
|
- if (rate == null) {
|
|
|
+ if (rate == null || (rate < 0 && rate > 100)) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入正确的比例");
|
|
|
}
|
|
|
List<Long> goodsIds = req.getGoodsIds();
|
|
|
- yhShopGoodsRateService.update(Wrappers.lambdaUpdate(YhShopGoodsRate.class).in(YhShopGoodsRate::getGoodsId, goodsIds).set(YhShopGoodsRate::getRate, rate));
|
|
|
+ goodsIds.forEach(goodsId -> {
|
|
|
+ List<YhShopGoodsRate> yhShopGoodsRates = beanSearcher.searchList(YhShopGoodsRate.class, MapUtils.builder().field(YhShopGoodsRate::getGoodsId, goodsId).build());
|
|
|
+ yhShopGoodsRates.forEach(data -> {
|
|
|
+ data.setRate(rate);
|
|
|
+ });
|
|
|
+ yhShopGoodsRateService.saveOrUpdateBatch(yhShopGoodsRates);
|
|
|
+ });
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|