优惠卷相关

This commit is contained in:
liuyingfang
2024-03-30 11:56:41 +08:00
parent d7c1754b6a
commit 1d93bc217c
13 changed files with 398 additions and 23 deletions

View File

@@ -386,6 +386,13 @@ public class TbProductServiceImpl implements TbProductService {
}
}
@Transactional(rollbackFor = Exception.class)
@Override
public void updateIsHot(Integer id, String shopId) {
tbProductRepository.updateNullHot(shopId);
tbProductRepository.updateIsHot(id);
}
@Override
@Transactional
public void deleteAll(Integer[] ids) {

View File

@@ -15,27 +15,33 @@
*/
package cn.ysk.cashier.service.impl.shopimpl;
import cn.hutool.core.bean.BeanUtil;
import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.pojo.product.TbProduct;
import cn.ysk.cashier.pojo.shop.TbMerchantCoupon;
import cn.ysk.cashier.repository.product.TbProductRepository;
import cn.ysk.cashier.utils.ValidationUtil;
import cn.ysk.cashier.utils.FileUtil;
import cn.ysk.cashier.vo.CouponVO;
import lombok.RequiredArgsConstructor;
import cn.ysk.cashier.repository.shop.TbMerchantCouponRepository;
import cn.ysk.cashier.service.shop.TbMerchantCouponService;
import cn.ysk.cashier.dto.shop.TbMerchantCouponDto;
import cn.ysk.cashier.dto.shop.TbMerchantCouponQueryCriteria;
import cn.ysk.cashier.mapper.shop.TbMerchantCouponMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import cn.ysk.cashier.utils.PageUtil;
import cn.ysk.cashier.utils.QueryHelp;
import java.util.List;
import java.util.Map;
import java.sql.Timestamp;
import java.time.Instant;
import java.util.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
/**
* @website https://eladmin.vip
@@ -49,13 +55,30 @@ public class TbMerchantCouponServiceImpl implements TbMerchantCouponService {
private final TbMerchantCouponRepository tbMerchantCouponRepository;
private final TbMerchantCouponMapper tbMerchantCouponMapper;
private final TbProductRepository tbProductRepository;
@Override
public Map<String,Object> queryAll(TbMerchantCouponQueryCriteria criteria, Pageable pageable){
Page<TbMerchantCoupon> page = tbMerchantCouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(tbMerchantCouponMapper::toDto));
List<CouponVO> objects = new ArrayList<>();
for (TbMerchantCoupon o :page.getContent()) {
CouponVO couponVO = new CouponVO();
BeanUtils.copyProperties(o,couponVO);
if (!o.getRelationIds().isEmpty()) {
List<Integer> integers = new ArrayList<>();
integers.add(Integer.valueOf(o.getRelationIds()));
List<TbProduct> byIds = tbProductRepository.findByIds(integers);
couponVO.setName(byIds.get(0).getName());
couponVO.setCoverImg(byIds.get(0).getCoverImg());
}
objects.add(couponVO);
}
HashMap<String, Object> couponvoMap = new HashMap<>();
couponvoMap.put("content", objects);
couponvoMap.put("totalElements", page.getTotalElements());
return couponvoMap;
// return PageUtil.toPage(page.map(tbMerchantCouponMapper::toDto));
}
@Override
public List<TbMerchantCouponDto> queryAll(TbMerchantCouponQueryCriteria criteria){
return tbMerchantCouponMapper.toDto(tbMerchantCouponRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
@@ -71,8 +94,29 @@ public class TbMerchantCouponServiceImpl implements TbMerchantCouponService {
@Override
@Transactional(rollbackFor = Exception.class)
public TbMerchantCouponDto create(TbMerchantCoupon resources) {
return tbMerchantCouponMapper.toDto(tbMerchantCouponRepository.save(resources));
public TbMerchantCoupon create(TbMerchantCoupon resources) {
resources.setCreatedAt(Instant.now().toEpochMilli());
resources.setUpdatedAt(Instant.now().toEpochMilli());
if (resources.getEffectType() == 1){
if (resources.getToTime() == null && resources.getFromTime() == null){
throw new BadRequestException("开始时间结束时间为空");
}
}else {
resources.setToTime(null);
resources.setFromTime(null);
}
if ("product".equals(resources.getClassType())){
if (resources.getRelationIds() == null){
throw new BadRequestException("商品不能为空");
}
}
if (resources.getNumber() == 0){
resources.setLeftNumber(0);
}else {
resources.setLeftNumber(resources.getNumber());
}
return tbMerchantCouponRepository.save(resources);
}
@Override

View File

@@ -142,6 +142,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
tbShopInfo.setCreatedAt(Instant.now().toEpochMilli());
tbShopInfo.setUpdatedAt(Instant.now().toEpochMilli());
tbShopInfo.setOnSale(1);
tbShopInfo.setIsOpenYhq(resources.getIsOpenYhq());
//激活码
TbMerchantRegister tbMerchantRegister = new TbMerchantRegister();
if (resources.getRegisterCode() != null){

View File

@@ -85,4 +85,6 @@ public interface TbProductService {
* @throws IOException /
*/
void download(List<TbProductDto> all, HttpServletResponse response) throws IOException;
void updateIsHot(Integer id, String shopId);
}

View File

@@ -59,7 +59,7 @@ public interface TbMerchantCouponService {
* @param resources /
* @return TbMerchantCouponDto
*/
TbMerchantCouponDto create(TbMerchantCoupon resources);
TbMerchantCoupon create(TbMerchantCoupon resources);
/**
* 编辑