GoodsDonController.java 53 KB

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