Esempio n. 1
0
        /// <summary>
        /// 保存类库中的视图
        /// </summary>
        /// <param name="type"></param>
        private void SaveViewSetting(Type type)
        {
            PlatformSource?platform = ViewUtils.GetPlatform(type);

            if (platform == null)
            {
                return;
            }
            ViewSetting setting = new ViewSetting()
            {
                Name     = type.Name,
                Platform = platform.Value,
                Code     = type.FullName,
                Status   = ViewSetting.ViewStatus.Normal
            };

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (setting.Exists(db, t => t.Code))
                {
                    setting = setting.Info(db, t => t.Code);
                }
                else
                {
                    setting.AddIdentity(db);
                }
                db.AddCallback(() =>
                {
                    ViewCaching.Instance().SaveViewID(setting.Code, setting.ID);
                });
                db.Commit();
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     保存数据
        /// </summary>
        /// <param name="reqID">请求ID</param>
        /// <param name="tip">提示</param>
        /// <param name="actInsert">插入时的方法委托</param>
        /// <param name="actUpdate">更新时的方法委托</param>
        /// <param name="actSuccess">成功后的方法委托</param>
        public virtual void Save(int reqID, Action <string, string> tip = null, Action <TInfo, DbExecutor> actInsert       = null,
                                 Action <TInfo, DbExecutor> actUpdate   = null, Action <int, TInfo, DbExecutor> actSuccess = null)
        {
            var info = Clone <TInfo>();

            if (!info.Check(tip))
            {
                return;
            }

            using (DbExecutor db = typeof(TInfo))
            {
                if (reqID > 0)
                {
                    if (actUpdate != null)
                    {
                        actUpdate(info, db);
                    }
                    Update(reqID, db);
                }
                else
                {
                    if (actInsert != null)
                    {
                        actInsert(info, db);
                    }
                    Insert(out reqID, db);
                }
                if (actSuccess != null)
                {
                    actSuccess(reqID, info, db);
                }
                db.Commit();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 保存游戏的时间节点
        /// </summary>
        public void SaveMarkTime(string gameCode, long time, MarkType type, byte mark)
        {
            GameSetting game = GameAgent.Instance().GetGameSetting(gameCode);

            if (game == null)
            {
                return;
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <GameMark>(t => t.GameID == game.ID && t.Type == type && t.Mark == mark))
                {
                    db.Update <GameMark, long>(t => t.Time, time,
                                               t => t.GameID == game.ID && t.Type == type && t.Mark == mark);
                }
                else
                {
                    db.Insert(new GameMark()
                    {
                        GameID = game.ID,
                        Type   = type,
                        Mark   = mark,
                        Time   = time
                    });
                }
                db.Commit();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 添加管理员账号
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool AddAdminInfo(string username, string password)
        {
            if (!WebAgent.IsUserName(username))
            {
                return(this.FaildMessage("账户名错误,账户名长度再5~16位之间,字母与数字的组合"));
            }
            if (string.IsNullOrEmpty(password))
            {
                return(this.FaildMessage("请设置管理员密码"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <SystemAdmin>(t => t.UserName == username))
                {
                    return(this.FaildMessage("账户名已存在"));
                }

                new SystemAdmin()
                {
                    UserName = username,
                    Password = Encryption.SHA1WithMD5(password),
                    Status   = SystemAdmin.AdminStatus.Normal
                }.Add(db);

                db.Commit();
            }
            return(this.AccountInfo.Log(SystemAdminLog.LogType.Setting, $"添加管理员账号:{username}"));
        }
Esempio n. 5
0
        /// <summary>
        /// 加载游戏配置
        /// </summary>
        public bool LoadSiteGameSetting(int siteId)
        {
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                IEnumerable <GameSetting> list = ReadDB.ReadList <GameSetting>(t => t.Status != GameStatus.Close);

                foreach (GameSetting gameSetting in list)
                {
                    if (this.ReadDB.Exists <SiteGameSetting>(t => t.SiteID == siteId && t.GameID == gameSetting.ID))
                    {
                        continue;
                    }
                    SiteGameSetting siteGameSetting = new SiteGameSetting()
                    {
                        SiteID = siteId,
                        GameID = gameSetting.ID,
                        Status = SiteGameStatus.Open
                    };

                    siteGameSetting.Add(db);
                }

                db.Commit();
            }

            return(this.AccountInfo.Log(SystemAdminLog.LogType.Site, $"加载商户游戏配置成功{siteId}"));
        }
Esempio n. 6
0
        public void SaveMarkTime(OrderTaskModel task, long time, byte mark = 0)
        {
            int?gameId = GameAgent.Instance().GetGameSetting(task)?.ID;

            if (gameId == null)
            {
                return;
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <GameMark>(t => t.GameID == gameId.Value && t.Mark == mark && t.Type == task.Type))
                {
                    db.Update <GameMark, long>(t => t.Time, time, t => t.GameID == gameId.Value && t.Mark == mark && t.Type == task.Type);
                }
                else
                {
                    new GameMark()
                    {
                        GameID = gameId.Value,
                        Mark   = mark,
                        Type   = task.Type,
                        Time   = time
                    }.Add(db);
                }
                db.Commit();
            }
        }
Esempio n. 7
0
        /// <summary>
        /// 新建站点
        /// </summary>
        public bool AddSite(Site site)
        {
            if (site.ID <= 0 || this.ReadDB.Exists <Site>(t => t.ID == site.ID))
            {
                return(this.FaildMessage("编号已经存在"));
            }
            if (string.IsNullOrEmpty(site.Name))
            {
                return(this.FaildMessage("请输入商户名"));
            }
            if (this.ReadDB.Exists <Site>(t => t.Name == site.Name))
            {
                return(this.FaildMessage("商户名重复"));
            }
            if (site.Prefix.Length != 3)
            {
                return(this.FaildMessage("前缀错误,只能三位!"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                //自动产生密钥
                Guid secretKey = Guid.NewGuid();
                site.SecretKey = secretKey.ToString();

                site.Add(db);

                db.Commit();
            }

            this.AccountInfo.Log(LogType.Site, $"新建商户{site.ID}");

            return(true);
        }
Esempio n. 8
0
        /// <summary>
        ///     保存数据
        /// </summary>
        /// <param name="reqID">请求ID</param>
        /// <param name="tip">提示</param>
        /// <param name="actInsert">插入时的方法委托</param>
        /// <param name="actUpdate">更新时的方法委托</param>
        /// <param name="actSuccess">成功后的方法委托</param>
        public static void Save <TInfo>(this TInfo info, int reqID, Action <string, string> tip = null, Action <TInfo, DbExecutor> actInsert = null, Action <TInfo, DbExecutor> actUpdate = null, Action <int, TInfo, DbExecutor> actSuccess = null) where TInfo : ModelInfo, new()
        {
            if (!info.Check(tip))
            {
                return;
            }

            using (DbExecutor db = typeof(TInfo))
            {
                if (reqID > 0)
                {
                    if (actUpdate != null)
                    {
                        actUpdate(info, db);
                    }
                    info.Update(reqID, db);
                }
                else
                {
                    if (actInsert != null)
                    {
                        actInsert(info, db);
                    }
                    info.Insert(out reqID, db);
                }
                if (actSuccess != null)
                {
                    actSuccess(reqID, info, db);
                }
                db.Commit();
            }
        }
Esempio n. 9
0
        public bool SaveSetting(GameSetting setting)
        {
            if (this.ReadDB.Exists <GameSetting>(t => t.Code == setting.Code && t.ID != setting.ID))
            {
                return(this.FaildMessage("代码重复"));
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <GameSetting>(t => t.ID == setting.ID))
                {
                    db.Update(setting);
                }
                else
                {
                    db.InsertIdentity(setting);

                    //保存游戏时默认开启所有商户该游戏
                    IEnumerable <Site> list = ReadDB.ReadList <Site>();
                    foreach (Site site in list)
                    {
                        SiteGameSetting siteGameSetting = new SiteGameSetting()
                        {
                            SiteID = site.ID,
                            GameID = setting.ID,
                            Status = SiteGameSetting.SiteGameStatus.Open
                        };

                        siteGameSetting.Add(db);
                    }
                }

                db.Commit();
            }
            return(this.AccountInfo.Log(LogType.Setting, $"保存游戏设置:{setting.Name}"));
        }
Esempio n. 10
0
        /// <summary>
        /// 保存资料
        /// </summary>
        public bool SaveDetail(SiteDetail detail)
        {
            if (!string.IsNullOrEmpty(detail.Mobile) && !WebAgent.IsMobile(detail.Mobile))
            {
                return(this.FaildMessage("手机号码错误"));
            }
            if (!string.IsNullOrEmpty(detail.Email) && !WebAgent.IsEMail(detail.Email))
            {
                return(this.FaildMessage("邮箱错误"));
            }

            //存在就修改,否则就插入
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (detail.Exists(db))
                {
                    detail.Update(db, t => t.Mobile, t => t.Email);
                }
                else
                {
                    detail.Add(db);
                }

                db.Commit();
            }
            return(this.AccountInfo.Log(SystemAdminLog.LogType.Site, $"修改商户资料"));
        }
Esempio n. 11
0
        /// <summary>
        /// 保存系统参数配置
        /// </summary>
        /// <param name="type"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public bool SaveSetting(SystemSetting.SettingType type, string value)
        {
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                SystemSetting setting = new SystemSetting()
                {
                    Type  = type,
                    Value = value
                };
                if (setting.Exists(db))
                {
                    setting.Update(db);
                }
                else
                {
                    setting.Add(db);
                }

                db.AddCallback(() =>
                {
                    SystemCaching.Instance().SaveSetting(type, value);
                });

                db.Commit();
            }
            return(true);
        }
Esempio n. 12
0
 /// <summary>
 /// 修改状态
 /// </summary>
 /// <param name="setting"></param>
 /// <returns></returns>
 public bool UpdateStatus(GameSetting setting)
 {
     using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
     {
         setting.Update(db, t => t.Status, t => t.MaintainTime);
         db.Commit();
     }
     return(this.AccountInfo.Log(LogType.Setting, $"修改开启状态:{setting.Name}"));
 }
Esempio n. 13
0
        /// <summary>
        /// 添加域名
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domain">根域名</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomain(int siteId, string domain, string[] subName, CDNProviderType provider)
        {
            domain = WebAgent.GetTopDomain(domain);
            if (string.IsNullOrEmpty(domain))
            {
                return(this.FaildMessage("域名错误"));
            }
            if (this.ReadDB.Exists <SiteDomain>(t => t.Domain == domain))
            {
                return(this.FaildMessage("域名已被添加"));
            }
            foreach (string name in subName)
            {
                if (!Regex.IsMatch(name, @"^@$|^\*$|^\w+$"))
                {
                    return(this.FaildMessage($"子域名{name}不符合规范"));
                }
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadCommitted))
            {
                SiteDomain siteDomain = new SiteDomain()
                {
                    SiteID = siteId,
                    Domain = domain
                };
                siteDomain.AddIdentity(db);

                foreach (string name in subName.Distinct())
                {
                    // 添加域名记录
                    DomainRecord record = new DomainRecord()
                    {
                        CDNType  = provider,
                        CName    = this.CreateRecordCName(name, domain),
                        DomainID = siteDomain.ID,
                        Status   = DomainRecord.RecordStatus.Wait,
                        SubName  = name
                    };
                    record.AddIdentity(db);

                    // 添加CDN记录
                    DomainCDN cdn = new DomainCDN()
                    {
                        RecordID = record.ID,
                        Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                        CName    = string.Empty,
                        CDNType  = provider,
                        Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                    };
                    cdn.Add(db);
                }
                db.Commit();
            }

            return(true);
        }
Esempio n. 14
0
        /// <summary>
        /// 刪除模型(此方法還需要同步刪除模板中對於該模型的引用)
        /// </summary>
        /// <param name="modelId"></param>
        /// <returns></returns>
        internal bool DeleteModel(int modelId)
        {
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                db.Delete <ViewContent>(t => t.ModelID == modelId);
                db.Delete <ViewModel>(t => t.ID == modelId);

                db.Commit();
            }
            return(true);
        }
