using Api.Framework.Enums;
using Api.Framework.Events;
using Api.Framework.Properties;
using Api.Framework.SDK;
using Api.Framework.Tools;
using Api.Framework.Tools;
using Api.Framework.Utils;
using CsharpHttpHelper;
using Newtonsoft.Json;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Api.Framework.Model
{
///
/// 扩展方法
///
public static class ModelExtend
{
private static readonly object lock_point = new object();
///
/// 改变积分
///
/// 数据库操作对象
/// 类型
/// 金额(单位:元)
/// 用户id
/// 备注
/// 自定义积分类型(为空即可)
public static fl_member_info ChangePoint(this SqlSugarClient session, PointType type, double money, long memberid, string message, string pointType_name = "")
{
//session.BeginTransaction();
try
{
lock (lock_point)
{
var member = session.FindMemberInfoById(memberid);
if (member == null) return null;
if (type < 0 && money > 0) money = -money;
if (string.IsNullOrEmpty(pointType_name)) pointType_name = Enum.GetName(type.GetType(), type);
var robot = session.FindRobotInfo(member.robot_name, member.robot_type);
var point_hist = new fl_point_hist() { message = message, point = money, type = pointType_name, rid = (robot == null ? 0 : robot.id), uid = member.id, before_point = member.cur_point };
if (type != PointType.人为修改)
{
if (money > 0)
{
switch (type)
{
case PointType.消费补贴:
{
member.buy_point = (double)decimal.Round((decimal)money + (decimal)member.buy_point, 2);
member.finish_order++;
}
break;
case PointType.提成奖励:
member.ext_point = (double)decimal.Round((decimal)member.ext_point + (decimal)money, 2);
break;
case PointType.其他奖励:
member.rew_point = (double)decimal.Round((decimal)member.rew_point + (decimal)money, 2);
break;
}
if (type != PointType.退回积分)
member.sum_point = (double)decimal.Round((decimal)member.sum_point + (decimal)money, 2);
}
else
{
if (type == PointType.维权扣除)
{
if (message.Contains("提成"))
{
member.ext_point = (double)decimal.Round((decimal)member.ext_point + (decimal)money, 2);
}
else
{
member.buy_point = (double)decimal.Round((decimal)member.buy_point + (decimal)money, 2);
member.finish_order -= 1;
}
}
}
}
member.cur_point = (double)decimal.Round((decimal)member.cur_point + (decimal)money, 2);
//#region 无视积分影响分组升级
//if (member.ignore_group_update == SwitchType.关闭)
//{
// //判断是否需要升级会员组
// var groups = session.FindGroups();
// var _oldGroup = session.FindGroup(member);
// var _newGroup = session.FindGroup(member.sum_point, member.bind_order);
// long group_id = member.group_id;
// if (_oldGroup != null && _newGroup != null && _oldGroup.id != _newGroup.id)
// {
// group_id = _newGroup.id;
// }
// member.group_id = group_id;
//}
//#endregion
session.SaveOrUpdate(member, true);
member = session.UpdateMemberGroup(member);
point_hist.after_point = member.cur_point;
point_hist = session.Insertable(point_hist).ExecuteReturnEntity();
//session.Commit();
EventClient.OnEvent(null, new MemberPointChangeEvent(point_hist));
return member;
}
}
catch (Exception ex)
{
//session.Rollback();
if (ex.Message.Contains("database disk image is malformed"))
throw new Exception("本地数据库已经损坏,请及时联系相关人员修复!");
throw ex;
}
return null;
}
public static void InsertRefundHistPoint(this SqlSugarClient session, string orderid, string orderid2, CpsType cpsType, string db_point, long uid = 0)
{
var rhPoint = FindRefundHistPoint(session, orderid, orderid2, cpsType);
if (rhPoint == null)
{
rhPoint = new fl_refund_hist_point() { cpstype = cpsType, orderid = orderid, orderid2 = orderid2, db_point = db_point, time = DateTime.Now, userid = uid };
session.Insertable(rhPoint).ExecuteCommand();
}
}
public static fl_refund_hist_point FindRefundHistPoint(this SqlSugarClient session, string orderid, string orderid2, CpsType cpsType)
{
try
{
return session.FindSingle("select * from fl_refund_hist_point where cpsType = @cpsType and orderid = @orderid and orderid2 = @orderid2", new { cpsType = (int)cpsType, orderid = orderid, orderid2 = orderid2 });
}
catch (Exception)
{ }
return null;
}
///
/// 微信支付密码集合
///
///
///
///
public static List FindWeixinpasswords(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_weixin_password_table";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.Find("select * from fl_weixin_password", new { });
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 查询微信密码信息
///
///
///
///
///
public static fl_weixin_password FindWeixinpassword(this SqlSugarClient session, long robot_id, bool refresh = false)
{
return session.FindWeixinpasswords(refresh).FirstOrDefault(f => f.robot_id == robot_id);
}
///
/// 查询淘宝自动绑定PID集合
///
///
/// true刷新
///
public static List FindAlimamaAutoBindPid(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_alimama_auto_bind_adzone_info";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.FindAdzoneInfos().Where(f => f.custom_type == Resources.TbSoftwareType && f.alliance_id == (int)CpsType.阿里妈妈).ToList();
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 尾号绑定.非订单查询绑定(朋友圈等其他推广)
///
///
///
///
public static List FindAlimamaTailBindPid(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_alimama_tail_bind_adzone_info";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.FindAdzoneInfos().Where(f => (f.custom_type == "群发优惠券" || f.custom_type == "朋友圈代运营" || f.custom_type == "精准朋友圈" || f.custom_type == "朋友圈工具" || f.custom_type == "淘宝发单") && f.alliance_id == (int)CpsType.阿里妈妈).ToList();
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 阿里私人推广位
///
///
/// 私人pid
///
public static List FindAlimamaPrivatePid(this SqlSugarClient session, string adzone_id)
{
var list = session.FindAdzoneInfos().Where(f => f.adzone_pid.EndsWith("_" + adzone_id) && f.alliance_id == (int)CpsType.阿里妈妈 && f.custom_type == "用户私人pid" && f.extend == "淘宝私人pid").ToList();
return list;
}
///
/// 抖音私人推广位
///
///
/// 私人pid
///
public static List FindDouyinPrivatePid(this SqlSugarClient session, string adzone_id)
{
var list = session.FindAdzoneInfos().Where(f => f.adzone_pid == adzone_id && f.alliance_id == (int)CpsType.抖音联盟 && f.custom_type == "用户私人pid" && f.extend == "抖音私人pid").ToList();
return list;
}
///
/// 京东私人推广位
///
///
/// 私人pid
///
public static List FindJingdongPrivatePid(this SqlSugarClient session, string adzone_id)
{
var list = session.FindAdzoneInfos().Where(f => f.adzone_pid.EndsWith("_" + adzone_id) && f.alliance_id == (int)CpsType.京东联盟 && f.custom_type == "用户私人pid" && f.extend == "京东私人pid").ToList();
return list;
}
///
/// 苏宁私人推广位
///
///
/// 私人pid
///
public static List FindSuningPrivatePid(this SqlSugarClient session, string adzone_id)
{
var list = session.FindAdzoneInfos().Where(f => f.adzone_pid == adzone_id && f.alliance_id == (int)CpsType.苏宁易购 && f.custom_type == "用户私人pid" && f.extend == "苏宁私人pid").ToList();
return list;
}
///
/// 拼多多推广位自动绑定推广位
///
///
/// 刷新
///
public static List FindSuningAutoBindPid(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_suning_auto_bind_adzone_info";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.苏宁易购 && f.custom_type == Resources.SNSoftwareType).Select(f => f.adzone_pid).ToList();
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 拼多多私人推广位
///
///
/// 私人pid
///
public static List FindPinduoduoPrivatePid(this SqlSugarClient session, string adzone_id)
{
var list = session.FindAdzoneInfos().Where(f => f.adzone_pid == adzone_id && f.alliance_id == (int)CpsType.多多进宝 && f.custom_type == "用户私人pid" && f.extend == "拼多多私人pid").ToList();
return list;
}
public static List FindKuaishouPrivatePid(this SqlSugarClient session, string adzone_id)
{
var list = session.FindAdzoneInfos().Where(f => f.adzone_pid == adzone_id && f.alliance_id == (int)CpsType.快手联盟 && f.custom_type == "用户私人pid" && f.extend == "快手私人pid").ToList();
return list;
}
///
/// 拼多多推广位自动绑定推广位
///
///
/// 刷新
///
public static List FindPinduoduoAutoBindPid(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_pinduoduo_auto_bind_adzone_info";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.多多进宝 && f.custom_type == Resources.PddSoftwareType).Select(f => f.adzone_pid).ToList();
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 快手推广位自动绑定推广位
///
///
/// 刷新
///
public static List FindKuaishouAutoBindPid(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_kuaishou_auto_bind_adzone_info";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.快手联盟 && f.custom_type == Resources.KsSoftwareType).Select(f => f.adzone_pid).ToList();
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 抖音推广位自动绑定推广位
///
///
/// 刷新
///
public static List FindDouyinAutoBindPid(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_douyin_auto_bind_adzone_info";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.抖音联盟 && f.custom_type == Resources.DySoftwareType).Select(f => f.adzone_pid).ToList();
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 抖音推广位自动绑定推广位
///
///
/// 刷新
///
public static List FindDoukeAutoBindPid(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_douke_auto_bind_adzone_info";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.抖客联盟 && f.custom_type == Resources.DkSoftwareType).Select(f => f.adzone_pid).ToList();
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 唯品会推广位自动绑定推广位
///
///
/// 刷新
///
public static List FindWeipinhuiAutoBindPid(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_weipinhui_auto_bind_adzone_info";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.唯品联盟 && f.custom_type == Resources.WphSoftwareType).Select(f => f.adzone_pid).ToList();
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 唯品会私人推广位
///
///
/// 私人pid
///
public static List FindWeipinhuiPrivatePid(this SqlSugarClient session, string adzone_id)
{
var list = session.FindAdzoneInfos().Where(f => f.adzone_pid == adzone_id && f.alliance_id == (int)CpsType.唯品联盟 && f.custom_type == "用户私人pid" && f.extend == "唯品会私人pid").ToList();
return list;
}
///
/// 获取通知Robots
///
///
/// 刷新
///
public static List FindNoticeapiRobots(this SqlSugarClient session, bool refresh = false)
{
string key = "FindNoticeapiRobots";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.Queryable().ToList();
ApiClient.Cache.Set(key, list, 60 * 24);
}
return list;
}
///
/// 京东推广位自动绑定推广位
///
///
/// 刷新
///
public static List FindJingdongAutoBindPid(this SqlSugarClient session, bool refresh = false)
{
string key = "fl_jingdong_auto_bind_adzone_info";
var list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.FindAdzoneInfos().Where(f => f.alliance_id == (int)CpsType.京东联盟 && f.custom_type == Resources.JdSoftwareType).Select(f => f.adzone_pid).ToList();
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
private readonly static object loc_obj = new object();
///
/// 获得会员数据
///
///
/// 通用IM消息
///
public static fl_member_info FindMemberinfo(this SqlSugarClient session, ReciveIMEvent e)
{
var m = session.FindSingle("select * from fl_member_info where robot_type = @robot_type and username = @username", new { username = e.Username, robot_type = e.ChatType });
if (m == null)
{
m = new fl_member_info()
{
crt_time = DateTime.Now,
usernick = e.NickName,
realnick = e.RealNick,
robot_name = e.RobotName,
robot_type = e.ChatType,
username = e.Username,
upd_time = DateTime.Now,
alipay_name = string.Empty,
alipay_num = string.Empty,
remark = string.Empty
};
var groups = session.FindGroups();
if (groups.Count == 0) throw new Exception("会员组未设置,请先设置会员组!");
if (!string.IsNullOrEmpty(e.RealNick)) m.realnick = e.RealNick;
if (!string.IsNullOrEmpty(e.Wechatid)) m.wechatid = e.Wechatid;
m.group_id = groups[0].id;
m = session.Insertable(m).ExecuteReturnEntity();
try
{
var result = UserRobotUpLoad.CustomerLink_UpLoadLink(new List()
{
new UserRobotUpLoad.CustomerLinkInput()
{
CreateTime = m.crt_time,
HeadUrl = m.headurl,
NickName = m.usernick,
Remark = m.remark,
RobotName = m.robot_name,
RobotType = UserRobotUpLoad.ConvertRobotType(m.robot_type),
UserName = m.username
}
});
}
catch (Exception ex)
{ }
}
else
{
m.upd_time = DateTime.Now;
m.robot_name = e.RobotName;
if (string.IsNullOrWhiteSpace(m.usernick)) m.usernick = e.NickName;
if (!string.IsNullOrEmpty(e.RealNick)) m.realnick = e.RealNick;
if (!string.IsNullOrEmpty(e.Wechatid)) m.wechatid = e.Wechatid;
}
return m;
//try
//{
// lock (loc_obj)
// {
// Console.WriteLine(e.ChatType);
// }
//}
//catch (Exception ex)
//{ }
//return null;
}
///
/// 通过用户账号查询用户对象
///
///
/// 用户账号
///
public static fl_member_info FindMemberInfoByUsername(this SqlSugarClient session, string username)
{
try
{
return session.FindSingle("select * from fl_member_info where username = @username", new { username = username });
}
catch (Exception ex)
{ }
return null;
}
///
/// 通过用户id查询用户对象
///
///
/// 用户id
///
public static fl_member_info FindMemberInfoById(this SqlSugarClient session, long uid)
{
try
{
return session.FindSingle("select * from fl_member_info where id = @id", new { id = uid });
}
catch (Exception ex)
{ }
return null;
}
///
/// 获取机器人集合
///
///
/// 刷新
///
public static List FindRobots(this SqlSugarClient session, bool refresh = false)
{
var key = $"find_robot_info_table";
List list = null;
list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.Find("select * from fl_robot_info order by id desc");
ApiClient.Cache.Set(key, list, 60 * 24);
}
return list;
}
///
/// 获取软件与插件的Config的配置
///
///
/// 刷新
///
public static List FindDictionaryItems(this SqlSugarClient session, bool refresh = false)
{
var key = $"find_fl_dictionary_item_table";
List list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.Find("select * from fl_dictionary_item");
ApiClient.Cache.Set(key, list, 60 * 24);
}
return list;
}
private static readonly object tljLock = new object();
///
/// 累加淘礼金创建次数
///
///
/// cps账号
public static void AddTljCreateNum(this SqlSugarClient session, string cpsname)
{
lock (tljLock)
{
var tljRecord = session.FindSingle("select * from fl_alimama_tlj_create_record where cpsname = @cpsname", new { cpsname = cpsname });
if (tljRecord != null)
{
var date = DateTime.Now.ToString("yyyyMMdd");
if (tljRecord.date == date)
tljRecord.number++;
else
{
tljRecord.number = 1;
tljRecord.date = date;
}
}
else
{
tljRecord = new fl_alimama_tlj_create_record() { cpsname = cpsname, date = DateTime.Now.ToString("yyyyMMdd"), number = 1 };
}
session.Saveable(tljRecord).ExecuteCommand();
}
}
///
/// 检测淘宝账号是否符合创建淘礼金(淘礼金每天创建30个)
///
///
/// cps账号
/// 返回true
public static bool FindTljCreateNum(this SqlSugarClient session, string cpsname)
{
lock (tljLock)
{
var tljRecord = session.FindSingle("select * from fl_alimama_tlj_create_record where cpsname = @cpsname", new { cpsname = cpsname });
if (tljRecord != null)
{
var date = DateTime.Now.ToString("yyyyMMdd");
return !(tljRecord.date == date && tljRecord.number >= 30);
}
return true;
}
}
///
/// 获取推广位集合
///
///
/// 刷新
///
public static List FindAdzoneInfos(this SqlSugarClient session, bool refresh = false)
{
var key = $"find_fl_adzone_info_table";
List list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
//list = session.Queryable().ToList();
list = session.Find("select * from fl_adzone_info");
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 获取所有的淘宝淘礼金信息
///
///
/// 刷新
///
public static List FindTljInfos(this SqlSugarClient session, bool refresh = false)
{
var key = $"find_fl_alimama_tlj_info_table";
List list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.Find("select * from fl_alimama_tlj_info");
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 通过推广位id判断是否为淘礼金订单
///
///
/// 推广位id
///
public static bool CheckIsTljOrder(this SqlSugarClient session, string adzone_id)
{
var tljInfos = session.FindTljInfos();
if (tljInfos.Count != 0)
{
tljInfos = tljInfos.Where(f => !string.IsNullOrWhiteSpace(f.adzone_pid)).ToList();
if (tljInfos.Count != 0)
{
var _tlj = tljInfos.FirstOrDefault(f => f.adzone_pid.EndsWith("_" + adzone_id));
return _tlj != null;
}
}
return false;
}
///
/// 15天内被拉黑过的用户不拉黑
///
///
/// 用户对象
/// 返回true不需要拉黑
public static bool TemporaryBypassedBlack(this SqlSugarClient session, fl_member_info member)
{
var time = DateTime.Now - member.blackout_time;
//15天内自动跳过
if (time.TotalDays <= 15)
{
EventClient.OnEvent(null, $"由于{member.usernick}({member.username})用户,最近被管理员人为去除黑名单,15天内将不会自动拉黑!");
return true;
}
return false;
}
///
/// 获取黑名单用户信息
///
///
///
///
public static List FindBlacklistMemberInfos(this SqlSugarClient session, bool refresh = false)
{
var key = $"find_fl_blacklist_member_info_table";
List list = ApiClient.Cache.Get>(key);
if (refresh || list == null)
{
list = session.Find("select * from fl_member_info where status = @status", new { status = MemberType.黑名单 });
ApiClient.Cache.Set(key, list, 60);
}
return list;
}
///
/// 通过文件key,获取配置文件
///
///
/// 配置文件的名称
/// 刷新
///
public static fl_dictionary_item FindDictionaryItem(this SqlSugarClient session, string key, bool refresh = false)
{
var table = session.FindDictionaryItems(refresh);
return table.FirstOrDefault(f => f.dickey == key);
}
///
/// 获得机器人信息
///
///
/// 机器人账号
/// 机器人平台类型
/// 刷新
///
public static fl_robot_info FindRobotInfo(this SqlSugarClient session, string robot_name, ChatType robot_type, bool refresh = false)
{
var robots = session.FindRobots(refresh);
var member = robots.FirstOrDefault(f => f.name.Trim() == robot_name.Trim() && f.type == robot_type);
return member;
}
///
/// 获取eid(关系)集合
///
///
/// 刷新
///
public static List FindTbRelations(this SqlSugarClient session, bool refresh = false)
{
var key = $"find_tb_relation_table";
var flTBRelationCache = ApiClient.Cache.Get>(key);
if (refresh || flTBRelationCache == null)
{
flTBRelationCache = session.Find("select * from fl_tb_relation");
}
return flTBRelationCache;
}
///
/// 公共分出比例列表
///
///
/// cps类型
/// 刷新
///
public static List FindRatios(this SqlSugarClient session, CpsType type, bool refresh = false)
{
var key = $"fl_ratio_info_tables_" + type;
var fl_ratio_infos = ApiClient.Cache.Get>(key);
if (!refresh && fl_ratio_infos != null) return fl_ratio_infos;
fl_ratio_infos = session.Find("select * from fl_ratio_info where cps_type = @cps_type order by comm asc", new { cps_type = type });
ApiClient.Cache.Set(key, fl_ratio_infos, 60);
return fl_ratio_infos;
}
///
/// 独立分出比例列表
///
///
///
///
///
public static List FindCustomRatios(this SqlSugarClient session, long cgid, bool refresh = false)
{
var key = $"fl_ratio_info_tables_" + cgid;
var fl_ratio_infos = ApiClient.Cache.Get>(key);
if (!refresh && fl_ratio_infos != null) return fl_ratio_infos;
fl_ratio_infos = session.Find("select * from fl_ratio_info_custom where cgid = @cgid order by comm asc", new { cgid = cgid });
ApiClient.Cache.Set(key, fl_ratio_infos, 60);
return fl_ratio_infos;
}
///
/// 根据金额获得佣金比例
///
///
/// cps类型
/// 佣金
///
public static fl_ratio_info FindRatio(this SqlSugarClient session, CpsType type, double commission)
{
var ratios = session.FindRatios(type);
int index = -1;
for (int i = 0; i < ratios.Count; i++)
{
double cur = ratios[i].comm;
if (i == (ratios.Count - 1)) cur = double.MaxValue;
if (commission <= cur)
{
index = i;
break;
}
}
if (index == -1) return null;
return ratios[index];
}
///
/// 根据金额获得独立佣金比例
///
///
///
///
///
public static fl_ratio_info_custom FindCustomRatio(this SqlSugarClient session, long cgid, double commission)
{
var ratios = session.FindCustomRatios(cgid);
int index = -1;
for (int i = 0; i < ratios.Count; i++)
{
double cur = ratios[i].comm;
if (i == (ratios.Count - 1)) cur = double.MaxValue;
if (commission <= cur)
{
index = i;
break;
}
}
if (index == -1) return null;
return ratios[index];
}
///
/// 扩展方法订单尾号集合缓存
///
///
///
///
public static List FindAlimamaOrderLastnums(this SqlSugarClient session, bool refresh = false)
{
var key = "fl_alimama_order_lastnum_tables";
var fl_alimama_order_lastnums = ApiClient.Cache.Get>(key);
if (refresh || fl_alimama_order_lastnums == null)
{
fl_alimama_order_lastnums = session.Find("select * from fl_alimama_order_lastnum");
ApiClient.Cache.Set(key, fl_alimama_order_lastnums, 60);
}
return fl_alimama_order_lastnums;
}
///
/// 获取会员组列表
///
///
/// 刷新
///
public static List FindGroups(this SqlSugarClient session, bool refresh = false)
{
var key = "fl_member_group_tables";
var fl_member_groups = ApiClient.Cache.Get>(key);//根据KEY、获得缓存
if (refresh || fl_member_groups == null)
{
fl_member_groups = session.Find("select * from fl_member_group order by terms asc");
for (int i = 0; i < fl_member_groups.Count; i++)
{
fl_member_groups[i].SetLevel(i + 1);
}
ApiClient.Cache.Set(key, fl_member_groups, 60);
}
return fl_member_groups;
}
///
/// 获得会员组
///
///
/// 根据组名称
///
public static fl_member_group FindGroup(this SqlSugarClient session, string group_name)
{
var groups = session.FindGroups();
return groups.FirstOrDefault(f => f.name == group_name);
}
///
/// 获得会员组
///
/// 会员组id
public static fl_member_group FindGroup(this SqlSugarClient session, long id)
{
var groups = session.FindGroups();
return groups.FirstOrDefault(f => f.id == id);
}
///
/// 获得用户组
///
///
/// 根据会员表
///
public static fl_member_group FindGroup(this SqlSugarClient session, fl_member_info member)
{
var group = session.FindGroup(member.group_id);
if (group == null) group = session.FindGroup(member.sum_point, member.bind_order);
if (group != null && member.group_id != group.id)
{
member.group_id = group.id;
if (member.id != 0)
session.SaveOrUpdate(member);
}
return group;
}
///
/// 根据消费总积分获得会员组
///
///
/// 消费总积分
/// 绑定订单数
///
public static fl_member_group FindGroup(this SqlSugarClient session, double sum_point, long bind_order)
{
var groups = session.FindGroups().OrderByDescending(f => f.terms).ThenByDescending(f => f.terms_ordersum).ToList();
var index = -1;
for (int i = 0; i < groups.Count; i++)
{
if (sum_point >= groups[i].terms && bind_order >= groups[i].terms_ordersum)
{
index = i;
break;
}
}
if (index == -1) return null;
return groups[index];
}
///
/// 获得推广位组信息
///
///
/// cps类型
/// 刷新
///
public static List FindAdzoneGroups(this SqlSugarClient session, CpsType type, bool refresh = false)
{
var key = $"fl_adzone_group_tables_{type}";
var list = ApiClient.Cache.Get>(key);
if (!refresh && list != null) return list;
list = session.Find("select * from fl_adzone_group where cps_type = @cps_type order by id Desc", new { cps_type = type });
if (list == null) list = new List();
ApiClient.Cache.Set(key, list, 60);
return list;
}
///
/// 获得延迟冻结信息
///
///
/// cps类型
/// 刷新
///
public static List FindSleeps(this SqlSugarClient session, CpsType type, bool refresh = false)
{
var key = $"fl_order_sleep_tables_{type}";
var list = ApiClient.Cache.Get>(key);
if (!refresh && list != null) return list;
list = session.Find("select * from fl_order_sleep where cps_type = @cps_type Order By money asc", new { cps_type = type });
if (list == null) list = new List();
ApiClient.Cache.Set(key, list, 60);
return list;
}
///
/// 获得延迟冻结时间
///
///
/// cps类型
/// 佣金
///
public static fl_order_sleep FindSleep(this SqlSugarClient session, CpsType type, double commission)
{
var list = session.FindSleeps(type);
if (list != null && list.Count > 0)
{
for (int i = 0; i < list.Count; i++)
{
if (commission <= list[i].money) return list[i];
}
return list[list.Count - 1];
}
return null;
}
///
/// 获得用户自定义变量信息
///
///
/// 刷新
///
public static List FindUserVariates(this SqlSugarClient session, bool refresh = false)
{
var key = $"fl_uservariate_info_tables";
var list = ApiClient.Cache.Get>(key);
if (!refresh && list != null) return list;
list = session.Find("select * from fl_uservariate_info");
if (list == null) list = new List();
ApiClient.Cache.Set(key, list, 60);
return list;
}
///
/// 获取查询阿里比价佣金的扣除后的计算佣金
///
/// 阿里订单
///
public static double GetTbComparisonFeeRate(this SqlSugarClient session, fl_order_alimama order)
{
var commission = (order.commission == 0 ? order.pub_share_pre_fee : order.commission);
if (order.alimama_rate != 0)
{
var tbConfig = OrderHelper.RefreshTbConfig();
if (tbConfig != null && tbConfig.ContainsKey("QueryComparisonSwitch") && tbConfig.ContainsKey("ComparisonFeeRate"))
{
var QueryComparisonSwitch = tbConfig["QueryComparisonSwitch"].ToString();
var ComparisonFeeRate = int.Parse(tbConfig["ComparisonFeeRate"].ToString());
if (QueryComparisonSwitch == "1" && ComparisonFeeRate > 0)//查询使用实时佣金 = 0,查询使用比价佣金 = 1,查询使用正常佣金 = 2
commission = Math.Round(commission * (1d - ((double)ComparisonFeeRate / 100d)), 2);
}
}
return commission;
}
///
/// 获取查询拼多多比价佣金的扣除后的计算佣金
///
/// 正常佣金
///
public static double GetPddComparisonFeeRate(this SqlSugarClient session, double commission)
{
//if (order.price_compare_status != PinduoduoBiJiaType.非比价)
{
var pddConfig = OrderHelper.RefreshPddConfig();
if (pddConfig != null && pddConfig.ContainsKey("ComparisonFeeRate"))
{
var ComparisonFeeRate = int.Parse(pddConfig["ComparisonFeeRate"].ToString());
if (ComparisonFeeRate > 0)//查询使用实时佣金 = 0,查询使用比价佣金 = 1,查询使用正常佣金 = 2
commission = Math.Round(commission * (1d - ((double)ComparisonFeeRate / 100d)), 2);
}
}
return commission;
}
///
/// 获得商品积分
///
///
/// 用户对象
/// 佣金
/// 购买数量
/// cps类型
///
public static ItemPoint FindItemPoint(this SqlSugarClient session, fl_member_info member, double _commission, int buy_count, CpsType type)
{
if (_commission == 0) return new ItemPoint();
var commission = (decimal)_commission / (decimal)buy_count;
member = session.UpdateMemberGroup(member);
//得到佣金
decimal _fl1 = 0;
#region 比例
if (member == null || member.private_ratio == 0)
{
var flag = true;
#region 是否使用独立分出比例分组
if (member != null)
{
fl_ratio_info_custom customR = null;
var ratioCustomId = -1l;
var g = session.FindGroup(member);
switch (type)
{
case CpsType.阿里妈妈:
ratioCustomId = g.ratio_custom_tb;
break;
case CpsType.多多进宝:
ratioCustomId = g.ratio_custom_pdd;
break;
case CpsType.京东联盟:
ratioCustomId = g.ratio_custom_jd;
break;
case CpsType.唯品联盟:
ratioCustomId = g.ratio_custom_wph;
break;
case CpsType.抖音联盟:
ratioCustomId = g.ratio_custom_dy;
break;
case CpsType.苏宁易购:
ratioCustomId = g.ratio_custom_sn;
break;
case CpsType.快手联盟:
ratioCustomId = g.ratio_custom_ks;
break;
default:
break;
}
if (ratioCustomId != -1)
{
var customRs = session.FindCustomRatios(ratioCustomId);
if (customRs != null && customRs.Count != 0)
{
customR = session.FindCustomRatio(ratioCustomId, (double)commission);
if (customR == null) throw new Exception($"独立佣金:{commission},没有满足该佣金的比例!");
_fl1 = (customR.subsidy_type == SubsidyType.固定积分 ? (decimal)customR.subsidy_num : ((decimal)customR.subsidy_num / 100m) * commission) * (decimal)buy_count;
LogHelper.GetSingleObj().Debug("", $"使用独立佣金计算:平台:{type.ToString()},独立分组:{ratioCustomId},补贴类型:{customR.subsidy_type},返点数:{customR.subsidy_num},单品佣金:{commission},品数:{buy_count}");
flag = false;
}
}
}
#endregion
if (flag)//公共分出比例
{
var ratio = session.FindRatio(type, (double)commission);
if (ratio == null) throw new Exception($"佣金:{commission},没有满足该佣金的比例!");
_fl1 = (ratio.subsidy_type == SubsidyType.固定积分 ? (decimal)ratio.subsidy_num : ((decimal)ratio.subsidy_num / 100m) * commission) * (decimal)buy_count;
LogHelper.GetSingleObj().Debug("", $"使用公共佣金计算:平台:{type.ToString()},佣金条件:{ratio.id},补贴类型:{ratio.subsidy_type},返点数:{ratio.subsidy_num},单品佣金:{commission},品数:{buy_count}");
}
}
else//私人比例
{
_fl1 = ((decimal)member.private_ratio / 100m) * commission * (decimal)buy_count;
}
#endregion
fl_member_group group = null;
if (member != null)
{
group = session.FindGroup(member.group_id);
if (group == null)//(这里锁定的用户对应的会员组不存在了,那么给用户设置一个默认值)
{
group = session.FindGroups().FirstOrDefault();
if (group != null)
{
member.group_id = group.id;
session.SaveOrUpdate(member);
}
}
}
else
group = session.FindGroups().FirstOrDefault();
if (group == null && member != null) throw new Exception($"积分:{member.sum_point},没有满足该积分的会员组!");
//补贴佣金
decimal _fl2 = (group.subsidy == 0 ? 0 : (group.subsidy_type == SubsidyType.固定积分 ? (decimal)group.subsidy : (decimal)group.subsidy / 100m * (decimal)_commission));
ItemPoint point = new ItemPoint();
//分出总额
decimal rst = Math.Round(_fl1 + _fl2, 2);
if (ApiClient.Setting.SystemConfig.AwardDepot == AwardDepotType.不扣分出佣金)
{
point.AwardOne = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardOne / 100m) * (decimal)rst), 2);
point.AwardTwo = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardTwo / 100m) * (decimal)rst), 2);
point.AwardThree = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardThree / 100m) * (decimal)rst), 2);
point.AwardCreate = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardCreator / 100m) * (decimal)rst), 2);
point.UserPoint = (double)rst;
}
else
{
point.AwardOne = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardOne / 100m) * (decimal)rst), 2);
point.AwardTwo = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardTwo / 100m) * (decimal)rst), 2);
point.AwardThree = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardThree / 100m) * (decimal)rst), 2);
point.AwardCreate = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardCreator / 100m) * (decimal)rst), 2);
point.UserPoint = Math.Round((double)((decimal)rst - (decimal)point.AwardOne - (decimal)point.AwardTwo - (decimal)point.AwardThree - (decimal)point.AwardCreate), 2);
}
point.UserPoint = point.UserPoint == 0 ? 0.01 : point.UserPoint;
return point;
}
///
/// 获得商品积分
///
///
/// 用户对象
/// 佣金
/// 购买数量
/// cps
/// 计算公式信息
///
public static ItemPoint FindItemPoint(this SqlSugarClient session, fl_member_info member, double _commission, int buy_count, CpsType type, out Compute compute)
{
compute = null;
if (_commission == 0) return new ItemPoint();
var commission = (decimal)_commission / (decimal)buy_count;
compute = new Compute();
member = session.UpdateMemberGroup(member);
//得到佣金
decimal _fl1 = 0;
#region 比例
if (member == null || member.private_ratio == 0)
{
var flag = true;
#region 是否使用独立分出比例分组
if (member != null)
{
fl_ratio_info_custom customR = null;
var ratioCustomId = -1l;
var g = session.FindGroup(member);
switch (type)
{
case CpsType.阿里妈妈:
ratioCustomId = g.ratio_custom_tb;
break;
case CpsType.多多进宝:
ratioCustomId = g.ratio_custom_pdd;
break;
case CpsType.京东联盟:
ratioCustomId = g.ratio_custom_jd;
break;
case CpsType.唯品联盟:
ratioCustomId = g.ratio_custom_wph;
break;
case CpsType.抖音联盟:
ratioCustomId = g.ratio_custom_dy;
break;
case CpsType.苏宁易购:
ratioCustomId = g.ratio_custom_sn;
break;
case CpsType.快手联盟:
ratioCustomId = g.ratio_custom_ks;
break;
default:
break;
}
if (ratioCustomId != -1)
{
var customRs = session.FindCustomRatios(ratioCustomId);
if (customRs != null && customRs.Count != 0)
{
customR = session.FindCustomRatio(ratioCustomId, (double)commission);
if (customR == null) throw new Exception($"独立佣金:{commission},没有满足该佣金的比例!");
_fl1 = (customR.subsidy_type == SubsidyType.固定积分 ? (decimal)customR.subsidy_num : ((decimal)customR.subsidy_num / 100m) * commission) * (decimal)buy_count;
compute.SubsidyType = customR.subsidy_type;
compute.IsPrivateRatio = false;
compute.Subsidy = customR.subsidy_num;
LogHelper.GetSingleObj().Debug("", $"使用独立佣金计算:平台:{type.ToString()},独立分组:{ratioCustomId},补贴类型:{customR.subsidy_type},返点数:{customR.subsidy_num},单品佣金:{commission},品数:{buy_count}");
flag = false;
}
}
}
#endregion
if (flag)//公共分出比例
{
var ratio = session.FindRatio(type, (double)commission);
if (ratio == null) throw new Exception($"佣金:{commission},没有满足该佣金的比例!");
_fl1 = (ratio.subsidy_type == SubsidyType.固定积分 ? (decimal)ratio.subsidy_num : ((decimal)ratio.subsidy_num / 100m) * commission) * (decimal)buy_count;
compute.SubsidyType = ratio.subsidy_type;
compute.IsPrivateRatio = false;
compute.Subsidy = ratio.subsidy_num;
LogHelper.GetSingleObj().Debug("", $"使用公共佣金计算:平台:{type.ToString()},佣金条件:{ratio.id},补贴类型:{ratio.subsidy_type},返点数:{ratio.subsidy_num},单品佣金:{commission},品数:{buy_count}");
}
}
else//私人比例
{
_fl1 = ((decimal)member.private_ratio / 100m) * commission * (decimal)buy_count;
compute.IsPrivateRatio = true;
compute.Subsidy = member.private_ratio;
}
#endregion
fl_member_group group = null;
if (member != null)
{
group = session.FindGroup(member.group_id);
if (group == null)//(这里锁定的用户对应的会员组不存在了,那么给用户设置一个默认值)
{
group = session.FindGroups().FirstOrDefault();
if (group != null)
{
member.group_id = group.id;
session.SaveOrUpdate(member);
}
}
}
else
group = session.FindGroups().FirstOrDefault();
if (group == null && member != null) throw new Exception($"积分:{member.sum_point},没有满足该积分的会员组!");
//补贴佣金
decimal _fl2 = (group.subsidy == 0 ? 0 : (group.subsidy_type == SubsidyType.固定积分 ? (decimal)group.subsidy : (decimal)group.subsidy / 100m * (decimal)_commission));
compute.GroupSubsidyType = group.subsidy_type;
compute.GroupSubsidy = group.subsidy;
ItemPoint point = new ItemPoint();
//分出总额
decimal rst = Math.Round(_fl1 + _fl2, 2);
if (ApiClient.Setting.SystemConfig.AwardDepot == AwardDepotType.不扣分出佣金)
{
point.AwardOne = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardOne / 100m) * (decimal)rst), 2);
point.AwardTwo = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardTwo / 100m) * (decimal)rst), 2);
point.AwardThree = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardThree / 100m) * (decimal)rst), 2);
point.AwardCreate = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardCreator / 100m) * (decimal)rst), 2);
point.UserPoint = (double)rst;
}
else
{
point.AwardOne = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardOne / 100m) * (decimal)rst), 2);
point.AwardTwo = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardTwo / 100m) * (decimal)rst), 2);
point.AwardThree = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardThree / 100m) * (decimal)rst), 2);
point.AwardCreate = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardCreator / 100m) * (decimal)rst), 2);
point.UserPoint = Math.Round((double)((decimal)rst - (decimal)point.AwardOne - (decimal)point.AwardTwo - (decimal)point.AwardThree - (decimal)point.AwardCreate), 2);
}
compute.AwardDepot = ApiClient.Setting.SystemConfig.AwardDepot;
compute.AwardOne = ApiClient.Setting.SystemConfig.AwardOne;
compute.AwardTwo = ApiClient.Setting.SystemConfig.AwardTwo;
compute.AwardThree = ApiClient.Setting.SystemConfig.AwardThree;
compute.AwardCreator = ApiClient.Setting.SystemConfig.AwardCreator;
point.UserPoint = point.UserPoint == 0 ? 0.01 : point.UserPoint;
return point;
}
///
/// 获得商品积分
///
///
/// 计算公式信息
/// 佣金
/// 购买数量
/// cps
///
public static ItemPoint FindItemPoint(this SqlSugarClient session, CpsType type, Compute compute, double _commission, int buy_count)
{
if (_commission == 0) return new ItemPoint();
var commission = (decimal)_commission / (decimal)buy_count;
//得到佣金
decimal _fl1 = 0;
#region 比例
if (!compute.IsPrivateRatio)
{
_fl1 = (compute.SubsidyType == SubsidyType.固定积分 ? (decimal)compute.Subsidy : ((decimal)compute.Subsidy / 100m) * commission) * (decimal)buy_count;
LogHelper.GetSingleObj().Debug("", $"使用历史佣金计算:平台:{type.ToString()},补贴类型:{compute.SubsidyType},返点数:{compute.Subsidy},单品佣金:{commission},品数:{buy_count}");
}
else
{
_fl1 = ((decimal)compute.Subsidy / 100m) * commission * (decimal)buy_count;
}
#endregion
//补贴佣金
decimal _fl2 = (compute.GroupSubsidy == 0 ? 0 : (compute.GroupSubsidyType == SubsidyType.固定积分 ? (decimal)compute.GroupSubsidy : (decimal)compute.GroupSubsidy / 100m * (decimal)_commission));
ItemPoint point = new ItemPoint();
//分出总额
decimal rst = Math.Round(_fl1 + _fl2, 2);
if (compute.AwardDepot == AwardDepotType.不扣分出佣金)
{
point.AwardOne = Math.Round((double)(((decimal)compute.AwardOne / 100m) * (decimal)rst), 2);
point.AwardTwo = Math.Round((double)(((decimal)compute.AwardTwo / 100m) * (decimal)rst), 2);
point.AwardThree = Math.Round((double)(((decimal)compute.AwardThree / 100m) * (decimal)rst), 2);
point.AwardCreate = Math.Round((double)(((decimal)compute.AwardCreator / 100m) * (decimal)rst), 2);
point.UserPoint = (double)rst;
}
else
{
point.AwardOne = Math.Round((double)(((decimal)compute.AwardOne / 100m) * (decimal)rst), 2);
point.AwardTwo = Math.Round((double)(((decimal)compute.AwardTwo / 100m) * (decimal)rst), 2);
point.AwardThree = Math.Round((double)(((decimal)compute.AwardThree / 100m) * (decimal)rst), 2);
point.AwardCreate = Math.Round((double)(((decimal)compute.AwardCreator / 100m) * (decimal)rst), 2);
point.UserPoint = Math.Round((double)((decimal)rst - (decimal)point.AwardOne - (decimal)point.AwardTwo - (decimal)point.AwardThree - (decimal)point.AwardCreate), 2);
}
point.UserPoint = point.UserPoint == 0 ? 0.01 : point.UserPoint;
return point;
}
#region 老版本的积分计算
//public static ItemPoint FindItemPoint(this SqlSugarClient session, fl_member_info member, double _commission, int buy_count, CpsType type)
//{
// if (_commission == 0) return new ItemPoint();
// var commission = (decimal)_commission / (decimal)buy_count;
// member = session.UpdateMemberGroup(member);
// //得到佣金
// decimal _fl1 = 0;
// #region 比例
// if (member == null || member.private_ratio == 0)
// {
// var ratio = session.FindRatio(type, (double)commission);
// if (ratio == null) throw new Exception($"佣金:{commission},没有满足该佣金的比例!");
// _fl1 = (ratio.subsidy_type == SubsidyType.固定积分 ? (decimal)ratio.subsidy_num : ((decimal)ratio.subsidy_num / 100m) * commission) * (decimal)buy_count;
// }
// else//私人比例
// {
// _fl1 = ((decimal)member.private_ratio / 100m) * commission * (decimal)buy_count;
// }
// #endregion
// fl_member_group group = null;
// if (member != null)
// {
// group = session.FindGroup(member.group_id);
// if (group == null)//(这里锁定的用户对应的会员组不存在了,那么给用户设置一个默认值)
// {
// group = session.FindGroups().FirstOrDefault();
// if (group != null)
// {
// member.group_id = group.id;
// session.SaveOrUpdate(member);
// }
// }
// }
// else
// group = session.FindGroups().FirstOrDefault();
// if (group == null && member != null) throw new Exception($"积分:{member.sum_point},没有满足该积分的会员组!");
// //补贴佣金
// //decimal _fl2 = (group.subsidy <= 0 ? 0 : (group.subsidy_type == SubsidyType.固定积分 ? (decimal)group.subsidy : (decimal)group.subsidy / 100m * commission)) * (decimal)buy_count;
// decimal _fl2 = (group.subsidy == 0 ? 0 : (group.subsidy_type == SubsidyType.固定积分 ? (decimal)group.subsidy : (decimal)group.subsidy / 100m * (decimal)_commission));
// ItemPoint point = new ItemPoint();
// //分出总额
// decimal rst = Math.Round(_fl1 + _fl2, 2);
// if (ApiClient.Setting.SystemConfig.AwardDepot == AwardDepotType.不扣分出佣金)
// {
// point.AwardOne = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardOne / 100m) * (decimal)rst), 2);
// point.AwardTwo = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardTwo / 100m) * (decimal)rst), 2);
// point.AwardThree = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardThree / 100m) * (decimal)rst), 2);
// point.AwardCreate = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardCreator / 100m) * (decimal)rst), 2);
// point.UserPoint = (double)rst;
// }
// else
// {
// point.AwardOne = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardOne / 100m) * (decimal)rst), 2);
// point.AwardTwo = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardTwo / 100m) * (decimal)rst), 2);
// point.AwardThree = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardThree / 100m) * (decimal)rst), 2);
// point.AwardCreate = Math.Round((double)(((decimal)ApiClient.Setting.SystemConfig.AwardCreator / 100m) * (decimal)rst), 2);
// point.UserPoint = Math.Round((double)((decimal)rst - (decimal)point.AwardOne - (decimal)point.AwardTwo - (decimal)point.AwardThree - (decimal)point.AwardCreate), 2);
// }
// point.UserPoint = point.UserPoint == 0 ? 0.01 : point.UserPoint;
// return point;
//}
#endregion
///
/// 读取绑定记录
///
///
/// 订单编号
/// 刷新
///
public static fl_bind_cache FindBindCache(this SqlSugarClient session, string orderid, bool refresh = false)
{
var key = $"fl_bind_cache_{orderid}";
var bind = ApiClient.Cache.Get(key);
if (!refresh && bind != null) return bind;
bind = session.FindSingle("orderid = @orderid", new { orderid = orderid });
if (bind != null) ApiClient.Cache.Set(key, bind, 30);
return bind;
}
///
/// 获得创建者信息
///
///
/// 群号
/// 类型
/// 刷新
///
public static fl_group_person FindCreateInfo(this SqlSugarClient session, string groupid, ChatType type, bool refresh = false)
{
try
{
var key = $"find_fl_group_person_{groupid}_{type}";
var item = ApiClient.Cache.Get(key);
if (!refresh && item != null) return item;
item = session.FindSingle("select * from fl_group_person where groupid = @groupid", new { groupid = groupid });
if (item != null) ApiClient.Cache.Set(key, item, 10);
return item;
}
catch { }
return null;
}
///
/// 更新用户所在分组
///
///
/// 用户对象
///
public static fl_member_info UpdateMemberGroup(this SqlSugarClient session, fl_member_info member)
{
try
{
if (member == null) return null;
#region 无视积分影响分组升级
if (member.ignore_group_update == SwitchType.关闭)
{
//判断是否需要升级会员组
var _oldGroup = session.FindGroup(member);
var _newGroup = session.FindGroup(member.sum_point, member.bind_order);
if (_oldGroup != null && _newGroup != null && _oldGroup.id != _newGroup.id)
{
member.group_id = _newGroup.id;
}
}
session.SaveOrUpdate(member);
#endregion
}
catch (Exception)
{ }
return member;
}
///
/// 删除cps对象
///
///
/// cps对象
public static void Delete(this SqlSugarClient session, fl_cps_member obj)
{
session.Deleteable(obj).ExecuteCommand();
}
///
/// 删除会员分组
///
///
/// 会员分组
public static void Delete(this SqlSugarClient session, fl_member_group obj)
{
session.Deleteable(obj).ExecuteCommand();
}
///
/// 添加/修改微信支付信息
///
///
/// 微信支付信息对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_weixin_password model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 苏宁推广位记录表
///
///
///
public static void SaveOrUpdate(this SqlSugarClient session, fl_suning_tgw model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
public static void SaveOrUpdate(this SqlSugarClient session, fl_ratio_info_custom model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 独立分出比例分组
///
///
///
public static void SaveOrUpdate(this SqlSugarClient session, fl_ratio_info_custom_group model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
public static fl_dy_ck FindDyCk(this SqlSugarClient session, string cpsname, string chname)
{
return session.FindSingle("select * from fl_dy_ck where cpsname = @cpsname and chname = @chname", new { cpsname = cpsname, chname = chname });
}
public static void SaveOrUpdate(this SqlSugarClient session, fl_dy_ck model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改群管理
///
///
/// 群管理对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_group_person model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改订单维权
///
///
///
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_refund_alimama model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改推广位信息
///
///
/// 推广位对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_adzone_info model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改订单冻结规则
///
///
/// 订单冻结规则对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_sleep model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改会员分组
///
///
/// 会员分组对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_member_group model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改机器人对象
///
///
/// 机器人对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_robot_info model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改用户对象
///
///
/// 用户对象
/// false:只修改关键信息
public static void SaveOrUpdate(this SqlSugarClient session, fl_member_info model, bool all = false)
{
if (model.id == 0)
model.id = session.Insertable(model).ExecuteReturnIdentity();
else
{
if (all)
session.Updateable(model).With(SqlWith.UpdLock).ExecuteCommand();
else
{
//session.Update(model).
session.Updateable(model)
.UpdateColumns(f =>
new
{
f.usernick,
f.robot_type,
f.robot_name,
f.status,
f.remark,
f.finish_order,
f.inviter_id,
f.group_id,
f.ignore_group_update,
f.alipay_name,
f.alipay_num,
f.identity_name,
f.identity_card,
f.upd_time,
f.blackout_time,
f.chat_count,
f.ban_exchange_time,
f.private_ratio,
f.realnick,
f.bind_order,
f.exchange_type,
f.wechatid,
f.is_cloud_black,
f.check_cloud_black_time,
f.headurl
}
).ExecuteCommand();
//session.Updateable(new
//{
// usernick = model.usernick,
// robot_type = model.robot_type,
// robot_name = model.robot_name,
// status = model.status,
// remark = model.remark,
// finish_order = model.finish_order,
// inviter_id = model.inviter_id,
// group_id = model.group_id,
// ignore_group_update = model.ignore_group_update,
// alipay_name = model.alipay_name,
// alipay_num = model.alipay_num,
// identity_name = model.identity_name,
// identity_card = model.identity_card,
// upd_time = DateTime.Now,
// blackout_time = model.blackout_time,
// chat_count = model.chat_count,
// ban_exchange_time = model.ban_exchange_time,
// private_ratio = model.private_ratio,
// realnick = model.realnick,
// bind_order = model.bind_order,
// wechatid = model.wechatid,
// is_cloud_black = model.is_cloud_black,
// check_cloud_black_time = model.check_cloud_black_time
//}).Where(f => f.id == model.id).ExecuteCommand();
}
}
}
///
/// 添加/修改cps对象
///
///
///
public static void SaveOrUpdate(this SqlSugarClient session, fl_cps_member model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改拼多多订单
///
///
/// 拼多多订单对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_pinduoduo model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改唯品会订单
///
///
/// 唯品会订单对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_weipinhui model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改快手订单
///
///
/// 快手订单对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_kuaishou model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改京东订单
///
///
/// 京东订单对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_jingdong model)
{
//if (model.id == 0)
// model.id = session.Insertable(model).ExecuteReturnBigIdentity();
//else
// session.Updateable(model).ExecuteCommand();
model = session.Saveable(model).ExecuteReturnEntity();
}
public static void SaveOrUpdate(this SqlSugarClient session, fl_query_ratio_hist model)
{
try
{
if (model == null) return;
var modelTmp = session.GetQueryRatioHist(model.cpstype, model.db_orderid);
if (modelTmp != null)
model.id = modelTmp.id;
model = session.Saveable(model).ExecuteReturnEntity();
}
catch (Exception)
{ }
}
private static fl_query_ratio_hist GetQueryRatioHist(this SqlSugarClient session, CpsType cpsTyp, long id)
{
return session.FindSingle("select * from fl_query_ratio_hist where cpstype = @cpstype and db_orderid = @db_orderid", new { cpstype = cpsTyp, db_orderid = id });
}
///
/// 添加/修改抖音订单
///
///
/// 抖音订单对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_douyin model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改苏宁订单
///
///
/// 抖音订单对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_suning model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改阿里订单
///
///
/// 阿里订单对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_alimama model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改分出比例
///
///
/// 分出比例对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_ratio_info model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 添加/修改配置
///
///
/// 配置对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_dictionary_item model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
///
/// 记录用户基础记录(商品查询次数)
///
///
/// 用户id
public static void UpdateRecord(this SqlSugarClient session, long uid)
{
var key = "fl_statistics_record_key";
var list = ApiClient.Cache.Get>(key);
if (list == null)
{
list = session.Find("select * from fl_statistics_record");
if (list == null) list = new List();
ApiClient.Cache.Set(key, list, 60);
}
if (list.FirstOrDefault(f => f.uid == uid) == null)
{
var record = new fl_statistics_record() { uid = uid, querynum = 1, ex3 = HttpExtend.GetTimeStamp(DateTime.Now) };
session.Insertable(record).ExecuteCommand();
list.Add(record);
}
else
session.ExcuteSQL("update fl_statistics_record set querynum = querynum + 1 where uid = @uid", new { uid = uid });
}
///
/// 查询用户基础记录
///
///
/// 用户id
///
public static fl_statistics_record FindStatisticsRecord(this SqlSugarClient session, long uid)
{
return session.FindSingle("select * from fl_statistics_record where uid = @uid", new { uid = uid });
}
///
/// 查询历史查询比例
///
///
/// 平台类型
/// 订单id
///
public static Compute FindQueryRatioHist(this SqlSugarClient session, CpsType cpstype, long db_orderid)
{
if (db_orderid == 0)
return null;
Compute compute = null;
#region 查询历史查询比例
var queryRatioHist = session.FindSingle("select * from fl_query_ratio_hist where cpstype = @cpstype and db_orderid = @db_orderid", new { cpstype = cpstype, db_orderid = db_orderid });
if (queryRatioHist != null && !string.IsNullOrWhiteSpace(queryRatioHist.compute_config))
{
compute = JsonConvert.DeserializeObject(queryRatioHist.compute_config);
}
#endregion
return compute;
}
///
/// 通过阿里商品id获取已经创建的淘礼金
///
///
/// 商品id
public static fl_alimama_tlj_get_record FindTljByItemid(this SqlSugarClient session, string itemid)
{
var tlj = session.FindSingle("select * from fl_alimama_tlj_get_record where itemid = @itemid", new { itemid = itemid });
if (tlj != null)
{
if (tlj.expiredate <= DateTime.Now || tlj.number <= 0)
{
session.Deleteable(tlj).ExecuteCommand();
return null;
}
return tlj;
}
return null;
}
///
/// 添加/修改阿里淘礼金记录
///
///
/// 阿里淘礼金记录对象
public static void SaveOrUpdate(this SqlSugarClient session, fl_alimama_tlj_get_record model)
{
model = session.Saveable(model).ExecuteReturnEntity();
}
}
}
///
/// 积分分配类
///
public class ItemPoint
{
///
/// 类型
///
public CpsType Type { get; set; }
///
/// 总佣金
///
public double Commission { get; set; }
///
/// 总积分
///
public double SumPoint
{
get { return (double)((decimal)UserPoint + (decimal)AwardOne + (decimal)AwardTwo + (decimal)AwardThree + (decimal)AwardCreate); }
}
///
/// 用户积分
///
public double UserPoint { get; set; }
///
/// 一级提成
///
public double AwardOne { get; set; }
///
/// 二级提成
///
public double AwardTwo { get; set; }
///
/// 三级提成
///
public double AwardThree { get; set; }
///
/// 创建者提成
///
public double AwardCreate { get; set; }
}