|
|
@@ -1,24 +1,22 @@
|
|
|
package com.izouma.dingdong.service;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
import com.izouma.dingdong.converter.LongArrayConverter;
|
|
|
import com.izouma.dingdong.domain.OrderGoodsSpec;
|
|
|
import com.izouma.dingdong.domain.merchant.Goods;
|
|
|
import com.izouma.dingdong.domain.merchant.GoodsSpecification;
|
|
|
-import com.izouma.dingdong.dto.OrderGoodsSpecDTO;
|
|
|
import com.izouma.dingdong.enums.ApplyStatus;
|
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
|
import com.izouma.dingdong.repo.OrderGoodsSpecRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.GoodsRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.GoodsSpecificationRepo;
|
|
|
-import com.izouma.dingdong.service.user.ShoppingCartService;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
@@ -28,44 +26,7 @@ public class OrderGoodsSpecService {
|
|
|
private OrderGoodsSpecRepo orderGoodsSpecRepo;
|
|
|
private GoodsSpecificationRepo goodsSpecificationRepo;
|
|
|
private GoodsRepo goodsRepo;
|
|
|
- private ShoppingCartService shoppingCartService;
|
|
|
-
|
|
|
- /*
|
|
|
- 添加规格
|
|
|
- */
|
|
|
- public OrderGoodsSpec add(OrderGoodsSpecDTO orderGoodsSpecDTO) {
|
|
|
- OrderGoodsSpec goodsSpec = null;
|
|
|
- if (orderGoodsSpecDTO.getId()!=null){
|
|
|
- goodsSpec = orderGoodsSpecRepo.findById(orderGoodsSpecDTO.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
- }
|
|
|
-
|
|
|
- String spec = null;
|
|
|
- //String ids = null;
|
|
|
- Goods goods = goodsRepo.findById(orderGoodsSpecDTO.getGoodsId()).orElseThrow(new BusinessException("无商品"));
|
|
|
-
|
|
|
- //判断商品是否通过审核
|
|
|
- if (!ApplyStatus.PASS.equals(goods.getStatus())) {
|
|
|
- throw new BusinessException("商品审核中或未通过");
|
|
|
- }
|
|
|
-
|
|
|
- BigDecimal total = goods.getAmount();
|
|
|
- BigDecimal real = goods.getDiscountAmount();
|
|
|
-
|
|
|
-/*
|
|
|
- if (CollUtil.isNotEmpty(goodsSpecifications)) {
|
|
|
- for (GoodsSpecification g : goodsSpecifications) {
|
|
|
- total = total.add(g.getAmount());
|
|
|
- real = real.add(g.getAmount());
|
|
|
-
|
|
|
|
|
|
- }
|
|
|
- spec = JSONObject.toJSONString(goodsSpecifications);
|
|
|
-*/
|
|
|
-
|
|
|
-// }
|
|
|
- return null;
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
public OrderGoodsSpec add(Long goodsId, String goodsSpecificationIds, Integer num) {
|
|
|
Goods goods = goodsRepo.findById(goodsId).orElseThrow(new BusinessException("无商品"));
|
|
|
@@ -82,8 +43,23 @@ public class OrderGoodsSpecService {
|
|
|
LongArrayConverter longArrayConverter = new LongArrayConverter();
|
|
|
List<Long> longs = longArrayConverter.convertToEntityAttribute(goodsSpecificationIds);
|
|
|
|
|
|
+ List<Long> parents = new ArrayList<>();
|
|
|
for (Long l : longs) {
|
|
|
GoodsSpecification spec = goodsSpecificationRepo.findById(l).orElseThrow(new BusinessException("无规格"));
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(spec.getParent())) {
|
|
|
+ throw new BusinessException("选择规格分类下的规格商品");
|
|
|
+ } else {
|
|
|
+ GoodsSpecification parentSpec = goodsSpecificationRepo.findById(spec.getParent()).orElseThrow(new BusinessException("无规格分类"));
|
|
|
+ if (!parentSpec.getMultiple()) {
|
|
|
+ parents.add(spec.getParent());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (ObjectUtil.isEmpty(spec.getAmount())) {
|
|
|
+ spec.setAmount(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
//价钱
|
|
|
total = total.add(spec.getAmount());
|
|
|
real = real.add(spec.getAmount());
|
|
|
@@ -95,6 +71,10 @@ public class OrderGoodsSpecService {
|
|
|
specName = new StringBuilder(spec.getName());
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (parents.size() != new HashSet<>(parents).size()) {
|
|
|
+ throw new BusinessException("存在不可多选规格");
|
|
|
+ }
|
|
|
}
|
|
|
if (num == null || num <= 0) {
|
|
|
num = 1;
|