|
|
@@ -1,6 +1,7 @@
|
|
|
package com.cyksj.service.giftcard.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.mapper.GiftCardGoodsSkuMapper;
|
|
|
@@ -12,7 +13,6 @@ import com.cyksj.model.entity.GoodsDonSku;
|
|
|
import com.cyksj.model.request.GiftCardGoodsSkuReq;
|
|
|
import com.cyksj.service.giftcard.GiftCardGoodsSkuService;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import org.springframework.dao.DuplicateKeyException;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
@@ -45,11 +45,11 @@ public class GiftCardGoodsSkuServiceImpl extends ServiceImpl<GiftCardGoodsSkuMap
|
|
|
}
|
|
|
BigDecimal cash = data.getCash();
|
|
|
Integer gcType = data.getGcType();
|
|
|
- BigDecimal price = data.getPrice();
|
|
|
//礼品卡金额 与购买价格一致
|
|
|
if (cash != null) {
|
|
|
- price = cash;
|
|
|
+ data.setPrice(cash);
|
|
|
}
|
|
|
+ BigDecimal price = data.getPrice();
|
|
|
if (price == null || price.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入正确的礼品卡配置价格");
|
|
|
}
|
|
|
@@ -61,13 +61,13 @@ public class GiftCardGoodsSkuServiceImpl extends ServiceImpl<GiftCardGoodsSkuMap
|
|
|
if (gcSkuId != null && cash != null) {
|
|
|
throw BusinessRuntimeException.getInstance("只能选择一种礼品卡类型");
|
|
|
}
|
|
|
- //虚拟卡
|
|
|
if (cash != null) {
|
|
|
if (cash.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
throw BusinessRuntimeException.getInstance("请输入正确的礼品卡现金类型金额");
|
|
|
}
|
|
|
gcType = 1;
|
|
|
}
|
|
|
+ //虚拟卡
|
|
|
if (gcSkuId != null) {
|
|
|
GoodsDonSku sku = goodsDonSkuMapper.selectById(gcSkuId);
|
|
|
if (sku == null) {
|
|
|
@@ -80,10 +80,14 @@ public class GiftCardGoodsSkuServiceImpl extends ServiceImpl<GiftCardGoodsSkuMap
|
|
|
data.setGcGoodsId(sku.getGoodsId());
|
|
|
}
|
|
|
data.setGcType(gcType);
|
|
|
- try {
|
|
|
- this.saveOrUpdate(data);
|
|
|
- } catch (DuplicateKeyException e) {
|
|
|
+ if (gcType == 2 && data.getId() == null) {
|
|
|
+ GiftCardGoodsSku one = this.getOne(Wrappers.lambdaQuery(GiftCardGoodsSku.class)
|
|
|
+ .eq(GiftCardGoodsSku::getGcSkuId, gcSkuId).last("limit 1"));
|
|
|
+ if (one != null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
+ this.saveOrUpdate(data);
|
|
|
}
|
|
|
|
|
|
@Override
|