Admin Request for personal use ajxa

/**
     * Save or modify product information
     * @returns
     */
    function saveOrUpdateBaseGoodInfo(){
        var json={};
        var goodName=$.trim($("#goodName").val());
        if(!goodName){
            Feng.info ( "trade name can not be empty!" );
             Return ;
        }
        json["name"]=goodName;
        var keyword=$.trim($("#keyword").val());
        if(!keyword){
            Feng.info ( "commodity keyword can not be empty!" );
             Return ;
        }
        json["label"]=keyword;
        var price=$.trim($("#price").val());
        if(!price){
            Feng.info ( "price can not be empty!" );
             Return ;
        }
        if(isNaN(price)){
            Feng.info ( "Please enter a numeric price!" );
             Return ;
        }
        json["price"]=price;
        var unit=$.trim($("#unit").val());
        if(!unit){
            Feng.info ( "Units can not be empty!" );
             Return ;
        }
        json["unit"]=unit;
        var volume=$.trim($("#volume").val());
        if(!volume){
            Feng.info ( "sales can not be empty!" );
             Return ;
        }
        if(isNaN(volume)){
            Feng.info ( "Please enter the digital sales type!" );
             Return ;
        }
        json["volume"]=volume;
        var jiFenBili=$.trim($("#jiFenBili").val());
        if(!jiFenBili){
            Feng.info ( "Points to redeem gift proportions can not be empty!" );
             Return ;
        }
        if(isNaN(jiFenBili)){
            Feng.info ( "Please enter the proportion of credits to purchase gift numeric!" );
             Return ;
        }
        json["receivableIntegrateRate"]=jiFenBili;
        var jiFenDkBili=$.trim($("#jiFenDkBili").val());
        if(!jiFenDkBili){
            Feng.info ( "credits to purchase a maximum deductible proportion can not be empty!" );
             Return ;
        }
        if(isNaN(jiFenDkBili)){
            Feng.info ( "credits to purchase a maximum deductible proportion enter numeric!" );
             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 ( "the consumer a sub-commission ratio can not be empty!" );
             Return ;
        }
        if(isNaN(consumerSalePercentage1)){
            Feng.info ( "the consumer a sub-commission proportion enter numeric!" );
             Return ;
        }
        if(consumerSalePercentage2==null||consumerSalePercentage2==""||consumerSalePercentage2==undefined){
            Feng.info ( "Consumer two sub-commission ratio can not be empty!" );
             Return ;
        }
        if(isNaN(consumerSalePercentage2)){
            Feng.info ( "Consumer two points enter numeric ratio Maid!" );
             Return ;
        }
        if(consumerSaleMoney1==null||consumerSaleMoney1==""||consumerSaleMoney1==undefined){
            Feng.info ( "the consumer a permanent split commission can not be empty!" );
             Return ;
        }
        if(isNaN(consumerSaleMoney1)){
            Feng.info ( "the consumer a permanent split commission enter numeric!" );
             Return ;
        }
        if(consumerSaleMoney2==null||consumerSaleMoney2==""||consumerSaleMoney2==undefined){
            Feng.info ( "Consumer commission two fixed points can not be empty!" );
             Return ;
        }
        if(isNaN(consumerSaleMoney2)){
            Feng.info ( "Consumer two fixed points Maid enter numeric!" );
             Return ;
        }
        //分销员
        if(salePercentage1==null||salePercentage1==""||salePercentage1==undefined){
            Feng.info ( "sub-distributor member of a commission ratio can not be empty!" );
             Return ;
        }
        if(isNaN(salePercentage1)){
            Feng.info ( "sub-distributor member of a commission proportional enter numeric!" );
             Return ;
        }
        if(salePercentage2==null||salePercentage2==""||salePercentage2==undefined){
            Feng.info ( "Distribution commission members two points ratio can not be empty!" );
             Return ;
        }
        if(isNaN(salePercentage2)){
            Feng.info ( "Distribution commission members two points proportional enter numeric!" );
             Return ;
        }
        if(saleMoney1==null||saleMoney1==""||saleMoney1==undefined){
            Feng.info ( "fixed distribution member of a sub-commission can not be empty!" );
             Return ;
        }
        if(isNaN(saleMoney1)){
            Feng.info ( "fixed distribution member of a sub-commission enter numeric!" );
             Return ;
        }
        if(saleMoney2==null||saleMoney2==""||saleMoney2==undefined){
            Feng.info ( "Distribution commission members two fixed points can not be empty!" );
             Return ;
        }
        if(isNaN(saleMoney2)){
            Feng.info ( "fixed points two distribution members Maid enter numeric!" );
             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 ( "Consumer fixed commission can not be empty!" );
             Return ;
        }
        if(isNaN(commonMoney)){
            Feng.info ( "Please enter the number of consumers on a fixed commission type!" );
             Return ;
        }
        if(parseFloat(saleMoney1)+parseFloat(saleMoney2)>parseFloat(price)){
            Feng.info ( "fixed points of distribution commission members is greater than the selling price, can not submit" );
             return ;
        }
        if(parseFloat(consumerSaleMoney1)+parseFloat(consumerSaleMoney2)
                +parseFloat(commonMoney)>parseFloat(price)){
            Feng.info ( "sub-commission and consumer fixed consumer fixed cashback amount is greater than the sale price, can not submit" );
             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 ( "There are not filled specifications, please check it again!" );
             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 ( "Commodity preview can not be empty!" );
             Return ;
        }
        json["preview"]=brandPic;
        var detailPic=$("#detailPic").attr("src");
        if(!detailPic){
            Feng.info ( "Product Details diagram can not be empty!" );
             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 ( "check Goods Services!" );
             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 ( "Please select NARROW label" );
                 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 ( "Operation Success!" );
                    window.location.href=Feng.ctxPath + '/goodBase'
                }else{
                    Feng.info(result.error);
                }
            }
        });
    }
/**
     * Submit product information
     * @param map
     * @return
     */
    @SuppressWarnings("unchecked")
    @BussinessLog (value = "new or modified product information", 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 ( "trade name already exists!" );
             return jsonResponse;
        }
        this.iGoodsBaseInfoService.insertGoodBaseInfo(goodsBaseInfoVO);
        jsonResponse.setSuccess(Boolean.TRUE);
        return jsonResponse;        
    }

 

Guess you like

Origin www.cnblogs.com/dianzan/p/11443091.html