Ejemplo n.º 1
0
        public string SaveSku(string pRequest)
        {
            var rp = pRequest.DeserializeJSONTo <APIRequest <SaveSkuRP> >();
            var loggingSessionInfo = new SessionManager().CurrentUserLoginInfo;
            var rd = new SaveSkuRD();//返回值

            //处理促销分组
            //先把之前的删除掉
            var service = new PropService(loggingSessionInfo);         //保存到t_sku表
            //    var brandDetailBLL = new BrandDetailBLL(CurrentUserInfo);
            var skuPropServer = new SkuPropServer(loggingSessionInfo); //保存到T_Sku_Property
            var propInfo      = rp.Parameters.SkuProp;

            //验证重复性
            int DistinctchildrenCount = propInfo.Children.Select(m => m.Prop_Name).Distinct().Count();

            if (DistinctchildrenCount != propInfo.Children.Count)
            {
                throw new APIException("规格的值不能重复添加")
                      {
                          ErrorCode = 135
                      };
            }

            if (string.IsNullOrEmpty(propInfo.Prop_Name))
            {
                throw new APIException("缺少参数【Prop_Name】或参数值为空")
                      {
                          ErrorCode = 135
                      };
            }

            bool isNew = false;

            if (string.IsNullOrEmpty(propInfo.Prop_Id))
            {
                propInfo.Prop_Id = Guid.NewGuid().ToString();
                isNew            = true;
            }
            propInfo.Prop_Code          = propInfo.Prop_Name;
            propInfo.Prop_Eng_Name      = "";
            propInfo.Prop_Type          = "2";//属性类型 1=组,2=属性,3=属性明细';
            propInfo.Parent_Prop_id     = "-99";
            propInfo.Prop_Level         = 1;
            propInfo.Prop_Domain        = "SKU";
            propInfo.Prop_Input_Flag    = "select";
            propInfo.Prop_Max_Length    = 1000;
            propInfo.Prop_Default_Value = "";
            propInfo.Prop_Status        = 1;
            propInfo.Display_Index      = 0;
            if (isNew)
            {
                propInfo.Create_User_Id = loggingSessionInfo.UserID;
                propInfo.Create_Time    = DateTime.Now.ToString();
            }
            propInfo.Modify_User_Id = loggingSessionInfo.UserID;
            propInfo.Modify_Time    = DateTime.Now.ToString();
            string error = "";

            service.SaveProp(propInfo, ref error);
            if (!string.IsNullOrEmpty(error))
            {
                throw new APIException(error)
                      {
                          ErrorCode = 135
                      };
            }
            if (!isNew)//不是新的
            {
                string propIds = "";
                foreach (var itemInfo in propInfo.Children)//数组,更新数据
                {
                    if (!string.IsNullOrEmpty(itemInfo.Prop_Id))
                    {
                        if (propIds != "")
                        {
                            propIds += ",";
                        }
                        propIds += "'" + itemInfo.Prop_Id + "'";
                    }
                }
                //删除不在这个里面的
                service.DeletePropByIds(propIds, propInfo);
            }

            int i = 0;

            foreach (var itemInfo in propInfo.Children)//数组,更新数据
            {
                if (string.IsNullOrEmpty(itemInfo.Prop_Id))
                {
                    itemInfo.Prop_Id = Guid.NewGuid().ToString();
                }
                itemInfo.Prop_Code          = itemInfo.Prop_Name;
                itemInfo.Prop_Eng_Name      = "";
                itemInfo.Prop_Type          = "3";              //属性类型 1=组,2=属性,3=属性明细';
                itemInfo.Parent_Prop_id     = propInfo.Prop_Id; //父类id
                itemInfo.Prop_Level         = 2;
                itemInfo.Prop_Domain        = "SKU";
                itemInfo.Prop_Input_Flag    = "select";
                itemInfo.Prop_Max_Length    = 1000;
                itemInfo.Prop_Default_Value = "";
                itemInfo.Prop_Status        = 1;
                itemInfo.Display_Index      = ++i;
                service.SaveProp(itemInfo, ref error);
            }

            //如果是新建的情况
            //如果不存在属性关系(sku和属性之间的关系)
            if (!skuPropServer.CheckSkuProp(propInfo.Prop_Id))
            {
                SkuPropInfo skuPropInfo = new SkuPropInfo();
                skuPropInfo.sku_prop_id   = Utils.NewGuid();
                skuPropInfo.prop_id       = propInfo.Prop_Id;
                skuPropInfo.CustomerId    = loggingSessionInfo.ClientID;
                skuPropInfo.status        = propInfo.Prop_Status.ToString();
                skuPropInfo.display_index = propInfo.Display_Index;
                skuPropServer.AddSkuProp(skuPropInfo);
            }

            var rsp = new SuccessResponse <IAPIResponseData>(rd);

            return(rsp.ToJSON());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 保存属性
        /// </summary>
        public string SavePropData()
        {
            var      service        = new PropService(CurrentUserInfo);
            var      brandDetailBLL = new BrandDetailBLL(CurrentUserInfo);
            var      skuPropServer  = new SkuPropServer(this.CurrentUserInfo);
            PropInfo item           = new PropInfo();
            string   content        = string.Empty;
            var      responseData   = new ResponseData();

            string key     = string.Empty;
            string item_id = string.Empty;

            if (Request("item") != null && Request("item") != string.Empty)
            {
                key = Request("item").ToString().Trim();
            }
            if (Request("PropId") != null && Request("PropId") != string.Empty)
            {
                item_id = Request("PropId").ToString().Trim();
            }

            item = key.DeserializeJSONTo <PropInfo>();

            PropInfo parentObj = new PropInfo();

            parentObj.Prop_Level = 1;
            if (item.Parent_Prop_id != null && item.Parent_Prop_id.Trim().Length > 0)
            {
                parentObj = service.GetPropInfoById(item.Parent_Prop_id);
                if (parentObj != null)
                {
                    item.Prop_Level = parentObj.Prop_Level + 1;
                }
            }
            else
            {
                item.Parent_Prop_id = "-99";
                item.Prop_Status    = 1;
            }

            if (item.Prop_Domain == "SKU" && item.Prop_Level == 2)
            {
                if (service.CheckSkuLast(item.Parent_Prop_id))
                {
                    responseData.success = false;
                    responseData.msg     = "SKU组最多有5个子节点";
                    return(responseData.ToJSON());
                }
            }

            if (item.Prop_Name == null || item.Prop_Name.Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "名称不能为空";
                return(responseData.ToJSON());
            }
            if (item.Prop_Code == null || item.Prop_Code.Trim().Length == 0)
            {
                responseData.success = false;
                responseData.msg     = "代码不能为空";
                return(responseData.ToJSON());
            }


            #region 商品sku 属性时判断  Display_Index只能在1-5,且不能在
            if (item.Prop_Type == "2" && item.Prop_Domain == "SKU")
            {
                string skuMsg = string.Empty;
                if (item.Display_Index < 1 || item.Display_Index > 5)
                {
                    skuMsg = "序号必须在1~5范围内";
                }

                //是否存在sku

                if (skuPropServer.CheckSkuPropByDisplayindex(this.CurrentUserInfo.CurrentLoggingManager.Customer_Id, item.Display_Index))
                {
                    skuMsg = "序号被占用,请重新选择1~5的序号。";
                }
                if (!string.IsNullOrWhiteSpace(skuMsg))
                {
                    responseData.msg = skuMsg;
                    return(responseData.ToJSON());
                }
            }
            #endregion


            bool   status  = true;
            string message = "保存成功";
            //------------------------------------------------
            //if (item.Prop_Domain.Equals("SKU") && item.Prop_Level.Equals("3"))
            //{
            //    item.Prop_Domain = "ITEM";
            //}
            //-----------------------------------------------------------------
            item.Prop_Status = 1;
            if (item.Prop_Id.Trim().Length == 0)
            {
                item.Prop_Id = Utils.NewGuid();
                service.SaveProp(item, ref message);
            }
            else
            {
                service.SaveProp(item, ref message);
            }

            if (message != "属性代码已存在")
            {
                if (item.Prop_Type == "2" && item.Prop_Domain == "SKU")
                {
                    string skuMsg = string.Empty;
                    if (item.Display_Index < 1 && item.Display_Index > 5)
                    {
                        skuMsg = "序号必须在1~5范围内";
                    }

                    //是否存在sku

                    if (skuPropServer.CheckSkuPropByDisplayindex(this.CurrentUserInfo.CurrentLoggingManager.Customer_Id, item.Display_Index))
                    {
                        skuMsg = "序号被占用,请重新选择1~5的序号。";
                    }
                    if (!string.IsNullOrWhiteSpace(skuMsg))
                    {
                        responseData.msg = skuMsg;
                        return(responseData.ToJSON());
                    }

                    //如果不存在属性关系
                    if (!skuPropServer.CheckSkuProp(item.Prop_Id))
                    {
                        SkuPropInfo skuPropInfo = new SkuPropInfo();
                        skuPropInfo.sku_prop_id   = Utils.NewGuid();
                        skuPropInfo.prop_id       = item.Prop_Id;
                        skuPropInfo.CustomerId    = this.CurrentUserInfo.CurrentLoggingManager.Customer_Id;
                        skuPropInfo.status        = item.Prop_Status.ToString();
                        skuPropInfo.display_index = item.Display_Index;
                        skuPropServer.AddSkuProp(skuPropInfo);
                    }
                }
                else
                {
                    SkuPropInfo skuPropInfo = new SkuPropInfo();
                    skuPropInfo.prop_id = item.Prop_Id;
                    skuPropServer.DeleteSkuProp(skuPropInfo);
                }
            }
            else
            {
                status = false;
            }



            if (parentObj != null && (parentObj.Prop_Code == "品牌" || parentObj.Prop_Id == "F8823C2EBACF4965BA134D3B10BD0B9F"))
            {
                brandDetailBLL.SetBrandAndPropSyn(item.Prop_Id, item.Prop_Name, 2, 0, out message);
            }

            responseData.success = status;
            responseData.msg     = message;

            content = responseData.ToJSON();
            return(content);
        }