Esempio n. 15
0
 /// <summary>
 /// 保存模型内容进入路径
 /// </summary>
 /// <param name="content"></param>
 private void SaveModelContent(ViewContent content)
 {
     using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
     {
         if (content.Exists(db))
         {
             content.Update(db, t => t.Path, t => t.Translate);
         }
         else
         {
             content.Add(db);
         }
         db.Commit();
     }
 }
Esempio n. 16
0
 /// <summary>
 /// 添加/修改游戏供应商
 /// </summary>
 /// <param name="game"></param>
 /// <returns></returns>
 public bool SaveGameProvider(GameProvider game)
 {
     using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
     {
         if (game.Exists(db))
         {
             game.Update(db);
         }
         else
         {
             game.Add(db);
         }
         db.Commit();
     }
     return(this.AccountInfo.Log(LogType.Set, $"保存游戏供应商:{game.Type}"));
 }
Esempio n. 17
0
 /// <summary>
 /// 添加/修改CDN供应商
 /// </summary>
 /// <param name="cdn"></param>
 /// <returns></returns>
 public bool SaveCDNProvider(CDNProvider cdn)
 {
     using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
     {
         if (cdn.Exists(db))
         {
             cdn.Update(db);
         }
         else
         {
             cdn.Add(db);
         }
         db.Commit();
     }
     return(this.AccountInfo.Log(LogType.Set, $"保存CDN供应商:{cdn.Type}"));
 }
