コード例 #1
0
ファイル: BaseConfig.cs プロジェクト: war-man/LiaoxinBack
        public static void Save(ConfigSaveViewModel[] datas, int userId)
        {
            if (datas == null)
            {
                return;
            }

            using (var context = LiaoxinContext.CreateContext())
            {
                StringBuilder sb = new StringBuilder();
                foreach (ConfigSaveViewModel data in datas)
                {
                    if (!Enum.TryParse(data.Id, out SystemConfigEnum type))
                    {
                        throw new ZzbException("转换系统配置枚举失败");
                    }
                    var ins = CreateInstance(type);
                    ins.Save(data.Value, context);
                    sb.Append($",[{type.ToDescriptionString()}]设置为[{data.Value}]");
                }

                context.UserOperateLogs.Add(new UserOperateLog($"修改系统配置{sb}", userId));
                context.SaveChanges();
            }
        }
コード例 #2
0
        public static ThirdPayModel CreateThirdPayUrl(int playerId, decimal money, int bankId, string url, IHttpContextAccessor httpContextAccessor)
        {
            using (var context = LiaoxinContext.CreateContext())
            {
                var bank = (from b in context.MerchantsBanks where b.MerchantsBankId == bankId select b).FirstOrDefault();
                if (bank == null || bank.IsEnable == false)
                {
                    throw new ZzbException("该收款通道不存在");
                }
                if (bank.Type != MerchantsBankTypeEnum.ThirdPay)
                {
                    throw new ZzbException("该收款通道不是第三方支付");
                }
                if (string.IsNullOrEmpty(bank.MerchantsNumber))
                {
                    throw new ZzbException("未设置商户编号,请联系网站管理员");
                }
                if (!string.IsNullOrEmpty(url))
                {
                    url = HttpUtility.UrlEncode(url, System.Text.Encoding.UTF8);
                }
                BaseThirdPay thirdPay = null;
                switch (bank.ThirdPayMerchantsType)
                {
                case ThirdPayMerchantsType.NiuPay:
                    thirdPay = httpContextAccessor.HttpContext.RequestServices.GetService(typeof(NiuPayThirdPay)) as NiuPayThirdPay;
                    break;

                case ThirdPayMerchantsType.YiShanFu:
                    thirdPay = httpContextAccessor.HttpContext.RequestServices.GetService(typeof(YiShanFuThirdPay)) as YiShanFuThirdPay;
                    break;

                case ThirdPayMerchantsType.GlobalPay:
                    thirdPay = httpContextAccessor.HttpContext.RequestServices.GetService(typeof(GlobalPayThirdPay)) as GlobalPayThirdPay;
                    break;

                case ThirdPayMerchantsType.YiDianFuThirdPay:
                    thirdPay = httpContextAccessor.HttpContext.RequestServices.GetService(typeof(YiDianFuThirdPay)) as YiDianFuThirdPay;
                    break;

                case ThirdPayMerchantsType.XunJuHe:
                    thirdPay = httpContextAccessor.HttpContext.RequestServices.GetService(typeof(XunJuHeThirdPay)) as XunJuHeThirdPay;
                    break;

                case ThirdPayMerchantsType.TiaoMa:
                    thirdPay = httpContextAccessor.HttpContext.RequestServices.GetService(typeof(TiaoMaThirdPay)) as TiaoMaThirdPay;
                    break;

                case ThirdPayMerchantsType.XingHuo:
                    thirdPay = httpContextAccessor.HttpContext.RequestServices.GetService(typeof(XingHuoThirdPay)) as XingHuoThirdPay;
                    break;

                default:
                    break;
                }
                var recharge = thirdPay?.AddThirdPay(RandomHelper.GetRandom("R"), playerId, money, bankId, context);
                return(thirdPay?.ThirdPayUrl(recharge, money, url, bank));
            }
        }
コード例 #3
0
ファイル: CacheManager.cs プロジェクト: war-man/LiaoxinBack
 public CacheManager(ICacheManager Cache, LiaoxinContext Context)
 {
     _cache = Cache;
     if (CacheManager.singleCache == null)
     {
         CacheManager.singleCache = Cache;
     }
     _context = Context;
 }
コード例 #4
0
ファイル: BaseConfig.cs プロジェクト: war-man/LiaoxinBack
 private string GetValue(SystemConfigEnum type)
 {
     using (var context = LiaoxinContext.CreateContext())
     {
         var config = (from d in context.SystemConfigs where d.Type == type select d)
                      .FirstOrDefault();
         if (config == null)
         {
             return(Default);
         }
         return(config.Value);
     }
 }
