GoodsDonController.java 59 KB

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