修改商品 规格

This commit is contained in:
wangw 2024-08-08 14:25:42 +08:00
parent bff2ad2250
commit 8e1aa5bc19
2 changed files with 25 additions and 10 deletions

View File

@ -18,6 +18,8 @@ package cn.ysk.cashier.repository.product;
import cn.ysk.cashier.pojo.product.TbProductSkuResult; import cn.ysk.cashier.pojo.product.TbProductSkuResult;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
/** /**
* @website https://eladmin.vip * @website https://eladmin.vip
@ -25,4 +27,9 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2024-02-08 * @date 2024-02-08
**/ **/
public interface TbProductSkuResultRepository extends JpaRepository<TbProductSkuResult, Integer>, JpaSpecificationExecutor<TbProductSkuResult> { public interface TbProductSkuResultRepository extends JpaRepository<TbProductSkuResult, Integer>, JpaSpecificationExecutor<TbProductSkuResult> {
@Modifying
@Query(value = "delete from tb_product_sku_result where id = ?1", nativeQuery = true)
void deleteByIdN(Integer id);
} }

View File

@ -83,9 +83,9 @@ public class TbProductServiceImpl implements TbProductService {
case "weight": case "weight":
return "称重商品"; return "称重商品";
case "currentPrice": case "currentPrice":
return "套餐商品/团购卷";
case "group":
return "时价商品"; return "时价商品";
case "group":
return "套餐商品/团购卷";
default: default:
return type; return type;
} }
@ -328,6 +328,9 @@ public class TbProductServiceImpl implements TbProductService {
TbProduct product = new TbProduct(); TbProduct product = new TbProduct();
//组装 //组装
BeanUtil.copyProperties(resources, product, CopyOptions.create().setIgnoreNullValue(true)); BeanUtil.copyProperties(resources, product, CopyOptions.create().setIgnoreNullValue(true));
if(CollectionUtils.isEmpty(resources.getSkuList())){
throw new BadRequestException("商品规格不可为空");
}
if (!"group".equals(resources.getTypeEnum())) { if (!"group".equals(resources.getTypeEnum())) {
if (resources.getCategoryId() == null) { if (resources.getCategoryId() == null) {
throw new BadRequestException("必填内容未填写"); throw new BadRequestException("必填内容未填写");
@ -446,6 +449,7 @@ public class TbProductServiceImpl implements TbProductService {
} }
} }
if (!"group".equals(product.getTypeEnum())) { if (!"group".equals(product.getTypeEnum())) {
if (resources.getCategoryId() == null) throw new BadRequestException("商品分类不可为空");
product.setIsCombo(0); product.setIsCombo(0);
product.setGroupSnap(null); product.setGroupSnap(null);
if (resources.getNotices() != null && resources.getNotices().getId() != null) { if (resources.getNotices() != null && resources.getNotices().getId() != null) {
@ -506,15 +510,19 @@ public class TbProductServiceImpl implements TbProductService {
productSkuResult.setTagSnap(resources.getSkuSnap()); productSkuResult.setTagSnap(resources.getSkuSnap());
productSkuResult.setId(save.getId()); productSkuResult.setId(save.getId());
tbProductSkuResultRepository.save(productSkuResult); tbProductSkuResultRepository.save(productSkuResult);
}else if ("group".equals(resources.getTypeEnum())) { }else {
TbPurchaseNotice notices = resources.getNotices(); tbProductSkuResultRepository.deleteByIdN(save.getId());
if (StringUtils.isBlank(notices.getDateUsed()) if ("group".equals(resources.getTypeEnum())) {
&& StringUtils.isBlank(notices.getAvailableTime()) TbPurchaseNotice notices = resources.getNotices();
&& StringUtils.isBlank(notices.getBookingType()) if (StringUtils.isBlank(notices.getDateUsed())
&& StringUtils.isBlank(notices.getRefundPolicy())) { && StringUtils.isBlank(notices.getAvailableTime())
throw new BadRequestException("修改购买须知失败,必填项未填写"); && StringUtils.isBlank(notices.getBookingType())
&& StringUtils.isBlank(notices.getRefundPolicy())) {
throw new BadRequestException("修改购买须知失败,必填项未填写");
}
resources.getNotices().setCouponId(save.getId());
noticeRepository.save(resources.getNotices());
} }
noticeRepository.save(resources.getNotices());
} }
} }