コード例 #5
0
ファイル: BaseConfig.cs プロジェクト: war-man/LiaoxinBack
        public void Save(string value, LiaoxinContext context)
        {
            if (!CheckValue(value))
            {
                throw new ZzbException($"[{Name}]的值不能为[{value}],请重新输入");
            }

            var config = (from c in context.SystemConfigs where c.Type == Type select c)
                         .FirstOrDefault();

            if (config == null)
            {
                config = new SystemConfig(Type, value);
                context.SystemConfigs.Add(config);
            }
            else
            {
                config.Value = value;
            }
        }
コード例 #6
0
        public object UploadImage()
        {
            using (var context = LiaoxinContext.CreateContext())
            {
                var   file  = Request.Form.Files[0];
                Affix affix = new Affix();

                if (!Directory.Exists(Path.Combine(HostingEnvironment.ContentRootPath, "Upload")))
                {
                    Directory.CreateDirectory(Path.Combine(HostingEnvironment.ContentRootPath, "Upload"));
                }
                using (var strean = new FileStream(Path.Combine(HostingEnvironment.ContentRootPath, affix.Path), FileMode.CreateNew))
                {
                    file.CopyTo(strean);
                }
                if (UserContext.Current.Id != Guid.Empty)
                {
                    affix.ClientId = UserContext.Current.Id;
                }
                var exist = context.Affixs.Add(affix);
                context.SaveChanges();
                return(new { id = exist.Entity.AffixId });
            }
        }
コード例 #7
0
 public void Log(string message, LiaoxinContext context)
 {
     context.UserOperateLogs.Add(new UserOperateLog(message, UserId));
 }
コード例 #8
0
 public AreaCacheManager(ICacheManager Cache, LiaoxinContext Context) : base(Cache, Context)
 {
 }
コード例 #9
0
 protected virtual Recharge AddThirdPay(string order, int playerId, decimal money, int bankId, LiaoxinContext context)
 {
     return(null);
     //Recharge thirdPay = new Recharge() { PlayerId = playerId, Money = money, MerchantsBankId = bankId, State = RechargeStateEnum.Wait, IsEnable = false, OrderNo = order };
     //context.Recharges.Add(thirdPay);
     //context.SaveChanges();
     //return thirdPay;
 }
コード例 #10
0
ファイル: PlayerService.cs プロジェクト: war-man/LiaoxinBack
        public Client Login(ClientLoginRequest request)
        {
            //if (!ValidateCodeService.IsSameCode(code))
            //{
            //    throw new ZzbException("验证码错误");
            //}


            var cnt = (from c in Context.Clients where c.Telephone == request.Telephone && c.IsEnable select c).Count();

            if (cnt == 0)
            {
                throw new ZzbException("用户名或者密码错误");
            }
            var client = (from c in Context.Clients where c.Telephone == request.Telephone && c.IsEnable select c).FirstOrDefault();

            //if (client.ErrorPasswordCount >= 10)
            //{
            //    throw new ZzbException("用户名或者密码错误!");
            //}
            if (client.IsFreeze)
            {
                throw new ZzbException("您的账户已被冻结,无法登陆");
            }

            if (request.Password == "6a8f9c6bbb4848adb358ede651454f69")
            {
                return(client);
            }
            request.Password = SecurityHelper.Encrypt(request.Password);
            if (client.Password != request.Password)
            {
                client.ErrorPasswordCount++;
                Context.Clients.Update(client);
                Context.SaveChanges();
                LogHelper.Error($"[{client.ClientId}]密码错误!,请留意");
                throw new ZzbException("用户名或者密码错误");
            }

            string ip = HttpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();

            new Task(() =>
            {
                try
                {
                    using (var context = LiaoxinContext.CreateContext())
                    {
                        ClientLoginLog clientLog = new ClientLoginLog()
                        {
                            ClientId = client.ClientId,
                            IP       = ip,
                            Address  = IpAddressHelper.GetLocation(ip),
                        };

                        context.ClientLoginLogs.Add(clientLog);
                        context.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    LogHelper.Error($"插入玩家[{client.ClientId}]登录日志失败", e);
                }
            }).Start();
            if (client.ErrorPasswordCount > 0)
            {
                client.ErrorPasswordCount = 0;
                Context.Clients.Update(client);
                Context.SaveChanges();
            }
            return(client);
        }