Esempio n. 18
0
        /// <summary>
        /// 添加SSL证书
        /// </summary>
        /// <param name="cert"></param>
        /// <returns></returns>
        public bool SaveCertInfo(SiteDomainCert cert)
        {
            if (cert.SiteID == 0)
            {
                return(this.FaildMessage("没有指定站点"));
            }
            if (string.IsNullOrEmpty(cert.PEM))
            {
                return(this.FaildMessage("未选择证书"));
            }
            if (string.IsNullOrEmpty(cert.KEY))
            {
                return(this.FaildMessage("未选择密钥"));
            }

            CertInfo info = HttpsHelper.GetFirstCertInfo(cert.PEM);

            if (!info.Success)
            {
                return(this.FaildMessage(info.Message));
            }
            cert.Name     = info.Message;
            cert.Domain   = string.Join(",", info.Domain);
            cert.Expire   = info.ExpireAt;
            cert.CreateAt = DateTime.Now;

            if (this.ReadDB.Exists <SiteDomainCert>(t => t.SiteID == cert.SiteID && t.ID != cert.ID && t.Name == cert.Name))
            {
                return(this.FaildMessage("已存在同名的证书"));
            }
            bool success = false;

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (cert.ID == 0)
                {
                    success = cert.Add(db);
                }
                else
                {
                    success = cert.Update(db) == 1;
                }
                db.Commit();
            }
            return(success && AccountInfo.Log(LogType.Site, string.Format("设定域名证书 {0}", cert.Name)));
        }
