电商项目日总结(第六天)

运营商对商家审核

1.实现了对商家状态的验证,只有状态为"1"的商家才能登陆,"0"是未审核,"1"是已审核,"2"是已驳回,"3"是已停用

UserDetailsServiceImpl中:

if (seller != null&&seller.getStatus().equals("1"))

2.实现了展示所有未审核的商家

seller_1.html页面(运营商服务器):

首先展示所有商家,下午敲代码的时候在页面下方忘引入分页组件了,因为分页插件是页面数据显示的入口,所以不写页面就不显示数据,整了半天..

<!--在页面上加上分页组件-->
<tm-pagination conf="paginationConf"></tm-pagination>

显示完所有商家之后再筛选出所有未审核的商家,只需在body标签加一个ng-init="searchEntity={status:'0'}"即可,因为此页面展示数据是通过分页显示的,执行reloadList()方法,所以可以通过设置$scope.searchEntity来筛选数据(★★★)

<body class="hold-transition skin-red sidebar-mini"  ng-app="pinyougou" ng-controller="sellerController" ng-init="searchEntity={status:'0'}">

3.审核通过未审核的商家

<button ng-click="updateStatus(entity.sellerId,'1')" class="btn btn-success" data-dismiss="modal" aria-hidden="true">审核通过</button>
<button ng-click="updateStatus(entity.sellerId,'2')" class="btn btn-danger"  data-dismiss="modal" aria-hidden="true">审核未通过</button>
<button ng-click="updateStatus(entity.sellerId,'3')" class="btn btn-danger" data-dismiss="modal" aria-hidden="true">关闭商家</button>

sellerController.js

//updateStatus(别忘了传参数sellerId,status)
    $scope.updateStatus=function(sellerId,status){
        sellerService.updateStatus(sellerId,status).success(
            function(response){
                if(response.success){
                    $scope.reloadList();
                    alert(response.message)
                }else{
                    alert(response.message);
                }
            }
        );
    }

sellerService.js

//updateStatus
this.updateStatus=function(sellerId,status){
    return $http.get('../seller/updateStatus.do?sellerId='+sellerId+"&status="+status);
}

SellerController.java

@RequestMapping("/updateStatus")
	public Result updateStatus(String sellerId,String status){
		try {
			sellerService.updateStatus(sellerId,status);
			return new Result(true, "修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "修改失败");
		}
	}

SellerServiceImpl.java

@Override
public void updateStatus(String sellerId, String status) {
	TbSeller seller = sellerMapper.selectByPrimaryKey(sellerId);
	seller.setStatus(status);
	//别忘了去数据库中修改数据
	sellerMapper.updateByPrimaryKey(seller);
}

这样审核未通过的用户就可以登陆了

4.实现了密码加密的效果

pyg_shop_web模块中的spring-security.xml配置文件:

<!-- 认证管理器 -->
<authentication-manager>
	<authentication-provider user-service-ref="userDetailService">
                <!--密码加密-->
		<password-encoder ref="bcryptEncoder"></password-encoder>
	</authentication-provider>	
</authentication-manager>

这样当你登陆的时候,安全框架从你的数据库中查的时候就会把你数据中的密码当作加密之后的来解析,但是之前注册的时候的密码没有进行加密,之前注册的全登陆不上了,所以要在数据库添加用户的时候把密码进行加密,重新注册

SellerServiceImpl.java

@Override
public void add(TbSeller seller) {
	seller.setStatus("0");
	seller.setCreateTime(new Date());
	//密码加密
	BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
	seller.setPassword(encoder.encode(seller.getPassword()));
	sellerMapper.insert(seller);		
}

新增商品页面goods_edit.html(涉及到共八张表)

1.八张表,其中五张表用来引入页面所需要的数据,另外三张表用来存放数据)

一个商品的展示可以分为两种:SPU(在商品详情页面展示的)和SKU(用户购买时的参照),SPU与SKU之间是一对多的关系

例如手机:IPhoneX是SPU,而不同运营商,不同颜色,不同内存等条件的IPhoneX是SKU

用户购买时参照的是SKU,tb_item表也就是我们说的SKU表

2.实现了商品的添加

