Bladeren bron

Merge branch 'coupon_goods_show_info'

zoujiajian 1 jaar geleden
bovenliggende
commit
0f469181e2

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/mapper/manage/coupon/CouponUserMapper.java

@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.cyksj.model.entity.Coupon;
 import com.cyksj.model.entity.CouponUser;
 import com.cyksj.model.views.CouponActiveView;
 import com.cyksj.model.views.CouponUserView;
@@ -37,4 +38,8 @@ public interface CouponUserMapper extends BaseMapper<CouponUser> {
 	Map<String, Long> selectCouponUserNumData(Long couponId);
 
 	List<CouponUserView> couponPersonalByCouponIds(@Param("userIds") List<Long> userIds, @Param("couponIds") List<Long> couponIds);
+
+	Coupon selectUserCouponByGidAndPrice(@Param("userId") Long userId, @Param("goodsId") Long goodsId, @Param("price") BigDecimal price);
+
+	Coupon selectUserCouponBySkuId(@Param("userId") Long userId, @Param("skuId") Long skuId);
 }

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/Coupon.java

@@ -1,6 +1,8 @@
 package com.cyksj.model.entity;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.ejlchina.searcher.bean.DbIgnore;
 import lombok.Getter;
 import lombok.Setter;
 
@@ -116,6 +118,10 @@ public class Coupon extends BaseEntity {
 	@TableLogic(value = "1", delval = "0")
 	private Boolean deleted;
 
+	@DbIgnore
+	@TableField(exist = false)
+	private BigDecimal couponMoney;
+
 	@Getter
 	public enum GoodsType {
 		realGoods("实物"),

+ 45 - 1
netflix-dao/src/main/java/com/cyksj/model/views/GoodsDonSkuFrontView.java

@@ -8,6 +8,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 /*
@@ -88,7 +89,50 @@ public class GoodsDonSkuFrontView {
 	/**
 	 * 价格
 	 */
-	private BigDecimal price;
+	private BigDecimal price = BigDecimal.ZERO;
+
+	/**
+	 * 渠道优惠折扣
+	 */
+	@DbIgnore
+	private BigDecimal channelDiscount;
+
+	/**
+	 * 优惠价格
+	 */
+	@DbIgnore
+	private BigDecimal discountPrice;
+
+	/**
+	 * 优惠折扣
+	 */
+	@DbIgnore
+	private BigDecimal discount;
+
+	/**
+	 * 满减金额
+	 */
+	@DbIgnore
+	private BigDecimal reduceMoney;
+
+	/**
+	 * 优惠券有效结束时间
+	 */
+	@DbIgnore
+	private Date validEndTime;
+
+	/**
+	 * 优惠券id
+	 */
+	@DbIgnore
+	private Long couponId;
+
+	/**
+	 * 支付来源
+	 * 0全无 1.优惠券 2.渠道 3特定价格
+	 */
+	@DbIgnore
+	private Integer source = 0;
 
 	/**
 	 * 专属用户规格

+ 45 - 1
netflix-dao/src/main/java/com/cyksj/model/views/GoodsFrontListCategoryView.java

@@ -9,6 +9,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -74,7 +75,50 @@ public class GoodsFrontListCategoryView {
 	 * 最低规格价格
 	 */
 	@DbField("g.min_price")
-	private BigDecimal price;
+	private BigDecimal price = BigDecimal.ZERO;
+
+	/**
+	 * 渠道优惠折扣
+	 */
+	@DbIgnore
+	private BigDecimal channelDiscount;
+
+	/**
+	 * 优惠价格
+	 */
+	@DbIgnore
+	private BigDecimal discountPrice;
+
+	/**
+	 * 优惠折扣
+	 */
+	@DbIgnore
+	private BigDecimal discount;
+
+	/**
+	 * 满减金额
+	 */
+	@DbIgnore
+	private BigDecimal reduceMoney;
+
+	/**
+	 * 优惠券有效结束时间
+	 */
+	@DbIgnore
+	private Date validEndTime;
+
+	/**
+	 * 优惠券id
+	 */
+	@DbIgnore
+	private Long couponId;
+
+	/**
+	 * 支付来源
+	 * 0全无 1.优惠券 2.渠道 3特定价格
+	 */
+	@DbIgnore
+	private Integer source = 0;
 
 	/**
 	 * 最低规格月份

+ 46 - 1
netflix-dao/src/main/java/com/cyksj/model/views/HomeManagementFrontView.java

@@ -12,6 +12,7 @@ import lombok.Getter;
 import lombok.Setter;
 
 import java.math.BigDecimal;
+import java.util.Date;
 import java.util.List;
 
 /*
@@ -116,6 +117,50 @@ public class HomeManagementFrontView {
 	@DbField("g.match_img")
 	private String matchImg;
 
+
+	/**
+	 * 渠道优惠折扣
+	 */
+	@DbIgnore
+	private BigDecimal channelDiscount;
+
+	/**
+	 * 优惠价格
+	 */
+	@DbIgnore
+	private BigDecimal discountPrice;
+
+	/**
+	 * 优惠折扣
+	 */
+	@DbIgnore
+	private BigDecimal discount;
+
+	/**
+	 * 满减金额
+	 */
+	@DbIgnore
+	private BigDecimal reduceMoney;
+
+	/**
+	 * 优惠券有效结束时间
+	 */
+	@DbIgnore
+	private Date validEndTime;
+
+	/**
+	 * 优惠券id
+	 */
+	@DbIgnore
+	private Long couponId;
+
+	/**
+	 * 支付来源
+	 * 0全无 1.优惠券 2.渠道 3特定价格
+	 */
+	@DbIgnore
+	private Integer source = 0;
+
 	/**
 	 * 类型
 	 */
@@ -132,7 +177,7 @@ public class HomeManagementFrontView {
 	 * 最低规格价格
 	 */
 	@DbField("g.min_price")
-	private BigDecimal price;
+	private BigDecimal price = BigDecimal.ZERO;;
 
 	/**
 	 * 最低规格月份

+ 28 - 0
netflix-dao/src/main/resources/mapper/CouponUserMapper.xml

@@ -287,4 +287,32 @@
         and cu.channel != 'exCode'
         order by `orderby`
     </select>
+
+    <select id="selectUserCouponByGidAndPrice" resultType="com.cyksj.model.entity.Coupon">
+        select c.id,
+               c.discount,
+               c.reduce_money,
+               cu.valid_start_time,
+               cu.valid_end_time,
+               if(type = 'discount', sku.price * (1 - c.discount), c.reduce_money) as couponMoney
+        from (select * from coupon_user where user_id = #{userId} and status = 'unused' and valid_start_time &lt; now() and valid_end_time > now()) cu
+                 inner join coupon c on c.id = cu.coupon_id
+                 inner join coupon_sku cs on cs.coupon_id = c.id and cs.goods_id = #{goodsId}
+                 inner join goods_don_sku sku on sku.id = cs.sku_id and sku.status is true and sku.price = #{price}
+        order by couponMoney desc limit 1
+    </select>
+
+    <select id="selectUserCouponBySkuId" resultType="com.cyksj.model.entity.Coupon">
+        select c.id,
+               c.discount,
+               c.reduce_money,
+               cu.valid_start_time,
+               cu.valid_end_time,
+               if(type = 'discount', sku.price * (1 - c.discount), c.reduce_money) as couponMoney
+        from (select * from coupon_user where user_id = #{userId} and status = 'unused' and valid_start_time &lt; now() and valid_end_time > now()) cu
+                 inner join coupon c on c.id = cu.coupon_id
+                 inner join coupon_sku cs on cs.coupon_id = c.id and cs.sku_id = #{skuId}
+                 inner join goods_don_sku sku on sku.id = cs.sku_id and sku.status is true
+        order by couponMoney desc limit 1
+    </select>
 </mapper>

+ 190 - 14
netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java

@@ -19,7 +19,7 @@ import com.cyksj.mapper.GiftCardGoodsSkuMapper;
 import com.cyksj.mapper.GoodsDonSkuMapper;
 import com.cyksj.mapper.OrderDonMapper;
 import com.cyksj.mapper.RegisterOrderDonMapper;
-import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
+import com.cyksj.mapper.manage.coupon.CouponUserMapper;
 import com.cyksj.mapper.shop.YhShopGoodsSkuMapper;
 import com.cyksj.mapper.sys.SysConfigMapper;
 import com.cyksj.model.entity.*;
@@ -82,7 +82,7 @@ public class GoodsDonController {
 
 	private final UserService userService;
 
-	private final UserDistributeSharedMapper userDistributeSharedMapper;
+	private final CouponUserMapper couponUserMapper;
 
 	private final GoodsDonFrontService goodsDonFrontService;
 
@@ -342,7 +342,7 @@ public class GoodsDonController {
 	 * 获取商品详情
 	 */
 	@GetMapping("/get/{id}")
-	public Result<? extends Object> getDetail(@PathVariable Long id, String customId, String dsCode) {
+	public Result<? extends Object> getDetail(@PathVariable Long id, String customId, String dsCode, BigDecimal discount) {
 		if (StrUtil.isNotBlank(customId) && id != 15) {
 			Result<YhShopGoodsFrontView> yhShopGoodsDetail = getGoodsDetailByYhsId(yhShopFrontService.getYhsIdByCustomId(customId), id);
 			return yhShopGoodsDetail;
@@ -409,7 +409,7 @@ public class GoodsDonController {
 				if (fUid == null) {
 					sku.setSpecificPrice(null);
 					sku.setSpecificGoodsIds(null);
-				}else {
+				} else {
 					//设置特定价格
 					if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
 						sku.setSpecificGoodsIds(null);
@@ -447,12 +447,14 @@ public class GoodsDonController {
 //					});
 //				}
 //			}
+			//设置规格优惠后的价格
+			sku.setChannelDiscount(discount);
+			setUserCouponSkuMoney(fUid, sku);
 			return true;
 		}).collect(Collectors.toList()));
 		return GatewayResponse.SUCCESS.newBuilder().toResult(views);
 	}
-
-    /**
+	/**
      * 获取商品推荐平台
      */
     @GetMapping("/get/recommend/{id}")
@@ -560,7 +562,7 @@ public class GoodsDonController {
 	 * 获取首页配置列表
 	 */
 	@GetMapping("/get/homeManage")
-	public Result<Map<String, List<HomeManagementFrontView>>> getHomeManagementFrontPage(String customId, String dsCode) {
+	public Result<Map<String, List<HomeManagementFrontView>>> getHomeManagementFrontPage(String customId, String dsCode, BigDecimal discount) {
 		String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "homeManage";
 		Long yhsId = null;
 		if (StrUtil.isNotBlank(customId)) {
@@ -613,11 +615,11 @@ public class GoodsDonController {
 			try {
 				//精彩推荐
 				List<HomeManagementFrontView> exList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.ex.name())), HomeManagementFrontView.class);
-				setHomeConfigGoods(map, HomeManagementConfig.Type.ex, exList, dsUserId, existsChannel, fUid);
+				setHomeConfigGoods(map, HomeManagementConfig.Type.ex, exList, dsUserId, existsChannel, fUid, discount);
 
 				//虚拟平台
 				List<HomeManagementFrontView> vgList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.vg.name())), HomeManagementFrontView.class);
-				setHomeConfigGoods(map, HomeManagementConfig.Type.vg, vgList, dsUserId, existsChannel, fUid);
+				setHomeConfigGoods(map, HomeManagementConfig.Type.vg, vgList, dsUserId, existsChannel, fUid, discount);
 			} catch (Exception e) {
 			}
 		}
@@ -862,7 +864,7 @@ public class GoodsDonController {
 	/**
 	 * 设置首页配置 涉及平台特定价格
 	 */
-	public void setHomeManageSpecific(List<HomeManagementFrontView> list, Long fUid, Long dsUserId) {
+	public void setHomeManageSpecific(List<HomeManagementFrontView> list, Long fUid, Long dsUserId, BigDecimal discount) {
 		DateTime now = DateTime.now();
 		list.forEach(data -> {
 			if (data.getIsSp() != null && data.getIsSp() && fUid != null) {
@@ -889,10 +891,13 @@ public class GoodsDonController {
 			}
 			data.setSold(getGoodsSold(data.getGoodsId(), data.getSold()));
 			data.setNotifyMsg(getPayMsgTime(data.getGoodsId(), now, 1, null));
+			//设置用户存在优惠券的优惠商品价格
+			data.setChannelDiscount(discount);
+			setHomeManageUserCouponGoodsMoney(fUid, data);
 		});
 	}
 
-	public void setHomeConfigGoods(Map<String, List<HomeManagementFrontView>> map, HomeManagementConfig.Type type, List<HomeManagementFrontView> list, AtomicLong dsUserId, AtomicBoolean existsChannel, Long fUid) throws Exception {
+	public void setHomeConfigGoods(Map<String, List<HomeManagementFrontView>> map, HomeManagementConfig.Type type, List<HomeManagementFrontView> list, AtomicLong dsUserId, AtomicBoolean existsChannel, Long fUid, BigDecimal discount) throws Exception {
 		//设置特定价格
 		if (CollUtil.isNotEmpty(list)) {
 			list = list.stream().filter(data -> {
@@ -914,7 +919,7 @@ public class GoodsDonController {
 				}
 				return true;
 			}).collect(Collectors.toList());
-			setHomeManageSpecific(list, fUid, dsUserId.get());
+			setHomeManageSpecific(list, fUid, dsUserId.get(), discount);
 			map.put(type.name(), list);
 		}
 	}
@@ -994,7 +999,7 @@ public class GoodsDonController {
 	 * 根据分类获取对应平台
 	 */
 	@GetMapping("/get/categoryGoods")
-	public Result<? extends Object> getGoodsByCategory(Long cgy, String customId, String dsCode) {
+	public Result<? extends Object> getGoodsByCategory(Long cgy, String customId, String dsCode, BigDecimal discount) {
 		if (StrUtil.isNotBlank(customId)) {
 			Result<List<YhShopGoodsFrontCategoryView>> shopGoods = getShopCategoryGoods(yhShopFrontService.getYhsIdByCustomId(customId), cgy);
 			return shopGoods;
@@ -1022,7 +1027,8 @@ public class GoodsDonController {
 			}
 			List<GoodsFrontListCategoryView> goodsFrontListViews = beanSearcher.searchAll(GoodsFrontListCategoryView.class, mapBuilder.build());
 			goodsFrontListViews.forEach(data -> {
-				data.setSold(getGoodsSold(data.getId(), data.getSold()));;
+				data.setSold(getGoodsSold(data.getId(), data.getSold()));
+				;
 				data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
 			});
 			redisService.setNx(categoryGoodsKey, goodsFrontListViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 10 * 60);
@@ -1071,6 +1077,9 @@ public class GoodsDonController {
 			}
 			//设置特定价格
 			setGcSpecificPrice(data, fUid, dsUserId.get());
+			//设置用户存在优惠券的优惠商品价格
+			data.setChannelDiscount(discount);
+			setUserCouponGoodsMoney(fUid, data);
 			return true;
 		}).collect(Collectors.toList());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(goodsFrontListViews);
@@ -1363,5 +1372,172 @@ public class GoodsDonController {
 		return Integer.parseInt(soldObj.toString());
 	}
 
+	/**
+	 * 设置平台优惠价格
+	 */
+	private void setUserCouponGoodsMoney(Long userId, GoodsFrontListCategoryView data) {
+		//登录后
+		if (userId != null) {
+			//特定价格
+			BigDecimal specificPrice = data.getSpecificPrice();
+			//渠道折扣
+			BigDecimal channelDiscount = data.getChannelDiscount();
+			//支付来源
+			Integer source = 0;
+			BigDecimal presentCouponMoney = null;
+			//寻找对应最低规格的优惠券
+			Coupon coupon = couponUserMapper.selectUserCouponByGidAndPrice(userId, data.getId(), data.getPrice());
+			if (coupon != null) {
+				source = 1;
+				data.setDiscount(coupon.getDiscount());
+				data.setReduceMoney(coupon.getReduceMoney());
+				data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney()));
+				data.setValidEndTime(coupon.getValidEndTime());
+				data.setCouponId(coupon.getId());
+				presentCouponMoney = data.getDiscountPrice();
+			}
+			if (channelDiscount != null) {
+				BigDecimal channelCouponMoney = data.getPrice().multiply(channelDiscount);
+				if (presentCouponMoney == null) {
+					presentCouponMoney = channelCouponMoney;
+				}
+				if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) {
+					source = 2;
+					presentCouponMoney = channelCouponMoney;
+					data.setDiscount(channelDiscount);
+					data.setReduceMoney(null);
+					data.setDiscountPrice(channelCouponMoney);
+					data.setValidEndTime(null);
+					data.setCouponId(null);
+				}
+			}
+			if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) {
+				if (presentCouponMoney == null) {
+					presentCouponMoney = specificPrice;
+				}
+				if (specificPrice.compareTo(presentCouponMoney) <= 0) {
+					source = 3;
+					data.setDiscount(null);
+					data.setReduceMoney(null);
+					data.setDiscountPrice(specificPrice);
+					data.setValidEndTime(null);
+					data.setCouponId(null);
+				}
+			}
+			data.setSource(source);
+		}
+	}
+
+	/**
+	 * 设置平台规格优惠价格
+	 */
+	private void setUserCouponSkuMoney(Long userId, GoodsDonSkuFrontView sku) {
+		//登录后
+		if (userId != null) {
+			//特定价格
+			BigDecimal specificPrice = sku.getSpecificPrice();
+			//渠道折扣
+			BigDecimal channelDiscount = sku.getChannelDiscount();
+			//支付来源
+			Integer source = 0;
+			BigDecimal presentCouponMoney = null;
+			//寻找对应最低规格的优惠券
+			Coupon coupon = couponUserMapper.selectUserCouponBySkuId(userId, sku.getId());
+			if (coupon != null) {
+				source = 1;
+				sku.setDiscount(coupon.getDiscount());
+				sku.setReduceMoney(coupon.getReduceMoney());
+				sku.setDiscountPrice(sku.getPrice().subtract(coupon.getCouponMoney()));
+				sku.setValidEndTime(coupon.getValidEndTime());
+				sku.setCouponId(coupon.getId());
+				presentCouponMoney = sku.getDiscountPrice();
+			}
+			if (channelDiscount != null) {
+				BigDecimal channelCouponMoney = sku.getPrice().multiply(channelDiscount);
+				if (presentCouponMoney == null) {
+					presentCouponMoney = channelCouponMoney;
+				}
+				if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) {
+					source = 2;
+					presentCouponMoney = channelCouponMoney;
+					sku.setDiscount(channelDiscount);
+					sku.setReduceMoney(null);
+					sku.setDiscountPrice(channelCouponMoney);
+					sku.setValidEndTime(null);
+					sku.setCouponId(null);
+				}
+			}
+			if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) {
+				if (presentCouponMoney == null) {
+					presentCouponMoney = specificPrice;
+				}
+				if (specificPrice.compareTo(presentCouponMoney) <= 0) {
+					source = 3;
+					sku.setDiscount(null);
+					sku.setReduceMoney(null);
+					sku.setDiscountPrice(specificPrice);
+					sku.setValidEndTime(null);
+					sku.setCouponId(null);
+				}
+			}
+			sku.setSource(source);
+		}
+	}
+
+	/**
+	 * 设置推荐平台优惠价格
+	 */
+	private void setHomeManageUserCouponGoodsMoney(Long userId, HomeManagementFrontView data) {
+		//登录后
+		if (userId != null) {
+			//特定价格
+			BigDecimal specificPrice = data.getSpecificPrice();
+			//渠道折扣
+			BigDecimal channelDiscount = data.getChannelDiscount();
+			//支付来源
+			Integer source = 0;
+			BigDecimal presentCouponMoney = null;
+			//寻找对应最低规格的优惠券
+			Coupon coupon = couponUserMapper.selectUserCouponByGidAndPrice(userId, data.getGoodsId(), data.getPrice());
+			if (coupon != null) {
+				source = 1;
+				data.setDiscount(coupon.getDiscount());
+				data.setReduceMoney(coupon.getReduceMoney());
+				data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney()));
+				data.setValidEndTime(coupon.getValidEndTime());
+				data.setCouponId(coupon.getId());
+				presentCouponMoney = data.getDiscountPrice();
+			}
+			if (channelDiscount != null) {
+				BigDecimal channelCouponMoney = data.getPrice().multiply(channelDiscount);
+				if (presentCouponMoney == null) {
+					presentCouponMoney = channelCouponMoney;
+				}
+				if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) {
+					source = 2;
+					presentCouponMoney = channelCouponMoney;
+					data.setDiscount(channelDiscount);
+					data.setReduceMoney(null);
+					data.setDiscountPrice(channelCouponMoney);
+					data.setValidEndTime(null);
+					data.setCouponId(null);
+				}
+			}
+			if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) {
+				if (presentCouponMoney == null) {
+					presentCouponMoney = specificPrice;
+				}
+				if (specificPrice.compareTo(presentCouponMoney) <= 0) {
+					source = 3;
+					data.setDiscount(null);
+					data.setReduceMoney(null);
+					data.setDiscountPrice(specificPrice);
+					data.setValidEndTime(null);
+					data.setCouponId(null);
+				}
+			}
+			data.setSource(source);
+		}
+	}
 
 }