From 7b710c5bb30d97005b06b28dfb09dca8bf6a04c5 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Tue, 27 Feb 2024 11:49:00 +0800
Subject: [PATCH] 抽奖
---
src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java | 151 ++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 146 insertions(+), 5 deletions(-)
diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
index 5f746d0..a413958 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
@@ -2,16 +2,24 @@
import cc.mrbird.febs.common.entity.FebsResponse;
import cc.mrbird.febs.common.entity.QueryRequest;
+import cc.mrbird.febs.common.enumerates.DataDictionaryEnum;
+import cc.mrbird.febs.common.utils.AppContants;
+import cc.mrbird.febs.common.utils.RedisUtils;
import cc.mrbird.febs.mall.conversion.MallGoodsConversion;
+import cc.mrbird.febs.mall.conversion.TzInfoConversion;
import cc.mrbird.febs.mall.dto.*;
import cc.mrbird.febs.mall.entity.*;
import cc.mrbird.febs.mall.mapper.*;
+import cc.mrbird.febs.mall.service.AsyncCjService;
import cc.mrbird.febs.mall.service.IAdminMallGoodsService;
import cc.mrbird.febs.mall.vo.*;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
+import cn.hutool.json.JSONObject;
+import cn.hutool.json.JSONUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -21,10 +29,8 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
+import java.util.*;
+import java.util.stream.Collectors;
@Slf4j
@Service
@@ -38,6 +44,12 @@
private final MallGoodsStyleMapper mallGoodsStyleMapper;
private final MallGoodsImagesMapper mallGoodsImagesMapper;
private final MallShoppingCartMapper mallShoppingCartMapper;
+ private final RedisUtils redisUtils;
+ private final CjItemMapper cjItemMapper;
+ private final CjInfoMapper cjInfoMapper;
+ private final TzInfoMapper tzInfoMapper;
+ private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
+ private final AsyncCjService asyncCjService;
@Override
public IPage<AdminMallGoodsVo> getCategoryListInPage(MallGoods mallGoods, QueryRequest request) {
@@ -109,6 +121,10 @@
//新增商品
MallGoods mallGoods = MallGoodsConversion.INSTANCE.dtoToEntity(addMallGoodsDto);
mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED);
+
+ if (mallGoods.getHasCarriage() == 2) {
+ mallGoods.setCarriage(BigDecimal.ZERO);
+ }
mallGoodsMapper.insert(mallGoods);
String thumbs = addMallGoodsDto.getThumbs();
@@ -128,6 +144,27 @@
}
if (addMallGoodsDto.getGoodsType() == 2) {
+ return new FebsResponse().success().message("添加成功");
+ }
+
+ // 单规格
+ if (addMallGoodsDto.getIsSku() == 2) {
+ MallGoodsStyle style = new MallGoodsStyle();
+ style.setGoodsId(mallGoods.getId());
+ style.setName(mallGoods.getGoodsName());
+ mallGoodsStyleMapper.insert(style);
+
+ MallGoodsSku sku = new MallGoodsSku();
+ sku.setGoodsId(mallGoods.getId());
+ sku.setSkuImage(mallGoods.getThumb());
+ sku.setSkuName(mallGoods.getGoodsName());
+ sku.setCostPrice(mallGoods.getCostPrice());
+ sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
+ sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice()));
+ sku.setSkuVolume(mallGoods.getVolume());
+ sku.setStock(mallGoods.getStock());
+ sku.setStyleId(style.getId());
+ mallGoodsSkuMapper.insert(sku);
return new FebsResponse().success().message("添加成功");
}
@@ -298,7 +335,7 @@
return new FebsResponse().fail().message("商品规格原价不能小于0");
}
BigDecimal presentPrice = addSku.getPresentPrice();
- if (presentPrice.compareTo(BigDecimal.ZERO) <= 0) {
+ if (presentPrice.compareTo(BigDecimal.ZERO) < 0) {
return new FebsResponse().fail().message("商品规格现价不能小于0");
}
@@ -308,7 +345,18 @@
//新增商品
MallGoods mallGoods = mallGoodsMapper.selectById(mallGoodsUpdateDto.getId());
+
+ // 若原来不为多规格或编辑后也不为多规格,则清空样式和规格
+ if (mallGoods.getIsSku() == 2 || mallGoodsUpdateDto.getIsSku() == 2) {
+ mallGoodsSkuMapper.deleteByGoodsId(mallGoods.getId());
+ mallGoodsStyleMapper.deleteByGoodsId(mallGoods.getId());
+ }
+
BeanUtil.copyProperties(mallGoodsUpdateDto, mallGoods);
+ if (mallGoodsUpdateDto.getHasCarriage() == 2) {
+ mallGoods.setCarriage(BigDecimal.ZERO);
+ }
+
mallGoodsMapper.updateById(mallGoods);
mallGoodsImagesMapper.deleteByGoodsId(mallGoodsUpdateDto.getId());
@@ -331,6 +379,29 @@
if (mallGoodsUpdateDto.getGoodsType() == 2) {
return new FebsResponse().success().message("编辑成功");
}
+
+ // 单规格
+ if (mallGoodsUpdateDto.getIsSku() == 2) {
+ MallGoodsStyle style = new MallGoodsStyle();
+ style.setGoodsId(mallGoods.getId());
+ style.setName(mallGoods.getGoodsName());
+ mallGoodsStyleMapper.insert(style);
+
+ MallGoodsSku sku = new MallGoodsSku();
+ sku.setGoodsId(mallGoods.getId());
+ sku.setSkuImage(mallGoods.getThumb());
+ sku.setSkuName(mallGoods.getGoodsName());
+ sku.setCostPrice(mallGoods.getCostPrice());
+ sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
+ sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice()));
+ sku.setSkuVolume(mallGoods.getVolume());
+ sku.setStock(mallGoods.getStock());
+ sku.setStyleId(style.getId());
+ mallGoodsSkuMapper.insert(sku);
+ return new FebsResponse().success().message("添加成功");
+ }
+
+
// 删除已存在sku
List<Long> delSkuIds = mallGoodsUpdateDto.getDelSkuId();
@@ -414,5 +485,75 @@
return mallGoodsMapper.getAllGoodsTree();
}
+ @Override
+ public FebsResponse goodsHot(Long id) {
+ MallGoods mallGoods = mallGoodsMapper.selectById(id);
+ if (ObjectUtil.isEmpty(mallGoods)) {
+ return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
+ }
+ mallGoods.setIsHot(MallGoods.ISHOT_STATE_YES);
+ mallGoodsMapper.updateById(mallGoods);
+ return new FebsResponse().success();
+ }
+
+ @Override
+ public FebsResponse goodsNotHot(Long id) {
+ MallGoods mallGoods = mallGoodsMapper.selectById(id);
+ if (ObjectUtil.isEmpty(mallGoods)) {
+ return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
+ }
+ mallGoods.setIsHot(MallGoods.ISHOT_STATE_NO);
+ mallGoodsMapper.updateById(mallGoods);
+ return new FebsResponse().success();
+ }
+
+ @Override
+ public IPage<TzInfo> getTzListInPage(TzInfo tzInfo, QueryRequest request) {
+ Page<TzInfo> page = new Page<>(request.getPageNum(), request.getPageSize());
+ IPage<TzInfo> adminMallGoodsVos = this.baseMapper.getTzListInPage(page, tzInfo);
+ List<TzInfo> records = adminMallGoodsVos.getRecords();
+
+ String kjNo = redisUtils.getString(AppContants.KJ_RECORD_NO);
+ QueryWrapper<CjInfo> objectQueryWrapper = new QueryWrapper<>();
+ objectQueryWrapper.eq("kj_no",kjNo);
+ List<CjInfo> cjInfos = cjInfoMapper.selectList(objectQueryWrapper);
+ if(CollUtil.isNotEmpty(cjInfos)){
+ List<Long> collect = cjInfos.stream().map(CjInfo::getId).collect(Collectors.toList());
+ List<CjItem> cjItems = cjItemMapper.selectSumAmountByInfoId(collect);
+ for(TzInfo tzInfo1 : records){
+ List<CjItem> collect1 = cjItems.stream().filter(cjItem -> cjItem.getTzCode().equals(tzInfo1.getTzCode())).collect(Collectors.toList());
+ if(CollUtil.isNotEmpty(collect1)){
+ BigDecimal reduce = collect1.stream().map(CjItem::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
+ tzInfo1.setTzAmount(reduce);
+ }else{
+ tzInfo1.setTzAmount(BigDecimal.ZERO);
+ }
+ }
+ }
+ return adminMallGoodsVos;
+ }
+
+ @Override
+ public FebsResponse tzUpdate(TzInfo tzInfo) {
+ Long id = tzInfo.getId();
+
+ TzInfo tzInfo1 = tzInfoMapper.selectById(id);
+ if(ObjectUtil.isEmpty(tzInfo1)){
+ return new FebsResponse().fail().message("设置失败");
+ }
+ tzInfo1.setTzPercent(tzInfo.getTzPercent());
+ tzInfoMapper.updateById(tzInfo1);
+
+ if(ObjectUtil.isNotEmpty(tzInfo.getIsRecommend())){
+ dataDictionaryCustomMapper.updateDicValueByTypeAndCode(
+ DataDictionaryEnum.OPEN_PRICE.getType(),
+ DataDictionaryEnum.OPEN_PRICE.getCode(),
+ tzInfo.getIsRecommend()
+ );
+ }
+ asyncCjService.tzInfo();
+ return new FebsResponse().success().message("操作成功");
+ }
+
}
--
Gitblit v1.9.1