8.1 商品录入+审核、上下架+nginx入门+springSecurity

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40406929/article/details/84930796

然后看下面的这个图,这些填写好的数据都保存到哪张表里面?
 


 
完成商品后台保存
1.1    分析保存时的默认值
涉及到3张表:
tb_goods:

`seller_id` varchar(20) DEFAULT NULL COMMENT '商家ID',  当前登录人
`audit_status` varchar(2) DEFAULT NULL COMMENT '状态',  //0:未审核 1:已审核  2:未通过
`is_marketable` varchar(1) DEFAULT NULL COMMENT '是否上架', //0:未上架  1:已上架 2:已下架
`is_delete` varchar(1) DEFAULT NULL COMMENT '是否删除', //0:未删除  1:已删除


tb_goods_desc
 

`goods_id` bigint(20) NOT NULL COMMENT 'SPU_ID',  //取自tb_goods的id


tb_item

 `title` varchar(100) NOT NULL COMMENT '商品标题',  //小米6X 电信4G 64G  ---》spu名称+spec中的value值
`sell_point` varchar(500) DEFAULT NULL COMMENT '商品卖点', //取自spu的副标题
         {"spec":{"网络":"移动4G","机身内存":"32G"},"price":"121121","num":9999,"status":"1","isDefault":"0"}
`image` varchar(2000) DEFAULT NULL COMMENT '商品图片',   //取自商品图片中的第一个图片
`categoryId` bigint(10) NOT NULL COMMENT '所属类目,叶子类目',  //第三级id
`create_time` datetime NOT NULL COMMENT '创建时间',
`update_time` datetime NOT NULL COMMENT '更新时间',
`goods_id` bigint(20) DEFAULT NULL,    //spuId
`seller_id` varchar(30) DEFAULT NULL,  // 商家id
`category` varchar(200) DEFAULT NULL, //分类的名称  根据分类id查对象  取名称
`brand` varchar(100) DEFAULT NULL,   //品牌的名称    根据品牌id查对象  取名称
`seller` varchar(200) DEFAULT NULL,  //商家的名称    根据商家id查对象  取名称


1.2    完成保存的代码
第一步:在controller层获取当前登录人
 
第二步:插入tb_goods表时返回id
 
第三步:完成方法

@Override
public void add(Goods goods) {
   TbGoods tbGoods = goods.getTbGoods();
   tbGoods.setAuditStatus("0");
   tbGoods.setIsMarketable("0");
   tbGoods.setIsDelete("0");
   goodsMapper.insert(tbGoods);

   TbGoodsDesc tbGoodsDesc = goods.getTbGoodsDesc();
   tbGoodsDesc.setGoodsId(tbGoods.getId());
   goodsDescMapper.insert(tbGoodsDesc);

   List<TbItem> itemList = goods.getItemList();
   for (TbItem tbItem : itemList) {
      String title = tbGoods.getGoodsName();
      String spec = tbItem.getSpec(); //{"网络":"移动4G","机身内存":"32G"}
      Map<String,String> specMap = JSON.parseObject(spec, Map.class);
      for(String key:specMap.keySet()){
         title+=" "+specMap.get(key);
      }
      tbItem.setTitle(title);
      tbItem.setSellPoint(tbGoods.getCaption());
      String itemImages = tbGoodsDesc.getItemImages(); //[{color:,url:}]
      List<Map> itemImageMapList = JSON.parseArray(itemImages, Map.class);
      if(itemImageMapList.size()>0){
         String url = (String) itemImageMapList.get(0).get("url");
         tbItem.setImage(url);
      }
      tbItem.setCategoryid(tbGoods.getCategory3Id());
      tbItem.setCreateTime(new Date());
      tbItem.setUpdateTime(new Date());
      tbItem.setGoodsId(tbGoods.getId());
      tbItem.setSellerId(tbGoods.getSellerId());
      tbItem.setCategory(itemCatMapper.selectByPrimaryKey(tbItem.getCategoryid()).getName());
      tbItem.setBrand(brandMapper.selectByPrimaryKey(tbGoods.getBrandId()).getName());
      tbItem.setSeller(sellerMapper.selectByPrimaryKey(tbItem.getSellerId()).getName());
      itemMapper.insert(tbItem);
   }
}

2    运营商审核商品

审核列表显示的数据是需要审核的商品数据
也就是传人一个参数 审核状态 audit_status=0

2.1    显示审核商品数据
第一步:从shop_web中拷贝GoodsController
第二步:在goods.html中添加ng-init
 
完成数据显示:
 
2.2    优化列表显示


把分类的id转成name

第一步:准备一个对象itemCat

第二步:查询所有的分类数据

第三步:把查询的所有分类的数据都存放到itemCat对象中

$scope.findAllItemCat=function () {
     itemCatService.findAll().success(function (response) {
         // [{"id":1,"name":"图书、音像/电子书刊","parentId":0,"typeId":35},
//     {"id":2,"name":"电子书刊","parentId":1,"typeId":35},
// {"id":558,"name":"手机","parentId":0,"typeId":35}]  ----->{1:"图书、音像/电子书刊",2:"电子书刊",558:"手机"}
         for (var i = 0; i < response.length; i++) {
             $scope.itemCat[response[i].id ]=response[i].name;
         }
         alert($scope.itemCat);
     })
 }


第四步:修改html显示分类名称

2.3    审核商品
第一步:按钮上添加方法

$scope.updateAuditStatus=function (auditStatus) {
   // update tb_goods set audit_status=? where id=?
     goodsService.updateAuditStatus($scope.selectIds,auditStatus).success(function (response) {
       if(response.success){
          $scope.reloadList();
          $scope.selectIds=[];
}else{
          alert(response.message);
}
     })
 }


第二步:完成后台的方法

Service代码:
    @Override
   public void updateAuditStatus(Long[] ids, String auditStatus) {
//    update tb_goods set audit_status=? where id=?
      for (Long id : ids) {
//       TbGoods tbGoods = goodsMapper.selectByPrimaryKey(id);
//       tbGoods.setAuditStatus(auditStatus);
//       goodsMapper.updateByPrimaryKey(tbGoods);
         Map paramMap = new HashMap();
         paramMap.put("id",id);
         paramMap.put("auditStatus",auditStatus);
         goodsMapper.updateAuditStatus(paramMap);
      }
   }
Mapper映射文件:
<update id="updateAuditStatus" parameterType="map">
  update tb_goods set audit_status=#{auditStatus} where id=#{id}
</update>

3    商家对商品上下架
1、    上下架状态的显示
 第一步:在js中准备一个数组


   
第二步:在HTML中从数组中取值
  


2、    显示的数据只能是本商家的
 在后台传参数 sellerId
 
注意:在service中构建条件时使用精确查询

4    商品删除(略)
 

猜你喜欢

转载自blog.csdn.net/qq_40406929/article/details/84930796
8.1