|
|
@@ -6,20 +6,23 @@ import cn.hutool.core.date.DateUnit;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.RandomUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import cn.hutool.extra.servlet.ServletUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.cyksj.common.constant.Constant;
|
|
|
-import com.cyksj.common.i18n.I18nMessageUtil;
|
|
|
+import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
-import com.cyksj.common.util.StringUtil;
|
|
|
import com.cyksj.dto.Result;
|
|
|
+import com.cyksj.dto.UserSharedDto;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
-import com.cyksj.mapper.SysConfigMapper;
|
|
|
-import com.cyksj.model.entity.*;
|
|
|
+import com.cyksj.model.entity.GoodsDon;
|
|
|
+import com.cyksj.model.entity.GoodsDonSku;
|
|
|
+import com.cyksj.model.entity.OrderDon;
|
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
+import com.cyksj.service.user.UserBindRelationService;
|
|
|
+import com.cyksj.service.user.UserService;
|
|
|
+import com.cyksj.web.util.StpUserUtil;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.SearchResult;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
@@ -30,9 +33,14 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author chan
|
|
|
@@ -50,12 +58,43 @@ public class GoodsDonController {
|
|
|
|
|
|
private final OrderDonMapper orderDonMapper;
|
|
|
|
|
|
-
|
|
|
private final GoodsDonSkuMapper goodsDonSkuMapper;
|
|
|
|
|
|
private final RedisService redisService;
|
|
|
|
|
|
- private final SysConfigMapper sysConfigMapper;
|
|
|
+ private final UserService userService;
|
|
|
+
|
|
|
+ private final UserBindRelationService userBindRelationService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取平台商品分类
|
|
|
+ */
|
|
|
+ @GetMapping("/get/category")
|
|
|
+ public Result<List<GoodsDonCategoryFrontView>> getCategory() {
|
|
|
+ String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "category";
|
|
|
+ Object o = redisService.get(key);
|
|
|
+ List<GoodsDonCategoryFrontView> list;
|
|
|
+ MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
+ String condition = " and (select count(*) from goods_don_category_relate gcr inner join goods_don g on g.id = gcr.goods_id where gcr.category = gc.id) > 0";
|
|
|
+ mapBuilder.put("condition", condition);
|
|
|
+ if (o == null) {
|
|
|
+ list = beanSearcher.searchAll(GoodsDonCategoryFrontView.class, mapBuilder
|
|
|
+ .build());
|
|
|
+ redisService.setNx(key, list, 30 * 60l);
|
|
|
+ o = redisService.get(key);
|
|
|
+ }
|
|
|
+ list = Jsons.parseList(o, GoodsDonCategoryFrontView.class);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商品搜索
|
|
|
+ */
|
|
|
+ @GetMapping("/search")
|
|
|
+ public Result<SearchResult<GoodsDonSearchView>> search() {
|
|
|
+ SearchResult<GoodsDonSearchView> search = beanSearcher.search(GoodsDonSearchView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取商品列表
|
|
|
@@ -65,7 +104,7 @@ public class GoodsDonController {
|
|
|
SearchResult<GoodsDon> search = beanSearcher.search(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
.field(GoodsDon::getStatus, true)
|
|
|
.field(GoodsDon::getDeleted, true)
|
|
|
- .orderBy(GoodsDon::getSortBy).desc()
|
|
|
+ .orderBy(GoodsDon::getSortBy).asc()
|
|
|
.orderBy(GoodsDon::getId).asc()
|
|
|
.build()
|
|
|
);
|
|
|
@@ -75,171 +114,97 @@ public class GoodsDonController {
|
|
|
.orderByAsc(GoodsDonSku::getPrice)
|
|
|
.last("limit 1")
|
|
|
.select(GoodsDonSku::getPrice));
|
|
|
- Optional.ofNullable(goodsDonSku).ifPresent(sku->{
|
|
|
+ Optional.ofNullable(goodsDonSku).ifPresent(sku -> {
|
|
|
goods.setPrice(goodsDonSku.getPrice());
|
|
|
- goods.setSoldNum(goods.getVirtualSold() + orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .eq(OrderDon::getGoodsId, goods.getId())
|
|
|
- .notIn(OrderDon::getStatus, Constant.noOrderStatus)));
|
|
|
+ goods.setSoldNum(getGoodsSold(goods.getId(), goods.getVirtualSold()));
|
|
|
});
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 推广未登录,虚拟商品列表
|
|
|
+ * 获取商品详情
|
|
|
*/
|
|
|
- @GetMapping("/get/popularize")
|
|
|
- public Result<SearchResult<GoodsDonPopularizeView>> getPopularizeVipGoods() {
|
|
|
- SearchResult<GoodsDonPopularizeView> search = beanSearcher.search(GoodsDonPopularizeView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
- .field(GoodsDonPopularizeView::getStatus, true)
|
|
|
- .field(GoodsDonPopularizeView::getDeleted, true)
|
|
|
- .field(GoodsDonPopularizeView::getType, 1)
|
|
|
- .orderBy(GoodsDonPopularizeView::getSortBy).desc()
|
|
|
- .orderBy(GoodsDonPopularizeView::getId).asc()
|
|
|
- .build());
|
|
|
- DateTime now = DateTime.now();
|
|
|
- search.getDataList().forEach(data -> {
|
|
|
- data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build()));
|
|
|
- data.setSkuList(beanSearcher.searchAll(GoodsDonSku.class, MapUtils.builder().field(GoodsDonSku::getGoodsId, data.getId()).field(GoodsDonSku::getStatus, true).orderBy(GoodsDonSku::getPrice).asc().build()));
|
|
|
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
- data.setSold(sold + data.getVirtualSold());
|
|
|
+ @GetMapping("/get/{id}")
|
|
|
+ public Result<? extends Object> getDetail(@PathVariable Long id, String dsCode) {
|
|
|
+ String goodsDetailKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "goods_detail:" + id;
|
|
|
+ //List<Long> filter_goodsIds = getFilterGoodsIds();
|
|
|
+ List<Long> filter_goodsIds = null;
|
|
|
+ //存在过滤平台 商品详情不返回
|
|
|
+ if (CollUtil.isNotEmpty(filter_goodsIds) && filter_goodsIds.contains(id)) {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
+ Object o = redisService.get(goodsDetailKey);
|
|
|
+ if (o == null) {
|
|
|
+ GoodsFrontListView views = beanSearcher.searchFirst(GoodsFrontListView.class, MapUtils.builder().field(GoodsFrontListView::getId, id)
|
|
|
+ .build());
|
|
|
+ if (views == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("商品已下架..");
|
|
|
+ }
|
|
|
|
|
|
- Optional.ofNullable(data.getSkuList()).ifPresent(skuList -> {
|
|
|
- if (skuList.size() > 0) {
|
|
|
- GoodsDonSku goodsDonSku = skuList.get(0);
|
|
|
- data.setPrice(goodsDonSku.getPrice());
|
|
|
- data.setMonths(goodsDonSku.getMonths());
|
|
|
- }
|
|
|
- });
|
|
|
- OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .eq(OrderDon::getGoodsId, data.getId())
|
|
|
- .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
|
|
|
- .orderByDesc(OrderDon::getId)
|
|
|
- .last("limit 1"));
|
|
|
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
|
|
|
- });
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
- }
|
|
|
+ views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build()));
|
|
|
+ MapBuilder builder = MapUtils.builder().field(GoodsDonSkuFrontView::getGoodsId, views.getId()).field(GoodsDonSkuFrontView::getStatus, true);
|
|
|
|
|
|
- /**
|
|
|
- * 官网首页 平台列表
|
|
|
- */
|
|
|
- @GetMapping("/get/list")
|
|
|
- public Result<List<GoodsFrontListView>> getGoodsList() {
|
|
|
- List<Long> filter_goodsIds = getFilterGoodsIds(false);
|
|
|
- String pcCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getNameLanguagePrefix() + "PC";
|
|
|
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
|
|
|
- pcCacheKey += ":hz-ip";
|
|
|
- }
|
|
|
- Object value = redisService.get(pcCacheKey);
|
|
|
- if (value != null) {
|
|
|
- try {
|
|
|
- List<GoodsFrontListView> list = Jsons.parseList(value, GoodsFrontListView.class);
|
|
|
- if (CollUtil.isNotEmpty(list)) {
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
+ if (views.getType() == 1) {
|
|
|
+ builder.orderBy(GoodsDonSkuFrontView::getSorted).asc();
|
|
|
}
|
|
|
+ views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, builder.build()));
|
|
|
+ views.setSold(getGoodsSold(views.getId(), views.getSold()));
|
|
|
+ redisService.setNx(goodsDetailKey, views, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
|
|
|
+ o = redisService.get(goodsDetailKey);
|
|
|
}
|
|
|
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
|
|
|
- builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
|
|
|
+ Long fUid = StpUserUtil.getUserIdAfterLogin();
|
|
|
+ GoodsFrontListView views = Jsons.parseObject(o, GoodsFrontListView.class);
|
|
|
+ AtomicLong dsUserId = new AtomicLong();
|
|
|
+ AtomicBoolean existsChannel = new AtomicBoolean(true);
|
|
|
+ if (StrUtil.isNotBlank(dsCode)) {
|
|
|
+ UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
|
|
|
+ dsUserId.set(userSharedDto.getSharedId());
|
|
|
}
|
|
|
- List<GoodsFrontListView> list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
|
|
|
- DateTime now = DateTime.now();
|
|
|
- list.forEach(data -> {
|
|
|
- data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build()));
|
|
|
- List<GoodsDonSkuFrontView> skuList = beanSearcher.searchAll(GoodsDonSkuFrontView.class, MapUtils.builder().field(GoodsDonSkuFrontView::getGoodsId, data.getId()).field(GoodsDonSkuFrontView::getStatus, true).orderBy(GoodsDonSkuFrontView::getPrice).asc().build());
|
|
|
- data.setSkuList(skuList);
|
|
|
- data.getSkuList().forEach(sku -> {
|
|
|
- if (sku.getIsDp()) {
|
|
|
- List<GoodsDiscountPlusPurchaseRelationFrontView> dpSkuViews = beanSearcher.searchAll(GoodsDiscountPlusPurchaseRelationFrontView.class, MapUtils.builder().field(GoodsDiscountPlusPurchaseRelationFrontView::getSkuId, sku.getId()).build());
|
|
|
- sku.setDpSkuViews(dpSkuViews);
|
|
|
+ views.setSkuList(views.getSkuList().stream().filter(sku -> {
|
|
|
+ if (StrUtil.isNotBlank(sku.getUserOwns())) {
|
|
|
+ if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
|
|
|
+ Long sharedId = userService.getSharedIdByUserId(fUid);
|
|
|
+ if (sharedId == 0) {
|
|
|
+ existsChannel.set(false);
|
|
|
+ }
|
|
|
+ dsUserId.set(sharedId);
|
|
|
}
|
|
|
- });
|
|
|
- if (!skuList.isEmpty()) {
|
|
|
- data.setTwPrice(skuList.get(0).getTwPrice());
|
|
|
- data.setHkPrice(skuList.get(0).getHkPrice());
|
|
|
- }
|
|
|
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
- data.setSold(sold + data.getVirtualSold());
|
|
|
- OrderCommentFrontView comments = beanSearcher.searchFirst(OrderCommentFrontView.class, MapUtils.builder()
|
|
|
- .field(OrderCommentFrontView::getGoodsId, data.getId())
|
|
|
- .orderBy(OrderCommentFrontView::getCommentTime).desc()
|
|
|
- .orderBy(OrderCommentFrontView::getId).desc()
|
|
|
- .build());
|
|
|
- data.setComments(comments);
|
|
|
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
|
|
|
- });
|
|
|
- redisService.setNx(pcCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * h5 银河首页平台展示
|
|
|
- */
|
|
|
- @GetMapping("/get/homePage")
|
|
|
- public Result<List<GoodsHomePageView>> getGoodsHomePage() {
|
|
|
- List<Long> filter_goodsIds = getFilterGoodsIds(false);
|
|
|
- String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getNameLanguagePrefix() + "H5";
|
|
|
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
|
|
|
- h5CacheKey += ":hz-ip";
|
|
|
- }
|
|
|
- Object value = redisService.get(h5CacheKey);
|
|
|
- if (value != null) {
|
|
|
- try {
|
|
|
- List<GoodsHomePageView> list = Jsons.parseList(value, GoodsHomePageView.class);
|
|
|
- if (CollUtil.isNotEmpty(list)) {
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
|
|
|
+ if (dsUserId.get() == 0 || !sku.getUserOwns().contains(String.valueOf(dsUserId.get()))) {
|
|
|
+ return false;
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
- }
|
|
|
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
|
|
|
- builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
|
|
|
- }
|
|
|
- List<GoodsHomePageView> dataList = beanSearcher.searchAll(GoodsHomePageView.class, builder.build());
|
|
|
- DateTime now = DateTime.now();
|
|
|
- dataList.forEach(data -> {
|
|
|
- Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
- .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
- data.setSold(sold + data.getVirtualSold());
|
|
|
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
|
|
|
- List<GoodsDonSku> skuList = beanSearcher.searchAll(GoodsDonSku.class, MapUtils.builder().field(GoodsDonSku::getGoodsId, data.getId()).field(GoodsDonSku::getStatus, true).orderBy(GoodsDonSku::getPrice).asc().build());
|
|
|
- if (!skuList.isEmpty()) {
|
|
|
- data.setTwPrice(skuList.get(0).getTwPrice());
|
|
|
- data.setHkPrice(skuList.get(0).getHkPrice());
|
|
|
}
|
|
|
- });
|
|
|
- redisService.setNx(h5CacheKey, dataList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(dataList);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取商品详情
|
|
|
- */
|
|
|
- @GetMapping("/get/{id}")
|
|
|
- public Result<GoodsDonViews> getDetail(@PathVariable Long id) {
|
|
|
- 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()));
|
|
|
- MapBuilder builder = MapUtils.builder().field(GoodsDonSku::getGoodsId, views.getId()).field(GoodsDonSku::getStatus, true);
|
|
|
-
|
|
|
- if (views.getType() == 1) {
|
|
|
- builder.orderBy(GoodsDonSku::getSorted).asc();
|
|
|
- }
|
|
|
- views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, builder.build()));
|
|
|
- views.getSkuList().forEach(sku -> {
|
|
|
if (sku.getIsDp()) {
|
|
|
sku.setDpSkuViews(beanSearcher.searchAll(GoodsDiscountPlusPurchaseRelationFrontView.class, MapUtils.builder()
|
|
|
.field(GoodsDiscountPlusPurchaseRelationFrontView::getSkuId, sku.getId())
|
|
|
.build()));
|
|
|
}
|
|
|
- });
|
|
|
+ if (views.getIsSp()) {
|
|
|
+ if (fUid == null) {
|
|
|
+ sku.setSpecificPrice(null);
|
|
|
+ sku.setSpecificGoodsIds(null);
|
|
|
+ }else {
|
|
|
+ //设置特定价格
|
|
|
+ if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
|
|
|
+ sku.setSpecificGoodsIds(null);
|
|
|
+ sku.setSpecificPrice(null);
|
|
|
+ } else {
|
|
|
+ BigDecimal specificPrice = views.getSpecificPrice();
|
|
|
+
|
|
|
+ BigDecimal skuSpecificPrice = sku.getSpecificPrice();
|
|
|
+ Long specificSkuId = sku.getId();
|
|
|
+ if (specificPrice == null) {
|
|
|
+ views.setSpecificPrice(skuSpecificPrice);
|
|
|
+ views.setSpecificSkuId(specificSkuId);
|
|
|
+ } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
|
|
|
+ views.setSpecificPrice(skuSpecificPrice);
|
|
|
+ views.setSpecificSkuId(specificSkuId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(views);
|
|
|
}
|
|
|
|
|
|
@@ -247,27 +212,60 @@ public class GoodsDonController {
|
|
|
* 获取商品推荐平台
|
|
|
*/
|
|
|
@GetMapping("/get/recommend/{id}")
|
|
|
- public Result<List<GoodsRecommendViews>> getRecommendGoodsByGid(@PathVariable Long id) throws Exception {
|
|
|
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getNameLanguagePrefix() + "recommend:" + id;
|
|
|
- Object value = redisService.get(key);
|
|
|
- if (value != null) {
|
|
|
- List<GoodsRecommendViews> goodsRecommendViews = Jsons.parseList(value.toString(), GoodsRecommendViews.class);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
|
|
|
- }
|
|
|
- if (value == null) {
|
|
|
+ public Result<List<GoodsFrontListView>> getRecommendGoodsByGid(@PathVariable Long id, String dsCode) throws Exception {
|
|
|
+ String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "recommend:" + id;
|
|
|
+ Object o = redisService.get(key);
|
|
|
+ Long fUid = StpUserUtil.getUserIdAfterLogin();
|
|
|
+ List<GoodsFrontListView> goodsRecommendViews = null;
|
|
|
+ if (o == null) {
|
|
|
GoodsDon goodsDon = beanSearcher.searchFirst(GoodsDon.class, MapUtils.builder()
|
|
|
- .field(GoodsDon::getId, id)
|
|
|
- .field(GoodsDon::getStatus, true)
|
|
|
+ .field(GoodsDon::getId, id).field(GoodsDon::getStatus, true)
|
|
|
.field(GoodsDon::getDeleted, true)
|
|
|
.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());
|
|
|
+ MapBuilder mapBuilder = MapUtils.builder();
|
|
|
+ mapBuilder.field(GoodsFrontListView::getId, recommend_gidList).op(Operator.InList);
|
|
|
+ goodsRecommendViews = beanSearcher.searchAll(GoodsFrontListView.class, mapBuilder.build());
|
|
|
redisService.setNx(key, Jsons.toJson(goodsRecommendViews), 60 * 15l);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
|
|
|
+ o = redisService.get(key);
|
|
|
+ } else {
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
}
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ if (goodsRecommendViews == null) {
|
|
|
+ goodsRecommendViews = Jsons.parseList(o.toString(), GoodsFrontListView.class);
|
|
|
+ }
|
|
|
+ AtomicLong dsUserId = new AtomicLong();
|
|
|
+ AtomicBoolean existsChannel = new AtomicBoolean(true);
|
|
|
+ if (StrUtil.isNotBlank(dsCode)) {
|
|
|
+ UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
|
|
|
+ dsUserId.set(userSharedDto.getSharedId());
|
|
|
+ }
|
|
|
+ goodsRecommendViews = goodsRecommendViews.stream().filter(data -> {
|
|
|
+ if (data.getIsOwns()) {
|
|
|
+ if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
|
|
|
+ Long sharedId = userService.getSharedIdByUserId(fUid);
|
|
|
+ if (sharedId == 0) {
|
|
|
+ existsChannel.set(false);
|
|
|
+ }
|
|
|
+ dsUserId.set(sharedId);
|
|
|
+ }
|
|
|
+ GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getId(), dsUserId.get());
|
|
|
+ if (minPriceUserOwnsSku == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ data.setPrice(minPriceUserOwnsSku.getPrice());
|
|
|
+ data.setMonths(minPriceUserOwnsSku.getMonths());
|
|
|
+ data.setDays(minPriceUserOwnsSku.getDays());
|
|
|
+ }
|
|
|
+ //销量
|
|
|
+ data.setSold(getGoodsSold(data.getId(), data.getSold()));
|
|
|
+ //设置特定价格
|
|
|
+ setSpecificPrice(data, fUid, dsUserId.get());
|
|
|
+ return true;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -296,30 +294,10 @@ public class GoodsDonController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(search);
|
|
|
}
|
|
|
|
|
|
- public List<Long> getFilterGoodsIds(Boolean isOpen) {
|
|
|
- if (!isOpen) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- //过滤杭州Ai ChatGPT平台
|
|
|
- //获取当前ip地址
|
|
|
- SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
- .eq(SysConfig::getSysKey, Constant.LOCATION_FOR_GOODS_IDS).last("limit 1"));
|
|
|
- List<Long> filter_goodsIds = null;
|
|
|
- if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
|
|
|
- if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("杭州")) {
|
|
|
- try {
|
|
|
- filter_goodsIds = Jsons.parseList(sysConfig.getSysValue(), Long.class);
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return filter_goodsIds;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
- *
|
|
|
* @param goodsId
|
|
|
- * @param type 1、普通,2、注册平台
|
|
|
+ * @param type 1、普通,2、注册平台
|
|
|
* @return
|
|
|
*/
|
|
|
public String getPayMsgTime(Long goodsId, DateTime now, Integer type) {
|
|
|
@@ -332,7 +310,7 @@ public class GoodsDonController {
|
|
|
.orderByDesc(OrderDon::getId)
|
|
|
.last("limit 1"));
|
|
|
if (orderDon == null) {
|
|
|
- notifyMsg.append(I18nMessageUtil.getI18nMsg("order_buy_now_notify"));
|
|
|
+ notifyMsg.append("点击购买立即上车");
|
|
|
return notifyMsg.toString();
|
|
|
}
|
|
|
startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
|
|
|
@@ -341,15 +319,10 @@ public class GoodsDonController {
|
|
|
if (hour == 0) {
|
|
|
long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
|
|
|
if (minute == 0) {
|
|
|
- notifyMsg.append("1");
|
|
|
- notifyMsg.append(I18nMessageUtil.getI18nMsg("minute"));
|
|
|
+ notifyMsg.append("1分钟");
|
|
|
} else {
|
|
|
notifyMsg.append(minute);
|
|
|
- if (minute > 1) {
|
|
|
- notifyMsg.append(I18nMessageUtil.getI18nMsg("minutes"));
|
|
|
- } else {
|
|
|
- notifyMsg.append(I18nMessageUtil.getI18nMsg("minute"));
|
|
|
- }
|
|
|
+ notifyMsg.append("分钟");
|
|
|
}
|
|
|
} else {
|
|
|
if (hour > 3) {
|
|
|
@@ -358,13 +331,234 @@ public class GoodsDonController {
|
|
|
} else {
|
|
|
notifyMsg.append(hour);
|
|
|
}
|
|
|
- if (hour > 1) {
|
|
|
- notifyMsg.append(I18nMessageUtil.getI18nMsg("hours"));
|
|
|
- } else {
|
|
|
- notifyMsg.append(I18nMessageUtil.getI18nMsg("hour"));
|
|
|
- }
|
|
|
+ notifyMsg.append("小时");
|
|
|
}
|
|
|
- notifyMsg.append(I18nMessageUtil.getI18nMsg("order_pre_buy_it"));
|
|
|
+ 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(GoodsFrontListView data, Long fUid, Long dsUserId) {
|
|
|
+ if (fUid != null) {
|
|
|
+ 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 -> {
|
|
|
+ if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置平台 特定价格
|
|
|
+ */
|
|
|
+ public void setGcSpecificPrice(GoodsFrontListCategoryView data, Long fUid, Long dsUserId) {
|
|
|
+ if (fUid != null) {
|
|
|
+ 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 -> {
|
|
|
+ if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据分类获取对应平台
|
|
|
+ */
|
|
|
+ @GetMapping("/get/categoryGoods")
|
|
|
+ public Result<? extends Object> getGoodsByCategory(Long cgy, String dsCode) {
|
|
|
+ Long fUid = StpUserUtil.getUserIdAfterLogin();
|
|
|
+ String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "category:goods";
|
|
|
+ if (cgy != null) {
|
|
|
+ categoryGoodsKey += ":" + cgy;
|
|
|
+ }
|
|
|
+ //List<Long> filter_goodsIds = getFilterGoodsIds();
|
|
|
+ List<Long> filter_goodsIds = null;
|
|
|
+ if (CollUtil.isNotEmpty(filter_goodsIds)) {
|
|
|
+ categoryGoodsKey += ":hz-ip";
|
|
|
+ }
|
|
|
+ Object o = redisService.get(categoryGoodsKey);
|
|
|
+ if (o == null) {
|
|
|
+ DateTime now = DateTime.now();
|
|
|
+ MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
|
|
|
+ if (cgy != null) {
|
|
|
+ String condition = String.format(" and gcr.category = %s", cgy);
|
|
|
+ mapBuilder.put("condition", condition);
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(filter_goodsIds)) {
|
|
|
+ mapBuilder.field(GoodsFrontListCategoryView::getId, filter_goodsIds).op(Operator.NotIn);
|
|
|
+ }
|
|
|
+ List<GoodsFrontListCategoryView> goodsFrontListViews = beanSearcher.searchAll(GoodsFrontListCategoryView.class, mapBuilder.build());
|
|
|
+ goodsFrontListViews.forEach(data -> {
|
|
|
+ data.setSold(getGoodsSold(data.getId(), data.getSold()));;
|
|
|
+ data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
|
|
|
+ });
|
|
|
+ redisService.setNx(categoryGoodsKey, goodsFrontListViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 10 * 60);
|
|
|
+ o = redisService.get(categoryGoodsKey);
|
|
|
+ }
|
|
|
+ List<GoodsFrontListCategoryView> goodsFrontListViews = Jsons.parseList(o, GoodsFrontListCategoryView.class);
|
|
|
+ AtomicLong dsUserId = new AtomicLong();
|
|
|
+ AtomicBoolean existsChannel = new AtomicBoolean(true);
|
|
|
+ if (StrUtil.isNotBlank(dsCode)) {
|
|
|
+ UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
|
|
|
+ dsUserId.set(userSharedDto.getSharedId());
|
|
|
+ }
|
|
|
+ AtomicBoolean filterCourseGoods = new AtomicBoolean(false);
|
|
|
+ //增值服务分类
|
|
|
+ if (fUid != null && cgy != null && (cgy == 3 || cgy == 4)) {
|
|
|
+ //GPT Plus基础2月 课程不展示
|
|
|
+ List<Long> userIdList = userBindRelationService.getRelationUserIdList(fUid, null);
|
|
|
+ Integer orders = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .in(OrderDon::getUserId, userIdList)
|
|
|
+ .eq(OrderDon::getSkuId, 444)
|
|
|
+ .notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
+ if (orders > 0) {
|
|
|
+ filterCourseGoods.set(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ goodsFrontListViews = goodsFrontListViews.stream().filter(data -> {
|
|
|
+ if (data.getIsOwns()) {
|
|
|
+ if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
|
|
|
+ Long sharedId = userService.getSharedIdByUserId(fUid);
|
|
|
+ if (sharedId == 0) {
|
|
|
+ existsChannel.set(false);
|
|
|
+ }
|
|
|
+ dsUserId.set(sharedId);
|
|
|
+ }
|
|
|
+ GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getId(), dsUserId.get());
|
|
|
+ if (minPriceUserOwnsSku == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ data.setPrice(minPriceUserOwnsSku.getPrice());
|
|
|
+ data.setMonths(minPriceUserOwnsSku.getMonths());
|
|
|
+ data.setDays(minPriceUserOwnsSku.getDays());
|
|
|
+ }
|
|
|
+ //课件类型 且过滤
|
|
|
+ if (filterCourseGoods.get() && data.getSpecialType() != null && data.getSpecialType() == GoodsDon.SpecialType.courseware) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ //设置特定价格
|
|
|
+ setGcSpecificPrice(data, fUid, dsUserId.get());
|
|
|
+ return true;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(goodsFrontListViews);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取平台销量
|
|
|
+ * @param goodsId
|
|
|
+ * @param virtualSold
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Integer getGoodsSold(Long goodsId, Integer virtualSold) {
|
|
|
+ Object soldObj = redisService.get(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "sold:" + goodsId);
|
|
|
+ if (soldObj == null) {
|
|
|
+ Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
|
|
|
+ .eq(OrderDon::getGoodsId, goodsId).notIn(OrderDon::getStatus, Constant.noOrderStatus));
|
|
|
+ soldObj = sold + virtualSold;
|
|
|
+ redisService.set(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "sold:" + goodsId, soldObj, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
|
|
|
+ }
|
|
|
+ return Integer.parseInt(soldObj.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+}
|