GoodsDonController.java 23 KB

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