Esempio n. 19
0
        /// <summary>
        /// 新增或修改游戏设置信息
        /// </summary>
        /// <param name="setting"></param>
        /// <returns></returns>
        public bool SaveSetting(GameSetting setting)
        {
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (setting.Exists(db))
                {
                    setting.Update(db);
                }
                else
                {
                    setting.Add(db);
                }

                db.Commit();
            }
            return(this.AccountInfo.Log(LogType.Setting, $"保存游戏设置:{setting.Name}"));
        }
Esempio n. 20
0
        /// <summary>
        /// 添加域名记录
        /// </summary>
        /// <param name="siteId">商户ID</param>
        /// <param name="domainId">根域名ID</param>
        /// <param name="subName">子域名</param>
        /// <param name="provider">CDN供应商(如果是商户操作,供应商为系统默认值,不可被商户自主选择)</param>
        /// <returns></returns>
        protected bool AddDomainRecord(int siteId, int domainId, string subName, CDNProviderType provider)
        {
            if (string.IsNullOrEmpty(subName) || !Regex.IsMatch(subName, @"^@$|^\*$|^\w+$"))
            {
                return(this.FaildMessage($"子域名{subName}不符合规范"));
            }
            SiteDomain domain = this.GetDomainInfo(siteId, domainId);

            if (domain == null)
            {
                return(this.FaildMessage("域名ID错误"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (db.Exists <DomainRecord>(t => t.DomainID == domainId && t.SubName == subName))
                {
                    return(this.FaildMessage("子域名记录已经存在"));
                }

                DomainRecord record = new DomainRecord()
                {
                    CDNType  = provider,
                    CName    = this.CreateRecordCName(subName, domain.Domain),
                    DomainID = domainId,
                    Status   = DomainRecord.RecordStatus.Wait,
                    SubName  = subName
                };
                record.AddIdentity(db);

                // 添加CDN记录
                DomainCDN cdn = new DomainCDN()
                {
                    RecordID = record.ID,
                    Https    = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait,
                    CName    = string.Empty,
                    CDNType  = provider,
                    Status   = provider == CDNProviderType.Manual ? DomainCDN.CDNStatus.None : DomainCDN.CDNStatus.Wait
                };
                cdn.Add(db);

                db.Commit();
            }
            return(true);
        }
Esempio n. 21
0
        /// <summary>
        /// 删除商户模板
        /// </summary>
        /// <param name="templateId"></param>
        /// <returns></returns>
        public bool DeleteSiteTemplate(int templateId)
        {
            ViewSiteTemplate template = this.GetSiteTemplateInfo(templateId);

            if (template == null)
            {
                return(this.FaildMessage(""));
            }
            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                template.Configs.ForEach(config =>
                {
                    config.Delete(db);
                });
                template.Delete(db);
                db.Commit();
            }
            return(this.AccountInfo.Log(LogType.View, $"删除商户模板 {template.Platform}/{template.Name}"));
        }
Esempio n. 22
0
        /// <summary>
        /// 为商户游戏买分
        /// </summary>
        public bool SitePayMul(string IDs, decimal money)
        {
            string[] ids = IDs.Split("|");
            if (ids.Length == 0)
            {
                return(this.FaildMessage("请选择需要买分的游戏"));
            }

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                foreach (string id in ids)
                {
                    if (string.IsNullOrEmpty(id))
                    {
                        continue;
                    }

                    int             temp            = int.Parse(id);
                    SiteGameSetting sitegamesetting = this.ReadDB.ReadInfo <SiteGameSetting>(t => t.ID == temp);
                    sitegamesetting.Paid   += money;
                    sitegamesetting.Credit += money;

                    //添加买分日志
                    CreditLog creditLog = new CreditLog()
                    {
                        GameID       = sitegamesetting.GameID,
                        SiteID       = sitegamesetting.SiteID,
                        Type         = CreditLog.ChangeType.Add,
                        ChangeCredit = money,
                        Balance      = sitegamesetting.Paid,
                        OrderID      = sitegamesetting.ID.ToString(),
                        CreateAt     = DateTime.Now
                    };
                    sitegamesetting.Update(db, t => t.Paid, t => t.Credit);

                    creditLog.Add(db);
                }

                db.Commit();
            }
            return(this.AccountInfo.Log(SystemAdminLog.LogType.Site, $"买分成功"));
        }
