PageServiceImpl.java 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855
  1. package com.caimei365.commodity.service.impl;
  2. import com.caimei365.commodity.components.PriceUtilService;
  3. import com.caimei365.commodity.mapper.*;
  4. import com.caimei365.commodity.model.ResponseJson;
  5. import com.caimei365.commodity.model.po.ProductDetailInfoPo;
  6. import com.caimei365.commodity.model.po.ProductImagePo;
  7. import com.caimei365.commodity.model.po.ProductParameterPo;
  8. import com.caimei365.commodity.model.search.ProductListVo;
  9. import com.caimei365.commodity.model.vo.*;
  10. import com.caimei365.commodity.service.PageService;
  11. import com.caimei365.commodity.utils.AppletsLinkUtil;
  12. import com.caimei365.commodity.utils.ImageUtils;
  13. import com.caimei365.commodity.utils.MathUtil;
  14. import com.github.pagehelper.PageHelper;
  15. import lombok.extern.slf4j.Slf4j;
  16. import org.apache.commons.lang.StringUtils;
  17. import org.springframework.beans.factory.annotation.Value;
  18. import org.springframework.cache.annotation.Cacheable;
  19. import org.springframework.stereotype.Service;
  20. import org.springframework.util.CollectionUtils;
  21. import javax.annotation.Resource;
  22. import java.util.*;
  23. import java.util.stream.Collectors;
  24. /**
  25. * Description
  26. *
  27. * @author : Charles
  28. * @date : 2021/4/12
  29. */
  30. @Slf4j
  31. @Service
  32. public class PageServiceImpl implements PageService {
  33. @Value("${caimei.wwwDomain}")
  34. private String domain;
  35. @Resource
  36. private UserLikeMapper likeMapper;
  37. @Resource
  38. private PageMapper pageMapper;
  39. @Resource
  40. private ShopMapper shopMapper;
  41. @Resource
  42. private PriceMapper priceMapper;
  43. @Resource
  44. private PriceUtilService priceUtilService;
  45. @Resource
  46. private ProductTypeMapper productTypeMapper;
  47. @Resource
  48. private PageService pageService;
  49. @Resource
  50. private CouponMapper couponMapper;
  51. /**
  52. * 获取分类列表
  53. *
  54. * @param typeSort 分类类型:1产品,2仪器,0全部
  55. * @param source 请求来源:www,crm
  56. */
  57. @Override
  58. @Cacheable(value = "getCommodityClassify", key = "#typeSort +'-'+ #source", unless = "#result == null")
  59. public ResponseJson<List<BigTypeVo>> getClassify(Integer typeSort, String source) {
  60. List<BigTypeVo> bigTypeList = productTypeMapper.getBigTypeList(typeSort, source);
  61. bigTypeList.forEach(bigType -> {
  62. String caiMeiImage = ImageUtils.getImageURL("caiMeiImage", null, 0, domain);
  63. bigType.setWwwIcon(StringUtils.isEmpty(bigType.getWwwIcon()) ? caiMeiImage : bigType.getWwwIcon());
  64. bigType.setCrmIcon(StringUtils.isEmpty(bigType.getCrmIcon()) ? caiMeiImage : bigType.getCrmIcon());
  65. List<SmallTypeVo> smallTypeList = productTypeMapper.getSmallTypeList(bigType.getBigTypeId(), source);
  66. if (!CollectionUtils.isEmpty(smallTypeList)) {
  67. smallTypeList.forEach(smallType -> {
  68. smallType.setWwwIcon(StringUtils.isEmpty(smallType.getWwwIcon()) ? caiMeiImage : smallType.getWwwIcon());
  69. smallType.setCrmIcon(StringUtils.isEmpty(smallType.getCrmIcon()) ? caiMeiImage : smallType.getCrmIcon());
  70. List<TinyTypeVo> tinyTypeList = productTypeMapper.getTinyTypeList(smallType.getSmallTypeId(), source);
  71. if (!CollectionUtils.isEmpty(tinyTypeList)) {
  72. tinyTypeList.forEach(tinyType -> {
  73. tinyType.setWwwIcon(StringUtils.isEmpty(tinyType.getWwwIcon()) ? caiMeiImage : tinyType.getWwwIcon());
  74. tinyType.setCrmIcon(StringUtils.isEmpty(tinyType.getCrmIcon()) ? caiMeiImage : tinyType.getCrmIcon());
  75. });
  76. smallType.setTinyTypeList(tinyTypeList);
  77. }
  78. });
  79. bigType.setSmallTypeList(smallTypeList);
  80. }
  81. });
  82. return ResponseJson.success(bigTypeList);
  83. }
  84. /**
  85. * 产品/仪器页面数据
  86. *
  87. * @param pageId 页面信息id
  88. * @param userId 用户id
  89. * @param source 来源:1网站,2小程序
  90. */
  91. @Override
  92. @Cacheable(value = "insCommodityData", key = "#pageId+'-'+#userId+'-'+#source", unless = "#result == null")
  93. public ResponseJson<Map<String, Object>> getClassifyData(Integer pageId, Integer userId, Integer source) {
  94. source = source == null ? 1 : source;
  95. Map<String, Object> map = new HashMap<>(3);
  96. Integer typeSort = pageMapper.getPageTypeSort(pageId);
  97. List<HotSearchVo> hotSearchList = pageMapper.getHotSearchByPageId(pageId, source);
  98. List<PageFloorVo> floorList = pageMapper.getFloorByPageId(pageId, source);
  99. for (PageFloorVo floor : floorList) {
  100. FloorContentVo floorContent = pageMapper.getFloorContentByCentreId(floor.getId());
  101. setFloorLinkType(floorContent);
  102. floor.setFloorContent(floorContent);
  103. List<FloorImageVo> floorImageList = pageMapper.getFloorImageByCentreId(floor.getId(), source);
  104. setFloorImageProduct(userId, floorImageList, source);
  105. floor.setFloorImageList(floorImageList);
  106. }
  107. map.put("typeSort", typeSort);
  108. map.put("hotSearchList", hotSearchList);
  109. map.put("floorList", floorList);
  110. return ResponseJson.success(map);
  111. }
  112. /**
  113. * 首页楼层数据
  114. *
  115. * @param userId 用户id
  116. * @param source 来源:1网站,2小程序
  117. */
  118. @Cacheable(value = "getHomeCommodityData", key = "#userId +'-'+ #source", unless = "#result == null")
  119. @Override
  120. public ResponseJson<Map<String, Object>> getHomeData(Integer userId, Integer source) {
  121. Map<String, Object> map = new HashMap<>(2);
  122. //楼层管理
  123. source = source == null ? 1 : source;
  124. List<PageFloorVo> homePageFloor = pageMapper.getHomePageFloor(source);
  125. Iterator<PageFloorVo> floorIterator = homePageFloor.iterator();
  126. while (floorIterator.hasNext()) {
  127. PageFloorVo floor = floorIterator.next();
  128. FloorContentVo floorContent = pageMapper.getFloorContentById(floor.getId());
  129. setFloorLinkType(floorContent);
  130. floor.setFloorContent(floorContent);
  131. List<FloorImageVo> floorImageList = pageMapper.getFloorImageById(floor.getId(), source);
  132. if (floorImageList == null || floorImageList.size() == 0) {
  133. floorIterator.remove();
  134. continue;
  135. }
  136. setFloorImageProduct(userId, floorImageList, source);
  137. floor.setFloorImageList(floorImageList);
  138. }
  139. map.put("homePageFloor", homePageFloor);
  140. // 优质供应商
  141. ShopFloorVo supplierImage = pageMapper.getSupplierFloorImage();
  142. List<ShopImageVo> supplierList = pageMapper.getSupplierImage(source);
  143. supplierList.forEach(supplier -> {
  144. Integer linkType = AppletsLinkUtil.getLinkType(supplier.getLink());
  145. supplier.setLinkType(linkType);
  146. supplier.setLinkParam(AppletsLinkUtil.getLinkParam(linkType, supplier.getLink()));
  147. });
  148. if (supplierImage != null) {
  149. supplierImage.setQualitySupplierList(supplierList);
  150. if (StringUtils.isNotBlank(supplierImage.getWwwLink())) {
  151. Integer linkType = AppletsLinkUtil.getLinkType(supplierImage.getWwwLink());
  152. supplierImage.setLinkType(linkType);
  153. supplierImage.setLinkParam(AppletsLinkUtil.getLinkParam(linkType, supplierImage.getWwwLink()));
  154. }
  155. }
  156. map.put("supplierImage", supplierImage);
  157. return ResponseJson.success(map);
  158. }
  159. /**
  160. * 首页基础数据(小程序)
  161. *
  162. * @param source 来源 : 1 网站 ; 2 小程序
  163. */
  164. @Override
  165. public ResponseJson<Map<String, Object>> getHomeInit(Integer source) {
  166. Map<String, Object> map = new HashMap<>(4);
  167. // 搜索热门关键字
  168. List<String> searchHotWord = pageMapper.getSearchKeyword();
  169. if (!CollectionUtils.isEmpty(searchHotWord) && searchHotWord.size() > 8) {
  170. searchHotWord.parallelStream()
  171. .filter(str -> !StringUtils.isEmpty(str)).limit(8)
  172. .collect(Collectors.toList());
  173. }
  174. map.put("searchHotWord", searchHotWord);
  175. // 头部菜单
  176. List<TopMenuVo> menuList = pageMapper.getTopMenus(source);
  177. menuList.forEach(item -> {
  178. String link = item.getLink();
  179. if (StringUtils.isNotBlank(link)) {
  180. if (source == 1) {
  181. if (link.contains("?")) {
  182. link = link + "&name=" + item.getName();
  183. } else {
  184. link = link + "?name=" + item.getName();
  185. }
  186. }
  187. item.setLinkType(AppletsLinkUtil.getLinkType(link));
  188. item.setLinkParam(AppletsLinkUtil.getLinkParam(item.getLinkType(), link));
  189. item.setLink(link);
  190. }
  191. });
  192. map.put("topMenuList", menuList);
  193. // 底部帮助页
  194. List<BaseLinkVo> helpPages = pageMapper.getHelpPageTypes();
  195. helpPages.forEach(item -> {
  196. List<BaseLinkVo> pageList = pageMapper.getHelpPagesByType(item.getId());
  197. item.setLinkList(pageList);
  198. });
  199. map.put("helpPages", helpPages);
  200. // 友情链接
  201. List<BaseLinkVo> friendLinks = pageMapper.getFriendLinks();
  202. map.put("friendLinks", friendLinks);
  203. //是否显示领取优惠券入口
  204. List<CouponVo> couponList = couponMapper.findCouponList(null);
  205. if (couponList != null && couponList.size() > 0) {
  206. //展示
  207. map.put("couponEntry", 1);
  208. } else {
  209. //隐藏
  210. map.put("couponEntry", 2);
  211. }
  212. return ResponseJson.success(map);
  213. }
  214. /**
  215. * 活动专题楼层数据(美博会)
  216. *
  217. * @param pageId 页面id
  218. * @param userId 用户id
  219. * @param source 来源 : 1 网站 ; 2 小程序
  220. */
  221. @Cacheable(value = "getPageFloorData", key = "#userId +'-'+ #pageId +'-'+ #source", unless = "#result == null")
  222. @Override
  223. public ResponseJson<Map<String, Object>> getPageData(Integer pageId, Integer userId, Integer source) {
  224. if (pageId == null) {
  225. return ResponseJson.error("参数异常: 页面id不能为空!", null);
  226. }
  227. source = source == null ? 1 : source;
  228. // 页面数据
  229. CmPageVo page = pageMapper.findCmPageById(pageId);
  230. //轮播图设置链接类型
  231. if (StringUtils.isNotBlank(page.getHeadLink())) {
  232. Integer linkType = AppletsLinkUtil.getLinkType(page.getHeadLink());
  233. page.setLinkType(linkType);
  234. page.setLinkParam(AppletsLinkUtil.getLinkParam(linkType, page.getHeadLink()));
  235. }
  236. List<PageFloorVo> floorList = pageMapper.getFloorByPageId(pageId, source);
  237. ListIterator<PageFloorVo> iterator = floorList.listIterator();
  238. while (iterator.hasNext()) {
  239. PageFloorVo floor = iterator.next();
  240. FloorContentVo floorContent = pageMapper.getFloorContentByCentreId(floor.getId());
  241. if (null == floorContent) {
  242. iterator.remove();
  243. } else {
  244. setFloorLinkType(floorContent);
  245. List<FloorImageVo> floorImageList = pageMapper.getFloorImageByCentreId(floor.getId(), source);
  246. setFloorImageProduct(userId, floorImageList, source);
  247. floor.setFloorImageList(floorImageList);
  248. String templateTypeStr = floorContent.getTemplateType();
  249. if (StringUtils.isNotEmpty(templateTypeStr)) {
  250. int templateType = Integer.parseInt(floorContent.getTemplateType());
  251. // 日期切换模板处理
  252. if (templateType == 1 || templateType == 2 || (templateType >= 7 && templateType <= 10)) {
  253. floorContent.setTemplateClassify(1);
  254. } else if (templateType >= 3 && templateType <= 6) {
  255. floorContent.setTemplateClassify(2);
  256. } else if (templateType >= 11 && templateType <= 21) {
  257. floorContent.setTemplateClassify(3);
  258. } else if (templateType >= 22 && templateType <= 25) {
  259. floorContent.setTemplateClassify(1);
  260. List<FloorImageVo> floorImageList1 = new ArrayList<>();
  261. List<FloorImageVo> floorImageList2 = new ArrayList<>();
  262. List<FloorImageVo> floorImageList3 = new ArrayList<>();
  263. floorImageList.forEach(image -> {
  264. // 根据展示日期排序分割进3个列表中
  265. if (1 == image.getDisplaySort()) {
  266. floorImageList1.add(image);
  267. } else if (2 == image.getDisplaySort()) {
  268. floorImageList2.add(image);
  269. } else if (3 == image.getDisplaySort()) {
  270. floorImageList3.add(image);
  271. }
  272. });
  273. floor.setFloorImageList(floorImageList1);
  274. floor.setFloorImageList2(floorImageList2);
  275. floor.setFloorImageList3(floorImageList3);
  276. } else if (templateType >= 26 && templateType <= 29) {
  277. floorContent.setTemplateClassify(4);
  278. }
  279. }
  280. floor.setFloorContent(floorContent);
  281. }
  282. }
  283. Map<String, Object> map = new HashMap<>(2);
  284. map.put("page", page);
  285. map.put("floorList", floorList);
  286. return ResponseJson.success(map);
  287. }
  288. /**
  289. * 楼层详情
  290. *
  291. * @param floorId 楼层id
  292. * @param userId 用户id
  293. * @param source 来源 : 1 网站 ; 2 小程序
  294. */
  295. @Override
  296. public ResponseJson<Map<String, Object>> getPageFloorData(Integer floorId, Integer userId, Integer source) {
  297. if (floorId == null) {
  298. return ResponseJson.error("参数异常: 页面id不能为空!", null);
  299. }
  300. FloorContentVo floorContent = pageMapper.getFloorContentById(floorId);
  301. setFloorLinkType(floorContent);
  302. List<FloorImageVo> floorImageList = pageMapper.getFloorImageById(floorId, source);
  303. setFloorImageProduct(userId, floorImageList, source);
  304. Map<String, Object> map = new HashMap<>(2);
  305. map.put("floorContent", floorContent);
  306. map.put("floorImageList", floorImageList);
  307. return ResponseJson.success(map);
  308. }
  309. /**
  310. * 分页详情楼层详情
  311. *
  312. * @param centreId 分页详情楼层id
  313. * @param userId 用户id
  314. * @param source 来源 : 1 网站 ; 2 小程序
  315. */
  316. @Override
  317. public ResponseJson<Map<String, Object>> getPageCentreData(Integer centreId, Integer userId, Integer source) {
  318. if (centreId == null) {
  319. return ResponseJson.error("参数异常: 分页详情楼层id不能为空!", null);
  320. }
  321. FloorContentVo floorContent = pageMapper.getFloorContentByCentreId(centreId);
  322. setFloorLinkType(floorContent);
  323. String templateTypeStr = floorContent.getTemplateType();
  324. if (StringUtils.isNotEmpty(templateTypeStr)) {
  325. int templateType = Integer.parseInt(floorContent.getTemplateType());
  326. // 日期切换模板处理
  327. if (templateType == 1 || templateType == 2 || (templateType >= 7 && templateType <= 10)) {
  328. floorContent.setTemplateClassify(1);
  329. } else if (templateType >= 3 && templateType <= 6) {
  330. floorContent.setTemplateClassify(2);
  331. } else if (templateType >= 11 && templateType <= 21) {
  332. floorContent.setTemplateClassify(3);
  333. } else if (templateType >= 22 && templateType <= 25) {
  334. floorContent.setTemplateClassify(1);
  335. } else if (templateType >= 26 && templateType <= 29) {
  336. floorContent.setTemplateClassify(4);
  337. }
  338. }
  339. List<FloorImageVo> floorImageList = pageMapper.getFloorImageByCentreId(centreId, source);
  340. setFloorImageProduct(userId, floorImageList, source);
  341. Map<String, Object> map = new HashMap<>(2);
  342. map.put("floorContent", floorContent);
  343. map.put("floorImageList", floorImageList);
  344. return ResponseJson.success(map);
  345. }
  346. /**
  347. * 商品详情页
  348. *
  349. * @param productId 商品Id
  350. * @param userId 用户Id
  351. */
  352. @Override
  353. public ResponseJson<ProductDetailVo> getProductDetails(Integer productId, Integer userId) {
  354. ProductDetailVo product = pageMapper.getProductDetails(productId);
  355. if (product == null) {
  356. //商品不存在
  357. product = new ProductDetailVo();
  358. product.setValidFlag(0);
  359. }
  360. boolean validFlag = 2 != product.getProductCategory() && 2 == product.getValidFlag() && (product.getStock() == null || product.getStock() == 0);
  361. if (validFlag) {
  362. //已上架但库存为0的正常商品,设置为已售罄商品
  363. product.setValidFlag(4);
  364. }
  365. String[] split = null;
  366. // 品牌名称
  367. String brandName = shopMapper.getBrandNameById(product.getBrandId());
  368. product.setBrandName(brandName);
  369. //商品标签
  370. if (product.getTags() != null) {
  371. String tags = product.getTags().replace(" ", ",").replace("、", ",").replace(",", ",");
  372. if (tags.contains(",")) {
  373. List<String> list = new ArrayList<String>();
  374. for (String s : tags.split(",")) {
  375. if (s != null && !"".equals(s)) {
  376. list.add(s);
  377. }
  378. }
  379. split = list.toArray(new String[list.size()]);
  380. }
  381. }
  382. product.setTagsList(split);
  383. // 主图
  384. product.setMainImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
  385. // 商品图片
  386. List<ProductImagePo> imageList = shopMapper.getProductImages(productId);
  387. for (ProductImagePo image : imageList) {
  388. String imageURL = ImageUtils.getImageURL("product", image.getImage(), 0, domain);
  389. image.setImage(imageURL);
  390. }
  391. product.setImageList(imageList);
  392. // 商品详情
  393. ProductDetailInfoPo productDetail = shopMapper.getProductDetailInfo(productId);
  394. product.setProductDetail(productDetail);
  395. // 相关参数
  396. List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
  397. product.setParametersList(parametersList);
  398. // 分类名称
  399. String typeName = shopMapper.getTypeName(product.getBigTypeId(), product.getSmallTypeId(), product.getTinyTypeId());
  400. product.setTypeName(typeName);
  401. List<String> list = StringUtils.isNotEmpty(typeName) ? Arrays.asList(typeName.split("-")) : new ArrayList<>();
  402. product.setBigTypeName(list.size() > 0 ? list.get(0) : null);
  403. product.setSmallTypeName(list.size() > 1 ? list.get(1) : null);
  404. product.setTinyTypeName(list.size() > 2 ? list.get(2) : null);
  405. //价格等级
  406. product.setPriceGrade(priceUtilService.getPriceGrade(product.getPrice()));
  407. // 商品云上美博会活动状态
  408. Integer pcBeautyStatus = shopMapper.getPcBeautyStatusById(product.getProductId());
  409. Integer appletsBeautyStatus = shopMapper.getAppletsBeautyStatusById(product.getProductId());
  410. product.setPcActType(null != pcBeautyStatus ? 1 : 0);
  411. product.setAppletsActType(null != appletsBeautyStatus ? 1 : 0);
  412. //供应商信息
  413. ShopVo shop = shopMapper.getProductShopById(product.getShopId());
  414. if (null != shop) {
  415. Integer normalNum = shopMapper.getProductNumById(product.getShopId());
  416. shop.setNormalNum(null == normalNum ? 0 : normalNum);
  417. if (shop.getBusinessScope() != null && shop.getBusinessScope().contains("/")) {
  418. String[] businessScopeArray = shop.getBusinessScope().split("/");
  419. shop.setBusinessScopeArray(businessScopeArray);
  420. }
  421. shop.setLogo(ImageUtils.getImageURL("shopLogo", shop.getLogo(), 0, domain));
  422. shop.setBusinessLicense(ImageUtils.getImageURL("shopLogo", shop.getBusinessLicense(), 0, domain));
  423. product.setShop(shop);
  424. }
  425. // 商品可见度:3:所有人可见,2:普通机构可见,1:会员机构可见
  426. Integer visibility = product.getVisibility();
  427. if (null != userId && userId > 0) {
  428. // 用户身份:0个人,1协销,2会员机构,3供应商,4普通机构
  429. Integer identity = shopMapper.getUserIdentityById(userId);
  430. // 协销 | 会员机构 | 综合供应商
  431. boolean pass1 = null != identity && (identity == 1 || identity == 2);
  432. // 普通机构
  433. boolean pass2 = null != identity && (identity == 4 && (visibility == 2 || visibility == 3));
  434. // 游客
  435. boolean pass3 = visibility == 3;
  436. if (!(pass1 || pass2 || pass3)) {
  437. return ResponseJson.success(1, "没有权限查看该商品", new ProductDetailVo());
  438. }
  439. } else if (2 == visibility || 1 == visibility) {
  440. return ResponseJson.success(1, "没有权限查看该商品,userId为空", new ProductDetailVo());
  441. }
  442. // 商品不处于已删除/待审核/审核未通过的状态
  443. if (0 != product.getValidFlag()) {
  444. // 数据库获取基本价格信息
  445. PriceVo price = priceMapper.getDetailPrice(productId);
  446. // 根据用户id设置详细价格
  447. priceUtilService.setPriceByUserId(price, userId);
  448. // 设置价格
  449. product.setActStatus(price.getActStatus());
  450. product.setPrice(price.getPrice());
  451. product.setOriginalPrice(price.getOriginalPrice());
  452. product.setNormalPrice(price.getNormalPrice());
  453. product.setLadderPriceFlag(price.getLadderPriceFlag());
  454. product.setPromotions(price.getPromotions());
  455. product.setMinBuyNumber(price.getMinBuyNumber());
  456. product.setUserIdentity(price.getUserIdentity());
  457. product.setRepurchaseFlag(price.getRepurchaseFlag());
  458. product.setMaxBuyNumber(price.getMaxBuyNumber());
  459. // 设置阶梯价格详情
  460. if (1 == price.getLadderPriceFlag()) {
  461. List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesByProductId(product.getProductId());
  462. TaxVo tax = priceMapper.getTaxByProductId(product.getProductId());
  463. if (!CollectionUtils.isEmpty(ladderPrices)) {
  464. priceUtilService.setLadderPriceList(ladderPrices, tax);
  465. }
  466. product.setLadderPriceList(ladderPrices);
  467. }
  468. //查询商品收藏情况,1未收藏,0未收藏
  469. Integer like = likeMapper.findLike(userId, productId);
  470. product.setUserLike(like);
  471. }
  472. return ResponseJson.success(product);
  473. }
  474. /**
  475. * 再次购买商品列表
  476. *
  477. * @param userId 用户Id
  478. * @param pageNum
  479. * @param pageSize
  480. */
  481. @Override
  482. public ResponseJson<PaginationVo<ProductItemVo>> getBuyAgainProducts(Integer userId, int pageNum, int pageSize) {
  483. if (null == userId) {
  484. return ResponseJson.error("参数错误:用户Id不能为空!", null);
  485. }
  486. PageHelper.startPage(pageNum, pageSize);
  487. List<ProductItemVo> productList = pageMapper.getBuyAgainProducts(userId);
  488. productList.forEach(product -> {
  489. double price = product.getPrice() != null ? product.getPrice() : 0d;
  490. double costPrice = product.getCostPrice() != null ? product.getCostPrice() : 0d;
  491. double discountPrice = product.getDiscountPrice() != null ? product.getDiscountPrice() : 0d;
  492. Integer costFlag = product.getCostCheckFlag();
  493. // 成本大于等于复购价 或 复购价大于机构价
  494. boolean state = (costFlag == 1 && MathUtil.compare(costPrice, discountPrice) >= 0) || MathUtil.compare(discountPrice, price) > 0;
  495. product.setRepurchasePriceState(state);
  496. // 设置商品主图及价格
  497. priceUtilService.setProductDetails(userId, product);
  498. //优惠券标识
  499. Boolean couponsLogo = pageService.setCouponsLogo(userId, product.getProductId(), 2);
  500. product.setCouponsLogo(couponsLogo);
  501. });
  502. PaginationVo<ProductItemVo> pageData = new PaginationVo<>(productList);
  503. return ResponseJson.success(pageData);
  504. }
  505. /**
  506. * 项目仪器详情页
  507. *
  508. * @param equipmentId 项目仪器Id
  509. */
  510. @Override
  511. public ResponseJson<EquipmentVo> getEquipmentDetails(Integer equipmentId) {
  512. if (equipmentId == null) {
  513. return ResponseJson.error("参数异常:项目仪器Id不能为空!", null);
  514. }
  515. //仪器详情
  516. EquipmentVo equipment = pageMapper.getEquipmentById(equipmentId);
  517. if (null != equipment) {
  518. Map<String, List<EquipmentParameterVo>> pageContentMap = new HashMap<>();
  519. List<EquipmentParameterVo> firstFloorList = pageMapper.getEquipmentParametersByType(equipmentId, 1);
  520. List<EquipmentParameterVo> secondFloorList = pageMapper.getEquipmentParametersByType(equipmentId, 2);
  521. List<EquipmentParameterVo> underSecondFloorList = pageMapper.getEquipmentParametersByType(equipmentId, 4);
  522. List<EquipmentParameterVo> pcDetailList = pageMapper.getEquipmentParametersByType(equipmentId, 3);
  523. List<EquipmentParameterVo> crmDetailList = pageMapper.getEquipmentParametersByType(equipmentId, 5);
  524. pageContentMap.put("firstFloorList", firstFloorList);
  525. pageContentMap.put("secondFloorList", secondFloorList);
  526. pageContentMap.put("underSecondFloorList", underSecondFloorList);
  527. pageContentMap.put("pcDetailList", pcDetailList);
  528. pageContentMap.put("crmDetailList", crmDetailList);
  529. equipment.setPageContentMap(pageContentMap);
  530. } else {
  531. return ResponseJson.error("该仪器不存在", null);
  532. }
  533. List<PageFloorVo> floorList = pageMapper.getFloorByPageId(equipmentId, 1);
  534. if (floorList.size() > 0) {
  535. List<PageFloorVo> tempList = new ArrayList<>();
  536. floorList.forEach(floor -> {
  537. List<ImageLinkVo> imageLinks = pageMapper.getImageLinkByFloorId(floor.getId());
  538. //设置链接类型及参数
  539. if (StringUtils.isNotEmpty(floor.getLink())) {
  540. floor.setLinkType(AppletsLinkUtil.getLinkType(floor.getLink()));
  541. floor.setLinkParam(AppletsLinkUtil.getLinkParam(floor.getLinkType(), floor.getLink()));
  542. }
  543. if (imageLinks.size() > 0) {
  544. imageLinks.forEach(img -> {
  545. img.setImage(ImageUtils.getImageURL("actType", img.getImage(), 0, domain));
  546. //设置链接类型及参数
  547. if (StringUtils.isNotEmpty(img.getLink())) {
  548. img.setLinkType(AppletsLinkUtil.getLinkType(img.getLink()));
  549. img.setLinkParam(AppletsLinkUtil.getLinkParam(img.getLinkType(), img.getLink()));
  550. }
  551. });
  552. floor.setFloorData(imageLinks);
  553. } else {
  554. tempList.add(floor);
  555. }
  556. });
  557. if (tempList.size() > 0) {
  558. floorList.removeAll(tempList);
  559. }
  560. }
  561. equipment.setFloorList(floorList);
  562. return ResponseJson.success(equipment);
  563. }
  564. /**
  565. * 商品详情页-图片
  566. *
  567. * @param productId 商品Id
  568. */
  569. @Override
  570. public ResponseJson<List<String>> getProductDetailImages(Integer productId) {
  571. if (productId == null) {
  572. return ResponseJson.error("参数错误:商品Id不能为空!", null);
  573. }
  574. List<ProductImagePo> imageList = shopMapper.getProductImages(productId);
  575. List<String> newList = new ArrayList<>();
  576. if (imageList.size() > 0) {
  577. // 设置老图片路径
  578. imageList.forEach(image -> {
  579. newList.add(ImageUtils.getImageURL("product", image.getImage(), 0, domain));
  580. });
  581. }
  582. return ResponseJson.success(newList);
  583. }
  584. /**
  585. * 商品详情页-相关参数
  586. *
  587. * @param productId 商品Id
  588. */
  589. @Override
  590. public ResponseJson<List<ProductParameterPo>> getProductParameters(Integer productId) {
  591. if (productId == null) {
  592. return ResponseJson.error("参数错误:商品Id不能为空!", null);
  593. }
  594. List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
  595. return ResponseJson.success(parametersList);
  596. }
  597. /**
  598. * 商品详情页-相关推荐
  599. *
  600. * @param productId 商品Id
  601. * @param recommendType 相关推荐类型: 0自动选择, 1手动推荐
  602. * @param userId 用户Id
  603. */
  604. @Override
  605. public ResponseJson<List<ProductListVo>> getProductDetailRecommends(Integer productId, Integer recommendType, Integer userId) {
  606. if (null == productId) {
  607. return ResponseJson.error("商品Id不能为空!", null);
  608. }
  609. // 根据用户Id查询用户身份
  610. Integer identity = 0;
  611. if (null != userId && userId > 0) {
  612. identity = priceMapper.getIdentityByUserId(userId);
  613. if (null == identity) {
  614. identity = 0;
  615. }
  616. }
  617. List<ProductListVo> list = null;
  618. //相关推荐类型 0自动选择(默认); 1手动推荐
  619. if (null == recommendType || 1 != recommendType) {
  620. list = pageMapper.getAutoProductRecommends(productId);
  621. } else {
  622. list = pageMapper.getProductRecommendsById(productId);
  623. }
  624. if (null != list && list.size() > 0) {
  625. // identity: 0个人,1协销,2会员机构,3供应商,4普通机构
  626. // visibility:3:所有人可见,2:普通机构可见,1:会员机构可见
  627. // boolean passFlag = identity ==1 || identity == 2 || product.getVisibility()==3 || (identity == 4 && product.getVisibility()==2);
  628. try {
  629. Integer finalIdentity = identity;
  630. list.removeIf(product -> (null == product || null == product.getVisibility() || !(finalIdentity == 1 || finalIdentity == 2 || product.getVisibility() == 3 || (finalIdentity == 4 && product.getVisibility() == 2))));
  631. list.forEach(product -> {
  632. // 设置 图片路径
  633. product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
  634. });
  635. } catch (Exception e) {
  636. log.error("相关推荐", e);
  637. }
  638. }
  639. return ResponseJson.success(list);
  640. }
  641. /**
  642. * 商品维修(链接分享数据)
  643. *
  644. * @param code 维修code
  645. */
  646. @Override
  647. public ResponseJson<ProductRepairVo> getProductRepair(String code) {
  648. if (StringUtils.isEmpty(code)) {
  649. return ResponseJson.error("维修code不能为空!", null);
  650. }
  651. ProductRepairVo repair = null;
  652. // 仪器维修表ID
  653. Integer maintenanceId = pageMapper.getMaintenanceIdByCode(code);
  654. if (null != maintenanceId) {
  655. // 维修详情
  656. repair = pageMapper.getMaintenanceById(maintenanceId);
  657. }
  658. if (null == repair) {
  659. return ResponseJson.error("无效的链接!", null);
  660. }
  661. List<String> imageList = new ArrayList<>();
  662. if (StringUtils.isNotEmpty(repair.getInstrumentImage1())) {
  663. imageList.add(repair.getInstrumentImage1());
  664. }
  665. if (StringUtils.isNotEmpty(repair.getInstrumentImage2())) {
  666. imageList.add(repair.getInstrumentImage2());
  667. }
  668. if (StringUtils.isNotEmpty(repair.getInstrumentImage3())) {
  669. imageList.add(repair.getInstrumentImage3());
  670. }
  671. if (StringUtils.isNotEmpty(repair.getInstrumentImage4())) {
  672. imageList.add(repair.getInstrumentImage4());
  673. }
  674. if (StringUtils.isNotEmpty(repair.getInstrumentImage5())) {
  675. imageList.add(repair.getInstrumentImage5());
  676. }
  677. String[] images = imageList.toArray(new String[imageList.size()]);
  678. repair.setInstrumentArr(images);
  679. String viewerType = repair.getViewerType();
  680. if ("1".equals(viewerType)) {
  681. // 用户可评价展示详细信息
  682. repair.setCanEvaluation(true);
  683. repair.setOnlyBaseInfo(false);
  684. } else if ("3".equals(viewerType)) {
  685. // 供应商不可评价展示详细信息
  686. repair.setCanEvaluation(false);
  687. repair.setOnlyBaseInfo(false);
  688. } else {
  689. // 供应商不可评价展示基础信息
  690. ProductRepairVo repairTemp = new ProductRepairVo();
  691. repairTemp.setCanEvaluation(false);
  692. repairTemp.setOnlyBaseInfo(true);
  693. repairTemp.setViewerType("2");
  694. repairTemp.setUserAddress(repair.getUserAddress());
  695. repairTemp.setInstrumentName(repair.getInstrumentName());
  696. repairTemp.setManufacturer(repair.getManufacturer());
  697. repairTemp.setInstrumentBrand(repair.getInstrumentBrand());
  698. repairTemp.setProblemDescription(repair.getProblemDescription());
  699. return ResponseJson.success(repairTemp);
  700. }
  701. return ResponseJson.success(repair);
  702. }
  703. /**
  704. * 设置跳转参数
  705. *
  706. * @param floorContent FloorContentVo
  707. */
  708. private void setFloorLinkType(FloorContentVo floorContent) {
  709. if (floorContent != null) {
  710. if (StringUtils.isNotBlank(floorContent.getAdsLink1())) {
  711. Integer linkType1 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink1());
  712. floorContent.setLinkType1(linkType1);
  713. floorContent.setLinkParam1(AppletsLinkUtil.getLinkParam(linkType1, floorContent.getAdsLink1()));
  714. }
  715. if (StringUtils.isNotBlank(floorContent.getAdsLink2())) {
  716. Integer linkType2 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink2());
  717. floorContent.setLinkType2(linkType2);
  718. floorContent.setLinkParam2(AppletsLinkUtil.getLinkParam(linkType2, floorContent.getAdsLink2()));
  719. }
  720. if (StringUtils.isNotBlank(floorContent.getAdsLink3())) {
  721. Integer linkType3 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink3());
  722. floorContent.setLinkType3(linkType3);
  723. floorContent.setLinkParam3(AppletsLinkUtil.getLinkParam(linkType3, floorContent.getAdsLink3()));
  724. }
  725. if (StringUtils.isNotBlank(floorContent.getAdsLink4())) {
  726. Integer linkType4 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink4());
  727. floorContent.setLinkType4(linkType4);
  728. floorContent.setLinkParam4(AppletsLinkUtil.getLinkParam(linkType4, floorContent.getAdsLink4()));
  729. }
  730. if (StringUtils.isNotBlank(floorContent.getAdsLink5())) {
  731. Integer linkType3 = AppletsLinkUtil.getLinkType(floorContent.getAdsLink3());
  732. floorContent.setLinkType3(linkType3);
  733. floorContent.setLinkParam3(AppletsLinkUtil.getLinkParam(linkType3, floorContent.getAdsLink3()));
  734. }
  735. }
  736. }
  737. /**
  738. * 设置楼层相关图片的商品信息
  739. */
  740. private void setFloorImageProduct(Integer userId, List<FloorImageVo> floorImageList, Integer source) {
  741. Iterator<FloorImageVo> iterator = floorImageList.iterator();
  742. while (iterator.hasNext()) {
  743. FloorImageVo image = iterator.next();
  744. Integer linkType = AppletsLinkUtil.getLinkType(image.getLink());
  745. Map<String, Object> linkParam = AppletsLinkUtil.getLinkParam(linkType, image.getLink());
  746. image.setLinkType(linkType);
  747. image.setLinkParam(linkParam);
  748. if (image.getProductId() != null) {
  749. // 获取商品及价格
  750. ProductItemVo product = pageMapper.getProductItemById(image.getProductId());
  751. if (product != null) {
  752. // 商品价格
  753. priceUtilService.setProductDetails(userId, product);
  754. // 设置商品主图
  755. image.setListType(1);
  756. image.setName(product.getName());
  757. image.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
  758. image.setProduct(product);
  759. if (userId != null) {
  760. if (product.getUserIdentity() > 0) {
  761. if (4 == product.getUserIdentity() && "1".equals(product.getVisibility())) {
  762. iterator.remove();
  763. }
  764. } else {
  765. if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
  766. iterator.remove();
  767. }
  768. }
  769. } else {
  770. if ("1".equals(product.getVisibility()) || "2".equals(product.getVisibility())) {
  771. iterator.remove();
  772. }
  773. }
  774. //优惠券标识
  775. Boolean couponsLogo = setCouponsLogo(userId, image.getProductId(), source);
  776. product.setCouponsLogo(couponsLogo);
  777. } else {
  778. iterator.remove();
  779. }
  780. } else {
  781. image.setListType(2);
  782. }
  783. }
  784. }
  785. /**
  786. * 优惠券标识是否显示
  787. *
  788. * @param userId 机构用户id
  789. * @param productId 商品id
  790. * @param source 来源 : 1 网站 ; 2 小程序
  791. * @return
  792. */
  793. @Override
  794. public Boolean setCouponsLogo(Integer userId, Integer productId, Integer source) {
  795. boolean couponsLogo = false;
  796. ProductDetailVo product = pageMapper.getProductDetails(productId);
  797. List<CouponVo> couponList = pageMapper.findAllCoupon(userId);
  798. if (couponList != null && couponList.size() > 0) {
  799. for (CouponVo coupon : couponList) {
  800. if (coupon.getCouponType() == 4 || coupon.getCouponType() == 2) {
  801. //用户券与用户专享券
  802. couponsLogo = true;
  803. break;
  804. }
  805. if (coupon.getCouponType() == 0) {
  806. if (coupon.getProductType() == 1) {
  807. //活动券-全商城商品
  808. couponsLogo = true;
  809. break;
  810. } else {
  811. //活动券-指定商品
  812. List<Integer> productIds = pageMapper.findAllProductId(coupon.getCouponId(), source);
  813. if (productIds.contains(productId)) {
  814. couponsLogo = true;
  815. break;
  816. }
  817. }
  818. }
  819. if (coupon.getCouponType() == 3 && product.getShopId().equals(coupon.getShopId())) {
  820. //店铺券
  821. couponsLogo = true;
  822. break;
  823. }
  824. if (coupon.getCouponType() == 1 && coupon.getCategoryType().equals(product.getCommodityType())) {
  825. //品类券
  826. couponsLogo = true;
  827. break;
  828. }
  829. }
  830. }
  831. return couponsLogo;
  832. }
  833. }