GoodsDonController.java 56 KB

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