GoodsDonController.java 24 KB

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