思路整理:

goods_edit.html页面

由此可见,添加一种商品涉及在数据库中要保存的表不止一张,而是三张,所以在entity目录下新建一个pojo对象Goods

public class Goods implements Serializable {
    private TbGoods tbGoods;
    private TbGoodsDesc tbGoodsDesc;
    private List<TbItem> tbItemList;
...
}

同时修改GoodsServiceImpl.java中的add方法

@Override
public void add(Goods goods) {
	//获取并添加商品中的TbGoods表
	TbGoods tbGoods = goods.getTbGoods();
	//设置商品状态为未审核
	tbGoods.setAuditStatus("0");
	goodsMapper.insert(tbGoods);
	//因为TbGoods和TbGoodsDesc这两张表是一对一的,主键相关
	Long id = tbGoods.getId();//为了能获取到id,别忘了去TbGoods的insert语句中添加selectKey去获取lastId
	TbGoodsDesc tbGoodsDesc = goods.getTbGoodsDesc();
	tbGoodsDesc.setGoodsId(id);
	goodsDescMapper.insert(tbGoodsDesc);
}

 GoodsController.java中

@RequestMapping("/add")
public Result add(@RequestBody Goods goods){
	try {
		    goodsService.add(goods);
			return new Result(true, "增加成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new Result(false, "增加失败");
		}
    }

goodsService.js中代码不变,GoodsController.js中:

    //保存
    $scope.add = function () {
        //增加获取富文本的内容并赋值
        $scope.entity.tbGoodsDesc.introduction=editor.html();
        //提交之后清空富文本编辑框
        editor.html();
        goodsService.add($scope.entity).success(
            function (response) {
                if (response.success) {
                    //如果成功,清空当前$scope.entity对象
                    $scope.entity = {};
                }
                alert(response.message);

            }
        );
    }

 goods_edit.html页面部分

<!--引入相关js文件-->
<script type="text/javascript" src="../plugins/angularjs/angular.min.js"></script>
<script type="text/javascript" src="../js/base.js" ></script>
<script type="text/javascript" src="../js/service/goodsService.js" ></script>
<script type="text/javascript" src="../js/service/itemCatService.js" ></script>
<script type="text/javascript" src="../js/service/typeTemplateService.js" ></script>
<script type="text/javascript" src="../js/controller/baseController.js" ></script>
<script type="text/javascript" src="../js/controller/goodsController.js" ></script>

<!--body标签-->
<body class="hold-transition skin-red sidebar-mini" ng-app="pinyougou" ng-controller="goodsController" ng-init="selectItemCat1List()">

<!--模型绑定之商品的三级目录和模板id-->
<td>
	<!--ng-options单选下拉列表 每一个选项的id as 每一个选项显示的名字 for 每一个选项 in 列表所有元素-->
	<select ng-model="entity.tbGoods.category1Id" ng-options=" itemCat.id as itemCat.name for itemCat in itemCat1List" class="form-control" >
	</select>
</td>
<td>
	<select ng-model="entity.tbGoods.category2Id" ng-options=" itemCat.id as itemCat.name for itemCat in itemCat2List" class="form-control select-sm" ></select>
</td>
<td>
	<select ng-model="entity.tbGoods.category3Id" ng-options=" itemCat.id as itemCat.name for itemCat in itemCat3List" class="form-control select-sm" ></select>
</td>
<td>
	模板ID:{{entity.tbGoods.typeTemplateId}}
</td>

<div class="col-md-2 title">商品名称</div>
<div class="col-md-10 data">
    <input ng-model="entity.tbGoods.goodsName" type="text" class="form-control"    placeholder="商品名称" value="">
</div>
<div class="col-md-2 title">品牌</div>
<div class="col-md-10 data">
    <!--注意这里不是brand.text而是brand.text因为去数据库里看都是{id:1;text:..}这种类型的,之前在Mapper查询时作过修改,为了在select2标签中展示-->
   <select ng-model="entity.tbGoods.brandId" ng-options=" brand.id as brand.text for brand in brandList" class="form-control" ></select>
</div>
<div class="col-md-2 title">副标题</div>
<div class="col-md-10 data">
    <input ng-model="entity.tbGoods.caption" type="text" class="form-control"   placeholder="副标题" value="">
</div>
<div class="col-md-2 title">价格</div>
<div class="col-md-10 data">
	   <div class="input-group">
   	   <span class="input-group-addon">¥</span>
            <input ng-model="entity.tbGoods.price" type="text" class="form-control"  placeholder="价格" value="">
	   </div>
</div>
<div class="col-md-2 title editer">商品介绍</div>
<div class="col-md-10 data editer">
    <textarea name="content" style="width:800px;height:400px;visibility:hidden;" ></textarea>
</div>
<div class="col-md-2 title rowHeight2x">包装列表</div>
<div class="col-md-10 data rowHeight2x"> 
	<textarea ng-model="entity.tbGoodsDesc.packageList" rows="4"  class="form-control"   placeholder="包装列表"></textarea>
</div>
<div class="col-md-2 title rowHeight2x">售后服务</div>
<div class="col-md-10 data rowHeight2x">
    <textarea ng-model="entity.tbGoodsDesc.saleService" rows="4"  class="form-control"    placeholder="售后服务"></textarea>
</div>        
<!--扩展属性-->
<div class="tab-pane" id="customAttribute">
    <div class="row data-type">                                
	<div ng-repeat="attr in entity.tbGoodsDesc.customAttributeItems">
	<div class="col-md-2 title">{{attr.text}}</div>
	<div class="col-md-10 data">
    <!--别忘了绑定ng-model-->
    <input ng-model="attr.value" class="form-control" placeholder="{{attr.text}}">
</div>
	                                

 保存按钮的点击事件绑定add()方法

<div class="btn-toolbar list-toolbar">
	<button ng-click="add()" class="btn btn-primary" ><i class="fa fa-save"></i>保存</button>
	<button class="btn btn-default" >返回列表</button>
</div>

展示上图三级分类

首先从manager_web层拷贝ItemCatController.java、itemCatService.js到shop_web层对应的目录下

//获取商品新增一级分类的数据
    $scope.selectItemCat1List = function () {
        itemCatService.selectItemCatByParentId(0).success(
            function (response) {
                $scope.itemCat1List = response;
            }
        )
    }
    //根据一级分类的变化去itemCateService中照对应的所有二级分类
    $scope.$watch('entity.tbGoods.category1Id', function (newValue, oldValue) {
        itemCatService.selectItemCatByParentId(newValue).success(
            function (response) {
                $scope.itemCat2List = response;
            }
        )
    })
    //根据二级分类的变化去itemCateService中照对应的所有三级分类
    $scope.$watch('entity.tbGoods.category2Id', function (newValue, oldValue) {
        itemCatService.selectItemCatByParentId(newValue).success(
            function (response) {
                $scope.itemCat3List = response;
            }
        )
    })
    //根据三级分类的变化去itemCateService中findOne方法照对应模板
    $scope.$watch('entity.tbGoods.category3Id', function (newValue, oldValue) {
        itemCatService.findOne(newValue).success(
            function (response) {
                $scope.entity.tbGoods.typeTemplateId = response.typeId;
            }
        )
    })

    //entity赋值后,才能对后面的属性赋值
    $scope.entity={tbGoodsDesc:{customAttributeItems:[]}}
    //根据模板id的变化去模板表里找对应的所有品牌(type_template表里所有的brandIds)
    $scope.$watch('entity.tbGoods.typeTemplateId',function (newValue,oldValue) {
        typeTemplateService.findOne(newValue).success(
            function (response) {
                $scope.brandList=JSON.parse(response.brandIds);
                //根据模板id的变化去模板表里找对应的所有扩展属性(type_template表里所有的customAttributeItems)
                $scope.entity.tbGoodsDesc.customAttributeItems=JSON.parse(response.customAttributeItems)
            }
        )
    })

在good_edit.html页面中在对应的位置调用controller层的这些方法,首先要引入itemCatService.js和typeTemplateService.js这两个文件

(上文中已经做出展示),以上步骤即可完成对tb_goods和tb_goods_desc两个表内容的添加,还差一个对tb_item表的添加

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值