| | |
| | | package com.sinata.modular.mall.controller; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import cn.hutool.json.JSONUtil; |
| | |
| | | import com.sinata.common.enums.EnumIsDelete; |
| | | import com.sinata.common.enums.mall.EnumMallGoodsGroupType; |
| | | import com.sinata.common.enums.mall.EnumMallGoodsState; |
| | | import com.sinata.common.model.GroupSpecGoodsSkuJsonVo; |
| | | import com.sinata.core.base.controller.BaseController; |
| | | import com.sinata.core.base.tips.ErrorTip; |
| | | import com.sinata.core.common.annotion.BussinessLog; |
| | |
| | | import com.sinata.core.common.constant.factory.PageFactory; |
| | | import com.sinata.core.common.exception.BizExceptionEnum; |
| | | import com.sinata.core.log.LogObjectHolder; |
| | | import com.sinata.core.shiro.ShiroKit; |
| | | import com.sinata.core.util.Convert; |
| | | import com.sinata.core.util.DateUtils2; |
| | | import com.sinata.core.util.ExcelExportUtil; |
| | | import com.sinata.core.util.SpringContextHolder; |
| | | import com.sinata.modular.mall.model.*; |
| | | import com.sinata.modular.mall.service.*; |
| | | import org.apache.commons.collections.CollectionUtils; |
| | |
| | | |
| | | @Autowired |
| | | private IMallGoodsService mallGoodsService; |
| | | |
| | | @Autowired |
| | | private IMallGroupSpecService groupSpecService; |
| | | |
| | | @Autowired |
| | | private IMallGoodsSkuService mallGoodsSkuService; |
| | |
| | | public List<MallGoodsSku> getGoodsSpecData(Integer goodsId) { |
| | | List<MallGoodsSku> skuList = mallGoodsSkuService.selectList( |
| | | new EntityWrapper<MallGoodsSku>() |
| | | .setSqlSelect("spec_ids id, grep_name, stock") |
| | | .setSqlSelect("spec_ids id, grep_name, stock,price_sale,price_member") |
| | | .eq("goods_id", goodsId) |
| | | .eq("merchant_id", 0) |
| | | ); |
| | |
| | | wrapper.eq("group_type", groupType); |
| | | } |
| | | List<MallGoods> goodsList = mallGoodsService.selectList(wrapper); |
| | | List<HashMap<String, Object>> goodsMapList = goodsList.stream().map(goods -> { |
| | | HashMap<String, Object> goodMap = new HashMap<>(); |
| | | //商品编号 |
| | | goodMap.put("aGoodsNo", goods.getGoodsNo()); |
| | | goodMap.put("bName", goods.getGoodsName()); |
| | | goodMap.put("cGroupType", goods.getGroupType()); |
| | | String groupTypName = goods.getGroupType() > 0 ? (goods.getGroupType() == 1 ? "黄金套餐" : "钻石套餐") : "普通商品"; |
| | | goodMap.put("cGroupTypeName", groupTypName); |
| | | goodMap.put("dPrice", goods.getPrice()); |
| | | goodMap.put("dPriceDale", goods.getPriceSale()); |
| | | goodMap.put("ePriceMember", goods.getPriceMember()); |
| | | goodMap.put("fStock", goods.getStock()); |
| | | goodMap.put("gBuyCount", goods.getBuyCount()); |
| | | goodMap.put("hId", goods.getId()); |
| | | return goodMap; |
| | | }).collect(Collectors.toList()); |
| | | Set<Integer> goodsIdList = goodsList.stream().map(MallGoods::getId).collect(Collectors.toSet()); |
| | | Wrapper skuWrapper = new EntityWrapper<MallGoodsSku>().in("goods_id", goodsIdList) |
| | | .eq("merchant_id", 0).orderBy("id", false); |
| | | List<MallGoodsSku> skuList = mallGoodsSkuService.selectList(skuWrapper); |
| | | List<HashMap<String, Object>> result = new ArrayList<>(); |
| | | goodsList.forEach(goods -> { |
| | | List<MallGoodsSku> goodsSkuList = skuList.stream() |
| | | .filter(sku -> sku.getGoodsId().equals(goods.getId())) |
| | | .collect(Collectors.toList()); |
| | | List<HashMap<String, Object>> goodsMapList = goodsSkuList.stream().map(sku -> { |
| | | HashMap<String, Object> goodMap = new HashMap<>(); |
| | | //商品编号 |
| | | goodMap.put("aGoodsNo", goods.getGoodsNo()); |
| | | goodMap.put("bName", goods.getGoodsName()); |
| | | goodMap.put("bbGrepName", sku.getGrepName()); |
| | | goodMap.put("cGroupType", goods.getGroupType()); |
| | | String groupTypName = goods.getGroupType() > 0 ? (goods.getGroupType() == 1 ? "黄金套餐" |
| | | : "钻石套餐") : "普通商品"; |
| | | goodMap.put("cGroupTypeName", groupTypName); |
| | | goodMap.put("dPrice", goods.getPrice()); |
| | | goodMap.put("dPriceDale", sku.getPriceSale()); |
| | | goodMap.put("ePriceMember", sku.getPriceMember()); |
| | | goodMap.put("fStock", sku.getStock()); |
| | | goodMap.put("gBuyCount", goods.getBuyCount()); |
| | | goodMap.put("hId", goods.getId()); |
| | | goodMap.put("iSpecIds", sku.getSpecIds()); |
| | | goodMap.put("jSkuId", sku.getId()); |
| | | return goodMap; |
| | | }).collect(Collectors.toList()); |
| | | result.addAll(goodsMapList); |
| | | }); |
| | | /*for (int i = 0; i < result.size(); i++) { |
| | | for (int j = i+1; j < result.size(); j++) { |
| | | if (result.get(i).get("hId").equals(result.get(j).get("hId"))) { |
| | | result.get(j).put("bName",""); |
| | | } |
| | | } |
| | | }*/ |
| | | return new HashMap<String, Object>() {{ |
| | | put("code", 200); |
| | | put("value", goodsMapList); |
| | | put("value", result); |
| | | }}; |
| | | } |
| | | |
| | |
| | | |
| | | @BussinessLog(value = "获取商品规格") |
| | | @RequestMapping(value = "/getGoodsSpecs") |
| | | public Object getGoodsSpecs(Integer oneClassifyId, Integer twoClassifyId, Model model) { |
| | | public Object getGoodsSpecs(Integer oneClassifyId, Integer twoClassifyId,@RequestParam(required = false) List<String> selectedItems, Model model) { |
| | | Wrapper<MallGoodsSpec> wrapper = new EntityWrapper<MallGoodsSpec>() |
| | | .eq("is_delete", EnumIsDelete.EXISTED.index) |
| | | .addFilter("concat(',',classify_id_one,',') like concat( '%,', {0}, ',%' )", oneClassifyId); |
| | | List<MallGoodsSpec> goodsSpecs = this.goodsSpecService.selectList(wrapper); |
| | | if (CollectionUtils.isEmpty(goodsSpecs)) { |
| | | goodsSpecs = Lists.newArrayList(); |
| | | } |
| | | if (!selectedItems.isEmpty()) { |
| | | goodsSpecs = goodsSpecs.stream() |
| | | .filter(specs -> !selectedItems.contains(specs.getSpecName())).collect( |
| | | Collectors.toList()); |
| | | } |
| | | model.addAttribute("goodsSpecs", goodsSpecs); |
| | | return PREFIX + "add_specs.html"; |
| | |
| | | .in("id", ids.split(",")) |
| | | ); |
| | | } |
| | | |
| | | @ResponseBody |
| | | @BussinessLog(value = "获取商品列表") |
| | | @GetMapping(value = "/goodsByGoodsSpecId") |
| | | public List<Map<String, Object>> goodsByIdsList(String goodsIds, Integer groupSpecId, String oldGoodsSkuJson) { |
| | | List<MallGoods> goodsList = mallGoodsService.selectList( |
| | | new EntityWrapper<MallGoods>() |
| | | .eq("group_type", EnumMallGoodsGroupType.GOODS.index) |
| | | .in("id", goodsIds.split(",")) |
| | | ); |
| | | |
| | | List<Map<String, Object>> list; |
| | | if (groupSpecId != null) { |
| | | String goodsSkuJson = oldGoodsSkuJson; |
| | | if (StrUtil.isBlank(goodsSkuJson) || goodsSkuJson.equals("[]")) { |
| | | // 查询套餐规格组信息 |
| | | MallGroupSpec groupSpec = groupSpecService.selectById(groupSpecId); |
| | | goodsSkuJson = groupSpec.getGoodsSkuJson(); |
| | | } |
| | | |
| | | // 格式化套餐规格组数据 |
| | | List<GroupSpecGoodsSkuJsonVo> groupSpecGoodsSkuJsonVoList; |
| | | if (StrUtil.isBlank(goodsSkuJson) || goodsSkuJson.equals("[]")) { |
| | | groupSpecGoodsSkuJsonVoList = null; |
| | | } else { |
| | | groupSpecGoodsSkuJsonVoList = JSONUtil.parseArray(goodsSkuJson).toList(GroupSpecGoodsSkuJsonVo.class); |
| | | } |
| | | |
| | | list = goodsList.stream().map(o -> { |
| | | Map<String, Object> map = BeanUtil.beanToMap(o); |
| | | Integer goodsNum = 1; |
| | | if (groupSpecGoodsSkuJsonVoList != null) { |
| | | // 匹配商品数量 |
| | | for (GroupSpecGoodsSkuJsonVo groupSpecGoodsSkuJsonVo : groupSpecGoodsSkuJsonVoList) { |
| | | if (o.getId().equals(groupSpecGoodsSkuJsonVo.getGoodsId())) { |
| | | goodsNum = groupSpecGoodsSkuJsonVo.getGoodsNum(); |
| | | } |
| | | } |
| | | } |
| | | map.put("goodsNum", goodsNum); |
| | | return map; |
| | | }).collect(Collectors.toList()); |
| | | } else { |
| | | list = goodsList.stream().map(o -> { |
| | | Map<String, Object> map = BeanUtil.beanToMap(o); |
| | | map.put("goodsNum", 1); |
| | | return map; |
| | | }).collect(Collectors.toList()); |
| | | } |
| | | return list; |
| | | } |
| | | } |