| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680 |
- 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.coupon.CouponUserMapper;
- 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.translations.BackInfoTranslationsFrontService;
- 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 CouponUserMapper couponUserMapper;
- private final GoodsDonFrontService goodsDonFrontService;
- private final UserBindRelationService userBindRelationService;
- private final GiftCardGoodsSkuMapper giftCardGoodsSkuMapper;
- private final BackInfoTranslationsFrontService backInfoTranslationsFrontService;
- /**
- * 获取平台商品分类
- */
- @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;
- }
- String lang = request.getHeader("lang");
- AtomicBoolean language = new AtomicBoolean(false);
- if (lang != null && !StrUtil.equals(UserPageLanguage.Language.zh_CN.name(), lang)) {
- key += ":" + lang;
- language.set(true);
- }
- 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());
- //多语言
- if (language.get()) {
- backInfoTranslationsFrontService.setListCategoryNameLanguage(list, lang);
- }
- redisService.setNx(key, list, 30 * 60l);
- o = redisService.get(key);
- }
- List<Long> gptBuyGids = getGptMirrorGiveawayBuyGids();
- list = Jsons.parseList(o, GoodsDonCategoryFrontView.class);
- for (GoodsDonCategoryFrontView data : list) {
- List<GoodsDonCategoryGoodsView> goodsDonCategoryGoodsViews = beanSearcher.searchAll(GoodsDonCategoryGoodsView.class, MapUtils.builder().field(GoodsDonCategoryGoodsView::getCategory, data.getId()).field(GoodsDonCategoryGoodsView::getStatus, 1).onlySelect(GoodsDonCategoryGoodsView::getGoodsId).build());
- List<Long> collect = goodsDonCategoryGoodsViews.stream().map(GoodsDonCategoryGoodsView::getGoodsId).distinct().collect(Collectors.toList());
- if (CollUtil.isNotEmpty(gptBuyGids) && gptBuyGids.containsAll(collect)) {
- data.setIsGptGift(true);
- }
- }
- 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, BigDecimal discount) {
- 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;
- String lang = request.getHeader("lang");
- AtomicBoolean language = new AtomicBoolean(false);
- if (lang != null && !StrUtil.equals(UserPageLanguage.Language.zh_CN.name(), lang)) {
- goodsDetailKey += ":" + lang;
- language.set(true);
- }
- //存在过滤平台 商品详情不返回
- 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()));
- //多语言
- if (language.get()) {
- backInfoTranslationsFrontService.setGoodsDetailLanguage(views, lang);
- }
- List<Long> gptBuyGids = getGptMirrorGiveawayBuyGids();
- if (CollUtil.isNotEmpty(gptBuyGids) && gptBuyGids.contains(views.getId())) {
- views.setIsGptGift(true);
- }
- 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 (language.get()) {
- for (GoodsDiscountPlusPurchaseRelationFrontView dpSkuView : sku.getDpSkuViews()) {
- String languageGoodsTitle = backInfoTranslationsFrontService.getGoodsTitleLanguage(dpSkuView.getDisGid(), lang);
- if (StrUtil.isNotBlank(languageGoodsTitle)) {
- dpSkuView.setTitle(languageGoodsTitle);
- }
- String languageSpecVal = backInfoTranslationsFrontService.getLanguageSpecVal(dpSkuView.getDisSid(), lang);
- if (StrUtil.isNotBlank(languageSpecVal)) {
- dpSkuView.setSpecVal(languageSpecVal);
- }
- }
- }
- }
- 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) {
- // }
- // }
- // });
- // }
- // }
- //设置规格优惠后的价格
- sku.setChannelDiscount(discount);
- setUserCouponSkuMoney(fUid, sku);
- 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, BigDecimal discount) {
- 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);
- // }
- String lang = request.getHeader("lang");
- AtomicBoolean language = new AtomicBoolean(false);
- if (lang != null && !StrUtil.equals(UserPageLanguage.Language.zh_CN.name(), lang)) {
- key += ":" + lang;
- language.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());
- //实物推荐多语言
- if (language.get() && type == HomeManagementConfig.Type.rg) {
- backInfoTranslationsFrontService.getHomeConfigRealGoodsLanguage(homeManagementFrontViews, lang);
- }
- 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, discount);
- //虚拟平台
- List<HomeManagementFrontView> vgList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.vg.name())), HomeManagementFrontView.class);
- setHomeConfigGoods(map, HomeManagementConfig.Type.vg, vgList, dsUserId, existsChannel, fUid, discount);
- } 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, BigDecimal discount) {
- DateTime now = DateTime.now();
- String lang = request.getHeader("lang");
- 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));
- //设置用户存在优惠券的优惠商品价格
- data.setChannelDiscount(discount);
- setHomeManageUserCouponGoodsMoney(fUid, data);
- });
- }
- public void setHomeConfigGoods(Map<String, List<HomeManagementFrontView>> map, HomeManagementConfig.Type type, List<HomeManagementFrontView> list, AtomicLong dsUserId, AtomicBoolean existsChannel, Long fUid, BigDecimal discount) throws Exception {
- //设置特定价格
- List<Long> gptBuyGids = getGptMirrorGiveawayBuyGids();
- if (CollUtil.isNotEmpty(list)) {
- list = list.stream().filter(data -> {
- if (CollUtil.isNotEmpty(gptBuyGids) && gptBuyGids.contains(data.getGoodsId())) {
- data.setIsGptGift(true);
- }
- 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());
- }
- //未登录
- if (fUid == null) {
- //推荐优惠券商品最低折扣
- setHomeConfigGoodsCouponMoney(data);
- }
- return true;
- }).collect(Collectors.toList());
- setHomeManageSpecific(list, fUid, dsUserId.get(), discount);
- 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_SHOP.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, BigDecimal discount) {
- 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";
- }
- String lang = request.getHeader("lang");
- AtomicBoolean language = new AtomicBoolean(false);
- if (lang != null && UserPageLanguage.Language.en_US.name().equals(lang)) {
- categoryGoodsKey += ":" + lang;
- language.set(true);
- }
- 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());
- List<Long> gptBuyGids = getGptMirrorGiveawayBuyGids();
- goodsFrontListViews.forEach(data -> {
- data.setSold(getGoodsSold(data.getId(), data.getSold()));
- data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
- if (CollUtil.isNotEmpty(gptBuyGids) && gptBuyGids.contains(data.getId())) {
- data.setIsGptGift(true);
- }
- if (language.get()) {
- //多语言
- backInfoTranslationsFrontService.setCategoryGoodsLanguage(data, lang);
- }
- });
- 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());
- //设置用户存在优惠券的优惠商品价格
- data.setChannelDiscount(discount);
- //商品优惠折扣
- setUserCouponGoodsMoney(fUid, data);
- //未登录
- if (fUid == null) {
- //推荐优惠券商品最低折扣
- setGoodsCouponMoney(data);
- }
- 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.pcBanner.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);
- }
- /**
- * 获取所有平台列表
- */
- @GetMapping("/get/goods")
- public Result<List<GoodsDon>> getAllGoodsList() {
- List<GoodsDon> goodsDons = beanSearcher.searchAll(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap()).field(GoodsDon::getStatus, 1)
- .onlySelect(GoodsDon::getId, GoodsDon::getTitle)
- .build());
- return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDons);
- }
- /**
- * 获取平台销量
- * @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());
- }
- /**
- * 设置平台优惠价格
- */
- private void setUserCouponGoodsMoney(Long userId, GoodsFrontListCategoryView data) {
- //登录后
- if (userId != null) {
- //特定价格
- BigDecimal specificPrice = data.getSpecificPrice();
- //渠道折扣
- BigDecimal channelDiscount = data.getChannelDiscount();
- //支付来源
- Integer source = 0;
- BigDecimal presentCouponMoney = null;
- //寻找对应最低规格的优惠券
- Coupon coupon = couponUserMapper.selectUserCouponByGidAndPrice(userId, data.getId(), data.getPrice());
- if (coupon != null) {
- source = 1;
- data.setDiscount(coupon.getDiscount());
- data.setReduceMoney(coupon.getReduceMoney());
- data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney()));
- data.setValidEndTime(coupon.getValidEndTime());
- data.setCouponId(coupon.getId());
- presentCouponMoney = data.getDiscountPrice();
- }
- if (channelDiscount != null) {
- BigDecimal channelCouponMoney = data.getPrice().multiply(channelDiscount);
- if (presentCouponMoney == null) {
- presentCouponMoney = channelCouponMoney;
- }
- if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) {
- source = 2;
- presentCouponMoney = channelCouponMoney;
- data.setDiscount(channelDiscount);
- data.setReduceMoney(null);
- data.setDiscountPrice(channelCouponMoney);
- data.setValidEndTime(null);
- data.setCouponId(null);
- }
- }
- if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) {
- if (presentCouponMoney == null) {
- presentCouponMoney = specificPrice;
- }
- if (specificPrice.compareTo(presentCouponMoney) <= 0) {
- source = 3;
- data.setDiscount(null);
- data.setReduceMoney(null);
- data.setDiscountPrice(specificPrice);
- data.setValidEndTime(null);
- data.setCouponId(null);
- }
- }
- data.setSource(source);
- }
- }
- /**
- * 设置平台规格优惠价格
- */
- private void setUserCouponSkuMoney(Long userId, GoodsDonSkuFrontView sku) {
- //登录后
- if (userId != null) {
- //特定价格
- BigDecimal specificPrice = sku.getSpecificPrice();
- //渠道折扣
- BigDecimal channelDiscount = sku.getChannelDiscount();
- //支付来源
- Integer source = 0;
- BigDecimal presentCouponMoney = null;
- //寻找对应最低规格的优惠券
- Coupon coupon = couponUserMapper.selectUserCouponBySkuId(userId, sku.getId());
- if (coupon != null) {
- source = 1;
- sku.setDiscount(coupon.getDiscount());
- sku.setReduceMoney(coupon.getReduceMoney());
- sku.setDiscountPrice(sku.getPrice().subtract(coupon.getCouponMoney()));
- sku.setValidEndTime(coupon.getValidEndTime());
- sku.setCouponId(coupon.getId());
- presentCouponMoney = sku.getDiscountPrice();
- }
- if (channelDiscount != null) {
- BigDecimal channelCouponMoney = sku.getPrice().multiply(channelDiscount);
- if (presentCouponMoney == null) {
- presentCouponMoney = channelCouponMoney;
- }
- if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) {
- source = 2;
- presentCouponMoney = channelCouponMoney;
- sku.setDiscount(channelDiscount);
- sku.setReduceMoney(null);
- sku.setDiscountPrice(channelCouponMoney);
- sku.setValidEndTime(null);
- sku.setCouponId(null);
- }
- }
- if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) {
- if (presentCouponMoney == null) {
- presentCouponMoney = specificPrice;
- }
- if (specificPrice.compareTo(presentCouponMoney) <= 0) {
- source = 3;
- sku.setDiscount(null);
- sku.setReduceMoney(null);
- sku.setDiscountPrice(specificPrice);
- sku.setValidEndTime(null);
- sku.setCouponId(null);
- }
- }
- sku.setSource(source);
- }
- }
- /**
- * 设置推荐平台优惠价格
- */
- private void setHomeManageUserCouponGoodsMoney(Long userId, HomeManagementFrontView data) {
- //登录后
- if (userId != null) {
- //特定价格
- BigDecimal specificPrice = data.getSpecificPrice();
- //渠道折扣
- BigDecimal channelDiscount = data.getChannelDiscount();
- //支付来源
- Integer source = 0;
- BigDecimal presentCouponMoney = null;
- //寻找对应最低规格的优惠券
- Coupon coupon = couponUserMapper.selectUserCouponByGidAndPrice(userId, data.getGoodsId(), data.getPrice());
- if (coupon != null) {
- source = 1;
- data.setDiscount(coupon.getDiscount());
- data.setReduceMoney(coupon.getReduceMoney());
- data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney()));
- data.setValidEndTime(coupon.getValidEndTime());
- data.setCouponId(coupon.getId());
- presentCouponMoney = data.getDiscountPrice();
- }
- if (channelDiscount != null) {
- BigDecimal channelCouponMoney = data.getPrice().multiply(channelDiscount);
- if (presentCouponMoney == null) {
- presentCouponMoney = channelCouponMoney;
- }
- if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) {
- source = 2;
- presentCouponMoney = channelCouponMoney;
- data.setDiscount(channelDiscount);
- data.setReduceMoney(null);
- data.setDiscountPrice(channelCouponMoney);
- data.setValidEndTime(null);
- data.setCouponId(null);
- }
- }
- if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) {
- if (presentCouponMoney == null) {
- presentCouponMoney = specificPrice;
- }
- if (specificPrice.compareTo(presentCouponMoney) <= 0) {
- source = 3;
- data.setDiscount(null);
- data.setReduceMoney(null);
- data.setDiscountPrice(specificPrice);
- data.setValidEndTime(null);
- data.setCouponId(null);
- }
- }
- data.setSource(source);
- }
- }
- /**
- * 获取gpt镜像天卡活动参与平台ids
- * @return
- */
- private List<Long> getGptMirrorGiveawayBuyGids() {
- GptMirrorDayCardGiveawayActivity gptMirrorDayCardGiveawayActivity = beanSearcher.searchFirst(GptMirrorDayCardGiveawayActivity.class, MapUtils.builder().build());
- if (gptMirrorDayCardGiveawayActivity != null) {
- String buyGoodsIds = gptMirrorDayCardGiveawayActivity.getBuyGoodsIds();
- try {
- return Jsons.parseList(buyGoodsIds, Long.class);
- } catch (Exception e) {
- }
- }
- return null;
- }
- /**
- * 未登录 分类下平台推荐优惠券
- */
- private void setGoodsCouponMoney(GoodsFrontListCategoryView data) {
- //寻找对应最低规格的推荐优惠券
- Coupon coupon = couponUserMapper.selectNoLoginRecommendCouponReduce(data.getId(), data.getPrice());
- if (coupon != null) {
- data.setDiscount(coupon.getDiscount());
- data.setReduceMoney(coupon.getReduceMoney());
- data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney()));
- data.setValidEndTime(coupon.getValidEndTime());
- data.setCouponId(coupon.getId());
- data.setSource(1);
- }
- }
- /**
- * 未登录 首页推荐推荐优惠券
- */
- private void setHomeConfigGoodsCouponMoney(HomeManagementFrontView data) {
- //寻找对应最低规格的推荐优惠券
- Coupon coupon = couponUserMapper.selectNoLoginRecommendCouponReduce(data.getGoodsId(), data.getPrice());
- if (coupon != null) {
- data.setDiscount(coupon.getDiscount());
- data.setReduceMoney(coupon.getReduceMoney());
- data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney()));
- data.setValidEndTime(coupon.getValidEndTime());
- data.setCouponId(coupon.getId());
- data.setSource(1);
- }
- }
- }
|