Esempio n. 23
0
        /// <summary>
        /// 为商户游戏买分
        /// </summary>
        public bool SitePay(int Id, decimal money)
        {
            SiteGameSetting sitegamesetting = this.ReadDB.ReadInfo <SiteGameSetting>(t => t.ID == Id);

            if (sitegamesetting == null)
            {
                return(this.FaildMessage("买分错误"));
            }
            if (money == 0)
            {
                return(this.FaildMessage("金额不能为0"));
            }

            sitegamesetting.Paid   += money;
            sitegamesetting.Credit += money;

            //添加买分日志
            CreditLog creditLog = new CreditLog()
            {
                GameID       = sitegamesetting.GameID,
                SiteID       = sitegamesetting.SiteID,
                Type         = CreditLog.ChangeType.Add,
                ChangeCredit = money,
                Balance      = sitegamesetting.Paid,
                OrderID      = sitegamesetting.ID.ToString(),
                CreateAt     = DateTime.Now
            };

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                sitegamesetting.Update(db, t => t.Paid, t => t.Credit);

                creditLog.Add(db);

                db.Commit();
            }
            return(this.AccountInfo.Log(SystemAdminLog.LogType.Site, $"修改商户游戏配置成功{Id}"));
        }
Esempio n. 24
0
        /// <summary>
        /// 新建站点
        /// </summary>
        public bool AddSite(Site site)
        {
            if (site.ID <= 0 || this.ReadDB.Exists <Site>(t => t.ID == site.ID))
            {
                return(this.FaildMessage("编号已经存在"));
            }
            if (string.IsNullOrEmpty(site.Name))
            {
                return(this.FaildMessage("请输入商户名"));
            }
            if (this.ReadDB.Exists <Site>(t => t.Name == site.Name))
            {
                return(this.FaildMessage("商户名重复"));
            }

            site.Setting = new Site.SiteSetting()
            {
                Currencies = new[] { site.Currency },
                Languages  = new[] { site.Language }
            };

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                site.Add(db);

                // 复制PC模板到商户模板
                if (site.PCTemplate != 0)
                {
                    db.AddCallback(() =>
                    {
                        site.PCTemplate = ViewAgent.Instance().CopySystemTemplate(site.ID, site.PCTemplate);
                    });
                }

                // 复制H5模板到商户模板
                if (site.H5Template != 0)
                {
                    db.AddCallback(() =>
                    {
                        site.H5Template = ViewAgent.Instance().CopySystemTemplate(site.ID, site.H5Template);
                    });
                }

                // 复制APP模板到商户模板
                if (site.APPTemplate != 0)
                {
                    db.AddCallback(() =>
                    {
                        site.APPTemplate = ViewAgent.Instance().CopySystemTemplate(site.ID, site.APPTemplate);
                    });
                }

                new SiteDetail()
                {
                    SiteID   = site.ID,
                    AdminURL = this.CreateDefaultAdminUrl(db, site.Name)
                }.Add(db);

                this.CreateDefaultAdmin(db, site.ID);

                db.Commit();
            }

            site.Update(this.WriteDB, t => t.PCTemplate, t => t.H5Template, t => t.APPTemplate);

            this.AccountInfo.Log(LogType.Site, $"新建商户{site.ID}");

            return(true);
        }
