自用ajxa 后台管理请求

/**
     * 保存或者修改商品信息
     * @returns
     */
    function saveOrUpdateBaseGoodInfo(){
        var json={};
        var goodName=$.trim($("#goodName").val());
        if(!goodName){
            Feng.info("商品名称不能为空!");
            return;
        }
        json["name"]=goodName;
        var keyword=$.trim($("#keyword").val());
        if(!keyword){
            Feng.info("商品关键词不能为空!");
            return;
        }
        json["label"]=keyword;
        var price=$.trim($("#price").val());
        if(!price){
            Feng.info("价格不能为空!");
            return;
        }
        if(isNaN(price)){
            Feng.info("价格请输入数字类型!");
            return;
        }
        json["price"]=price;
        var unit=$.trim($("#unit").val());
        if(!unit){
            Feng.info("单位不能为空!");
            return;
        }
        json["unit"]=unit;
        var volume=$.trim($("#volume").val());
        if(!volume){
            Feng.info("销量不能为空!");
            return;
        }
        if(isNaN(volume)){
            Feng.info("销量请输入数字类型!");
            return;
        }
        json["volume"]=volume;
        var jiFenBili=$.trim($("#jiFenBili").val());
        if(!jiFenBili){
            Feng.info("积分购买赠送比例不能为空!");
            return;
        }
        if(isNaN(jiFenBili)){
            Feng.info("积分购买赠送比例请输入数字类型!");
            return;
        }
        json["receivableIntegrateRate"]=jiFenBili;
        var jiFenDkBili=$.trim($("#jiFenDkBili").val());
        if(!jiFenDkBili){
            Feng.info("积分购买最大抵扣比例不能为空!");
            return;
        }
        if(isNaN(jiFenDkBili)){
            Feng.info("积分购买最大抵扣比例请输入数字类型!");
            return;
        }
        json["maxPayIntegrateRate"]=jiFenDkBili;
        var trs=$(".table-responsive table tbody tr");
        var consumerSalePercentage1=trs[0].cells[1].childNodes[0].value;
        var consumerSalePercentage2=trs[0].cells[2].childNodes[0].value;
        var consumerSaleMoney1=trs[0].cells[3].childNodes[0].value;
        var consumerSaleMoney2=trs[0].cells[4].childNodes[0].value;
        var salePercentage1=trs[1].cells[1].childNodes[0].value;
        var salePercentage2=trs[1].cells[2].childNodes[0].value;
        var saleMoney1=trs[1].cells[3].childNodes[0].value;
        var saleMoney2=trs[1].cells[4].childNodes[0].value;
        //消费者
        if(consumerSalePercentage1==null||consumerSalePercentage1==""||consumerSalePercentage1==undefined){
            Feng.info("消费者一级分佣比例不能为空!");
            return;
        }
        if(isNaN(consumerSalePercentage1)){
            Feng.info("消费者一级分佣比例请输入数字类型!");
            return;
        }
        if(consumerSalePercentage2==null||consumerSalePercentage2==""||consumerSalePercentage2==undefined){
            Feng.info("消费者二级分佣比例不能为空!");
            return;
        }
        if(isNaN(consumerSalePercentage2)){
            Feng.info("消费者二级分佣比例请输入数字类型!");
            return;
        }
        if(consumerSaleMoney1==null||consumerSaleMoney1==""||consumerSaleMoney1==undefined){
            Feng.info("消费者一级固定分佣不能为空!");
            return;
        }
        if(isNaN(consumerSaleMoney1)){
            Feng.info("消费者一级固定分佣请输入数字类型!");
            return;
        }
        if(consumerSaleMoney2==null||consumerSaleMoney2==""||consumerSaleMoney2==undefined){
            Feng.info("消费者二级固定分佣不能为空!");
            return;
        }
        if(isNaN(consumerSaleMoney2)){
            Feng.info("消费者二级固定分佣请输入数字类型!");
            return;
        }
        //分销员
        if(salePercentage1==null||salePercentage1==""||salePercentage1==undefined){
            Feng.info("分销员一级分佣比例不能为空!");
            return;
        }
        if(isNaN(salePercentage1)){
            Feng.info("分销员一级分佣比例请输入数字类型!");
            return;
        }
        if(salePercentage2==null||salePercentage2==""||salePercentage2==undefined){
            Feng.info("分销员二级分佣比例不能为空!");
            return;
        }
        if(isNaN(salePercentage2)){
            Feng.info("分销员二级分佣比例请输入数字类型!");
            return;
        }
        if(saleMoney1==null||saleMoney1==""||saleMoney1==undefined){
            Feng.info("分销员一级固定分佣不能为空!");
            return;
        }
        if(isNaN(saleMoney1)){
            Feng.info("分销员一级固定分佣请输入数字类型!");
            return;
        }
        if(saleMoney2==null||saleMoney2==""||saleMoney2==undefined){
            Feng.info("分销员二级固定分佣不能为空!");
            return;
        }
        if(isNaN(saleMoney2)){
            Feng.info("分销员二级固定分佣请输入数字类型!");
            return;
        }
        json["salePercentage1"]=salePercentage1;
        json["salePercentage2"]=salePercentage2;
        json["saleMoney1"]=saleMoney1;
        json["saleMoney2"]=saleMoney2;
        json["consumerSalePercentage1"]=consumerSalePercentage1;
        json["consumerSalePercentage2"]=consumerSalePercentage2;
        json["consumerSaleMoney1"]=consumerSaleMoney1;
        json["consumerSaleMoney2"]=consumerSaleMoney2;
        var commonMoney=$.trim($("#commonMoney").val());
        json["commonMoney"]=commonMoney;
        if(!commonMoney){
            Feng.info("消费者固定佣金不能为空!");
            return;
        }
        if(isNaN(commonMoney)){
            Feng.info("消费者固定佣金请输入数字类型!");
            return;
        }
        if(parseFloat(saleMoney1)+parseFloat(saleMoney2)>parseFloat(price)){
            Feng.info("分销员固定分佣之和大于销售价,无法提交");
            return;
        }
        if(parseFloat(consumerSaleMoney1)+parseFloat(consumerSaleMoney2)
                +parseFloat(commonMoney)>parseFloat(price)){
            Feng.info("消费者固定分佣与消费者固定返现金额大于销售价,无法提交");
            return;
        }
        var flag=true;
        var $inputDomList=$("#paramList input");
        for(var i=0;i<$inputDomList.length;i++){
            if(!$inputDomList[i].value){
                flag=false;
                break;
            }
            flag=true;
        }
        if(!flag){
            Feng.info("规格参数还有未填写的,请检查一遍!");
            return;
        }
        var parameterArr=new Array();
        $("#paramList div").each(function(){
            var parameterJson=new Object();
            if($(this).find("input").eq(0).val()&&$(this).find("input").eq(1).val()){
                parameterJson.name=$(this).find("input").eq(0).val();
                parameterJson.value=$(this).find("input").eq(1).val();
                parameterArr.push(parameterJson);
            }
        });
        json["parameter"]=JSON.stringify(parameterArr);
        var brandPic=$("#brandPic").attr("src");
        if(!brandPic){
            Feng.info("商品预览图不能为空!");
            return;
        }
        json["preview"]=brandPic;
        var detailPic=$("#detailPic").attr("src");
        if(!detailPic){
            Feng.info("商品详情图不能为空!");
            return;
        }
        json["imageSrc"]=detailPic;
        var serviceJsonArr=[];
        $("[name=arr2]:checked").each(function(){
            var serviceJson={};
            serviceJson.name=$(this).next().text();
            serviceJson.value=$(this).val();
            serviceJsonArr.push(serviceJson);
        });
        if(!serviceJsonArr.length){
            Feng.info("请勾选商品服务!");
            return;
        }
        json["serviceDetails"]=JSON.stringify(serviceJsonArr);
        var goodLabelJsonArr=[];
        $("#paramList1 div").each(function(){
            var selectJson={};
            $(this).find("select").each(function(){
                var name=$(this).find("option:selected").text();
                var value=$(this).find("option:selected").val();
                if(this.id=="firstLabelSelect"){
                    if(name!='请选择'&&name){
                        selectJson["firstName"]=name;
                        selectJson["firstValue"]=parseInt(value,10);
                    }
                }
                if(this.id=="secondLabelSelect"){
                    if(name!='请选择'&&name){
                        selectJson["secondName"]=name;
                        selectJson["secondValue"]=parseInt(value,10);
                    }
                    
                }
                if(this.id=="thirdLabelSelect"){
                    if(name!='请选择'&&name){
                        selectJson["thirdName"]=name;
                        selectJson["thirdValue"]=parseInt(value,10);
                    }
                    
                }
            });
            if(JSON.stringify(selectJson)!="{}"){
                goodLabelJsonArr.push(selectJson);
            }
            
        });
        var isUniversal=$("[name=isUniversal]:checked").val();
        if(isUniversal=="0"){
            if(!goodLabelJsonArr.length){
                Feng.info("请选择商品筛选标签");
                return;
            }
        }
        json["isUniversal"]=isUniversal;
        json["goodLabelJson"]=goodLabelJsonArr.length?JSON.stringify(goodLabelJsonArr):"";
        json["shoppingMethods"]=$("[name=shoppingMethods]:checked").val()==undefined?0:$("[name=shoppingMethods]:checked").val();    
        var ue = UE.getEditor('editor');
        json["intro"]=ue.getContent();
        var relGoodArr=new Array();
        $("#z-tre li").each(function(){
            if(relGoodArr.indexOf(this.id)==-1){
                relGoodArr.push(this.id);
            }
        });
        json["relGoodId"]=relGoodArr.toString();
        json["id"]=$("#goodId").val()?$("#goodId").val():null;
        $.ajax({
            url : Feng.ctxPath + '/goodBase/saveorupdatebasegoodinfo',
            type : 'POST',
            contentType : 'application/json;charset=UTF-8',
            dataType : 'json',
            cache : false,
            data : JSON.stringify(json),
            success : function(result) {
                if(result&&result.success){
                    Feng.info("操作成功!");
                    window.location.href=Feng.ctxPath + '/goodBase'
                }else{
                    Feng.info(result.error);
                }
            }
        });
    }
