1
0

ApiGoodsController.java 24 KB

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