Пример #1
0
        public object GetStoreWeightList(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg  = string.Empty;
                string storeId = dicParas.ContainsKey("storeId") ? (dicParas["storeId"] + "") : string.Empty;

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

                IBase_UserInfoService    base_UserInfoService    = BLLContainer.Resolve <IBase_UserInfoService>(resolveNew: true);
                IBase_StoreWeightService base_StoreWeightService = BLLContainer.Resolve <IBase_StoreWeightService>(resolveNew: true);
                var result = from a in base_UserInfoService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase) && p.UserType == (int)UserType.StoreBoss)
                             join b in base_StoreWeightService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase)) on a.UserID equals b.BossID
                             select new
                {
                    RealName    = a.RealName,
                    LogName     = a.LogName,
                    WeightValue = b.WeightValue,
                    ID          = b.ID
                };

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn, result));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
Пример #2
0
        public object DelStoreWeight(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg = string.Empty;
                string id     = dicParas.ContainsKey("id") ? (dicParas["id"] + "") : string.Empty;

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

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        IBase_StoreWeightService base_StoreWeightService = BLLContainer.Resolve <IBase_StoreWeightService>();
                        int iId = Convert.ToInt32(id);
                        var base_StoreWeight = base_StoreWeightService.GetModels(p => p.ID == iId).FirstOrDefault();
                        if (!base_StoreWeightService.Delete(base_StoreWeight))
                        {
                            errMsg = "删除门店权重信息失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        var dbContext             = DbContextFactory.CreateByModelNamespace(typeof(Base_StoreWeight_Game).Namespace);
                        var base_StoreWeight_Game = dbContext.Set <Base_StoreWeight_Game>().Where(p => p.WeightID == iId).ToList();
                        foreach (var model in base_StoreWeight_Game)
                        {
                            dbContext.Entry(model).State = EntityState.Deleted;
                        }

                        if (dbContext.SaveChanges() < 0)
                        {
                            errMsg = "删除门店权重游戏机信息失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, ex.Message));
                    }
                }

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
Пример #3
0
        public object GetStoreWeightUserGameList(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;

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

                if (string.IsNullOrEmpty(userId))
                {
                    errMsg = "用户ID不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                int iUserId = Convert.ToInt32(userId);
                IBase_StoreWeightService      base_StoreWeightService      = BLLContainer.Resolve <IBase_StoreWeightService>(resolveNew: true);
                IBase_StoreWeight_GameService base_StoreWeight_GameService = BLLContainer.Resolve <IBase_StoreWeight_GameService>(resolveNew: true);
                IData_GameInfoService         data_GameInfoService         = BLLContainer.Resolve <IData_GameInfoService>(resolveNew: true);
                var result = from a in base_StoreWeightService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase) && p.BossID == iUserId)
                             join b in base_StoreWeight_GameService.GetModels() on a.ID equals b.WeightID
                             join c in data_GameInfoService.GetModels() on b.GameID equals c.ID
                             select new
                {
                    GameName = c.GameName,
                    GameID   = c.ID
                };

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn, result));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
Пример #4
0
        public object SaveStoreWeightUserGameInfo(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 weightType = dicParas.ContainsKey("weightType") ? (dicParas["weightType"] + "") : string.Empty;
                var    gameIDs    = dicParas.ContainsKey("gameIDs") ? ((object[])dicParas["gameIDs"]).Cast <int>() : null;

                #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(weightType))
                {
                    errMsg = "门店权重类别不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }
                #endregion

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        IBase_StoreWeightService base_StoreWeightService = BLLContainer.Resolve <IBase_StoreWeightService>();
                        int iWeightType = Convert.ToInt32(weightType);
                        int iUserId     = Convert.ToInt32(userId);

                        if (!base_StoreWeightService.Any(a => a.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase) && a.BossID == iUserId))
                        {
                            errMsg = "请先分配权重";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        var base_StoreWeight = base_StoreWeightService.GetModels(p => p.StoreID.Equals(storeId, StringComparison.OrdinalIgnoreCase) && p.BossID == iUserId).FirstOrDefault();
                        base_StoreWeight.WeightType = iWeightType;
                        if (!base_StoreWeightService.Update(base_StoreWeight))
                        {
                            errMsg = "保存权重用户游戏机信息失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        if (iWeightType == (int)ChainStoreWeightType.Game)
                        {
                            if (gameIDs == null)
                            {
                                errMsg = "选择的游戏机列表不能为空";
                                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                            }

                            //先删除后添加
                            int iId                   = base_StoreWeight.ID;
                            var dbContext             = DbContextFactory.CreateByModelNamespace(typeof(Base_StoreWeight_Game).Namespace);
                            var base_StoreWeight_Game = dbContext.Set <Base_StoreWeight_Game>().Where(p => p.WeightID == iId).ToList();
                            foreach (var model in base_StoreWeight_Game)
                            {
                                dbContext.Entry(model).State = EntityState.Deleted;
                            }

                            foreach (var gId in gameIDs)
                            {
                                var base_StoreWeight_GameModel = new Base_StoreWeight_Game();
                                base_StoreWeight_GameModel.WeightID = iId;
                                base_StoreWeight_GameModel.GameID   = gId;
                                dbContext.Entry(base_StoreWeight_GameModel).State = EntityState.Added;
                            }

                            if (dbContext.SaveChanges() < 0)
                            {
                                errMsg = "保存权重用户游戏机信息失败";
                                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                            }
                        }

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        errMsg = ex.Message;
                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                    }
                }

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
Пример #5
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));
            }
        }