279 lines
11 KiB
C#
279 lines
11 KiB
C#
|
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";
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取fl_fadzone_info表的数据集合缓存
|
|||
|
/// </summary>
|
|||
|
/// <param name="session"></param>
|
|||
|
/// <param name="refresh">刷新</param>
|
|||
|
/// <returns></returns>
|
|||
|
public static List<ksinfo_temp> FindKsInfoTempGroups(this SqlSugarClient session, bool refresh = false)
|
|||
|
{
|
|||
|
//var stopWatch = new Stopwatch();
|
|||
|
//stopWatch.Start();
|
|||
|
var ksinfo_temp_groups = ApiClient.Cache.Get<List<ksinfo_temp>>(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<ksinfo_temp>();
|
|||
|
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<fl_adzone_info>().Where(f => f.robot_id == item.ID && f.custom_type == Resources.SoftwareType && f.alliance_id == (int)CpsType.快手联盟).ToList();
|
|||
|
var adzones = session.Find<fl_adzone_info>("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
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 获取推广位
|
|||
|
/// </summary>
|
|||
|
/// <param name="member"></param>
|
|||
|
/// <param name="ksInfoTemp"></param>
|
|||
|
/// <returns></returns>
|
|||
|
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<Tuiguangwei>(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<Tuiguangwei>(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;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 临时的表 (用于数据显示)
|
|||
|
/// </summary>
|
|||
|
public class ksinfo_temp
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// id
|
|||
|
/// </summary>
|
|||
|
public long ID { get; set; }
|
|||
|
/// <summary>
|
|||
|
/// 平台类型
|
|||
|
/// </summary>
|
|||
|
public ChatType chattype { get; set; }
|
|||
|
/// <summary>
|
|||
|
/// 用户账号
|
|||
|
/// </summary>
|
|||
|
public string name { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// [昵称]
|
|||
|
/// </summary>
|
|||
|
public string nick { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 主推广位是否是组推广位
|
|||
|
/// </summary>
|
|||
|
public bool is_chief_group { get; set; }
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 主推广位cps名称
|
|||
|
/// </summary>
|
|||
|
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;
|
|||
|
/// <summary>
|
|||
|
/// 主推广位id
|
|||
|
/// </summary>
|
|||
|
public string pid_chief
|
|||
|
{
|
|||
|
get { return _pid_chief; }
|
|||
|
set { _pid_chief = string.IsNullOrEmpty(value) ? string.Empty : value; }
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 主推广位昵称
|
|||
|
/// </summary>
|
|||
|
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; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 主推广位是否是组推广位
|
|||
|
/// </summary>
|
|||
|
public bool is_deputy_group { get; set; }
|
|||
|
/// <summary>
|
|||
|
/// 副推广位cps名称
|
|||
|
/// </summary>
|
|||
|
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; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 副推广位id
|
|||
|
/// </summary>
|
|||
|
private string _pid_deputy;
|
|||
|
|
|||
|
public string pid_deputy
|
|||
|
{
|
|||
|
get { return _pid_deputy; }
|
|||
|
set { _pid_deputy = string.IsNullOrEmpty(value) ? string.Empty : value; }
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 副推广位名称
|
|||
|
/// </summary>
|
|||
|
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; }
|
|||
|
|
|||
|
///// <summary>
|
|||
|
///// 推广位
|
|||
|
///// </summary>
|
|||
|
//public string adzone_activity_pid { get; set; }
|
|||
|
|
|||
|
|
|||
|
public string adzone_activity_pid_cps_name { get; set; }
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 是否禁用
|
|||
|
/// </summary>
|
|||
|
public bool onoff { get; set; }
|
|||
|
}
|
|||
|
|
|||
|
}
|