ApiGoodsController.java 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. package com.kmall.api.api;
  2. import com.google.common.collect.Maps;
  3. import com.kmall.api.annotation.IgnoreAuth;
  4. import com.kmall.api.annotation.LoginUser;
  5. import com.kmall.api.entity.*;
  6. import com.kmall.api.service.*;
  7. import com.kmall.api.util.ApiBaseAction;
  8. import com.kmall.api.util.ApiPageUtils;
  9. import com.kmall.common.constant.Dict;
  10. import com.kmall.common.utils.DateUtils;
  11. import com.kmall.common.utils.Query;
  12. import com.kmall.common.utils.enums.CouponTypeEnum;
  13. import com.qiniu.util.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestParam;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import java.util.ArrayList;
  20. import java.util.HashMap;
  21. import java.util.List;
  22. import java.util.Map;
  23. /**
  24. * 作者: @author Scott <br>
  25. * 时间: 2017-08-11 08:32<br>
  26. * 描述: ApiIndexController <br>
  27. */
  28. @RestController
  29. @RequestMapping("/api/goods")
  30. public class ApiGoodsController extends ApiBaseAction {
  31. @Autowired
  32. private ApiGoodsService goodsService;
  33. @Autowired
  34. private ApiGoodsSpecificationService goodsSpecificationService;
  35. @Autowired
  36. private ApiProductService productService;
  37. @Autowired
  38. private ApiGoodsGalleryService goodsGalleryService;
  39. @Autowired
  40. private ApiGoodsIssueService goodsIssueService;
  41. @Autowired
  42. private ApiAttributeService attributeService;
  43. @Autowired
  44. private ApiCommentService commentService;
  45. @Autowired
  46. private ApiUserService userService;
  47. @Autowired
  48. private ApiCommentPictureService commentPictureService;
  49. @Autowired
  50. private ApiCollectService collectService;
  51. @Autowired
  52. private ApiFootprintService footprintService;
  53. @Autowired
  54. private ApiCategoryService categoryService;
  55. @Autowired
  56. private ApiSearchHistoryService searchHistoryService;
  57. @Autowired
  58. private ApiRelatedGoodsService relatedGoodsService;
  59. @Autowired
  60. private ApiCouponService apiCouponService;
  61. @Autowired
  62. private ApiUserCouponService apiUserCouponService;
  63. @Autowired
  64. private ApiCartService cartService;
  65. @Autowired
  66. private ApiAdService apiAdService;
  67. @Autowired
  68. private ApiBrandService apiBrandService;
  69. @Autowired
  70. private ApiFreightService apiFreightService;
  71. @Autowired
  72. private ApiThirdMerchantBizService apiThirdMerchantBizService;
  73. @Autowired
  74. private ApiStoreService apiStoreService;
  75. /**
  76. */
  77. @IgnoreAuth
  78. @GetMapping("index")
  79. public Object index(@LoginUser UserVo loginUser) {
  80. //
  81. Map param = Maps.newHashMap();
  82. List<GoodsVo> goodsList = goodsService.queryList(param);
  83. //
  84. return toResponsSuccess(goodsList);
  85. }
  86. /**
  87. * 获取sku信息,用于购物车编辑时选择规格
  88. */
  89. @IgnoreAuth
  90. @GetMapping("sku")
  91. public Object sku(@LoginUser UserVo loginUser, Long goodsId) {
  92. Map<String, Object> resultObj = Maps.newHashMap();
  93. //
  94. GoodsVo goodsVo = goodsService.queryObjectByStoreId(goodsId, getStoreId());
  95. //
  96. List<Map> goodsSpecificationEntityList = goodsSpecificationService.queryByGoodsIdGroupByNames(goodsId);
  97. //
  98. Map param = Maps.newHashMap();
  99. param.put("goods_id", goodsId);
  100. param.put("store_id", getStoreId());
  101. List<ProductVo> productEntityList = productService.queryList(param);
  102. CartVo cartVo = cartService.queryObjectByGoodsIdAndUserId(goodsId, getUserId(), getStoreId());
  103. if(cartVo == null){
  104. resultObj.put("cartNumber", 0);
  105. }else{
  106. resultObj.put("cartNumber", cartVo.getNumber());
  107. }
  108. resultObj.put("goodsVo", goodsVo);
  109. resultObj.put("specificationList", goodsSpecificationEntityList);
  110. resultObj.put("productList", productEntityList);
  111. return toResponsSuccess(resultObj);
  112. }
  113. /**
  114. * 商品画廊数据
  115. */
  116. @IgnoreAuth
  117. @GetMapping("goodsGallery")
  118. public Object goodsGallery(Integer goods_id) {
  119. Map param = Maps.newHashMap();
  120. param.put("goods_id", goods_id);
  121. List<GoodsGalleryVo> gallery = goodsGalleryService.queryList(param);
  122. return toResponsSuccess(gallery);
  123. }
  124. /**
  125. * 商品详情页数据
  126. * */
  127. @GetMapping("detail")
  128. public Object detail(Long id, Long referrer,String merchSn) {
  129. Map<String, Object> resultObj = Maps.newHashMap();
  130. //
  131. Long userId = getUserId();
  132. Long storeId = getStoreId();
  133. GoodsVo info = goodsService.queryObjectByStoreId(id, storeId);
  134. if(info == null){
  135. return toResponsFail("此商品不存在");
  136. }
  137. BrandVo brand = apiBrandService.queryObject(info.getBrand_id());
  138. resultObj.put("brand", brand);
  139. Map param = Maps.newHashMap();
  140. param.put("goods_id", id);
  141. param.put("store_id", getStoreId());
  142. List<Map> specificationList = goodsSpecificationService.queryByGoodsIdGroupByNames(id);
  143. //
  144. List<ProductVo> productEntityList = productService.queryList(param);
  145. //
  146. List<GoodsGalleryVo> gallery = goodsGalleryService.queryList(param);
  147. resultObj.put("gallery", gallery);
  148. Map ngaParam = Maps.newHashMap();
  149. ngaParam.put("fields", "nga.value, na.name");
  150. ngaParam.put("sidx", "nga.id");
  151. ngaParam.put("order", "asc");
  152. ngaParam.put("goods_id", id);
  153. List<AttributeVo> attribute = attributeService.queryList(ngaParam);
  154. //
  155. Map issueParam = Maps.newHashMap();
  156. issueParam.put("merch_sn", merchSn);
  157. List<GoodsIssueVo> issue = goodsIssueService.queryList(issueParam);
  158. //
  159. param.put("value_id", id);
  160. param.put("type_id", 0);
  161. Integer commentCount = commentService.queryTotal(param);
  162. List<CommentVo> hotComment = commentService.queryList(param);
  163. Map commentInfo = Maps.newHashMap();
  164. if (null != hotComment && hotComment.size() > 0) {
  165. UserVo commentUser = userService.queryObject(hotComment.get(0).getUserId());
  166. commentInfo.put("content", hotComment.get(0).getContent());
  167. commentInfo.put("add_time", DateUtils.timeToStr(hotComment.get(0).getAddTime(), DateUtils.PATTERN_YYYY_MM_DD_HH_MM));
  168. commentInfo.put("nickname", commentUser.getNickname());
  169. commentInfo.put("avatar", commentUser.getAvatar());
  170. Map paramPicture = Maps.newHashMap();
  171. paramPicture.put("comment_id", hotComment.get(0).getId());
  172. List<CommentPictureVo> commentPictureEntities = commentPictureService.queryList(paramPicture);
  173. commentInfo.put("pic_list", commentPictureEntities);
  174. }
  175. Map comment = Maps.newHashMap();
  176. comment.put("count", commentCount);
  177. comment.put("data", commentInfo);
  178. //当前用户是否收藏
  179. Map collectParam = Maps.newHashMap();
  180. collectParam.put("user_id", getUserId());
  181. collectParam.put("value_id", id);
  182. collectParam.put("type_id", 0);
  183. Integer userHasCollect = collectService.queryTotal(collectParam);
  184. if (userHasCollect > 0) {
  185. userHasCollect = 1;
  186. }
  187. //记录用户的足迹
  188. FootprintVo footprintEntity = new FootprintVo();
  189. footprintEntity.setAdd_time(System.currentTimeMillis() / 1000);
  190. footprintEntity.setGoods_brief(info.getGoods_brief());
  191. footprintEntity.setList_pic_url(info.getList_pic_url());
  192. footprintEntity.setGoods_id(info.getId());
  193. footprintEntity.setName(info.getName());
  194. footprintEntity.setRetail_price(info.getRetail_price());
  195. footprintEntity.setUser_id(userId);
  196. if (null != referrer) {
  197. footprintEntity.setReferrer(referrer);
  198. } else {
  199. footprintEntity.setReferrer(0L);
  200. }
  201. footprintService.save(footprintEntity);
  202. Map cartMap= Maps.newHashMap();
  203. cartMap.put("user_id",userId);
  204. cartMap.put("goods_id",info.getId());
  205. cartMap.put("store_id", storeId);
  206. cartMap.put("isStockShare", info.getIsStockShare());
  207. List<CartVo> cartVoList = cartService.queryList(cartMap);
  208. FreightEntity freightEntity = apiFreightService.queryObjectByGoodsId(info.getId(), getStoreId());
  209. Integer stockNum = 0;
  210. if(info.getGoodsBizType().equalsIgnoreCase(Dict.orderBizType.item_00.getItem())){
  211. if (info.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_1.getItem())) {
  212. stockNum = info.getGoods_number();
  213. info.setSell_volume(info.getGoods_sell_volume());
  214. }
  215. if (info.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
  216. stockNum = info.getStockNum();
  217. }
  218. }else {
  219. stockNum = info.getStockNum();
  220. }
  221. resultObj.put("info", info);
  222. resultObj.put("attribute", attribute);
  223. resultObj.put("userHasCollect", userHasCollect);
  224. resultObj.put("issue", issue);
  225. resultObj.put("comment", comment);
  226. resultObj.put("specificationList", specificationList);
  227. resultObj.put("productList", productEntityList);
  228. resultObj.put("stockNum", stockNum);
  229. resultObj.put("cartNumber", cartVoList.size()!=0? cartVoList.get(0).getNumber():0);
  230. resultObj.put("defaultFreight", freightEntity != null? freightEntity.getDefaultFreight() :0);
  231. return toResponsSuccess(resultObj);
  232. }
  233. /*
  234. *  用户转发获取优惠券
  235. */
  236. @IgnoreAuth
  237. @GetMapping("transferCoupon")
  238. public Object transferCoupon(@LoginUser UserVo loginUser, Long goods_id, Integer send_type, Long referrer) {
  239. Map<String, Object> resultObj = Maps.newHashMap();
  240. // 记录推荐人是否可以领取红包,用户登录时校验
  241. Long userId = getUserId();
  242. try {
  243. // 是否已经有可用的转发红包
  244. Map params = Maps.newHashMap();
  245. params.put("user_id", userId);
  246. params.put("send_type", send_type);
  247. params.put("unUsed", true);
  248. List<CouponVo> enabledCouponVos = apiCouponService.queryUserCoupons(params);
  249. if ((null == enabledCouponVos || enabledCouponVos.size() == 0)
  250. && null != referrer && null != userId) {
  251. // 获取优惠信息提示
  252. Map couponParam = Maps.newHashMap();
  253. couponParam.put("enabled", true);
  254. Integer[] send_types = new Integer[]{CouponTypeEnum.COUPONTYPE2.getIndex()};
  255. couponParam.put("send_types", send_types);
  256. List<CouponVo> couponVos = apiCouponService.queryList(couponParam);
  257. if (null != couponVos && couponVos.size() > 0) {
  258. CouponVo couponVo = couponVos.get(0);
  259. Map footprintParam = Maps.newHashMap();
  260. footprintParam.put("goods_id", goods_id);
  261. footprintParam.put("referrer", referrer);
  262. Integer footprintNum = footprintService.queryTotal(footprintParam);
  263. if (null != footprintNum && null != couponVo.getMin_transmit_num()
  264. && footprintNum > couponVo.getMin_transmit_num()) {
  265. apiCouponService.takeCoupon(couponVo, userId, "", 0L, 1);
  266. }
  267. }
  268. }
  269. } catch (Exception e) {
  270. e.printStackTrace();
  271. }
  272. return toResponsSuccess("");
  273. }
  274. /**
  275. *  获取分类下的商品
  276. */
  277. @IgnoreAuth
  278. @GetMapping("category")
  279. public Object category(@LoginUser UserVo loginUser, Integer id) {
  280. Map<String, Object> resultObj = Maps.newHashMap();
  281. //
  282. CategoryVo currentCategory = categoryService.queryObject(id);
  283. //
  284. CategoryVo parentCategory = categoryService.queryObject(currentCategory.getParent_id());
  285. Map params = Maps.newHashMap();
  286. params.put("parent_id", currentCategory.getParent_id());
  287. List<CategoryVo> brotherCategory = categoryService.queryList(params);
  288. //
  289. resultObj.put("currentCategory", currentCategory);
  290. resultObj.put("parentCategory", parentCategory);
  291. resultObj.put("brotherCategory", brotherCategory);
  292. return toResponsSuccess(resultObj);
  293. }
  294. /**
  295. *  获取品牌下的商品
  296. */
  297. @IgnoreAuth
  298. @GetMapping("brand")
  299. public Object brand(@LoginUser UserVo loginUser, Integer id) {
  300. Map<String, Object> resultObj = Maps.newHashMap();
  301. //
  302. BrandVo currentBrand = apiBrandService.queryObject(id);
  303. //
  304. CategoryVo parentCategory = categoryService.queryObject(currentBrand.getCategoryId());
  305. Map params = Maps.newHashMap();
  306. params.put("categoryId", currentBrand.getCategoryId());
  307. List<BrandVo> brandList = apiBrandService.queryList(params);
  308. //
  309. resultObj.put("currentBrand", currentBrand);
  310. resultObj.put("brandList", brandList);
  311. return toResponsSuccess(resultObj);
  312. }
  313. /**
  314. *   获取商品列表
  315. */
  316. @GetMapping("list")
  317. public Object list(@LoginUser UserVo loginUser, Integer categoryId,
  318. Integer brandId, String keyword, Integer isNew, Integer isHot,String goodsBizType,
  319. @RequestParam(value = "page", defaultValue = "1") Integer
  320. page, @RequestParam(value = "size", defaultValue = "10") Integer size,
  321. String sort, String order) {
  322. Map params = Maps.newHashMap();
  323. if(org.apache.commons.lang3.StringUtils.isNotEmpty(keyword)){
  324. try{
  325. keyword = new String(keyword.getBytes("iso-8859-1"),"utf-8");
  326. }catch (Exception e){
  327. logger.error("error:", e);
  328. }
  329. params.put("keyword", keyword);
  330. }
  331. params.put("brand_id", brandId);
  332. params.put("is_new", isNew);
  333. params.put("is_hot", isHot);
  334. params.put("page", page);
  335. params.put("limit", size);
  336. // params.put("order", sort);
  337. // params.put("sidx", order);
  338. params.put("goodsBizType", goodsBizType);
  339. params.put("store_id", getStoreId());
  340. params.put("notGoodsBizType", true);
  341. //
  342. if (null != sort && sort.equals("price")) {
  343. params.put("sidx", "psr1.retail_price");
  344. params.put("order", order);
  345. } else {
  346. params.put("sidx", "a.id");
  347. params.put("order", "desc");
  348. }
  349. //添加到搜索历史
  350. if (!StringUtils.isNullOrEmpty(keyword)) {
  351. SearchHistoryVo searchHistoryVo = new SearchHistoryVo();
  352. searchHistoryVo.setAdd_time(System.currentTimeMillis() / 1000);
  353. searchHistoryVo.setKeyword(keyword);
  354. searchHistoryVo.setUser_id(null != loginUser ? loginUser.getId().toString() : "");
  355. searchHistoryVo.setFrom("");
  356. searchHistoryService.save(searchHistoryVo);
  357. }
  358. //筛选的分类
  359. List<CategoryVo> filterCategory = new ArrayList();
  360. CategoryVo rootCategory = new CategoryVo();
  361. rootCategory.setId(0);
  362. rootCategory.setName("全部");
  363. rootCategory.setChecked(false);
  364. filterCategory.add(rootCategory);
  365. //
  366. params.put("fields", "psr1.category_id");
  367. params.put("limit", 1);
  368. List<GoodsVo> goodsVoList = goodsService.queryList(params);
  369. params.put("limit", size);
  370. params.remove("fields");
  371. if (null != goodsVoList && goodsVoList.size() > 0) {
  372. List<Integer> categoryIds = new ArrayList();
  373. for (GoodsVo goodsVo : goodsVoList) {
  374. if (null != goodsVo && null != goodsVo.getCategory_id()) {
  375. categoryIds.add(goodsVo.getCategory_id());
  376. }
  377. }
  378. //查找二级分类的parent_id
  379. Map categoryParam = Maps.newHashMap();
  380. categoryParam.put("ids", categoryIds);
  381. categoryParam.put("fields", "parent_id");
  382. List<CategoryVo> parentCategoryList = categoryService.queryList(categoryParam);
  383. //
  384. List<Integer> parentIds = new ArrayList();
  385. for (CategoryVo categoryEntity : parentCategoryList) {
  386. parentIds.add(categoryEntity.getParent_id());
  387. }
  388. //一级分类
  389. categoryParam = Maps.newHashMap();
  390. categoryParam.put("fields", "id,name");
  391. categoryParam.put("order", "asc");
  392. categoryParam.put("sidx", "sort_order");
  393. categoryParam.put("ids", parentIds);
  394. List<CategoryVo> parentCategory = categoryService.queryList(categoryParam);
  395. if (null != parentCategory) {
  396. filterCategory.addAll(parentCategory);
  397. }
  398. }
  399. //查询列表数据
  400. params.put("fields", "distinct a.id, a.name, a.list_pic_url, psr1.market_price, psr1.retail_price, a.goods_brief");
  401. params.put("category_parent_id", categoryId);
  402. Query query = new Query(params);
  403. List<GoodsVo> goodsList = goodsService.queryList(query);
  404. int total = goodsService.queryTotal(query);
  405. ApiPageUtils goodsData = new ApiPageUtils(goodsList, total, query.getLimit(), query.getPage());
  406. //搜索到的商品
  407. for (CategoryVo categoryEntity : filterCategory) {
  408. if (null != categoryId && categoryEntity.getId() == 0 || categoryEntity.getId() == categoryId) {
  409. categoryEntity.setChecked(true);
  410. } else {
  411. categoryEntity.setChecked(false);
  412. }
  413. }
  414. goodsData.setFilterCategory(filterCategory);
  415. return toResponsSuccess(goodsData);
  416. }
  417. /**
  418. *   获取疯狂折扣商品列表
  419. */
  420. @IgnoreAuth
  421. @GetMapping("hotGoodsList")
  422. public Object hotGoodsList(@LoginUser UserVo loginUser, Integer categoryId,
  423. @RequestParam(value = "page", defaultValue = "1") Integer
  424. page, @RequestParam(value = "size", defaultValue = "10") Integer size,
  425. String sort, String order) {
  426. Map reusltObj = Maps.newHashMap();
  427. //
  428. Long store_id = getStoreId();
  429. StoreVo storeVo = apiStoreService.queryObject(store_id);
  430. ThirdMerchantBizVo thirdMerchantBiz = new ThirdMerchantBizVo();
  431. if(storeVo != null) {
  432. thirdMerchantBiz = apiThirdMerchantBizService.getThirdMerchangByCode(storeVo.getThirdPartyMerchCode());
  433. if (null == thirdMerchantBiz) {
  434. return toResponsFail("第三方商户为空");
  435. }
  436. }
  437. Map params = Maps.newHashMap();
  438. //筛选的分类
  439. List<CategoryVo> filterCategory = new ArrayList();
  440. CategoryVo rootCategory = new CategoryVo();
  441. rootCategory.setId(0);
  442. rootCategory.setName("全部");
  443. rootCategory.setChecked(false);
  444. filterCategory.add(rootCategory);
  445. //
  446. params.put("fields", "psr1.category_id");
  447. params.put("is_hot", "1");
  448. params.put("store_id", store_id);
  449. List<GoodsVo> goodsEntityList = goodsService.queryList(params);
  450. params.remove("fields");
  451. if (null != goodsEntityList && goodsEntityList.size() > 0) {
  452. List<Integer> categoryIds = new ArrayList();
  453. for (GoodsVo goodsVo : goodsEntityList) {
  454. if (null == goodsVo || null == goodsVo.getCategory_id()) {
  455. continue;
  456. }
  457. categoryIds.add(goodsVo.getCategory_id());
  458. }
  459. //查找二级分类的parent_id
  460. Map categoryParam = Maps.newHashMap();
  461. categoryParam.put("ids", categoryIds);
  462. categoryParam.put("fields", "parent_id");
  463. List<CategoryVo> parentCategoryList = categoryService.queryList(categoryParam);
  464. //
  465. List<Integer> parentIds = new ArrayList();
  466. for (CategoryVo categoryEntity : parentCategoryList) {
  467. parentIds.add(categoryEntity.getParent_id());
  468. }
  469. //一级分类
  470. categoryParam = Maps.newHashMap();
  471. categoryParam.put("fields", "id,name");
  472. categoryParam.put("order", "asc");
  473. categoryParam.put("sidx", "sort_order");
  474. categoryParam.put("ids", parentIds);
  475. List<CategoryVo> parentCategory = categoryService.queryList(categoryParam);
  476. if (null != parentCategory) {
  477. filterCategory.addAll(parentCategory);
  478. }
  479. }
  480. params.put("category_parent_id", categoryId);
  481. params.put("fields", "a.id,a.name,a.goods_brief,a.list_pic_url,psr1.retail_price," +
  482. "psr1.market_price,b.id as product_id,psr1.stock_num");
  483. params.put("is_hot", "1");
  484. params.put("is_delete", 0);
  485. params.put("store_id", store_id);
  486. if (!StringUtils.isNullOrEmpty(sort) && !StringUtils.isNullOrEmpty(order)) {
  487. if (sort.equals("price")) {
  488. params.put("sidx", "psr1.retail_price");
  489. params.put("order", order);
  490. }
  491. }
  492. reusltObj.put("filterCategory", filterCategory);
  493. params.put("isStockShare", thirdMerchantBiz.getIsStockShare());
  494. params.put("page", page);
  495. params.put("limit", size);
  496. Query query = new Query(params);
  497. List<GoodsVo> hotGoods = goodsService.queryHotGoodsList(query);
  498. // 当前购物车中
  499. List<CartVo> cartList = new ArrayList();
  500. if (null != getUserId()) {
  501. //查询列表数据
  502. Map cartParam = Maps.newHashMap();
  503. cartParam.put("user_id", getUserId());
  504. cartParam.put("store_id", getStoreId());
  505. cartParam.put("isStockShare", thirdMerchantBiz.getIsStockShare());
  506. cartList = cartService.queryList(cartParam);
  507. }
  508. if (null != cartList && cartList.size() > 0 && null != hotGoods && hotGoods.size() > 0) {
  509. for (GoodsVo goodsVo : hotGoods) {
  510. for (CartVo cartVo : cartList) {
  511. if (goodsVo.getId().equals(cartVo.getGoods_id())) {
  512. goodsVo.setCart_num(cartVo.getNumber());
  513. }
  514. }
  515. }
  516. }
  517. reusltObj.put("goodsList", hotGoods);
  518. return toResponsSuccess(reusltObj);
  519. }
  520. /**
  521. *   新品首发
  522. */
  523. @IgnoreAuth
  524. @GetMapping("new")
  525. public Object newAction(@LoginUser UserVo loginUser) {
  526. Map<String, Object> resultObj = Maps.newHashMap();
  527. Map bannerInfo = Maps.newHashMap();
  528. bannerInfo.put("url", "");
  529. bannerInfo.put("name", "坚持初心,为你寻觅世间好物");
  530. bannerInfo.put("img_url", "http://yanxuan.nosdn.127.net/8976116db321744084774643a933c5ce.png");
  531. resultObj.put("bannerInfo", bannerInfo);
  532. return toResponsSuccess(resultObj);
  533. }
  534. /**
  535. *   人气推荐
  536. */
  537. @IgnoreAuth
  538. @GetMapping("hot")
  539. public Object hot(@LoginUser UserVo loginUser) {
  540. Map<String, Object> resultObj = Maps.newHashMap();
  541. //
  542. Map param = Maps.newHashMap();
  543. param.put("ad_position_id", 4);
  544. List<AdVo> adVoList = apiAdService.queryList(param);
  545. if (null != adVoList && adVoList.size() > 0) {
  546. Map bannerInfo = Maps.newHashMap();
  547. bannerInfo.put("url", "");
  548. bannerInfo.put("name", adVoList.get(0).getName());
  549. bannerInfo.put("img_url", adVoList.get(0).getImageUrl());
  550. resultObj.put("bannerInfo", bannerInfo);
  551. } else {
  552. Map bannerInfo = Maps.newHashMap();
  553. bannerInfo.put("url", "");
  554. bannerInfo.put("name", "大家都在商城选好物");
  555. bannerInfo.put("img_url", "https://platform-wxmall.oss-cn-beijing.aliyuncs.com/upload/20180807/1057182334dfb2.png");
  556. resultObj.put("bannerInfo", bannerInfo);
  557. }
  558. return toResponsSuccess(resultObj);
  559. }
  560. /**
  561. *   商品详情页的大家都在看的商品
  562. */
  563. @IgnoreAuth
  564. @GetMapping("related")
  565. public Object related(@LoginUser UserVo loginUser, Long id,
  566. @RequestParam(value = "page", defaultValue = "1") Integer
  567. page, @RequestParam(value = "size", defaultValue = "4") Integer size) {
  568. Map<String, Object> resultObj = Maps.newHashMap();
  569. Map param = Maps.newHashMap();
  570. param.put("goods_id", id);
  571. param.put("fields", "related_goods_id");
  572. List<RelatedGoodsVo> relatedGoodsEntityList = relatedGoodsService.queryList(param);
  573. List<Integer> relatedGoodsIds = new ArrayList();
  574. for (RelatedGoodsVo relatedGoodsEntity : relatedGoodsEntityList) {
  575. relatedGoodsIds.add(relatedGoodsEntity.getRelated_goods_id());
  576. }
  577. List<Integer> relatedGoods = new ArrayList();
  578. if (null == relatedGoodsIds || relatedGoods.size() < 1) {
  579. //查找同分类下的商品
  580. GoodsVo goodsCategory = goodsService.queryObjectByStoreId(id, getStoreId());
  581. if (null != goodsCategory) {
  582. Map paramRelated = Maps.newHashMap();
  583. paramRelated.put("store_id", getStoreId());
  584. paramRelated.put("notGoodsBizType", true);
  585. paramRelated.put("fields", "a.id, a.name, a.list_pic_url, psr1.retail_price,b.id as product_id");
  586. paramRelated.put("category_id", goodsCategory.getCategory_id());
  587. paramRelated.put("limit", size);
  588. paramRelated.put("offset", (page - 1) * size);
  589. paramRelated.put("sidx", "a.create_time");
  590. paramRelated.put("order", "desc");
  591. relatedGoods = goodsService.queryList(paramRelated);
  592. }
  593. } else {
  594. Map paramRelated = Maps.newHashMap();
  595. paramRelated.put("store_id", getStoreId());
  596. paramRelated.put("notGoodsBizType", true);
  597. paramRelated.put("goods_ids", relatedGoodsIds);
  598. paramRelated.put("fields", "a.id, a.name, a.list_pic_url, psr1.retail_price,b.id as product_id");
  599. paramRelated.put("limit", size);
  600. paramRelated.put("offset", (page - 1) * size);
  601. paramRelated.put("sidx", "a.create_time");
  602. paramRelated.put("order", "desc");
  603. relatedGoods = goodsService.queryList(paramRelated);
  604. }
  605. resultObj.put("goodsList", relatedGoods);
  606. return toResponsSuccess(resultObj);
  607. }
  608. /**
  609. * 在售的商品总数
  610. */
  611. @IgnoreAuth
  612. @GetMapping("count")
  613. public Object count(@LoginUser UserVo loginUser) {
  614. Map<String, Object> resultObj = Maps.newHashMap();
  615. Map param = Maps.newHashMap();
  616. param.put("storeId", getStoreId());
  617. param.put("notGoodsBizType", true);
  618. param.put("is_delete", 0);
  619. param.put("is_on_sale", 1);
  620. Integer goodsCount = goodsService.queryTotal(param);
  621. resultObj.put("goodsCount", goodsCount);
  622. return toResponsSuccess(resultObj);
  623. }
  624. /**
  625. *   获取商品列表
  626. */
  627. @IgnoreAuth
  628. @GetMapping("productlist")
  629. public Object productlist(@LoginUser UserVo loginUser, Integer categoryId,
  630. Integer isNew, Integer discount,String goodsBizType,
  631. @RequestParam(value = "page", defaultValue = "1") Integer
  632. page, @RequestParam(value = "size", defaultValue = "10") Integer size,
  633. String sort, String order) {
  634. Long storeId = getStoreId();
  635. Map params = Maps.newHashMap();
  636. params.put("is_new", isNew);
  637. params.put("page", page);
  638. params.put("limit", size);
  639. params.put("order", sort);
  640. params.put("sidx", order);
  641. params.put("store_id", storeId);
  642. StoreVo storeVo = apiStoreService.queryObject(storeId);
  643. String isStockShare = "";
  644. if(storeVo != null) {
  645. ThirdMerchantBizVo thirdMerchantBiz = apiThirdMerchantBizService.getThirdMerchangByCode(storeVo.getThirdPartyMerchCode());
  646. if (null == thirdMerchantBiz) {
  647. return toResponsFail("第三方商户为空");
  648. }
  649. isStockShare = thirdMerchantBiz.getIsStockShare();
  650. }
  651. //
  652. if (null != sort && sort.equals("price")) {
  653. params.put("sidx", "psr1.retail_price");
  654. params.put("order", order);
  655. } else if (null != sort && sort.equals("sell") && Dict.isStockShare.item_0.getItem().equalsIgnoreCase(isStockShare)) {
  656. params.put("sidx", "psr1.sell_volume");
  657. params.put("order", order);
  658. } else if (null != sort && sort.equals("sell") && Dict.isStockShare.item_1.getItem().equalsIgnoreCase(isStockShare)) {
  659. params.put("sidx", "a.sell_volume");
  660. params.put("order", order);
  661. } else {
  662. params.put("sidx", "id");
  663. params.put("order", "desc");
  664. }
  665. // 0不限 1特价 2团购
  666. if (null != discount && discount == 1) {
  667. params.put("is_hot", 1);
  668. } else if (null != discount && discount == 2) {
  669. params.put("is_group", true);
  670. }
  671. params.put("goodsBizType", goodsBizType);
  672. CategoryVo categoryVo = categoryService.queryObject(categoryId);
  673. if(categoryVo != null){
  674. if(categoryVo.getSort_order()!= null && categoryVo.getSort_order()== 0){
  675. }else{
  676. params.put("category_parent_id", categoryId);
  677. }
  678. }
  679. //查询列表数据
  680. Query query = new Query(params);
  681. List<GoodsVo> goodsList = goodsService.queryCatalogProductList(query);
  682. int total = goodsService.queryTotal(query);
  683. // 当前购物车中
  684. List<CartVo> cartList = new ArrayList();
  685. if (null != getUserId()) {
  686. //查询列表数据
  687. Map cartParam = Maps.newHashMap();
  688. cartParam.put("user_id", getUserId());
  689. cartParam.put("store_id", storeId);
  690. cartParam.put("isStockShare", isStockShare);
  691. cartList = cartService.queryList(cartParam);
  692. }
  693. if (null != cartList && cartList.size() > 0 && null != goodsList && goodsList.size() > 0) {
  694. for (GoodsVo goodsVo : goodsList) {
  695. for (CartVo cartVo : cartList) {
  696. if (goodsVo.getId().equals(cartVo.getGoods_id())) {
  697. goodsVo.setCart_num(cartVo.getNumber());
  698. }
  699. }
  700. }
  701. }
  702. ApiPageUtils goodsData = new ApiPageUtils(goodsList, total, query.getLimit(), query.getPage());
  703. return toResponsSuccess(goodsData);
  704. }
  705. }