package cc.mrbird.febs.mall.service.impl;
|
|
import cc.mrbird.febs.common.entity.FebsResponse;
|
import cc.mrbird.febs.common.entity.QueryRequest;
|
import cc.mrbird.febs.mall.conversion.MallGoodsConversion;
|
import cc.mrbird.febs.mall.dto.*;
|
import cc.mrbird.febs.mall.entity.*;
|
import cc.mrbird.febs.mall.mapper.*;
|
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.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;
|
import lombok.RequiredArgsConstructor;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.stereotype.Service;
|
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;
|
|
@Slf4j
|
@Service
|
@RequiredArgsConstructor
|
@Transactional
|
public class AdminMallGoodsService extends ServiceImpl<MallGoodsMapper, MallGoods> implements IAdminMallGoodsService {
|
|
private final MallGoodsCategoryMapper mallGoodsCategoryMapper;
|
private final MallGoodsMapper mallGoodsMapper;
|
private final MallGoodsSkuMapper mallGoodsSkuMapper;
|
private final MallGoodsStyleMapper mallGoodsStyleMapper;
|
private final MallGoodsImagesMapper mallGoodsImagesMapper;
|
private final MallShoppingCartMapper mallShoppingCartMapper;
|
private final MallCarriageRuleMapper mallCarriageRuleMapper;
|
private final MallCarriageRuleInfoMapper mallCarriageRuleInfoMapper;
|
private final MallGoodsCouponMapper mallGoodsCouponMapper;
|
private final CouponGoodsMapper couponGoodsMapper;
|
|
@Override
|
public IPage<AdminMallGoodsVo> getCategoryListInPage(MallGoods mallGoods, QueryRequest request) {
|
Page<AdminMallGoodsVo> page = new Page<>(request.getPageNum(), request.getPageSize());
|
IPage<AdminMallGoodsVo> adminMallGoodsVos = this.baseMapper.selectMallGoodsInPage(page, mallGoods);
|
return adminMallGoodsVos;
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse addMallGoods(AddMallGoodsDto addMallGoodsDto) {
|
String goodsName = addMallGoodsDto.getGoodsName();
|
if (StrUtil.isEmpty(goodsName)) {
|
return new FebsResponse().fail().message("商品名称不能为空");
|
}
|
Integer mallGoodsByGoodsName = mallGoodsMapper.selectMallGoodsCountByGoodsName(goodsName);
|
if (mallGoodsByGoodsName > 0) {
|
return new FebsResponse().fail().message("商品名称不能重复");
|
}
|
String goodsNo = addMallGoodsDto.getGoodsNo();
|
if (StrUtil.isEmpty(goodsNo)) {
|
return new FebsResponse().fail().message("商品编号不能为空");
|
}
|
Integer mallGoodsByGoodsNo = mallGoodsMapper.selectMallGoodsCountByGoodsNo(goodsNo);
|
if (mallGoodsByGoodsNo > 0) {
|
return new FebsResponse().fail().message("商品编号不能重复");
|
}
|
Integer carriageType = addMallGoodsDto.getCarriageType();
|
if (addMallGoodsDto.getGoodsType() == 1) {
|
if (1 == carriageType) {
|
if (ObjectUtil.isEmpty(addMallGoodsDto.getCarriageAmount())
|
|| BigDecimal.ZERO.compareTo(addMallGoodsDto.getCarriageAmount()) > 0) {
|
return new FebsResponse().fail().message("固定邮费不能小于零");
|
}
|
} else {
|
Long carriageRuleId = addMallGoodsDto.getCarriageRuleId();
|
MallCarriageRule mallCarriageRule = mallCarriageRuleMapper.selectById(carriageRuleId);
|
if (ObjectUtil.isEmpty(mallCarriageRule)) {
|
return new FebsResponse().fail().message("邮费模板不能为空");
|
}
|
}
|
}
|
|
|
// 付费商品
|
if (addMallGoodsDto.getGoodsType() != 2) {
|
Long categoryId = addMallGoodsDto.getCategoryId();
|
if (ObjectUtil.isEmpty(categoryId)) {
|
return new FebsResponse().fail().message("商品分类不能为空");
|
}
|
|
if (addMallGoodsDto.getIsSku() == 1) {
|
List<AddMallGoodsSkuDto> addSkus = addMallGoodsDto.getAddMallGoodsSkuDtos();
|
if (CollUtil.isEmpty(addSkus)) {
|
return new FebsResponse().fail().message("商品规格不能为空");
|
}
|
for (AddMallGoodsSkuDto addSku : addSkus) {
|
String skuName = addSku.getSkuName();
|
if (StrUtil.isEmpty(skuName)) {
|
return new FebsResponse().fail().message("商品规格名称不能为空");
|
}
|
String skuImage = addSku.getSkuImage();
|
if (StrUtil.isEmpty(skuImage)) {
|
return new FebsResponse().fail().message("商品规格图片不能为空");
|
}
|
Integer skuVolume = addSku.getSkuVolume() == null ? 0 : addSku.getSkuVolume();
|
if (skuVolume < 0) {
|
return new FebsResponse().fail().message("商品规格销售数量不能小于0");
|
}
|
Integer stock = addSku.getStock() == null ? 0 : addSku.getStock();
|
if (stock < 0) {
|
return new FebsResponse().fail().message("商品规格库存必须大于0");
|
}
|
String originalPrice = addSku.getOriginalPrice();
|
if (StrUtil.isEmpty(originalPrice)) {
|
return new FebsResponse().fail().message("商品规格原价不能为空");
|
}
|
String presentPrice = addSku.getPresentPrice();
|
if (StrUtil.isEmpty(presentPrice)) {
|
return new FebsResponse().fail().message("商品规格现价不能为空");
|
}
|
// if (StrUtil.isEmpty(addSku.getLevelOnePrice())
|
// || StrUtil.isEmpty(addSku.getLevelTwoPrice())
|
// || StrUtil.isEmpty(addSku.getLevelThreePrice())) {
|
// return new FebsResponse().fail().message("商品规格级别价格不能为空");
|
// }
|
BigDecimal goodsWeight = addSku.getGoodsWeight();
|
if(BigDecimal.ZERO.compareTo(goodsWeight) > 0){
|
return new FebsResponse().fail().message("重量不能小于零");
|
}
|
}
|
}
|
}
|
//新增商品
|
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();
|
if (StrUtil.isNotEmpty(thumbs)) {
|
List<String> imgs = StrUtil.splitTrim(thumbs, ",");
|
if (CollUtil.isNotEmpty(imgs)) {
|
int i = 1;
|
for (String img : imgs) {
|
MallGoodsImages mallGoodsImages = new MallGoodsImages();
|
mallGoodsImages.setGoodsId(mallGoods.getId());
|
mallGoodsImages.setImageUrl(img);
|
mallGoodsImages.setSeq(i);
|
mallGoodsImagesMapper.insert(mallGoodsImages);
|
i++;
|
}
|
}
|
}
|
|
Long goodsId = mallGoods.getId();
|
QueryWrapper<CouponGoods> objectQueryWrapper = new QueryWrapper<>();
|
objectQueryWrapper.eq("goods_id",goodsId);
|
List<CouponGoods> mallGoodsCoupons = couponGoodsMapper.selectList(objectQueryWrapper);
|
if(CollUtil.isNotEmpty(mallGoodsCoupons)){
|
for(CouponGoods couponGoods : mallGoodsCoupons){
|
couponGoodsMapper.deleteById(couponGoods);
|
}
|
}
|
if(CollUtil.isNotEmpty(addMallGoodsDto.getCouponIds())){
|
List<Long> couponIds = addMallGoodsDto.getCouponIds();
|
for(Long couponId : couponIds){
|
CouponGoods couponGoods = new CouponGoods();
|
couponGoods.setGoodsId(goodsId);
|
couponGoods.setCouponId(couponId);
|
couponGoodsMapper.insert(couponGoods);
|
}
|
}
|
|
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.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice()));
|
sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
|
sku.setLevelOnePrice(new BigDecimal(mallGoods.getPresentPrice()));
|
sku.setLevelTwoPrice(new BigDecimal(mallGoods.getPresentPrice()));
|
sku.setLevelThreePrice(new BigDecimal(mallGoods.getPresentPrice()));
|
sku.setSkuVolume(mallGoods.getVolume());
|
sku.setStock(mallGoods.getStock());
|
sku.setStyleId(style.getId());
|
sku.setGoodsWeight(mallGoods.getGoodsWeight());
|
mallGoodsSkuMapper.insert(sku);
|
return new FebsResponse().success().message("添加成功");
|
}
|
|
|
List<AddMallGoodsSkuDto> addMallGoodsSkuDtos = addMallGoodsDto.getAddMallGoodsSkuDtos();
|
Set<String> styles = new HashSet<>();
|
if (CollUtil.isNotEmpty(addMallGoodsSkuDtos)) {
|
for (AddMallGoodsSkuDto addStyleDto : addMallGoodsSkuDtos) {
|
styles.add(addStyleDto.getStyleName());
|
}
|
}
|
if (CollUtil.isNotEmpty(styles)) {
|
for (String style : styles) {
|
//新增样式
|
MallGoodsStyle mallGoodsStyle = new MallGoodsStyle();
|
mallGoodsStyle.setName(style);
|
mallGoodsStyle.setGoodsId(mallGoods.getId());
|
mallGoodsStyleMapper.insert(mallGoodsStyle);
|
}
|
}
|
|
if (CollUtil.isNotEmpty(addMallGoodsSkuDtos)) {
|
for (AddMallGoodsSkuDto addMallGoodsSkuDto : addMallGoodsSkuDtos) {
|
MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addMallGoodsSkuDto.getStyleName(), mallGoods.getId());
|
//新增商品规格
|
MallGoodsSku mallGoodsSku = new MallGoodsSku();
|
mallGoodsSku.setSkuName(addMallGoodsSkuDto.getSkuName());
|
mallGoodsSku.setSkuImage(addMallGoodsSkuDto.getSkuImage());
|
mallGoodsSku.setStock(addMallGoodsSkuDto.getStock() == null ? 0 : addMallGoodsSkuDto.getStock());
|
mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume() == null ? 0 : addMallGoodsSkuDto.getSkuVolume());
|
mallGoodsSku.setOriginalPrice(new BigDecimal(addMallGoodsSkuDto.getOriginalPrice()));
|
mallGoodsSku.setPresentPrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
|
mallGoodsSku.setCostPrice(addMallGoodsSkuDto.getCostPrice());
|
|
mallGoodsSku.setLevelOnePrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
|
mallGoodsSku.setLevelTwoPrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
|
mallGoodsSku.setLevelThreePrice(new BigDecimal(addMallGoodsSkuDto.getPresentPrice()));
|
mallGoodsSku.setStyleId(mallGoodsStyleSku.getId());
|
mallGoodsSku.setGoodsId(mallGoods.getId());
|
mallGoodsSku.setGoodsWeight(addMallGoodsSkuDto.getGoodsWeight());
|
mallGoodsSku.setSample(addMallGoodsSkuDto.getSample());
|
mallGoodsSkuMapper.insert(mallGoodsSku);
|
}
|
}
|
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public FebsResponse upMallGoods(Long id) {
|
MallGoods mallGoods = mallGoodsMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallGoods)) {
|
return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
|
}
|
mallGoods.setIsSale(MallGoods.ISSALE_STATUS_ENABLE);
|
mallGoodsMapper.updateById(mallGoods);
|
return new FebsResponse().success();
|
}
|
|
@Override
|
public FebsResponse downMallGoods(Long id) {
|
MallGoods mallGoods = mallGoodsMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallGoods)) {
|
return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
|
}
|
mallGoods.setIsSale(MallGoods.ISSALE_STATUS_DISABLED);
|
mallGoodsMapper.updateById(mallGoods);
|
return new FebsResponse().success();
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse delMallGoods(Long id) {
|
MallGoods mallGoods = mallGoodsMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallGoods)) {
|
return new FebsResponse().fail().message("商品不存在,请刷新当前页面");
|
}
|
Integer isSale = mallGoods.getIsSale();
|
if (MallGoods.ISSALE_STATUS_DISABLED != isSale) {
|
return new FebsResponse().fail().message("请先下架该商品");
|
}
|
|
mallGoodsStyleMapper.deleteByGoodsId(id);
|
mallGoodsSkuMapper.deleteByGoodsId(id);
|
mallGoodsMapper.deleteById(mallGoods);
|
mallShoppingCartMapper.deleteByGoodsId(id);
|
|
return new FebsResponse().success();
|
}
|
|
@Override
|
public AdminMailGoodsDetailVo getMallGoodsInfoById(long id) {
|
AdminMailGoodsDetailVo adminMailGoodsDetailVo = mallGoodsMapper.selectMallGoodsInfoById(id);
|
List<AdminMailGoodsSkuDetailVo> adminMailGoodsSkuDetailVos = mallGoodsSkuMapper.selectByGoodId(id);
|
adminMailGoodsDetailVo.setMailGoodsSkuDetailVo(adminMailGoodsSkuDetailVos);
|
return adminMailGoodsDetailVo;
|
}
|
|
@Override
|
public AdminMailGoodsUpdateVo getMallGoodsUpdateInfoById(long id) {
|
AdminMailGoodsUpdateVo adminMailGoodsUpdateVo = mallGoodsMapper.getMallGoodsUpdateInfoById(id);
|
List<AdminMailGoodsSkuDetailVo> adminMailGoodsSkuDetailVos = mallGoodsSkuMapper.selectByGoodId(id);
|
if (CollUtil.isNotEmpty(adminMailGoodsSkuDetailVos)) {
|
adminMailGoodsUpdateVo.setMailGoodsSkuDetailVo(adminMailGoodsSkuDetailVos);
|
}
|
List<String> adminMailGoodsImagesVos = mallGoodsImagesMapper.selectByGoodId(id);
|
if (CollUtil.isNotEmpty(adminMailGoodsImagesVos)) {
|
adminMailGoodsUpdateVo.setMailGoodsImagesVo(adminMailGoodsImagesVos);
|
}
|
return adminMailGoodsUpdateVo;
|
}
|
|
@Override
|
public MallGoods selectGoodsById(long id) {
|
MallGoods mallGoods = mallGoodsMapper.selectById(id);
|
|
List<MallGoodsSku> skus = mallGoodsSkuMapper.selectSkuByGoodsId(mallGoods.getId());
|
List<String> thumbs = mallGoodsImagesMapper.selectByGoodId(mallGoods.getId());
|
List<Long> couponIds = couponGoodsMapper.selectByGoodId(mallGoods.getId());
|
mallGoods.setImages(thumbs);
|
mallGoods.setSkus(skus);
|
mallGoods.setCouponIds(couponIds);
|
return mallGoods;
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse updateMallGoods(MallGoodsUpdateDto mallGoodsUpdateDto) {
|
String goodsName = mallGoodsUpdateDto.getGoodsName();
|
if (StrUtil.isEmpty(goodsName)) {
|
return new FebsResponse().fail().message("商品名称不能为空");
|
}
|
Integer mallGoodsByGoodsName = mallGoodsMapper.selectMallGoodsCountByGoodsNameAndGoodId(goodsName, mallGoodsUpdateDto.getId());
|
if (mallGoodsByGoodsName > 0) {
|
return new FebsResponse().fail().message("商品名称不能重复");
|
}
|
String goodsNo = mallGoodsUpdateDto.getGoodsNo();
|
if (StrUtil.isEmpty(goodsNo)) {
|
return new FebsResponse().fail().message("商品编号不能为空");
|
}
|
Integer mallGoodsByGoodsNo = mallGoodsMapper.selectMallGoodsCountByGoodsNoAndGoodId(goodsNo, mallGoodsUpdateDto.getId());
|
if (mallGoodsByGoodsNo > 0) {
|
return new FebsResponse().fail().message("商品编号不能重复");
|
}
|
Integer carriageType = mallGoodsUpdateDto.getCarriageType();
|
if(1 == carriageType){
|
if(ObjectUtil.isEmpty(mallGoodsUpdateDto.getCarriageAmount())
|
|| BigDecimal.ZERO.compareTo(mallGoodsUpdateDto.getCarriageAmount()) > 0){
|
return new FebsResponse().fail().message("固定邮费不能小于零");
|
}
|
}else{
|
Long carriageRuleId = mallGoodsUpdateDto.getCarriageRuleId();
|
MallCarriageRule mallCarriageRule = mallCarriageRuleMapper.selectById(carriageRuleId);
|
if(ObjectUtil.isEmpty(mallCarriageRule)){
|
return new FebsResponse().fail().message("邮费模板不能为空");
|
}
|
}
|
|
if (mallGoodsUpdateDto.getGoodsType() != 2) {
|
Long categoryId = mallGoodsUpdateDto.getCategoryId();
|
if (ObjectUtil.isEmpty(categoryId)) {
|
return new FebsResponse().fail().message("商品分类不能为空");
|
}
|
|
if (mallGoodsUpdateDto.getIsSku() == 1) {
|
List<MailGoodsSkuDto> addSkus = mallGoodsUpdateDto.getMailGoodsSkuDto();
|
if (CollUtil.isEmpty(addSkus)) {
|
return new FebsResponse().fail().message("商品规格不能为空");
|
}
|
for (MailGoodsSkuDto addSku : addSkus) {
|
String skuName = addSku.getSkuName();
|
if (StrUtil.isEmpty(skuName)) {
|
return new FebsResponse().fail().message("商品规格名称不能为空");
|
}
|
String skuImage = addSku.getSkuImage();
|
if (StrUtil.isEmpty(skuImage)) {
|
return new FebsResponse().fail().message("商品规格图片不能为空");
|
}
|
Integer skuVolume = addSku.getSkuVolume() == null ? 0 : addSku.getSkuVolume();
|
if (skuVolume < 0) {
|
return new FebsResponse().fail().message("商品规格销售数量不能小于0");
|
}
|
Integer stock = addSku.getStock() == null ? 0 : addSku.getStock();
|
if (stock < 0) {
|
return new FebsResponse().fail().message("商品规格库存必须大于0");
|
}
|
BigDecimal originalPrice = addSku.getOriginalPrice();
|
if (originalPrice.compareTo(BigDecimal.ZERO) <= 0) {
|
return new FebsResponse().fail().message("商品规格原价不能小于0");
|
}
|
BigDecimal presentPrice = addSku.getPresentPrice();
|
if (presentPrice.compareTo(BigDecimal.ZERO) < 0) {
|
return new FebsResponse().fail().message("商品规格现价不能小于0");
|
}
|
BigDecimal goodsWeight = addSku.getGoodsWeight();
|
if(BigDecimal.ZERO.compareTo(goodsWeight) > 0){
|
return new FebsResponse().fail().message("重量不能小于零");
|
}
|
|
}
|
}
|
}
|
|
//新增商品
|
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 (mallGoods.getHasCarriage() == 2) {
|
// mallGoods.setCarriage(BigDecimal.ZERO);
|
// }
|
|
mallGoodsMapper.updateById(mallGoods);
|
|
if( 1 == mallGoods.getCarriageType()){
|
mallGoodsMapper.updateCarriageRuleId(mallGoods.getId());
|
}else{
|
mallGoodsMapper.updateCarriageAmount(mallGoods.getId());
|
}
|
|
mallGoodsImagesMapper.deleteByGoodsId(mallGoodsUpdateDto.getId());
|
String thumbs = mallGoodsUpdateDto.getThumbs();
|
if (StrUtil.isNotEmpty(thumbs)) {
|
List<String> imgs = StrUtil.splitTrim(thumbs, ",");
|
if (CollUtil.isNotEmpty(imgs)) {
|
int i = 1;
|
for (String img : imgs) {
|
MallGoodsImages mallGoodsImages = new MallGoodsImages();
|
mallGoodsImages.setGoodsId(mallGoods.getId());
|
mallGoodsImages.setImageUrl(img);
|
mallGoodsImages.setSeq(i);
|
mallGoodsImagesMapper.insert(mallGoodsImages);
|
i++;
|
}
|
}
|
}
|
|
Long goodsId = mallGoodsUpdateDto.getId();
|
QueryWrapper<CouponGoods> objectQueryWrapper = new QueryWrapper<>();
|
objectQueryWrapper.eq("goods_id",goodsId);
|
List<CouponGoods> mallGoodsCoupons = couponGoodsMapper.selectList(objectQueryWrapper);
|
if(CollUtil.isNotEmpty(mallGoodsCoupons)){
|
for(CouponGoods couponGoods : mallGoodsCoupons){
|
couponGoodsMapper.deleteById(couponGoods);
|
}
|
}
|
if(CollUtil.isNotEmpty(mallGoodsUpdateDto.getCouponIds())){
|
List<Long> couponIds = mallGoodsUpdateDto.getCouponIds();
|
for(Long couponId : couponIds){
|
CouponGoods couponGoods = new CouponGoods();
|
couponGoods.setGoodsId(goodsId);
|
couponGoods.setCouponId(couponId);
|
couponGoodsMapper.insert(couponGoods);
|
}
|
}
|
|
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.setLevelOnePrice(new BigDecimal(mallGoods.getPresentPrice()));
|
sku.setLevelTwoPrice(new BigDecimal(mallGoods.getPresentPrice()));
|
sku.setLevelThreePrice(new BigDecimal(mallGoods.getPresentPrice()));
|
sku.setSkuVolume(mallGoods.getVolume());
|
sku.setStock(mallGoods.getStock());
|
sku.setStyleId(style.getId());
|
sku.setGoodsWeight(mallGoods.getGoodsWeight());
|
mallGoodsSkuMapper.insert(sku);
|
return new FebsResponse().success().message("添加成功");
|
}
|
|
// 删除已存在sku
|
List<Long> delSkuIds = mallGoodsUpdateDto.getDelSkuId();
|
if (CollUtil.isNotEmpty(delSkuIds)) {
|
mallGoodsSkuMapper.delSkuByIds(delSkuIds);
|
|
// 如果该样式下sku全删除,则删除该样式
|
List<MallGoodsStyle> styles = mallGoodsStyleMapper.selectByGoodsId(mallGoods.getId());
|
for (MallGoodsStyle style : styles) {
|
if (CollUtil.isEmpty(style.getSkus())) {
|
mallGoodsStyleMapper.deleteById(style.getId());
|
}
|
}
|
}
|
|
List<MailGoodsSkuDto> mailGoodsSkuDto = mallGoodsUpdateDto.getMailGoodsSkuDto();
|
Set<String> styles = new HashSet<>();
|
if (CollUtil.isNotEmpty(mailGoodsSkuDto)) {
|
for (MailGoodsSkuDto addStyleDto : mailGoodsSkuDto) {
|
// if (ObjectUtil.isNotEmpty(addStyleDto.getDelLog())) {
|
// mallGoodsSkuMapper.deleteById(addStyleDto.getId());
|
// mallShoppingCartMapper.deleteByGoodsIdAndSkuId(addStyleDto.getId(), addStyleDto.getGoodsId());
|
// }
|
|
if (ObjectUtil.isEmpty(addStyleDto.getStyleId())) {
|
MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addStyleDto.getStyleName(), mallGoods.getId());
|
if (ObjectUtil.isEmpty(mallGoodsStyleSku)) {
|
styles.add(addStyleDto.getStyleName());
|
}
|
}else{
|
MallGoodsStyle mallGoodsStyle = mallGoodsStyleMapper.selectById(addStyleDto.getStyleId());
|
mallGoodsStyle.setName(addStyleDto.getStyleName());
|
mallGoodsStyleMapper.updateById(mallGoodsStyle);
|
}
|
}
|
}
|
if (CollUtil.isNotEmpty(styles)) {
|
for (String style : styles) {
|
//新增样式
|
MallGoodsStyle mallGoodsStyle = new MallGoodsStyle();
|
mallGoodsStyle.setName(style);
|
mallGoodsStyle.setGoodsId(mallGoods.getId());
|
mallGoodsStyleMapper.insert(mallGoodsStyle);
|
}
|
}
|
|
if (CollUtil.isNotEmpty(mailGoodsSkuDto)) {
|
for (MailGoodsSkuDto addMallGoodsSkuDto : mailGoodsSkuDto) {
|
if (StrUtil.isEmpty(addMallGoodsSkuDto.getDelLog())) {
|
if (ObjectUtil.isNotEmpty(addMallGoodsSkuDto.getId())) {
|
MallGoodsSku mallGoodsSku = mallGoodsSkuMapper.selectById(addMallGoodsSkuDto.getId());
|
mallGoodsSku.setSkuName(addMallGoodsSkuDto.getSkuName());
|
mallGoodsSku.setSkuImage(addMallGoodsSkuDto.getSkuImage());
|
mallGoodsSku.setStock(addMallGoodsSkuDto.getStock() == null ? 0 : addMallGoodsSkuDto.getStock());
|
mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume() == null ? 0 : addMallGoodsSkuDto.getSkuVolume());
|
mallGoodsSku.setOriginalPrice(addMallGoodsSkuDto.getOriginalPrice());
|
mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice());
|
mallGoodsSku.setCostPrice(addMallGoodsSkuDto.getCostPrice());
|
mallGoodsSku.setLevelOnePrice(addMallGoodsSkuDto.getPresentPrice());
|
mallGoodsSku.setLevelTwoPrice(addMallGoodsSkuDto.getPresentPrice());
|
mallGoodsSku.setLevelThreePrice(addMallGoodsSkuDto.getPresentPrice());
|
mallGoodsSku.setStyleId(addMallGoodsSkuDto.getStyleId());
|
mallGoodsSku.setGoodsId(mallGoods.getId());
|
mallGoodsSku.setGoodsWeight(addMallGoodsSkuDto.getGoodsWeight());
|
mallGoodsSku.setSample(addMallGoodsSkuDto.getSample());
|
mallGoodsSkuMapper.updateById(mallGoodsSku);
|
} else {
|
//新增商品规格
|
MallGoodsStyle mallGoodsStyleSku = mallGoodsStyleMapper.selectByStyleName(addMallGoodsSkuDto.getStyleName(), mallGoods.getId());
|
MallGoodsSku mallGoodsSku = new MallGoodsSku();
|
mallGoodsSku.setSkuName(addMallGoodsSkuDto.getSkuName());
|
mallGoodsSku.setSkuImage(addMallGoodsSkuDto.getSkuImage());
|
mallGoodsSku.setStock(addMallGoodsSkuDto.getStock() == null ? 0 : addMallGoodsSkuDto.getStock());
|
mallGoodsSku.setSkuVolume(addMallGoodsSkuDto.getSkuVolume() == null ? 0 : addMallGoodsSkuDto.getSkuVolume());
|
mallGoodsSku.setOriginalPrice(addMallGoodsSkuDto.getOriginalPrice());
|
mallGoodsSku.setPresentPrice(addMallGoodsSkuDto.getPresentPrice());
|
mallGoodsSku.setCostPrice(addMallGoodsSkuDto.getCostPrice());
|
mallGoodsSku.setLevelOnePrice(addMallGoodsSkuDto.getPresentPrice());
|
mallGoodsSku.setLevelTwoPrice(addMallGoodsSkuDto.getPresentPrice());
|
mallGoodsSku.setLevelThreePrice(addMallGoodsSkuDto.getPresentPrice());
|
mallGoodsSku.setStyleId(mallGoodsStyleSku.getId());
|
mallGoodsSku.setGoodsId(mallGoods.getId());
|
mallGoodsSku.setGoodsWeight(addMallGoodsSkuDto.getGoodsWeight());
|
mallGoodsSku.setSample(addMallGoodsSkuDto.getSample());
|
mallGoodsSkuMapper.insert(mallGoodsSku);
|
}
|
}
|
}
|
}
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public List<AdminMallGoodsTreeVo> getAllGoodsTree() {
|
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<AdminHomeDeliverySettingVo> getDeliveryHomeListInPage(AdminHomeDeliverySettingVo adminHomeDeliverySetting, QueryRequest request) {
|
Page<DataDictionaryCustom> page = new Page<>(request.getPageNum(), request.getPageSize());
|
IPage<DataDictionaryCustom> dataDictionaryCustomIPage = this.baseMapper.getDeliveryHomeListInPage(page, adminHomeDeliverySetting);
|
List<DataDictionaryCustom> records = dataDictionaryCustomIPage.getRecords();
|
List<AdminHomeDeliverySettingVo> adminHomeDeliverySettingVos = new ArrayList<>();
|
if(CollUtil.isNotEmpty(records)){
|
for(DataDictionaryCustom dataDictionaryCustom : records){
|
AdminHomeDeliverySettingVo adminHomeDeliverySettingVo = JSONUtil.toBean(dataDictionaryCustom.getValue(), AdminHomeDeliverySettingVo.class);
|
adminHomeDeliverySettingVo.setId(dataDictionaryCustom.getId());
|
adminHomeDeliverySettingVos.add(adminHomeDeliverySettingVo);
|
}
|
}
|
IPage<AdminHomeDeliverySettingVo> adminHomeDeliverySettingVoIPage = new Page<>();
|
adminHomeDeliverySettingVoIPage.setRecords(adminHomeDeliverySettingVos);
|
adminHomeDeliverySettingVoIPage.setTotal(dataDictionaryCustomIPage.getTotal());
|
return adminHomeDeliverySettingVoIPage;
|
}
|
|
|
private final DataDictionaryCustomMapper dataDictionaryCustomMapper;
|
@Override
|
public FebsResponse deliveryHomeUpdate(AdminHomeDeliverySettingVo adminHomeDeliverySettingVo) {
|
DataDictionaryCustom dataDictionaryCustom = dataDictionaryCustomMapper.selectById(adminHomeDeliverySettingVo.getId());
|
adminHomeDeliverySettingVo.setId(null);
|
dataDictionaryCustom.setValue(JSONUtil.toJsonStr(adminHomeDeliverySettingVo));
|
dataDictionaryCustomMapper.updateById(dataDictionaryCustom);
|
return new FebsResponse().success();
|
}
|
|
@Override
|
public IPage<MallCarriageRule> getMallCarriageRuleListInPage(MallCarriageRule mallCarriageRule, QueryRequest request) {
|
Page<MallCarriageRule> page = new Page<>(request.getPageNum(), request.getPageSize());
|
IPage<MallCarriageRule> mallCarriageRules = mallCarriageRuleMapper.selectMallCarriageRuleListInPage(page, mallCarriageRule);
|
return mallCarriageRules;
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse carriageRuleDelById(Long id) {
|
MallCarriageRule mallCarriageRule = mallCarriageRuleMapper.selectById(id);
|
if(ObjectUtil.isEmpty(mallCarriageRule)){
|
return new FebsResponse().fail().message("操作失败");
|
}
|
List<MallGoods> mallGoods = this.baseMapper.selectMallGoodsListQueryByRuleId(id);
|
if(CollUtil.isNotEmpty(mallGoods)){
|
StringBuffer goodsNameBuffer = new StringBuffer();
|
for(MallGoods goods : mallGoods){
|
goodsNameBuffer.append(goods.getGoodsName());
|
goodsNameBuffer.append(",");
|
}
|
return new FebsResponse().fail().message(goodsNameBuffer+"正在使用当前模板,请先编辑商品信息");
|
}
|
QueryWrapper<MallCarriageRuleInfo> objectQueryWrapper = new QueryWrapper<>();
|
objectQueryWrapper.eq("rule_id",id);
|
mallCarriageRuleInfoMapper.delete(objectQueryWrapper);
|
|
mallCarriageRuleMapper.deleteById(id);
|
return new FebsResponse().success();
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse carriageRuleAdd(AdminCarriageRuleAddDto adminCarriageRuleAddDto) {
|
String ruleName = adminCarriageRuleAddDto.getRuleName();
|
QueryWrapper<MallCarriageRule> objectQueryWrapper = new QueryWrapper<>();
|
objectQueryWrapper.eq("name",ruleName);
|
List<MallCarriageRule> mallCarriageRules = mallCarriageRuleMapper.selectList(objectQueryWrapper);
|
if(CollUtil.isNotEmpty(mallCarriageRules)){
|
return new FebsResponse().fail().message("标题不能重复");
|
}
|
|
MallCarriageRule mallCarriageRule = new MallCarriageRule();
|
mallCarriageRule.setName(ruleName);
|
mallCarriageRuleMapper.insert(mallCarriageRule);
|
|
Long ruleId = mallCarriageRule.getId();
|
/**
|
* 生成默认的运费规则
|
*/
|
MallCarriageRuleInfo mallCarriageRuleInfoDefault = new MallCarriageRuleInfo();
|
mallCarriageRuleInfoDefault.setRuleId(ruleId);
|
//计价方式(1:按件算 2:按重量算)
|
mallCarriageRuleInfoDefault.setValuationType(adminCarriageRuleAddDto.getValuationType());
|
mallCarriageRuleInfoDefault.setValuationUnit(
|
adminCarriageRuleAddDto.getValuationType() == 1?"件":"千克"
|
);
|
mallCarriageRuleInfoDefault.setBasicCnt(adminCarriageRuleAddDto.getBasicCntDefault());
|
mallCarriageRuleInfoDefault.setBasicPrice(adminCarriageRuleAddDto.getBasicPriceDefault());
|
mallCarriageRuleInfoDefault.setMoreCnt(adminCarriageRuleAddDto.getMoreCntDefault());
|
mallCarriageRuleInfoDefault.setMorePrice(adminCarriageRuleAddDto.getMorePriceDefault());
|
mallCarriageRuleInfoMapper.insert(mallCarriageRuleInfoDefault);
|
|
List<AdminCarriageRuleAddInfoDto> adminCarriageRuleAddInfoDtos = adminCarriageRuleAddDto.getAdminCarriageRuleAddInfoDtos();
|
if(CollUtil.isNotEmpty(adminCarriageRuleAddInfoDtos)){
|
for(AdminCarriageRuleAddInfoDto adminCarriageRuleAddInfoDto : adminCarriageRuleAddInfoDtos){
|
MallCarriageRuleInfo mallCarriageRuleInfo = new MallCarriageRuleInfo();
|
mallCarriageRuleInfo.setRuleId(ruleId);
|
mallCarriageRuleInfo.setAreaAddress(adminCarriageRuleAddInfoDto.getAreaAddress());
|
//计价方式(1:按件算 2:按重量算)
|
mallCarriageRuleInfo.setValuationType(adminCarriageRuleAddDto.getValuationType());
|
mallCarriageRuleInfo.setValuationUnit(
|
adminCarriageRuleAddDto.getValuationType() == 1?"件":"千克"
|
);
|
mallCarriageRuleInfo.setBasicCnt(adminCarriageRuleAddInfoDto.getBasicCnt());
|
mallCarriageRuleInfo.setBasicPrice(adminCarriageRuleAddInfoDto.getBasicPrice());
|
mallCarriageRuleInfo.setMoreCnt(adminCarriageRuleAddInfoDto.getMoreCnt());
|
mallCarriageRuleInfo.setMorePrice(adminCarriageRuleAddInfoDto.getMorePrice());
|
mallCarriageRuleInfoMapper.insert(mallCarriageRuleInfo);
|
}
|
}
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public AdminMallCarriageRuleVo selectCarriageRuleByRuleId(long id) {
|
AdminMallCarriageRuleVo adminMallCarriageRuleVo = new AdminMallCarriageRuleVo();
|
|
MallCarriageRule mallCarriageRule = mallCarriageRuleMapper.selectById(id);
|
adminMallCarriageRuleVo.setId(id);
|
adminMallCarriageRuleVo.setRuleName(mallCarriageRule.getName());
|
|
List<MallCarriageRuleInfo> mallCarriageRuleInfos = mallCarriageRuleInfoMapper.selectMallCarriageRuleInfoByRuleIdAndAreaAddress(id,null);
|
if(CollUtil.isNotEmpty(mallCarriageRuleInfos)){
|
StringBuffer areaAddressStr = new StringBuffer();
|
List<AdminMallCarriageRuleInfoVo> adminCarriageRuleInfoVos = new ArrayList<>();
|
for(MallCarriageRuleInfo mallCarriageRuleInfo : mallCarriageRuleInfos){
|
if(StrUtil.isNotEmpty(mallCarriageRuleInfo.getAreaAddress())){
|
AdminMallCarriageRuleInfoVo adminMallCarriageRuleInfoVo = new AdminMallCarriageRuleInfoVo();
|
adminMallCarriageRuleInfoVo.setId(mallCarriageRuleInfo.getId());
|
adminMallCarriageRuleInfoVo.setAreaAddress(mallCarriageRuleInfo.getAreaAddress());
|
adminMallCarriageRuleInfoVo.setBasicCnt(mallCarriageRuleInfo.getBasicCnt());
|
adminMallCarriageRuleInfoVo.setBasicPrice(mallCarriageRuleInfo.getBasicPrice());
|
adminMallCarriageRuleInfoVo.setMoreCnt(mallCarriageRuleInfo.getMoreCnt());
|
adminMallCarriageRuleInfoVo.setMorePrice(mallCarriageRuleInfo.getMorePrice());
|
adminCarriageRuleInfoVos.add(adminMallCarriageRuleInfoVo);
|
|
areaAddressStr.append(mallCarriageRuleInfo.getAreaAddress());
|
}else{
|
//默认规则
|
adminMallCarriageRuleVo.setBasicCntDefault(mallCarriageRuleInfo.getBasicCnt());
|
adminMallCarriageRuleVo.setBasicPriceDefault(mallCarriageRuleInfo.getBasicPrice());
|
adminMallCarriageRuleVo.setMoreCntDefault(mallCarriageRuleInfo.getMoreCnt());
|
adminMallCarriageRuleVo.setMorePriceDefault(mallCarriageRuleInfo.getMorePrice());
|
adminMallCarriageRuleVo.setValuationType(mallCarriageRuleInfo.getValuationType());
|
}
|
}
|
adminMallCarriageRuleVo.setAdminCarriageRuleInfoVos(adminCarriageRuleInfoVos);
|
adminMallCarriageRuleVo.setAreaAddressStr(areaAddressStr.toString());
|
}
|
return adminMallCarriageRuleVo;
|
}
|
|
@Override
|
@Transactional
|
public FebsResponse carriageRuleUpdate(AdminCarriageRuleUpdateDto adminCarriageRuleUpdateDto) {
|
Long id = adminCarriageRuleUpdateDto.getId();
|
MallCarriageRule mallCarriageRule = mallCarriageRuleMapper.selectById(id);
|
if(ObjectUtil.isEmpty(mallCarriageRule)){
|
return new FebsResponse().fail().message("运费模板不存在");
|
}
|
|
List<MallGoods> mallGoods = this.baseMapper.selectMallGoodsListQueryByRuleIdAndIsSale(id,MallGoods.ISHOT_STATE_YES);
|
if(CollUtil.isNotEmpty(mallGoods)){
|
StringBuffer goodsNameBuffer = new StringBuffer();
|
for(MallGoods goods : mallGoods){
|
goodsNameBuffer.append(goods.getGoodsName());
|
goodsNameBuffer.append(",");
|
}
|
return new FebsResponse().fail().message(goodsNameBuffer+"正在使用当前模板,请先下架商品");
|
}
|
|
mallCarriageRule.setName(adminCarriageRuleUpdateDto.getRuleName());
|
mallCarriageRuleMapper.updateById(mallCarriageRule);
|
//删除现有的所有运费模板子表数据
|
List<MallCarriageRuleInfo> mallCarriageRuleInfos = mallCarriageRuleInfoMapper.selectMallCarriageRuleInfoByRuleIdAndAreaAddress(id, null);
|
if(CollUtil.isNotEmpty(mallCarriageRuleInfos)){
|
for(MallCarriageRuleInfo mallCarriageRuleInfo : mallCarriageRuleInfos){
|
mallCarriageRuleInfoMapper.deleteById(mallCarriageRuleInfo.getId());
|
}
|
}
|
|
/**
|
* 生成运费模板子表数据
|
*/
|
MallCarriageRuleInfo mallCarriageRuleInfoDefault = new MallCarriageRuleInfo();
|
mallCarriageRuleInfoDefault.setRuleId(id);
|
//计价方式(1:按件算 2:按重量算)
|
mallCarriageRuleInfoDefault.setValuationType(adminCarriageRuleUpdateDto.getValuationType());
|
mallCarriageRuleInfoDefault.setValuationUnit(
|
adminCarriageRuleUpdateDto.getValuationType() == 1?"件":"千克"
|
);
|
mallCarriageRuleInfoDefault.setBasicCnt(adminCarriageRuleUpdateDto.getBasicCntDefault());
|
mallCarriageRuleInfoDefault.setBasicPrice(adminCarriageRuleUpdateDto.getBasicPriceDefault());
|
mallCarriageRuleInfoDefault.setMoreCnt(adminCarriageRuleUpdateDto.getMoreCntDefault());
|
mallCarriageRuleInfoDefault.setMorePrice(adminCarriageRuleUpdateDto.getMorePriceDefault());
|
mallCarriageRuleInfoMapper.insert(mallCarriageRuleInfoDefault);
|
|
List<AdminCarriageRuleAddInfoDto> adminCarriageRuleAddInfoDtos = adminCarriageRuleUpdateDto.getAdminCarriageRuleAddInfoDtos();
|
if(CollUtil.isNotEmpty(adminCarriageRuleAddInfoDtos)){
|
for(AdminCarriageRuleAddInfoDto adminCarriageRuleAddInfoDto : adminCarriageRuleAddInfoDtos){
|
MallCarriageRuleInfo mallCarriageRuleInfo = new MallCarriageRuleInfo();
|
mallCarriageRuleInfo.setRuleId(id);
|
mallCarriageRuleInfo.setAreaAddress(adminCarriageRuleAddInfoDto.getAreaAddress());
|
//计价方式(1:按件算 2:按重量算)
|
mallCarriageRuleInfo.setValuationType(mallCarriageRuleInfoDefault.getValuationType());
|
mallCarriageRuleInfo.setValuationUnit(
|
mallCarriageRuleInfoDefault.getValuationType() == 1?"件":"千克"
|
);
|
mallCarriageRuleInfo.setBasicCnt(adminCarriageRuleAddInfoDto.getBasicCnt());
|
mallCarriageRuleInfo.setBasicPrice(adminCarriageRuleAddInfoDto.getBasicPrice());
|
mallCarriageRuleInfo.setMoreCnt(adminCarriageRuleAddInfoDto.getMoreCnt());
|
mallCarriageRuleInfo.setMorePrice(adminCarriageRuleAddInfoDto.getMorePrice());
|
mallCarriageRuleInfoMapper.insert(mallCarriageRuleInfo);
|
}
|
}
|
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public List<MallCarriageRule> findAllCarriageRuleTree() {
|
List<MallCarriageRule> mallCarriageRules = mallCarriageRuleMapper.selectList(new QueryWrapper<>());
|
return mallCarriageRules;
|
}
|
|
@Override
|
public IPage<MallGoodsCoupon> getMallGoodsCouponListInPage(MallGoodsCoupon mallGoodsCoupon, QueryRequest request) {
|
Page<MallGoodsCoupon> page = new Page<>(request.getPageNum(), request.getPageSize());
|
IPage<MallGoodsCoupon> mallGoodsCouponIPage = mallGoodsCouponMapper.selectMallGoodsCouponListInPage(page, mallGoodsCoupon);
|
return mallGoodsCouponIPage;
|
}
|
|
@Override
|
public FebsResponse couponRuleAdd(CouponRuleAddDto couponRuleAddDto) {
|
String name = couponRuleAddDto.getName();
|
QueryWrapper<MallGoodsCoupon> objectQueryWrapper = new QueryWrapper<>();
|
objectQueryWrapper.eq("name",name);
|
List<MallGoodsCoupon> mallGoodsCoupons = mallGoodsCouponMapper.selectList(objectQueryWrapper);
|
if(CollUtil.isNotEmpty(mallGoodsCoupons)){
|
return new FebsResponse().fail().message("名称不能重复");
|
}
|
|
MallGoodsCoupon mallGoodsCoupon = new MallGoodsCoupon();
|
mallGoodsCoupon.setName(name);
|
mallGoodsCoupon.setExpireDay(couponRuleAddDto.getExpireDay());
|
mallGoodsCoupon.setCostAmount(couponRuleAddDto.getCostAmount());
|
mallGoodsCoupon.setType(couponRuleAddDto.getType());
|
mallGoodsCoupon.setRealAmount(couponRuleAddDto.getRealAmount());
|
mallGoodsCouponMapper.insert(mallGoodsCoupon);
|
|
Long couponId = mallGoodsCoupon.getId();
|
QueryWrapper<CouponGoods> objectQueryWrapperCoupon = new QueryWrapper<>();
|
objectQueryWrapperCoupon.eq("coupon_id",couponId);
|
List<CouponGoods> couponGoodsList = couponGoodsMapper.selectList(objectQueryWrapperCoupon);
|
if(CollUtil.isNotEmpty(couponGoodsList)){
|
for(CouponGoods couponGoods : couponGoodsList){
|
couponGoodsMapper.deleteById(couponGoods);
|
}
|
}
|
if(CollUtil.isNotEmpty(couponRuleAddDto.getGoodsIds())){
|
List<Long> goodsIds = couponRuleAddDto.getGoodsIds();
|
for(Long goodsId : goodsIds){
|
CouponGoods couponGoods = new CouponGoods();
|
couponGoods.setGoodsId(goodsId);
|
couponGoods.setCouponId(couponId);
|
couponGoodsMapper.insert(couponGoods);
|
}
|
}
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public FebsResponse couponRuleDel(Long id) {
|
MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallGoodsCoupon)) {
|
return new FebsResponse().fail().message("优惠卷不存在,请刷新当前页面");
|
}
|
Integer state = mallGoodsCoupon.getState();
|
if(2 == state){
|
return new FebsResponse().fail().message("请先下架优惠卷");
|
}
|
mallGoodsCouponMapper.deleteById(id);
|
return new FebsResponse().success();
|
}
|
|
@Override
|
public FebsResponse upCoupon(Long id) {
|
MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallGoodsCoupon)) {
|
return new FebsResponse().fail().message("优惠卷不存在,请刷新当前页面");
|
}
|
mallGoodsCoupon.setState(2);
|
mallGoodsCouponMapper.updateById(mallGoodsCoupon);
|
return new FebsResponse().success();
|
}
|
|
@Override
|
public FebsResponse downCoupon(Long id) {
|
MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallGoodsCoupon)) {
|
return new FebsResponse().fail().message("优惠卷不存在,请刷新当前页面");
|
}
|
mallGoodsCoupon.setState(1);
|
mallGoodsCouponMapper.updateById(mallGoodsCoupon);
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public AdminMallGoodsCouponVo selectGoodsCouponById(long id) {
|
List<Long> goodsIds = couponGoodsMapper.selectByCouponId(id);
|
AdminMallGoodsCouponVo adminMallGoodsCouponVo = mallGoodsCouponMapper.selectGoodsCouponById(id);
|
adminMallGoodsCouponVo.setGoodsIds(goodsIds);
|
return adminMallGoodsCouponVo;
|
}
|
|
@Override
|
public FebsResponse couponUpdate(AdminMallGoodsCouponVo adminMallGoodsCouponVo) {
|
Long id = adminMallGoodsCouponVo.getId();
|
MallGoodsCoupon mallGoodsCoupon = mallGoodsCouponMapper.selectById(id);
|
if (ObjectUtil.isEmpty(mallGoodsCoupon)) {
|
return new FebsResponse().fail().message("优惠卷不存在,请刷新当前页面");
|
}
|
Integer state = mallGoodsCoupon.getState();
|
if(2 == state){
|
return new FebsResponse().fail().message("请先下架优惠卷");
|
}
|
mallGoodsCoupon.setName(adminMallGoodsCouponVo.getName());
|
mallGoodsCoupon.setExpireDay(adminMallGoodsCouponVo.getExpireDay());
|
mallGoodsCoupon.setCostAmount(adminMallGoodsCouponVo.getCostAmount());
|
mallGoodsCoupon.setType(adminMallGoodsCouponVo.getType());
|
mallGoodsCoupon.setRealAmount(adminMallGoodsCouponVo.getRealAmount());
|
mallGoodsCouponMapper.updateById(mallGoodsCoupon);
|
|
Long couponId = mallGoodsCoupon.getId();
|
QueryWrapper<CouponGoods> objectQueryWrapperCoupon = new QueryWrapper<>();
|
objectQueryWrapperCoupon.eq("coupon_id",couponId);
|
List<CouponGoods> couponGoodsList = couponGoodsMapper.selectList(objectQueryWrapperCoupon);
|
if(CollUtil.isNotEmpty(couponGoodsList)){
|
for(CouponGoods couponGoods : couponGoodsList){
|
couponGoodsMapper.deleteById(couponGoods);
|
}
|
}
|
if(CollUtil.isNotEmpty(adminMallGoodsCouponVo.getGoodsIds())){
|
List<Long> goodsIds = adminMallGoodsCouponVo.getGoodsIds();
|
for(Long goodsId : goodsIds){
|
CouponGoods couponGoods = new CouponGoods();
|
couponGoods.setGoodsId(goodsId);
|
couponGoods.setCouponId(couponId);
|
couponGoodsMapper.insert(couponGoods);
|
}
|
}
|
return new FebsResponse().success().message("操作成功");
|
}
|
|
@Override
|
public List<AdminMallGoodsCouponTreeVo> findAdminMallGoodsCouponVoTree() {
|
QueryWrapper<MallGoodsCoupon> objectQueryWrapper = new QueryWrapper<>();
|
objectQueryWrapper.eq("state",2);
|
List<MallGoodsCoupon> mallGoodsCoupons = mallGoodsCouponMapper.selectList(objectQueryWrapper);
|
|
List<AdminMallGoodsCouponTreeVo> objects = new ArrayList<>();
|
if(CollUtil.isNotEmpty(mallGoodsCoupons)){
|
for(MallGoodsCoupon mallGoodsCoupon : mallGoodsCoupons){
|
AdminMallGoodsCouponTreeVo adminMallGoodsCouponTreeVo = new AdminMallGoodsCouponTreeVo();
|
adminMallGoodsCouponTreeVo.setCouponId(mallGoodsCoupon.getId());
|
adminMallGoodsCouponTreeVo.setCouponName(mallGoodsCoupon.getName());
|
objects.add(adminMallGoodsCouponTreeVo);
|
}
|
}
|
return objects;
|
}
|
|
@Override
|
public List<AdminMallGoodsCouponTreeListVo> findAdminMallGoodsCouponVoTreeList() {
|
QueryWrapper<MallGoodsCoupon> objectQueryWrapper = new QueryWrapper<>();
|
objectQueryWrapper.eq("state",2);
|
List<MallGoodsCoupon> mallGoodsCoupons = mallGoodsCouponMapper.selectList(objectQueryWrapper);
|
|
List<AdminMallGoodsCouponTreeListVo> objects = new ArrayList<>();
|
if(CollUtil.isNotEmpty(mallGoodsCoupons)){
|
for(MallGoodsCoupon mallGoodsCoupon : mallGoodsCoupons){
|
AdminMallGoodsCouponTreeListVo adminMallGoodsCouponTreeListVo = new AdminMallGoodsCouponTreeListVo();
|
adminMallGoodsCouponTreeListVo.setId(mallGoodsCoupon.getId());
|
adminMallGoodsCouponTreeListVo.setName(mallGoodsCoupon.getName());
|
objects.add(adminMallGoodsCouponTreeListVo);
|
}
|
}
|
return objects;
|
}
|
|
@Override
|
public List<AdminMallGoodsCouponTreeListVo> findAdminMallGoodsVoTreeList() {
|
QueryWrapper<MallGoods> objectQueryWrapper = new QueryWrapper<>();
|
objectQueryWrapper.eq("is_sale",1);
|
List<MallGoods> mallGoodsList = mallGoodsMapper.selectList(objectQueryWrapper);
|
|
List<AdminMallGoodsCouponTreeListVo> objects = new ArrayList<>();
|
if(CollUtil.isNotEmpty(mallGoodsList)){
|
for(MallGoods mallGoods : mallGoodsList){
|
AdminMallGoodsCouponTreeListVo adminMallGoodsCouponTreeListVo = new AdminMallGoodsCouponTreeListVo();
|
adminMallGoodsCouponTreeListVo.setId(mallGoods.getId());
|
adminMallGoodsCouponTreeListVo.setName(mallGoods.getGoodsName());
|
objects.add(adminMallGoodsCouponTreeListVo);
|
}
|
}
|
return objects;
|
}
|
}
|