GoodsDonController.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  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.util.Jsons;
  12. import com.cyksj.common.util.StringUtil;
  13. import com.cyksj.dto.Result;
  14. import com.cyksj.enums.GatewayResponse;
  15. import com.cyksj.mapper.GoodsDonSkuMapper;
  16. import com.cyksj.mapper.OrderDonMapper;
  17. import com.cyksj.mapper.RegisterOrderDonMapper;
  18. import com.cyksj.mapper.SysConfigMapper;
  19. import com.cyksj.model.entity.*;
  20. import com.cyksj.model.views.*;
  21. import com.cyksj.redis.RedisService;
  22. import com.cyksj.web.util.StpUserUtil;
  23. import com.ejlchina.searcher.BeanSearcher;
  24. import com.ejlchina.searcher.SearchResult;
  25. import com.ejlchina.searcher.param.Operator;
  26. import com.ejlchina.searcher.util.MapBuilder;
  27. import com.ejlchina.searcher.util.MapUtils;
  28. import lombok.RequiredArgsConstructor;
  29. import lombok.extern.slf4j.Slf4j;
  30. import org.springframework.web.bind.annotation.*;
  31. import javax.servlet.http.HttpServletRequest;
  32. import java.math.BigDecimal;
  33. import java.util.*;
  34. /**
  35. * @author chan
  36. * @date 2022/9/26 5:33 PM
  37. */
  38. @Slf4j
  39. @RestController
  40. @RequestMapping("/applets/goods")
  41. @RequiredArgsConstructor
  42. public class GoodsDonController {
  43. private final HttpServletRequest request;
  44. private final BeanSearcher beanSearcher;
  45. private final OrderDonMapper orderDonMapper;
  46. private final RegisterOrderDonMapper registerOrderDonMapper;
  47. private final GoodsDonSkuMapper goodsDonSkuMapper;
  48. private final RedisService redisService;
  49. private final SysConfigMapper sysConfigMapper;
  50. /**
  51. * 获取商品列表
  52. */
  53. @GetMapping("/get")
  54. public Result<SearchResult<GoodsDon>> get(Boolean isLogin) {
  55. Long userId = null;
  56. if (isLogin != null && isLogin) {
  57. userId = StpUserUtil.getLoginIdAsLong();
  58. }
  59. final Long fUid = userId;
  60. SearchResult<GoodsDon> search = beanSearcher.search(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap())
  61. .field(GoodsDon::getStatus, true)
  62. .field(GoodsDon::getDeleted, true)
  63. .orderBy(GoodsDon::getSortBy).desc()
  64. .orderBy(GoodsDon::getId).asc()
  65. .build()
  66. );
  67. search.getDataList().forEach(goods -> {
  68. GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectOne(Wrappers.lambdaQuery(GoodsDonSku.class).eq(GoodsDonSku::getGoodsId, goods.getId())
  69. .eq(GoodsDonSku::getStatus, true)
  70. .orderByAsc(GoodsDonSku::getPrice)
  71. .last("limit 1")
  72. .select(GoodsDonSku::getPrice));
  73. Optional.ofNullable(goodsDonSku).ifPresent(sku->{
  74. goods.setPrice(goodsDonSku.getPrice());
  75. goods.setSoldNum(goods.getVirtualSold() + orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  76. .eq(OrderDon::getGoodsId, goods.getId())
  77. .notIn(OrderDon::getStatus, Constant.noOrderStatus)));
  78. if (fUid != null) {
  79. //设置特定价格
  80. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  81. sku.setSpecificGoodsIds(null);
  82. sku.setSpecificPrice(null);
  83. }
  84. }
  85. });
  86. });
  87. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  88. }
  89. /**
  90. * 推广未登录,虚拟商品列表
  91. */
  92. @GetMapping("/get/popularize")
  93. @Deprecated
  94. public Result<SearchResult<GoodsDonPopularizeView>> getPopularizeVipGoods() {
  95. SearchResult<GoodsDonPopularizeView> search = beanSearcher.search(GoodsDonPopularizeView.class, MapUtils.flatBuilder(request.getParameterMap())
  96. .field(GoodsDonPopularizeView::getStatus, true)
  97. .field(GoodsDonPopularizeView::getDeleted, true)
  98. .field(GoodsDonPopularizeView::getType, 1)
  99. .orderBy(GoodsDonPopularizeView::getSortBy).desc()
  100. .orderBy(GoodsDonPopularizeView::getId).asc()
  101. .build());
  102. DateTime now = DateTime.now();
  103. search.getDataList().forEach(data -> {
  104. data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build()));
  105. data.setSkuList(beanSearcher.searchAll(GoodsDonSku.class, MapUtils.builder().field(GoodsDonSku::getGoodsId, data.getId()).field(GoodsDonSku::getStatus, true).orderBy(GoodsDonSku::getPrice).asc().build()));
  106. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  107. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  108. data.setSold(sold + data.getVirtualSold());
  109. Optional.ofNullable(data.getSkuList()).ifPresent(skuList -> {
  110. if (skuList.size() > 0) {
  111. GoodsDonSku goodsDonSku = skuList.get(0);
  112. data.setPrice(goodsDonSku.getPrice());
  113. data.setMonths(goodsDonSku.getMonths());
  114. }
  115. });
  116. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  117. .eq(OrderDon::getGoodsId, data.getId())
  118. .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
  119. .orderByDesc(OrderDon::getId)
  120. .last("limit 1"));
  121. StringBuilder notifyMsg = new StringBuilder();
  122. if (orderDon == null) {
  123. notifyMsg.append("点击购买立即上车");
  124. data.setNotifyMsg(notifyMsg.toString());
  125. return;
  126. } else {
  127. Date payTime = orderDon.getPayTime();
  128. Date startTime = payTime != null ? payTime : orderDon.getCreatedTime();
  129. long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
  130. if (hour == 0) {
  131. long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
  132. if (minute == 0) {
  133. notifyMsg.append("1分钟");
  134. } else {
  135. notifyMsg.append(minute);
  136. notifyMsg.append("分钟");
  137. }
  138. } else {
  139. if (hour > 3) {
  140. int hours = RandomUtil.randomInt(3) + 1;
  141. notifyMsg.append(hours);
  142. } else {
  143. notifyMsg.append(hour);
  144. }
  145. notifyMsg.append("小时");
  146. }
  147. }
  148. notifyMsg.append("前有人购买");
  149. data.setNotifyMsg(notifyMsg.toString());
  150. });
  151. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  152. }
  153. /**
  154. * 官网首页 平台列表
  155. */
  156. @GetMapping("/get/list")
  157. public Result<List<GoodsFrontListView>> getGoodsList(Boolean isLogin) {
  158. List<Long> filter_goodsIds = getFilterGoodsIds();
  159. String pcCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "PC";
  160. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  161. pcCacheKey += ":hz-ip";
  162. }
  163. Long userId = null;
  164. if (isLogin != null && isLogin) {
  165. userId = StpUserUtil.getLoginIdAsLong();
  166. }
  167. final Long fUid = userId;
  168. Object value = redisService.get(pcCacheKey);
  169. if (value != null) {
  170. try {
  171. List<GoodsFrontListView> list = Jsons.parseObject(value, List.class);
  172. if (CollUtil.isNotEmpty(list)) {
  173. //设置特定价格
  174. setSpecificPrice(list, fUid);
  175. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  176. }
  177. } catch (Exception e) {
  178. }
  179. }
  180. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  181. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  182. builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
  183. }
  184. List<GoodsFrontListView> list = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
  185. DateTime now = DateTime.now();
  186. list.forEach(data -> {
  187. data.setSpecs(beanSearcher.searchFirst(GoodsDonSpec.class, MapUtils.builder().field(GoodsDonSpec::getGoodsId, data.getId()).build()));
  188. data.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, MapUtils.builder().field(GoodsDonSkuFrontView::getGoodsId, data.getId()).field(GoodsDonSkuFrontView::getStatus, true).orderBy(GoodsDonSkuFrontView::getPrice).asc().build()));
  189. data.getSkuList().forEach(sku -> {
  190. if (sku.getIsDp()) {
  191. List<GoodsDiscountPlusPurchaseRelationFrontView> dpSkuViews = beanSearcher.searchAll(GoodsDiscountPlusPurchaseRelationFrontView.class, MapUtils.builder().field(GoodsDiscountPlusPurchaseRelationFrontView::getSkuId, sku.getId()).build());
  192. sku.setDpSkuViews(dpSkuViews);
  193. }
  194. });
  195. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  196. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  197. data.setSold(sold + data.getVirtualSold());
  198. OrderCommentFrontView comments = beanSearcher.searchFirst(OrderCommentFrontView.class, MapUtils.builder()
  199. .field(OrderCommentFrontView::getGoodsId, data.getId())
  200. .orderBy(OrderCommentFrontView::getCommentTime).desc()
  201. .orderBy(OrderCommentFrontView::getId).desc()
  202. .build());
  203. data.setComments(comments);
  204. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
  205. });
  206. redisService.setNx(pcCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  207. //设置特定价格
  208. setSpecificPrice(list, fUid);
  209. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  210. }
  211. /**
  212. * h5 银河首页平台展示
  213. */
  214. @GetMapping("/get/homePage")
  215. public Result<List<GoodsFrontListView>> getGoodsHomePage(Boolean isLogin) {
  216. List<Long> filter_goodsIds = getFilterGoodsIds();
  217. String h5CacheKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "H5";
  218. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  219. h5CacheKey += ":hz-ip";
  220. }
  221. Long userId = null;
  222. if (isLogin != null && isLogin) {
  223. userId = StpUserUtil.getLoginIdAsLong();
  224. }
  225. final Long fUid = userId;
  226. Object value = redisService.get(h5CacheKey);
  227. if (value != null) {
  228. try {
  229. List<GoodsFrontListView> list = Jsons.parseObject(value, List.class);
  230. if (CollUtil.isNotEmpty(list)) {
  231. //设置特定价格
  232. setSpecificPrice(list, fUid);
  233. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  234. }
  235. } catch (Exception e) {
  236. }
  237. }
  238. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  239. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  240. builder.field(GoodsFrontListView::getId, filter_goodsIds).op(Operator.NotIn);
  241. }
  242. List<GoodsFrontListView> dataList = beanSearcher.searchAll(GoodsFrontListView.class, builder.build());
  243. DateTime now = DateTime.now();
  244. dataList.forEach(data -> {
  245. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  246. .eq(OrderDon::getGoodsId, data.getId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  247. data.setSold(sold + data.getVirtualSold());
  248. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1));
  249. });
  250. redisService.setNx(h5CacheKey, dataList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  251. //设置特定价格
  252. setSpecificPrice(dataList, fUid);
  253. return GatewayResponse.SUCCESS.newBuilder().toResult(dataList);
  254. }
  255. /**
  256. * 注册首页平台展示
  257. */
  258. @GetMapping("/get/register")
  259. public Result<List<RegisterGoodsDonView>> getRegisterGoodsDon() {
  260. String registerCacheKey = RedisService.key.REGISTER_HOME_PAGE_CACHE.getName();
  261. Object value = redisService.get(registerCacheKey);
  262. if (value != null) {
  263. try {
  264. List<RegisterGoodsDonView> list = Jsons.parseList(value, RegisterGoodsDonView.class);
  265. if (CollUtil.isNotEmpty(list)) {
  266. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  267. }
  268. } catch (Exception e) {
  269. }
  270. }
  271. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  272. List<RegisterGoodsDonView> dataList = beanSearcher.searchAll(RegisterGoodsDonView.class, builder.build());
  273. DateTime now = DateTime.now();
  274. dataList.forEach(data->{
  275. Integer sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class)
  276. .eq(RegisterOrderDon::getGoodsId, data.getId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
  277. data.setSold(sold + data.getVirtualSold());
  278. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 2));
  279. });
  280. redisService.setNx(registerCacheKey, dataList, RedisService.key.REGISTER_HOME_PAGE_CACHE.getTimeout());
  281. return GatewayResponse.SUCCESS.newBuilder().toResult(dataList);
  282. }
  283. /**
  284. * 获取商品详情
  285. */
  286. @GetMapping("/get/{id}")
  287. public Result<GoodsDonViews> getDetail(@PathVariable Long id, Boolean isLogin) {
  288. Long userId = null;
  289. if (isLogin != null && isLogin) {
  290. userId = StpUserUtil.getLoginIdAsLong();
  291. }
  292. final Long fUid = userId;
  293. GoodsDonViews views = beanSearcher.searchFirst(GoodsDonViews.class, MapUtils.builder().field(GoodsDonViews::getId, id).build());
  294. views.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, views.getId()).build()));
  295. MapBuilder builder = MapUtils.builder().field(GoodsDonSku::getGoodsId, views.getId()).field(GoodsDonSku::getStatus, true);
  296. if (views.getType() == 1) {
  297. builder.orderBy(GoodsDonSku::getOrderBy).asc();
  298. }
  299. views.setSkuList(beanSearcher.searchAll(GoodsDonSkuFrontView.class, builder.build()));
  300. views.getSkuList().forEach(sku -> {
  301. if (sku.getIsDp()) {
  302. sku.setDpSkuViews(beanSearcher.searchAll(GoodsDiscountPlusPurchaseRelationFrontView.class, MapUtils.builder()
  303. .field(GoodsDiscountPlusPurchaseRelationFrontView::getSkuId, sku.getId())
  304. .build()));
  305. }
  306. if (fUid != null && views.getIsSp()) {
  307. //设置特定价格
  308. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  309. sku.setSpecificGoodsIds(null);
  310. sku.setSpecificPrice(null);
  311. }
  312. }
  313. });
  314. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  315. }
  316. /**
  317. * 获取商品推荐平台
  318. */
  319. @GetMapping("/get/recommend/{id}")
  320. public Result<List<GoodsFrontListView>> getRecommendGoodsByGid(@PathVariable Long id, Boolean isLogin) throws Exception {
  321. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "recommend:" + id;
  322. Object value = redisService.get(key);
  323. Long userId = null;
  324. if (isLogin != null && isLogin) {
  325. userId = StpUserUtil.getLoginIdAsLong();
  326. }
  327. final Long fUid = userId;
  328. if (value != null) {
  329. List<GoodsFrontListView> goodsRecommendViews = Jsons.parseList(value.toString(), GoodsFrontListView.class);
  330. setSpecificPrice(goodsRecommendViews, fUid);
  331. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
  332. }
  333. if (value == null) {
  334. GoodsDon goodsDon = beanSearcher.searchFirst(GoodsDon.class, MapUtils.builder()
  335. .field(GoodsDon::getId, id)
  336. .field(GoodsDon::getStatus, true)
  337. .field(GoodsDon::getDeleted, true)
  338. .build());
  339. if (goodsDon != null && StrUtil.isNotEmpty(goodsDon.getRecommendGoods())) {
  340. List<Long> recommend_gidList = Jsons.parseList(goodsDon.getRecommendGoods(), Long.class);
  341. List<GoodsFrontListView> goodsRecommendViews = beanSearcher.searchAll(GoodsFrontListView.class, MapUtils.builder().field(GoodsRecommendViews::getGoodsId, recommend_gidList).op(Operator.InList).build());
  342. goodsRecommendViews.forEach(data -> {
  343. Integer sold = registerOrderDonMapper.selectCount(Wrappers.lambdaQuery(RegisterOrderDon.class)
  344. .eq(RegisterOrderDon::getGoodsId, data.getId()).notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus));
  345. data.setSold(sold + data.getVirtualSold());
  346. });
  347. redisService.setNx(key, Jsons.toJson(goodsRecommendViews), 60 * 15l);
  348. //设置特定价格
  349. setSpecificPrice(goodsRecommendViews, fUid);
  350. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
  351. }
  352. }
  353. return GatewayResponse.SUCCESS.newBuilder().toResult();
  354. }
  355. /**
  356. * 获取商品多规格列表
  357. */
  358. @GetMapping("/get/sku")
  359. public Result<List<GoodsDonSkuView>> getGoodsDonSkuView(@RequestParam(value = "skuIds") List<Long> skuIds) {
  360. if (skuIds.isEmpty()) {
  361. return GatewayResponse.SUCCESS.newBuilder().toResult();
  362. }
  363. List<GoodsDonSkuView> views = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder()
  364. .field(GoodsDonSkuView::getSkuId, skuIds).op(Operator.InList)
  365. .build());
  366. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  367. }
  368. /**
  369. * 获取评价列表
  370. */
  371. @GetMapping("/get/comments")
  372. public Result<SearchResult<OrderCommentFrontView>> getComments() {
  373. SearchResult<OrderCommentFrontView> search = beanSearcher.search(OrderCommentFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
  374. .orderBy(OrderCommentFrontView::getCommentTime).desc()
  375. .orderBy(OrderCommentFrontView::getId).desc()
  376. .build());
  377. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  378. }
  379. public List<Long> getFilterGoodsIds() {
  380. //过滤杭州Ai ChatGPT平台
  381. //获取当前ip地址
  382. SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
  383. .eq(SysConfig::getSysKey, Constant.LOCATION_FOR_GOODS_IDS).last("limit 1"));
  384. List<Long> filter_goodsIds = null;
  385. if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
  386. if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("杭州")) {
  387. try {
  388. filter_goodsIds = Jsons.parseList(sysConfig.getSysValue(), Long.class);
  389. } catch (Exception e) {
  390. }
  391. }
  392. }
  393. return filter_goodsIds;
  394. }
  395. /**
  396. *
  397. * @param goodsId
  398. * @param type 1、普通,2、注册平台
  399. * @return
  400. */
  401. public String getPayMsgTime(Long goodsId, DateTime now, Integer type) {
  402. Date startTime = null;
  403. StringBuilder notifyMsg = new StringBuilder();
  404. if (type == 1) {
  405. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  406. .eq(OrderDon::getGoodsId, goodsId)
  407. .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
  408. .orderByDesc(OrderDon::getId)
  409. .last("limit 1"));
  410. if (orderDon == null) {
  411. notifyMsg.append("点击购买立即上车");
  412. return notifyMsg.toString();
  413. }
  414. startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
  415. } else if (type == 2) {
  416. RegisterOrderDon orderDon = registerOrderDonMapper.selectOne(Wrappers.lambdaQuery(RegisterOrderDon.class)
  417. .eq(RegisterOrderDon::getGoodsId, goodsId)
  418. .notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus).select(RegisterOrderDon::getCreatedTime, RegisterOrderDon::getPayTime, RegisterOrderDon::getId)
  419. .orderByDesc(RegisterOrderDon::getId)
  420. .last("limit 1"));
  421. if (orderDon == null) {
  422. return null;
  423. }
  424. startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
  425. }
  426. long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
  427. if (hour == 0) {
  428. long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
  429. if (minute == 0) {
  430. notifyMsg.append("1分钟");
  431. } else {
  432. notifyMsg.append(minute);
  433. notifyMsg.append("分钟");
  434. }
  435. } else {
  436. if (hour > 3) {
  437. int hours = RandomUtil.randomInt(3) + 1;
  438. notifyMsg.append(hours);
  439. } else {
  440. notifyMsg.append(hour);
  441. }
  442. notifyMsg.append("小时");
  443. }
  444. notifyMsg.append("前有人购买");
  445. return notifyMsg.toString();
  446. }
  447. /**
  448. * 是否购买过特定平台
  449. */
  450. public Boolean isPaySpecificGoodsIds(String specificGoodsIdsStr, Long userId) {
  451. if (StrUtil.isNotBlank(specificGoodsIdsStr)) {
  452. try {
  453. Set<Long> specificGoodsIds = Jsons.parseSet(specificGoodsIdsStr, Long.class);
  454. Number number = beanSearcher.searchCount(OrderDon.class, MapUtils.builder().field(OrderDon::getGoodsId, specificGoodsIds).op(Operator.InList)
  455. .field(OrderDon::getUserId, userId)
  456. .field(OrderDon::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn)
  457. .build());
  458. if (number.intValue() == 0) {
  459. return false;
  460. }
  461. return true;
  462. } catch (Exception e) {
  463. }
  464. }
  465. return false;
  466. }
  467. /**
  468. * 设置平台 特定价格
  469. */
  470. public void setSpecificPrice(List<GoodsFrontListView> list, Long fUid) {
  471. if (fUid != null) {
  472. list.forEach(data -> {
  473. if (data.getIsSp()) {
  474. //查找所有特定规格最小价格 满足条件
  475. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId();
  476. Object speciObj = redisService.get(specificGoodsKey);
  477. List<GoodsDonSku> specificSkus = null;
  478. if (speciObj != null) {
  479. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  480. } else {
  481. specificSkus = goodsDonSkuMapper.selectList(
  482. Wrappers.lambdaQuery(GoodsDonSku.class)
  483. .eq(GoodsDonSku::getGoodsId, data.getId())
  484. .eq(GoodsDonSku::getStatus, true)
  485. .gt(GoodsDonSku::getSpecificPrice, 0));
  486. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  487. }
  488. specificSkus.forEach(specificSku -> {
  489. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  490. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  491. BigDecimal specificPrice = data.getSpecificPrice();
  492. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  493. Long specificSkuId = specificSku.getId();
  494. if (specificPrice == null) {
  495. data.setSpecificPrice(skuSpecificPrice);
  496. data.setSpecificSkuId(specificSkuId);
  497. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  498. data.setSpecificPrice(skuSpecificPrice);
  499. data.setSpecificSkuId(specificSkuId);
  500. }
  501. }
  502. });
  503. List<GoodsDonSkuFrontView> skuList = data.getSkuList();
  504. if (CollUtil.isNotEmpty(skuList)) {
  505. skuList.forEach(sku->{
  506. //设置特定价格
  507. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  508. sku.setSpecificGoodsIds(null);
  509. sku.setSpecificPrice(null);
  510. }
  511. });
  512. }
  513. }
  514. });
  515. }
  516. }
  517. }