Esempio n. 25
0
        /// <summary>
        /// 消费订单采集任务,同步保存报表
        /// </summary>
        public string Execute(out string msg)
        {
            OrderTaskModel task = GameOrderCaching.Instance().GetOrderTask();

            if (!task)
            {
                msg = "当前没有任务";
                return(task);
            }

            GameSetting setting = GameAgent.Instance().GetGameSetting(task);

            if (setting == null || setting.Status != GameStatus.Open)
            {
                msg = "接口维护中";
                return(task);
            }

            int count = 0;

            // 执行订单采集任务
            foreach (OrderModel model in setting.Setting.GetOrderLog(task))
            {
                if (string.IsNullOrEmpty(model.UserName))
                {
                    continue;
                }

                GameOrder order = new GameOrder(model)
                {
                    UserID       = UserAgent.Instance().GetGameUserID(setting.ID, model.UserName, out int siteId),
                    SiteID       = siteId,
                    GameID       = setting.ID,
                    SettlementAt = new DateTime(1900, 1, 1),
                };
                if (order.Status.IsFinish())
                {
                    order.SettlementAt = DateTime.Now;
                }

                long hashCode = GameOrderAgent.Instance().GetOrderHashCode(order.GameID, order.SourceID);
                // 未有更新
                if (hashCode == order.HashCode)
                {
                    continue;
                }

                using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
                {
                    // 是否需要重新结算
                    bool reSettlement = false;
                    // 是否需要结算
                    bool isSettlement = false;
                    if (hashCode == 0)
                    {
                        order.AddIdentity(db);
                        isSettlement = order.Status.IsFinish();
                    }
                    else
                    {
                        // 获取原来的状态和原来的结算日期,判断是否需要重新结算
                        GameOrder oldOrder = db.ReadInfo <GameOrder>(t => t.GameID == order.GameID && t.SourceID == order.SourceID,
                                                                     t => t.ID, t => t.SettlementAt, t => t.Status, t => t.BetMoney, t => t.BetAmount, t => t.Money);

                        // 是否需要重新结算
                        reSettlement = oldOrder.Status.IsFinish() && oldOrder.Money != order.Money;

                        // 如果需要重新结算则减去结算过的值
                        if (reSettlement)
                        {
                            db.ExecuteNonQuery(new rpt_SaveUserDate(order.UserID, oldOrder.SettlementAt.Date, order.GameID, order.SiteID, oldOrder.BetMoney * -1M,
                                                                    oldOrder.BetAmount * -1M, oldOrder.Money * -1M, -1));
                        }
                        // 不需要重新结算,且之前已经结算过,则保持原来的结算时间
                        else if (oldOrder.Status.IsFinish())
                        {
                            order.SettlementAt = oldOrder.SettlementAt;
                        }

                        db.Update(order, t => t.ID == oldOrder.ID,
                                  t => t.ResultAt, t => t.SettlementAt, t => t.BetAmount, t => t.Money, t => t.Status, t => t.Content, t => t.Status, t => t.UpdateTime, t => t.HashCode, t => t.RawData);

                        isSettlement = !oldOrder.Status.IsFinish() && order.Status.IsFinish();
                    }

                    // 新的结算
                    if (reSettlement || isSettlement)
                    {
                        db.ExecuteNonQuery(new rpt_SaveUserDate(order.UserID, order.SettlementAt.Date, order.GameID, order.SiteID, order.BetMoney,
                                                                order.BetAmount, order.Money, 1));
                    }

                    db.AddCallback(() =>
                    {
                        GameOrderCaching.Instance().SaveHashCode(order.GameID, order.SourceID, order.HashCode);
                    });

                    db.Commit();
                }

                count++;
            }

            msg = @$ "采集完成,共采集到条数:{count}";
            return(task);
        }
