using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Api.Framework; using Api.Framework.Cps; using Api.Framework.Enums; using Api.Framework.Model; using Api.Framework.SDK; using Api.Framework.Tools; using CsharpHttpHelper; using KSRebate.Properties; using SqlSugar; namespace KSRebate { public static class KsSessionExt { const string ksinfo_temp_list_ksrebate = "ksinfo_temp_list_ksrebates"; /// /// 获取fl_fadzone_info表的数据集合缓存 /// /// /// 刷新 /// public static List FindKsInfoTempGroups(this SqlSugarClient session, bool refresh = false) { //var stopWatch = new Stopwatch(); //stopWatch.Start(); var ksinfo_temp_groups = ApiClient.Cache.Get>(ksinfo_temp_list_ksrebate);//根据KEY、获得缓存 //stopWatch.Stop(); //EventClient.OnEvent("", "AAAA = " + stopWatch.Elapsed.TotalSeconds.ToString() + " ----------- " + (ksinfo_temp_groups == null ? "null" : ksinfo_temp_groups.Count.ToString())); try { if (refresh || ksinfo_temp_groups == null) { ksinfo_temp_groups = new List(); var robots = session.FindRobots(true); foreach (var item in robots) { ksinfo_temp_groups.Add(new ksinfo_temp() { ID = item.id, chattype = item.type, nick = item.nick, name = item.name }); } foreach (var item in ksinfo_temp_groups) { //var adzones = session.Queryable().Where(f => f.robot_id == item.ID && f.custom_type == Resources.SoftwareType && f.alliance_id == (int)CpsType.快手联盟).ToList(); var adzones = session.Find("select * from fl_adzone_info where robot_id = @robot_id and custom_type = @custom_type and alliance_id = @alliance_id", new { robot_id = item.ID, custom_type = Resources.SoftwareType, alliance_id = (int)CpsType.快手联盟 }); foreach (var adzone in adzones) { if (adzone.extend == "chief")//主 { item.onoff = adzone.onoff; if (adzone.adzone_group != 0)//组 { var _adzone = session.FindAdzoneGroups(CpsType.快手联盟, true).Where(f => string.IsNullOrWhiteSpace(f.remark)).FirstOrDefault(f => f.id == adzone.adzone_group); if (_adzone != null) { item.is_chief_group = true; item.pid_chief = _adzone.adzones; item.pid_chief_name = _adzone.name; } } else//单 { item.is_chief_group = false; item.pid_chief_cps_name = adzone.adzone_pid_cps_name; item.pid_chief = adzone.adzone_pid; item.pid_chief_name = adzone.adzone_name; } } else//副 { item.onoff = adzone.onoff; if (adzone.adzone_group != 0)//组 { var _adzone = session.FindAdzoneGroups(CpsType.快手联盟, true).Where(f => string.IsNullOrWhiteSpace(f.remark)).FirstOrDefault(f => f.id == adzone.adzone_group); if (_adzone != null) { item.is_deputy_group = true; item.pid_deputy = _adzone.adzones; item.pid_deputy_name = _adzone.name; } } else//单 { item.is_deputy_group = false; item.pid_deputy_cps_name = adzone.adzone_pid_cps_name; item.pid_deputy = adzone.adzone_pid; item.pid_deputy_name = adzone.adzone_name; } } } } ApiClient.Cache.Set(ksinfo_temp_list_ksrebate, ksinfo_temp_groups, 60); } } catch (Exception ex) { EventClient.OnEvent(null, $"【快手返利】 => 获取推广位异常:{ex.Message} - {ex.StackTrace}"); } return ksinfo_temp_groups; } public static void Clear() { ApiClient.Cache.Remove(ksinfo_temp_list_ksrebate); } } public class Tools { /// /// 获取推广位 /// /// /// /// public static Tuiguangwei GetTuiguangwei(string robotName, fl_member_info member) { try { var ksinfoTemps = ApiClient.GetSession().FindKsInfoTempGroups(); var ksInfoTemp = ksinfoTemps.FirstOrDefault(f => f.name == robotName && f.onoff == false); #region var choose = (member.buy_point >= Class1.Config.Point && member.finish_order >= Class1.Config.OrderNum);//判断是主还是副 if (choose) { if (ksInfoTemp.is_chief_group) { string key_chief = "fl_ksrebate_key_chief_" + robotName; Tuiguangwei tgw = ApiClient.Cache.Get(key_chief); return tgw; } else return new Tuiguangwei() { Pid = ksInfoTemp.pid_chief, Name = ksInfoTemp.pid_chief_name, Member = new fl_cps_member() { username = ksInfoTemp.pid_chief_cps_name } }; } else { if (ksInfoTemp.is_deputy_group) { string key_deputy = "fl_ksrebate_key_deputy_" + robotName; var tgw = ApiClient.Cache.Get(key_deputy); return tgw; } else return new Tuiguangwei() { Pid = ksInfoTemp.pid_deputy, Name = ksInfoTemp.pid_deputy_name, Member = new fl_cps_member() { username = ksInfoTemp.pid_deputy_cps_name } }; } #endregion } catch (System.Exception ex) { EventClient.OnEvent(null, $"选择使用的推广位异常:{ex.Message} - {ex.StackTrace}"); } return null; } } /// /// 临时的表 (用于数据显示) /// public class ksinfo_temp { /// /// id /// public long ID { get; set; } /// /// 平台类型 /// public ChatType chattype { get; set; } /// /// 用户账号 /// public string name { get; set; } /// /// [昵称] /// public string nick { get; set; } /// /// 主推广位是否是组推广位 /// public bool is_chief_group { get; set; } /// /// 主推广位cps名称 /// private string _pid_chief_cps_name { get; set; } public string pid_chief_cps_name { get { return _pid_chief_cps_name; } set { _pid_chief_cps_name = string.IsNullOrEmpty(value) ? string.Empty : value; } } private string _pid_chief; /// /// 主推广位id /// public string pid_chief { get { return _pid_chief; } set { _pid_chief = string.IsNullOrEmpty(value) ? string.Empty : value; } } /// /// 主推广位昵称 /// private string _pid_chief_name; public string pid_chief_name { get { return _pid_chief_name; } set { _pid_chief_name = string.IsNullOrEmpty(value) ? string.Empty : value; } } /// /// 主推广位是否是组推广位 /// public bool is_deputy_group { get; set; } /// /// 副推广位cps名称 /// private string _pid_deputy_cps_name { get; set; } public string pid_deputy_cps_name { get { return _pid_deputy_cps_name; } set { _pid_deputy_cps_name = string.IsNullOrEmpty(value) ? string.Empty : value; } } /// /// 副推广位id /// private string _pid_deputy; public string pid_deputy { get { return _pid_deputy; } set { _pid_deputy = string.IsNullOrEmpty(value) ? string.Empty : value; } } /// /// 副推广位名称 /// private string _pid_deputy_name; public string pid_deputy_name { get { return _pid_deputy_name; } set { _pid_deputy_name = string.IsNullOrEmpty(value) ? string.Empty : value; } } //public string adzone_activity_name { get; set; } ///// ///// 推广位 ///// //public string adzone_activity_pid { get; set; } public string adzone_activity_pid_cps_name { get; set; } /// /// 是否禁用 /// public bool onoff { get; set; } } }