/// <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(); } }
/// <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); }
/// <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); }
/// <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()}")); }
/// <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}")); }
/// <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); }