概述
商品规格表:
CREATE TABLE `shop_sku` (
`id` varchar(64) NOT NULL DEFAULT '' COMMENT '商品规格',
`name` varchar(64) DEFAULT '' COMMENT '名称',
`img` varchar(1000) DEFAULT '' COMMENT '规格图片',
`money` double(20,2) DEFAULT '0.00' COMMENT '售价',
`pid` varchar(64) DEFAULT '' COMMENT '上级规格id 如果为空则自己是上级',
`shopid` varchar(64) DEFAULT '' COMMENT '商品id',
`status` int(2) DEFAULT '1' COMMENT '1有效 2无效',
`ctime` varchar(64) DEFAULT '' COMMENT '时间',
`num` int(11) DEFAULT '0' COMMENT '库存',
`sort` int(20) DEFAULT '0' COMMENT '排序',
`weight` double DEFAULT NULL COMMENT '重量',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
商品表:
CREATE TABLE `shop_info` (
`id` varchar(64) NOT NULL DEFAULT '' COMMENT '商品',
`sort` int(11) DEFAULT '0' COMMENT '排序字段',
`shop_typeid` int(11) DEFAULT '0' COMMENT '商品分类id',
`type` int(2) DEFAULT '1' COMMENT '1 普通商品 2新人优惠商品 3秒杀商品 4团购商品 5会员商品',
`shop_name` varchar(64) DEFAULT '' COMMENT '商品名称(加粗)',
`title` varchar(64) DEFAULT '' COMMENT '名称(不加粗)',
`shop_img` varchar(200) DEFAULT '' COMMENT '商品图片',
`imgs` varchar(5000) DEFAULT '' COMMENT '轮播图片',
`sell_money` double(20,2) DEFAULT '0.00' COMMENT '原价',
`real_money` double(20,2) DEFAULT '0.00' COMMENT '售价',
`sku_first_name` varchar(32) DEFAULT '' COMMENT '一级sku名字',
`sku_two_name` varchar(32) DEFAULT '' COMMENT '二级sku名字',
`sell_num` int(11) DEFAULT '0' COMMENT '销量',
`shop_num` int(11) DEFAULT '0' COMMENT '库存',
`type_name` varchar(64) DEFAULT '' COMMENT '分类名称',
`attri_name` varchar(64) DEFAULT '' COMMENT '属性',
`detials` longtext COMMENT '图文详情',
`is_show` int(2) DEFAULT '2' COMMENT '是否推荐 1是 2否',
`ctime` varchar(64) DEFAULT '' COMMENT '时间',
`status` int(2) DEFAULT '1' COMMENT '是否上架 1是 2否',
`is_delete` int(2) DEFAULT '1' COMMENT '1有效 2无效',
`is_fans` int(2) DEFAULT '2' COMMENT '是否收藏 1是 2否',
`car_num` int(11) DEFAULT '0' COMMENT '购物车数量',
`shop_type` int(2) DEFAULT '1' COMMENT '废弃字段',
`max_num` int(11) DEFAULT NULL COMMENT '开团人数',
`time_axis_id` int(11) DEFAULT NULL COMMENT '时间轴id',
`groups_time` int(11) DEFAULT NULL COMMENT '成团时间换算成秒存',
`is_type` int(11) DEFAULT NULL,
`is_new` int(11) DEFAULT NULL COMMENT '最新团购',
`is_hot` int(11) DEFAULT NULL COMMENT '热门团购',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
controller类中
用的json传值所以是String
@ApiOperation("添加商品") // @HeaderChecker(headerNames = { "token", "userId" }) @PostMapping(value = "/addShopInfo") public Response addShopInfo(@RequestBody String shopInfo) { return Response.success(systemAdminService.addShopInfo(shopInfo)); }
service 类
Object addShopInfo(String shopInfo);
impl类
@Override public Object addShopInfo(String shopInfo) { //解析 JSONObject jsonObject = (JSONObject) JSON.parse(shopInfo); System.out.println("displays:"+jsonObject); //商品轮播图 JSONArray imgs = jsonObject.getJSONArray("imgs"); System.out.println("imgs:"+imgs); //商品名称 String title = jsonObject.getString("title"); System.out.println("title:"+title); // 原价 String sellMoney = jsonObject.getString("sellMoney"); // 库存 String shopNum = jsonObject.getString("shopNum"); //商品图片 String shopImg = jsonObject.getString("shopImg"); //分类id String shopTypeId = jsonObject.getString("crumbsId"); //售价 String realMoney = jsonObject.getString("realMoney"); //销量 String sellNum = jsonObject.getString("sellNum"); //'是否推荐 1是 2否' String isShow = jsonObject.getString("isShow"); //'一级sku名字', String skuFirstName = jsonObject.getString("spc0"); System.out.println("sellMoney:"+sellMoney); //'二级sku名字', String skuTwoName = jsonObject.getString("spc1"); JSONArray privatelist = jsonObject.getJSONArray("privatelist"); System.out.println("privatelist:"+privatelist); String detials = jsonObject.getString("detials"); String ctime = DateUtil.timeStamp2Date(DateUtil.timeStamp(), "yyyy-MM-dd HH:mm:ss"); ShopInfo shopInfo1 =new ShopInfo(); String imgsesd=""; //图片以,号隔开 for (int i = 0; i < imgs.size(); i++) { String imgses = imgs.get(i).toString(); imgsesd = imgses +","+imgsesd; } shopInfo1.setImgs(imgsesd); shopInfo1.setShopName(title); shopInfo1.setTitle(title); Double fromString = new Double (sellMoney); shopInfo1.setSellMoney(fromString); Integer shopNums = null; if(shopNum!=null){ shopNums = Integer.valueOf(shopNum); } shopInfo1.setShopNum(shopNums); Integer shopTypeIds = null; if(shopTypeId!=null){ shopTypeIds = Integer.valueOf(shopTypeId); } shopInfo1.setShopTypeid(shopTypeIds); Double realMoneys = new Double (realMoney); shopInfo1.setRealMoney(realMoneys); Integer sellNums = null; if(sellNum!=null){ sellNums = Integer.valueOf(sellNum); } shopInfo1.setShopImg(shopImg); shopInfo1.setSellNum(sellNums); Integer isShowSe = null; if(isShow!=null){ isShowSe = Integer.valueOf(isShow); } shopInfo1.setIsShow(isShowSe); shopInfo1.setSkuFirstName(skuFirstName); shopInfo1.setSkuTwoName(skuTwoName); shopInfo1.setIsDelete(1); shopInfo1.setDetials(detials); shopInfo1.setCtime(ctime); shopInfoMapper.insert(shopInfo1); for (int i = 0; i < privatelist.size(); i++) { ShopSku shopSku =new ShopSku(); shopSku.setStatus(1); shopSku.setCtime(ctime); //传入的list解析 Object privatelist1 = privatelist.get(i); //Object 转map Map entity = (Map) privatelist1; String spaVal = entity.get("spaVal").toString(); List list= (List) entity.get("children"); //第一层图片 if(Strings.isBlank(entity.get("img").toString())){ return SLYPResult.build(500,"img","请检查第一层img"); } String img= entity.get("img").toString(); System.out.println("spaVal:"+list); shopSku.setShopid(shopInfo1.getId()); shopSku.setImg(img); shopSku.setName(spaVal); shopSkuMapper.insert(shopSku); //读取里面的值 for (int j = 0; j < list.size(); j++) { ShopSku shopSku1 =new ShopSku(); shopSku1.setStatus(1); shopSku1.setCtime(ctime); Object children = list.get(i); Map childrenS = (Map) children; String goodsMarketPrice = childrenS.get("goodsMarketPrice").toString(); String val1 = childrenS.get("val1").toString(); String weight = childrenS.get("goodsCubage").toString(); String goodsStock = childrenS.get("goodsStock").toString(); System.out.println("price:"+goodsMarketPrice); shopSku1.setPid(shopSku.getId()); Integer weights = null; if(weight!=null){ weights = Integer.valueOf(weight); } shopSku1.setWeight(weights); Integer goodsStocks = null; if(goodsStock!=null){ goodsStocks = Integer.valueOf(goodsStock); } shopSku1.setNum(goodsStocks); shopSku1.setShopid(shopInfo1.getId()); Double goodsMarketPrices = new Double (goodsMarketPrice); shopSku1.setMoney(goodsMarketPrices); shopSku1.setName(val1); shopSkuMapper.insert(shopSku1); } } return SLYPResult.build(200, "添加成功", true); }
通过解析,拿到传过来的数据,前端传值,取的是这个标准值json文章数据_candy_no_sweets的博客-CSDN博客【代码】json文章数据。https://blog.csdn.net/candy_no_sweets/article/details/126836600?spm=1001.2014.3001.5502
最后
以上就是完美树叶为你收集整理的sku库设计以及代码的全部内容,希望文章能够帮你解决sku库设计以及代码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复