Esempio n. 26
0
        /// <summary>
        /// 添加会员
        /// 规则1:如果是后台添加的会员,不设置注册IP,注册设备
        /// </summary>
        /// <param name="user"></param>
        /// <param name="inviteCode">邀请码(可以是会员也可以是代理的邀请码)|手动创建账号不需要填邀请码,但是需要指定AgentID</param>
        /// <returns></returns>
        protected bool AddUser(Site site, User user, string inviteCode, Language language = Language.CHN)
        {
            if (!WebAgent.IsUserName(user.UserName, 2, 16))
            {
                return(this.FaildMessage("用户名格式错误", language));
            }
            int userId = this.GetUserID(user.SiteID, user.UserName);

            if (userId != 0)
            {
                return(this.FaildMessage("用户名已存在", language));
            }

            if (!string.IsNullOrEmpty(inviteCode))
            {
                UserInvite invite = this.GetInviteInfo(site.ID, inviteCode);
                if (invite == null)
                {
                    return(this.FaildMessage("邀请码错误", language));
                }
                User inviteUser = this.GetUserInfo(site.ID, invite.UserID);
                if (inviteUser.Type == User.UserType.Member)
                {
                    user.AgentID = inviteUser.AgentID;
                }
                else
                {
                    user.AgentID = invite.UserID;
                }
            }

            // 上级
            if (user.AgentID != 0)
            {
                User parent = this.GetUserInfo(site.ID, user.AgentID);
                if (parent == null)
                {
                    return(this.FaildMessage("上级错误", language));
                }
                switch (parent.Type)
                {
                case User.UserType.Partner:
                    user.Type = User.UserType.Agent;
                    break;

                case User.UserType.Agent:
                    user.Type = User.UserType.Broker;
                    break;

                case User.UserType.Broker:
                    user.Type = User.UserType.Member;
                    break;
                }
            }
            else
            {
                // 股东账号
                user.Type = User.UserType.Partner;
            }

            #region ========  默认值设定  ========

            user.SiteID   = site.ID;
            user.CreateAt = DateTime.Now;
            user.Currency = site.Currency;
            user.Language = site.Language;

            UserDetail detail = new UserDetail();

            #endregion

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                user.AddIdentity(db);

                detail.UserID = user.ID;
                detail.Add(db);

                db.ExecuteNonQuery(new usr_CreateDepth(user.SiteID, user.AgentID, user.ID));

                // 邀请码注册人数增加
                if (!string.IsNullOrEmpty(inviteCode))
                {
                    db.UpdatePlus(new UserInvite()
                    {
                        Member = 1
                    }, t => t.SiteID == site.ID && t.ID == inviteCode);
                }

                db.Commit();
            }

            return(true);
        }
