GoodsDonController.java 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543
  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.coupon.CouponUserMapper;
  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 CouponUserMapper couponUserMapper;
  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, BigDecimal discount) {
  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. //设置规格优惠后的价格
  417. sku.setChannelDiscount(discount);
  418. setUserCouponSkuMoney(fUid, sku);
  419. return true;
  420. }).collect(Collectors.toList()));
  421. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  422. }
  423. /**
  424. * 获取商品推荐平台
  425. */
  426. @GetMapping("/get/recommend/{id}")
  427. public Result<List<GoodsFrontListView>> getRecommendGoodsByGid(@PathVariable Long id, String customId, String dsCode) throws Exception {
  428. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "recommend:" + id;
  429. Long yhsId = null;
  430. if (StrUtil.isNotBlank(customId)) {
  431. yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  432. key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":recommend:" + id;
  433. }
  434. Object o = redisService.get(key);
  435. Long fUid = StpUserUtil.getUserIdAfterLogin();
  436. List<GoodsFrontListView> goodsRecommendViews = null;
  437. if (o == null) {
  438. GoodsDon goodsDon = beanSearcher.searchFirst(GoodsDon.class, MapUtils.builder()
  439. .field(GoodsDon::getId, id).field(GoodsDon::getStatus, true)
  440. .field(GoodsDon::getDeleted, true)
  441. .build());
  442. if (goodsDon != null && StrUtil.isNotEmpty(goodsDon.getRecommendGoods())) {
  443. List<Long> recommend_gidList = Jsons.parseList(goodsDon.getRecommendGoods(), Long.class);
  444. MapBuilder mapBuilder = MapUtils.builder();
  445. if (yhsId != null) {
  446. 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));
  447. }
  448. mapBuilder.field(GoodsFrontListView::getId, recommend_gidList).op(Operator.InList);
  449. goodsRecommendViews = beanSearcher.searchAll(GoodsFrontListView.class, mapBuilder.build());
  450. redisService.setNx(key, Jsons.toJson(goodsRecommendViews), 60 * 15l);
  451. o = redisService.get(key);
  452. } else {
  453. return GatewayResponse.SUCCESS.newBuilder().toResult();
  454. }
  455. }
  456. if (goodsRecommendViews == null) {
  457. goodsRecommendViews = Jsons.parseList(o.toString(), GoodsFrontListView.class);
  458. }
  459. AtomicLong dsUserId = new AtomicLong();
  460. AtomicBoolean existsChannel = new AtomicBoolean(true);
  461. if (StrUtil.isNotBlank(dsCode)) {
  462. UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
  463. dsUserId.set(userSharedDto.getSharedId());
  464. }
  465. goodsRecommendViews = goodsRecommendViews.stream().filter(data -> {
  466. if (data.getIsOwns()) {
  467. if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
  468. Long sharedId = userService.getSharedIdByUserId(fUid);
  469. if (sharedId == 0) {
  470. existsChannel.set(false);
  471. }
  472. dsUserId.set(sharedId);
  473. }
  474. GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getId(), dsUserId.get());
  475. if (minPriceUserOwnsSku == null) {
  476. return false;
  477. }
  478. data.setPrice(minPriceUserOwnsSku.getPrice());
  479. data.setMonths(minPriceUserOwnsSku.getMonths());
  480. data.setDays(minPriceUserOwnsSku.getDays());
  481. }
  482. //销量
  483. data.setSold(getGoodsSold(data.getId(), data.getSold()));
  484. //设置特定价格
  485. setSpecificPrice(data, fUid, dsUserId.get());
  486. return true;
  487. }).collect(Collectors.toList());
  488. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsRecommendViews);
  489. }
  490. /**
  491. * 获取商品多规格列表
  492. */
  493. @GetMapping("/get/sku")
  494. public Result<List<GoodsDonSkuView>> getGoodsDonSkuView(@RequestParam(value = "skuIds") List<Long> skuIds) {
  495. if (skuIds.isEmpty()) {
  496. return GatewayResponse.SUCCESS.newBuilder().toResult();
  497. }
  498. List<GoodsDonSkuView> views = beanSearcher.searchAll(GoodsDonSkuView.class, MapUtils.builder()
  499. .field(GoodsDonSkuView::getSkuId, skuIds).op(Operator.InList)
  500. .build());
  501. return GatewayResponse.SUCCESS.newBuilder().toResult(views);
  502. }
  503. /**
  504. * 获取评价列表
  505. */
  506. @GetMapping("/get/comments")
  507. public Result<SearchResult<OrderCommentFrontView>> getComments() {
  508. SearchResult<OrderCommentFrontView> search = beanSearcher.search(OrderCommentFrontView.class, MapUtils.flatBuilder(request.getParameterMap())
  509. .orderBy(OrderCommentFrontView::getCommentTime).desc()
  510. .orderBy(OrderCommentFrontView::getId).desc()
  511. .build());
  512. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  513. }
  514. /**
  515. * 获取礼品卡平台性情
  516. */
  517. @GetMapping("/get/card/{id}")
  518. public Result<Map<Integer, List<GiftCardGoodsSkuFrontView>>> getGiftCardDetail(@PathVariable Long id) {
  519. List<GiftCardGoodsSkuFrontView> giftCardGoodsSkuFrontViews = beanSearcher.searchAll(GiftCardGoodsSkuFrontView.class, MapUtils.builder().field(GiftCardGoodsSkuFrontView::getGoodsId, id).build());
  520. Map<Integer, List<GiftCardGoodsSkuFrontView>> map = giftCardGoodsSkuFrontViews.stream().collect(Collectors.groupingBy(GiftCardGoodsSkuFrontView::getGcType));
  521. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  522. }
  523. /**
  524. * 获取首页配置列表
  525. */
  526. @GetMapping("/get/homeManage")
  527. public Result<Map<String, List<HomeManagementFrontView>>> getHomeManagementFrontPage(String customId, String dsCode, BigDecimal discount) {
  528. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "homeManage";
  529. Long yhsId = null;
  530. if (StrUtil.isNotBlank(customId)) {
  531. yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
  532. key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":homeManage";
  533. }
  534. // List<Long> filter_goodsIds = getFilterGoodsIds();
  535. List<Long> filter_goodsIds = null;
  536. AtomicBoolean isRemoveRg = new AtomicBoolean(false);
  537. // if (isHzIp()) {
  538. // key += ":hz-ip";
  539. // isRemoveRg.set(true);
  540. // }
  541. Long fUid = StpUserUtil.getUserIdAfterLogin();
  542. Object o = redisService.get(key);
  543. if (o == null) {
  544. String condition = "g.deleted is true and g.status is true";
  545. if (yhsId != null) {
  546. 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);
  547. }
  548. Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
  549. final String conditionSql = condition;
  550. Stream.of(HomeManagementConfig.Type.values())
  551. .forEach(type -> {
  552. if (isRemoveRg.get() && type == HomeManagementConfig.Type.rg) {
  553. return;
  554. }
  555. MapBuilder builder = MapUtils.builder()
  556. .field(HomeManagementFrontView::getType, type.name());
  557. if (type == HomeManagementConfig.Type.ex || type == HomeManagementConfig.Type.vg) {
  558. builder.put("condition", conditionSql);
  559. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  560. builder.field(HomeManagementFrontView::getGoodsId, filter_goodsIds).op(Operator.NotIn);
  561. }
  562. }
  563. List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
  564. map.putIfAbsent(type.name(), homeManagementFrontViews);
  565. });
  566. redisService.setNx(key, map, 50 * 60l);
  567. o = redisService.get(key);
  568. }
  569. AtomicLong dsUserId = new AtomicLong();
  570. AtomicBoolean existsChannel = new AtomicBoolean(true);
  571. if (StrUtil.isNotBlank(dsCode)) {
  572. UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
  573. dsUserId.set(userSharedDto.getSharedId());
  574. }
  575. Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
  576. if (map.containsKey(HomeManagementConfig.Type.ex.name()) || map.containsKey(HomeManagementConfig.Type.vg.name())) {
  577. try {
  578. //精彩推荐
  579. List<HomeManagementFrontView> exList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.ex.name())), HomeManagementFrontView.class);
  580. setHomeConfigGoods(map, HomeManagementConfig.Type.ex, exList, dsUserId, existsChannel, fUid, discount);
  581. //虚拟平台
  582. List<HomeManagementFrontView> vgList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.vg.name())), HomeManagementFrontView.class);
  583. setHomeConfigGoods(map, HomeManagementConfig.Type.vg, vgList, dsUserId, existsChannel, fUid, discount);
  584. } catch (Exception e) {
  585. }
  586. }
  587. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  588. }
  589. /**
  590. * 首页点击 记录
  591. */
  592. @PostMapping("/homePage/click")
  593. public Result<String> homeManageClick(@RequestBody ClickRecordReq request) {
  594. Long userId = StpUserUtil.getUserIdAfterLogin();
  595. clickRecordFrontService.click(userId, request);
  596. return GatewayResponse.SUCCESS.newBuilder().toResult();
  597. }
  598. public List<Long> getFilterGoodsIds() {
  599. List<Long> filter_goodsIds = null;
  600. //获取当前ip地址
  601. if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("杭州")) {
  602. //过滤杭州Ai ChatGPT平台
  603. SysConfig sysConfig = sysConfigMapper.selectOne(Wrappers.lambdaQuery(SysConfig.class)
  604. .eq(SysConfig::getSysKey, Constant.LOCATION_FOR_GOODS_IDS).last("limit 1"));
  605. if (sysConfig != null && StrUtil.isNotBlank(sysConfig.getSysValue())) {
  606. try {
  607. filter_goodsIds = Jsons.parseList(sysConfig.getSysValue(), Long.class);
  608. } catch (Exception e) {
  609. }
  610. }
  611. }
  612. return filter_goodsIds;
  613. }
  614. public Boolean isHzIp() {
  615. if (StringUtil.getRealAddressByIP(ServletUtil.getClientIP(request)).contains("无锡")) {
  616. return true;
  617. }
  618. return false;
  619. }
  620. /**
  621. * @param goodsId
  622. * @param type 1、普通,2、注册平台
  623. * @param yhsId 店铺id
  624. * @return
  625. */
  626. public String getPayMsgTime(Long goodsId, DateTime now, Integer type, Long yhsId) {
  627. Date startTime = null;
  628. StringBuilder notifyMsg = new StringBuilder();
  629. if (type == 1) {
  630. OrderDon orderDon = orderDonMapper.selectOne(Wrappers.lambdaQuery(OrderDon.class)
  631. .eq(OrderDon::getGoodsId, goodsId)
  632. .notIn(OrderDon::getStatus, Constant.noOrderStatus).select(OrderDon::getCreatedTime, OrderDon::getPayTime, OrderDon::getId)
  633. .eq(yhsId != null, OrderDon::getYhsId, yhsId)
  634. .orderByDesc(OrderDon::getId)
  635. .last("limit 1"));
  636. if (orderDon == null) {
  637. notifyMsg.append("点击购买立即上车");
  638. return notifyMsg.toString();
  639. }
  640. startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
  641. } else if (type == 2) {
  642. RegisterOrderDon orderDon = registerOrderDonMapper.selectOne(Wrappers.lambdaQuery(RegisterOrderDon.class)
  643. .eq(RegisterOrderDon::getGoodsId, goodsId)
  644. .notIn(RegisterOrderDon::getStatus, Constant.noOrderStatus).select(RegisterOrderDon::getCreatedTime, RegisterOrderDon::getPayTime, RegisterOrderDon::getId)
  645. .orderByDesc(RegisterOrderDon::getId)
  646. .last("limit 1"));
  647. if (orderDon == null) {
  648. return null;
  649. }
  650. startTime = orderDon.getPayTime() != null ? orderDon.getPayTime() : orderDon.getCreatedTime();
  651. }
  652. long hour = DateUtil.between(startTime, now, DateUnit.HOUR);
  653. if (hour == 0) {
  654. long minute = DateUtil.between(startTime, now, DateUnit.MINUTE);
  655. if (minute == 0) {
  656. notifyMsg.append("1分钟");
  657. } else {
  658. notifyMsg.append(minute);
  659. notifyMsg.append("分钟");
  660. }
  661. } else {
  662. if (hour > 3) {
  663. int hours = RandomUtil.randomInt(3) + 1;
  664. notifyMsg.append(hours);
  665. } else {
  666. notifyMsg.append(hour);
  667. }
  668. notifyMsg.append("小时");
  669. }
  670. notifyMsg.append("前有人购买");
  671. return notifyMsg.toString();
  672. }
  673. /**
  674. * 是否购买过特定平台
  675. */
  676. public Boolean isPaySpecificGoodsIds(String specificGoodsIdsStr, Long userId) {
  677. if (StrUtil.isNotBlank(specificGoodsIdsStr)) {
  678. try {
  679. Set<Long> specificGoodsIds = Jsons.parseSet(specificGoodsIdsStr, Long.class);
  680. Number number = beanSearcher.searchCount(OrderDon.class, MapUtils.builder().field(OrderDon::getGoodsId, specificGoodsIds).op(Operator.InList)
  681. .field(OrderDon::getUserId, userId)
  682. .field(OrderDon::getStatus, Constant.noOrderAllStatus).op(Operator.NotIn)
  683. .build());
  684. if (number.intValue() == 0) {
  685. return false;
  686. }
  687. return true;
  688. } catch (Exception e) {
  689. }
  690. }
  691. return false;
  692. }
  693. /**
  694. * 设置平台 特定价格
  695. */
  696. public void setSpecificPrice(GoodsFrontListView data, Long fUid, Long dsUserId) {
  697. if (fUid != null) {
  698. if (data.getIsSp()) {
  699. //查找所有特定规格最小价格 满足条件
  700. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId();
  701. Object speciObj = redisService.get(specificGoodsKey);
  702. List<GoodsDonSku> specificSkus = null;
  703. if (speciObj != null) {
  704. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  705. } else {
  706. specificSkus = goodsDonSkuMapper.selectList(
  707. Wrappers.lambdaQuery(GoodsDonSku.class)
  708. .eq(GoodsDonSku::getGoodsId, data.getId())
  709. .eq(GoodsDonSku::getStatus, true)
  710. .gt(GoodsDonSku::getSpecificPrice, 0));
  711. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  712. }
  713. specificSkus.forEach(specificSku -> {
  714. if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) {
  715. return;
  716. }
  717. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  718. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  719. BigDecimal specificPrice = data.getSpecificPrice();
  720. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  721. Long specificSkuId = specificSku.getId();
  722. if (specificPrice == null) {
  723. data.setSpecificPrice(skuSpecificPrice);
  724. data.setSpecificSkuId(specificSkuId);
  725. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  726. data.setSpecificPrice(skuSpecificPrice);
  727. data.setSpecificSkuId(specificSkuId);
  728. }
  729. }
  730. });
  731. List<GoodsDonSkuFrontView> skuList = data.getSkuList();
  732. if (CollUtil.isNotEmpty(skuList)) {
  733. skuList.forEach(sku -> {
  734. //设置特定价格
  735. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  736. sku.setSpecificGoodsIds(null);
  737. sku.setSpecificPrice(null);
  738. }
  739. });
  740. }
  741. }
  742. }
  743. }
  744. /**
  745. * 设置平台 特定价格
  746. */
  747. public void setGcSpecificPrice(GoodsFrontListCategoryView data, Long fUid, Long dsUserId) {
  748. if (fUid != null) {
  749. if (data.getIsSp()) {
  750. //查找所有特定规格最小价格 满足条件
  751. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + data.getId();
  752. Object speciObj = redisService.get(specificGoodsKey);
  753. List<GoodsDonSku> specificSkus = null;
  754. if (speciObj != null) {
  755. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  756. } else {
  757. specificSkus = goodsDonSkuMapper.selectList(
  758. Wrappers.lambdaQuery(GoodsDonSku.class)
  759. .eq(GoodsDonSku::getGoodsId, data.getId())
  760. .eq(GoodsDonSku::getStatus, true)
  761. .gt(GoodsDonSku::getSpecificPrice, 0));
  762. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  763. }
  764. specificSkus.forEach(specificSku -> {
  765. if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) {
  766. return;
  767. }
  768. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  769. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  770. BigDecimal specificPrice = data.getSpecificPrice();
  771. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  772. Long specificSkuId = specificSku.getId();
  773. if (specificPrice == null) {
  774. data.setSpecificPrice(skuSpecificPrice);
  775. data.setSpecificSkuId(specificSkuId);
  776. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  777. data.setSpecificPrice(skuSpecificPrice);
  778. data.setSpecificSkuId(specificSkuId);
  779. }
  780. }
  781. });
  782. List<GoodsDonSkuFrontView> skuList = data.getSkuList();
  783. if (CollUtil.isNotEmpty(skuList)) {
  784. skuList.forEach(sku -> {
  785. //设置特定价格
  786. if (!isPaySpecificGoodsIds(sku.getSpecificGoodsIds(), fUid)) {
  787. sku.setSpecificGoodsIds(null);
  788. sku.setSpecificPrice(null);
  789. }
  790. });
  791. }
  792. }
  793. }
  794. }
  795. /**
  796. * 获取特定规格
  797. */
  798. public List<GoodsDonSku> getSpecificSku(Long goodsId) {
  799. //查找所有特定规格最小价格 满足条件
  800. String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "specific:" + goodsId;
  801. Object speciObj = redisService.get(specificGoodsKey);
  802. List<GoodsDonSku> specificSkus = null;
  803. if (speciObj != null) {
  804. specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
  805. } else {
  806. specificSkus = goodsDonSkuMapper.selectList(
  807. Wrappers.lambdaQuery(GoodsDonSku.class)
  808. .eq(GoodsDonSku::getGoodsId, goodsId)
  809. .eq(GoodsDonSku::getStatus, true)
  810. .gt(GoodsDonSku::getSpecificPrice, 0));
  811. redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  812. }
  813. specificSkus = Optional.ofNullable(specificSkus).orElse(new ArrayList<>());
  814. return specificSkus;
  815. }
  816. /**
  817. * 设置首页配置 涉及平台特定价格
  818. */
  819. public void setHomeManageSpecific(List<HomeManagementFrontView> list, Long fUid, Long dsUserId, BigDecimal discount) {
  820. DateTime now = DateTime.now();
  821. list.forEach(data -> {
  822. if (data.getIsSp() != null && data.getIsSp() && fUid != null) {
  823. //查找所有特定规格最小价格 满足条件
  824. List<GoodsDonSku> specificSkus = getSpecificSku(data.getGoodsId());
  825. specificSkus.forEach(specificSku -> {
  826. if (StrUtil.isNotEmpty(specificSku.getUserOwns()) && (dsUserId == null || !specificSku.getUserOwns().contains(dsUserId.toString()))) {
  827. return;
  828. }
  829. String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
  830. if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
  831. BigDecimal specificPrice = data.getSpecificPrice();
  832. BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
  833. Long specificSkuId = specificSku.getId();
  834. if (specificPrice == null) {
  835. data.setSpecificPrice(skuSpecificPrice);
  836. data.setSpecificSkuId(specificSkuId);
  837. } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
  838. data.setSpecificPrice(skuSpecificPrice);
  839. data.setSpecificSkuId(specificSkuId);
  840. }
  841. }
  842. });
  843. }
  844. data.setSold(getGoodsSold(data.getGoodsId(), data.getSold()));
  845. data.setNotifyMsg(getPayMsgTime(data.getGoodsId(), now, 1, null));
  846. //设置用户存在优惠券的优惠商品价格
  847. data.setChannelDiscount(discount);
  848. setHomeManageUserCouponGoodsMoney(fUid, data);
  849. });
  850. }
  851. public void setHomeConfigGoods(Map<String, List<HomeManagementFrontView>> map, HomeManagementConfig.Type type, List<HomeManagementFrontView> list, AtomicLong dsUserId, AtomicBoolean existsChannel, Long fUid, BigDecimal discount) throws Exception {
  852. //设置特定价格
  853. if (CollUtil.isNotEmpty(list)) {
  854. list = list.stream().filter(data -> {
  855. if (data.getIsOwns()) {
  856. if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
  857. Long sharedId = userService.getSharedIdByUserId(fUid);
  858. if (sharedId == 0) {
  859. existsChannel.set(false);
  860. }
  861. dsUserId.set(sharedId);
  862. }
  863. GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getGoodsId(), dsUserId.get());
  864. if (minPriceUserOwnsSku == null) {
  865. return false;
  866. }
  867. data.setPrice(minPriceUserOwnsSku.getPrice());
  868. data.setMonths(minPriceUserOwnsSku.getMonths());
  869. data.setDays(minPriceUserOwnsSku.getDays());
  870. }
  871. return true;
  872. }).collect(Collectors.toList());
  873. setHomeManageSpecific(list, fUid, dsUserId.get(), discount);
  874. map.put(type.name(), list);
  875. }
  876. }
  877. /**
  878. * 店铺平台列表
  879. */
  880. @GetMapping("/get/shop/goods/{yhsId}")
  881. public Result<List<YhShopGoodsFrontView>> getShopGoods(@PathVariable Long yhsId) {
  882. String yhShopCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId;
  883. Object value = redisService.get(yhShopCacheKey);
  884. List<YhShopGoodsFrontView> list = null;
  885. if (value != null) {
  886. try {
  887. list = Jsons.parseList(value, YhShopGoodsFrontView.class);
  888. } catch (Exception e) {
  889. }
  890. }
  891. if (CollUtil.isEmpty(list)) {
  892. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  893. builder.put("condition", String.format("and yhs_id = %s", yhsId));
  894. list = beanSearcher.searchAll(YhShopGoodsFrontView.class, builder.build());
  895. redisService.setNx(yhShopCacheKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  896. }
  897. DateTime now = DateTime.now();
  898. list.forEach(data -> {
  899. data.setSold(getGoodsSold(data.getId(), data.getSold()));
  900. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
  901. Optional.ofNullable(yhShopGoodsSkuMapper.selectOne(Wrappers.lambdaQuery(YhShopGoodsSku.class)
  902. .eq(YhShopGoodsSku::getYhsId, yhsId)
  903. .eq(YhShopGoodsSku::getGoodsId, data.getId())
  904. .eq(YhShopGoodsSku::getPrice, data.getPrice())
  905. .eq(YhShopGoodsSku::getStatus, 1)
  906. .eq(YhShopGoodsSku::getDeleted, 1)
  907. .last("limit 1"))).ifPresent(yhSku -> {
  908. GoodsDonSku sku = goodsDonSkuMapper.selectById(yhSku.getSkuId());
  909. if (sku != null) {
  910. data.setMonths(sku.getMonths());
  911. data.setDays(sku.getDays());
  912. }
  913. });
  914. });
  915. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  916. }
  917. /**
  918. * 店铺平台详情
  919. */
  920. @GetMapping("/get/shop/goods/detail/{yhsId}/{goodsId}")
  921. public Result<YhShopGoodsFrontView> getGoodsDetailByYhsId(@PathVariable Long yhsId, @PathVariable Long goodsId) {
  922. String yhShopDetailCacheKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":goodsId:" + goodsId;
  923. Object value = redisService.get(yhShopDetailCacheKey);
  924. if (value == null) {
  925. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  926. String condition = String.format("and yhs_id = %s and ys.goods_id = %s", yhsId, goodsId);
  927. builder.put("condition", condition);
  928. YhShopGoodsFrontView goodsDetailView = beanSearcher.searchFirst(YhShopGoodsFrontView.class, builder.build());
  929. if (goodsDetailView == null) {
  930. throw BusinessRuntimeException.getInstance("该平台不存在或已下架,请刷新页面");
  931. }
  932. goodsDetailView.setSkuList(beanSearcher.searchAll(YhShopGoodsSkuFrontView.class, MapUtils.builder().put("condition", condition).orderBy(YhShopGoodsSkuFrontView::getSorted).asc().build()));
  933. goodsDetailView.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, goodsDetailView.getId()).build()));
  934. OrderCommentFrontView comments = beanSearcher.searchFirst(OrderCommentFrontView.class, MapUtils.builder()
  935. .field(OrderCommentFrontView::getGoodsId, goodsDetailView.getId())
  936. .orderBy(OrderCommentFrontView::getCommentTime).desc()
  937. .orderBy(OrderCommentFrontView::getId).desc()
  938. .build());
  939. goodsDetailView.setComments(comments);
  940. redisService.setNx(yhShopDetailCacheKey, goodsDetailView, RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getTimeout() + RandomUtil.randomInt(1000));
  941. value = redisService.get(yhShopDetailCacheKey);
  942. }
  943. YhShopGoodsFrontView goodsDetailView = Jsons.parseObject(value, YhShopGoodsFrontView.class);
  944. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDetailView);
  945. }
  946. /**
  947. * 根据分类获取对应平台
  948. */
  949. @GetMapping("/get/categoryGoods")
  950. public Result<? extends Object> getGoodsByCategory(Long cgy, String customId, String dsCode, BigDecimal discount) {
  951. if (StrUtil.isNotBlank(customId)) {
  952. Result<List<YhShopGoodsFrontCategoryView>> shopGoods = getShopCategoryGoods(yhShopFrontService.getYhsIdByCustomId(customId), cgy);
  953. return shopGoods;
  954. }
  955. Long fUid = StpUserUtil.getUserIdAfterLogin();
  956. String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "category:goods";
  957. if (cgy != null) {
  958. categoryGoodsKey += ":" + cgy;
  959. }
  960. //List<Long> filter_goodsIds = getFilterGoodsIds();
  961. List<Long> filter_goodsIds = null;
  962. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  963. categoryGoodsKey += ":hz-ip";
  964. }
  965. Object o = redisService.get(categoryGoodsKey);
  966. if (o == null) {
  967. DateTime now = DateTime.now();
  968. MapBuilder mapBuilder = MapUtils.flatBuilder(request.getParameterMap());
  969. if (cgy != null) {
  970. String condition = String.format(" and gcr.category = %s", cgy);
  971. mapBuilder.put("condition", condition);
  972. }
  973. if (CollUtil.isNotEmpty(filter_goodsIds)) {
  974. mapBuilder.field(GoodsFrontListCategoryView::getId, filter_goodsIds).op(Operator.NotIn);
  975. }
  976. List<GoodsFrontListCategoryView> goodsFrontListViews = beanSearcher.searchAll(GoodsFrontListCategoryView.class, mapBuilder.build());
  977. goodsFrontListViews.forEach(data -> {
  978. data.setSold(getGoodsSold(data.getId(), data.getSold()));
  979. ;
  980. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, null));
  981. });
  982. redisService.setNx(categoryGoodsKey, goodsFrontListViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 10 * 60);
  983. o = redisService.get(categoryGoodsKey);
  984. }
  985. List<GoodsFrontListCategoryView> goodsFrontListViews = Jsons.parseList(o, GoodsFrontListCategoryView.class);
  986. AtomicLong dsUserId = new AtomicLong();
  987. AtomicBoolean existsChannel = new AtomicBoolean(true);
  988. if (StrUtil.isNotBlank(dsCode)) {
  989. UserSharedDto userSharedDto = userService.getUserShredDtoByDsCode(dsCode);
  990. dsUserId.set(userSharedDto.getSharedId());
  991. }
  992. AtomicBoolean filterCourseGoods = new AtomicBoolean(false);
  993. //增值服务分类
  994. if (fUid != null && cgy != null && (cgy == 3 || cgy == 4)) {
  995. //GPT Plus基础2月 课程不展示
  996. List<Long> userIdList = userBindRelationService.getRelationUserIdList(fUid, null);
  997. Integer orders = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  998. .in(OrderDon::getUserId, userIdList)
  999. .eq(OrderDon::getSkuId, 444)
  1000. .notIn(OrderDon::getStatus, Constant.noOrderStatus));
  1001. if (orders > 0) {
  1002. filterCourseGoods.set(true);
  1003. }
  1004. }
  1005. goodsFrontListViews = goodsFrontListViews.stream().filter(data -> {
  1006. if (data.getIsOwns()) {
  1007. if (dsUserId.get() == 0 && fUid != null && existsChannel.get()) {
  1008. Long sharedId = userService.getSharedIdByUserId(fUid);
  1009. if (sharedId == 0) {
  1010. existsChannel.set(false);
  1011. }
  1012. dsUserId.set(sharedId);
  1013. }
  1014. GoodsDonSku minPriceUserOwnsSku = goodsDonSkuMapper.checkAndReturnMinPriceUserOwnsSku(data.getId(), dsUserId.get());
  1015. if (minPriceUserOwnsSku == null) {
  1016. return false;
  1017. }
  1018. data.setPrice(minPriceUserOwnsSku.getPrice());
  1019. data.setMonths(minPriceUserOwnsSku.getMonths());
  1020. data.setDays(minPriceUserOwnsSku.getDays());
  1021. }
  1022. //课件类型 且过滤
  1023. if (filterCourseGoods.get() && data.getSpecialType() != null && data.getSpecialType() == GoodsDon.SpecialType.courseware) {
  1024. return false;
  1025. }
  1026. //设置特定价格
  1027. setGcSpecificPrice(data, fUid, dsUserId.get());
  1028. //设置用户存在优惠券的优惠商品价格
  1029. data.setChannelDiscount(discount);
  1030. setUserCouponGoodsMoney(fUid, data);
  1031. return true;
  1032. }).collect(Collectors.toList());
  1033. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsFrontListViews);
  1034. }
  1035. @GetMapping("/get/shop/categoryGoods/{yhsId}")
  1036. public Result<List<YhShopGoodsFrontCategoryView>> getShopCategoryGoods(@PathVariable Long yhsId, Long category) {
  1037. String categoryGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + yhsId + ":category";
  1038. if (category != null) {
  1039. categoryGoodsKey += ":" + category;
  1040. }
  1041. Object value = redisService.get(categoryGoodsKey);
  1042. if (value == null) {
  1043. DateTime now = DateTime.now();
  1044. MapBuilder builder = MapUtils.flatBuilder(request.getParameterMap());
  1045. builder.put("yhsId", String.format(" and yhs_id = %s", yhsId));
  1046. String condition = StrUtil.EMPTY;
  1047. if (category != null) {
  1048. condition += String.format(" and gcr.category = %s", category);
  1049. }
  1050. builder.put("condition", condition);
  1051. List<YhShopGoodsFrontCategoryView> list = beanSearcher.searchAll(YhShopGoodsFrontCategoryView.class, builder.build());
  1052. list.forEach(data->{
  1053. data.setSold(getGoodsSold(data.getId(), data.getSold()));
  1054. data.setNotifyMsg(getPayMsgTime(data.getId(), now, 1, yhsId));
  1055. //重新设置最低价格规格
  1056. YhShopGoodsSku sku = yhShopGoodsSkuMapper.selectMinPriceSkuByYhsId(yhsId, data.getId());
  1057. data.setPrice(sku.getPrice());
  1058. data.setSkuId(sku.getSkuId());
  1059. });
  1060. redisService.setNx(categoryGoodsKey, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 5 * 60);
  1061. value = redisService.get(categoryGoodsKey);
  1062. }
  1063. List<YhShopGoodsFrontCategoryView> list = Jsons.parseList(value, YhShopGoodsFrontCategoryView.class);
  1064. list.forEach(data->{
  1065. Optional.ofNullable(yhShopGoodsSkuMapper.selectOne(Wrappers.lambdaQuery(YhShopGoodsSku.class)
  1066. .eq(YhShopGoodsSku::getYhsId, yhsId)
  1067. .eq(YhShopGoodsSku::getGoodsId, data.getId())
  1068. .eq(YhShopGoodsSku::getPrice, data.getPrice())
  1069. .eq(YhShopGoodsSku::getStatus, 1)
  1070. .eq(YhShopGoodsSku::getDeleted, 1)
  1071. .last("limit 1"))).ifPresent(yhSku -> {
  1072. GoodsDonSku sku = goodsDonSkuMapper.selectById(yhSku.getSkuId());
  1073. if (sku != null) {
  1074. data.setMonths(sku.getMonths());
  1075. data.setDays(sku.getDays());
  1076. }
  1077. });
  1078. });
  1079. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  1080. }
  1081. /**
  1082. * 获取设备活动详情
  1083. */
  1084. @GetMapping("/get/equipment/activity")
  1085. public Result<EquipmentActivityReduce> getEpActivity() {
  1086. DateTime now = DateTime.now();
  1087. EquipmentActivityReduce equipmentActivityReduce = beanSearcher.searchFirst(EquipmentActivityReduce.class, MapUtils.builder()
  1088. .field(EquipmentActivityReduce::getSt, now).op(Operator.LessEqual)
  1089. .field(EquipmentActivityReduce::getEt, now).op(Operator.GreaterThan)
  1090. .field(EquipmentActivityReduce::getDeleted, 1)
  1091. .onlySelect(EquipmentActivityReduce::getF, EquipmentActivityReduce::getQ, EquipmentActivityReduce::getTq, EquipmentActivityReduce::getSt, EquipmentActivityReduce::getEt)
  1092. .build());
  1093. return GatewayResponse.SUCCESS.newBuilder().toResult(equipmentActivityReduce);
  1094. }
  1095. /**
  1096. * 获取租赁商品列表
  1097. */
  1098. @GetMapping("/get/deposit")
  1099. public Result<? extends Object> getDepositGoods() {
  1100. String depositGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "deposit";
  1101. Object o = redisService.get(depositGoodsKey);
  1102. if (o == null) {
  1103. List<GoodsDon> depositList = beanSearcher.searchAll(GoodsDon.class, MapUtils.builder()
  1104. .field(GoodsDon::getType, 4)
  1105. .field(GoodsDon::getStatus, true)
  1106. .field(GoodsDon::getDeleted, true)
  1107. .onlySelect(GoodsDon::getId, GoodsDon::getTitle, GoodsDon::getLogo)
  1108. .build());
  1109. if (CollUtil.isEmpty(depositList)) {
  1110. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1111. }
  1112. redisService.setNx(depositGoodsKey, depositList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
  1113. o = redisService.get(depositGoodsKey);
  1114. }
  1115. List<GoodsDon> depositList = Jsons.parseList(o, GoodsDon.class);
  1116. return GatewayResponse.SUCCESS.newBuilder().toResult(depositList);
  1117. }
  1118. /**
  1119. * 获取pc广告配置
  1120. */
  1121. @GetMapping("/get/pc/homeManage")
  1122. public Result<Map<String, List<HomeManagementFrontView>>> getPcHomeManagementFrontPage() {
  1123. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "pc:homeManage";
  1124. //移除奈飞客厅 临时
  1125. Long filterConfigId = null;
  1126. // if (isHzIp()) {
  1127. // key += ":hz_ip";
  1128. // filterConfigId = 55l;
  1129. // }
  1130. Object o = redisService.get(key);
  1131. if (o == null) {
  1132. MapBuilder builder = MapUtils.builder()
  1133. .field(HomeManagementFrontView::getAdType, List.of(HomeManagementConfig.AdType.pc.name(), HomeManagementConfig.AdType.pcSec.name(), HomeManagementConfig.AdType.pcDis.name())).op(Operator.InList);
  1134. if (filterConfigId != null) {
  1135. builder.field(HomeManagementFrontView::getHomeManageConfigId, filterConfigId).op(Operator.NotEqual);
  1136. }
  1137. List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
  1138. Map<HomeManagementConfig.AdType, List<HomeManagementFrontView>> map = homeManagementFrontViews.stream().collect(Collectors.groupingBy(HomeManagementFrontView::getAdType));
  1139. redisService.setNx(key, map, 50 * 60l);
  1140. o = redisService.get(key);
  1141. }
  1142. Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
  1143. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  1144. }
  1145. /**
  1146. * 获取pc实物配置
  1147. */
  1148. @GetMapping("/get/pc/realGoodsConfig")
  1149. public Result<? extends Object> getPcRealGoodsConfig() throws Exception {
  1150. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "pc:realHomePage";
  1151. Object o = redisService.get(key);
  1152. List<HomeManagementFrontView> list = null;
  1153. if (o == null) {
  1154. list = goodsDonFrontService.getRealGoodsConfig();
  1155. redisService.setNx(key, list, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 300);
  1156. }
  1157. if (list == null && o != null) {
  1158. list = Jsons.parseList(o, HomeManagementFrontView.class);
  1159. }
  1160. return GatewayResponse.SUCCESS.newBuilder().toResult(list);
  1161. }
  1162. /**
  1163. * 百亿补贴
  1164. * 补贴规格列表
  1165. */
  1166. @GetMapping("/get/subsidy")
  1167. public Result<List<GoodsDonSkuSubsidyFrontView>> getSubsidyGoods() {
  1168. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy";
  1169. Object o = redisService.get(key);
  1170. if (o == null) {
  1171. List<GoodsDonSkuSubsidyFrontView> subsidyList = beanSearcher.searchAll(GoodsDonSkuSubsidyFrontView.class, MapUtils.builder().build());
  1172. subsidyList.forEach(e -> {
  1173. Optional.ofNullable(beanSearcher.searchFirst(GoodsDonSkuSubsidyDetailView.class, MapUtils.builder().field(GoodsDonSkuSubsidyDetailView::getGoodsId, e.getId()).field(GoodsDonSkuSubsidyDetailView::getPrice, e.getPrice()).build())).ifPresent(sku -> {
  1174. e.setOriPrice(sku.getOriPrice());
  1175. e.setMonths(sku.getMonths());
  1176. e.setDays(sku.getDays());
  1177. e.setSkuId(sku.getId());
  1178. e.setPicture(sku.getSubsidyPicture());
  1179. });
  1180. });
  1181. redisService.setNx(key, subsidyList, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
  1182. o = redisService.get(key);
  1183. }
  1184. List<GoodsDonSkuSubsidyFrontView> subsidyList = Jsons.parseList(o, GoodsDonSkuSubsidyFrontView.class);
  1185. if (CollUtil.isEmpty(subsidyList)) {
  1186. return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyList);
  1187. }
  1188. Long userId = StpUserUtil.getUserIdAfterLogin();
  1189. if (userId != null) {
  1190. List<Long> relationUserIdList = userBindRelationService.getRelationUserIdList(userId, null);
  1191. //过滤用户已经购买过平台
  1192. List<Long> goodsIds = orderDonMapper.getPayGoodsIds(relationUserIdList);
  1193. if (CollUtil.isNotEmpty(goodsIds)) {
  1194. subsidyList = subsidyList.stream().filter(data -> !goodsIds.contains(data.getId())).collect(Collectors.toList());
  1195. }
  1196. }
  1197. return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyList);
  1198. }
  1199. /**
  1200. * 百亿补贴规格详情
  1201. */
  1202. @GetMapping("/get/subsidy/detail/{id}")
  1203. public Result<GoodsDonSubsidyDetailView> getSubsidyDetailById(@PathVariable Long id) throws Exception {
  1204. String goodsDetailKey = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy:detail:" + id;
  1205. Object o = redisService.get(goodsDetailKey);
  1206. GoodsDonSubsidyDetailView subsidyDetail = null;
  1207. if (o == null) {
  1208. subsidyDetail = beanSearcher.searchFirst(GoodsDonSubsidyDetailView.class, MapUtils.builder().field(GoodsDonSubsidyDetailView::getId, id).build());
  1209. if (subsidyDetail == null) {
  1210. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1211. }
  1212. subsidyDetail.setSpecs(beanSearcher.searchFirst(GoodsDonSpecFrontView.class, MapUtils.builder().field(GoodsDonSpecFrontView::getGoodsId, subsidyDetail.getId()).build()));
  1213. MapBuilder builder = MapUtils.builder().field(GoodsDonSkuSubsidyDetailView::getGoodsId, subsidyDetail.getId());
  1214. subsidyDetail.setSkuList(beanSearcher.searchAll(GoodsDonSkuSubsidyDetailView.class, builder.build()));
  1215. subsidyDetail.setSold(getGoodsSold(subsidyDetail.getId(), subsidyDetail.getSold()));
  1216. redisService.setNx(goodsDetailKey, Jsons.toJson(subsidyDetail), RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + 60 * RandomUtil.randomInt(10));
  1217. }
  1218. if (subsidyDetail == null) {
  1219. o = redisService.get(goodsDetailKey);
  1220. subsidyDetail = Jsons.parseObject(o.toString(), GoodsDonSubsidyDetailView.class);
  1221. }
  1222. return GatewayResponse.SUCCESS.newBuilder().toResult(subsidyDetail);
  1223. }
  1224. /**
  1225. * 可选百亿补贴规格列表
  1226. */
  1227. @GetMapping("/get/available/subsidy/sku/{goodsId}")
  1228. public Result<List<GoodsDonSkuSubsidyAvailableView>> getAvailableSubsidySku(@PathVariable Long goodsId) {
  1229. String key = RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "subsidy:" + goodsId;
  1230. Object o = redisService.get(key);
  1231. if (o == null) {
  1232. List<GoodsDonSkuSubsidyAvailableView> goodsDonSkuSubsidyAvailableViews = beanSearcher.searchAll(GoodsDonSkuSubsidyAvailableView.class, MapUtils.builder().put("gid", String.format(" and goods_id = %s", goodsId)).build());
  1233. if (CollUtil.isEmpty(goodsDonSkuSubsidyAvailableViews)) {
  1234. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1235. }
  1236. redisService.set(key, goodsDonSkuSubsidyAvailableViews, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout() + RandomUtil.randomInt(10000));
  1237. o = redisService.get(key);
  1238. }
  1239. List<GoodsDonSkuSubsidyAvailableView> goodsDonSkuSubsidyAvailableViews = Jsons.parseList(o, GoodsDonSkuSubsidyAvailableView.class);
  1240. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDonSkuSubsidyAvailableViews);
  1241. }
  1242. /**
  1243. * 获取用户店铺首页配置列表
  1244. */
  1245. @GetMapping("/get/shop/homeManage")
  1246. public Result<Map<String, List<HomeManagementFrontView>>> getShopHomeManageConfig(String customId) {
  1247. //是否同意展示对应首页广告位
  1248. String key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getName() + customId + ":homeManage";
  1249. Object o = redisService.get(key);
  1250. if (o == null) {
  1251. MapBuilder builder = MapUtils.builder()
  1252. .field(HomeManagementFrontView::getType, HomeManagementConfig.Type.ad.name())
  1253. .field(HomeManagementFrontView::getIsShop, 1);
  1254. List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
  1255. if (homeManagementFrontViews == null) {
  1256. return GatewayResponse.SUCCESS.newBuilder().toResult();
  1257. }
  1258. Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
  1259. map.putIfAbsent(HomeManagementConfig.Type.ad.name(), homeManagementFrontViews);
  1260. redisService.setNx(key, map, 50 * 60l);
  1261. o = redisService.get(key);
  1262. }
  1263. Map map = Jsons.parseObject(o, Map.class);
  1264. return GatewayResponse.SUCCESS.newBuilder().toResult(map);
  1265. }
  1266. /**
  1267. * 获取套餐列表
  1268. */
  1269. @GetMapping("/get/upgradePackage")
  1270. public Result<SearchResult<UpgradePackageView>> list(Long skuId) {
  1271. long userId = StpUserUtil.getLoginIdAsLong();
  1272. log.info("userId:{}获取套餐列表", userId);
  1273. Map<String, Object> build = MapUtils.flatBuilder(request.getParameterMap()).build();
  1274. if (skuId != null) {
  1275. build.put("sku", String.format(" and JSON_CONTAINS(up.sku_ids,'\"%s\"')", skuId));
  1276. }
  1277. SearchResult<UpgradePackageView> search = beanSearcher.search(UpgradePackageView.class, build);
  1278. return GatewayResponse.SUCCESS.newBuilder().toResult(search);
  1279. }
  1280. /**
  1281. * 获取所有平台列表
  1282. */
  1283. @GetMapping("/get/goods")
  1284. public Result<List<GoodsDon>> getAllGoodsList() {
  1285. List<GoodsDon> goodsDons = beanSearcher.searchAll(GoodsDon.class, MapUtils.flatBuilder(request.getParameterMap()).field(GoodsDon::getStatus, 1)
  1286. .onlySelect(GoodsDon::getId, GoodsDon::getTitle)
  1287. .build());
  1288. return GatewayResponse.SUCCESS.newBuilder().toResult(goodsDons);
  1289. }
  1290. /**
  1291. * 获取平台销量
  1292. * @param goodsId
  1293. * @param virtualSold
  1294. * @return
  1295. */
  1296. private Integer getGoodsSold(Long goodsId, Integer virtualSold) {
  1297. Object soldObj = redisService.get(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "sold:" + goodsId);
  1298. if (soldObj == null) {
  1299. Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
  1300. .eq(OrderDon::getGoodsId, goodsId).notIn(OrderDon::getStatus, Constant.noOrderStatus));
  1301. soldObj = sold + virtualSold;
  1302. redisService.set(RedisService.key.YH_HOME_PAGHE_CACHE.getName() + "sold:" + goodsId, soldObj, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
  1303. }
  1304. return Integer.parseInt(soldObj.toString());
  1305. }
  1306. /**
  1307. * 设置平台优惠价格
  1308. */
  1309. private void setUserCouponGoodsMoney(Long userId, GoodsFrontListCategoryView data) {
  1310. //登录后
  1311. if (userId != null) {
  1312. //特定价格
  1313. BigDecimal specificPrice = data.getSpecificPrice();
  1314. //渠道折扣
  1315. BigDecimal channelDiscount = data.getChannelDiscount();
  1316. //支付来源
  1317. Integer source = 0;
  1318. BigDecimal presentCouponMoney = null;
  1319. //寻找对应最低规格的优惠券
  1320. Coupon coupon = couponUserMapper.selectUserCouponByGidAndPrice(userId, data.getId(), data.getPrice());
  1321. if (coupon != null) {
  1322. source = 1;
  1323. data.setDiscount(coupon.getDiscount());
  1324. data.setReduceMoney(coupon.getReduceMoney());
  1325. data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney()));
  1326. data.setValidEndTime(coupon.getValidEndTime());
  1327. data.setCouponId(coupon.getId());
  1328. presentCouponMoney = data.getDiscountPrice();
  1329. }
  1330. if (channelDiscount != null) {
  1331. BigDecimal channelCouponMoney = data.getPrice().multiply(channelDiscount);
  1332. if (presentCouponMoney == null) {
  1333. presentCouponMoney = channelCouponMoney;
  1334. }
  1335. if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) {
  1336. source = 2;
  1337. presentCouponMoney = channelCouponMoney;
  1338. data.setDiscount(channelDiscount);
  1339. data.setReduceMoney(null);
  1340. data.setDiscountPrice(channelCouponMoney);
  1341. data.setValidEndTime(null);
  1342. data.setCouponId(null);
  1343. }
  1344. }
  1345. if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) {
  1346. if (presentCouponMoney == null) {
  1347. presentCouponMoney = specificPrice;
  1348. }
  1349. if (specificPrice.compareTo(presentCouponMoney) <= 0) {
  1350. source = 3;
  1351. data.setDiscount(null);
  1352. data.setReduceMoney(null);
  1353. data.setDiscountPrice(specificPrice);
  1354. data.setValidEndTime(null);
  1355. data.setCouponId(null);
  1356. }
  1357. }
  1358. data.setSource(source);
  1359. }
  1360. }
  1361. /**
  1362. * 设置平台规格优惠价格
  1363. */
  1364. private void setUserCouponSkuMoney(Long userId, GoodsDonSkuFrontView sku) {
  1365. //登录后
  1366. if (userId != null) {
  1367. //特定价格
  1368. BigDecimal specificPrice = sku.getSpecificPrice();
  1369. //渠道折扣
  1370. BigDecimal channelDiscount = sku.getChannelDiscount();
  1371. //支付来源
  1372. Integer source = 0;
  1373. BigDecimal presentCouponMoney = null;
  1374. //寻找对应最低规格的优惠券
  1375. Coupon coupon = couponUserMapper.selectUserCouponBySkuId(userId, sku.getId());
  1376. if (coupon != null) {
  1377. source = 1;
  1378. sku.setDiscount(coupon.getDiscount());
  1379. sku.setReduceMoney(coupon.getReduceMoney());
  1380. sku.setDiscountPrice(sku.getPrice().subtract(coupon.getCouponMoney()));
  1381. sku.setValidEndTime(coupon.getValidEndTime());
  1382. sku.setCouponId(coupon.getId());
  1383. presentCouponMoney = sku.getDiscountPrice();
  1384. }
  1385. if (channelDiscount != null) {
  1386. BigDecimal channelCouponMoney = sku.getPrice().multiply(channelDiscount);
  1387. if (presentCouponMoney == null) {
  1388. presentCouponMoney = channelCouponMoney;
  1389. }
  1390. if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) {
  1391. source = 2;
  1392. presentCouponMoney = channelCouponMoney;
  1393. sku.setDiscount(channelDiscount);
  1394. sku.setReduceMoney(null);
  1395. sku.setDiscountPrice(channelCouponMoney);
  1396. sku.setValidEndTime(null);
  1397. sku.setCouponId(null);
  1398. }
  1399. }
  1400. if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) {
  1401. if (presentCouponMoney == null) {
  1402. presentCouponMoney = specificPrice;
  1403. }
  1404. if (specificPrice.compareTo(presentCouponMoney) <= 0) {
  1405. source = 3;
  1406. sku.setDiscount(null);
  1407. sku.setReduceMoney(null);
  1408. sku.setDiscountPrice(specificPrice);
  1409. sku.setValidEndTime(null);
  1410. sku.setCouponId(null);
  1411. }
  1412. }
  1413. sku.setSource(source);
  1414. }
  1415. }
  1416. /**
  1417. * 设置推荐平台优惠价格
  1418. */
  1419. private void setHomeManageUserCouponGoodsMoney(Long userId, HomeManagementFrontView data) {
  1420. //登录后
  1421. if (userId != null) {
  1422. //特定价格
  1423. BigDecimal specificPrice = data.getSpecificPrice();
  1424. //渠道折扣
  1425. BigDecimal channelDiscount = data.getChannelDiscount();
  1426. //支付来源
  1427. Integer source = 0;
  1428. BigDecimal presentCouponMoney = null;
  1429. //寻找对应最低规格的优惠券
  1430. Coupon coupon = couponUserMapper.selectUserCouponByGidAndPrice(userId, data.getGoodsId(), data.getPrice());
  1431. if (coupon != null) {
  1432. source = 1;
  1433. data.setDiscount(coupon.getDiscount());
  1434. data.setReduceMoney(coupon.getReduceMoney());
  1435. data.setDiscountPrice(data.getPrice().subtract(coupon.getCouponMoney()));
  1436. data.setValidEndTime(coupon.getValidEndTime());
  1437. data.setCouponId(coupon.getId());
  1438. presentCouponMoney = data.getDiscountPrice();
  1439. }
  1440. if (channelDiscount != null) {
  1441. BigDecimal channelCouponMoney = data.getPrice().multiply(channelDiscount);
  1442. if (presentCouponMoney == null) {
  1443. presentCouponMoney = channelCouponMoney;
  1444. }
  1445. if (channelCouponMoney.compareTo(presentCouponMoney) <= 0) {
  1446. source = 2;
  1447. presentCouponMoney = channelCouponMoney;
  1448. data.setDiscount(channelDiscount);
  1449. data.setReduceMoney(null);
  1450. data.setDiscountPrice(channelCouponMoney);
  1451. data.setValidEndTime(null);
  1452. data.setCouponId(null);
  1453. }
  1454. }
  1455. if (specificPrice != null && specificPrice.compareTo(BigDecimal.ZERO) > 0) {
  1456. if (presentCouponMoney == null) {
  1457. presentCouponMoney = specificPrice;
  1458. }
  1459. if (specificPrice.compareTo(presentCouponMoney) <= 0) {
  1460. source = 3;
  1461. data.setDiscount(null);
  1462. data.setReduceMoney(null);
  1463. data.setDiscountPrice(specificPrice);
  1464. data.setValidEndTime(null);
  1465. data.setCouponId(null);
  1466. }
  1467. }
  1468. data.setSource(source);
  1469. }
  1470. }
  1471. }