zoujiajian 2 роки тому
батько
коміт
5c1ce737f9

+ 4 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/GiftCardGoodsSku.java

@@ -41,4 +41,8 @@ public class GiftCardGoodsSku extends BaseEntity{
 	private BigDecimal price;
 
 	private String logo;
+
+	private Boolean status;
+
+	private Boolean deleted;
 }

+ 2 - 1
netflix-dao/src/main/java/com/cyksj/model/views/GiftCardGoodsSkuFrontView.java

@@ -17,7 +17,8 @@ import java.math.BigDecimal;
 @Getter
 @Setter
 @SearchBean(tables = "gift_card_goods_sku gc left join goods_don g on g.id = gc.gc_goods_id" +
-		" left join goods_don_sku sku on sku.id = gc.gc_sku_id")
+		" left join goods_don_sku sku on sku.id = gc.gc_sku_id",
+		where = "gc.status is true and gc.deleted is true")
 @JsonInclude(JsonInclude.Include.NON_NULL)
 public class GiftCardGoodsSkuFrontView {
 	@DbField("gc.id")

+ 5 - 1
netflix-dao/src/main/java/com/cyksj/model/views/GiftCardGoodsSkuView.java

@@ -16,7 +16,8 @@ import java.math.BigDecimal;
 @Getter
 @Setter
 @SearchBean(tables = "gift_card_goods_sku gc left join goods_don g on g.id = gc.gc_goods_id" +
-		" left join goods_don_sku sku on sku.id = gc.gc_sku_id")
+		" left join goods_don_sku sku on sku.id = gc.gc_sku_id",
+		where = "gc.deleted is true")
 public class GiftCardGoodsSkuView {
 	@DbField("gc.id")
 	private Long id;
@@ -56,4 +57,7 @@ public class GiftCardGoodsSkuView {
 
 	@DbField("gc.logo")
 	private String logo;
+
+	@DbField("gc.status")
+	private Boolean status;
 }

+ 11 - 7
netflix-service/src/main/java/com/cyksj/service/giftcard/impl/GiftCardGoodsSkuServiceImpl.java

@@ -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

+ 28 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/goods/GiftCardController.java

@@ -70,4 +70,32 @@ public class GiftCardController {
 		SearchResult<GiftCardUserPayView> search = beanSearcher.search(GiftCardUserPayView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
 	}
+
+	/**
+	 * 礼品卡上下架
+	 */
+	@PutMapping("/update/status/{id}")
+	public Result<String> updateStatusById(@PathVariable Long id) {
+		GiftCardGoodsSku byId = giftCardGoodsSkuService.getById(id);
+		if (byId == null) {
+			return GatewayResponse.SUCCESS.newBuilder().toResult();
+		}
+		byId.setStatus(!byId.getStatus());
+		giftCardGoodsSkuService.updateById(byId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
+
+	/**
+	 * 删除礼品卡
+	 */
+	@DeleteMapping("/del/{id}")
+	public Result<String> delById(@PathVariable Long id) {
+		GiftCardGoodsSku byId = giftCardGoodsSkuService.getById(id);
+		if (byId == null) {
+			return GatewayResponse.SUCCESS.newBuilder().toResult();
+		}
+		byId.setDeleted(false);
+		giftCardGoodsSkuService.updateById(byId);
+		return GatewayResponse.SUCCESS.newBuilder().toResult();
+	}
 }