sku规格设计I中规格及J中规格明细之间的联动
来源:互联网 发布:科尔沃折叠刀淘宝 编辑:程序博客网 时间:2024/05/17 09:42
最近在开发SKU这块,负责写接口,在规格联动这块卡住了许久,最后在大神的帮助下,终于写出来了.现在我在此给大家分享
1.数据库设计 一个商品SPU对应多个SKU
sku表设计
sku表和规格的中间表
规格表
规格明细表
2.前端要达到的效果
3.思路
4.代码实现
/** * 获取当前sku 的货品所有的规格明细 * * @return */@ResponseBody@RequestMapping("/getSpecificationAll")public JData getSpecificationAll() { JSONObject jsonObject = JSONObject.parseObject(getData()); Integer skuId = jsonObject.getInteger("skuId"); ProductSku productSku = productSkuService.selectBySkuId(skuId); List<Integer> productSpecificationList = productSpecificationService.findBySkuId(skuId); //获取所有的规格详细 List<Integer> specificationIds = productSpecificationService.getSpecificationsByProductId(productSku.getProductId()); List<SpecificationModel> specificationModels =new ArrayList<SpecificationModel>(); if(specificationIds!=null && specificationIds.size()>0){ specificationModels = specificationService.getAllSpecifications(specificationIds); //sku与规格中间表list List<Integer[]> listZH = CombinationUtils.Zhlist(productSpecificationList); List<ProductSpecificationDetailIds> psdIds = productSpecificationService.getPsdIds(productSku.getProductId()); //规格联动置灰 changeGrey(specificationModels, listZH, psdIds); } return new JData(ReturnCode.SUCCESS, specificationModels);}将前台传过来的规格明细id进行组合
public static List<Integer[]> Zhlist(List<Integer> list){ List<Integer[]> listZH =new ArrayList<Integer[]>(); for (int i=0;i<list.size();i++){ Integer[] array =new Integer[list.size()-1]; int count=0; for (int j=0;j<list.size();j++){ if(i!=j){ array[count] =list.get(j); count++; } } listZH.add(array); } return listZH;}
此规格联动置灰方法时公有的,初始化和切换规格都可以用
lsitZh是前台传过来的规格明细id组合 [黄色id,100ml id] [黄色id,30id] [100ml id,30id]
specificationModels 是一个集合,集合SpecificationModel 规格基本属性 + 规格明细List集合
psdIds 是所有上架的规格id组合 [黄色,100ml,10] [黄色,100ml,30].......这是都是上架的
字段grey是将规格明细置灰
/** * 规格联动置灰 * * @param specificationModels 规格详细 * @param listZH 前台传过来的规格详细id 组合 * @param psdIds 所有上架的规格id组合 */public void changeGrey(List<SpecificationModel> specificationModels, List<Integer[]> listZH, List<ProductSpecificationDetailIds> psdIds) { for (int i = 0; i < specificationModels.size(); i++) { Integer[] integers = listZH.get(i); List<SpecificationDetail> specificationDetailList = specificationModels.get(i).getSpecificationDetailList(); //规格明细 for (SpecificationDetail sfd : specificationDetailList) { boolean canSelect = false; for (int j = 0; j < psdIds.size(); j++) { List<Integer> specificationDetailIdNList = psdIds.get(j).getSpecificationDetailIdNList(); int count = 0; boolean needContinue = false; for (int k = 0; k < specificationModels.size(); k++) { if (k == i) { if (sfd.getId().equals(specificationDetailIdNList.get(i))) { } else { needContinue = true; break; } } else { if (integers[count].equals(specificationDetailIdNList.get(k))) { count++; } else { needContinue = true; break; } } if (k == specificationModels.size() - 1) { canSelect = true; } } if (needContinue) continue; if (canSelect) { sfd.setGrey(true); break; } } if (sfd.getGrey() == null) sfd.setGrey(false); } }}
阅读全文
0 0
- sku规格设计I中规格及J中规格明细之间的联动
- 网页设计中基本的规格
- Android 商品详情中规格的联动选择实现
- 谈谈电子商务系统中的规格设计,SKU的简单管理
- 接口规格的设计
- android中图片规格
- 网站设计中标准网页广告规格
- 商品规格sku算法应用
- 网页商品SKU(规格)选择
- Axure RP Pro - Specification规格文档 - 规格文档中显示部件的属性
- Axure RP Pro - Specification规格文档 - 规格文档中屏幕截图的脚标
- SKU的笛卡尔积计算,未知规格数量
- 规格参数设计思路
- 商品sku,N规格js实现
- ios开发中导航栏背景的出图规格
- Yii CModel中rules验证规格
- Yii CModel中rules验证规格
- Yii CModel中rules验证规格
- VMware虚拟磁盘管理器用法帮助 用法:vmware-vdiskmanager.exe
- 谈“+”,你真的了解么?一个面试题引发的思考------2017.10.19
- Python出现: TypeError: expected string or buffer
- 搭建本地git服务器(前面Linux版本为:Ubuntu或Debian;后面Linux版本为:CentOs)
- Codeforces Round #441 (Div. 2, by Moscow Team Olympiad) C. Classroom Watch
- sku规格设计I中规格及J中规格明细之间的联动
- 多态
- 剑指offer--跳台阶
- 高通 android 源代码以及目标系统目录结构
- 基于 Azure 托管磁盘配置高可用共享文件系统
- 时间加上偏移量于当前时间比较大小 java实现
- 结合php验证码图片生成实现点击刷新
- JavaScript一些简单的内置对象(String,Math,Date)
- 如何查看和设置sga和pga的当前内存的建议值