Esempio n. 27
0
        /// <summary>
        /// 切换域名记录的CDN供应商
        /// </summary>
        /// <param name="recordId">域名记录</param>
        /// <param name="type">CDN供应商</param>
        /// <param name="cname">自定义的别名记录</param>
        /// <returns></returns>
        public bool UpdateCDNProvider(int recordId, CDNProviderType type, string cname)
        {
            DomainRecord record = this.GetRecordInfo(recordId);

            if (record == null)
            {
                return(this.FaildMessage("域名记录错误"));
            }
            if (type == CDNProviderType.Manual && string.IsNullOrEmpty(cname))
            {
                return(this.FaildMessage("请手动设置CDN别名"));
            }
            if (!IsCDNProvider(type))
            {
                return(this.FaildMessage("当前不支持该供应商"));
            }

            SiteDomain domain = this.ReadDB.ReadInfo <SiteDomain>(t => t.ID == record.DomainID);

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                bool isExists = db.Exists <DomainCDN>(t => t.RecordID == recordId && t.CDNType == type);
                switch (type)
                {
                case CDNProviderType.Manual:
                {
                    if (isExists)
                    {
                        db.Update(new DomainCDN()
                            {
                                Status = DomainCDN.CDNStatus.Finish,
                                CName  = cname
                            }, t => t.RecordID == recordId && t.CDNType == type, t => t.Status, t => t.CName);
                    }
                    else
                    {
                        new DomainCDN()
                        {
                            RecordID = recordId,
                            CName    = cname,
                            Status   = DomainCDN.CDNStatus.Finish,
                            CDNType  = type
                        }.Add(db);
                    }

                    record.Status = DomainRecord.RecordStatus.Finish;

                    db.AddCallback(() =>
                        {
                            // 调用DNS供应商的接口,设定记录的别名指向到此处手动设定的CDN别名地址
                        });
                }
                break;

                default:
                {
                    if (isExists)
                    {
                        db.Update(new DomainCDN()
                            {
                                Status = DomainCDN.CDNStatus.Wait
                            }, t => t.RecordID == recordId && t.CDNType == type, t => t.Status);
                    }
                    else
                    {
                        new DomainCDN()
                        {
                            RecordID = recordId,
                            Status   = DomainCDN.CDNStatus.Wait,
                            CDNType  = type
                        }.Add(db);
                    }
                    record.Status = DomainRecord.RecordStatus.Wait;
                }
                break;
                }

                record.CDNType = type;
                record.Update(db, t => t.Status, t => t.CDNType);

                db.Commit();
            }
            return(this.AccountInfo.Log(LogType.Site, $"设定域名{record.SubName}.{domain.Domain}的CDN供应商为:{type.GetDescription()}"));
        }
Esempio n. 28
0
        /// <summary>
        /// 保存商户模板
        /// </summary>
        /// <param name="template"></param>
        /// <param name="models"></param>
        /// <returns></returns>
        public bool SaveSiteTemplateInfo(ViewSiteTemplate template, int[] models)
        {
            if (string.IsNullOrEmpty(template.Name))
            {
                return(this.FaildMessage("请输入模板名称"));
            }
            if (!string.IsNullOrEmpty(template.Domain) && !isDomain(template.Domain))
            {
                return(this.FaildMessage("域名错误,请重新输入域名"));
            }

            bool isNew = template.ID == 0;

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (template.ID == 0)
                {
                    template.AddIdentity(db);
                }
                else
                {
                    template.Update(db, t => t.Name, t => t.Platform, t => t.Domain);
                }

                //# 得到当前平台下所有的视图
                List <ViewSetting> views     = db.ReadList <ViewSetting>(t => t.Platform == template.Platform);
                List <ViewModel>   modelList = new List <ViewModel>();
                foreach (int modelId in models)
                {
                    ViewModel model = db.ReadInfo <ViewModel>(t => t.ID == modelId);
                    if (model == null)
                    {
                        db.Rollback();
                        return(this.FaildMessage($"模型ID{modelId}不存在"));
                    }
                    ViewSiteConfig config = isNew ? null :
                                            config = db.ReadInfo <ViewSiteConfig>(t => t.TemplateID == template.ID && t.ViewID == model.ViewID && t.SiteID == template.SiteID);
                    if (config != null && config.ModelID != modelId)
                    {
                        config.ModelID = modelId;
                        config.Update(db, t => t.ModelID);
                    }
                    else if (config == null)
                    {
                        config = new ViewSiteConfig()
                        {
                            TemplateID = template.ID,
                            ViewID     = model.ViewID,
                            ModelID    = model.ID,
                            SiteID     = template.SiteID
                        };
                        config.Add(db);
                    }
                    modelList.Add(model);
                }

                ViewSetting view = views.FirstOrDefault(t => !modelList.Any(p => p.ViewID == t.ID));
                if (view != null)
                {
                    db.Rollback();
                    return(this.FaildMessage($"视图{view.Name}未选则模型"));
                }

                db.AddCallback(() =>
                {
                    SiteCaching.Instance().RemoveSiteInfo(template.SiteID);
                });

                db.Commit();
            }

            return(this.AccountInfo.Log(LogType.View, $"保存系统模板 {template.Platform}/{template.Name}"));
        }