2305 lines
162 KiB
C#
2305 lines
162 KiB
C#
using Api.Framework;
|
||
using Api.Framework.Enums;
|
||
using Api.Framework.Events;
|
||
using Api.Framework.Model;
|
||
using Api.Framework.SDK;
|
||
using Api.Framework.Tools;
|
||
using Chat.Framework;
|
||
using Chat.Framework.WXSdk.Events;
|
||
using Chat.Framework.WXSdk.Implement;
|
||
using Chat.Framework.WXSdk.IPAD;
|
||
using CsharpHttpHelper;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Concurrent;
|
||
using System.Collections.Generic;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using UI.Framework.Tools;
|
||
using UserFission.Entitys;
|
||
using UserFission.Properties;
|
||
using System.Text;
|
||
using Api.Framework.Utils;
|
||
|
||
namespace UserFission
|
||
{
|
||
|
||
public class Class1 : Plugin
|
||
{
|
||
public Class1()
|
||
{
|
||
this.Logo = Resources.用户分裂;
|
||
this.Name = Resources.PluginName;
|
||
this.Note = Resources.PluginNote;
|
||
}
|
||
|
||
#region 自定义变量
|
||
public static Config Config;
|
||
public static PickBox pick;
|
||
private MainForm mainForm = null;
|
||
public static Queue<long> queue = new Queue<long>();//新加好友审核队列
|
||
public static Queue<string> group_queue = new Queue<string>();//新加入群审核队列
|
||
#endregion
|
||
|
||
public CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
|
||
|
||
public override void Start()
|
||
{
|
||
try
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
#region 判断表是否存在,不存在创建表
|
||
if (!session.TableExist<fl_plugin_userfission_applyfriend_info>())
|
||
{
|
||
session.CreateTable<fl_plugin_userfission_applyfriend_info>();
|
||
session.AddIndex<fl_plugin_userfission_applyfriend_info>("robot_name", "new_friend_wxid");//增加索引.以后数据多了.查询速度会比较快
|
||
session.AddUnique<fl_plugin_userfission_applyfriend_info>("robot_name", "new_friend_wxid");//增加唯一约束
|
||
}
|
||
if (!session.TableExist<fl_plugin_userfission_invite_record>())
|
||
{
|
||
session.CreateTable<fl_plugin_userfission_invite_record>();
|
||
}
|
||
if (!session.TableExist<fl_plugin_userfission_user_invitation_code>()) session.CreateTable<fl_plugin_userfission_user_invitation_code>();
|
||
//if (!session.TableExist<fl_plugin_userfission_leadgroup_info>())
|
||
//{
|
||
// session.CreateTable<fl_plugin_userfission_leadgroup_info>();
|
||
// session.AddIndex<fl_plugin_userfission_leadgroup_info>("rid");//增加索引.
|
||
// session.AddUnique<fl_plugin_userfission_leadgroup_info>("rid");//增加唯一约束.
|
||
//}
|
||
if (!session.TableExist<fl_plugin_userfission_automatic_approval_setting>())
|
||
{
|
||
session.CreateTable<fl_plugin_userfission_automatic_approval_setting>();
|
||
session.AddIndex<fl_plugin_userfission_automatic_approval_setting>("rid");//增加索引.
|
||
session.AddUnique<fl_plugin_userfission_automatic_approval_setting>("rid");//增加唯一约束.
|
||
}
|
||
if (!session.TableExist<fl_plugin_userfission_superior_reward>())
|
||
{
|
||
session.CreateTable<fl_plugin_userfission_superior_reward>();
|
||
session.AddUnique<fl_plugin_userfission_superior_reward>("subordinate_order_totle");//增加唯一约束.
|
||
}
|
||
if (!session.TableExist<fl_plugin_userfission_fan_notify>())
|
||
{
|
||
session.CreateTable<fl_plugin_userfission_fan_notify>();
|
||
session.AddUnique<fl_plugin_userfission_fan_notify>("mid");//增加唯一约束.
|
||
}
|
||
|
||
if (!session.TableExist<fl_plugin_userfission_extra>())
|
||
{
|
||
session.CreateTable<fl_plugin_userfission_extra>();
|
||
session.AddUnique<fl_plugin_userfission_extra>("userid");//增加唯一约束.
|
||
}
|
||
|
||
#endregion
|
||
|
||
//创建配置文件
|
||
Config = this.ReadConfig<Config>();
|
||
|
||
if ((Config.NewUserTipStartTime == DateTime.MinValue) && (!string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip_UnFan) || !string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip_Coupon) || !string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip_UnCoupon) || !string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip)))
|
||
{
|
||
Config.NewUserTipStartTime = DateTime.Now;
|
||
}
|
||
|
||
Tools.GetBaseIco();
|
||
pick = new PickBox();
|
||
SDK.ReciveIMEvent += SDK_ReciveIMEvent;
|
||
SDK.WXApplyFriendEvent += SDK_WXApplyFriendEvent;
|
||
SDK.WXNewFriendEvent += SDK_WXNewFriendEvent;
|
||
SDK.OrderNoticeEvent += SDK_OrderNoticeEvent;
|
||
SDK.WXNewMemerEvent += SDK_WXNewMemerEvent;
|
||
SDK.SharedEvent += SDK_SharedEvent;
|
||
|
||
SDK.QQAddMeNeedAuthEvents += SDK_QQAddMeNeedAuthEvents;
|
||
SDK.QQNewFriendEvents += SDK_QQNewFriendEvents;
|
||
SDK.QQNewGroupMemberEvents += SDK_QQNewGroupMemberEvents;
|
||
SDK.QQAddToClusterNeedAuthEvents += SDK_QQAddToClusterNeedAuthEvents;
|
||
|
||
//启动软件后,刷新一次数据库数据,防止软件重启部分好友未添加
|
||
Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
Thread.Sleep(1000 * 60 * 4);
|
||
|
||
var friends = ApiClient.GetSession().Find<fl_plugin_userfission_applyfriend_info>("select * from fl_plugin_userfission_applyfriend_info where crt_time>@crt_time and state == '待审核'", new { crt_time = DateTime.Now.AddMinutes(-30).ToString("yyyy-MM-dd HH:mm:ss") }).ToList();
|
||
foreach (var item in friends) queue.Enqueue(item.id);
|
||
if (friends.Count > 0) ApplyWechatFriend();
|
||
}
|
||
catch (Exception)
|
||
{ }
|
||
}, cancellationTokenSource.Token);
|
||
|
||
Task.Run(() =>
|
||
{
|
||
do
|
||
{
|
||
Thread.Sleep(2 * 60 * 1000);
|
||
/// <summary>
|
||
/// 绑定群上下级的定时器
|
||
/// </summary>
|
||
BindGroupInvite();
|
||
} while (!cancellationTokenSource.IsCancellationRequested);
|
||
|
||
}, cancellationTokenSource.Token);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("Start = " + ex.Message);
|
||
}
|
||
}
|
||
|
||
public override void ShowForm()
|
||
{
|
||
try
|
||
{
|
||
if (mainForm == null || mainForm.IsDisposed)
|
||
{
|
||
mainForm = new MainForm();
|
||
mainForm.Show();
|
||
}
|
||
mainForm.TopMost = true;
|
||
mainForm.TopMost = false;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
public override void Stop()
|
||
{
|
||
try
|
||
{
|
||
if (mainForm != null)
|
||
{
|
||
mainForm.CloseForm();
|
||
mainForm = null;
|
||
}
|
||
cancellationTokenSource.Cancel();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
private static readonly object padlock = new object();
|
||
|
||
/// <summary>
|
||
/// 记录已经拉群处理的用户id
|
||
/// </summary>
|
||
private static List<long> userIdlist = new List<long>();
|
||
|
||
/// <summary>
|
||
/// 首单奖励
|
||
/// </summary>
|
||
private static List<long> sdjl = new List<long>();
|
||
|
||
/// <summary>
|
||
/// 订单通知
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void SDK_OrderNoticeEvent(object sender, OrderNoticeEvent e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Member != null)
|
||
{
|
||
var wx = ChatClient.WXClient.FirstOrDefault(f => f.Key == e.Member.robot_name).Value;
|
||
if (wx != null /*&& wx.WeixinType == WeixinType.Grpc微信*/ && wx.Status == Chat.Framework.WXSdk.WxStatus.在线)
|
||
{
|
||
//var ipad = wx as WXClientImpl_IPAD;
|
||
//if (ipad != null)
|
||
//{
|
||
//var price = 0d;
|
||
CpsType cpstype = CpsType.阿里妈妈;
|
||
long orderid = 0;
|
||
var systemOrderStatus = -1;
|
||
if (e.Order is fl_order_alimama)
|
||
{
|
||
var alimama = e.Order as fl_order_alimama;
|
||
systemOrderStatus = (int)alimama.db_status;
|
||
cpstype = CpsType.阿里妈妈;
|
||
orderid = alimama.id;
|
||
}
|
||
if (e.Order is fl_order_pinduoduo)
|
||
{
|
||
var pdd = e.Order as fl_order_pinduoduo;
|
||
systemOrderStatus = (int)pdd.db_status;
|
||
cpstype = CpsType.多多进宝;
|
||
orderid = pdd.id;
|
||
}
|
||
if (e.Order is fl_order_jingdong)
|
||
{
|
||
var jd = e.Order as fl_order_jingdong;
|
||
systemOrderStatus = (int)jd.db_status;
|
||
cpstype = CpsType.京东联盟;
|
||
orderid = jd.id;
|
||
}
|
||
if (e.Order is fl_order_douyin)
|
||
{
|
||
var dy = e.Order as fl_order_douyin;
|
||
systemOrderStatus = (int)dy.db_status;
|
||
cpstype = CpsType.抖音联盟;
|
||
orderid = dy.id;
|
||
}
|
||
if (e.Order is fl_order_suning)
|
||
{
|
||
var sn = e.Order as fl_order_suning;
|
||
systemOrderStatus = (int)sn.db_status;
|
||
cpstype = CpsType.苏宁易购;
|
||
orderid = sn.id;
|
||
}
|
||
|
||
#region 首单奖励 || 分红奖励
|
||
var t1 = Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
#region 新的
|
||
var isIpad = (wx.GetType() == typeof(WXClientImpl_IPAD));
|
||
var session = ApiClient.GetSession();
|
||
var memberinfo = e.Member;
|
||
|
||
#region 首单付款额外提示语
|
||
if (e.Customer == null && Config.Extra_FirstPay_Tip_Switch == SwitchType.开启 && systemOrderStatus == 1005 && memberinfo.bind_order == 1)
|
||
{
|
||
try
|
||
{
|
||
var robotInfo = session.FindRobotInfo(memberinfo.robot_name, memberinfo.robot_type);
|
||
if (robotInfo == null) throw new Exception("找不到对应的机器人账号,首付额外提示操作终止");
|
||
ApiClient.SendMessage(robotInfo, memberinfo.username, Config.Extra_FirstPay_Tip);
|
||
}
|
||
catch (Exception ex)
|
||
{ this.OnLog(ex.Message); }
|
||
}
|
||
|
||
var strb = new StringBuilder();
|
||
strb.AppendLine($"e.Customer == null = {(e.Customer == null ? string.Empty : $"{e.Customer.id}:{e.Customer.usernick}({e.Customer.username})")}");
|
||
strb.AppendLine($"e.Member = {e.Member.id}:{e.Member.usernick}({e.Member.username})");
|
||
strb.AppendLine($"e.Customer == null = {e.Customer == null}");
|
||
strb.AppendLine($"Config.ExtraBonus_SwitchType == SwitchType.开启 = {Config.ExtraBonus_SwitchType == SwitchType.开启}");
|
||
strb.AppendLine($"memberinfo.crt_time.AddHours(Config.ExtraBonus_ValidDay) = {memberinfo.crt_time.AddHours(Config.ExtraBonus_ValidDay)}");
|
||
strb.AppendLine($"DateTime.Now = {DateTime.Now}");
|
||
strb.AppendLine($"memberinfo.crt_time.AddHours(Config.ExtraBonus_ValidDay) >= DateTime.Now = {memberinfo.crt_time.AddHours(Config.ExtraBonus_ValidDay) >= DateTime.Now}");
|
||
strb.AppendLine($"systemOrderStatus = " + systemOrderStatus);
|
||
strb.AppendLine($"systemOrderStatus == 1005 = {systemOrderStatus == 1005}");
|
||
strb.AppendLine($"memberinfo.bind_order = {memberinfo.bind_order}");
|
||
strb.AppendLine($"memberinfo.bind_order == 1 = {memberinfo.bind_order == 1}");
|
||
strb.AppendLine($"memberinfo.inviter_id = {memberinfo.inviter_id}");
|
||
strb.AppendLine($"memberinfo.inviter_id != 0 = {memberinfo.inviter_id != 0}");
|
||
LogHelper.GetSingleObj().Debug("....", $"{strb.ToString()}");
|
||
|
||
if (e.Customer == null && Config.ExtraBonus_SwitchType == SwitchType.开启 && memberinfo.crt_time.AddHours(Config.ExtraBonus_ValidDay) >= DateTime.Now && systemOrderStatus == 1005 && memberinfo.bind_order == 1 && memberinfo.inviter_id != 0)
|
||
{
|
||
try
|
||
{
|
||
var extra = new fl_plugin_userfission_extra()
|
||
{
|
||
point = Config.ExtraBonus,
|
||
userid = memberinfo.id
|
||
};
|
||
session.Insertable(extra).ExecuteCommand();
|
||
}
|
||
catch (Exception ex)
|
||
{ }
|
||
}
|
||
|
||
#region 上级额外奖励xxx
|
||
////以下为冗余代码,为了实现功能
|
||
//if (e.Customer == null && systemOrderStatus == 1005)
|
||
//{
|
||
// var extraTmp = session.Queryable<fl_plugin_userfission_extra>().First(f => f.orderid == orderid && f.cpstype == cpstype);
|
||
// if (extraTmp != null)
|
||
// {
|
||
// try
|
||
// {
|
||
// var robotInfo = session.FindRobotInfo(memberinfo.robot_name, memberinfo.robot_type);
|
||
// if (robotInfo == null) throw new Exception("找不到对应的机器人账号,下级首付款奖励操作终止");
|
||
|
||
// var inviter = session.FindMemberInfoById(memberinfo.inviter_id);
|
||
// if (inviter != null)
|
||
// {
|
||
// var _bonus = extraTmp.point;//奖励金额
|
||
|
||
// if (isIpad && inviter.robot_type == ChatType.微信 && (Config.ExtraBonus_RechargeType == RechargeType.发送红包 || Config.ExtraBonus_RechargeType == RechargeType.微信转账))
|
||
// {
|
||
// var passinfo = session.FindWeixinpassword(session.FindRobotInfo(wx.WeixinHao, inviter.robot_type).id);//获取微信支付信息
|
||
// if (passinfo != null && !string.IsNullOrEmpty(passinfo.password))
|
||
// {
|
||
// var flag = wx.SendPay(inviter.username, Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonus.ToString()), (int)((decimal)_bonus * 100m), passinfo.password, 1, (Config.ExtraBonus_RechargeType == RechargeType.发送红包 ? PayType.红包 : PayType.转账), passinfo.GetBank());
|
||
// if (!string.IsNullOrEmpty(flag))
|
||
// {
|
||
// this.OnLog("新人首付款上级奖励失败:" + flag + ",已添加积分到用户余额!");//发送红包不成功,将积分增加余额
|
||
// inviter = session.ChangePoint(PointType.其他奖励, _bonus, inviter.id, $"新人{inviter.usernick}-{inviter.username},首新人首付款上级积分{_bonus}【微信红包操作失败】");
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// this.OnLog("新人首付款上级奖励失败:未设置支付密码,已添加积分到用户余额!");
|
||
// inviter = session.ChangePoint(PointType.其他奖励, _bonus, inviter.id, $"新人{inviter.usernick}-{inviter.username},首付款上级积分{_bonus}【微信红包操作失败,未设置支付密码】");
|
||
// }
|
||
// ApiClient.SendMessage(robotInfo, inviter.username, Config.ExtraBonusCompletedTip.Replace("[奖励金额]", _bonus.ToString()).Replace("[剩余积分]", inviter.cur_point.ToString()));
|
||
// }
|
||
// else if ((inviter.robot_type == ChatType.微信 || inviter.robot_type == ChatType.企业微信) && Config.ExtraBonus_RechargeType == RechargeType.商户付款)
|
||
// {
|
||
// if (_bonus >= 0.3)
|
||
// {
|
||
// var ispaid = false;
|
||
// object appinfo = null;
|
||
// string url = ApiClient.SendWechatPay(new { robot_name = robotInfo.name, robot_nick = robotInfo.nick, username = inviter.username, usernick = inviter.usernick }, Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonus.ToString()), _bonus, out ispaid, out appinfo);
|
||
// if (!string.IsNullOrEmpty(url))
|
||
// {
|
||
// inviter = session.ChangePoint(PointType.其他奖励, _bonus, inviter.id, $"新人首付款上级奖励金额");
|
||
// Thread.Sleep(20);
|
||
// inviter = session.ChangePoint(PointType.提现扣除, _bonus, inviter.id, $"新人首付款上级金额【商户付款成功】 商户链接:{url}");
|
||
|
||
// var mess = string.Empty;
|
||
// if (ispaid)
|
||
// mess = Config.ExtraCommercialEftTip.Replace("[奖励金额]", _bonus.ToString());
|
||
// else
|
||
// {
|
||
// if (Config.ShangHu_MiNiApp == SwitchType.开启 && appinfo != null)
|
||
// mess = Util.GetMiNiAppXml(appinfo, robotInfo.type);
|
||
// if (string.IsNullOrWhiteSpace(mess))
|
||
// mess = Config.ExtraBonusCommercialPayTip.Replace("[领取地址]", url/*ApiClient.ShortURL(url).Result*/).Replace("[奖励金额]", _bonus.ToString());
|
||
// }
|
||
// ApiClient.SendMessage(robotInfo, inviter.username, mess);
|
||
// this.OnLog("商户付款信息 = " + mess);
|
||
// }
|
||
// else
|
||
// {
|
||
// this.OnLog("新人首付款上级商户付款失败:获取不到商户付款地址,已添加积分到用户余额!");
|
||
// inviter = session.ChangePoint(PointType.其他奖励, _bonus, inviter.id, $"新人{inviter.usernick}-{inviter.username},首付款上级奖励积分{_bonus}【商户付款操作失败,请求商户链接失败】");
|
||
// ApiClient.SendMessage(robotInfo, inviter.username, Config.ExtraBonusCompletedTip.Replace("[奖励金额]", _bonus.ToString()).Replace("[剩余积分]", inviter.cur_point.ToString()));
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// this.OnLog("新人首付款上级商户付款失败:奖励积分小于0.3,已添加积分到用户余额!");
|
||
// inviter = session.ChangePoint(PointType.其他奖励, _bonus, inviter.id, $"新人{inviter.usernick}-{inviter.username},首付款上级奖励积分{_bonus}【商户付款操作失败,积分小于0.3】");
|
||
// ApiClient.SendMessage(robotInfo, inviter.username, Config.ExtraBonusCompletedTip.Replace("[奖励金额]", _bonus.ToString()).Replace("[剩余积分]", inviter.cur_point.ToString()));
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// inviter = session.ChangePoint(PointType.其他奖励, _bonus, inviter.id, $"新人{inviter.usernick}-{inviter.username},首付款上级奖励积分{_bonus}【增加积分操作】");
|
||
// ApiClient.SendMessage(robotInfo, inviter.username, Config.ExtraBonusCompletedTip.Replace("[奖励金额]", _bonus.ToString()).Replace("[剩余积分]", inviter.cur_point.ToString()));
|
||
// }
|
||
// }
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// this.OnLog("额外奖励:" + ex.Message);
|
||
// }
|
||
// }
|
||
//}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 用户首单奖励
|
||
if (e.Customer == null && e.IsRewards)
|
||
{
|
||
try
|
||
{
|
||
double _bonus = 0;
|
||
|
||
var robotInfo = session.FindRobotInfo(memberinfo.robot_name, memberinfo.robot_type);
|
||
if (robotInfo == null) throw new Exception("找不到对应的机器人账号,首单奖励操作终止");
|
||
|
||
if (Config.FirstOrder_Sum2 < Config.FirstOrder_Sum1) throw new Exception("新用户首单奖励积分设置数据异常,最大奖励值应大于最小值");
|
||
|
||
_bonus = Math.Round((
|
||
new Random().Next(
|
||
int.Parse(Math.Round(Config.FirstOrder_Sum1 * 100, 2).ToString()),
|
||
int.Parse(Math.Round((Config.FirstOrder_Sum2 + 0.01) * 100, 2).ToString())
|
||
)) / 100d, 2);
|
||
|
||
if (isIpad && memberinfo.robot_type == ChatType.微信 && (Config.FirstOrder_RechargeType == RechargeType.发送红包 || Config.FirstOrder_RechargeType == RechargeType.微信转账))
|
||
{
|
||
var passinfo = session.FindWeixinpassword(session.FindRobotInfo(wx.WeixinHao, memberinfo.robot_type).id);//获取微信支付信息
|
||
if (passinfo != null && !string.IsNullOrEmpty(passinfo.password))
|
||
{
|
||
var flag = wx.SendPay(memberinfo.username, Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonus.ToString()), (int)((decimal)_bonus * 100m), passinfo.password, 1, (Config.FirstOrder_RechargeType == RechargeType.发送红包 ? PayType.红包 : PayType.转账), passinfo.GetBank());
|
||
if (!string.IsNullOrEmpty(flag))
|
||
{
|
||
this.OnLog($"新人首单奖励失败:" + flag + ",已添加积分到用户余额!");//发送红包不成功,将积分增加余额
|
||
memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, memberinfo.id, $"新人{memberinfo.usernick}-{memberinfo.username},首单奖励积分{_bonus}【微信红包操作失败】");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog($"新人首单奖励失败:未设置支付密码,已添加积分到用户余额!");
|
||
memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, memberinfo.id, $"新人{memberinfo.usernick}-{memberinfo.username},首单奖励积分{_bonus}【微信红包操作失败,未设置支付密码】");
|
||
}
|
||
ApiClient.SendMessage(robotInfo, memberinfo.username, Class1.Config.NewUserFirstOrderCompletedTip.Replace("[首单奖励金额]", _bonus.ToString()).Replace("[剩余积分]", memberinfo.cur_point.ToString()));
|
||
}
|
||
else if ((memberinfo.robot_type == ChatType.微信 || memberinfo.robot_type == ChatType.企业微信) && Config.FirstOrder_RechargeType == RechargeType.商户付款)
|
||
{
|
||
if (_bonus >= 0.3)
|
||
{
|
||
var ispaid = false;
|
||
object appinfo = null;
|
||
string url = ApiClient.SendWechatPay(new { robot_name = robotInfo.name, robot_nick = robotInfo.nick, username = memberinfo.username, usernick = memberinfo.usernick }, Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonus.ToString()), _bonus, out ispaid, out appinfo);
|
||
if (!string.IsNullOrEmpty(url))
|
||
{
|
||
memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, memberinfo.id, $"首单奖励金额");
|
||
Thread.Sleep(20);
|
||
memberinfo = session.ChangePoint(PointType.提现扣除, _bonus, memberinfo.id, $"首单金额【商户付款成功】 商户链接:{url}");
|
||
|
||
var mess = string.Empty;
|
||
if (ispaid)
|
||
mess = Config.FirstOrder_CommercialEftTip.Replace("[首单奖励金额]", _bonus.ToString());
|
||
else
|
||
{
|
||
if (Config.ShangHu_MiNiApp == SwitchType.开启 && appinfo != null)
|
||
mess = Util.GetMiNiAppXml(appinfo, robotInfo.type);
|
||
if (string.IsNullOrWhiteSpace(mess))
|
||
mess = Config.FirstOrder_CommercialPayTip.Replace("[领取地址]", url/*ApiClient.ShortURL(url).Result*/).Replace("[首单奖励金额]", _bonus.ToString());
|
||
}
|
||
ApiClient.SendMessage(robotInfo, memberinfo.username, mess);
|
||
this.OnLog("商户付款信息 = " + mess);
|
||
}
|
||
else
|
||
{
|
||
this.OnLog($"新人首单商户付款失败:获取不到商户付款地址,已添加积分到用户余额!");
|
||
memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, memberinfo.id, $"新人{memberinfo.usernick}-{memberinfo.username},首单奖励积分{_bonus}【商户付款操作失败,请求商户链接失败】");
|
||
ApiClient.SendMessage(robotInfo, memberinfo.username, Class1.Config.NewUserFirstOrderCompletedTip.Replace("[首单奖励金额]", _bonus.ToString()).Replace("[剩余积分]", memberinfo.cur_point.ToString()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog($"新人首单商户付款失败:奖励积分小于0.3,已添加积分到用户余额!");
|
||
memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, memberinfo.id, $"新人{memberinfo.usernick}-{memberinfo.username},首单奖励积分{_bonus}【商户付款操作失败,积分小于0.3】");
|
||
ApiClient.SendMessage(robotInfo, memberinfo.username, Config.NewUserFirstOrderCompletedTip.Replace("[首单奖励金额]", _bonus.ToString()).Replace("[剩余积分]", memberinfo.cur_point.ToString()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, memberinfo.id, $"新人{memberinfo.usernick}-{memberinfo.username},首单奖励积分{_bonus}【增加积分操作】");
|
||
ApiClient.SendMessage(robotInfo, memberinfo.username, Config.NewUserFirstOrderCompletedTip.Replace("[首单奖励金额]", _bonus.ToString()).Replace("[剩余积分]", memberinfo.cur_point.ToString()));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog($"{ex.Message} _ {ex.StackTrace}");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 下级用户订单结算,统计下级用户订单是否满足条件(付款金额/订单数量),满足奖励上级(分红)
|
||
try
|
||
{
|
||
if (e.Customer == null && systemOrderStatus == 1002)
|
||
{
|
||
var rewards = Tools.FindRewards();
|
||
var reward = rewards.FirstOrDefault(f => f.subordinate_order_totle == e.Member.finish_order);
|
||
if (reward != null && memberinfo.inviter_id != 0 && memberinfo.inviter_id != memberinfo.id)
|
||
{
|
||
var presenter_memberinfo = session.FindMemberInfoById(memberinfo.inviter_id);
|
||
if (presenter_memberinfo == null) throw new Exception("找不到对应的上级信息,分红奖励操作终止");
|
||
var robotInfo = session.FindRobots().FirstOrDefault(f => f.name == presenter_memberinfo.robot_name && f.type == presenter_memberinfo.robot_type);
|
||
if (robotInfo == null) throw new Exception("找不到对应的机器人账号,分红奖励操作终止");
|
||
|
||
var _bonus = reward.superior_point_reward;
|
||
if (isIpad && robotInfo.type == ChatType.微信 && (Config.Superior_DividendType == RechargeType.发送红包 || Config.Superior_DividendType == RechargeType.微信转账))
|
||
{
|
||
var passinfo = session.FindWeixinpassword(session.FindRobotInfo(robotInfo.name, robotInfo.type).id);//获取微信支付信息
|
||
if (passinfo != null && !string.IsNullOrEmpty(passinfo.password))
|
||
{
|
||
var flag = wx.SendPay(presenter_memberinfo.username, Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonus.ToString()), (int)((decimal)_bonus * 100m), passinfo.password, 1, (Config.Superior_DividendType == RechargeType.发送红包 ? PayType.红包 : PayType.转账), passinfo.GetBank());
|
||
if (!string.IsNullOrEmpty(flag))
|
||
{
|
||
this.OnLog("分红奖励失败:" + flag + ",已添加积分到用户余额!");//发送红包不成功,将积分增加余额
|
||
presenter_memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, presenter_memberinfo.id, $"分红奖励积分{_bonus}【微信红包操作失败】");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("分红奖励失败:未设置支付密码,已添加积分到用户余额!");
|
||
presenter_memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, presenter_memberinfo.id, $"分红奖励积分{_bonus}【微信红包操作失败,未设置支付密码】");
|
||
}
|
||
ApiClient.SendMessage(robotInfo, presenter_memberinfo.username, Config.SuperiorDividendPayTip.Replace("[下级有效订单数]", reward.subordinate_order_totle.ToString()).Replace("[分红奖励金额]", _bonus.ToString()).Replace("[下级昵称]", memberinfo.realnick).Replace("[剩余积分]", presenter_memberinfo.cur_point.ToString()));
|
||
}
|
||
else if ((presenter_memberinfo.robot_type == ChatType.微信 || presenter_memberinfo.robot_type == ChatType.企业微信) && Config.Superior_DividendType == RechargeType.商户付款)
|
||
{
|
||
if (_bonus >= 0.3)
|
||
{
|
||
var ispaid = false;
|
||
object appinfo = null;
|
||
string url = ApiClient.SendWechatPay(new { robot_name = robotInfo.name, robot_nick = robotInfo.nick, username = presenter_memberinfo.username, usernick = presenter_memberinfo.usernick }, Class1.Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonus.ToString()), _bonus, out ispaid, out appinfo);
|
||
if (!string.IsNullOrEmpty(url))
|
||
{
|
||
presenter_memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, presenter_memberinfo.id, $"分红奖励积分{_bonus}");
|
||
Thread.Sleep(20);
|
||
presenter_memberinfo = session.ChangePoint(PointType.提现扣除, _bonus, presenter_memberinfo.id, $"分红奖励【商户付款成功】 商户链接:{url}");
|
||
|
||
var _mess = string.Empty;
|
||
if (ispaid)
|
||
_mess = Config.SuperiorDividendCommercialEftTip.Replace("[下级有效订单数]", reward.subordinate_order_totle.ToString()).Replace("[分红奖励金额]", _bonus.ToString()).Replace("[下级昵称]", memberinfo.realnick);
|
||
else
|
||
{
|
||
if (Config.ShangHu_MiNiApp == SwitchType.开启 && appinfo != null)
|
||
_mess = Util.GetMiNiAppXml(appinfo, robotInfo.type);
|
||
if (string.IsNullOrWhiteSpace(_mess))
|
||
_mess = Config.SuperiorDividendCommercialPayTip.Replace("[下级有效订单数]", reward.subordinate_order_totle.ToString()).Replace("[领取地址]", url).Replace("[分红奖励金额]", _bonus.ToString()).Replace("[下级昵称]", memberinfo.realnick);
|
||
}
|
||
ApiClient.SendMessage(robotInfo, presenter_memberinfo.username, _mess);
|
||
this.OnLog("商户付款信息= " + _mess);
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("分红奖励商户付款失败:获取不到商户付款地址,已添加积分到用户余额!");
|
||
presenter_memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, presenter_memberinfo.id, $"分红奖励积分{_bonus}【商户付款操作失败,请求商户链接失败】");
|
||
ApiClient.SendMessage(robotInfo, presenter_memberinfo.username, Config.SuperiorDividendPayTip.Replace("[下级有效订单数]", reward.subordinate_order_totle.ToString()).Replace("[下级昵称]", memberinfo.realnick).Replace("[分红奖励金额]", _bonus.ToString()).Replace("[剩余积分]", presenter_memberinfo.cur_point.ToString()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("分红奖励商户付款失败:奖励积分小于0.3,已添加积分到用户余额!");
|
||
presenter_memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, presenter_memberinfo.id, $"分红奖励积分{_bonus}【商户付款操作失败,积分小于0.3】");
|
||
ApiClient.SendMessage(robotInfo, presenter_memberinfo.username, Config.SuperiorDividendPayTip.Replace("[下级有效订单数]", reward.subordinate_order_totle.ToString()).Replace("[下级昵称]", memberinfo.realnick).Replace("[分红奖励金额]", _bonus.ToString()).Replace("[剩余积分]", presenter_memberinfo.cur_point.ToString()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
presenter_memberinfo = session.ChangePoint(PointType.其他奖励, _bonus, presenter_memberinfo.id, $"分红奖励积分{_bonus}【增加积分操作】");
|
||
ApiClient.SendMessage(robotInfo, presenter_memberinfo.username, Config.SuperiorDividendPayTip.Replace("[下级有效订单数]", reward.subordinate_order_totle.ToString()).Replace("[下级昵称]", memberinfo.realnick).Replace("[分红奖励金额]", _bonus.ToString()).Replace("[剩余积分]", presenter_memberinfo.cur_point.ToString()));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog($"推荐者分红奖励异常:{ex.Message} - {ex.StackTrace}");
|
||
}
|
||
#endregion
|
||
|
||
#region 奖励开关开启,并且为新人完成首单奖励,并且用户有完成订单记录(推荐者奖励)
|
||
if (e.Customer != null && e.IsRewards)
|
||
{
|
||
var inviter = e.Member;
|
||
if (inviter == null) throw new Exception("上级奖励错误:上级用户数据不存在");
|
||
|
||
var member = e.Customer;
|
||
|
||
if (Config.SuperiorSum2 < Config.SuperiorSum1) throw new Exception("上级奖励积分设置数据异常,最大奖励值应大于最小值");
|
||
var remark = string.Empty;
|
||
try
|
||
{
|
||
var robotInfo = session.FindRobotInfo(inviter.robot_name, inviter.robot_type);
|
||
if (robotInfo == null) throw new Exception("找不到对应的机器人账号,上级奖励操作终止");
|
||
|
||
if (IsSuperiorReward(robotInfo))
|
||
{
|
||
var _bonusSuperior = 0d;
|
||
|
||
var extra = session.FindSingle<fl_plugin_userfission_extra>("select * from fl_plugin_userfission_extra where userid = @userid", new { userid = e.Customer.id });
|
||
if (extra != null)//按默认的奖励执行
|
||
{
|
||
_bonusSuperior = extra.point;
|
||
remark = "额外奖励";
|
||
}
|
||
else
|
||
_bonusSuperior = Math.Round((
|
||
new Random().Next(
|
||
int.Parse(Math.Round(Config.SuperiorSum1 * 100, 2).ToString()),
|
||
int.Parse(Math.Round((Config.SuperiorSum2 + 0.01) * 100, 2).ToString())
|
||
)) / 100d, 2);
|
||
|
||
if (isIpad && inviter.robot_type == ChatType.微信 && (Config.Superior_RechargeType == RechargeType.发送红包 || Config.Superior_RechargeType == RechargeType.微信转账))
|
||
{
|
||
var passinfo = session.FindWeixinpassword(session.FindRobotInfo(wx.WeixinHao, ChatType.微信).id);//获取微信支付信息
|
||
if (passinfo != null && !string.IsNullOrEmpty(passinfo.password))
|
||
{
|
||
var flag = wx.SendPay(inviter.username, Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonusSuperior.ToString()), (int)((decimal)_bonusSuperior * 100m), passinfo.password, 1, (Config.Superior_RechargeType == RechargeType.发送红包 ? PayType.红包 : PayType.转账), passinfo.GetBank());
|
||
if (!string.IsNullOrEmpty(flag))
|
||
{
|
||
this.OnLog($"推荐新人首单{remark}奖励失败:" + flag + ",已添加积分到用户余额!");//发送红包不成功,将积分增加余额
|
||
inviter = session.ChangePoint(PointType.其他奖励, _bonusSuperior, inviter.id, $"推荐新人{member.usernick}-{member.username},首单{remark}奖励积分{_bonusSuperior}【微信红包操作失败】");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog($"推荐新人首单{remark}奖励失败:未设置支付密码,已添加积分到用户余额!");
|
||
inviter = session.ChangePoint(PointType.其他奖励, _bonusSuperior, inviter.id, $"推荐新人{member.usernick}-{member.username},首单{remark}奖励积分{_bonusSuperior}【微信红包操作失败,未设置支付密码】");
|
||
}
|
||
ApiClient.SendMessage(robotInfo, inviter.username, Class1.Config.ImmediateReward_AddANewSubordinateTip.Replace("[使用者昵称]", member.realnick).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[剩余积分]", inviter.cur_point.ToString()));
|
||
}
|
||
else if ((inviter.robot_type == ChatType.微信 || inviter.robot_type == ChatType.企业微信) && Config.Superior_RechargeType == RechargeType.商户付款)
|
||
{
|
||
if (_bonusSuperior >= 0.3)
|
||
{
|
||
var ispaid = false;
|
||
object appinfo = null;
|
||
string url = ApiClient.SendWechatPay(new { robot_name = robotInfo.name, robot_nick = robotInfo.nick, username = inviter.username, usernick = inviter.usernick }, Class1.Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonusSuperior.ToString()), _bonusSuperior, out ispaid, out appinfo);
|
||
if (!string.IsNullOrEmpty(url))
|
||
{
|
||
inviter = session.ChangePoint(PointType.其他奖励, _bonusSuperior, inviter.id, $"推荐新人{member.usernick}-{member.username},首单{remark}奖励积分{_bonusSuperior}");
|
||
Thread.Sleep(20);
|
||
inviter = session.ChangePoint(PointType.提现扣除, _bonusSuperior, inviter.id, $"推荐新人{member.usernick}-{member.username},首单{remark}奖励积分{_bonusSuperior}【商户付款成功】 商户链接:{url}");
|
||
|
||
var mess = string.Empty;
|
||
if (ispaid)
|
||
mess = Config.SuperiorCommercialEftTip.Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[下级昵称]", e.Customer.realnick);
|
||
else
|
||
{
|
||
if (Config.ShangHu_MiNiApp == SwitchType.开启 && appinfo != null)
|
||
mess = Util.GetMiNiAppXml(appinfo, robotInfo.type);
|
||
if (string.IsNullOrWhiteSpace(mess))
|
||
mess = Config.SuperiorCommercialPayTip.Replace("[领取地址]", url/* ApiClient.ShortURL(url).Result*/).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[下级昵称]", e.Customer.realnick);
|
||
}
|
||
ApiClient.SendMessage(robotInfo, inviter.username, mess);
|
||
this.OnLog("商户付款信息 = " + mess);
|
||
}
|
||
else
|
||
{
|
||
this.OnLog($"推荐新人首单{remark}商户付款失败:获取不到商户付款地址,已添加积分到用户余额!");
|
||
inviter = session.ChangePoint(PointType.其他奖励, _bonusSuperior, inviter.id, $"推荐新人{member.usernick}-{member.username},首单{remark}奖励积分{_bonusSuperior}【商户付款操作失败,请求商户链接失败】");
|
||
ApiClient.SendMessage(robotInfo, inviter.username, Class1.Config.ImmediateReward_AddANewSubordinateTip.Replace("[使用者昵称]", member.realnick).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[剩余积分]", inviter.cur_point.ToString()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog($"推荐新人首单{remark}商户付款失败:奖励积分小于0.3,已添加积分到用户余额!");
|
||
inviter = session.ChangePoint(PointType.其他奖励, _bonusSuperior, inviter.id, $"推荐新人{member.usernick}-{member.username},首单{remark}奖励积分{_bonusSuperior}【商户付款操作失败,积分小于0.3】");
|
||
ApiClient.SendMessage(robotInfo, inviter.username, Class1.Config.ImmediateReward_AddANewSubordinateTip.Replace("[使用者昵称]", member.realnick).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[剩余积分]", inviter.cur_point.ToString()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
inviter = session.ChangePoint(PointType.其他奖励, _bonusSuperior, inviter.id, $"推荐新人{member.usernick}-{member.username},首单{remark}奖励积分{_bonusSuperior}【增加积分操作】");
|
||
ApiClient.SendMessage(robotInfo, inviter.username, Class1.Config.ImmediateReward_AddANewSubordinateTip.Replace("[使用者昵称]", member.realnick).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[剩余积分]", inviter.cur_point.ToString()));
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog($"{remark} - {ex.Message} - {ex.StackTrace}");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog($"用户首单奖励/新手完成首单奖励异常:{ex.Message} - {ex.StackTrace}");
|
||
}
|
||
});
|
||
#endregion
|
||
|
||
#region 完成订单将用户拉入群操作
|
||
var t2 = Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
if (Config.InvitedIntoGroupSwitch == SwitchType.关闭) return;
|
||
if (!Config.InvitegroupWay) return;
|
||
if (e.Member.finish_order < Config.FinishOrder_Rule) return;//没有满足设置的订单数
|
||
if (Config.InviteGroupInfo2 == null || Config.InviteGroupInfo2.Count == 0) return;
|
||
if (userIdlist.Contains(e.Member.id)) return;
|
||
var groupInfo = Config.InviteGroupInfo2.Where(f => f.Key == wx.WeixinHao && !f.Value.onoff && f.Value.groupInfos.Count != 0);
|
||
if (groupInfo == null) return;
|
||
//查询的对象不为空 并且 自动拉进群的操作非禁用 && f.WeixinType == WeixinType.Grpc微信
|
||
var wxBase = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == wx.WeixinHao && f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
||
if (wxBase == null) return;
|
||
var session = ApiClient.GetSession();
|
||
if (Config.InviteGroupInfo2.ContainsKey(wx.WeixinHao) && Config.InviteGroupInfo2[wx.WeixinHao].groupInfos.Count != 0)
|
||
{
|
||
var robotInfo = session.FindRobots().FirstOrDefault(f => f.name == e.Member.robot_name && f.type == e.Member.robot_type);
|
||
if (robotInfo == null) throw new Exception("找不到对应的机器人账号,拉群操作终止");
|
||
|
||
var groupIds = Config.InviteGroupInfo2[wx.WeixinHao].groupInfos;
|
||
foreach (var groupId in groupIds)
|
||
{
|
||
lock (padlock)
|
||
{
|
||
if (!userIdlist.Contains(e.Member.id))
|
||
userIdlist.Add(e.Member.id);
|
||
if (wx.GetType() == typeof(WXClientImpl_QYHOOK))
|
||
{
|
||
var result = session.FindSingle<fl_plugin_userfission_invite_record>("username = @username and groupid = @groupid", new { username = e.Member.username, groupid = groupId.Key });
|
||
if (result != null) return;
|
||
|
||
ApiClient.SendMessage(robotInfo, e.Member.username, Config.InvitedIntoGroupTip.Replace("[账号]", e.Member.username).Replace("[昵称]", e.Member.usernick));
|
||
wx.InviteIntoGroup(e.Member.username, groupId.Key);
|
||
}
|
||
else
|
||
{
|
||
var group = wx.GetContact(groupId.Key);
|
||
if (group == null) continue;
|
||
var result = session.FindSingle<fl_plugin_userfission_invite_record>("username = @username and groupid = @groupid", new { username = e.Member.username, groupid = group.UserName });
|
||
if (result != null) return;
|
||
//该用户不在群内 并且 没有给用户发送过邀请入群卡片
|
||
if (!group.ExtInfo.Contains(e.Member.username))
|
||
{
|
||
wx.InviteIntoGroup(e.Member.username, group.UserName);
|
||
ApiClient.SendMessage(robotInfo, e.Member.username, new VariateReplace().CommonReplace(Config.InvitedIntoGroupTip, e.Member, robotInfo));
|
||
}
|
||
}
|
||
var _result = new fl_plugin_userfission_invite_record() { groupid = groupId.Key, username = e.Member.username };
|
||
session.Insertable(_result).ExecuteCommand();
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog($"用户拉入群操作失败:{ex.Message} - {ex.StackTrace}");
|
||
}
|
||
});
|
||
#endregion
|
||
|
||
//}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("OrderNotice = " + ex.Message);
|
||
}
|
||
}
|
||
|
||
#region QQ
|
||
|
||
#region QQ - 申请添加我为好友,需要审核
|
||
private void SDK_QQAddMeNeedAuthEvents(object sender, Chat.Framework.QQSdk.Events.QQAddMeNeedAuthEvents e)
|
||
{
|
||
try
|
||
{
|
||
var friend = ApiClient.GetSession().FindSingle<fl_plugin_userfission_applyfriend_info>("new_friend_wxid = @new_friend_wxid and robot_name = @robot_name", new { new_friend_wxid = e.QQ.ToString(), robot_name = e.QQBase.QQ.ToString() });
|
||
if (friend != null && friend.state == "已接受") return;
|
||
|
||
if (friend == null)
|
||
{
|
||
friend = new fl_plugin_userfission_applyfriend_info()
|
||
{
|
||
state = "待审核",
|
||
crt_time = DateTime.Parse(e.CrtTime.ToString("yyyy-MM-dd HH:mm:ss")),
|
||
message = e.Message.Trim(),
|
||
robot_name = e.QQBase.QQ.ToString(),
|
||
user_nick = e.Nickname,
|
||
new_friend_nick = e.Nickname,
|
||
new_friend_wxid = e.QQ.ToString(),
|
||
old_friend_nick = string.Empty,
|
||
old_friend_wxid = string.Empty
|
||
};
|
||
friend.id = ApiClient.GetSession().Insertable<fl_plugin_userfission_applyfriend_info>(friend).ExecuteReturnIdentity();
|
||
}
|
||
|
||
if (Config.QQ_Accept == SwitchType.开启)
|
||
{
|
||
var id = ApiClient.GetSession().FindRobotInfo(e.QQBase.QQ.ToString(), ChatType.QQ).id;
|
||
var aas = ApiClient.GetSession().FindSingle<fl_plugin_userfission_automatic_approval_setting>("rid = @rid", new { rid = id });
|
||
if (aas != null && aas.onoff) return;
|
||
|
||
if (!queue.Contains(friend.id))
|
||
{
|
||
queue.Enqueue(friend.id);
|
||
QQApplyWechatFriend();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("新人申请处理 = " + ex.Message);
|
||
}
|
||
}
|
||
|
||
private List<string> qqwelcomeTip_Friends = new List<string>();
|
||
|
||
private bool IsApplyQQ = false;
|
||
private void QQApplyWechatFriend()
|
||
{
|
||
if (IsApplyQQ) return;
|
||
IsApplyQQ = true;
|
||
Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
//var session = ApiClient.GetSession();
|
||
do
|
||
{
|
||
var apply_id = queue.Dequeue();
|
||
var friend = ApiClient.GetSession().FindSingle<fl_plugin_userfission_applyfriend_info>("id = @id", new { id = apply_id });
|
||
if (friend != null)
|
||
{
|
||
Thread.Sleep(Config.QQ_Retardation * 1000);
|
||
if (friend != null && friend.state == "已接受") continue;
|
||
var client = ChatClient.QQClients.Values.FirstOrDefault(f => f.IsLogin && f.QQ.ToString() == friend.robot_name);
|
||
if (client != null)
|
||
{
|
||
client.AerifyAddMe(uint.Parse(friend.new_friend_wxid), 3);
|
||
friend.state = "已接受";
|
||
friend.allow_time = DateTime.Now;
|
||
ApiClient.GetSession().Saveable(friend).ExecuteReturnEntity();
|
||
|
||
var robot = ApiClient.GetSession().FindRobotInfo(friend.robot_name, ChatType.QQ, true);
|
||
if (robot == null) continue;
|
||
var member = ApiClient.GetSession().FindSingle<fl_member_info>("select * from fl_member_info where robot_type = @robot_type and username = @username", new { username = friend.new_friend_wxid, robot_type = ChatType.QQ });
|
||
if (member == null)
|
||
{
|
||
member = new fl_member_info() { crt_time = DateTime.Now, usernick = string.Empty, robot_name = friend.robot_name, robot_type = ChatType.QQ, username = friend.new_friend_wxid, alipay_name = string.Empty, alipay_num = string.Empty, remark = string.Empty };
|
||
var groups = ApiClient.GetSession().FindGroups();
|
||
if (groups.Count != 0)
|
||
member.group_id = groups[0].id;
|
||
ApiClient.GetSession().SaveOrUpdate(member);
|
||
}
|
||
ApiClient.SendMessage(robot, friend.new_friend_wxid, new VariateReplace().CommonReplace(Config.QQ_WelcomeTip, member));
|
||
}
|
||
}
|
||
} while (true);
|
||
}
|
||
catch (Exception)
|
||
{
|
||
}
|
||
finally
|
||
{
|
||
IsApplyQQ = false;
|
||
}
|
||
});
|
||
}
|
||
#endregion
|
||
|
||
#region QQ - 新增QQ好友
|
||
private void SDK_QQNewFriendEvents(object sender, Chat.Framework.QQSdk.Events.QQNewFriendEvents e)
|
||
{
|
||
try
|
||
{
|
||
//fl_plugin_userfission_applyfriend_info friend = null;
|
||
//var session = ApiClient.GetSession();
|
||
//var robot = session.FindRobotInfo(e.QQClient.QQ.ToString(), ChatType.QQ);
|
||
//if (robot != null)
|
||
//{
|
||
// Thread.Sleep(1100);
|
||
// lock (lock_newfriend)
|
||
// {
|
||
// if (!qqwelcomeTip_Friends.Contains(e.QQ.ToString()))
|
||
// {
|
||
// friend = session.Queryable<fl_plugin_userfission_applyfriend_info>().First(f => f.new_friend_wxid == e.QQ.ToString() && f.robot_name == e.QQClient.QQ.ToString());
|
||
|
||
// #region 将表fl_plugin_userfission_applyfriend_info中的请求状态改成 "已接受"
|
||
// if (friend != null && friend.state != "已接受")
|
||
// {
|
||
// friend.state = "已接受";
|
||
// session.Saveable(friend).ExecuteReturnEntity();
|
||
// }
|
||
// #endregion
|
||
|
||
// if (qqwelcomeTip_Friends.Count > 10000) qqwelcomeTip_Friends.Clear();
|
||
// qqwelcomeTip_Friends.Add(e.QQ.ToString());
|
||
|
||
// var member = session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username and robot_type = @robot_type", new { username = e.QQ.ToString(), robot_type = ChatType.QQ });
|
||
// if (member == null)
|
||
// {
|
||
// member = new fl_member_info() { crt_time = DateTime.Now, usernick = e.Nickname, robot_name = e.QQClient.QQ.ToString(), robot_type = ChatType.QQ, username = e.QQ.ToString(), alipay_name = string.Empty, alipay_num = string.Empty, remark = string.Empty };
|
||
// var groups = session.FindGroups();
|
||
// if (groups.Count != 0)
|
||
// member.group_id = groups[0].id;
|
||
// session.SaveOrUpdate(member);
|
||
// }
|
||
// ApiClient.SendMessage(robot, e.QQ.ToString(), Config.QQ_WelcomeTip).Wait();
|
||
// }
|
||
// }
|
||
//}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("NewMemer = " + ex.Message);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region QQ群添加新用户
|
||
private void SDK_QQAddToClusterNeedAuthEvents(object sender, Chat.Framework.QQSdk.Events.QQAddToClusterNeedAuthEvents e)
|
||
{
|
||
try
|
||
{
|
||
if (Config.QQ_AcceptGroupApplyForSwitch == SwitchType.开启)
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
var id = session.FindRobotInfo(e.QQBase.QQ.ToString(), ChatType.QQ).id;
|
||
var aas = session.FindSingle<fl_plugin_userfission_automatic_approval_setting>("rid = @rid", new { rid = id });
|
||
if (aas != null && aas.onoff) return;
|
||
|
||
if (!group_queue.Contains(e.ClusterId + "_" + e.QQ + "_" + e.QQBase.QQ))
|
||
{
|
||
group_queue.Enqueue(e.ClusterId + "_" + e.QQ + "_" + e.QQBase.QQ);
|
||
QQApplyWechatGroup();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(" " + ex.Message);
|
||
}
|
||
}
|
||
|
||
private bool IsApplyGroupQQ = false;
|
||
private void QQApplyWechatGroup()
|
||
{
|
||
if (IsApplyGroupQQ) return;
|
||
IsApplyGroupQQ = true;
|
||
Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
do
|
||
{
|
||
var value = group_queue.Dequeue();
|
||
var strs = value.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
|
||
if (strs.Length == 3)
|
||
{
|
||
Thread.Sleep(Config.QQ_RetardationAcceptGroup * 1000);
|
||
var client = ChatClient.QQClients.Values.FirstOrDefault(f => f.IsLogin && f.QQ.ToString() == strs[2]);
|
||
if (client != null)
|
||
{
|
||
client.AerifyAddGroup(uint.Parse(strs[0]), uint.Parse(strs[1]));
|
||
}
|
||
}
|
||
} while (true);
|
||
}
|
||
catch (Exception)
|
||
{ }
|
||
finally
|
||
{
|
||
IsApplyGroupQQ = false;
|
||
}
|
||
});
|
||
}
|
||
#endregion
|
||
|
||
#region QQ - 新成员进群
|
||
private void SDK_QQNewGroupMemberEvents(object sender, Chat.Framework.QQSdk.Events.QQNewGroupMemberEvents e)
|
||
{
|
||
try
|
||
{
|
||
if (!string.IsNullOrWhiteSpace(Config.QQ_GroupWelcomeTip))
|
||
{
|
||
e.QQBase.SendGroupMessage(e.GroupId, Config.QQ_GroupWelcomeTip.Replace("[群昵称]", e.GroupName).Replace("[昵称]", e.NewFriendNick).Replace("[账号]", e.NewFriendQQ.ToString()));
|
||
}
|
||
|
||
#region 用户是被用户邀请进群,绑定上级
|
||
if (e.InviteQQ != 0 && Config.QQInviteBindSwitch == SwitchType.开启)
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
var invite_member = session.FindSingle<fl_member_info>("select * from fl_member_info where robot_type = @robot_type and username = @username", new { username = e.InviteQQ, robot_type = ChatType.QQ });
|
||
if (invite_member == null)
|
||
{
|
||
invite_member = new fl_member_info() { crt_time = DateTime.Now, usernick = string.Empty, robot_name = e.QQBase.QQ.ToString(), robot_type = ChatType.QQ, username = e.InviteQQ.ToString(), alipay_name = string.Empty, alipay_num = string.Empty, remark = string.Empty };
|
||
var groups = session.FindGroups();
|
||
if (groups.Count != 0)
|
||
invite_member.group_id = groups[0].id;
|
||
session.SaveOrUpdate(invite_member);
|
||
}
|
||
var robot = session.FindRobots().FirstOrDefault(f => f.type == invite_member.robot_type && f.name == invite_member.robot_name);
|
||
if (robot == null) throw new Exception("上级用户对应的机器人数据异常");
|
||
|
||
var new_member = session.FindSingle<fl_member_info>("robot_type = @robot_type and username = @username", new { robot_type = ChatType.QQ, username = e.NewFriendQQ.ToString() });
|
||
if (new_member == null)
|
||
{
|
||
new_member = new fl_member_info() { crt_time = DateTime.Now, usernick = e.NewFriendNick, robot_name = e.QQBase.QQ.ToString(), robot_type = ChatType.QQ, username = e.NewFriendQQ.ToString(), alipay_name = string.Empty, alipay_num = string.Empty, remark = string.Empty };
|
||
var groups = session.FindGroups();
|
||
if (groups.Count != 0)
|
||
new_member.group_id = groups[0].id;
|
||
session.SaveOrUpdate(new_member);
|
||
}
|
||
if (new_member.inviter_id != 0) return;
|
||
else
|
||
{
|
||
new_member.inviter_id = invite_member.id;
|
||
session.SaveOrUpdate(new_member);
|
||
|
||
ApiClient.SendMessage(robot, e.InviteQQ.ToString(), Config.QQGroupInviteBind_AddANewSubordinateTip
|
||
.Replace("[账号]", e.NewFriendQQ.ToString())
|
||
.Replace("[昵称]", e.NewFriendNick)
|
||
.Replace("[群昵称]", e.GroupName)
|
||
.Replace("[群账号]", e.GroupId.ToString())
|
||
.Replace("[剩余积分]", invite_member.cur_point.ToString("0.00")));
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("QQNewGroupMember = " + ex.Message);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#endregion
|
||
|
||
#region 微信
|
||
private void SDK_SharedEvent(object sender, SharedEvents e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Shareds != null && e.Shareds.ContainsKey("msg_type") && e.Shareds["msg_type"].ToString() == "查询宝贝" && ((Config.SubordinateSumSwitch == SwitchType.开启 && Config.SubordinateRewardWay == NewcomerAwardType.首次查券奖励) || !string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip) || !string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip_UnFan) || !string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip_Coupon) || !string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip_UnCoupon)))
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
var username = e.Shareds["msg_username"].ToString();
|
||
var member = session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username", new { username = username });
|
||
if (member == null) return;
|
||
var incomeResult = session.FindSingle<fl_statistics_record>(@"select * from fl_statistics_record where uid = @userid and querynum = 1", new { userid = member.id });
|
||
if (incomeResult != null)
|
||
{
|
||
if (member.bind_order != 0 || member.finish_order != 0) return;
|
||
var orderCount = 0;
|
||
orderCount += session.Find<fl_order_alimama>("select * from fl_order_alimama where db_userid = @db_userid", new { db_userid = member.id }).Count;
|
||
if (orderCount == 0)
|
||
{
|
||
orderCount += session.Find<fl_order_jingdong>("select * from fl_order_jingdong where db_userid = @db_userid", new { db_userid = member.id }).Count;
|
||
if (orderCount == 0)
|
||
orderCount += session.Find<fl_order_pinduoduo>("select * from fl_order_pinduoduo where db_userid = @db_userid", new { db_userid = member.id }).Count;
|
||
if (orderCount == 0)
|
||
orderCount += session.Find<fl_order_douyin>("select * from fl_order_douyin where db_userid = @db_userid", new { db_userid = member.id }).Count;
|
||
if (orderCount == 0)
|
||
orderCount += session.Find<fl_order_weipinhui>("select * from fl_order_weipinhui where db_userid = @db_userid", new { db_userid = member.id }).Count;
|
||
if (orderCount == 0)
|
||
orderCount += session.Find<fl_order_douyin>("select * from fl_order_douyin where db_userid = @db_userid", new { db_userid = member.id }).Count;
|
||
if (orderCount == 0)
|
||
orderCount += session.Find<fl_order_suning>("select * from fl_order_suning where db_userid = @db_userid", new { db_userid = member.id }).Count;
|
||
}
|
||
if (orderCount != 0) return;
|
||
|
||
if (Config.SubordinateSumSwitch == SwitchType.开启 && Config.SubordinateRewardWay == NewcomerAwardType.首次查券奖励)
|
||
{
|
||
try
|
||
{
|
||
if (Config.SubordinateSum2 < Config.SubordinateSum1) throw new Exception("新用户奖励积分设置数据异常,最大奖励值应大于最小值");
|
||
|
||
var robots = session.FindRobots();
|
||
var robot = robots.FirstOrDefault(f => f.type == member.robot_type && f.name == member.robot_name);
|
||
if (robot == null) throw new Exception("用户对应的机器人信息异常");
|
||
|
||
var wxBase = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == robot.name && f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
||
if (wxBase == null) return;
|
||
|
||
NewFriendRewards(wxBase, member, robot, e);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip))
|
||
{
|
||
try
|
||
{
|
||
var robots = session.FindRobots();
|
||
var robot = robots.FirstOrDefault(f => f.type == member.robot_type && f.name == member.robot_name);
|
||
if (robot == null) throw new Exception("用户对应的机器人信息异常");
|
||
|
||
var wxBase = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == robot.name && f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
||
if (wxBase == null) return;
|
||
var price = e.Shareds["price"].ToString();
|
||
var title = e.Shareds["title"].ToString();
|
||
var coupon_price = e.Shareds["coupon_price"].ToString();
|
||
var user_point = e.Shareds["user_point"].ToString();
|
||
var economize = e.Shareds["economize"].ToString();
|
||
|
||
wxBase.SendMessage(username, Config.FirstQueryGoodsTip.Replace("[商品原价]", price).Replace("[商品标题]", title).Replace("[优惠券金额]", coupon_price).Replace("[用户佣金]", user_point).Replace("[优惠券金额]", economize).Replace("[机器人账号]", wxBase.User.Username).Replace("[机器人昵称]", wxBase.User.Nick).Replace("[账号]", member.username).Replace("[昵称]", member.usernick));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
|
||
//由于业务需要,这里将时间设置为2021年11月24日12点整
|
||
//var stateTime = DateTime.Parse("2021-11-24 11:00:00");
|
||
if (Config.NewUserTipStartTime <= member.crt_time)
|
||
{
|
||
var notify = session.FindSingle<fl_plugin_userfission_fan_notify>("select * from fl_plugin_userfission_fan_notify where mid = @mid", new { mid = member.id });
|
||
if (notify == null)
|
||
notify = new fl_plugin_userfission_fan_notify() { mid = member.id, coupon = 0, uncoupon = 0, unfan = 0 };
|
||
|
||
if (!string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip_UnFan) && notify.unfan == 0)
|
||
{
|
||
try
|
||
{
|
||
var robots = session.FindRobots();
|
||
var robot = robots.FirstOrDefault(f => f.type == member.robot_type && f.name == member.robot_name);
|
||
if (robot == null) throw new Exception("用户对应的机器人信息异常");
|
||
|
||
var wxBase = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == robot.name && f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
||
if (wxBase == null) return;
|
||
var price = e.Shareds["price"].ToString();
|
||
if (price == "未知")
|
||
{
|
||
notify.unfan = HttpExtend.GetTimeStamp(DateTime.Now);
|
||
if (Config.FirstQueryGoodsTip_Switch == SwitchType.开启)
|
||
{
|
||
notify.coupon = HttpExtend.GetTimeStamp(DateTime.Now);
|
||
notify.uncoupon = HttpExtend.GetTimeStamp(DateTime.Now);
|
||
}
|
||
session.Saveable(notify).ExecuteCommand();
|
||
wxBase.SendMessage(username, Config.FirstQueryGoodsTip_UnFan.Replace("[机器人账号]", wxBase.User.Username).Replace("[机器人昵称]", wxBase.User.Nick).Replace("[账号]", member.username).Replace("[昵称]", member.usernick));
|
||
return;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip_Coupon) && notify.coupon == 0)
|
||
{
|
||
try
|
||
{
|
||
var robots = session.FindRobots();
|
||
var robot = robots.FirstOrDefault(f => f.type == member.robot_type && f.name == member.robot_name);
|
||
if (robot == null) throw new Exception("用户对应的机器人信息异常");
|
||
|
||
var wxBase = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == robot.name && f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
||
if (wxBase == null) return;
|
||
var coupon_price = e.Shareds["coupon_price"].ToString();
|
||
if (coupon_price != "未知" && double.Parse(coupon_price) > 0)
|
||
{
|
||
notify.coupon = HttpExtend.GetTimeStamp(DateTime.Now);
|
||
if (Config.FirstQueryGoodsTip_Switch == SwitchType.开启)
|
||
{
|
||
notify.unfan = HttpExtend.GetTimeStamp(DateTime.Now);
|
||
notify.uncoupon = HttpExtend.GetTimeStamp(DateTime.Now);
|
||
}
|
||
session.Saveable(notify).ExecuteCommand();
|
||
|
||
var price = e.Shareds["price"].ToString();
|
||
var title = e.Shareds["title"].ToString();
|
||
var user_point = e.Shareds["user_point"].ToString();
|
||
var economize = e.Shareds["economize"].ToString();
|
||
|
||
wxBase.SendMessage(username, Config.FirstQueryGoodsTip_Coupon.Replace("[商品原价]", price).Replace("[商品标题]", title).Replace("[优惠券金额]", coupon_price).Replace("[用户佣金]", user_point).Replace("[优惠券金额]", economize).Replace("[机器人账号]", wxBase.User.Username).Replace("[机器人昵称]", wxBase.User.Nick).Replace("[账号]", member.username).Replace("[昵称]", member.usernick));
|
||
return;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
if (!string.IsNullOrWhiteSpace(Config.FirstQueryGoodsTip_UnCoupon) && notify.uncoupon == 0)
|
||
{
|
||
try
|
||
{
|
||
var robots = session.FindRobots();
|
||
var robot = robots.FirstOrDefault(f => f.type == member.robot_type && f.name == member.robot_name);
|
||
if (robot == null) throw new Exception("用户对应的机器人信息异常");
|
||
|
||
var wxBase = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == robot.name && f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
||
if (wxBase == null) return;
|
||
var coupon_price = e.Shareds["coupon_price"].ToString();
|
||
if (coupon_price != "未知" && double.Parse(coupon_price) <= 0)
|
||
{
|
||
notify.uncoupon = HttpExtend.GetTimeStamp(DateTime.Now);
|
||
if (Config.FirstQueryGoodsTip_Switch == SwitchType.开启)
|
||
{
|
||
notify.unfan = HttpExtend.GetTimeStamp(DateTime.Now);
|
||
notify.coupon = HttpExtend.GetTimeStamp(DateTime.Now);
|
||
}
|
||
session.Saveable(notify).ExecuteCommand();
|
||
|
||
var price = e.Shareds["price"].ToString();
|
||
var title = e.Shareds["title"].ToString();
|
||
var user_point = e.Shareds["user_point"].ToString();
|
||
var economize = e.Shareds["economize"].ToString();
|
||
|
||
wxBase.SendMessage(username, Config.FirstQueryGoodsTip_UnCoupon.Replace("[商品原价]", price).Replace("[商品标题]", title).Replace("[优惠券金额]", coupon_price).Replace("[用户佣金]", user_point).Replace("[优惠券金额]", economize).Replace("[机器人账号]", wxBase.User.Username).Replace("[机器人昵称]", wxBase.User.Nick).Replace("[账号]", member.username).Replace("[昵称]", member.usernick));
|
||
return;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(" " + ex.Message);
|
||
}
|
||
}
|
||
|
||
private void NewFriendRewards(WeixinBase wx, fl_member_info member, fl_robot_info robot, SharedEvents e = null)
|
||
{
|
||
try
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
var _bonusSubordinate = Math.Round((new Random().Next(
|
||
int.Parse(Math.Round(Config.SubordinateSum1 * 100, 2).ToString()),
|
||
int.Parse(Math.Round((Config.SubordinateSum2 + 0.01) * 100, 2).ToString())
|
||
)) / 100d, 2);//新人奖励积分
|
||
if (robot.type == ChatType.微信 && wx.GetType() == typeof(WXClientImpl_IPAD) && (Config.Subordinate_RechargeType == RechargeType.发送红包 || Config.Subordinate_RechargeType == RechargeType.微信转账))
|
||
{
|
||
var passinfo = session.FindWeixinpassword(session.FindRobotInfo(wx.WeixinHao, ChatType.微信).id);//获取微信支付信息
|
||
if (passinfo != null && !string.IsNullOrEmpty(passinfo.password))
|
||
{
|
||
var flag = wx.SendPay(member.username, Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonusSubordinate.ToString()), (int)((decimal)_bonusSubordinate * 100m), passinfo.password, 1, (Config.Subordinate_RechargeType == RechargeType.发送红包 ? PayType.红包 : PayType.转账), passinfo.GetBank());
|
||
if (!string.IsNullOrEmpty(flag))
|
||
{
|
||
this.OnLog("微信新人奖励失败:" + flag + ",已添加积分到用户余额!");//发送红包不成功,将积分增加余额
|
||
member = session.ChangePoint(PointType.其他奖励, _bonusSubordinate, member.id, $"新人赠送积分{_bonusSubordinate}【微信红包操作失败】");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("微信新人奖励失败:未设置支付密码,已添加积分到用户余额!");
|
||
member = session.ChangePoint(PointType.其他奖励, _bonusSubordinate, member.id, $"新人赠送积分{_bonusSubordinate}【微信红包操作失败,未设置支付密码】");
|
||
}
|
||
}
|
||
else if (Config.Subordinate_RechargeType == RechargeType.商户付款)
|
||
{
|
||
if (_bonusSubordinate >= 0.3)
|
||
{
|
||
var ispaid = false;
|
||
object appinfo = null;
|
||
string url = ApiClient.SendWechatPay(new { robot_name = robot.name, robot_nick = robot.nick, username = member.username, usernick = member.usernick }, Class1.Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonusSubordinate.ToString()), _bonusSubordinate, out ispaid, out appinfo);
|
||
if (!string.IsNullOrEmpty(url))
|
||
{
|
||
member = session.ChangePoint(PointType.其他奖励, _bonusSubordinate, member.id, $"新人赠送积分{_bonusSubordinate}");
|
||
Thread.Sleep(20);
|
||
member = session.ChangePoint(PointType.提现扣除, _bonusSubordinate, member.id, $"新人奖励【商户付款成功】 商户链接:{url}");
|
||
|
||
var mess = string.Empty;
|
||
if (ispaid)
|
||
mess = Config.SubordinateCommercialEftTip.Replace("[推荐奖励金额]", "[奖励金额]").Replace("[奖励金额]", _bonusSubordinate.ToString());
|
||
else
|
||
{
|
||
if (Config.ShangHu_MiNiApp == SwitchType.开启 && appinfo != null)
|
||
mess = Util.GetMiNiAppXml(appinfo, robot.type);
|
||
if (string.IsNullOrWhiteSpace(mess))
|
||
mess = Config.SubordinateCommercialPayTip.Replace("[领取地址]", url/*ApiClient.ShortURL(url).Result*/).Replace("[推荐奖励金额]", "[奖励金额]").Replace("[奖励金额]", _bonusSubordinate.ToString());
|
||
}
|
||
|
||
ApiClient.SendMessage(robot, member.username, mess);
|
||
this.OnLog("商户付款信息 = " + mess);
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("新人奖励商户付款失败:获取不到商户付款地址,已添加积分到用户余额!");
|
||
member = session.ChangePoint(PointType.其他奖励, _bonusSubordinate, member.id, $"新人赠送积分{_bonusSubordinate}【商户付款操作失败,请求商户链接失败】");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("新人奖励商户付款失败:奖励积分小于0.3,已添加积分到用户余额!");
|
||
member = session.ChangePoint(PointType.其他奖励, _bonusSubordinate, member.id, $"新人赠送积分{_bonusSubordinate}【商户付款操作失败,积分小于0.3】");
|
||
}
|
||
}
|
||
else
|
||
member = session.ChangePoint(PointType.其他奖励, _bonusSubordinate, member.id, $"新人赠送积分{_bonusSubordinate}【增加积分操作】");
|
||
|
||
if (e != null)
|
||
{
|
||
wx.SendMessage(member.username, new VariateReplace().CommonReplace(Config.Subordinate_AdditionalTip_Query.Replace("[奖励金额]", _bonusSubordinate.ToString())
|
||
.Replace("[商品标题]", e.Shareds["title"].ToString())
|
||
.Replace("[商品价格]", e.Shareds["price"].ToString())
|
||
.Replace("[商品优惠券]", e.Shareds["coupon_price"].ToString())
|
||
.Replace("[用户返利]", e.Shareds["user_point"].ToString())
|
||
.Replace("[共节省]", e.Shareds["economize"].ToString())
|
||
, member));
|
||
}
|
||
else
|
||
{
|
||
wx.SendMessage(member.username, new VariateReplace().CommonReplace(Config.Subordinate_AdditionalTip.Replace("[奖励金额]", _bonusSubordinate.ToString()), member));
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
throw ex;
|
||
}
|
||
}
|
||
|
||
private void SDK_WXOpenWindowEvent(object sender, WXOpenWindow e)
|
||
{
|
||
try
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
var friend = session.Find<fl_plugin_userfission_applyfriend_info>("select * from fl_plugin_userfission_applyfriend_info where new_friend_wxid = @new_friend_wxid and state != '已接受'", new { new_friend_wxid = e.Friend.UserName }).FirstOrDefault();
|
||
if (friend != null)
|
||
{
|
||
var _e = new WXNewFriend(e.Client, e.Friend);
|
||
|
||
Task.Run(() =>
|
||
{
|
||
SDK_WXNewFriendEvent(sender, _e);
|
||
});
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("Open = " + ex.Message + " - " + ex.StackTrace);
|
||
}
|
||
}
|
||
|
||
private bool IsApply = false;
|
||
private void ApplyWechatFriend()
|
||
{
|
||
if (IsApply) return;
|
||
IsApply = true;
|
||
Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
do
|
||
{
|
||
var apply_id = queue.Dequeue();
|
||
var friend = session.FindSingle<fl_plugin_userfission_applyfriend_info>("id = @id", new { id = apply_id });
|
||
if (friend != null)
|
||
{
|
||
Thread.Sleep(Config.Retardation * 1000);
|
||
if (friend != null && friend.state == "已接受") continue;
|
||
var client = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == friend.robot_name && /*f.WeixinType == WeixinType.Grpc微信 &&*/ f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
||
|
||
if (client != null)
|
||
{
|
||
//%3cmsg+fromusername%3d%22wxid_syajaydqg2mi22%22+encryptusername%3d%22v1_98b2f7e33fdd0211eefe3c5a372bc565f3cae00066c66f67cd39f7a008c43ac66658d416fae14a20a434313a3ac3552f%40stranger%22+fromnickname%3d%22%b2%e9%d3%c5%bb%dd%d0%a1%d6%fa%ca%d6-%d4%cb%d3%aa-%c3%c8%c3%c8%22+content%3d%22%c7%d7++%df%e4%df%e4%d4%dd%ca%b1%b7%a2%b2%bb%b3%f6%c8%a5%d0%c5%cf%a2%2c%d0%e8%d2%aa%ba%c3%d3%d1%b0%ef%c3%a6%d1%e9%d6%a4%a3%ac%bf%c9%d2%d4%b0%ef%cf%c2%c3%a6%c2%f0%3f%3f%3f%3f%22+fullpy%3d%22zhayouhuixiaozhushouyunyingmengmeng%22+shortpy%3d%22ZYHXZSYYMM%22+imagestatus%3d%223%22+scene%3d%2217%22+country%3d%22%22+province%3d%22%22+city%3d%22%22+sign%3d%22%ce%d2%ca%c7%ca%a1%c7%ae%d0%a1%d6%fa%ca%d6%d4%cb%d3%aa%a1%a2%c3%c8%c3%c8%a1%a2%d0%bb%d0%bb%b4%f3%bc%d2%d2%bb%d6%b1%d2%d4%c0%b4%b6%d4%ce%d2%c3%c7%b5%c4%d6%a7%b3%d6!%22+percard%3d%221%22+sex%3d%222%22+alias%3d%22jb31818%22+weibo%3d%22%22+albumflag%3d%220%22+albumstyle%3d%220%22+albumbgimgid%3d%22%22+snsflag%3d%221%22+snsbgimgid%3d%22http%3a%2f%2fszmmsns.qpic.cn%2fmmsns%2fswxPWAic8Eyxld2DN94W2IkQ5Q17JShIQp3YKibvF4pzAfqmNrAzyAkW9fYElTSFjd6J4ylyCvKeI%2f0%22+snsbgobjectid%3d%2213282630333274796184%22+mhash%3d%22dcb3ac624574902decb75866a6934a6e%22+mfullhash%3d%22dcb3ac624574902decb75866a6934a6e%22+bigheadimgurl%3d%22http%3a%2f%2fwx.qlogo.cn%2fmmhead%2fver_1%2f1ibs5sUHIKr1hBvRWPaichaQXiaXib06icfsUn6EuoV5YskibBZlYLSTPztuVMdXiaqQyhys5ozEoQswhMd6cFbLkWnovzLH7iamsQ6aQnIKzCyUr48%2f0%22+smallheadimgurl%3d%22http%3a%2f%2fwx.qlogo.cn%2fmmhead%2fver_1%2f1ibs5sUHIKr1hBvRWPaichaQXiaXib06icfsUn6EuoV5YskibBZlYLSTPztuVMdXiaqQyhys5ozEoQswhMd6cFbLkWnovzLH7iamsQ6aQnIKzCyUr48%2f96%22+ticket%3d%22v2_ed61758c0d517c2a7b5fa83d26b48e3aad8cec1239bf37db9a381858fe2507ac1205b9b36114db60b0ac1d009249a9da17ebf506cc234e8723d1ef47bfdd34ecef24f5d86846a487d4dc53c5812f5c66619ad95253c341e7310e076299c985e05d8b5e70583f5e7602cc1a783bb136f286e9163e59b7042b964ae858aabcd6973b9519b9ae58997b1674826f459882a7d217a07259ae07e564f9b768e75b267939762dcd58be0ec242a434b06cddf04e1bfe69c6425caadf51be980ac5cf26dd3b32b5796ed4d6bdb6e3998b7e9cec56598e2c5df5288d562b0b6f5199ead90f974446656a9df971c7163a2e1bb8047f9116d316c289b43b50acbd9344b5132d%40stranger%22+opcode%3d%222%22+googlecontact%3d%22%22+qrticket%3d%22%22+chatroomusername%3d%22%22+sourceusername%3d%22wxid_2ufntuf4purl22%22+sourcenickname%3d%22%c7%ef%b1%b1%cf%c8%c9%fa%22+sharecardusername%3d%22wxid_2ufntuf4purl22%22+sharecardnickname%3d%22%c7%ef%b1%b1%cf%c8%c9%fa%22+cardversion%3d%220%22%3e%3cbrandlist+count%3d%220%22+ver%3d%22703522235%22%3e%3c%2fbrandlist%3e%3c%2fmsg%3e
|
||
var ss = HttpHelper.URLDecode(friend.token);
|
||
string result = client.AgreeAddMe(HttpHelper.URLDecode(friend.token));
|
||
if (string.IsNullOrEmpty(result))
|
||
{
|
||
friend.state = "已接受";
|
||
friend.allow_time = DateTime.Now;
|
||
}
|
||
else friend.state = result;
|
||
session.Saveable(friend).ExecuteReturnEntity();
|
||
}
|
||
}
|
||
} while (true);
|
||
}
|
||
catch (Exception)
|
||
{ }
|
||
finally
|
||
{
|
||
IsApply = false;
|
||
}
|
||
});
|
||
}
|
||
|
||
private static readonly object applyFriendLock = new object();
|
||
|
||
/// <summary>
|
||
/// 微信 - 申请添加我为好友,需要审核
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void SDK_WXApplyFriendEvent(object sender, WXApplyFriend e)
|
||
{
|
||
try
|
||
{
|
||
lock (applyFriendLock)
|
||
{
|
||
var friend = ApiClient.GetSession().FindSingle<fl_plugin_userfission_applyfriend_info>("select * from fl_plugin_userfission_applyfriend_info where new_friend_wxid = @new_friend_wxid and robot_name = @robot_name", new { new_friend_wxid = e.NewFriendWxid, robot_name = e.Client.WeixinHao });
|
||
if (friend != null && friend.state == "已接受") return;
|
||
if (friend == null)
|
||
{
|
||
friend = new fl_plugin_userfission_applyfriend_info()
|
||
{
|
||
state = "待审核",
|
||
crt_time = DateTime.Parse(e.CrtTime.ToString("yyyy-MM-dd HH:mm:ss")),
|
||
message = e.Message.Trim(),
|
||
robot_name = e.Client.WeixinHao,
|
||
user_nick = e.Client.User.Nick,
|
||
new_friend_nick = e.NewFriendNick,
|
||
new_friend_wxid = e.NewFriendWxid,
|
||
old_friend_nick = e.OldFriendNick,
|
||
old_friend_wxid = e.OldFriendWxid,
|
||
token = HttpHelper.URLEncode(e.Token)
|
||
};
|
||
friend.id = ApiClient.GetSession().Insertable(friend).ExecuteReturnIdentity();
|
||
}
|
||
if (Config.Accept == SwitchType.关闭) return;
|
||
var reg = Regex.Match(e.Token, @"sex=""(?<性别>\d+)""");
|
||
if (reg.Success)
|
||
{
|
||
var sex = reg.Groups["性别"].ToString();
|
||
if (sex == "1" && !Config.GenderType.Contains("男")) return;
|
||
else if (sex == "2" && !Config.GenderType.Contains("女")) return;
|
||
else if (sex == "0" && !Config.GenderType.Contains("未知")) return;
|
||
}
|
||
//var robot = session.FindRobots().FirstOrDefault(f => f.name == e.Client.WeixinHao && f.type == (e.Client.WeixinType == WeixinType.QYHook微信 ? ChatType.企业微信 : ChatType.微信));
|
||
var robot = ApiClient.GetSession().FindRobotInfo(e.Client.WeixinHao, (e.Client.WeixinType == WeixinType.QYHook微信 ? ChatType.企业微信 : ChatType.微信));
|
||
if (robot == null) return;
|
||
var aas = ApiClient.GetSession().FindSingle<fl_plugin_userfission_automatic_approval_setting>("select * from fl_plugin_userfission_automatic_approval_setting where rid = @rid", new { rid = robot.id });
|
||
if (aas != null && aas.onoff) return;
|
||
if (!queue.Contains(friend.id))
|
||
{
|
||
queue.Enqueue(friend.id);
|
||
ApplyWechatFriend();
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("ApplyFriend = " + ex.Message + " - " + ex.StackTrace);
|
||
}
|
||
}
|
||
|
||
private List<string> welcomeTip_Friends = new List<string>();
|
||
private static object lock_newfriend = new object();
|
||
/// <summary>
|
||
/// 微信 - 新增微信好友
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void SDK_WXNewFriendEvent(object sender, WXNewFriend e)
|
||
{
|
||
var strb = new StringBuilder();
|
||
try
|
||
{
|
||
strb.AppendLine("1");
|
||
fl_plugin_userfission_applyfriend_info friend = null;
|
||
var isNewMember = false;
|
||
var chatType = e.Client.WeixinType == WeixinType.QYHook微信 ? ChatType.企业微信 : ChatType.微信;
|
||
//var session = ApiClient.GetSession();
|
||
fl_member_info new_member = null;
|
||
strb.AppendLine("2");
|
||
var robot = ApiClient.GetSession().FindRobotInfo(e.Client.WeixinHao, chatType);
|
||
if (robot != null)
|
||
{
|
||
strb.AppendLine("3");
|
||
Thread.Sleep(1100);
|
||
lock (lock_newfriend)
|
||
{
|
||
strb.AppendLine("4");
|
||
if (!welcomeTip_Friends.Contains(e.Friend.UserName))
|
||
{
|
||
strb.AppendLine("4-1");
|
||
var mess = Config.WelcomeTip;
|
||
friend = ApiClient.GetSession().FindSingle<fl_plugin_userfission_applyfriend_info>(
|
||
"new_friend_wxid = @new_friend_wxid and robot_name = @robot_name",
|
||
new { new_friend_wxid = e.Friend.UserName, robot_name = e.Client.WeixinHao });
|
||
if (friend != null && !string.IsNullOrWhiteSpace(friend.old_friend_wxid))
|
||
mess = Config.WelcomeBeInvitedTip.Replace("[邀请人昵称]", friend.old_friend_nick);
|
||
strb.AppendLine("4-2");
|
||
#region 将表fl_plugin_userfission_applyfriend_info中的请求状态改成 "已接受"
|
||
|
||
if (friend != null && friend.state != "已接受")
|
||
{
|
||
strb.AppendLine("4-3");
|
||
friend.state = "已接受";
|
||
friend.allow_time = DateTime.Now;
|
||
ApiClient.GetSession().Saveable(friend).ExecuteReturnEntity();
|
||
}
|
||
strb.AppendLine("4-4");
|
||
#endregion
|
||
|
||
if (welcomeTip_Friends.Count > 10000) welcomeTip_Friends.Clear();
|
||
welcomeTip_Friends.Add(e.Friend.UserName);
|
||
strb.AppendLine("4-5");
|
||
new_member = ApiClient.GetSession().FindSingle<fl_member_info>(
|
||
"robot_type = @robot_type and username = @username",
|
||
new { robot_type = robot.type, username = e.Friend.UserName });
|
||
if (new_member == null)
|
||
{
|
||
strb.AppendLine("4-6");
|
||
new_member = new fl_member_info()
|
||
{
|
||
crt_time = DateTime.Now,
|
||
usernick = e.Friend.NickName,
|
||
realnick = e.Friend.NickName,
|
||
robot_name = e.Client.WeixinHao,
|
||
robot_type = robot.type,
|
||
username = e.Friend.UserName,
|
||
alipay_name = string.Empty,
|
||
alipay_num = string.Empty,
|
||
remark = string.Empty
|
||
};
|
||
var groups = ApiClient.GetSession().FindGroups();
|
||
if (groups.Count != 0)
|
||
new_member.group_id = groups[0].id;
|
||
strb.AppendLine("4-7");
|
||
ApiClient.GetSession().SaveOrUpdate(new_member);
|
||
isNewMember = true;
|
||
}
|
||
else if (new_member.crt_time.AddSeconds(15) > DateTime.Now)
|
||
{
|
||
strb.AppendLine("4-8");
|
||
isNewMember = true;
|
||
}
|
||
strb.AppendLine("4-9");
|
||
ApiClient.SendMessage(robot, e.Friend.UserName, mess);
|
||
}
|
||
}
|
||
}
|
||
|
||
#region 新人加入奖励
|
||
strb.AppendLine("5");
|
||
if (new_member == null || !isNewMember)
|
||
{
|
||
strb.AppendLine("6");
|
||
new_member = ApiClient.GetSession().FindSingle<fl_member_info>(
|
||
"select * from fl_member_info where robot_type = @robot_type and username = @username",
|
||
new { robot_type = chatType, username = e.Friend.UserName });
|
||
if (new_member == null)
|
||
{
|
||
new_member = new fl_member_info()
|
||
{
|
||
crt_time = DateTime.Now,
|
||
usernick = e.Friend.NickName,
|
||
realnick = e.Friend.NickName,
|
||
robot_name = e.Client.WeixinHao,
|
||
robot_type = chatType,
|
||
username = e.Friend.UserName,
|
||
alipay_name = string.Empty,
|
||
alipay_num = string.Empty,
|
||
remark = string.Empty
|
||
};
|
||
var groups = ApiClient.GetSession().FindGroups();
|
||
if (groups.Count != 0)
|
||
new_member.group_id = groups[0].id;
|
||
ApiClient.GetSession().SaveOrUpdate(new_member);
|
||
isNewMember = true;
|
||
}
|
||
}
|
||
|
||
if (isNewMember)
|
||
{
|
||
strb.AppendLine("7");
|
||
if (Config.SubordinateSumSwitch == SwitchType.开启 &&
|
||
Config.SubordinateRewardWay == NewcomerAwardType.通过立即奖励)
|
||
{
|
||
if (Config.SubordinateSum2 < Config.SubordinateSum1)
|
||
throw new Exception("新用户奖励积分设置数据异常,最大奖励值应大于最小值");
|
||
|
||
NewFriendRewards(e.Client, new_member, robot);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
strb.AppendLine("8");
|
||
//if (new_member != null || Config.Bind == SwitchType.开启)
|
||
if (Config.Bind == SwitchType.开启 && new_member != null)
|
||
{
|
||
strb.AppendLine("9");
|
||
//this.OnLog($"新用户绑定:{new_member.usernick} - {new_member.username} - {isNewMember}");
|
||
if (friend == null)
|
||
friend = ApiClient.GetSession().Find<fl_plugin_userfission_applyfriend_info>(
|
||
$"select * from fl_plugin_userfission_applyfriend_info where new_friend_wxid = @wxid and robot_name = @robotName order by id desc",
|
||
new { wxid = e.Friend.UserName, robotName = e.Client.WeixinHao }).FirstOrDefault();
|
||
|
||
this.OnLog(
|
||
$"新用户绑定:{new_member.usernick} - {new_member.username} {(friend == null ? "无" : $"{friend.old_friend_nick}({friend.old_friend_wxid})")} - {isNewMember}");
|
||
|
||
if (friend != null)
|
||
{
|
||
string mess = string.Empty;
|
||
if (new_member.inviter_id == 0)
|
||
{
|
||
//防止用户反复添加获取奖励
|
||
if (!string.IsNullOrEmpty(friend.old_friend_wxid) ||
|
||
!string.IsNullOrEmpty(friend.old_friend_nick))
|
||
{
|
||
var old_member = ApiClient.GetSession()
|
||
.FindSingle<fl_member_info>("robot_type = @robot_type and username = @username",
|
||
new { username = friend.old_friend_wxid, robot_type = chatType });
|
||
if (old_member == null)
|
||
{
|
||
old_member = new fl_member_info()
|
||
{
|
||
crt_time = DateTime.Now,
|
||
usernick = friend.old_friend_nick,
|
||
robot_name = e.Client.WeixinHao,
|
||
robot_type = chatType,
|
||
username = friend.old_friend_wxid,
|
||
alipay_name = string.Empty,
|
||
alipay_num = string.Empty,
|
||
remark = string.Empty
|
||
};
|
||
var groups = ApiClient.GetSession().FindGroups();
|
||
if (groups.Count != 0)
|
||
old_member.group_id = groups[0].id;
|
||
ApiClient.GetSession().SaveOrUpdate(old_member);
|
||
}
|
||
|
||
if (old_member.inviter_id != new_member.id) //排除相互绑定
|
||
{
|
||
new_member.inviter_id = old_member.id;
|
||
ApiClient.GetSession().SaveOrUpdate(new_member);
|
||
|
||
//上级奖励开关
|
||
if (Config.SuperiorSumSwitch == SwitchType.开启 &&
|
||
Config.SuperiorRewardWay == ReferralJackpotType.推荐新人立马奖励)
|
||
{
|
||
if (IsSuperiorReward(robot))
|
||
{
|
||
if (Config.SuperiorSum2 < Config.SuperiorSum1)
|
||
throw new Exception("上级奖励积分设置数据异常,最大奖励值应大于最小值");
|
||
var _bonusSuperior = Math.Round((
|
||
new Random().Next(
|
||
int.Parse(Math.Round(Config.SuperiorSum1 * 100, 2).ToString()),
|
||
int.Parse(Math.Round((Config.SuperiorSum2 + 0.01) * 100, 2)
|
||
.ToString())
|
||
)) / 100d, 2);
|
||
if (Config.Superior_RechargeType == RechargeType.发送红包 ||
|
||
Config.Superior_RechargeType == RechargeType.微信转账)
|
||
{
|
||
var passinfo = ApiClient.GetSession()
|
||
.FindWeixinpassword(ApiClient.GetSession()
|
||
.FindRobotInfo(e.Client.WeixinHao, chatType).id); //获取微信支付信息
|
||
if (passinfo != null && !string.IsNullOrEmpty(passinfo.password))
|
||
{
|
||
var flag = e.Client.SendPay(old_member.username,
|
||
Config.ExchangePacketTitle
|
||
.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName)
|
||
.Replace("[兑换金额]", _bonusSuperior.ToString()),
|
||
(int)((decimal)_bonusSuperior * 100m), passinfo.password, 1,
|
||
(Config.Superior_RechargeType == RechargeType.发送红包
|
||
? PayType.红包
|
||
: PayType.转账), passinfo.GetBank());
|
||
if (!string.IsNullOrEmpty(flag))
|
||
{
|
||
this.OnLog("推荐新人奖励失败:" + flag +
|
||
",已添加积分到用户余额!"); //发送红包不成功,将积分增加余额
|
||
old_member = ApiClient.GetSession().ChangePoint(PointType.其他奖励,
|
||
_bonusSuperior, old_member.id,
|
||
$"推荐新人{new_member.usernick}-{new_member.username},奖励积分{_bonusSuperior}【微信红包操作失败】");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("推荐新人奖励失败:未设置支付密码,已添加积分到用户余额!");
|
||
old_member = ApiClient.GetSession().ChangePoint(PointType.其他奖励,
|
||
_bonusSuperior, old_member.id,
|
||
$"推荐新人{new_member.usernick}-{new_member.username},奖励积分{_bonusSuperior}【微信红包操作失败,未设置支付密码】");
|
||
}
|
||
}
|
||
else if (Config.Superior_RechargeType == RechargeType.商户付款)
|
||
{
|
||
if (_bonusSuperior >= 0.3)
|
||
{
|
||
var ispaid = false;
|
||
object appinfo = null;
|
||
string url = ApiClient.SendWechatPay(
|
||
new
|
||
{
|
||
robot_name = robot.name,
|
||
robot_nick = robot.nick,
|
||
username = old_member.username,
|
||
usernick = old_member.usernick
|
||
},
|
||
Class1.Config.ExchangePacketTitle
|
||
.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName)
|
||
.Replace("[兑换金额]", _bonusSuperior.ToString()),
|
||
_bonusSuperior, out ispaid, out appinfo);
|
||
if (!string.IsNullOrEmpty(url))
|
||
{
|
||
old_member = ApiClient.GetSession().ChangePoint(PointType.其他奖励,
|
||
_bonusSuperior, old_member.id,
|
||
$"推荐新人{new_member.usernick}-{new_member.username},奖励积分{_bonusSuperior}");
|
||
Thread.Sleep(20);
|
||
old_member = ApiClient.GetSession().ChangePoint(PointType.提现扣除,
|
||
_bonusSuperior, old_member.id, $"推荐新人【商户付款成功】 商户链接:{url}");
|
||
|
||
var _mess = string.Empty;
|
||
if (ispaid)
|
||
_mess = Config.SuperiorCommercialEftTip
|
||
.Replace("[下级昵称]", new_member.realnick)
|
||
.Replace("[推荐奖励金额]", _bonusSuperior.ToString());
|
||
else
|
||
{
|
||
if (Config.ShangHu_MiNiApp == SwitchType.开启 &&
|
||
appinfo != null)
|
||
_mess = Util.GetMiNiAppXml(appinfo, robot.type);
|
||
if (string.IsNullOrWhiteSpace(_mess))
|
||
_mess = Config.SuperiorCommercialPayTip
|
||
.Replace("[领取地址]",
|
||
url /*ApiClient.ShortURL(url).Result*/)
|
||
.Replace("[下级昵称]", new_member.realnick)
|
||
.Replace("[推荐奖励金额]", _bonusSuperior.ToString());
|
||
}
|
||
|
||
ApiClient.SendMessage(robot, old_member.username, _mess);
|
||
this.OnLog("商户付款信息 = " + _mess);
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("推荐新人商户付款失败:获取不到商户付款地址,已添加积分到用户余额!");
|
||
old_member = ApiClient.GetSession().ChangePoint(PointType.其他奖励,
|
||
_bonusSuperior, old_member.id,
|
||
$"推荐新人{new_member.usernick}-{new_member.username},奖励积分{_bonusSuperior}【商户付款操作失败,请求商户链接失败】");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("推荐新人商户付款失败:奖励积分小于0.3,已添加积分到用户余额!");
|
||
old_member = ApiClient.GetSession().ChangePoint(PointType.其他奖励,
|
||
_bonusSuperior, old_member.id,
|
||
$"推荐新人{new_member.usernick}-{new_member.username},奖励积分{_bonusSuperior}【商户付款操作失败,积分小于0.3】");
|
||
}
|
||
}
|
||
else
|
||
old_member = ApiClient.GetSession().ChangePoint(PointType.其他奖励,
|
||
_bonusSuperior, old_member.id,
|
||
$"推荐新人{new_member.usernick}-{new_member.username},奖励积分{_bonusSuperior}【增加积分操作】");
|
||
|
||
Thread.Sleep(400);
|
||
//邀请成功通知上级用户
|
||
ApiClient.SendMessage(robot, old_member.username,
|
||
Config.ImmediateReward_AddANewSubordinateTip
|
||
.Replace("[使用者昵称]", new_member.realnick)
|
||
.Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[剩余积分]",
|
||
old_member.cur_point.ToString()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ApiClient.SendMessage(robot, old_member.username,
|
||
Config.FirstSingleReward_AddANewSubordinateTip
|
||
.Replace("[使用者昵称]", new_member.realnick).Replace("[剩余积分]",
|
||
old_member.cur_point.ToString()));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
|
||
#region 将用户拉入群操作
|
||
|
||
Task.Run(() =>
|
||
{
|
||
try
|
||
{
|
||
if (robot == null) return;
|
||
if (Config.InvitedIntoGroupSwitch == SwitchType.关闭) return;
|
||
if (Config.InvitegroupWay) return;
|
||
if (Config.InviteGroupInfo2 == null || Config.InviteGroupInfo2.Count == 0) return;
|
||
var _session = ApiClient.GetSession();
|
||
var member = _session.FindSingle<fl_member_info>(
|
||
"robot_type = @robot_type and username = @username",
|
||
new { username = e.Friend.UserName, robot_type = chatType });
|
||
if (member == null) return;
|
||
if (userIdlist.Contains(member.id)) return;
|
||
var groupInfo = Config.InviteGroupInfo2.Where(f =>
|
||
f.Key == e.Client.WeixinHao && !f.Value.onoff && f.Value.groupInfos.Count != 0);
|
||
if (groupInfo != null) //查询的对象不为空 并且 自动拉进群的操作非禁用
|
||
{
|
||
var wechat = ChatClient.WXClient.Values.ToList().FirstOrDefault(f =>
|
||
f.WeixinHao == e.Client.WeixinHao && /*f.WeixinType == WeixinType.Grpc微信 &&*/
|
||
f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
||
//if (wxBase == null) return;
|
||
//var ipad = wxBase as WXClientImpl_IPAD;
|
||
//if (ipad == null) return;
|
||
if (Config.InviteGroupInfo2.ContainsKey(e.Client.WeixinHao))
|
||
{
|
||
var groupIds = Config.InviteGroupInfo2[e.Client.WeixinHao].groupInfos;
|
||
foreach (var groupId in groupIds)
|
||
{
|
||
lock (padlock)
|
||
{
|
||
if (!userIdlist.Contains(member.id))
|
||
userIdlist.Add(member.id);
|
||
if (wechat.GetType() == typeof(WXClientImpl_QYHOOK))
|
||
{
|
||
var result = _session.FindSingle<fl_plugin_userfission_invite_record>(
|
||
"username = @username and groupid = @groupid",
|
||
new { username = e.Friend.UserName, groupid = groupId.Key });
|
||
if (result != null) return;
|
||
|
||
ApiClient.SendMessage(robot, e.Friend.UserName,
|
||
Config.InvitedIntoGroupTip.Replace("[账号]", e.Friend.UserName)
|
||
.Replace("[昵称]", e.Friend.NickName));
|
||
e.Client.InviteIntoGroup(e.Friend.UserName, groupId.Key);
|
||
}
|
||
else
|
||
{
|
||
var group = wechat.GetContact(groupId.Key);
|
||
if (group == null) continue;
|
||
|
||
var result = _session.FindSingle<fl_plugin_userfission_invite_record>(
|
||
"username = @username and groupid = @groupid",
|
||
new { username = e.Friend.UserName, groupid = group.UserName });
|
||
if (result != null) return;
|
||
//该用户不在群内 并且 没有给用户发送过邀请入群卡片
|
||
if (string.IsNullOrWhiteSpace(group.ExtInfo) ||
|
||
!group.ExtInfo.Contains(e.Friend.UserName))
|
||
{
|
||
ApiClient.SendMessage(robot, e.Friend.UserName,
|
||
Config.InvitedIntoGroupTip.Replace("[账号]", e.Friend.UserName)
|
||
.Replace("[昵称]", e.Friend.NickName));
|
||
var sss = e.Client.InviteIntoGroup(e.Friend.UserName, group.UserName);
|
||
}
|
||
}
|
||
|
||
var _result = new fl_plugin_userfission_invite_record()
|
||
{ groupid = groupId.Key, username = e.Friend.UserName };
|
||
_session.Insertable(_result).ExecuteCommand();
|
||
}
|
||
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog($"拉用户入群操作异常:{ex.Message} ~ {ex.StackTrace}");
|
||
}
|
||
});
|
||
|
||
#endregion
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
strb.AppendLine("10000:" + ex.Message);
|
||
this.OnLog("NewFriend = " + ex.Message + " - " + ex.StackTrace);
|
||
}
|
||
finally
|
||
{
|
||
//this.OnLog("......." + strb.ToString());
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 进群的用户
|
||
/// </summary>
|
||
private static ConcurrentBag<string> JoinGroups = new ConcurrentBag<string>();
|
||
private void JoinGroup(string groupId, string weixinhao)
|
||
{
|
||
try
|
||
{
|
||
if (!JoinGroups.Contains(groupId + "!!!" + weixinhao))
|
||
JoinGroups.Add(groupId + "!!!" + weixinhao);
|
||
}
|
||
catch (Exception ex)
|
||
{ }
|
||
}
|
||
|
||
static bool isRunning = false;
|
||
private static void BindGroupInvite()
|
||
{
|
||
if (!isRunning)
|
||
{
|
||
isRunning = true;
|
||
try
|
||
{
|
||
if (Config.GroupBind == SwitchType.开启)
|
||
{
|
||
if (JoinGroups.Count != 0)
|
||
{
|
||
var joinGroups = JoinGroups.ToList();
|
||
var session = ApiClient.GetSession();
|
||
for (int i = 0; i < joinGroups.Count; i++)
|
||
{
|
||
var temp = joinGroups[i];
|
||
var splits = temp.Split(new string[] { "!!!" }, StringSplitOptions.RemoveEmptyEntries);
|
||
|
||
var wx = ChatClient.WXClient.Values.FirstOrDefault(f => f.WeixinType == WeixinType.Grpc微信 && f.WeixinHao == splits[1] && f.Status == Chat.Framework.WXSdk.WxStatus.在线);
|
||
if (wx == null) continue;
|
||
var members = wx.GetMembers(splits[0], true);
|
||
if (members == null) continue;
|
||
for (int z = 0; z < members.Length; z++)
|
||
{
|
||
var item = members[z];
|
||
var member = session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username", new { username = item.Username });
|
||
if (member == null)
|
||
{
|
||
member = new fl_member_info() { crt_time = DateTime.Now, usernick = item.NickName, robot_name = wx.WeixinHao, robot_type = wx.WeixinType == WeixinType.QYHook微信 ? ChatType.企业微信 : ChatType.微信, username = item.Username, alipay_name = string.Empty, alipay_num = string.Empty, remark = string.Empty };
|
||
session.SaveOrUpdate(member);
|
||
}
|
||
|
||
if (member.inviter_id != 0) continue;
|
||
if (string.IsNullOrWhiteSpace(members[z].InviterUserName)) continue;
|
||
var member_inviter = session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username", new { username = members[z].InviterUserName });
|
||
if (member_inviter != null)
|
||
{
|
||
member.inviter_id = member_inviter.id;
|
||
session.SaveOrUpdate(member);
|
||
}
|
||
}
|
||
JoinGroups.TryTake(out temp);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
EventClient.OnEvent(null, "群绑定上下级异常:" + ex.Message);
|
||
}
|
||
finally
|
||
{
|
||
isRunning = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 微信 - 新成员进群
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void SDK_WXNewMemerEvent(object sender, WXNewMemer e)
|
||
{
|
||
try
|
||
{
|
||
//this.OnLog($"Wx = {e.Client.WeixinHao}" + string.Join("#", Config.NewComerGroupInfo.Keys));
|
||
if (!Config.NewComerGroupInfo.ContainsKey(e.Client.WeixinHao)) return;
|
||
|
||
//this.OnLog($"新人入群:{e.MemberNicks}({e.MemberName}),邀请人:{e.SourceNick}({e.SourceName})");
|
||
|
||
if (sender.GetType() == typeof(WXClientImpl_IPAD))
|
||
JoinGroup(e.GroupId, e.Client.WeixinHao);
|
||
else if (sender.GetType() == typeof(WXClientImpl_HOOK) && Config.GroupBind == SwitchType.开启 && e.Client != null && e.Client.Status == Chat.Framework.WXSdk.WxStatus.在线)
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
var member = session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username", new { username = e.MemberName });
|
||
if (member == null)
|
||
{
|
||
member = new fl_member_info() { crt_time = DateTime.Now, usernick = e.MemberNicks, robot_name = e.Client.WeixinHao, robot_type = e.Client.WeixinType == WeixinType.QYHook微信 ? ChatType.企业微信 : ChatType.微信, username = e.MemberName, alipay_name = string.Empty, alipay_num = string.Empty, remark = string.Empty };
|
||
session.SaveOrUpdate(member);
|
||
}
|
||
|
||
if (member.inviter_id == 0 && !string.IsNullOrWhiteSpace(e.SourceName))
|
||
{
|
||
var member_inviter = session.FindSingle<fl_member_info>("select * from fl_member_info where username = @username", new { username = e.SourceName });
|
||
if (member_inviter != null)
|
||
{
|
||
member.inviter_id = member_inviter.id;
|
||
session.SaveOrUpdate(member);
|
||
}
|
||
}
|
||
}
|
||
|
||
var groups = Config.NewComerGroupInfo[e.Client.WeixinHao];
|
||
if (groups != null && !groups.onoff && !string.IsNullOrWhiteSpace(Config.GroupWelcomeTip) && groups.groupIds.Contains(e.GroupId))
|
||
e.Client.SendMessage(e.Group.UserName, Config.GroupWelcomeTip.Replace("[群昵称]", e.Group.NickName).Replace("[昵称]", e.MemberNicks).Replace("[账号]", e.MemberName));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("NewMemer = " + ex.Message);
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 通用消息
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="e"></param>
|
||
private void SDK_ReciveIMEvent(object sender, ReciveIMEvent e)
|
||
{
|
||
try
|
||
{
|
||
//return;
|
||
//var ss = HttpHelper.URLDecode("%3cmsg+fromusername%3d%22wxid_8s44kddouuaj21%22+encryptusername%3d%22v3_020b3826fd03010000000000a5d42b864ffd71000000501ea9a3dba12f95f6b60a0536a1adb6561f62944a04a2c4fdda9f7b55eb4da2fce833ad6a6599155cf7409f469a16e5c9d7a307a2b7a3d54984f749326f1c871b836e6f1a78b819e881de7f%40stranger%22+fromnickname%3d%22%c7%a7%c4%ea%c0%cf%d1%fd%22+content%3d%22%ce%d2%ca%c7%c7%a7%c4%ea%c0%cf%d1%fd%22+fullpy%3d%22qiannianlaoyao%22+shortpy%3d%22QNLY%22+imagestatus%3d%223%22+scene%3d%2230%22+country%3d%22CN%22+province%3d%22Sichuan%22+city%3d%22Chengdu%22+sign%3d%22%c3%bb%d3%d0%b8%b9%bc%a1%b5%c4%a3%ac%b6%bc%ca%c7%c5%d6%d7%d3%22+percard%3d%221%22+sex%3d%221%22+alias%3d%22my-object%22+weibo%3d%22%22+albumflag%3d%220%22+albumstyle%3d%220%22+albumbgimgid%3d%22%22+snsflag%3d%22273%22+snsbgimgid%3d%22http%3a%2f%2fszmmsns.qpic.cn%2fmmsns%2fA6bBbWlnGV5569R1Oj3I4mBORwqAic2BwzPzthtzlk6LVZ4svk6ExDKibds7l7ibtVSojkjL3A03jk%2f0%22+snsbgobjectid%3d%2213554445051344457821%22+mhash%3d%22823f3771ac7bcfb9bcde1b7efe76673a%22+mfullhash%3d%22823f3771ac7bcfb9bcde1b7efe76673a%22+bigheadimgurl%3d%22http%3a%2f%2fwx.qlogo.cn%2fmmhead%2fver_1%2fzRJZKRa7TNyUvlWQichZsq4aekeCkvVibmzicibh9MFc2JP03AwAwCpbhGtVy4S3otINAM21jc6yYQoahUibBXjLHJ7MNoiakgkfCNuHHQJqJymtE%2f0%22+smallheadimgurl%3d%22http%3a%2f%2fwx.qlogo.cn%2fmmhead%2fver_1%2fzRJZKRa7TNyUvlWQichZsq4aekeCkvVibmzicibh9MFc2JP03AwAwCpbhGtVy4S3otINAM21jc6yYQoahUibBXjLHJ7MNoiakgkfCNuHHQJqJymtE%2f96%22+ticket%3d%22v4_000b708f0b04000001000000000096e0c313574586ca6e8561a44e621000000050ded0b020927e3c97896a09d47e6e9ed1dcf0f5ef4fd59b8e9b5738dfead530b104a0f5e21ae8a3adb686632abc3da249a28815faf08e773472137ebcf6f953e649ddd5c6688ea6efa11292ad0c16c09ebb175ffeb47f63ebab11b4e7e18fa5556a4a076d31f654fa874f98fcc447700e3b4a0a4463f2a5%40stranger%22+opcode%3d%222%22+googlecontact%3d%22%22+qrticket%3d%22%22+chatroomusername%3d%22%22+sourceusername%3d%22%22+sourcenickname%3d%22%22+sharecardusername%3d%22%22+sharecardnickname%3d%22%22+cardversion%3d%22%22+extflag%3d%220%22%3e%3cbrandlist+count%3d%220%22+ver%3d%22768305994%22%3e%3c%2fbrandlist%3e%3c%2fmsg%3e");
|
||
//string result = (sender as WXClientImpl_HOOK).AgreeAddMe(ss);
|
||
|
||
|
||
switch (e.ChatType)
|
||
{
|
||
//case ChatType.未知来源:
|
||
// break;
|
||
case ChatType.QQ:
|
||
case ChatType.微信:
|
||
case ChatType.企业微信:
|
||
{
|
||
if (!string.IsNullOrEmpty(e.Groupid)) return;
|
||
var session = ApiClient.GetSession();
|
||
WeixinBase wx = null;
|
||
//QQClient ipad_qq = null;
|
||
if (e.ChatType == ChatType.微信 || e.ChatType == ChatType.企业微信)
|
||
wx = sender as WeixinBase;
|
||
//else
|
||
//ipad_qq = sender as QQClient;
|
||
|
||
var member = e.GetMemberinfo();
|
||
if (member != null && member.inviter_id == 0)
|
||
{
|
||
if (Regex.IsMatch(e.Message.Trim(), Tools.Rex_Code))//输入的为邀请码格式的数据,不管是否开启强制绑定
|
||
{
|
||
var reg = Regex.Match(e.Message.Trim(), Tools.Rex_Code);
|
||
if (reg.Success)
|
||
{
|
||
var old_member = session.Find<fl_member_info>($"select m.* from fl_member_info m join fl_plugin_userfission_user_invitation_code ic on m.id = ic.member_info_id where ic.code = @code and robot_type = @robotType", new { code = reg.Groups[1].Value, robotType = (int)e.ChatType }).FirstOrDefault();
|
||
//上级用户存在
|
||
if (old_member != null)
|
||
{
|
||
if (member.id == old_member.id)
|
||
{
|
||
e.SendMessage(Config.BindTheInvitationCodeOneselfTip);
|
||
return;
|
||
}
|
||
if (old_member.inviter_id == member.id)
|
||
{
|
||
e.SendMessage(Config.InviteEachOtherTip);
|
||
return;
|
||
}
|
||
|
||
#region 绑定上级操作
|
||
member.inviter_id = old_member.id;
|
||
session.SaveOrUpdate(member);//绑定上级关系
|
||
e.SendMessage(Config.BindTheInvitationCodeSuccessfully.Replace("[邀请人昵称]", old_member.usernick));
|
||
#endregion
|
||
|
||
Thread.Sleep(300);
|
||
|
||
if (Config.SuperiorSumSwitch == SwitchType.开启 && Config.SuperiorRewardWay == ReferralJackpotType.推荐新人立马奖励)
|
||
{
|
||
if (IsSuperiorReward(e.RobotInfo))
|
||
{
|
||
if (Config.SuperiorSum2 < Config.SuperiorSum1) throw new Exception("上级奖励积分设置数据异常,最大奖励值应大于最小值");
|
||
|
||
var _bonusSuperior = Math.Round((new Random().Next(int.Parse(Math.Round(Config.SuperiorSum1 * 100, 2).ToString()), int.Parse(Math.Round(((Config.SuperiorSum2 + 0.01) * 100), 2).ToString()))) / 100d, 2);
|
||
if (e.ChatType == ChatType.微信 && (Config.Superior_RechargeType == RechargeType.发送红包 || Config.Superior_RechargeType == RechargeType.微信转账))
|
||
{
|
||
var passinfo = session.FindWeixinpassword(session.FindRobotInfo(e.RobotInfo.name, e.ChatType).id);//获取微信支付信息
|
||
if (passinfo != null && !string.IsNullOrEmpty(passinfo.password))
|
||
{
|
||
var flag = wx.SendPay(old_member.username, Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonusSuperior.ToString()), (int)((decimal)_bonusSuperior * 100m), passinfo.password, 1, (Config.Superior_RechargeType == RechargeType.发送红包 ? PayType.红包 : PayType.转账), passinfo.GetBank());
|
||
if (!string.IsNullOrEmpty(flag))
|
||
{
|
||
this.OnLog("推荐新人奖励失败:" + flag + ",已添加积分到用户余额!");//发送红包不成功,将积分增加余额
|
||
old_member = session.ChangePoint(PointType.其他奖励, _bonusSuperior, old_member.id, $"推荐新人{member.usernick}-{member.username},奖励积分{_bonusSuperior}【微信红包操作失败】");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("推荐新人奖励失败:未设置支付密码,已添加积分到用户余额!");
|
||
old_member = session.ChangePoint(PointType.其他奖励, _bonusSuperior, old_member.id, $"推荐新人{member.usernick}-{member.username},奖励积分{_bonusSuperior}【微信红包操作失败,未设置支付密码】");
|
||
}
|
||
ApiClient.SendMessage(e.RobotInfo, old_member.username, Config.ImmediateReward_AddANewSubordinateTip.Replace("[使用者昵称]", member.realnick).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[剩余积分]", old_member.cur_point.ToString()));
|
||
}
|
||
else if ((e.ChatType == ChatType.微信 || e.ChatType == ChatType.企业微信) && Config.Superior_RechargeType == RechargeType.商户付款)
|
||
{
|
||
if (_bonusSuperior >= 0.3)
|
||
{
|
||
var ispaid = false;
|
||
object appinfo = null;
|
||
string url = ApiClient.SendWechatPay(new { robot_name = e.RobotInfo.name, robot_nick = e.RobotInfo.nick, username = old_member.username, usernick = old_member.usernick }, Class1.Config.ExchangePacketTitle.Replace("[积分名称]", ApiClient.Setting.SystemConfig.PointName).Replace("[兑换金额]", _bonusSuperior.ToString()), _bonusSuperior, out ispaid, out appinfo);
|
||
if (!string.IsNullOrEmpty(url))
|
||
{
|
||
old_member = session.ChangePoint(PointType.其他奖励, _bonusSuperior, old_member.id, $"推荐新人{member.usernick}-{member.username},奖励积分{_bonusSuperior}");
|
||
Thread.Sleep(20);
|
||
old_member = session.ChangePoint(PointType.提现扣除, _bonusSuperior, old_member.id, $"推荐新人【商户付款成功】 商户链接:{url}");
|
||
|
||
var _mess = string.Empty;
|
||
if (ispaid)
|
||
_mess = Config.SuperiorCommercialEftTip.Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[下级昵称]", member.realnick);
|
||
else
|
||
{
|
||
if (Config.ShangHu_MiNiApp == SwitchType.开启 && appinfo != null)
|
||
_mess = Util.GetMiNiAppXml(appinfo, e.RobotInfo.type);
|
||
if (string.IsNullOrWhiteSpace(_mess))
|
||
_mess = Config.SuperiorCommercialPayTip.Replace("[领取地址]", url/*ApiClient.ShortURL(url).Result*/).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[下级昵称]", member.realnick);
|
||
}
|
||
ApiClient.SendMessage(e.RobotInfo, old_member.username, _mess);
|
||
this.OnLog("商户付款信息 = " + _mess);
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("推荐新人商户付款失败:获取不到商户付款地址,已添加积分到用户余额!");
|
||
old_member = session.ChangePoint(PointType.其他奖励, _bonusSuperior, old_member.id, $"推荐新人{member.usernick}-{member.username},奖励积分{_bonusSuperior}【商户付款操作失败,请求商户链接失败】");
|
||
ApiClient.SendMessage(e.RobotInfo, old_member.username, Config.ImmediateReward_AddANewSubordinateTip.Replace("[使用者昵称]", member.realnick).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[剩余积分]", old_member.cur_point.ToString()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
this.OnLog("推荐新人商户付款失败:奖励积分小于0.3,已添加积分到用户余额!");
|
||
old_member = session.ChangePoint(PointType.其他奖励, _bonusSuperior, old_member.id, $"推荐新人{member.usernick}-{member.username},奖励积分{_bonusSuperior}【商户付款操作失败,积分小于0.3】");
|
||
ApiClient.SendMessage(e.RobotInfo, old_member.username, Config.ImmediateReward_AddANewSubordinateTip.Replace("[使用者昵称]", member.realnick).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[剩余积分]", old_member.cur_point.ToString()));
|
||
}
|
||
}
|
||
else
|
||
{
|
||
old_member = session.ChangePoint(PointType.其他奖励, _bonusSuperior, old_member.id, $"推荐新人{member.usernick}-{member.username},奖励积分{_bonusSuperior}【增加积分操作】");
|
||
ApiClient.SendMessage(e.RobotInfo, old_member.username, Config.ImmediateReward_AddANewSubordinateTip.Replace("[使用者昵称]", member.realnick).Replace("[推荐奖励金额]", _bonusSuperior.ToString()).Replace("[剩余积分]", old_member.cur_point.ToString()));
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ApiClient.SendMessage(e.RobotInfo, old_member.username, Config.FirstSingleReward_AddANewSubordinateTip.Replace("[使用者昵称]", member.realnick).Replace("[剩余积分]", old_member.cur_point.ToString()));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else if (Config.ForcedBind == SwitchType.开启 && !Regex.IsMatch(e.Message.Trim(), Tools.Rex_Code))//强制开启并且输入的非邀请码格式的数据
|
||
{
|
||
e.SendMessage(Config.EnterInvitationCodeTip); return;
|
||
}
|
||
}
|
||
else if (member != null && member.inviter_id != 0 && Regex.IsMatch(e.Message.Trim(), Tools.Rex_Code))//已经有上级的用户
|
||
{
|
||
var count = int.Parse(session.FindRow("select count(*) as num from fl_plugin_userfission_user_invitation_code where code = @code", new { code = e.Message })["num"].ToString());//判断用户输入的是否为有效的邀请码
|
||
if (count != 0)
|
||
{
|
||
e.SendMessage(Config.BindTheInvitationCodeRepeatTip);
|
||
return;
|
||
}
|
||
}
|
||
|
||
#region 用户已经有绑定上级推荐人 或者没有开启强制开启邀请码
|
||
if (member != null && (Config.ForcedBind != SwitchType.开启 || member.inviter_id != 0))
|
||
{
|
||
var memberInfo = session.FindMemberinfo(e);
|
||
//海报功能开启 并且 为获取邀请码
|
||
if ((e.ChatType == ChatType.微信 || e.ChatType == ChatType.企业微信) && Config.ImageDesign == SwitchType.开启 && !string.IsNullOrWhiteSpace(Config.InviteCmd) && Regex.IsMatch(e.Message.Trim(), Config.InviteCmd.ToString()))
|
||
{
|
||
e.SendMessage(Config.PleaseWaitTip);
|
||
Controls control = null;
|
||
//邀请码
|
||
var invitationCode = Tools.FindInvitationCode(memberInfo.id);
|
||
#region 通过海报模板绘制 推广海报
|
||
try
|
||
{
|
||
//上面要先判断上面的图片是否已经加载到panel_Plot中
|
||
var _controls = JsonConvert.DeserializeObject<Dictionary<string, Controls>>(Config.Controlsdic);
|
||
control = _controls["panel_Plot"];
|
||
string url = string.Empty;
|
||
using (Bitmap bmp = new Bitmap(Image.FromFile(Tools.PosterPathImgUrl), control.C_Size))
|
||
{
|
||
using (Graphics g = Graphics.FromImage(bmp))
|
||
{
|
||
//绘制二维码
|
||
control = _controls["pBox_QRcode"];
|
||
string _QRCodeData = string.Empty;
|
||
if (Config.AutoQrCode && wx.GetType() == typeof(WXClientImpl_IPAD))
|
||
{
|
||
var key = "qrcode_wx_" + wx.User.Username;
|
||
_QRCodeData = ApiClient.Cache.Get<string>(key);
|
||
if (string.IsNullOrEmpty(_QRCodeData))
|
||
{
|
||
int count = 0;
|
||
while (count < 3)
|
||
{
|
||
var bitmap = wx.GetRobotQRcode(count != 0 ? true : false);
|
||
//获取机器人的二维码信息
|
||
if (bitmap != null)
|
||
{
|
||
_QRCodeData = Util.DecodeQRCode(bitmap);//解析机器人二维码,获取到二维码的链接
|
||
if (!string.IsNullOrEmpty(_QRCodeData))
|
||
{
|
||
ApiClient.Cache.Set(key, _QRCodeData, 60);
|
||
break;
|
||
}
|
||
}
|
||
count++;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (string.IsNullOrWhiteSpace(_QRCodeData))
|
||
{
|
||
//_QRCodeData = control.C_Tag;//后台二维码的内容
|
||
|
||
var qrCode = Config.QrCodes.FirstOrDefault(f => f.rname == wx.WeixinHao);
|
||
if (qrCode != null)
|
||
_QRCodeData = qrCode.url;
|
||
}
|
||
|
||
if (string.IsNullOrEmpty(_QRCodeData))
|
||
{
|
||
e.SendMessage("合成推广海报失败,请稍后重试!");
|
||
throw new Exception($"合成推广码失败,解析机器人二维码异常.");
|
||
}
|
||
|
||
string logourl = string.Empty;
|
||
if (Config.AutoPicture)
|
||
{
|
||
var robot = wx.GetContact(wx.User.Username);
|
||
if (string.IsNullOrEmpty(robot.BigHeadImgUrl)) robot = wx.GetContact(wx.User.Username, true);
|
||
logourl = robot.BigHeadImgUrl;
|
||
}
|
||
else if (!Config.AutoPicture && !string.IsNullOrEmpty(Config.LogoUrl))
|
||
logourl = Config.LogoUrl.Trim();
|
||
|
||
if (string.IsNullOrEmpty(logourl)) logourl = string.Empty;
|
||
|
||
Bitmap bitmapQrCode = Tools.CreateQRCode(_QRCodeData, logourl, Config.LogoSize, 5);
|
||
bitmapQrCode = new Bitmap(bitmapQrCode, control.C_Size);
|
||
g.DrawImage(bitmapQrCode, control.C_Point);
|
||
//扩展文本1
|
||
control = _controls["lbltxt1"];
|
||
if (control.C_Visible)
|
||
g.DrawString(control.C_Tag.ToString().Replace("[微信账号]", e.RobotName).Replace("[微信名称]", e.RobotNick).Replace("[邀请码]", Tools.FindInvitationCode(memberInfo.id)), JsonConvert.DeserializeObject<Font>(control.T_FontJson), new SolidBrush(control.T_ForeColor), control.C_Point);
|
||
//扩展文本2
|
||
control = _controls["lbltxt2"];
|
||
if (control.C_Visible)
|
||
g.DrawString(control.C_Tag.ToString().Replace("[微信账号]", e.RobotName).Replace("[微信名称]", e.RobotNick).Replace("[邀请码]", Tools.FindInvitationCode(memberInfo.id)), JsonConvert.DeserializeObject<Font>(control.T_FontJson), new SolidBrush(control.T_ForeColor), control.C_Point);
|
||
}
|
||
url = Util.MapFile(Guid.NewGuid().ToString() + ".jpg", "Cache\\Image");
|
||
bmp.Save(url);
|
||
}
|
||
string mess = Config.ReplyToTheInvitationCodePrompt.Replace("[推广海报]", $"[图片={url}]").Replace("[邀请码]", Tools.FindInvitationCode(memberInfo.id)).Replace("[微信号]", wx.WeixinHao);
|
||
e.SendMessage(mess);
|
||
return;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("ex = " + ex.Message);
|
||
}
|
||
#endregion
|
||
}
|
||
//统计邀请
|
||
if (!string.IsNullOrWhiteSpace(Config.RecommendedAmountCmd) && Regex.IsMatch(e.Message.Trim(), Config.RecommendedAmountCmd))
|
||
{
|
||
e.SendMessage(new VariateReplace().CommonReplace(Config.ObtainRecommendationStatistics, e.GetMemberinfo()));
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
break;
|
||
//case ChatType.微信公众号:
|
||
// break;
|
||
//default:
|
||
// break;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog("B:" + ex.Message);
|
||
e.SendMessage(ApiClient.Setting.SystemConfig.msg_error);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取上级奖励是否满足
|
||
/// </summary>
|
||
/// <param name="info"></param>
|
||
/// <returns></returns>
|
||
private bool IsSuperiorReward(fl_robot_info info)
|
||
{
|
||
try
|
||
{
|
||
//if (info == null) return true;
|
||
|
||
if (Config.SuperiorRewardCount <= 0) return true;
|
||
|
||
var beginTime = DateTime.Now.Date.ToString("yyyy-MM-dd HH:mm:ss");
|
||
var endTime = DateTime.Now.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss");
|
||
var session = ApiClient.GetSession();
|
||
var count = session.Find<fl_point_hist>("select * from fl_point_hist where @beginTime <= crt_time and crt_time < @endTime and type = @_type and rid = @rid and message like '推荐新人%'", new { beginTime = beginTime, endTime = endTime, rid = info.id, _type = "其他奖励" }).Count;
|
||
return Config.SuperiorRewardCount > count;
|
||
}
|
||
catch (Exception ex)
|
||
{ }
|
||
return false;
|
||
}
|
||
|
||
}
|
||
}
|