| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355 |
- package com.cyksj.web.controller.goods;
- import cn.hutool.core.collection.CollUtil;
- import cn.hutool.core.date.DateTime;
- 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.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.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.shop.YhShopGoodsSkuMapper;
- import com.cyksj.mapper.sys.SysConfigMapper;
- import com.cyksj.model.entity.*;
- import com.cyksj.model.request.ClickRecordReq;
- import com.cyksj.model.views.*;
- import com.cyksj.redis.RedisService;
- import com.cyksj.service.goods.GoodsDonFrontService;
- import com.cyksj.service.home.ClickRecordFrontService;
- import com.cyksj.service.shop.YhShopFrontService;
- 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;
- import com.ejlchina.searcher.util.MapBuilder;
- import com.ejlchina.searcher.util.MapUtils;
- import lombok.RequiredArgsConstructor;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import java.math.BigDecimal;
- import java.util.*;
- import java.util.concurrent.ConcurrentHashMap;
- import java.util.concurrent.atomic.AtomicBoolean;
- import java.util.concurrent.atomic.AtomicLong;
- import java.util.stream.Collectors;
- import java.util.stream.Stream;
- /**
- * @author chan
- * @date 2022/9/26 5:33 PM
- */
- @Slf4j
- @RestController
- @RequestMapping("/applets/goods")
- @RequiredArgsConstructor
- public class GoodsDonController {
- private final HttpServletRequest request;
- private final BeanSearcher beanSearcher;
- private final OrderDonMapper orderDonMapper;
- private final RegisterOrderDonMapper registerOrderDonMapper;
- private final GoodsDonSkuMapper goodsDonSkuMapper;
- private final YhShopGoodsSkuMapper yhShopGoodsSkuMapper;
- private final RedisService redisService;
- private final SysConfigMapper sysConfigMapper;
- private final ClickRecordFrontService clickRecordFrontService;
- private final YhShopFrontService yhShopFrontService;
- private final UserService userService;
- private final UserDistributeSharedMapper userDistributeSharedMapper;
- private final GoodsDonFrontService goodsDonFrontService;
- private final UserBindRelationService userBindRelationService;
- private final GiftCardGoodsSkuMapper giftCardGoodsSkuMapper;
- /**
- * 获取平台商品分类
- */
- @GetMapping("/get/category")
- public Result<List<GoodsDonCategoryFrontView>> getCategory(String customId) {
- Long yhsId = null;
- if (StrUtil.isNotBlank(customId)) {
- yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
- }
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "category";
- if (yhsId != null) {
- key += ":yhShop:" + yhsId;
- }
- 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 %s where gcr.category = gc.id) > 0";
- if (yhsId != null) {
- condition = String.format(condition, String.format(" and (select count(*) from yh_shop_goods_sku ys where ys.goods_id = g.id and ys.status is true and ys.deleted is true and g.is_distribute is true and ys.yhs_id = %s) > 0", yhsId));
- } else {
- condition = String.format(condition, StrUtil.EMPTY);
- }
- 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);
- }
- /**
- * 获取商品列表
- */
- @GetMapping("/get")
- public Result<SearchResult<GoodsDon>> get() {
- SearchResult<GoodsDon> search = beanSearcher.search(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap())
- .field(GoodsDon::getStatus, true)
- .field(GoodsDon::getDeleted, true)
- .orderBy(GoodsDon::getSortBy).asc()
- .orderBy(GoodsDon::getId).asc()
- .build()
- );
- search.getDataList().forEach(goods -> {
- GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, goods.getId())
- .eq(GoodsDonSku::getStatus, true)
- .orderByAsc(GoodsDonSku::getPrice)
- .last("limit 1")
- .select(GoodsDonSku::getPrice));
- Optional.ofNullable(goodsDonSku).ifPresent(sku -> {
- goods.setPrice(goodsDonSku.getPrice());
- goods.setSoldNum(getGoodsSold(goods.getId(), goods.getVirtualSold()));
- });
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 推广未登录,虚拟商品列表
- */
- @GetMapping("/get/popularize")
- @Deprecated
- 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).asc()
- .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()));
- data.setSold(getGoodsSold(data.getId(), data.getVirtualSold()));
- 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"));
- StringBuilder notifyMsg = new StringBuilder();
- if (orderDon == null) {
- notifyMsg.append("点击购买立即上车");
- data.setNotifyMsg(notifyMsg.toString());
- return;
- } else {
- Date payTime = orderDon.getPayTime();
- Date startTime = payTime != null ? payTime : orderDon.getCreatedTime();
- long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
- if (hour == 0) {
- long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
- if (minute == 0) {
- notifyMsg.append("1分钟");
- } else {
- notifyMsg.append(minute);
- notifyMsg.append("分钟");
- }
- } else {
- if (hour > 3) {
- int hours = RandomUtil.randomInt(3) + 1;
- notifyMsg.append(hours);
- } else {
- notifyMsg.append(hour);
- }
- notifyMsg.append("小时");
- }
- }
- notifyMsg.append("前有人购买");
- data.setNotifyMsg(notifyMsg.toString());
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 官网首页 平台列表
- */
- @GetMapping("/get/list")
- @Deprecated
- public Result<? extends Object> getGoodsList(String customId) {
- if (StrUtil.isNotBlank(customId)) {
- Result<List<YhShopGoodsFrontView>> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId));
- return shopGoods;
- }
- //List<Long> filter_goodsIds = getFilterGoodsIds();
- List<Long> filter_goodsIds = null;
- String pcCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "PC";
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
- pcCacheKey += ":hz-ip";
- }
- Long fUid = StpUserUtil.getUserIdAfterLogin();
- Object o = redisService.get(pcCacheKey);
- List<GoodsFrontListView> list = null;
- if (o == null) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
- builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
- }
- builder.field(GoodsFrontListView::getType, 1);
- list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
- redisService.setNx(pcCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
- o = redisService.get(pcCacheKey);
- }
- if (list == null) {
- list = Jsons.parseList(o, GoodsFrontListView.class);
- }
- DateTime now = DateTime.now();
- list.forEach(data -> {
- data.setSold(getGoodsSold(data.getId(), data.getSold()));
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
- //设置特定价格
- setSpecificPrice(data, fUid, null);
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(Optional.of(list));
- }
- /**
- * h5 银河首页平台展示
- */
- @GetMapping("/get/homePage")
- @Deprecated
- public Result<? extends Object> getGoodsHomePage(String customId) {
- if (StrUtil.isNotBlank(customId)) {
- Result<List<YhShopGoodsFrontView>> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId));
- return shopGoods;
- }
- //List<Long> filter_goodsIds = getFilterGoodsIds();
- List<Long> filter_goodsIds = null;
- String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "H5";
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
- h5CacheKey += ":hz-ip";
- }
- Long fUid = StpUserUtil.getUserIdAfterLogin();
- Object o = redisService.get(h5CacheKey);
- List<GoodsFrontListView> list = null;
- if (o == null) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
- builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
- }
- list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
- redisService.setNx(h5CacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
- o = redisService.get(h5CacheKey);
- }
- if (list == null) {
- list = Jsons.parseList(o, GoodsFrontListView.class);
- }
- DateTime now = DateTime.now();
- list.forEach(data -> {
- data.setSold(getGoodsSold(data.getId(), data.getSold()));
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
- //设置特定价格
- setSpecificPrice(data, fUid, null);
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(Optional.of(list));
- }
- /**
- * 注册首页平台展示
- */
- @GetMapping("/get/register")
- public Result<List<RegisterGoodsDonView>> getRegisterGoodsDon() {
- String registerCacheKey = RedisService.key.REGISTER_HOME_PAGE_CACHE.getName();
- Object value = redisService.get(registerCacheKey);
- if (value != null) {
- try {
- List<RegisterGoodsDonView> list = Jsons.parseList(value, RegisterGoodsDonView.class);
- if (CollUtil.isNotEmpty(list)) {
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
- }
- } catch (Exception e) {
- }
- }
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- List<RegisterGoodsDonView> dataList = beanSearcher.searchAll(RegisterGoodsDonView.class, builder.build());
- DateTime now = DateTime.now();
- dataList.forEach(data -> {
- Integer sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class)
- .eq(RegisterOrderDon::getGoodsId, data.getId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
- data.setSold(sold + data.getVirtualSold());
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 2, null));
- });
- redisService.setNx(registerCacheKey, dataList, RedisService.key.REGISTER_HOME_PAGE_CACHE.getTimeout());
- return GatewayResponse.SUCCESS.newBuilder().toResult(dataList);
- }
- /**
- * 获取商品详情
- */
- @GetMapping("/get/{id}")
- public Result<? extends Object> getDetail(@PathVariable Long id, String customId, String dsCode) {
- if (StrUtil.isNotBlank(customId) && id != 15) {
- Result<YhShopGoodsFrontView> yhShopGoodsDetail = getGoodsDetailByYhsId(yhShopFrontService.getYhsIdByCustomId(customId), id);
- return yhShopGoodsDetail;
- }
- 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) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- 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);
- if (views.getType() == 1) {
- builder.orderBy(GoodsDonSkuFrontView::getSorted).asc();
- }
- views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, builder.build()));
- views.setSold(getGoodsSold(views.getId(), views.getSold()));
- List<GoodsDonQaFrontView> donQaFrontViews = beanSearcher.searchAll(GoodsDonQaFrontView.class, MapUtils.builder().field(GoodsDonQaFrontView::getGoodsId, id).field(GoodsDonQaFrontView::getType, 1).build());
- views.setQuestions(donQaFrontViews);
- redisService.setNx(goodsDetailKey, views, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
- o = redisService.get(goodsDetailKey);
- }
- 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());
- }
- views.setIsGift(giftCardGoodsSkuMapper.selectCount(Wrappers.lambdaQuery(GiftCardGoodsSku.class)
- .eq(GiftCardGoodsSku::getGcGoodsId, views.getId())
- .eq(GiftCardGoodsSku::getStatus, 1)
- .eq(GiftCardGoodsSku::getDeleted, 1)) > 0);
- 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 (dsUserId.get() == 0 || !sku.getUserOwns().contains(String.valueOf(dsUserId.get()))) {
- return false;
- }
- }
- 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);
- }
- }
- }
- }
- // if (fUid != null && Constant.SPECIAL_PRICE_SKU_IDS.contains(sku.getId())) {
- // UserDistributeShared distributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class)
- // .eq(UserDistributeShared::getUserId, fUid)
- // .last("limit 1"));
- // if (distributeShared != null) {
- // Optional.ofNullable(sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
- // .eq(SysConfig::getSysKey, Constant.MJ_SPECIAL_SKU_PRICE_KEY)
- // .last("limit 1"))).ifPresent(sysConfig -> {
- // if (StrUtil.isNotBlank(sysConfig.getSysValue())) {
- // try {
- // GoodsDonPriceDto goodsDonPriceDto = Jsons.parseObject(sysConfig.getSysValue(), GoodsDonPriceDto.class);
- // sku.setPrice(goodsDonPriceDto.getPrice());
- // } catch (Exception e) {
- // }
- // }
- // });
- // }
- // }
- return true;
- }).collect(Collectors.toList()));
- return GatewayResponse.SUCCESS.newBuilder().toResult(views);
- }
- /**
- * 获取商品推荐平台
- */
- @GetMapping("/get/recommend/{id}")
- public Result<List<GoodsFrontListView>> getRecommendGoodsByGid(@PathVariable Long id, String customId, String dsCode) throws Exception {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "recommend:" + id;
- Long yhsId = null;
- if (StrUtil.isNotBlank(customId)) {
- yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
- key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":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::getDeleted, true)
- .build());
- if (goodsDon != null && StrUtil.isNotEmpty(goodsDon.getRecommendGoods())) {
- List<Long> recommend_gidList = Jsons.parseList(goodsDon.getRecommendGoods(), Long.class);
- MapBuilder mapBuilder = MapUtils.builder();
- if (yhsId != null) {
- mapBuilder.put("condition", String.format(" and g.id in (select distinct goods_id from yh_shop_goods_sku where yhs_id = %s and status is true and deleted is true) and g.is_distribute is true", yhsId));
- }
- mapBuilder.field(GoodsFrontListView::getId, recommend_gidList).op(Operator.InList);
- goodsRecommendViews = beanSearcher.searchAll(GoodsFrontListView.class, mapBuilder.build());
- redisService.setNx(key, Jsons.toJson(goodsRecommendViews), 60 * 15l);
- o = redisService.get(key);
- } else {
- 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);
- }
- /**
- * 获取商品多规格列表
- */
- @GetMapping("/get/sku")
- public Result<List<GoodsDonSkuView>> getGoodsDonSkuView(@RequestParam(value = "skuIds") List<Long> skuIds) {
- if (skuIds.isEmpty()) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- List<GoodsDonSkuView> views = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder()
- .field(GoodsDonSkuView::getSkuId, skuIds).op(Operator.InList)
- .build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(views);
- }
- /**
- * 获取评价列表
- */
- @GetMapping("/get/comments")
- public Result<SearchResult<OrderCommentFrontView>> getComments() {
- SearchResult<OrderCommentFrontView> search = beanSearcher.search(OrderCommentFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
- .orderBy(OrderCommentFrontView::getCommentTime).desc()
- .orderBy(OrderCommentFrontView::getId).desc()
- .build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 获取礼品卡平台性情
- */
- @GetMapping("/get/card/{id}")
- public Result<Map<Integer, List<GiftCardGoodsSkuFrontView>>> getGiftCardDetail(@PathVariable Long id) {
- List<GiftCardGoodsSkuFrontView> giftCardGoodsSkuFrontViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getGoodsId, id).build());
- Map<Integer, List<GiftCardGoodsSkuFrontView>> map = giftCardGoodsSkuFrontViews.stream().collect(Collectors.groupingBy(GiftCardGoodsSkuFrontView::getGcType));
- return GatewayResponse.SUCCESS.newBuilder().toResult(map);
- }
- /**
- * 获取首页配置列表
- */
- @GetMapping("/get/homeManage")
- public Result<Map<String, List<HomeManagementFrontView>>> getHomeManagementFrontPage(String customId, String dsCode) {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "homeManage";
- Long yhsId = null;
- if (StrUtil.isNotBlank(customId)) {
- yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
- key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":homeManage";
- }
- // List<Long> filter_goodsIds = getFilterGoodsIds();
- List<Long> filter_goodsIds = null;
- AtomicBoolean isRemoveRg = new AtomicBoolean(false);
- // if (isHzIp()) {
- // key += ":hz-ip";
- // isRemoveRg.set(true);
- // }
- Long fUid = StpUserUtil.getUserIdAfterLogin();
- Object o = redisService.get(key);
- if (o == null) {
- String condition = "g.deleted is true and g.status is true";
- if (yhsId != null) {
- condition += String.format(" and g.id in (select distinct goods_id from yh_shop_goods_sku where yhs_id = %s and status is true and deleted is true) and g.is_distribute is true", yhsId);
- }
- Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
- final String conditionSql = condition;
- Stream.of(HomeManagementConfig.Type.values())
- .forEach(type -> {
- if (isRemoveRg.get() && type == HomeManagementConfig.Type.rg) {
- return;
- }
- MapBuilder builder = MapUtils.builder()
- .field(HomeManagementFrontView::getType, type.name());
- if (type == HomeManagementConfig.Type.ex || type == HomeManagementConfig.Type.vg) {
- builder.put("condition", conditionSql);
- if (CollUtil.isNotEmpty(filter_goodsIds)) {
- builder.field(HomeManagementFrontView::getGoodsId, filter_goodsIds).op(Operator.NotIn);
- }
- }
- List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
- map.putIfAbsent(type.name(), homeManagementFrontViews);
- });
- redisService.setNx(key, map, 50 * 60l);
- o = redisService.get(key);
- }
- AtomicLong dsUserId = new AtomicLong();
- AtomicBoolean existsChannel = new AtomicBoolean(true);
- if (StrUtil.isNotBlank(dsCode)) {
- UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
- dsUserId.set(userSharedDto.getSharedId());
- }
- Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
- if (map.containsKey(HomeManagementConfig.Type.ex.name()) || map.containsKey(HomeManagementConfig.Type.vg.name())) {
- 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);
- //虚拟平台
- List<HomeManagementFrontView> vgList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.vg.name())), HomeManagementFrontView.class);
- setHomeConfigGoods(map, HomeManagementConfig.Type.vg, vgList, dsUserId, existsChannel, fUid);
- } catch (Exception e) {
- }
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(map);
- }
- /**
- * 首页点击 记录
- */
- @PostMapping("/homePage/click")
- public Result<String> homeManageClick(@RequestBody ClickRecordReq request) {
- Long userId = StpUserUtil.getUserIdAfterLogin();
- clickRecordFrontService.click(userId, request);
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- public List<Long> getFilterGoodsIds() {
- List<Long> filter_goodsIds = null;
- //获取当前ip地址
- if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("杭州")) {
- //过滤杭州Ai ChatGPT平台
- SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
- .eq(SysConfig::getSysKey, Constant.LOCATION_FOR_GOODS_IDS).last("limit 1"));
- if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
- try {
- filter_goodsIds = Jsons.parseList(sysConfig.getSysValue(), Long.class);
- } catch (Exception e) {
- }
- }
- }
- return filter_goodsIds;
- }
- public Boolean isHzIp() {
- if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("无锡")) {
- return true;
- }
- return false;
- }
- /**
- * @param goodsId
- * @param type 1、普通,2、注册平台
- * @param yhsId 店铺id
- * @return
- */
- public String getPayMsgTime(Long goodsId, DateTime now, Integer type, Long yhsId) {
- Date startTime = null;
- StringBuilder notifyMsg = new StringBuilder();
- if (type == 1) {
- OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
- .eq(OrderDon::getGoodsId, goodsId)
- .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
- .eq(yhsId != null, OrderDon::getYhsId, yhsId)
- .orderByDesc(OrderDon::getId)
- .last("limit 1"));
- if (orderDon == null) {
- notifyMsg.append("点击购买立即上车");
- return notifyMsg.toString();
- }
- startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
- } else if (type == 2) {
- RegisterOrderDon orderDon = registerOrderDonMapper.selectOne(Wrappers.lambdaQuery(RegisterOrderDon.class)
- .eq(RegisterOrderDon::getGoodsId, goodsId)
- .notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus).select(RegisterOrderDon::getCreatedTime, RegisterOrderDon::getPayTime, RegisterOrderDon::getId)
- .orderByDesc(RegisterOrderDon::getId)
- .last("limit 1"));
- if (orderDon == null) {
- return null;
- }
- startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
- }
- long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
- if (hour == 0) {
- long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
- if (minute == 0) {
- notifyMsg.append("1分钟");
- } else {
- notifyMsg.append(minute);
- notifyMsg.append("分钟");
- }
- } else {
- if (hour > 3) {
- int hours = RandomUtil.randomInt(3) + 1;
- notifyMsg.append(hours);
- } else {
- notifyMsg.append(hour);
- }
- notifyMsg.append("小时");
- }
- 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);
- }
- });
- }
- }
- }
- }
- /**
- * 获取特定规格
- */
- public List<GoodsDonSku> getSpecificSku(Long goodsId) {
- //查找所有特定规格最小价格 满足条件
- String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + goodsId;
- 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, goodsId)
- .eq(GoodsDonSku::getStatus, true)
- .gt(GoodsDonSku::getSpecificPrice, 0));
- redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
- }
- specificSkus = Optional.ofNullable(specificSkus).orElse(new ArrayList<>());
- return specificSkus;
- }
- /**
- * 设置首页配置 涉及平台特定价格
- */
- public void setHomeManageSpecific(List<HomeManagementFrontView> list, Long fUid, Long dsUserId) {
- DateTime now = DateTime.now();
- list.forEach(data -> {
- if (data.getIsSp() != null && data.getIsSp() && fUid != null) {
- //查找所有特定规格最小价格 满足条件
- List<GoodsDonSku> specificSkus = getSpecificSku(data.getGoodsId());
- 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);
- }
- }
- });
- }
- data.setSold(getGoodsSold(data.getGoodsId(), data.getSold()));
- data.setNotifyMsg(getPayMsgTime(data.getGoodsId(), now, 1, null));
- });
- }
- public void setHomeConfigGoods(Map<String, List<HomeManagementFrontView>> map, HomeManagementConfig.Type type, List<HomeManagementFrontView> list, AtomicLong dsUserId, AtomicBoolean existsChannel, Long fUid) throws Exception {
- //设置特定价格
- if (CollUtil.isNotEmpty(list)) {
- list = list.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.getGoodsId(), dsUserId.get());
- if (minPriceUserOwnsSku == null) {
- return false;
- }
- data.setPrice(minPriceUserOwnsSku.getPrice());
- data.setMonths(minPriceUserOwnsSku.getMonths());
- data.setDays(minPriceUserOwnsSku.getDays());
- }
- return true;
- }).collect(Collectors.toList());
- setHomeManageSpecific(list, fUid, dsUserId.get());
- map.put(type.name(), list);
- }
- }
- /**
- * 店铺平台列表
- */
- @GetMapping("/get/shop/goods/{yhsId}")
- public Result<List<YhShopGoodsFrontView>> getShopGoods(@PathVariable Long yhsId) {
- String yhShopCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId;
- Object value = redisService.get(yhShopCacheKey);
- List<YhShopGoodsFrontView> list = null;
- if (value != null) {
- try {
- list = Jsons.parseList(value, YhShopGoodsFrontView.class);
- } catch (Exception e) {
- }
- }
- if (CollUtil.isEmpty(list)) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- builder.put("condition", String.format("and yhs_id = %s", yhsId));
- list = beanSearcher.searchAll(YhShopGoodsFrontView.class, builder.build());
- redisService.setNx(yhShopCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
- }
- DateTime now = DateTime.now();
- list.forEach(data -> {
- data.setSold(getGoodsSold(data.getId(), data.getSold()));
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
- Optional.ofNullable(yhShopGoodsSkuMapper.selectOne(Wrappers.lambdaQuery(YhShopGoodsSku.class)
- .eq(YhShopGoodsSku::getYhsId, yhsId)
- .eq(YhShopGoodsSku::getGoodsId, data.getId())
- .eq(YhShopGoodsSku::getPrice, data.getPrice())
- .eq(YhShopGoodsSku::getStatus, 1)
- .eq(YhShopGoodsSku::getDeleted, 1)
- .last("limit 1"))).ifPresent(yhSku -> {
- GoodsDonSku sku = goodsDonSkuMapper.selectById(yhSku.getSkuId());
- if (sku != null) {
- data.setMonths(sku.getMonths());
- data.setDays(sku.getDays());
- }
- });
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
- }
- /**
- * 店铺平台详情
- */
- @GetMapping("/get/shop/goods/detail/{yhsId}/{goodsId}")
- public Result<YhShopGoodsFrontView> getGoodsDetailByYhsId(@PathVariable Long yhsId, @PathVariable Long goodsId) {
- String yhShopDetailCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":goodsId:" + goodsId;
- Object value = redisService.get(yhShopDetailCacheKey);
- if (value == null) {
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- String condition = String.format("and yhs_id = %s and ys.goods_id = %s", yhsId, goodsId);
- builder.put("condition", condition);
- YhShopGoodsFrontView goodsDetailView = beanSearcher.searchFirst(YhShopGoodsFrontView.class, builder.build());
- if (goodsDetailView == null) {
- throw BusinessRuntimeException.getInstance("该平台不存在或已下架,请刷新页面");
- }
- goodsDetailView.setSkuList(beanSearcher.searchAll(YhShopGoodsSkuFrontView.class, MapUtils.builder().put("condition", condition).orderBy(YhShopGoodsSkuFrontView::getSorted).asc().build()));
- goodsDetailView.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, goodsDetailView.getId()).build()));
- OrderCommentFrontView comments = beanSearcher.searchFirst(OrderCommentFrontView.class, MapUtils.builder()
- .field(OrderCommentFrontView::getGoodsId, goodsDetailView.getId())
- .orderBy(OrderCommentFrontView::getCommentTime).desc()
- .orderBy(OrderCommentFrontView::getId).desc()
- .build());
- goodsDetailView.setComments(comments);
- redisService.setNx(yhShopDetailCacheKey, goodsDetailView, RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getTimeout() + RandomUtil.randomInt(1000));
- value = redisService.get(yhShopDetailCacheKey);
- }
- YhShopGoodsFrontView goodsDetailView = Jsons.parseObject(value, YhShopGoodsFrontView.class);
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDetailView);
- }
- /**
- * 根据分类获取对应平台
- */
- @GetMapping("/get/categoryGoods")
- public Result<? extends Object> getGoodsByCategory(Long cgy, String customId, String dsCode) {
- if (StrUtil.isNotBlank(customId)) {
- Result<List<YhShopGoodsFrontCategoryView>> shopGoods = getShopCategoryGoods(yhShopFrontService.getYhsIdByCustomId(customId), cgy);
- return shopGoods;
- }
- 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, null));
- });
- 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);
- }
- @GetMapping("/get/shop/categoryGoods/{yhsId}")
- public Result<List<YhShopGoodsFrontCategoryView>> getShopCategoryGoods(@PathVariable Long yhsId, Long category) {
- String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":category";
- if (category != null) {
- categoryGoodsKey += ":" + category;
- }
- Object value = redisService.get(categoryGoodsKey);
- if (value == null) {
- DateTime now = DateTime.now();
- MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
- builder.put("yhsId", String.format(" and yhs_id = %s", yhsId));
- String condition = StrUtil.EMPTY;
- if (category != null) {
- condition += String.format(" and gcr.category = %s", category);
- }
- builder.put("condition", condition);
- List<YhShopGoodsFrontCategoryView> list = beanSearcher.searchAll(YhShopGoodsFrontCategoryView.class, builder.build());
- list.forEach(data->{
- data.setSold(getGoodsSold(data.getId(), data.getSold()));
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
- //重新设置最低价格规格
- YhShopGoodsSku sku = yhShopGoodsSkuMapper.selectMinPriceSkuByYhsId(yhsId, data.getId());
- data.setPrice(sku.getPrice());
- data.setSkuId(sku.getSkuId());
- });
- redisService.setNx(categoryGoodsKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 5 * 60);
- value = redisService.get(categoryGoodsKey);
- }
- List<YhShopGoodsFrontCategoryView> list = Jsons.parseList(value, YhShopGoodsFrontCategoryView.class);
- list.forEach(data->{
- Optional.ofNullable(yhShopGoodsSkuMapper.selectOne(Wrappers.lambdaQuery(YhShopGoodsSku.class)
- .eq(YhShopGoodsSku::getYhsId, yhsId)
- .eq(YhShopGoodsSku::getGoodsId, data.getId())
- .eq(YhShopGoodsSku::getPrice, data.getPrice())
- .eq(YhShopGoodsSku::getStatus, 1)
- .eq(YhShopGoodsSku::getDeleted, 1)
- .last("limit 1"))).ifPresent(yhSku -> {
- GoodsDonSku sku = goodsDonSkuMapper.selectById(yhSku.getSkuId());
- if (sku != null) {
- data.setMonths(sku.getMonths());
- data.setDays(sku.getDays());
- }
- });
- });
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
- }
- /**
- * 获取设备活动详情
- */
- @GetMapping("/get/equipment/activity")
- public Result<EquipmentActivityReduce> getEpActivity() {
- DateTime now = DateTime.now();
- EquipmentActivityReduce equipmentActivityReduce = beanSearcher.searchFirst(EquipmentActivityReduce.class, MapUtils.builder()
- .field(EquipmentActivityReduce::getSt, now).op(Operator.LessEqual)
- .field(EquipmentActivityReduce::getEt, now).op(Operator.GreaterThan)
- .field(EquipmentActivityReduce::getDeleted, 1)
- .onlySelect(EquipmentActivityReduce::getF, EquipmentActivityReduce::getQ, EquipmentActivityReduce::getTq, EquipmentActivityReduce::getSt, EquipmentActivityReduce::getEt)
- .build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(equipmentActivityReduce);
- }
- /**
- * 获取租赁商品列表
- */
- @GetMapping("/get/deposit")
- public Result<? extends Object> getDepositGoods() {
- String depositGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "deposit";
- Object o = redisService.get(depositGoodsKey);
- if (o == null) {
- List<GoodsDon> depositList = beanSearcher.searchAll(GoodsDon.class, MapUtils.builder()
- .field(GoodsDon::getType, 4)
- .field(GoodsDon::getStatus, true)
- .field(GoodsDon::getDeleted, true)
- .onlySelect(GoodsDon::getId, GoodsDon::getTitle, GoodsDon::getLogo)
- .build());
- if (CollUtil.isEmpty(depositList)) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- redisService.setNx(depositGoodsKey, depositList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
- o = redisService.get(depositGoodsKey);
- }
- List<GoodsDon> depositList = Jsons.parseList(o, GoodsDon.class);
- return GatewayResponse.SUCCESS.newBuilder().toResult(depositList);
- }
- /**
- * 获取pc广告配置
- */
- @GetMapping("/get/pc/homeManage")
- public Result<Map<String, List<HomeManagementFrontView>>> getPcHomeManagementFrontPage() {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "pc:homeManage";
- //移除奈飞客厅 临时
- Long filterConfigId = null;
- // if (isHzIp()) {
- // key += ":hz_ip";
- // filterConfigId = 55l;
- // }
- Object o = redisService.get(key);
- if (o == null) {
- MapBuilder builder = MapUtils.builder()
- .field(HomeManagementFrontView::getAdType, List.of(HomeManagementConfig.AdType.pc.name(), HomeManagementConfig.AdType.pcSec.name(), HomeManagementConfig.AdType.pcDis.name())).op(Operator.InList);
- if (filterConfigId != null) {
- builder.field(HomeManagementFrontView::getHomeManageConfigId, filterConfigId).op(Operator.NotEqual);
- }
- List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
- Map<HomeManagementConfig.AdType, List<HomeManagementFrontView>> map = homeManagementFrontViews.stream().collect(Collectors.groupingBy(HomeManagementFrontView::getAdType));
- redisService.setNx(key, map, 50 * 60l);
- o = redisService.get(key);
- }
- Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
- return GatewayResponse.SUCCESS.newBuilder().toResult(map);
- }
- /**
- * 获取pc实物配置
- */
- @GetMapping("/get/pc/realGoodsConfig")
- public Result<? extends Object> getPcRealGoodsConfig() throws Exception {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "pc:realHomePage";
- Object o = redisService.get(key);
- List<HomeManagementFrontView> list = null;
- if (o == null) {
- list = goodsDonFrontService.getRealGoodsConfig();
- redisService.setNx(key, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 300);
- }
- if (list == null && o != null) {
- list = Jsons.parseList(o, HomeManagementFrontView.class);
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(list);
- }
- /**
- * 百亿补贴
- * 补贴规格列表
- */
- @GetMapping("/get/subsidy")
- public Result<List<GoodsDonSkuSubsidyFrontView>> getSubsidyGoods() {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy";
- Object o = redisService.get(key);
- if (o == null) {
- List<GoodsDonSkuSubsidyFrontView> subsidyList = beanSearcher.searchAll(GoodsDonSkuSubsidyFrontView.class, MapUtils.builder().build());
- subsidyList.forEach(e -> {
- Optional.ofNullable(beanSearcher.searchFirst(GoodsDonSkuSubsidyDetailView.class, MapUtils.builder().field(GoodsDonSkuSubsidyDetailView::getGoodsId, e.getId()).field(GoodsDonSkuSubsidyDetailView::getPrice, e.getPrice()).build())).ifPresent(sku -> {
- e.setOriPrice(sku.getOriPrice());
- e.setMonths(sku.getMonths());
- e.setDays(sku.getDays());
- e.setSkuId(sku.getId());
- e.setPicture(sku.getSubsidyPicture());
- });
- });
- redisService.setNx(key, subsidyList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
- o = redisService.get(key);
- }
- List<GoodsDonSkuSubsidyFrontView> subsidyList = Jsons.parseList(o, GoodsDonSkuSubsidyFrontView.class);
- if (CollUtil.isEmpty(subsidyList)) {
- return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyList);
- }
- Long userId = StpUserUtil.getUserIdAfterLogin();
- if (userId != null) {
- List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
- //过滤用户已经购买过平台
- List<Long> goodsIds = orderDonMapper.getPayGoodsIds(relationUserIdList);
- if (CollUtil.isNotEmpty(goodsIds)) {
- subsidyList = subsidyList.stream().filter(data -> !goodsIds.contains(data.getId())).collect(Collectors.toList());
- }
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyList);
- }
- /**
- * 百亿补贴规格详情
- */
- @GetMapping("/get/subsidy/detail/{id}")
- public Result<GoodsDonSubsidyDetailView> getSubsidyDetailById(@PathVariable Long id) throws Exception {
- String goodsDetailKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy:detail:" + id;
- Object o = redisService.get(goodsDetailKey);
- GoodsDonSubsidyDetailView subsidyDetail = null;
- if (o == null) {
- subsidyDetail = beanSearcher.searchFirst(GoodsDonSubsidyDetailView.class, MapUtils.builder().field(GoodsDonSubsidyDetailView::getId, id).build());
- if (subsidyDetail == null) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- subsidyDetail.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, subsidyDetail.getId()).build()));
- MapBuilder builder = MapUtils.builder().field(GoodsDonSkuSubsidyDetailView::getGoodsId, subsidyDetail.getId());
- subsidyDetail.setSkuList(beanSearcher.searchAll(GoodsDonSkuSubsidyDetailView.class, builder.build()));
- subsidyDetail.setSold(getGoodsSold(subsidyDetail.getId(), subsidyDetail.getSold()));
- redisService.setNx(goodsDetailKey, Jsons.toJson(subsidyDetail), RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
- }
- if (subsidyDetail == null) {
- o = redisService.get(goodsDetailKey);
- subsidyDetail = Jsons.parseObject(o.toString(), GoodsDonSubsidyDetailView.class);
- }
- return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyDetail);
- }
- /**
- * 可选百亿补贴规格列表
- */
- @GetMapping("/get/available/subsidy/sku/{goodsId}")
- public Result<List<GoodsDonSkuSubsidyAvailableView>> getAvailableSubsidySku(@PathVariable Long goodsId) {
- String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy:" + goodsId;
- Object o = redisService.get(key);
- if (o == null) {
- List<GoodsDonSkuSubsidyAvailableView> goodsDonSkuSubsidyAvailableViews = beanSearcher.searchAll(GoodsDonSkuSubsidyAvailableView.class, MapUtils.builder().put("gid", String.format(" and goods_id = %s", goodsId)).build());
- if (CollUtil.isEmpty(goodsDonSkuSubsidyAvailableViews)) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- redisService.set(key, goodsDonSkuSubsidyAvailableViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + RandomUtil.randomInt(10000));
- o = redisService.get(key);
- }
- List<GoodsDonSkuSubsidyAvailableView> goodsDonSkuSubsidyAvailableViews = Jsons.parseList(o, GoodsDonSkuSubsidyAvailableView.class);
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonSkuSubsidyAvailableViews);
- }
- /**
- * 获取用户店铺首页配置列表
- */
- @GetMapping("/get/shop/homeManage")
- public Result<Map<String, List<HomeManagementFrontView>>> getShopHomeManageConfig(String customId) {
- //是否同意展示对应首页广告位
- String key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + customId + ":homeManage";
- Object o = redisService.get(key);
- if (o == null) {
- MapBuilder builder = MapUtils.builder()
- .field(HomeManagementFrontView::getType, HomeManagementConfig.Type.ad.name())
- .field(HomeManagementFrontView::getIsShop, 1);
- List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
- if (homeManagementFrontViews == null) {
- return GatewayResponse.SUCCESS.newBuilder().toResult();
- }
- Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
- map.putIfAbsent(HomeManagementConfig.Type.ad.name(), homeManagementFrontViews);
- redisService.setNx(key, map, 50 * 60l);
- o = redisService.get(key);
- }
- Map map = Jsons.parseObject(o, Map.class);
- return GatewayResponse.SUCCESS.newBuilder().toResult(map);
- }
- /**
- * 获取套餐列表
- */
- @GetMapping("/get/upgradePackage")
- public Result<SearchResult<UpgradePackageView>> list(Long skuId) {
- long userId = StpUserUtil.getLoginIdAsLong();
- log.info("userId:{}获取套餐列表", userId);
- Map<String, Object> build = MapUtils.flatBuilder(request.getParameterMap()).build();
- if (skuId != null) {
- build.put("sku", String.format(" and JSON_CONTAINS(up.sku_ids,'\"%s\"')", skuId));
- }
- SearchResult<UpgradePackageView> search = beanSearcher.search(UpgradePackageView.class, build);
- return GatewayResponse.SUCCESS.newBuilder().toResult(search);
- }
- /**
- * 获取平台销量
- * @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());
- }
- }
|