| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543 |
- 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.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;
- /**
- * 获取平台商品分类
- */
- @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, 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;
- //存在过滤平台 商品详情不返回
- 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) {
- // }
- // }
- // });
- // }
- // }
- //设置规格优惠后的价格
- 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);
- // }
- 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, 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();
- 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 {
- //设置特定价格
- 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(), 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.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";
- }
- 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());
- //设置用户存在优惠券的优惠商品价格
- data.setChannelDiscount(discount);
- setUserCouponGoodsMoney(fUid, 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.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);
- }
- }
- }
|