GoodsDonController.java 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327
  1. package com.cyksj.web.controller.goods;
  2. import cn.hutool.core.collection.CollUtil;
  3. import cn.hutool.core.date.DateTime;
  4. import cn.hutool.core.date.DateUnit;
  5. import cn.hutool.core.date.DateUtil;
  6. import cn.hutool.core.util.RandomUtil;
  7. import cn.hutool.core.util.StrUtil;
  8. import cn.hutool.extra.servlet.ServletUtil;
  9. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  10. import com.cyksj.common.constant.Constant;
  11. import com.cyksj.common.exception.BusinessRuntimeException;
  12. import com.cyksj.common.util.Jsons;
  13. import com.cyksj.common.util.StringUtil;
  14. import com.cyksj.dto.Result;
  15. import com.cyksj.dto.UserSharedDto;
  16. import com.cyksj.enums.GatewayResponse;
  17. import com.cyksj.mapper.GiftCardGoodsSkuMapper;
  18. import com.cyksj.mapper.GoodsDonSkuMapper;
  19. import com.cyksj.mapper.OrderDonMapper;
  20. import com.cyksj.mapper.RegisterOrderDonMapper;
  21. import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
  22. import com.cyksj.mapper.shop.YhShopGoodsSkuMapper;
  23. import com.cyksj.mapper.sys.SysConfigMapper;
  24. import com.cyksj.model.entity.*;
  25. import com.cyksj.model.request.ClickRecordReq;
  26. import com.cyksj.model.views.*;
  27. import com.cyksj.redis.RedisService;
  28. import com.cyksj.service.goods.GoodsDonFrontService;
  29. import com.cyksj.service.home.ClickRecordFrontService;
  30. import com.cyksj.service.shop.YhShopFrontService;
  31. import com.cyksj.service.user.UserBindRelationService;
  32. import com.cyksj.service.user.UserService;
  33. import com.cyksj.web.util.StpUserUtil;
  34. import com.ejlchina.searcher.BeanSearcher;
  35. import com.ejlchina.searcher.SearchResult;
  36. import com.ejlchina.searcher.param.Operator;
  37. import com.ejlchina.searcher.util.MapBuilder;
  38. import com.ejlchina.searcher.util.MapUtils;
  39. import lombok.RequiredArgsConstructor;
  40. import lombok.extern.slf4j.Slf4j;
  41. import org.springframework.web.bind.annotation.*;
  42. import javax.servlet.http.HttpServletRequest;
  43. import java.math.BigDecimal;
  44. import java.util.*;
  45. import java.util.concurrent.ConcurrentHashMap;
  46. import java.util.concurrent.atomic.AtomicBoolean;
  47. import java.util.concurrent.atomic.AtomicLong;
  48. import java.util.stream.Collectors;
  49. import java.util.stream.Stream;
  50. /**
  51. * @author chan
  52. * @date 2022/9/26 5:33 PM
  53. */
  54. @Slf4j
  55. @RestController
  56. @RequestMapping("/applets/goods")
  57. @RequiredArgsConstructor
  58. public class GoodsDonController {
  59. private final HttpServletRequest request;
  60. private final BeanSearcher beanSearcher;
  61. private final OrderDonMapper orderDonMapper;
  62. private final RegisterOrderDonMapper registerOrderDonMapper;
  63. private final GoodsDonSkuMapper goodsDonSkuMapper;
  64. private final YhShopGoodsSkuMapper yhShopGoodsSkuMapper;
  65. private final RedisService redisService;
  66. private final SysConfigMapper sysConfigMapper;
  67. private final ClickRecordFrontService clickRecordFrontService;
  68. private final YhShopFrontService yhShopFrontService;
  69. private final UserService userService;
  70. private final UserDistributeSharedMapper userDistributeSharedMapper;
  71. private final GoodsDonFrontService goodsDonFrontService;
  72. private final UserBindRelationService userBindRelationService;
  73. private final GiftCardGoodsSkuMapper giftCardGoodsSkuMapper;
  74. /**
  75. * 获取平台商品分类
  76. */
  77. @GetMapping("/get/category")
  78. public Result<List<GoodsDonCategoryFrontView>> getCategory(String customId) {
  79. Long yhsId = null;
  80. if (StrUtil.isNotBlank(customId)) {
  81. yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  82. }
  83. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "category";
  84. if (yhsId != null) {
  85. key += ":yhShop:" + yhsId;
  86. }
  87. Object o = redisService.get(key);
  88. List<GoodsDonCategoryFrontView> list;
  89. MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
  90. 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";
  91. if (yhsId != null) {
  92. 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));
  93. } else {
  94. condition = String.format(condition, StrUtil.EMPTY);
  95. }
  96. mapBuilder.put("condition", condition);
  97. if (o == null) {
  98. list = beanSearcher.searchAll(GoodsDonCategoryFrontView.class, mapBuilder
  99. .build());
  100. redisService.setNx(key, list, 30 * 60l);
  101. o = redisService.get(key);
  102. }
  103. list = Jsons.parseList(o, GoodsDonCategoryFrontView.class);
  104. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  105. }
  106. /**
  107. * 商品搜索
  108. */
  109. @GetMapping("/search")
  110. public Result<SearchResult<GoodsDonSearchView>> search() {
  111. SearchResult<GoodsDonSearchView> search = beanSearcher.search(GoodsDonSearchView.class, MapUtils.flatBuilder(request.getParameterMap()).build());
  112. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  113. }
  114. /**
  115. * 获取商品列表
  116. */
  117. @GetMapping("/get")
  118. public Result<SearchResult<GoodsDon>> get() {
  119. SearchResult<GoodsDon> search = beanSearcher.search(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap())
  120. .field(GoodsDon::getStatus, true)
  121. .field(GoodsDon::getDeleted, true)
  122. .orderBy(GoodsDon::getSortBy).asc()
  123. .orderBy(GoodsDon::getId).asc()
  124. .build()
  125. );
  126. search.getDataList().forEach(goods -> {
  127. GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, goods.getId())
  128. .eq(GoodsDonSku::getStatus, true)
  129. .orderByAsc(GoodsDonSku::getPrice)
  130. .last("limit 1")
  131. .select(GoodsDonSku::getPrice));
  132. Optional.ofNullable(goodsDonSku).ifPresent(sku -> {
  133. goods.setPrice(goodsDonSku.getPrice());
  134. goods.setSoldNum(getGoodsSold(goods.getId(), goods.getVirtualSold()));
  135. });
  136. });
  137. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  138. }
  139. /**
  140. * 推广未登录,虚拟商品列表
  141. */
  142. @GetMapping("/get/popularize")
  143. @Deprecated
  144. public Result<SearchResult<GoodsDonPopularizeView>> getPopularizeVipGoods() {
  145. SearchResult<GoodsDonPopularizeView> search = beanSearcher.search(GoodsDonPopularizeView.class, MapUtils.flatBuilder(request.getParameterMap())
  146. .field(GoodsDonPopularizeView::getStatus, true)
  147. .field(GoodsDonPopularizeView::getDeleted, true)
  148. .field(GoodsDonPopularizeView::getType, 1)
  149. .orderBy(GoodsDonPopularizeView::getSortBy).asc()
  150. .orderBy(GoodsDonPopularizeView::getId).asc()
  151. .build());
  152. DateTime now = DateTime.now();
  153. search.getDataList().forEach(data -> {
  154. data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build()));
  155. data.setSkuList(beanSearcher.searchAll(GoodsDonSku.class, MapUtils.builder().field(GoodsDonSku::getGoodsId, data.getId()).field(GoodsDonSku::getStatus, true).orderBy(GoodsDonSku::getPrice).asc().build()));
  156. data.setSold(getGoodsSold(data.getId(), data.getVirtualSold()));
  157. Optional.ofNullable(data.getSkuList()).ifPresent(skuList -> {
  158. if (skuList.size() > 0) {
  159. GoodsDonSku goodsDonSku = skuList.get(0);
  160. data.setPrice(goodsDonSku.getPrice());
  161. data.setMonths(goodsDonSku.getMonths());
  162. }
  163. });
  164. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  165. .eq(OrderDon::getGoodsId, data.getId())
  166. .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
  167. .orderByDesc(OrderDon::getId)
  168. .last("limit 1"));
  169. StringBuilder notifyMsg = new StringBuilder();
  170. if (orderDon == null) {
  171. notifyMsg.append("点击购买立即上车");
  172. data.setNotifyMsg(notifyMsg.toString());
  173. return;
  174. } else {
  175. Date payTime = orderDon.getPayTime();
  176. Date startTime = payTime != null ? payTime : orderDon.getCreatedTime();
  177. long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
  178. if (hour == 0) {
  179. long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
  180. if (minute == 0) {
  181. notifyMsg.append("1分钟");
  182. } else {
  183. notifyMsg.append(minute);
  184. notifyMsg.append("分钟");
  185. }
  186. } else {
  187. if (hour > 3) {
  188. int hours = RandomUtil.randomInt(3) + 1;
  189. notifyMsg.append(hours);
  190. } else {
  191. notifyMsg.append(hour);
  192. }
  193. notifyMsg.append("小时");
  194. }
  195. }
  196. notifyMsg.append("前有人购买");
  197. data.setNotifyMsg(notifyMsg.toString());
  198. });
  199. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  200. }
  201. /**
  202. * 官网首页 平台列表
  203. */
  204. @GetMapping("/get/list")
  205. @Deprecated
  206. public Result<? extends Object> getGoodsList(String customId) {
  207. if (StrUtil.isNotBlank(customId)) {
  208. Result<List<YhShopGoodsFrontView>> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId));
  209. return shopGoods;
  210. }
  211. //List<Long> filter_goodsIds = getFilterGoodsIds();
  212. List<Long> filter_goodsIds = null;
  213. String pcCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "PC";
  214. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  215. pcCacheKey += ":hz-ip";
  216. }
  217. Long fUid = StpUserUtil.getUserIdAfterLogin();
  218. Object o = redisService.get(pcCacheKey);
  219. List<GoodsFrontListView> list = null;
  220. if (o == null) {
  221. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  222. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  223. builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
  224. }
  225. builder.field(GoodsFrontListView::getType, 1);
  226. list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
  227. redisService.setNx(pcCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  228. o = redisService.get(pcCacheKey);
  229. }
  230. if (list == null) {
  231. list = Jsons.parseList(o, GoodsFrontListView.class);
  232. }
  233. DateTime now = DateTime.now();
  234. list.forEach(data -> {
  235. data.setSold(getGoodsSold(data.getId(), data.getSold()));
  236. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
  237. //设置特定价格
  238. setSpecificPrice(data, fUid, null);
  239. });
  240. return GatewayResponse.SUCCESS.newBuilder().toResult(Optional.of(list));
  241. }
  242. /**
  243. * h5 银河首页平台展示
  244. */
  245. @GetMapping("/get/homePage")
  246. @Deprecated
  247. public Result<? extends Object> getGoodsHomePage(String customId) {
  248. if (StrUtil.isNotBlank(customId)) {
  249. Result<List<YhShopGoodsFrontView>> shopGoods = getShopGoods(yhShopFrontService.getYhsIdByCustomId(customId));
  250. return shopGoods;
  251. }
  252. //List<Long> filter_goodsIds = getFilterGoodsIds();
  253. List<Long> filter_goodsIds = null;
  254. String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "H5";
  255. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  256. h5CacheKey += ":hz-ip";
  257. }
  258. Long fUid = StpUserUtil.getUserIdAfterLogin();
  259. Object o = redisService.get(h5CacheKey);
  260. List<GoodsFrontListView> list = null;
  261. if (o == null) {
  262. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  263. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  264. builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
  265. }
  266. list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
  267. redisService.setNx(h5CacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  268. o = redisService.get(h5CacheKey);
  269. }
  270. if (list == null) {
  271. list = Jsons.parseList(o, GoodsFrontListView.class);
  272. }
  273. DateTime now = DateTime.now();
  274. list.forEach(data -> {
  275. data.setSold(getGoodsSold(data.getId(), data.getSold()));
  276. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
  277. //设置特定价格
  278. setSpecificPrice(data, fUid, null);
  279. });
  280. return GatewayResponse.SUCCESS.newBuilder().toResult(Optional.of(list));
  281. }
  282. /**
  283. * 注册首页平台展示
  284. */
  285. @GetMapping("/get/register")
  286. public Result<List<RegisterGoodsDonView>> getRegisterGoodsDon() {
  287. String registerCacheKey = RedisService.key.REGISTER_HOME_PAGE_CACHE.getName();
  288. Object value = redisService.get(registerCacheKey);
  289. if (value != null) {
  290. try {
  291. List<RegisterGoodsDonView> list = Jsons.parseList(value, RegisterGoodsDonView.class);
  292. if (CollUtil.isNotEmpty(list)) {
  293. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  294. }
  295. } catch (Exception e) {
  296. }
  297. }
  298. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  299. List<RegisterGoodsDonView> dataList = beanSearcher.searchAll(RegisterGoodsDonView.class, builder.build());
  300. DateTime now = DateTime.now();
  301. dataList.forEach(data -> {
  302. Integer sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class)
  303. .eq(RegisterOrderDon::getGoodsId, data.getId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
  304. data.setSold(sold + data.getVirtualSold());
  305. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 2, null));
  306. });
  307. redisService.setNx(registerCacheKey, dataList, RedisService.key.REGISTER_HOME_PAGE_CACHE.getTimeout());
  308. return GatewayResponse.SUCCESS.newBuilder().toResult(dataList);
  309. }
  310. /**
  311. * 获取商品详情
  312. */
  313. @GetMapping("/get/{id}")
  314. public Result<? extends Object> getDetail(@PathVariable Long id, String customId, String dsCode) {
  315. if (StrUtil.isNotBlank(customId) && id != 15) {
  316. Result<YhShopGoodsFrontView> yhShopGoodsDetail = getGoodsDetailByYhsId(yhShopFrontService.getYhsIdByCustomId(customId), id);
  317. return yhShopGoodsDetail;
  318. }
  319. String goodsDetailKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "goods_detail:" + id;
  320. //List<Long> filter_goodsIds = getFilterGoodsIds();
  321. List<Long> filter_goodsIds = null;
  322. //存在过滤平台 商品详情不返回
  323. if (CollUtil.isNotEmpty(filter_goodsIds) && filter_goodsIds.contains(id)) {
  324. return GatewayResponse.SUCCESS.newBuilder().toResult();
  325. }
  326. Object o = redisService.get(goodsDetailKey);
  327. if (o == null) {
  328. GoodsFrontListView views = beanSearcher.searchFirst(GoodsFrontListView.class, MapUtils.builder().field(GoodsFrontListView::getId, id)
  329. .build());
  330. if (views == null) {
  331. return GatewayResponse.SUCCESS.newBuilder().toResult();
  332. }
  333. views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build()));
  334. MapBuilder builder = MapUtils.builder().field(GoodsDonSkuFrontView::getGoodsId, views.getId()).field(GoodsDonSkuFrontView::getStatus, true);
  335. if (views.getType() == 1) {
  336. builder.orderBy(GoodsDonSkuFrontView::getSorted).asc();
  337. }
  338. views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, builder.build()));
  339. views.setSold(getGoodsSold(views.getId(), views.getSold()));
  340. List<GoodsDonQaFrontView> donQaFrontViews = beanSearcher.searchAll(GoodsDonQaFrontView.class, MapUtils.builder().field(GoodsDonQaFrontView::getGoodsId, id).field(GoodsDonQaFrontView::getType, 1).build());
  341. views.setQuestions(donQaFrontViews);
  342. redisService.setNx(goodsDetailKey, views, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
  343. o = redisService.get(goodsDetailKey);
  344. }
  345. Long fUid = StpUserUtil.getUserIdAfterLogin();
  346. GoodsFrontListView views = Jsons.parseObject(o, GoodsFrontListView.class);
  347. AtomicLong dsUserId = new AtomicLong();
  348. AtomicBoolean existsChannel = new AtomicBoolean(true);
  349. if (StrUtil.isNotBlank(dsCode)) {
  350. UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
  351. dsUserId.set(userSharedDto.getSharedId());
  352. }
  353. views.setIsGift(giftCardGoodsSkuMapper.selectCount(Wrappers.lambdaQuery(GiftCardGoodsSku.class)
  354. .eq(GiftCardGoodsSku::getGcGoodsId, views.getId())
  355. .eq(GiftCardGoodsSku::getStatus, 1)
  356. .eq(GiftCardGoodsSku::getDeleted, 1)) > 0);
  357. views.setSkuList(views.getSkuList().stream().filter(sku -> {
  358. if (StrUtil.isNotBlank(sku.getUserOwns())) {
  359. if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
  360. Long sharedId = userService.getSharedIdByUserId(fUid);
  361. if (sharedId == 0) {
  362. existsChannel.set(false);
  363. }
  364. dsUserId.set(sharedId);
  365. }
  366. if (dsUserId.get() == 0 || !sku.getUserOwns().contains(String.valueOf(dsUserId.get()))) {
  367. return false;
  368. }
  369. }
  370. if (sku.getIsDp()) {
  371. sku.setDpSkuViews(beanSearcher.searchAll(GoodsDiscountPlusPurchaseRelationFrontView.class, MapUtils.builder()
  372. .field(GoodsDiscountPlusPurchaseRelationFrontView::getSkuId, sku.getId())
  373. .build()));
  374. }
  375. if (views.getIsSp()) {
  376. if (fUid == null) {
  377. sku.setSpecificPrice(null);
  378. sku.setSpecificGoodsIds(null);
  379. }else {
  380. //设置特定价格
  381. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  382. sku.setSpecificGoodsIds(null);
  383. sku.setSpecificPrice(null);
  384. } else {
  385. BigDecimal specificPrice = views.getSpecificPrice();
  386. BigDecimal skuSpecificPrice = sku.getSpecificPrice();
  387. Long specificSkuId = sku.getId();
  388. if (specificPrice == null) {
  389. views.setSpecificPrice(skuSpecificPrice);
  390. views.setSpecificSkuId(specificSkuId);
  391. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  392. views.setSpecificPrice(skuSpecificPrice);
  393. views.setSpecificSkuId(specificSkuId);
  394. }
  395. }
  396. }
  397. }
  398. // if (fUid != null && Constant.SPECIAL_PRICE_SKU_IDS.contains(sku.getId())) {
  399. // UserDistributeShared distributeShared = userDistributeSharedMapper.selectOne(Wrappers.lambdaQuery(UserDistributeShared.class)
  400. // .eq(UserDistributeShared::getUserId, fUid)
  401. // .last("limit 1"));
  402. // if (distributeShared != null) {
  403. // Optional.ofNullable(sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
  404. // .eq(SysConfig::getSysKey, Constant.MJ_SPECIAL_SKU_PRICE_KEY)
  405. // .last("limit 1"))).ifPresent(sysConfig -> {
  406. // if (StrUtil.isNotBlank(sysConfig.getSysValue())) {
  407. // try {
  408. // GoodsDonPriceDto goodsDonPriceDto = Jsons.parseObject(sysConfig.getSysValue(), GoodsDonPriceDto.class);
  409. // sku.setPrice(goodsDonPriceDto.getPrice());
  410. // } catch (Exception e) {
  411. // }
  412. // }
  413. // });
  414. // }
  415. // }
  416. return true;
  417. }).collect(Collectors.toList()));
  418. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  419. }
  420. /**
  421. * 获取商品推荐平台
  422. */
  423. @GetMapping("/get/recommend/{id}")
  424. public Result<List<GoodsFrontListView>> getRecommendGoodsByGid(@PathVariable Long id, String customId, String dsCode) throws Exception {
  425. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "recommend:" + id;
  426. Long yhsId = null;
  427. if (StrUtil.isNotBlank(customId)) {
  428. yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  429. key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":recommend:" + id;
  430. }
  431. Object o = redisService.get(key);
  432. Long fUid = StpUserUtil.getUserIdAfterLogin();
  433. List<GoodsFrontListView> goodsRecommendViews = null;
  434. if (o == null) {
  435. GoodsDon goodsDon = beanSearcher.searchFirst(GoodsDon.class, MapUtils.builder()
  436. .field(GoodsDon::getId, id).field(GoodsDon::getStatus, true)
  437. .field(GoodsDon::getDeleted, true)
  438. .build());
  439. if (goodsDon != null && StrUtil.isNotEmpty(goodsDon.getRecommendGoods())) {
  440. List<Long> recommend_gidList = Jsons.parseList(goodsDon.getRecommendGoods(), Long.class);
  441. MapBuilder mapBuilder = MapUtils.builder();
  442. if (yhsId != null) {
  443. 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));
  444. }
  445. mapBuilder.field(GoodsFrontListView::getId, recommend_gidList).op(Operator.InList);
  446. goodsRecommendViews = beanSearcher.searchAll(GoodsFrontListView.class, mapBuilder.build());
  447. redisService.setNx(key, Jsons.toJson(goodsRecommendViews), 60 * 15l);
  448. o = redisService.get(key);
  449. } else {
  450. return GatewayResponse.SUCCESS.newBuilder().toResult();
  451. }
  452. }
  453. if (goodsRecommendViews == null) {
  454. goodsRecommendViews = Jsons.parseList(o.toString(), GoodsFrontListView.class);
  455. }
  456. AtomicLong dsUserId = new AtomicLong();
  457. AtomicBoolean existsChannel = new AtomicBoolean(true);
  458. if (StrUtil.isNotBlank(dsCode)) {
  459. UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
  460. dsUserId.set(userSharedDto.getSharedId());
  461. }
  462. goodsRecommendViews = goodsRecommendViews.stream().filter(data -> {
  463. if (data.getIsOwns()) {
  464. if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
  465. Long sharedId = userService.getSharedIdByUserId(fUid);
  466. if (sharedId == 0) {
  467. existsChannel.set(false);
  468. }
  469. dsUserId.set(sharedId);
  470. }
  471. GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getId(), dsUserId.get());
  472. if (minPriceUserOwnsSku == null) {
  473. return false;
  474. }
  475. data.setPrice(minPriceUserOwnsSku.getPrice());
  476. data.setMonths(minPriceUserOwnsSku.getMonths());
  477. data.setDays(minPriceUserOwnsSku.getDays());
  478. }
  479. //销量
  480. data.setSold(getGoodsSold(data.getId(), data.getSold()));
  481. //设置特定价格
  482. setSpecificPrice(data, fUid, dsUserId.get());
  483. return true;
  484. }).collect(Collectors.toList());
  485. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
  486. }
  487. /**
  488. * 获取商品多规格列表
  489. */
  490. @GetMapping("/get/sku")
  491. public Result<List<GoodsDonSkuView>> getGoodsDonSkuView(@RequestParam(value = "skuIds") List<Long> skuIds) {
  492. if (skuIds.isEmpty()) {
  493. return GatewayResponse.SUCCESS.newBuilder().toResult();
  494. }
  495. List<GoodsDonSkuView> views = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder()
  496. .field(GoodsDonSkuView::getSkuId, skuIds).op(Operator.InList)
  497. .build());
  498. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  499. }
  500. /**
  501. * 获取评价列表
  502. */
  503. @GetMapping("/get/comments")
  504. public Result<SearchResult<OrderCommentFrontView>> getComments() {
  505. SearchResult<OrderCommentFrontView> search = beanSearcher.search(OrderCommentFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
  506. .orderBy(OrderCommentFrontView::getCommentTime).desc()
  507. .orderBy(OrderCommentFrontView::getId).desc()
  508. .build());
  509. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  510. }
  511. /**
  512. * 获取礼品卡平台性情
  513. */
  514. @GetMapping("/get/card/{id}")
  515. public Result<Map<Integer, List<GiftCardGoodsSkuFrontView>>> getGiftCardDetail(@PathVariable Long id) {
  516. List<GiftCardGoodsSkuFrontView> giftCardGoodsSkuFrontViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getGoodsId, id).build());
  517. Map<Integer, List<GiftCardGoodsSkuFrontView>> map = giftCardGoodsSkuFrontViews.stream().collect(Collectors.groupingBy(GiftCardGoodsSkuFrontView::getGcType));
  518. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  519. }
  520. /**
  521. * 获取首页配置列表
  522. */
  523. @GetMapping("/get/homeManage")
  524. public Result<Map<String, List<HomeManagementFrontView>>> getHomeManagementFrontPage(String customId, String dsCode) {
  525. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "homeManage";
  526. Long yhsId = null;
  527. if (StrUtil.isNotBlank(customId)) {
  528. yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  529. key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":homeManage";
  530. }
  531. // List<Long> filter_goodsIds = getFilterGoodsIds();
  532. List<Long> filter_goodsIds = null;
  533. AtomicBoolean isRemoveRg = new AtomicBoolean(false);
  534. // if (isHzIp()) {
  535. // key += ":hz-ip";
  536. // isRemoveRg.set(true);
  537. // }
  538. Long fUid = StpUserUtil.getUserIdAfterLogin();
  539. Object o = redisService.get(key);
  540. if (o == null) {
  541. String condition = "g.deleted is true and g.status is true";
  542. if (yhsId != null) {
  543. 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);
  544. }
  545. Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
  546. final String conditionSql = condition;
  547. Stream.of(HomeManagementConfig.Type.values())
  548. .forEach(type -> {
  549. if (isRemoveRg.get() && type == HomeManagementConfig.Type.rg) {
  550. return;
  551. }
  552. MapBuilder builder = MapUtils.builder()
  553. .field(HomeManagementFrontView::getType, type.name());
  554. if (type == HomeManagementConfig.Type.ex || type == HomeManagementConfig.Type.vg) {
  555. builder.put("condition", conditionSql);
  556. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  557. builder.field(HomeManagementFrontView::getGoodsId, filter_goodsIds).op(Operator.NotIn);
  558. }
  559. }
  560. List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
  561. map.putIfAbsent(type.name(), homeManagementFrontViews);
  562. });
  563. redisService.setNx(key, map, 50 * 60l);
  564. o = redisService.get(key);
  565. }
  566. AtomicLong dsUserId = new AtomicLong();
  567. AtomicBoolean existsChannel = new AtomicBoolean(true);
  568. if (StrUtil.isNotBlank(dsCode)) {
  569. UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
  570. dsUserId.set(userSharedDto.getSharedId());
  571. }
  572. Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
  573. if (map.containsKey(HomeManagementConfig.Type.ex.name()) || map.containsKey(HomeManagementConfig.Type.vg.name())) {
  574. try {
  575. //精彩推荐
  576. List<HomeManagementFrontView> exList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.ex.name())), HomeManagementFrontView.class);
  577. setHomeConfigGoods(map, HomeManagementConfig.Type.ex, exList, dsUserId, existsChannel, fUid);
  578. //虚拟平台
  579. List<HomeManagementFrontView> vgList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.vg.name())), HomeManagementFrontView.class);
  580. setHomeConfigGoods(map, HomeManagementConfig.Type.vg, vgList, dsUserId, existsChannel, fUid);
  581. } catch (Exception e) {
  582. }
  583. }
  584. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  585. }
  586. /**
  587. * 首页点击 记录
  588. */
  589. @PostMapping("/homePage/click")
  590. public Result<String> homeManageClick(@RequestBody ClickRecordReq request) {
  591. Long userId = StpUserUtil.getUserIdAfterLogin();
  592. clickRecordFrontService.click(userId, request);
  593. return GatewayResponse.SUCCESS.newBuilder().toResult();
  594. }
  595. public List<Long> getFilterGoodsIds() {
  596. List<Long> filter_goodsIds = null;
  597. //获取当前ip地址
  598. if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("杭州")) {
  599. //过滤杭州Ai ChatGPT平台
  600. SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
  601. .eq(SysConfig::getSysKey, Constant.LOCATION_FOR_GOODS_IDS).last("limit 1"));
  602. if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
  603. try {
  604. filter_goodsIds = Jsons.parseList(sysConfig.getSysValue(), Long.class);
  605. } catch (Exception e) {
  606. }
  607. }
  608. }
  609. return filter_goodsIds;
  610. }
  611. public Boolean isHzIp() {
  612. if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("无锡")) {
  613. return true;
  614. }
  615. return false;
  616. }
  617. /**
  618. * @param goodsId
  619. * @param type 1、普通,2、注册平台
  620. * @param yhsId 店铺id
  621. * @return
  622. */
  623. public String getPayMsgTime(Long goodsId, DateTime now, Integer type, Long yhsId) {
  624. Date startTime = null;
  625. StringBuilder notifyMsg = new StringBuilder();
  626. if (type == 1) {
  627. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  628. .eq(OrderDon::getGoodsId, goodsId)
  629. .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
  630. .eq(yhsId != null, OrderDon::getYhsId, yhsId)
  631. .orderByDesc(OrderDon::getId)
  632. .last("limit 1"));
  633. if (orderDon == null) {
  634. notifyMsg.append("点击购买立即上车");
  635. return notifyMsg.toString();
  636. }
  637. startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
  638. } else if (type == 2) {
  639. RegisterOrderDon orderDon = registerOrderDonMapper.selectOne(Wrappers.lambdaQuery(RegisterOrderDon.class)
  640. .eq(RegisterOrderDon::getGoodsId, goodsId)
  641. .notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus).select(RegisterOrderDon::getCreatedTime, RegisterOrderDon::getPayTime, RegisterOrderDon::getId)
  642. .orderByDesc(RegisterOrderDon::getId)
  643. .last("limit 1"));
  644. if (orderDon == null) {
  645. return null;
  646. }
  647. startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
  648. }
  649. long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
  650. if (hour == 0) {
  651. long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
  652. if (minute == 0) {
  653. notifyMsg.append("1分钟");
  654. } else {
  655. notifyMsg.append(minute);
  656. notifyMsg.append("分钟");
  657. }
  658. } else {
  659. if (hour > 3) {
  660. int hours = RandomUtil.randomInt(3) + 1;
  661. notifyMsg.append(hours);
  662. } else {
  663. notifyMsg.append(hour);
  664. }
  665. notifyMsg.append("小时");
  666. }
  667. notifyMsg.append("前有人购买");
  668. return notifyMsg.toString();
  669. }
  670. /**
  671. * 是否购买过特定平台
  672. */
  673. public Boolean isPaySpecificGoodsIds(String specificGoodsIdsStr, Long userId) {
  674. if (StrUtil.isNotBlank(specificGoodsIdsStr)) {
  675. try {
  676. Set<Long> specificGoodsIds = Jsons.parseSet(specificGoodsIdsStr, Long.class);
  677. Number number = beanSearcher.searchCount(OrderDon.class, MapUtils.builder().field(OrderDon::getGoodsId, specificGoodsIds).op(Operator.InList)
  678. .field(OrderDon::getUserId, userId)
  679. .field(OrderDon::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn)
  680. .build());
  681. if (number.intValue() == 0) {
  682. return false;
  683. }
  684. return true;
  685. } catch (Exception e) {
  686. }
  687. }
  688. return false;
  689. }
  690. /**
  691. * 设置平台 特定价格
  692. */
  693. public void setSpecificPrice(GoodsFrontListView data, Long fUid, Long dsUserId) {
  694. if (fUid != null) {
  695. if (data.getIsSp()) {
  696. //查找所有特定规格最小价格 满足条件
  697. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId();
  698. Object speciObj = redisService.get(specificGoodsKey);
  699. List<GoodsDonSku> specificSkus = null;
  700. if (speciObj != null) {
  701. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  702. } else {
  703. specificSkus = goodsDonSkuMapper.selectList(
  704. Wrappers.lambdaQuery(GoodsDonSku.class)
  705. .eq(GoodsDonSku::getGoodsId, data.getId())
  706. .eq(GoodsDonSku::getStatus, true)
  707. .gt(GoodsDonSku::getSpecificPrice, 0));
  708. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  709. }
  710. specificSkus.forEach(specificSku -> {
  711. if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) {
  712. return;
  713. }
  714. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  715. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  716. BigDecimal specificPrice = data.getSpecificPrice();
  717. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  718. Long specificSkuId = specificSku.getId();
  719. if (specificPrice == null) {
  720. data.setSpecificPrice(skuSpecificPrice);
  721. data.setSpecificSkuId(specificSkuId);
  722. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  723. data.setSpecificPrice(skuSpecificPrice);
  724. data.setSpecificSkuId(specificSkuId);
  725. }
  726. }
  727. });
  728. List<GoodsDonSkuFrontView> skuList = data.getSkuList();
  729. if (CollUtil.isNotEmpty(skuList)) {
  730. skuList.forEach(sku -> {
  731. //设置特定价格
  732. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  733. sku.setSpecificGoodsIds(null);
  734. sku.setSpecificPrice(null);
  735. }
  736. });
  737. }
  738. }
  739. }
  740. }
  741. /**
  742. * 设置平台 特定价格
  743. */
  744. public void setGcSpecificPrice(GoodsFrontListCategoryView data, Long fUid, Long dsUserId) {
  745. if (fUid != null) {
  746. if (data.getIsSp()) {
  747. //查找所有特定规格最小价格 满足条件
  748. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId();
  749. Object speciObj = redisService.get(specificGoodsKey);
  750. List<GoodsDonSku> specificSkus = null;
  751. if (speciObj != null) {
  752. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  753. } else {
  754. specificSkus = goodsDonSkuMapper.selectList(
  755. Wrappers.lambdaQuery(GoodsDonSku.class)
  756. .eq(GoodsDonSku::getGoodsId, data.getId())
  757. .eq(GoodsDonSku::getStatus, true)
  758. .gt(GoodsDonSku::getSpecificPrice, 0));
  759. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  760. }
  761. specificSkus.forEach(specificSku -> {
  762. if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) {
  763. return;
  764. }
  765. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  766. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  767. BigDecimal specificPrice = data.getSpecificPrice();
  768. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  769. Long specificSkuId = specificSku.getId();
  770. if (specificPrice == null) {
  771. data.setSpecificPrice(skuSpecificPrice);
  772. data.setSpecificSkuId(specificSkuId);
  773. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  774. data.setSpecificPrice(skuSpecificPrice);
  775. data.setSpecificSkuId(specificSkuId);
  776. }
  777. }
  778. });
  779. List<GoodsDonSkuFrontView> skuList = data.getSkuList();
  780. if (CollUtil.isNotEmpty(skuList)) {
  781. skuList.forEach(sku -> {
  782. //设置特定价格
  783. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  784. sku.setSpecificGoodsIds(null);
  785. sku.setSpecificPrice(null);
  786. }
  787. });
  788. }
  789. }
  790. }
  791. }
  792. /**
  793. * 获取特定规格
  794. */
  795. public List<GoodsDonSku> getSpecificSku(Long goodsId) {
  796. //查找所有特定规格最小价格 满足条件
  797. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + goodsId;
  798. Object speciObj = redisService.get(specificGoodsKey);
  799. List<GoodsDonSku> specificSkus = null;
  800. if (speciObj != null) {
  801. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  802. } else {
  803. specificSkus = goodsDonSkuMapper.selectList(
  804. Wrappers.lambdaQuery(GoodsDonSku.class)
  805. .eq(GoodsDonSku::getGoodsId, goodsId)
  806. .eq(GoodsDonSku::getStatus, true)
  807. .gt(GoodsDonSku::getSpecificPrice, 0));
  808. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  809. }
  810. specificSkus = Optional.ofNullable(specificSkus).orElse(new ArrayList<>());
  811. return specificSkus;
  812. }
  813. /**
  814. * 设置首页配置 涉及平台特定价格
  815. */
  816. public void setHomeManageSpecific(List<HomeManagementFrontView> list, Long fUid, Long dsUserId) {
  817. DateTime now = DateTime.now();
  818. list.forEach(data -> {
  819. if (data.getIsSp() != null && data.getIsSp() && fUid != null) {
  820. //查找所有特定规格最小价格 满足条件
  821. List<GoodsDonSku> specificSkus = getSpecificSku(data.getGoodsId());
  822. specificSkus.forEach(specificSku -> {
  823. if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) {
  824. return;
  825. }
  826. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  827. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  828. BigDecimal specificPrice = data.getSpecificPrice();
  829. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  830. Long specificSkuId = specificSku.getId();
  831. if (specificPrice == null) {
  832. data.setSpecificPrice(skuSpecificPrice);
  833. data.setSpecificSkuId(specificSkuId);
  834. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  835. data.setSpecificPrice(skuSpecificPrice);
  836. data.setSpecificSkuId(specificSkuId);
  837. }
  838. }
  839. });
  840. }
  841. data.setSold(getGoodsSold(data.getGoodsId(), data.getSold()));
  842. data.setNotifyMsg(getPayMsgTime(data.getGoodsId(), now, 1, null));
  843. });
  844. }
  845. public void setHomeConfigGoods(Map<String, List<HomeManagementFrontView>> map, HomeManagementConfig.Type type, List<HomeManagementFrontView> list, AtomicLong dsUserId, AtomicBoolean existsChannel, Long fUid) throws Exception {
  846. //设置特定价格
  847. if (CollUtil.isNotEmpty(list)) {
  848. list = list.stream().filter(data -> {
  849. if (data.getIsOwns()) {
  850. if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
  851. Long sharedId = userService.getSharedIdByUserId(fUid);
  852. if (sharedId == 0) {
  853. existsChannel.set(false);
  854. }
  855. dsUserId.set(sharedId);
  856. }
  857. GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getGoodsId(), dsUserId.get());
  858. if (minPriceUserOwnsSku == null) {
  859. return false;
  860. }
  861. data.setPrice(minPriceUserOwnsSku.getPrice());
  862. data.setMonths(minPriceUserOwnsSku.getMonths());
  863. data.setDays(minPriceUserOwnsSku.getDays());
  864. }
  865. return true;
  866. }).collect(Collectors.toList());
  867. setHomeManageSpecific(list, fUid, dsUserId.get());
  868. map.put(type.name(), list);
  869. }
  870. }
  871. /**
  872. * 店铺平台列表
  873. */
  874. @GetMapping("/get/shop/goods/{yhsId}")
  875. public Result<List<YhShopGoodsFrontView>> getShopGoods(@PathVariable Long yhsId) {
  876. String yhShopCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId;
  877. Object value = redisService.get(yhShopCacheKey);
  878. List<YhShopGoodsFrontView> list = null;
  879. if (value != null) {
  880. try {
  881. list = Jsons.parseList(value, YhShopGoodsFrontView.class);
  882. } catch (Exception e) {
  883. }
  884. }
  885. if (CollUtil.isEmpty(list)) {
  886. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  887. builder.put("condition", String.format("and yhs_id = %s", yhsId));
  888. list = beanSearcher.searchAll(YhShopGoodsFrontView.class, builder.build());
  889. redisService.setNx(yhShopCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  890. }
  891. DateTime now = DateTime.now();
  892. list.forEach(data->{
  893. data.setSold(getGoodsSold(data.getId(), data.getSold()));
  894. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
  895. });
  896. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  897. }
  898. /**
  899. * 店铺平台详情
  900. */
  901. @GetMapping("/get/shop/goods/detail/{yhsId}/{goodsId}")
  902. public Result<YhShopGoodsFrontView> getGoodsDetailByYhsId(@PathVariable Long yhsId, @PathVariable Long goodsId) {
  903. String yhShopDetailCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":goodsId:" + goodsId;
  904. Object value = redisService.get(yhShopDetailCacheKey);
  905. if (value == null) {
  906. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  907. String condition = String.format("and yhs_id = %s and ys.goods_id = %s", yhsId, goodsId);
  908. builder.put("condition", condition);
  909. YhShopGoodsFrontView goodsDetailView = beanSearcher.searchFirst(YhShopGoodsFrontView.class, builder.build());
  910. if (goodsDetailView == null) {
  911. throw BusinessRuntimeException.getInstance("该平台不存在或已下架,请刷新页面");
  912. }
  913. goodsDetailView.setSkuList(beanSearcher.searchAll(YhShopGoodsSkuFrontView.class, MapUtils.builder().put("condition", condition).orderBy(YhShopGoodsSkuFrontView::getSorted).asc().build()));
  914. goodsDetailView.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, goodsDetailView.getId()).build()));
  915. OrderCommentFrontView comments = beanSearcher.searchFirst(OrderCommentFrontView.class, MapUtils.builder()
  916. .field(OrderCommentFrontView::getGoodsId, goodsDetailView.getId())
  917. .orderBy(OrderCommentFrontView::getCommentTime).desc()
  918. .orderBy(OrderCommentFrontView::getId).desc()
  919. .build());
  920. goodsDetailView.setComments(comments);
  921. redisService.setNx(yhShopDetailCacheKey, goodsDetailView, RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getTimeout() + RandomUtil.randomInt(1000));
  922. value = redisService.get(yhShopDetailCacheKey);
  923. }
  924. YhShopGoodsFrontView goodsDetailView = Jsons.parseObject(value, YhShopGoodsFrontView.class);
  925. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDetailView);
  926. }
  927. /**
  928. * 根据分类获取对应平台
  929. */
  930. @GetMapping("/get/categoryGoods")
  931. public Result<? extends Object> getGoodsByCategory(Long cgy, String customId, String dsCode) {
  932. if (StrUtil.isNotBlank(customId)) {
  933. Result<List<YhShopGoodsFrontCategoryView>> shopGoods = getShopCategoryGoods(yhShopFrontService.getYhsIdByCustomId(customId), cgy);
  934. return shopGoods;
  935. }
  936. Long fUid = StpUserUtil.getUserIdAfterLogin();
  937. String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "category:goods";
  938. if (cgy != null) {
  939. categoryGoodsKey += ":" + cgy;
  940. }
  941. //List<Long> filter_goodsIds = getFilterGoodsIds();
  942. List<Long> filter_goodsIds = null;
  943. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  944. categoryGoodsKey += ":hz-ip";
  945. }
  946. Object o = redisService.get(categoryGoodsKey);
  947. if (o == null) {
  948. DateTime now = DateTime.now();
  949. MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
  950. if (cgy != null) {
  951. String condition = String.format(" and gcr.category = %s", cgy);
  952. mapBuilder.put("condition", condition);
  953. }
  954. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  955. mapBuilder.field(GoodsFrontListCategoryView::getId, filter_goodsIds).op(Operator.NotIn);
  956. }
  957. List<GoodsFrontListCategoryView> goodsFrontListViews = beanSearcher.searchAll(GoodsFrontListCategoryView.class, mapBuilder.build());
  958. goodsFrontListViews.forEach(data -> {
  959. data.setSold(getGoodsSold(data.getId(), data.getSold()));;
  960. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
  961. });
  962. redisService.setNx(categoryGoodsKey, goodsFrontListViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 10 * 60);
  963. o = redisService.get(categoryGoodsKey);
  964. }
  965. List<GoodsFrontListCategoryView> goodsFrontListViews = Jsons.parseList(o, GoodsFrontListCategoryView.class);
  966. AtomicLong dsUserId = new AtomicLong();
  967. AtomicBoolean existsChannel = new AtomicBoolean(true);
  968. if (StrUtil.isNotBlank(dsCode)) {
  969. UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
  970. dsUserId.set(userSharedDto.getSharedId());
  971. }
  972. AtomicBoolean filterCourseGoods = new AtomicBoolean(false);
  973. //增值服务分类
  974. if (fUid != null && cgy != null && (cgy == 3 || cgy == 4)) {
  975. //GPT Plus基础2月 课程不展示
  976. List<Long> userIdList = userBindRelationService.getRelationUserIdList(fUid, null);
  977. Integer orders = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  978. .in(OrderDon::getUserId, userIdList)
  979. .eq(OrderDon::getSkuId, 444)
  980. .notIn(OrderDon::getStatus, Constant.noOrderStatus));
  981. if (orders > 0) {
  982. filterCourseGoods.set(true);
  983. }
  984. }
  985. goodsFrontListViews = goodsFrontListViews.stream().filter(data -> {
  986. if (data.getIsOwns()) {
  987. if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
  988. Long sharedId = userService.getSharedIdByUserId(fUid);
  989. if (sharedId == 0) {
  990. existsChannel.set(false);
  991. }
  992. dsUserId.set(sharedId);
  993. }
  994. GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getId(), dsUserId.get());
  995. if (minPriceUserOwnsSku == null) {
  996. return false;
  997. }
  998. data.setPrice(minPriceUserOwnsSku.getPrice());
  999. data.setMonths(minPriceUserOwnsSku.getMonths());
  1000. data.setDays(minPriceUserOwnsSku.getDays());
  1001. }
  1002. //课件类型 且过滤
  1003. if (filterCourseGoods.get() && data.getSpecialType() != null && data.getSpecialType() == GoodsDon.SpecialType.courseware) {
  1004. return false;
  1005. }
  1006. //设置特定价格
  1007. setGcSpecificPrice(data, fUid, dsUserId.get());
  1008. return true;
  1009. }).collect(Collectors.toList());
  1010. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsFrontListViews);
  1011. }
  1012. @GetMapping("/get/shop/categoryGoods/{yhsId}")
  1013. public Result<List<YhShopGoodsFrontCategoryView>> getShopCategoryGoods(@PathVariable Long yhsId, Long category) {
  1014. String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":category";
  1015. if (category != null) {
  1016. categoryGoodsKey += ":" + category;
  1017. }
  1018. Object value = redisService.get(categoryGoodsKey);
  1019. if (value == null) {
  1020. DateTime now = DateTime.now();
  1021. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  1022. builder.put("yhsId", String.format(" and yhs_id = %s", yhsId));
  1023. String condition = StrUtil.EMPTY;
  1024. if (category != null) {
  1025. condition += String.format(" and gcr.category = %s", category);
  1026. }
  1027. builder.put("condition", condition);
  1028. List<YhShopGoodsFrontCategoryView> list = beanSearcher.searchAll(YhShopGoodsFrontCategoryView.class, builder.build());
  1029. list.forEach(data->{
  1030. data.setSold(getGoodsSold(data.getId(), data.getSold()));
  1031. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
  1032. //重新设置最低价格规格
  1033. YhShopGoodsSku sku = yhShopGoodsSkuMapper.selectMinPriceSkuByYhsId(yhsId, data.getId());
  1034. data.setPrice(sku.getPrice());
  1035. data.setSkuId(sku.getSkuId());
  1036. });
  1037. redisService.setNx(categoryGoodsKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 5 * 60);
  1038. value = redisService.get(categoryGoodsKey);
  1039. }
  1040. List<YhShopGoodsFrontCategoryView> list = Jsons.parseList(value, YhShopGoodsFrontCategoryView.class);
  1041. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  1042. }
  1043. /**
  1044. * 获取设备活动详情
  1045. */
  1046. @GetMapping("/get/equipment/activity")
  1047. public Result<EquipmentActivityReduce> getEpActivity() {
  1048. DateTime now = DateTime.now();
  1049. EquipmentActivityReduce equipmentActivityReduce = beanSearcher.searchFirst(EquipmentActivityReduce.class, MapUtils.builder()
  1050. .field(EquipmentActivityReduce::getSt, now).op(Operator.LessEqual)
  1051. .field(EquipmentActivityReduce::getEt, now).op(Operator.GreaterThan)
  1052. .field(EquipmentActivityReduce::getDeleted, 1)
  1053. .onlySelect(EquipmentActivityReduce::getF, EquipmentActivityReduce::getQ, EquipmentActivityReduce::getTq, EquipmentActivityReduce::getSt, EquipmentActivityReduce::getEt)
  1054. .build());
  1055. return GatewayResponse.SUCCESS.newBuilder().toResult(equipmentActivityReduce);
  1056. }
  1057. /**
  1058. * 获取租赁商品列表
  1059. */
  1060. @GetMapping("/get/deposit")
  1061. public Result<? extends Object> getDepositGoods() {
  1062. String depositGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "deposit";
  1063. Object o = redisService.get(depositGoodsKey);
  1064. if (o == null) {
  1065. List<GoodsDon> depositList = beanSearcher.searchAll(GoodsDon.class, MapUtils.builder()
  1066. .field(GoodsDon::getType, 4)
  1067. .field(GoodsDon::getStatus, true)
  1068. .field(GoodsDon::getDeleted, true)
  1069. .onlySelect(GoodsDon::getId, GoodsDon::getTitle, GoodsDon::getLogo)
  1070. .build());
  1071. if (CollUtil.isEmpty(depositList)) {
  1072. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1073. }
  1074. redisService.setNx(depositGoodsKey, depositList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
  1075. o = redisService.get(depositGoodsKey);
  1076. }
  1077. List<GoodsDon> depositList = Jsons.parseList(o, GoodsDon.class);
  1078. return GatewayResponse.SUCCESS.newBuilder().toResult(depositList);
  1079. }
  1080. /**
  1081. * 获取pc广告配置
  1082. */
  1083. @GetMapping("/get/pc/homeManage")
  1084. public Result<Map<String, List<HomeManagementFrontView>>> getPcHomeManagementFrontPage() {
  1085. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "pc:homeManage";
  1086. //移除奈飞客厅 临时
  1087. Long filterConfigId = null;
  1088. // if (isHzIp()) {
  1089. // key += ":hz_ip";
  1090. // filterConfigId = 55l;
  1091. // }
  1092. Object o = redisService.get(key);
  1093. if (o == null) {
  1094. MapBuilder builder = MapUtils.builder()
  1095. .field(HomeManagementFrontView::getAdType, List.of(HomeManagementConfig.AdType.pc.name(), HomeManagementConfig.AdType.pcSec.name(), HomeManagementConfig.AdType.pcDis.name())).op(Operator.InList);
  1096. if (filterConfigId != null) {
  1097. builder.field(HomeManagementFrontView::getHomeManageConfigId, filterConfigId).op(Operator.NotEqual);
  1098. }
  1099. List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
  1100. Map<HomeManagementConfig.AdType, List<HomeManagementFrontView>> map = homeManagementFrontViews.stream().collect(Collectors.groupingBy(HomeManagementFrontView::getAdType));
  1101. redisService.setNx(key, map, 50 * 60l);
  1102. o = redisService.get(key);
  1103. }
  1104. Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
  1105. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  1106. }
  1107. /**
  1108. * 获取pc实物配置
  1109. */
  1110. @GetMapping("/get/pc/realGoodsConfig")
  1111. public Result<? extends Object> getPcRealGoodsConfig() throws Exception {
  1112. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "pc:realHomePage";
  1113. Object o = redisService.get(key);
  1114. List<HomeManagementFrontView> list = null;
  1115. if (o == null) {
  1116. list = goodsDonFrontService.getRealGoodsConfig();
  1117. redisService.setNx(key, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 300);
  1118. }
  1119. if (list == null && o != null) {
  1120. list = Jsons.parseList(o, HomeManagementFrontView.class);
  1121. }
  1122. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  1123. }
  1124. /**
  1125. * 百亿补贴
  1126. * 补贴规格列表
  1127. */
  1128. @GetMapping("/get/subsidy")
  1129. public Result<List<GoodsDonSkuSubsidyFrontView>> getSubsidyGoods() {
  1130. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy";
  1131. Object o = redisService.get(key);
  1132. if (o == null) {
  1133. List<GoodsDonSkuSubsidyFrontView> subsidyList = beanSearcher.searchAll(GoodsDonSkuSubsidyFrontView.class, MapUtils.builder().build());
  1134. subsidyList.forEach(e -> {
  1135. Optional.ofNullable(beanSearcher.searchFirst(GoodsDonSkuSubsidyDetailView.class, MapUtils.builder().field(GoodsDonSkuSubsidyDetailView::getGoodsId, e.getId()).field(GoodsDonSkuSubsidyDetailView::getPrice, e.getPrice()).build())).ifPresent(sku -> {
  1136. e.setOriPrice(sku.getOriPrice());
  1137. e.setMonths(sku.getMonths());
  1138. e.setDays(sku.getDays());
  1139. e.setSkuId(sku.getId());
  1140. e.setPicture(sku.getSubsidyPicture());
  1141. });
  1142. });
  1143. redisService.setNx(key, subsidyList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
  1144. o = redisService.get(key);
  1145. }
  1146. List<GoodsDonSkuSubsidyFrontView> subsidyList = Jsons.parseList(o, GoodsDonSkuSubsidyFrontView.class);
  1147. if (CollUtil.isEmpty(subsidyList)) {
  1148. return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyList);
  1149. }
  1150. Long userId = StpUserUtil.getUserIdAfterLogin();
  1151. if (userId != null) {
  1152. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1153. //过滤用户已经购买过平台
  1154. List<Long> goodsIds = orderDonMapper.getPayGoodsIds(relationUserIdList);
  1155. if (CollUtil.isNotEmpty(goodsIds)) {
  1156. subsidyList = subsidyList.stream().filter(data -> !goodsIds.contains(data.getId())).collect(Collectors.toList());
  1157. }
  1158. }
  1159. return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyList);
  1160. }
  1161. /**
  1162. * 百亿补贴规格详情
  1163. */
  1164. @GetMapping("/get/subsidy/detail/{id}")
  1165. public Result<GoodsDonSubsidyDetailView> getSubsidyDetailById(@PathVariable Long id) throws Exception {
  1166. String goodsDetailKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy:detail:" + id;
  1167. Object o = redisService.get(goodsDetailKey);
  1168. GoodsDonSubsidyDetailView subsidyDetail = null;
  1169. if (o == null) {
  1170. subsidyDetail = beanSearcher.searchFirst(GoodsDonSubsidyDetailView.class, MapUtils.builder().field(GoodsDonSubsidyDetailView::getId, id).build());
  1171. if (subsidyDetail == null) {
  1172. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1173. }
  1174. subsidyDetail.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, subsidyDetail.getId()).build()));
  1175. MapBuilder builder = MapUtils.builder().field(GoodsDonSkuSubsidyDetailView::getGoodsId, subsidyDetail.getId());
  1176. subsidyDetail.setSkuList(beanSearcher.searchAll(GoodsDonSkuSubsidyDetailView.class, builder.build()));
  1177. subsidyDetail.setSold(getGoodsSold(subsidyDetail.getId(), subsidyDetail.getSold()));
  1178. redisService.setNx(goodsDetailKey, Jsons.toJson(subsidyDetail), RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
  1179. }
  1180. if (subsidyDetail == null) {
  1181. o = redisService.get(goodsDetailKey);
  1182. subsidyDetail = Jsons.parseObject(o.toString(), GoodsDonSubsidyDetailView.class);
  1183. }
  1184. return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyDetail);
  1185. }
  1186. /**
  1187. * 可选百亿补贴规格列表
  1188. */
  1189. @GetMapping("/get/available/subsidy/sku/{goodsId}")
  1190. public Result<List<GoodsDonSkuSubsidyAvailableView>> getAvailableSubsidySku(@PathVariable Long goodsId) {
  1191. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy:" + goodsId;
  1192. Object o = redisService.get(key);
  1193. if (o == null) {
  1194. List<GoodsDonSkuSubsidyAvailableView> goodsDonSkuSubsidyAvailableViews = beanSearcher.searchAll(GoodsDonSkuSubsidyAvailableView.class, MapUtils.builder().put("gid", String.format(" and goods_id = %s", goodsId)).build());
  1195. if (CollUtil.isEmpty(goodsDonSkuSubsidyAvailableViews)) {
  1196. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1197. }
  1198. redisService.set(key, goodsDonSkuSubsidyAvailableViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + RandomUtil.randomInt(10000));
  1199. o = redisService.get(key);
  1200. }
  1201. List<GoodsDonSkuSubsidyAvailableView> goodsDonSkuSubsidyAvailableViews = Jsons.parseList(o, GoodsDonSkuSubsidyAvailableView.class);
  1202. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonSkuSubsidyAvailableViews);
  1203. }
  1204. /**
  1205. * 获取用户店铺首页配置列表
  1206. */
  1207. @GetMapping("/get/shop/homeManage")
  1208. public Result<Map<String, List<HomeManagementFrontView>>> getShopHomeManageConfig(String customId) {
  1209. //是否同意展示对应首页广告位
  1210. String key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + customId + ":homeManage";
  1211. Object o = redisService.get(key);
  1212. if (o == null) {
  1213. MapBuilder builder = MapUtils.builder()
  1214. .field(HomeManagementFrontView::getType, HomeManagementConfig.Type.ad.name())
  1215. .field(HomeManagementFrontView::getIsShop, 1);
  1216. List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
  1217. if (homeManagementFrontViews == null) {
  1218. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1219. }
  1220. Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
  1221. map.putIfAbsent(HomeManagementConfig.Type.ad.name(), homeManagementFrontViews);
  1222. redisService.setNx(key, map, 50 * 60l);
  1223. o = redisService.get(key);
  1224. }
  1225. Map map = Jsons.parseObject(o, Map.class);
  1226. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  1227. }
  1228. /**
  1229. * 获取套餐列表
  1230. */
  1231. @GetMapping("/get/upgradePackage")
  1232. public Result<SearchResult<UpgradePackageView>> list(Long skuId) {
  1233. long userId = StpUserUtil.getLoginIdAsLong();
  1234. log.info("userId:{}获取套餐列表", userId);
  1235. Map<String, Object> build = MapUtils.flatBuilder(request.getParameterMap()).build();
  1236. if (skuId != null) {
  1237. build.put("sku", String.format(" and JSON_CONTAINS(up.sku_ids,'\"%s\"')", skuId));
  1238. }
  1239. SearchResult<UpgradePackageView> search = beanSearcher.search(UpgradePackageView.class, build);
  1240. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  1241. }
  1242. /**
  1243. * 获取平台销量
  1244. * @param goodsId
  1245. * @param virtualSold
  1246. * @return
  1247. */
  1248. private Integer getGoodsSold(Long goodsId, Integer virtualSold) {
  1249. Object soldObj = redisService.get(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "sold:" + goodsId);
  1250. if (soldObj == null) {
  1251. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  1252. .eq(OrderDon::getGoodsId, goodsId).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  1253. soldObj = sold + virtualSold;
  1254. redisService.set(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "sold:" + goodsId, soldObj, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  1255. }
  1256. return Integer.parseInt(soldObj.toString());
  1257. }
  1258. }