123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- package com.fuint.module.clientApi.controller;
- import com.alibaba.fastjson.JSONObject;
- import com.fuint.common.Constants;
- import com.fuint.common.dto.*;
- import com.fuint.common.enums.StatusEnum;
- import com.fuint.common.enums.YesOrNoEnum;
- import com.fuint.common.param.GoodsInfoParam;
- import com.fuint.common.service.CateService;
- import com.fuint.common.service.GoodsService;
- import com.fuint.common.service.MerchantService;
- import com.fuint.common.service.SettingService;
- import com.fuint.common.util.CommonUtil;
- import com.fuint.framework.exception.BusinessCheckException;
- import com.fuint.framework.pagination.PaginationRequest;
- import com.fuint.framework.pagination.PaginationResponse;
- import com.fuint.framework.web.BaseController;
- import com.fuint.framework.web.ResponseObject;
- import com.fuint.module.clientApi.request.GoodsSearchRequest;
- import com.fuint.repository.model.MtGoods;
- import com.fuint.repository.model.MtGoodsCate;
- import com.fuint.repository.model.MtGoodsSku;
- import com.fuint.repository.model.MtGoodsSpec;
- import com.fuint.utils.StringUtil;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import lombok.AllArgsConstructor;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import java.lang.reflect.InvocationTargetException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- /**
- * 商品类controller
- *
- * Created by FSQ
- * CopyRight https://www.fuint.cn
- */
- @Api(tags="会员端-商品相关接口")
- @RestController
- @AllArgsConstructor
- @RequestMapping(value = "/clientApi/goodsApi")
- public class ClientGoodsController extends BaseController {
- /**
- * 商品服务接口
- * */
- private GoodsService goodsService;
- /**
- * 商品类别服务接口
- * */
- private CateService cateService;
- /**
- * 系统设置服务接口
- * */
- private SettingService settingService;
- /**
- * 商户服务接口
- */
- private MerchantService merchantService;
- /**
- * 获取商品分类列表
- */
- @ApiOperation(value = "获取商品分类列表")
- @RequestMapping(value = "/cateList", method = RequestMethod.GET)
- @CrossOrigin
- public ResponseObject cateList(HttpServletRequest request) throws BusinessCheckException {
- String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
- Integer storeId = request.getHeader("storeId") == null ? 0 : Integer.parseInt(request.getHeader("storeId"));
- String platform = request.getHeader("platform") == null ? "" : request.getHeader("platform");
- Integer merchantId = merchantService.getMerchantId(merchantNo);
- List<MtGoodsCate> cateList = cateService.getCateList(merchantId, storeId, null, StatusEnum.ENABLED.getKey());
- Map<String, Object> goodsData = goodsService.getStoreGoodsList(storeId, "", platform, 0, 1, 500);
- List<MtGoods> goodsList = (ArrayList)goodsData.get("goodsList");
- String baseImage = settingService.getUploadBasePath();
- if (goodsList.size() > 0) {
- for (MtGoods goods : goodsList) {
- goods.setLogo(baseImage + goods.getLogo());
- }
- }
- List<ResCateDto> result = new ArrayList<>();
- for (MtGoodsCate cate : cateList) {
- ResCateDto dto = new ResCateDto();
- dto.setCateId(cate.getId());
- dto.setName(cate.getName());
- dto.setLogo(baseImage + cate.getLogo());
- List<MtGoods> goodsArr = new ArrayList<>();
- for (MtGoods goods : goodsList) {
- if (goods.getCateId().compareTo(cate.getId()) == 0) {
- goodsArr.add(goods);
- }
- }
- dto.setGoodsList(goodsArr);
- result.add(dto);
- }
- return getSuccessResult(result);
- }
- /**
- * 获取商品列表
- */
- @ApiOperation(value = "获取商品列表")
- @RequestMapping(value = "/list", method = RequestMethod.GET)
- @CrossOrigin
- public ResponseObject list(HttpServletRequest request) throws BusinessCheckException {
- Integer storeId = request.getHeader("storeId") == null ? 0 : Integer.parseInt(request.getHeader("storeId"));
- String platform = request.getHeader("platform") == null ? "" : request.getHeader("platform");
- Map<String, Object> goodsData = goodsService.getStoreGoodsList(storeId, "", platform, 0,1, 200);
- return getSuccessResult(goodsData.get("goodsList"));
- }
- /**
- * 搜索商品
- */
- @ApiOperation(value = "搜索商品")
- @RequestMapping(value = "/search", method = RequestMethod.POST)
- @CrossOrigin
- public ResponseObject search(HttpServletRequest request, @RequestBody GoodsSearchRequest params) throws BusinessCheckException {
- Integer storeId = request.getHeader("storeId") == null ? 0 : Integer.parseInt(request.getHeader("storeId"));
- String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
- String platform = request.getHeader("platform") == null ? "" : request.getHeader("platform");
- Integer page = params.getPage() == null ? 1 : params.getPage();
- Integer pageSize = params.getPageSize() == null ? Constants.PAGE_SIZE : params.getPageSize();
- String name = params.getName() == null ? "" : params.getName();
- Integer cateId = params.getCateId() == null ? 0 : params.getCateId();
- String sortType = params.getSortType() == null ? "all" : params.getSortType();
- String sortPrice = params.getSortPrice() == null ? "0" : params.getSortPrice();
- PaginationRequest paginationRequest = new PaginationRequest();
- paginationRequest.setCurrentPage(page);
- paginationRequest.setPageSize(pageSize);
- Map<String, Object> searchParams = new HashMap<>();
- searchParams.put("status", StatusEnum.ENABLED.getKey());
- searchParams.put("hasPrice", YesOrNoEnum.YES.getKey());
- if (storeId > 0) {
- searchParams.put("storeId", storeId.toString());
- }
- if (cateId > 0) {
- searchParams.put("cateId", cateId);
- }
- if (StringUtil.isNotEmpty(name)) {
- searchParams.put("name", name);
- }
- Integer merchantId = merchantService.getMerchantId(merchantNo);
- if (merchantId > 0 ) {
- searchParams.put("merchantId", merchantId);
- }
- if (StringUtil.isNotEmpty(sortType)) {
- searchParams.put("sortType", sortType);
- }
- if (StringUtil.isNotEmpty(sortPrice)) {
- searchParams.put("sortPrice", sortPrice);
- }
- if (StringUtil.isNotEmpty(platform)) {
- searchParams.put("platform", platform);
- }
- paginationRequest.setSearchParams(searchParams);
- PaginationResponse<GoodsDto> paginationResponse = goodsService.queryGoodsListByPagination(paginationRequest);
- return getSuccessResult(paginationResponse);
- }
- /**
- * 获取商品详情
- */
- @ApiOperation(value = "获取商品详情")
- @RequestMapping(value = "/detail", method = RequestMethod.POST)
- @CrossOrigin
- public ResponseObject detail(@RequestBody GoodsInfoParam goodsInfoParam) throws BusinessCheckException, InvocationTargetException, IllegalAccessException {
- String goodsId = goodsInfoParam.getGoodsId() == null ? "0" : goodsInfoParam.getGoodsId();
- if (StringUtil.isEmpty(goodsId)) {
- return getFailureResult(2000, "商品ID不能为空");
- }
- GoodsDto goodsDto = goodsService.getGoodsDetail(Integer.parseInt(goodsId), false);
- GoodsDetailDto goodsDetailDto = new GoodsDetailDto();
- goodsDetailDto.setGoodsNo(goodsDto.getGoodsNo());
- goodsDetailDto.setGoodsId(goodsDto.getId());
- goodsDetailDto.setName(goodsDto.getName());
- goodsDetailDto.setCateId(goodsDto.getCateId());
- goodsDetailDto.setPrice(goodsDto.getPrice());
- goodsDetailDto.setLinePrice(goodsDto.getLinePrice());
- goodsDetailDto.setSalePoint(goodsDto.getSalePoint());
- goodsDetailDto.setSort(goodsDto.getSort());
- goodsDetailDto.setCanUsePoint(goodsDto.getCanUsePoint());
- goodsDetailDto.setIsMemberDiscount(goodsDto.getIsMemberDiscount());
- List<String> images = JSONObject.parseArray(goodsDto.getImages(), String.class);
- List<String> imageList = new ArrayList<>();
- String baseImage = settingService.getUploadBasePath();
- for (String image : images) {
- imageList.add((baseImage + image));
- }
- goodsDetailDto.setImages(imageList);
- goodsDetailDto.setIsSingleSpec(goodsDto.getIsSingleSpec());
- goodsDetailDto.setLogo(goodsDto.getLogo());
- goodsDetailDto.setStock(goodsDto.getStock());
- goodsDetailDto.setWeight(goodsDto.getWeight());
- goodsDetailDto.setDescription(goodsDto.getDescription());
- if (StringUtil.isNotEmpty(goodsDetailDto.getDescription())) {
- goodsDetailDto.setDescription(CommonUtil.fixVideo(goodsDetailDto.getDescription()));
- }
- goodsDetailDto.setInitSale(goodsDto.getInitSale());
- goodsDetailDto.setStatus(goodsDto.getStatus());
- // 商品规格列表
- List<MtGoodsSpec> goodsSpecList = goodsDto.getSpecList();
- List<String> specNameArr = new ArrayList<>();
- List<MtGoodsSpec> specArr = new ArrayList<>();
- for (MtGoodsSpec mtGoodsSpec : goodsSpecList) {
- if (!specNameArr.contains(mtGoodsSpec.getName())) {
- MtGoodsSpec spec = new MtGoodsSpec();
- spec.setId(mtGoodsSpec.getId());
- spec.setName(mtGoodsSpec.getName());
- specArr.add(spec);
- specNameArr.add(mtGoodsSpec.getName());
- }
- }
- List<GoodsSpecDto> specDtoList = new ArrayList<>();
- for (MtGoodsSpec mtSpec : specArr) {
- GoodsSpecDto dto = new GoodsSpecDto();
- dto.setSpecId(mtSpec.getId());
- dto.setName(mtSpec.getName());
- List<GoodsSpecValueDto> valueList = new ArrayList<>();
- for (MtGoodsSpec spec : goodsSpecList) {
- if (spec.getName().equals(mtSpec.getName())) {
- GoodsSpecValueDto valueDto = new GoodsSpecValueDto();
- valueDto.setSpecValue(spec.getValue());
- valueDto.setSpecValueId(spec.getId());
- valueList.add(valueDto);
- }
- }
- dto.setValueList(valueList);
- if (!goodsDetailDto.getIsSingleSpec().equals(YesOrNoEnum.YES.getKey())) {
- specDtoList.add(dto);
- }
- }
- // sku列表
- List<MtGoodsSku> goodsSkuList = goodsDto.getSkuList();
- List<GoodsSkuDto> skuDtoList = new ArrayList<>();
- String basePath = settingService.getUploadBasePath();
- for (MtGoodsSku sku : goodsSkuList) {
- GoodsSkuDto dto = new GoodsSkuDto();
- dto.setId(sku.getId());
- if (sku.getLogo() != null && StringUtil.isNotEmpty(sku.getLogo())) {
- dto.setLogo(basePath + sku.getLogo());
- } else {
- dto.setLogo(goodsDetailDto.getLogo());
- }
- dto.setGoodsId(sku.getGoodsId());
- dto.setSkuNo(sku.getSkuNo());
- dto.setPrice(sku.getPrice());
- dto.setLinePrice(sku.getLinePrice());
- dto.setStock(sku.getStock());
- dto.setWeight(sku.getWeight());
- dto.setSpecIds(sku.getSpecIds());
- skuDtoList.add(dto);
- }
- if (goodsDetailDto.getIsSingleSpec().equals(YesOrNoEnum.YES.getKey())) {
- GoodsSkuDto dto = new GoodsSkuDto();
- dto.setId(0);
- dto.setLogo(goodsDetailDto.getLogo());
- dto.setGoodsId(goodsDetailDto.getGoodsId());
- dto.setSkuNo("");
- dto.setPrice(goodsDetailDto.getPrice());
- dto.setLinePrice(goodsDetailDto.getLinePrice());
- dto.setStock(goodsDetailDto.getStock());
- dto.setWeight(goodsDetailDto.getWeight());
- dto.setSpecIds("");
- skuDtoList.add(dto);
- }
- goodsDetailDto.setSpecList(specDtoList);
- goodsDetailDto.setSkuList(skuDtoList);
- return getSuccessResult(goodsDetailDto);
- }
- /**
- * 通过sku编码获取商品信息
- * */
- @ApiOperation(value = "通过sku编码获取商品信息")
- @RequestMapping(value = "/getGoodsInfoBySkuNo", method = RequestMethod.POST)
- @CrossOrigin
- public ResponseObject getGoodsInfoBySkuNo(HttpServletRequest request, @RequestBody GoodsInfoParam goodsInfoParam) throws BusinessCheckException, InvocationTargetException, IllegalAccessException {
- String merchantNo = request.getHeader("merchantNo") == null ? "" : request.getHeader("merchantNo");
- String skuNo = goodsInfoParam.getSkuNo() == null ? "" : goodsInfoParam.getSkuNo();
- if (StringUtil.isEmpty(skuNo)) {
- return getFailureResult(201, "商品编码不能为空");
- }
- Integer merchantId = merchantService.getMerchantId(merchantNo);
- Integer goodsId = 0;
- Integer skuId = 0;
- MtGoodsSku mtGoodsSku = goodsService.getSkuInfoBySkuNo(skuNo);
- if (mtGoodsSku == null) {
- MtGoods mtGoods = goodsService.queryGoodsByGoodsNo(merchantId, skuNo);
- if (mtGoods != null) {
- goodsId = mtGoods.getId();
- }
- } else {
- goodsId = mtGoodsSku.getGoodsId();
- skuId = mtGoodsSku.getId();
- }
- if (goodsId > 0) {
- GoodsDto goodsDto = goodsService.getGoodsDetail(goodsId, false);
- Map<String, Object> data = new HashMap();
- data.put("skuId", skuId);
- data.put("goodsInfo", goodsDto);
- return getSuccessResult(data);
- } else {
- return getFailureResult(201, "未查询到商品信息");
- }
- }
- }
|