1990 lines
86 KiB
C#
1990 lines
86 KiB
C#
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
|
||
{
|
||
/// <summary>
|
||
/// 扩展方法
|
||
/// </summary>
|
||
public static class ModelExtend
|
||
{
|
||
|
||
private static readonly object lock_point = new object();
|
||
|
||
/// <summary>
|
||
/// 改变积分
|
||
/// </summary>
|
||
/// <param name="session">数据库操作对象</param>
|
||
/// <param name="type">类型</param>
|
||
/// <param name="money">金额(单位:元)</param>
|
||
/// <param name="memberid">用户id</param>
|
||
/// <param name="message">备注</param>
|
||
/// <param name="pointType_name">自定义积分类型(为空即可)</param>
|
||
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<fl_refund_hist_point>("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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 微信支付密码集合
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh"></param>
|
||
/// <returns></returns>
|
||
public static List<fl_weixin_password> FindWeixinpasswords(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "fl_weixin_password_table";
|
||
var list = ApiClient.Cache.Get<List<fl_weixin_password>>(key);
|
||
if (refresh || list == null)
|
||
{
|
||
list = session.Find<fl_weixin_password>("select * from fl_weixin_password", new { });
|
||
ApiClient.Cache.Set(key, list, 60);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询微信密码信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="robot_id"></param>
|
||
/// <param name="refresh"></param>
|
||
/// <returns></returns>
|
||
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);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询淘宝自动绑定PID集合
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">true刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_info> FindAlimamaAutoBindPid(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "fl_alimama_auto_bind_adzone_info";
|
||
var list = ApiClient.Cache.Get<List<fl_adzone_info>>(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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 尾号绑定.非订单查询绑定(朋友圈等其他推广)
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh"></param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_info> FindAlimamaTailBindPid(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "fl_alimama_tail_bind_adzone_info";
|
||
var list = ApiClient.Cache.Get<List<fl_adzone_info>>(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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 阿里私人推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="adzone_pid">私人pid</param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_info> 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 抖音私人推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="adzone_pid">私人pid</param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_info> 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 京东私人推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="adzone_pid">私人pid</param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_info> 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 苏宁私人推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="adzone_pid">私人pid</param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_info> 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 拼多多推广位自动绑定推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<string> FindSuningAutoBindPid(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "fl_suning_auto_bind_adzone_info";
|
||
var list = ApiClient.Cache.Get<List<String>>(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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 拼多多私人推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="adzone_pid">私人pid</param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_info> 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<fl_adzone_info> 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 拼多多推广位自动绑定推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<string> FindPinduoduoAutoBindPid(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "fl_pinduoduo_auto_bind_adzone_info";
|
||
var list = ApiClient.Cache.Get<List<String>>(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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 快手推广位自动绑定推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<string> FindKuaishouAutoBindPid(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "fl_kuaishou_auto_bind_adzone_info";
|
||
var list = ApiClient.Cache.Get<List<String>>(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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 抖音推广位自动绑定推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<string> FindDouyinAutoBindPid(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "fl_douyin_auto_bind_adzone_info";
|
||
var list = ApiClient.Cache.Get<List<String>>(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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 唯品会推广位自动绑定推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<string> FindWeipinhuiAutoBindPid(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "fl_weipinhui_auto_bind_adzone_info";
|
||
var list = ApiClient.Cache.Get<List<String>>(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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 唯品会私人推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="adzone_pid">私人pid</param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_info> 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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取通知Robots
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_noticeapi_info> FindNoticeapiRobots(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "FindNoticeapiRobots";
|
||
var list = ApiClient.Cache.Get<List<fl_noticeapi_info>>(key);
|
||
if (refresh || list == null)
|
||
{
|
||
list = session.Queryable<fl_noticeapi_info>().ToList();
|
||
ApiClient.Cache.Set(key, list, 60 * 24);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 京东推广位自动绑定推广位
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<string> FindJingdongAutoBindPid(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
string key = "fl_jingdong_auto_bind_adzone_info";
|
||
var list = ApiClient.Cache.Get<List<String>>(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();
|
||
|
||
/// <summary>
|
||
/// 获得会员数据
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="e">通用IM消息</param>
|
||
/// <returns></returns>
|
||
public static fl_member_info FindMemberinfo(this SqlSugarClient session, ReciveIMEvent e)
|
||
{
|
||
|
||
var m = session.FindSingle<fl_member_info>("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;
|
||
session.Insertable(m).ExecuteReturnEntity();
|
||
}
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过用户账号查询用户对象
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="username">用户账号</param>
|
||
/// <returns></returns>
|
||
public static fl_member_info FindMemberInfoByUsername(this SqlSugarClient session, string username)
|
||
{
|
||
try
|
||
{
|
||
return session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username", new { username = username });
|
||
}
|
||
catch (Exception ex)
|
||
{ }
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过用户id查询用户对象
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="uid">用户id</param>
|
||
/// <returns></returns>
|
||
public static fl_member_info FindMemberInfoById(this SqlSugarClient session, long uid)
|
||
{
|
||
try
|
||
{
|
||
return session.FindSingle<fl_member_info>("select * from fl_member_info where id = @id", new { id = uid });
|
||
}
|
||
catch (Exception ex)
|
||
{ }
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取机器人集合
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_robot_info> FindRobots(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
var key = $"find_robot_info_table";
|
||
List<fl_robot_info> list = null;
|
||
list = ApiClient.Cache.Get<List<fl_robot_info>>(key);
|
||
if (refresh || list == null)
|
||
{
|
||
list = session.Find<fl_robot_info>("select * from fl_robot_info order by id desc");
|
||
ApiClient.Cache.Set(key, list, 60 * 24);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取软件与插件的Config的配置
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_dictionary_item> FindDictionaryItems(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
var key = $"find_fl_dictionary_item_table";
|
||
List<fl_dictionary_item> list = ApiClient.Cache.Get<List<fl_dictionary_item>>(key);
|
||
if (refresh || list == null)
|
||
{
|
||
list = session.Find<fl_dictionary_item>("select * from fl_dictionary_item");
|
||
ApiClient.Cache.Set(key, list, 60 * 24);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
private static readonly object tljLock = new object();
|
||
/// <summary>
|
||
/// 累加淘礼金创建次数
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="cpsname">cps账号</param>
|
||
public static void AddTljCreateNum(this SqlSugarClient session, string cpsname)
|
||
{
|
||
lock (tljLock)
|
||
{
|
||
var tljRecord = session.FindSingle<fl_alimama_tlj_create_record>("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();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检测淘宝账号是否符合创建淘礼金(淘礼金每天创建30个)
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="cpsname">cps账号</param>
|
||
/// <returns>返回true</returns>
|
||
public static bool FindTljCreateNum(this SqlSugarClient session, string cpsname)
|
||
{
|
||
lock (tljLock)
|
||
{
|
||
var tljRecord = session.FindSingle<fl_alimama_tlj_create_record>("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;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取推广位集合
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_info> FindAdzoneInfos(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
var key = $"find_fl_adzone_info_table";
|
||
List<fl_adzone_info> list = ApiClient.Cache.Get<List<fl_adzone_info>>(key);
|
||
if (refresh || list == null)
|
||
{
|
||
//list = session.Queryable<fl_adzone_info>().ToList();
|
||
list = session.Find<fl_adzone_info>("select * from fl_adzone_info");
|
||
ApiClient.Cache.Set(key, list, 60);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取所有的淘宝淘礼金信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_alimama_tlj_info> FindTljInfos(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
var key = $"find_fl_alimama_tlj_info_table";
|
||
List<fl_alimama_tlj_info> list = ApiClient.Cache.Get<List<fl_alimama_tlj_info>>(key);
|
||
if (refresh || list == null)
|
||
{
|
||
list = session.Find<fl_alimama_tlj_info>("select * from fl_alimama_tlj_info");
|
||
ApiClient.Cache.Set(key, list, 60);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过推广位id判断是否为淘礼金订单
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="adzone_id">推广位id</param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 15天内被拉黑过的用户不拉黑
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="member">用户对象</param>
|
||
/// <returns>返回true不需要拉黑</returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取黑名单用户信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh"></param>
|
||
/// <returns></returns>
|
||
public static List<fl_member_info> FindBlacklistMemberInfos(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
var key = $"find_fl_blacklist_member_info_table";
|
||
List<fl_member_info> list = ApiClient.Cache.Get<List<fl_member_info>>(key);
|
||
if (refresh || list == null)
|
||
{
|
||
list = session.Find<fl_member_info>("select * from fl_member_info where status = @status", new { status = MemberType.黑名单 });
|
||
ApiClient.Cache.Set(key, list, 60);
|
||
}
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过文件key,获取配置文件
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="key">配置文件的名称</param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
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);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得机器人信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="username">机器人账号</param>
|
||
/// <param name="robot_type">机器人平台类型</param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取eid(关系)集合
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_tb_relation> FindTbRelations(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
var key = $"find_tb_relation_table";
|
||
var flTBRelationCache = ApiClient.Cache.Get<List<fl_tb_relation>>(key);
|
||
if (refresh || flTBRelationCache == null)
|
||
{
|
||
flTBRelationCache = session.Find<fl_tb_relation>("select * from fl_tb_relation");
|
||
}
|
||
return flTBRelationCache;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 公共分出比例列表
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="type">cps类型</param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_ratio_info> FindRatios(this SqlSugarClient session, CpsType type, bool refresh = false)
|
||
{
|
||
var key = $"fl_ratio_info_tables_" + type;
|
||
var fl_ratio_infos = ApiClient.Cache.Get<List<fl_ratio_info>>(key);
|
||
if (!refresh && fl_ratio_infos != null) return fl_ratio_infos;
|
||
fl_ratio_infos = session.Find<fl_ratio_info>("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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 独立分出比例列表
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="type"></param>
|
||
/// <param name="refresh"></param>
|
||
/// <returns></returns>
|
||
public static List<fl_ratio_info_custom> FindCustomRatios(this SqlSugarClient session, long cgid, bool refresh = false)
|
||
{
|
||
var key = $"fl_ratio_info_tables_" + cgid;
|
||
var fl_ratio_infos = ApiClient.Cache.Get<List<fl_ratio_info_custom>>(key);
|
||
if (!refresh && fl_ratio_infos != null) return fl_ratio_infos;
|
||
fl_ratio_infos = session.Find<fl_ratio_info_custom>("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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据金额获得佣金比例
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="type">cps类型</param>
|
||
/// <param name="commission">佣金</param>
|
||
/// <returns></returns>
|
||
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];
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据金额获得独立佣金比例
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="cgid"></param>
|
||
/// <param name="commission"></param>
|
||
/// <returns></returns>
|
||
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];
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 扩展方法订单尾号集合缓存
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh"></param>
|
||
/// <returns></returns>
|
||
public static List<fl_alimama_order_lastnum> FindAlimamaOrderLastnums(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
var key = "fl_alimama_order_lastnum_tables";
|
||
var fl_alimama_order_lastnums = ApiClient.Cache.Get<List<fl_alimama_order_lastnum>>(key);
|
||
if (refresh || fl_alimama_order_lastnums == null)
|
||
{
|
||
fl_alimama_order_lastnums = session.Find<fl_alimama_order_lastnum>("select * from fl_alimama_order_lastnum");
|
||
ApiClient.Cache.Set(key, fl_alimama_order_lastnums, 60);
|
||
}
|
||
return fl_alimama_order_lastnums;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 获取会员组列表
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_member_group> FindGroups(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
var key = "fl_member_group_tables";
|
||
var fl_member_groups = ApiClient.Cache.Get<List<fl_member_group>>(key);//根据KEY、获得缓存
|
||
if (refresh || fl_member_groups == null)
|
||
{
|
||
fl_member_groups = session.Find<fl_member_group>("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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得会员组
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="group_name">根据组名称</param>
|
||
/// <returns></returns>
|
||
public static fl_member_group FindGroup(this SqlSugarClient session, string group_name)
|
||
{
|
||
var groups = session.FindGroups();
|
||
return groups.FirstOrDefault(f => f.name == group_name);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得会员组
|
||
/// </summary>
|
||
/// <param name="id">会员组id</param>
|
||
public static fl_member_group FindGroup(this SqlSugarClient session, long id)
|
||
{
|
||
var groups = session.FindGroups();
|
||
return groups.FirstOrDefault(f => f.id == id);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得用户组
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="member">根据会员表</param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 根据消费总积分获得会员组
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="sum_point">消费总积分</param>
|
||
/// <param name="bind_order">绑定订单数</param>
|
||
/// <returns></returns>
|
||
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];
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得推广位组信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="type">cps类型</param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_adzone_group> FindAdzoneGroups(this SqlSugarClient session, CpsType type, bool refresh = false)
|
||
{
|
||
var key = $"fl_adzone_group_tables_{type}";
|
||
var list = ApiClient.Cache.Get<List<fl_adzone_group>>(key);
|
||
if (!refresh && list != null) return list;
|
||
list = session.Find<fl_adzone_group>("select * from fl_adzone_group where cps_type = @cps_type order by id Desc", new { cps_type = type });
|
||
if (list == null) list = new List<fl_adzone_group>();
|
||
ApiClient.Cache.Set(key, list, 60);
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得延迟冻结信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="type">cps类型</param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_order_sleep> FindSleeps(this SqlSugarClient session, CpsType type, bool refresh = false)
|
||
{
|
||
var key = $"fl_order_sleep_tables_{type}";
|
||
var list = ApiClient.Cache.Get<List<fl_order_sleep>>(key);
|
||
if (!refresh && list != null) return list;
|
||
list = session.Find<fl_order_sleep>("select * from fl_order_sleep where cps_type = @cps_type Order By money asc", new { cps_type = type });
|
||
if (list == null) list = new List<fl_order_sleep>();
|
||
ApiClient.Cache.Set(key, list, 60);
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得延迟冻结时间
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="type">cps类型</param>
|
||
/// <param name="commission">佣金</param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得用户自定义变量信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
public static List<fl_uservariate_info> FindUserVariates(this SqlSugarClient session, bool refresh = false)
|
||
{
|
||
var key = $"fl_uservariate_info_tables";
|
||
var list = ApiClient.Cache.Get<List<fl_uservariate_info>>(key);
|
||
if (!refresh && list != null) return list;
|
||
list = session.Find<fl_uservariate_info>("select * from fl_uservariate_info");
|
||
if (list == null) list = new List<fl_uservariate_info>();
|
||
ApiClient.Cache.Set(key, list, 60);
|
||
return list;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取查询阿里比价佣金的扣除后的计算佣金
|
||
/// </summary>
|
||
/// <param name="order">阿里订单</param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取查询拼多多比价佣金的扣除后的计算佣金
|
||
/// </summary>
|
||
/// <param name="commission">正常佣金</param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得商品积分
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="member">用户对象</param>
|
||
/// <param name="_commission">佣金</param>
|
||
/// <param name="buy_count">购买数量</param>
|
||
/// <param name="type">cps类型</param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得商品积分
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="member">用户对象</param>
|
||
/// <param name="_commission">佣金</param>
|
||
/// <param name="buy_count">购买数量</param>
|
||
/// <param name="type">cps</param>
|
||
/// <param name="compute">计算公式信息</param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得商品积分
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="compute">计算公式信息</param>
|
||
/// <param name="_commission">佣金</param>
|
||
/// <param name="buy_count">购买数量</param>
|
||
/// <param name="type">cps</param>
|
||
/// <returns></returns>
|
||
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
|
||
|
||
/// <summary>
|
||
/// 读取绑定记录
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="orderid">订单编号</param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
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<fl_bind_cache>(key);
|
||
if (!refresh && bind != null) return bind;
|
||
bind = session.FindSingle<fl_bind_cache>("orderid = @orderid", new { orderid = orderid });
|
||
if (bind != null) ApiClient.Cache.Set(key, bind, 30);
|
||
return bind;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获得创建者信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="groupid">群号</param>
|
||
/// <param name="type">类型</param>
|
||
/// <param name="refresh">刷新</param>
|
||
/// <returns></returns>
|
||
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<fl_group_person>(key);
|
||
if (!refresh && item != null) return item;
|
||
item = session.FindSingle<fl_group_person>("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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 更新用户所在分组
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="member">用户对象</param>
|
||
/// <returns></returns>
|
||
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;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除cps对象
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="obj">cps对象</param>
|
||
public static void Delete(this SqlSugarClient session, fl_cps_member obj)
|
||
{
|
||
session.Deleteable(obj).ExecuteCommand();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 删除会员分组
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="obj">会员分组</param>
|
||
public static void Delete(this SqlSugarClient session, fl_member_group obj)
|
||
{
|
||
session.Deleteable(obj).ExecuteCommand();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改微信支付信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">微信支付信息对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_weixin_password model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 苏宁推广位记录表
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model"></param>
|
||
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();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 独立分出比例分组
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model"></param>
|
||
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<fl_dy_ck>("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();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改群管理
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">群管理对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_group_person model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改订单维权
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model"></param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_refund_alimama model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改推广位信息
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">推广位对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_adzone_info model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改订单冻结规则
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">订单冻结规则对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_sleep model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改会员分组
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">会员分组对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_member_group model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改机器人对象
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">机器人对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_robot_info model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改用户对象
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">用户对象</param>
|
||
/// <param name="all">false:只修改关键信息</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_member_info model, bool all = false)
|
||
{
|
||
if (model.id == 0)
|
||
model.id = session.Insertable<fl_member_info>(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<fl_member_info>(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();
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改cps对象
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model"></param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_cps_member model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改拼多多订单
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">拼多多订单对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_pinduoduo model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改唯品会订单
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">唯品会订单对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_weipinhui model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改快手订单
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">快手订单对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_kuaishou model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改京东订单
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">京东订单对象</param>
|
||
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<fl_query_ratio_hist>("select * from fl_query_ratio_hist where cpstype = @cpstype and db_orderid = @db_orderid", new { cpstype = cpsTyp, db_orderid = id });
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改抖音订单
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">抖音订单对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_douyin model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改苏宁订单
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">抖音订单对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_suning model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改阿里订单
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">阿里订单对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_order_alimama model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改分出比例
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">分出比例对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_ratio_info model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改配置
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">配置对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_dictionary_item model)
|
||
{
|
||
model = session.Saveable(model).ExecuteReturnEntity();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 记录用户基础记录(商品查询次数)
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="uid">用户id</param>
|
||
public static void UpdateRecord(this SqlSugarClient session, long uid)
|
||
{
|
||
var key = "fl_statistics_record_key";
|
||
var list = ApiClient.Cache.Get<List<fl_statistics_record>>(key);
|
||
if (list == null)
|
||
{
|
||
list = session.Find<fl_statistics_record>("select * from fl_statistics_record");
|
||
if (list == null) list = new List<fl_statistics_record>();
|
||
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 });
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询用户基础记录
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="uid">用户id</param>
|
||
/// <returns></returns>
|
||
public static fl_statistics_record FindStatisticsRecord(this SqlSugarClient session, long uid)
|
||
{
|
||
return session.FindSingle<fl_statistics_record>("select * from fl_statistics_record where uid = @uid", new { uid = uid });
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询历史查询比例
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="cpstype">平台类型</param>
|
||
/// <param name="db_orderid">订单id</param>
|
||
/// <returns></returns>
|
||
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<fl_query_ratio_hist>("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<Compute>(queryRatioHist.compute_config);
|
||
}
|
||
#endregion
|
||
return compute;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 通过阿里商品id获取已经创建的淘礼金
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="itemid">商品id</param>
|
||
public static fl_alimama_tlj_get_record FindTljByItemid(this SqlSugarClient session, string itemid)
|
||
{
|
||
var tlj = session.FindSingle<fl_alimama_tlj_get_record>("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<fl_alimama_tlj_get_record>(tlj).ExecuteCommand();
|
||
return null;
|
||
}
|
||
return tlj;
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 添加/修改阿里淘礼金记录
|
||
/// </summary>
|
||
/// <param name="session"></param>
|
||
/// <param name="model">阿里淘礼金记录对象</param>
|
||
public static void SaveOrUpdate(this SqlSugarClient session, fl_alimama_tlj_get_record model)
|
||
{
|
||
model = session.Saveable<fl_alimama_tlj_get_record>(model).ExecuteReturnEntity();
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 积分分配类
|
||
/// </summary>
|
||
public class ItemPoint
|
||
{
|
||
/// <summary>
|
||
/// 类型
|
||
/// </summary>
|
||
public CpsType Type { get; set; }
|
||
|
||
/// <summary>
|
||
/// 总佣金
|
||
/// </summary>
|
||
public double Commission { get; set; }
|
||
|
||
/// <summary>
|
||
/// 总积分
|
||
/// </summary>
|
||
public double SumPoint
|
||
{
|
||
get { return (double)((decimal)UserPoint + (decimal)AwardOne + (decimal)AwardTwo + (decimal)AwardThree + (decimal)AwardCreate); }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 用户积分
|
||
/// </summary>
|
||
public double UserPoint { get; set; }
|
||
|
||
/// <summary>
|
||
/// 一级提成
|
||
/// </summary>
|
||
public double AwardOne { get; set; }
|
||
|
||
/// <summary>
|
||
/// 二级提成
|
||
/// </summary>
|
||
public double AwardTwo { get; set; }
|
||
|
||
/// <summary>
|
||
/// 三级提成
|
||
/// </summary>
|
||
public double AwardThree { get; set; }
|
||
|
||
/// <summary>
|
||
/// 创建者提成
|
||
/// </summary>
|
||
public double AwardCreate { get; set; }
|
||
|
||
}
|