Example #1
0
        public object AddFreeRule(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg        = string.Empty;
                var    gameIndexIds  = dicParas.ContainsKey("gameIndexIds") ? ((object[])dicParas["gameIndexIds"]).ToList().Select <object, int>(x => Convert.ToInt32(x)) : null;
                string memberLevelId = dicParas.ContainsKey("memberLevelId") ? (dicParas["memberLevelId"] + "") : string.Empty;
                string ruleType      = dicParas.ContainsKey("ruleType") ? (dicParas["ruleType"] + "") : string.Empty;
                string needCoin      = dicParas.ContainsKey("needCoin") ? (dicParas["needCoin"] + "") : string.Empty;
                string freeCoin      = dicParas.ContainsKey("freeCoin") ? (dicParas["freeCoin"] + "") : string.Empty;
                string exitCoin      = dicParas.ContainsKey("exitCoin") ? (dicParas["exitCoin"] + "") : string.Empty;
                string startTime     = dicParas.ContainsKey("startTime") ? (dicParas["startTime"] + "") : string.Empty;
                string endTime       = dicParas.ContainsKey("endTime") ? (dicParas["endTime"] + "") : string.Empty;
                string times         = dicParas.ContainsKey("times") ? (dicParas["times"] + "") : string.Empty;

                #region 参数验证

                if (gameIndexIds == null || gameIndexIds.Count() == 0)
                {
                    errMsg = "游戏机数组gameIndexIds不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(memberLevelId))
                {
                    errMsg = "会员级别memberLevelId不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(ruleType))
                {
                    errMsg = "规则类别ruleType不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(needCoin))
                {
                    errMsg = "扣币(局)数needCoin不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!Utils.isNumber(needCoin))
                {
                    errMsg = "扣币(局)数needCoin格式不正确";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                int iNeedCoin = Convert.ToInt32(needCoin);
                if (iNeedCoin < 0)
                {
                    errMsg = "扣币(局)数不能为负数";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(freeCoin))
                {
                    errMsg = "送币(局)数freeCoin不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!Utils.isNumber(freeCoin))
                {
                    errMsg = "送币(局)数freeCoin格式不正确";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                int iFreeCoin = Convert.ToInt32(freeCoin);
                if (iFreeCoin < 0)
                {
                    errMsg = "送币(局)数不能为负数";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                int iRuleType = Convert.ToInt32(ruleType);
                if (iRuleType == 1 && string.IsNullOrEmpty(exitCoin)) //博彩机
                {
                    errMsg = "最小退币数exitCoin不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                int iExitCoin = 0;
                if (!string.IsNullOrEmpty(exitCoin))
                {
                    if (!Utils.isNumber(exitCoin))
                    {
                        errMsg = "最小退币数exitCoin格式不正确";
                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                    }
                    else
                    {
                        if ((iExitCoin = Convert.ToInt32(exitCoin)) < 0)
                        {
                            errMsg = "最小退币数exitCoin不能为负数";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }
                    }
                }

                int iTimes = 0;
                if (!string.IsNullOrEmpty(times))
                {
                    if (!Utils.isNumber(times))
                    {
                        errMsg = "重复次数times格式不正确";
                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                    }
                    else
                    {
                        if ((iTimes = Convert.ToInt32(times)) < 0)
                        {
                            errMsg = "重复次数times不能为负数";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }
                    }
                }

                if (string.IsNullOrEmpty(startTime))
                {
                    errMsg = "生效时段startTime不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                DateTime st;
                try
                {
                    st = Convert.ToDateTime(startTime);
                }
                catch
                {
                    errMsg = "生效时段startTime格式不正确";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }


                if (string.IsNullOrEmpty(endTime))
                {
                    errMsg = "生效时段endTime不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                DateTime et;
                try
                {
                    et = Convert.ToDateTime(endTime);
                }
                catch
                {
                    errMsg = "生效时段endTime格式不正确";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (st.CompareTo(et) > 0)
                {
                    errMsg = "生效时段开始时间startTime须小于结束时间endTime";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (et.Subtract(st).Hours > 23)
                {
                    errMsg = "生效时段须在24小时之内";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                #endregion

                IData_GameFreeRule_ListService data_GameFreeRule_ListService = BLLContainer.Resolve <IData_GameFreeRule_ListService>();
                IData_GameFreeRuleService      data_GameFreeRuleService      = BLLContainer.Resolve <IData_GameFreeRuleService>();

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        for (int i = 0; i <= iTimes; i++)
                        {
                            var data_GameFreeRule = new Data_GameFreeRule();
                            data_GameFreeRule.MemberLevelID = Convert.ToInt32(memberLevelId);
                            data_GameFreeRule.RuleType      = iRuleType;
                            data_GameFreeRule.State         = 1;
                            data_GameFreeRule.NeedCoin      = iNeedCoin;
                            data_GameFreeRule.FreeCoin      = iFreeCoin;
                            data_GameFreeRule.ExitCoin      = iExitCoin;
                            data_GameFreeRule.StartTime     = st;
                            data_GameFreeRule.EndTime       = et;
                            data_GameFreeRuleService.AddModel(data_GameFreeRule);
                            if (!data_GameFreeRuleService.SaveChanges())
                            {
                                errMsg = "添加送局规则失败";
                                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                            }

                            foreach (int gameIndexId in gameIndexIds)
                            {
                                var data_GameFreeRule_List = new Data_GameFreeRule_List();
                                data_GameFreeRule_List.GameIndexID = gameIndexId;
                                data_GameFreeRule_List.RuleID      = data_GameFreeRule.ID;
                                data_GameFreeRule_ListService.AddModel(data_GameFreeRule_List);
                            }

                            st = st.AddDays(1);
                            et = et.AddDays(1);
                        }

                        if (!data_GameFreeRule_ListService.SaveChanges())
                        {
                            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 (DbEntityValidationException e)
            {
                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, e.EntityValidationErrors.ToErrors()));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
Example #2
0
        public object DelFreeRule(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg = string.Empty;
                string id     = dicParas.ContainsKey("id") ? (dicParas["id"] + "") : string.Empty;
                if (string.IsNullOrEmpty(id))
                {
                    errMsg = "送局规则ID不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                int iId = Convert.ToInt32(id);
                IData_GameFreeRuleService      data_GameFreeRuleService      = BLLContainer.Resolve <IData_GameFreeRuleService>();
                IData_GameFreeRule_ListService data_GameFreeRule_ListService = BLLContainer.Resolve <IData_GameFreeRule_ListService>();
                IFlw_Game_FreeService          flw_Game_FreeService          = BLLContainer.Resolve <IFlw_Game_FreeService>();
                if (flw_Game_FreeService.Any(a => a.RuleID == iId))
                {
                    errMsg = "该送局规则已使用不能删除";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!data_GameFreeRuleService.Any(a => a.ID == iId))
                {
                    errMsg = "该送局规则信息不存在";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        var data_GameFreeRule = data_GameFreeRuleService.GetModels(p => p.ID == iId).FirstOrDefault();
                        data_GameFreeRuleService.DeleteModel(data_GameFreeRule);

                        var data_GameFreeRule_List = data_GameFreeRule_ListService.GetModels(p => p.RuleID == iId);
                        foreach (var data_GameFreeRule_ListMode in data_GameFreeRule_List)
                        {
                            data_GameFreeRule_ListService.DeleteModel(data_GameFreeRule_ListMode);
                        }

                        if (!data_GameFreeRuleService.SaveChanges())
                        {
                            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));
            }
        }