|
|
@@ -15,11 +15,12 @@ import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
-import com.cyksj.mapper.SysConfigMapper;
|
|
|
import com.cyksj.mapper.RegisterOrderDonMapper;
|
|
|
+import com.cyksj.mapper.SysConfigMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
+import com.cyksj.web.util.StpUserUtil;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
@@ -30,9 +31,8 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @author chan
|
|
|
@@ -90,6 +90,7 @@ public class GoodsDonController {
|
|
|
* 推广未登录,虚拟商品列表
|
|
|
*/
|
|
|
@GetMapping("/get/popularize")
|
|
|
+ @Deprecated
|
|
|
public Result<SearchResult<GoodsDonPopularizeView>> getPopularizeVipGoods() {
|
|
|
SearchResult<GoodsDonPopularizeView> search = beanSearcher.search(GoodsDonPopularizeView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
.field(GoodsDonPopularizeView::getStatus, true)
|
|
|
@@ -161,11 +162,14 @@ public class GoodsDonController {
|
|
|
if (CollUtil.isNotEmpty(filter_goodsIds)) {
|
|
|
pcCacheKey += ":hz-ip";
|
|
|
}
|
|
|
+ Long fUid = StpUserUtil.getUserIdAfterLogin();
|
|
|
Object value = redisService.get(pcCacheKey);
|
|
|
if (value != null) {
|
|
|
try {
|
|
|
- List<GoodsFrontListView> list = Jsons.parseObject(value, List.class);
|
|
|
+ List<GoodsFrontListView> list = Jsons.parseList(value, GoodsFrontListView.class);
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
+ //设置特定价格
|
|
|
+ setSpecificPrice(list, fUid);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -195,9 +199,11 @@ public class GoodsDonController {
|
|
|
.orderBy(OrderCommentFrontView::getId).desc()
|
|
|
.build());
|
|
|
data.setComments(comments);
|
|
|
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
|
|
|
+ data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
|
|
|
});
|
|
|
redisService.setNx(pcCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
|
|
|
+ //设置特定价格
|
|
|
+ setSpecificPrice(list, fUid);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
}
|
|
|
|
|
|
@@ -205,17 +211,20 @@ public class GoodsDonController {
|
|
|
* h5 银河首页平台展示
|
|
|
*/
|
|
|
@GetMapping("/get/homePage")
|
|
|
- public Result<List<GoodsHomePageView>> getGoodsHomePage() {
|
|
|
+ public Result<List<GoodsFrontListView>> getGoodsHomePage() {
|
|
|
List<Long> filter_goodsIds = getFilterGoodsIds();
|
|
|
String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "H5";
|
|
|
if (CollUtil.isNotEmpty(filter_goodsIds)) {
|
|
|
h5CacheKey += ":hz-ip";
|
|
|
}
|
|
|
+ Long fUid = StpUserUtil.getUserIdAfterLogin();
|
|
|
Object value = redisService.get(h5CacheKey);
|
|
|
if (value != null) {
|
|
|
try {
|
|
|
- List<GoodsHomePageView> list = Jsons.parseObject(value, List.class);
|
|
|
+ List<GoodsFrontListView> list = Jsons.parseList(value, GoodsFrontListView.class);
|
|
|
if (CollUtil.isNotEmpty(list)) {
|
|
|
+ //设置特定价格
|
|
|
+ setSpecificPrice(list, fUid);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
@@ -225,7 +234,7 @@ public class GoodsDonController {
|
|
|
if (CollUtil.isNotEmpty(filter_goodsIds)) {
|
|
|
builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
|
|
|
}
|
|
|
- List<GoodsHomePageView> dataList = beanSearcher.searchAll(GoodsHomePageView.class, builder.build());
|
|
|
+ List<GoodsFrontListView> dataList = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
|
|
|
DateTime now = DateTime.now();
|
|
|
dataList.forEach(data -> {
|
|
|
Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
@@ -234,6 +243,8 @@ public class GoodsDonController {
|
|
|
data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
|
|
|
});
|
|
|
redisService.setNx(h5CacheKey, dataList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
|
|
|
+ //设置特定价格
|
|
|
+ setSpecificPrice(dataList, fUid);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(dataList);
|
|
|
}
|
|
|
|
|
|
@@ -272,6 +283,8 @@ public class GoodsDonController {
|
|
|
*/
|
|
|
@GetMapping("/get/{id}")
|
|
|
public Result<GoodsDonViews> getDetail(@PathVariable Long id) {
|
|
|
+ Long userId = null;
|
|
|
+ Long fUid = StpUserUtil.getUserIdAfterLogin();
|
|
|
GoodsDonViews views = beanSearcher.searchFirst(GoodsDonViews.class, MapUtils.builder().field(GoodsDonViews::getId, id).build());
|
|
|
|
|
|
views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build()));
|
|
|
@@ -287,6 +300,13 @@ public class GoodsDonController {
|
|
|
.field(GoodsDiscountPlusPurchaseRelationFrontView::getSkuId, sku.getId())
|
|
|
.build()));
|
|
|
}
|
|
|
+ if (fUid != null && views.getIsSp()) {
|
|
|
+ //设置特定价格
|
|
|
+ if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
|
|
|
+ sku.setSpecificGoodsIds(null);
|
|
|
+ sku.setSpecificPrice(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(views);
|
|
|
}
|
|
|
@@ -295,11 +315,13 @@ public class GoodsDonController {
|
|
|
* 获取商品推荐平台
|
|
|
*/
|
|
|
@GetMapping("/get/recommend/{id}")
|
|
|
- public Result<List<GoodsRecommendViews>> getRecommendGoodsByGid(@PathVariable Long id) throws Exception {
|
|
|
+ public Result<List<GoodsFrontListView>> getRecommendGoodsByGid(@PathVariable Long id) throws Exception {
|
|
|
String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "recommend:" + id;
|
|
|
Object value = redisService.get(key);
|
|
|
+ Long fUid = StpUserUtil.getUserIdAfterLogin();
|
|
|
if (value != null) {
|
|
|
- List<GoodsRecommendViews> goodsRecommendViews = Jsons.parseList(value.toString(), GoodsRecommendViews.class);
|
|
|
+ List<GoodsFrontListView> goodsRecommendViews = Jsons.parseList(value.toString(), GoodsFrontListView.class);
|
|
|
+ setSpecificPrice(goodsRecommendViews, fUid);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
|
|
|
}
|
|
|
if (value == null) {
|
|
|
@@ -310,13 +332,15 @@ public class GoodsDonController {
|
|
|
.build());
|
|
|
if (goodsDon != null && StrUtil.isNotEmpty(goodsDon.getRecommendGoods())) {
|
|
|
List<Long> recommend_gidList = Jsons.parseList(goodsDon.getRecommendGoods(), Long.class);
|
|
|
- List<GoodsRecommendViews> goodsRecommendViews = beanSearcher.searchAll(GoodsRecommendViews.class, MapUtils.builder().field(GoodsRecommendViews::getGoodsId, recommend_gidList).op(Operator.InList).build());
|
|
|
- goodsRecommendViews.forEach(data->{
|
|
|
+ List<GoodsFrontListView> goodsRecommendViews = beanSearcher.searchAll(GoodsFrontListView.class, MapUtils.builder().field(GoodsRecommendViews::getGoodsId, recommend_gidList).op(Operator.InList).build());
|
|
|
+ goodsRecommendViews.forEach(data -> {
|
|
|
Integer sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class)
|
|
|
- .eq(RegisterOrderDon::getGoodsId, data.getGoodsId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
|
|
|
+ .eq(RegisterOrderDon::getGoodsId, data.getId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
|
|
|
data.setSold(sold + data.getVirtualSold());
|
|
|
});
|
|
|
redisService.setNx(key, Jsons.toJson(goodsRecommendViews), 60 * 15l);
|
|
|
+ //设置特定价格
|
|
|
+ setSpecificPrice(goodsRecommendViews, fUid);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
|
|
|
}
|
|
|
}
|
|
|
@@ -418,4 +442,76 @@ public class GoodsDonController {
|
|
|
notifyMsg.append("前有人购买");
|
|
|
return notifyMsg.toString();
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否购买过特定平台
|
|
|
+ */
|
|
|
+ public Boolean isPaySpecificGoodsIds(String specificGoodsIdsStr, Long userId) {
|
|
|
+ if (StrUtil.isNotBlank(specificGoodsIdsStr)) {
|
|
|
+ try {
|
|
|
+ Set<Long> specificGoodsIds = Jsons.parseSet(specificGoodsIdsStr, Long.class);
|
|
|
+ Number number = beanSearcher.searchCount(OrderDon.class, MapUtils.builder().field(OrderDon::getGoodsId, specificGoodsIds).op(Operator.InList)
|
|
|
+ .field(OrderDon::getUserId, userId)
|
|
|
+ .field(OrderDon::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn)
|
|
|
+ .build());
|
|
|
+ if (number.intValue() == 0) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置平台 特定价格
|
|
|
+ */
|
|
|
+ public void setSpecificPrice(List<GoodsFrontListView> list, Long fUid) {
|
|
|
+ if (fUid != null) {
|
|
|
+ list.forEach(data -> {
|
|
|
+ if (data.getIsSp()) {
|
|
|
+ //查找所有特定规格最小价格 满足条件
|
|
|
+ String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId();
|
|
|
+ Object speciObj = redisService.get(specificGoodsKey);
|
|
|
+ List<GoodsDonSku> specificSkus = null;
|
|
|
+ if (speciObj != null) {
|
|
|
+ specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
|
|
|
+ } else {
|
|
|
+ specificSkus = goodsDonSkuMapper.selectList(
|
|
|
+ Wrappers.lambdaQuery(GoodsDonSku.class)
|
|
|
+ .eq(GoodsDonSku::getGoodsId, data.getId())
|
|
|
+ .eq(GoodsDonSku::getStatus, true)
|
|
|
+ .gt(GoodsDonSku::getSpecificPrice, 0));
|
|
|
+ redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
|
|
|
+ }
|
|
|
+ specificSkus.forEach(specificSku -> {
|
|
|
+ String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
|
|
|
+ if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
|
|
|
+ BigDecimal specificPrice = data.getSpecificPrice();
|
|
|
+ BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
|
|
|
+ Long specificSkuId = specificSku.getId();
|
|
|
+ if (specificPrice == null) {
|
|
|
+ data.setSpecificPrice(skuSpecificPrice);
|
|
|
+ data.setSpecificSkuId(specificSkuId);
|
|
|
+ } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
|
|
|
+ data.setSpecificPrice(skuSpecificPrice);
|
|
|
+ data.setSpecificSkuId(specificSkuId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ List<GoodsDonSkuFrontView> skuList = data.getSkuList();
|
|
|
+ if (CollUtil.isNotEmpty(skuList)) {
|
|
|
+ skuList.forEach(sku->{
|
|
|
+ //设置特定价格
|
|
|
+ if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
|
|
|
+ sku.setSpecificGoodsIds(null);
|
|
|
+ sku.setSpecificPrice(null);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|