/**
     * 提交商品信息
     * @param map
     * @return
     */
    @SuppressWarnings("unchecked")
    @BussinessLog(value = "新增或修改商品信息", key = "saveorupdatebasegoodinfo")
    @RequestMapping("/saveorupdatebasegoodinfo")
    @ResponseBody
    public JSONResponse saveOrUpdateBaseGoodinfo(@RequestBody Map<String,Object>map,HttpServletRequest request) {
        JSONResponse jsonResponse=new JSONResponse();    
        HttpSession session=request.getSession(false);
        if(session==null) {
            throw new RuntimeException("session已经超时!");
        }
        Map<String,Object>firstMap=(Map<String, Object>) session.getAttribute("map");
        firstMap.putAll(map);
        GoodsBaseInfo goodsBaseInfo=new GoodsBaseInfo();
        MapUtils.mapToJavaBean(goodsBaseInfo,GoodsBaseInfo.class,firstMap);
        GoodsBaseInfoVO goodsBaseInfoVO=new GoodsBaseInfoVO();
        BeanUtils.copyProperties(goodsBaseInfo, goodsBaseInfoVO);
        goodsBaseInfoVO.setCreator(ShiroKit.getUser().getId());
        goodsBaseInfoVO.setModifier(ShiroKit.getUser().getId());
        goodsBaseInfoVO.setRelGoodId(map.get("relGoodId")+"");
        goodsBaseInfoVO.setCreated(new Date());
        goodsBaseInfoVO.setModified(new Date());
        goodsBaseInfoVO.setIsDeleted(CommonConst.NO);
        goodsBaseInfoVO.setIsEnable(CommonConst.YES);
        Integer goodId=goodsBaseInfoVO.getId();
        List<GoodsBaseInfo>goodsBaseInfoList=null;
        if(goodId==null) {
            goodsBaseInfoList=this.iGoodsBaseInfoService.selectList(new EntityWrapper<GoodsBaseInfo>()
                    .addFilter("name={0}", goodsBaseInfoVO.getName()));
        }else {
            goodsBaseInfoList=this.iGoodsBaseInfoService.selectList(new EntityWrapper<GoodsBaseInfo>()
                    .addFilter("name={0}", goodsBaseInfoVO.getName()).ne("id", goodId));
        }
        if(goodsBaseInfoList.size()>0) {
            jsonResponse.setSuccess(Boolean.FALSE);
            jsonResponse.setError("商品名称已经存在!");
            return jsonResponse;
        }
        this.iGoodsBaseInfoService.insertGoodBaseInfo(goodsBaseInfoVO);
        jsonResponse.setSuccess(Boolean.TRUE);
        return jsonResponse;        
    }

 

posted @ 2019-09-01 18:25  ThisCall  阅读(162)  评论(0编辑  收藏  举报