Exemplo n.º 1
0
        public object AddStoreWeight(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg      = string.Empty;
                string storeId     = dicParas.ContainsKey("storeId") ? (dicParas["storeId"] + "") : string.Empty;
                string userId      = dicParas.ContainsKey("userId") ? (dicParas["userId"] + "") : string.Empty;
                string weightValue = dicParas.ContainsKey("weightValue") ? (dicParas["weightValue"] + "") : string.Empty;

                #region 验证参数
                if (string.IsNullOrEmpty(storeId))
                {
                    errMsg = "门店ID不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(userId))
                {
                    errMsg = "门店老板ID不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(weightValue))
                {
                    errMsg = "门店权重值不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!Utils.isNumber(weightValue))
                {
                    errMsg = "门店权重值格式不正确";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }
                #endregion

                IBase_StoreWeightService base_StoreWeightService = BLLContainer.Resolve <IBase_StoreWeightService>();
                int bossId = Convert.ToInt32(userId);
                if (base_StoreWeightService.Any(a => a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase) && a.BossID == bossId))
                {
                    errMsg = "该门店老板权重已分配";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                int iWeightValue   = Convert.ToInt32(weightValue);
                int sumWeightValue = base_StoreWeightService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)).Sum(s => s.WeightValue) ?? 0;
                if ((sumWeightValue + iWeightValue) > 100)
                {
                    errMsg = "门店权重之和不得超过100";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                var base_StoreWeight = new Base_StoreWeight();
                base_StoreWeight.BossID      = bossId;
                base_StoreWeight.StoreID     = storeId;
                base_StoreWeight.WeightType  = (int)ChainStoreWeightType.Whole;
                base_StoreWeight.WeightValue = iWeightValue;
                if (!base_StoreWeightService.Add(base_StoreWeight))
                {
                    errMsg = "添加门店权重信息失败";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }