ApiGoodsController.java 26 KB

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