919 lines
54 KiB
C#
919 lines
54 KiB
C#
using Api.Framework;
|
||
using Api.Framework.Enums;
|
||
using Api.Framework.Events;
|
||
using Api.Framework.Model;
|
||
using Api.Framework.SDK;
|
||
using Api.Framework.Timers;
|
||
using Api.Framework.Tools;
|
||
using Chat.Framework;
|
||
using Chat.Framework.WXSdk.Implement;
|
||
using CsharpHttpHelper;
|
||
using Newtonsoft.Json;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text.RegularExpressions;
|
||
using WPHRebate.Entitys;
|
||
using WPHRebate.Properties;
|
||
|
||
namespace WPHRebate
|
||
{
|
||
public class Class1 : Plugin
|
||
{
|
||
public Class1()
|
||
{
|
||
this.Logo = Resources.唯品会;
|
||
this.Name = Resources.PluginName;
|
||
this.Note = Resources.PluginNote;
|
||
}
|
||
|
||
#region 自定义变量
|
||
public static Config Config;
|
||
private MainForm mainForm = null;
|
||
#endregion
|
||
|
||
public override void Start()
|
||
{
|
||
try
|
||
{
|
||
var session = ApiClient.GetSession();
|
||
#region 判断表是否存在,不存在创建表
|
||
if (session.TableExist<fl_plugin_wphrebate_wphtgw>())
|
||
{
|
||
var wphtgws = session.Find<fl_plugin_wphrebate_wphtgw>("select * from fl_plugin_wphrebate_wphtgw").ToList();
|
||
if (wphtgws != null)
|
||
{
|
||
foreach (var item in wphtgws)
|
||
{
|
||
//插入主推广位数据
|
||
session.Insertable(new fl_adzone_info()
|
||
{
|
||
adzone_name = item.pid_chief_name, //推广位名称
|
||
adzone_pid = item.pid_chief, //推广位pid
|
||
adzone_pid_cps_name = item.pid_chief_cps_name, //推广位cps名称
|
||
alliance_id = (int)CpsType.唯品联盟, //联盟id
|
||
robot_id = item.robot_id, //机器人id
|
||
group_id = string.Empty, //群id
|
||
is_download = false, //不下载
|
||
member_id = 0, //私人id
|
||
onoff = item.onoff, //不禁用
|
||
custom_type = Resources.SoftwareType, //自定义类型
|
||
extend = "chief"
|
||
}).ExecuteCommand();
|
||
//插入副推广位数据
|
||
session.Insertable(new fl_adzone_info()
|
||
{
|
||
adzone_name = item.pid_deputy_name, //推广位名称
|
||
adzone_pid = item.pid_deputy, //推广位pid
|
||
adzone_pid_cps_name = item.pid_deputy_cps_name, //推广位cps名称
|
||
alliance_id = (int)CpsType.唯品联盟, //联盟id
|
||
robot_id = item.robot_id, //机器人id
|
||
group_id = string.Empty, //群id
|
||
is_download = false, //不下载
|
||
member_id = 0, //私人id
|
||
onoff = item.onoff, //不禁用
|
||
custom_type = Resources.SoftwareType, //自定义类型
|
||
extend = "deputy"
|
||
}).ExecuteCommand();
|
||
}
|
||
}
|
||
session.DropTable<fl_plugin_wphrebate_wphtgw>();
|
||
}
|
||
#endregion
|
||
|
||
//创建配置文件
|
||
Config = this.ReadConfig<Config>();
|
||
|
||
SDK.ReciveIMEvent += SDK_ReciveIMEvent;
|
||
SDK.OrderNoticeEvent += SDK_OrderNoticeEvent;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
#region 订单事件处理
|
||
private void SDK_OrderNoticeEvent(object sender, OrderNoticeEvent e)
|
||
{
|
||
try
|
||
{
|
||
if (e.Member != null && e.ChatType == CpsType.唯品联盟)
|
||
{
|
||
//是否黑名单
|
||
if (ApiClient.IsBlackFlMemberInfo(e.Member))
|
||
{
|
||
return;
|
||
}
|
||
|
||
var session = ApiClient.GetSession();
|
||
var order = e.Order as fl_order_weipinhui;
|
||
if (order == null) return;
|
||
var robot_info = session.FindRobotInfo(e.Member.robot_name, e.Member.robot_type);
|
||
|
||
if (robot_info != null)
|
||
{
|
||
var mess = string.Empty;
|
||
var point = HttpHelper.JsonToObject<ItemPoint>(order.db_point) as ItemPoint;
|
||
|
||
#region 下单用户订单检测(防撸)
|
||
if (e.Customer == null)
|
||
{
|
||
var prevent_theft_cache = session.FindSingle<fl_prevent_theft_cache>("select * from fl_prevent_theft_cache where order_id = @order_id", new { order_id = order.orderSn });//防止上级多次触发
|
||
if (prevent_theft_cache == null)
|
||
{
|
||
var isHint = false;
|
||
if (!string.IsNullOrWhiteSpace(order.mallId) && e.Member.status != MemberType.白名单)
|
||
{
|
||
#region 同一店铺多次购买(同一商品)
|
||
if (Class1.Config.AShop_SameCommodity_Switch)
|
||
{
|
||
var frequency = session.Find<fl_order_weipinhui>("select * from fl_order_weipinhui where db_userid = @db_userid and goodsId = @goodsId", new { db_userid = order.db_userid, goodsId = order.goodsId }).Count;
|
||
if (Class1.Config.AShop_SameCommodity_Number <= frequency)
|
||
{
|
||
if (Class1.Config.AShop_SameCommodity_OperateType == OperateType.拉入黑名单)
|
||
{
|
||
if (!session.TemporaryBypassedBlack(e.Member))
|
||
{
|
||
e.Member.status = MemberType.黑名单; //拉入黑名单
|
||
session.SaveOrUpdate(e.Member);
|
||
session.FindBlacklistMemberInfos(true);//刷新黑名单缓存
|
||
|
||
ApiClient.SendMessage(robot_info, e.Member.username, new VariateReplace().CommonReplace(Config.Blocked_RestrictTip, order, e.Member, point), order.msg_groupid);
|
||
|
||
ApiClient.SendNoticeMessage($@"嫌疑用户拉黑
|
||
————
|
||
事件类型:订单检测
|
||
微信账号:{robot_info.name}
|
||
微信昵称:{robot_info.nick}
|
||
客户账号:{e.Member.username}
|
||
客户昵称:{e.Member.usernick}
|
||
拉黑原因:用户购买同一商品{frequency}次", Config.notice_robotname);
|
||
e.Cancel = true;
|
||
|
||
{
|
||
prevent_theft_cache = new fl_prevent_theft_cache();
|
||
prevent_theft_cache.operate_type = Class1.Config.AShop_SameCommodity_OperateType;
|
||
prevent_theft_cache.member_id = e.Member.id;
|
||
prevent_theft_cache.item_id = order.goodsId;
|
||
prevent_theft_cache.mall_id = order.mallId;
|
||
prevent_theft_cache.order_id = order.orderSn;
|
||
prevent_theft_cache.cps_type = CpsType.唯品联盟;
|
||
session.Insertable(prevent_theft_cache).ExecuteCommand();
|
||
}
|
||
|
||
if (Config.AShop_SameCommodity_UserTop)
|
||
{
|
||
if (robot_info.type == ChatType.微信)
|
||
{
|
||
var wx = ChatClient.WXClient.Values.FirstOrDefault(f => f.WeixinHao == robot_info.name /*&& f.WeixinType == WeixinType.Grpc微信*/);
|
||
if (wx != null)
|
||
{
|
||
//var ipad = wx as WXClientImpl_IPAD;
|
||
//if (ipad != null)
|
||
// ipad.EditContacts(e.Member.username, EditContactsType.置顶, e.Member.usernick);
|
||
wx.EditContacts(e.Member.username, EditContactsType.置顶, e.Member.usernick);
|
||
}
|
||
}
|
||
}
|
||
|
||
return;
|
||
}
|
||
}
|
||
else if (Class1.Config.AShop_SameCommodity_OperateType == OperateType.通知钉钉群)
|
||
{
|
||
ApiClient.SendNoticeMessage($@"嫌疑用户警告
|
||
————
|
||
事件类型:订单检测
|
||
微信账号:{robot_info.name}
|
||
微信昵称:{robot_info.nick}
|
||
客户账号:{e.Member.username}
|
||
客户昵称:{e.Member.usernick}
|
||
警告原因:用户购买同一商品{frequency}次", Config.notice_robotname);
|
||
isHint = true;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 同一店铺多次购买(不同商品)
|
||
if (!isHint && Class1.Config.AShop_DifferentCommodity_Switch)
|
||
{
|
||
var frequency = session.Find<fl_order_weipinhui>("select * from fl_order_weipinhui where db_userid = @db_userid and mallId = @mallId", new { db_userid = order.db_userid, mallId = order.mallId }).Count;
|
||
if (Class1.Config.AShop_DifferentCommodity_Number <= frequency)
|
||
{
|
||
if (Class1.Config.AShop_DifferentCommodity_OperateType == OperateType.拉入黑名单)
|
||
{
|
||
if (!session.TemporaryBypassedBlack(e.Member))
|
||
{
|
||
e.Member.status = MemberType.黑名单; //拉入黑名单
|
||
session.SaveOrUpdate(e.Member);
|
||
session.FindBlacklistMemberInfos(true);//刷新黑名单缓存
|
||
|
||
ApiClient.SendMessage(robot_info, e.Member.username, new VariateReplace().CommonReplace(Config.Blocked_RestrictTip, order, e.Member, point), order.msg_groupid);
|
||
|
||
ApiClient.SendNoticeMessage($@"嫌疑用户拉黑
|
||
————
|
||
事件类型:订单检测
|
||
微信账号:{robot_info.name}
|
||
微信昵称:{robot_info.nick}
|
||
客户账号:{e.Member.username}
|
||
客户昵称:{e.Member.usernick}
|
||
拉黑原因:用户在同家店铺购买{frequency}次", Config.notice_robotname);
|
||
e.Cancel = true;
|
||
|
||
{
|
||
prevent_theft_cache = new fl_prevent_theft_cache();
|
||
prevent_theft_cache.operate_type = Class1.Config.AShop_DifferentCommodity_OperateType;
|
||
prevent_theft_cache.member_id = e.Member.id;
|
||
prevent_theft_cache.item_id = order.goodsId;
|
||
prevent_theft_cache.mall_id = order.mallId;
|
||
prevent_theft_cache.order_id = order.orderSn;
|
||
prevent_theft_cache.cps_type = CpsType.唯品联盟;
|
||
session.Insertable(prevent_theft_cache).ExecuteCommand();
|
||
}
|
||
|
||
if (Config.AShop_DifferentCommodity_UserTop)
|
||
{
|
||
if (robot_info.type == ChatType.微信)
|
||
{
|
||
var wx = ChatClient.WXClient.Values.FirstOrDefault(f => f.WeixinHao == robot_info.name /*&& f.WeixinType == WeixinType.Grpc微信*/);
|
||
if (wx != null)
|
||
{
|
||
//var ipad = wx as WXClientImpl_IPAD;
|
||
//if (ipad != null)
|
||
// ipad.EditContacts(e.Member.username, EditContactsType.置顶, e.Member.usernick);
|
||
wx.EditContacts(e.Member.username, EditContactsType.置顶, e.Member.usernick);
|
||
}
|
||
}
|
||
}
|
||
|
||
return;
|
||
}
|
||
}
|
||
else if (Class1.Config.AShop_DifferentCommodity_OperateType == OperateType.通知钉钉群)
|
||
{
|
||
ApiClient.SendNoticeMessage($@"嫌疑用户警告
|
||
————
|
||
事件类型:订单检测
|
||
微信账号:{robot_info.name}
|
||
微信昵称:{robot_info.nick}
|
||
客户账号:{e.Member.username}
|
||
客户昵称:{e.Member.usernick}
|
||
警告原因:用户在同家店铺购买{frequency}次", Config.notice_robotname);
|
||
isHint = true;
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
#region 收货时间验证时长
|
||
if (!isHint && Class1.Config.ReceivingTimeCheck_Switch && order.orderSubStatusName == WeipinhuiOrderSubStatusName.已签收 && e.Member.status != MemberType.白名单)
|
||
{
|
||
if (DateTime.Now != DateTime.MinValue)
|
||
{
|
||
var timeLag = (int)Math.Floor((DateTime.Now - Util.GetDateTime(order.orderTime)).TotalHours);
|
||
if (timeLag <= Class1.Config.ReceivingTimeCheck_Hour)
|
||
{
|
||
if (Class1.Config.ReceivingTimeCheck_OperateType == OperateType.拉入黑名单)
|
||
{
|
||
if (!session.TemporaryBypassedBlack(e.Member))
|
||
{
|
||
e.Member.status = MemberType.黑名单; //拉入黑名单
|
||
session.SaveOrUpdate(e.Member);
|
||
session.FindBlacklistMemberInfos(true);//刷新黑名单缓存
|
||
|
||
ApiClient.SendMessage(robot_info, e.Member.username, new VariateReplace().CommonReplace(Config.Blocked_RestrictTip, order, e.Member, point), order.msg_groupid);
|
||
|
||
ApiClient.SendNoticeMessage($@"嫌疑用户拉黑
|
||
————
|
||
事件类型:订单检测
|
||
微信账号:{robot_info.name}
|
||
微信昵称:{robot_info.nick}
|
||
客户账号:{e.Member.username}
|
||
客户昵称:{e.Member.usernick}
|
||
拉黑原因:订单收货时间间隔{timeLag}小时", Config.notice_robotname);
|
||
e.Cancel = true;
|
||
|
||
{
|
||
prevent_theft_cache = new fl_prevent_theft_cache();
|
||
prevent_theft_cache.operate_type = Class1.Config.ReceivingTimeCheck_OperateType;
|
||
prevent_theft_cache.member_id = e.Member.id;
|
||
prevent_theft_cache.item_id = order.goodsId;
|
||
prevent_theft_cache.mall_id = order.mallId;
|
||
prevent_theft_cache.order_id = order.orderSn;
|
||
prevent_theft_cache.cps_type = CpsType.唯品联盟;
|
||
session.Insertable(prevent_theft_cache).ExecuteCommand();
|
||
}
|
||
|
||
if (Config.ReceivingTimeCheck_UserTop)
|
||
{
|
||
if (robot_info.type == ChatType.微信)
|
||
{
|
||
var wx = ChatClient.WXClient.Values.FirstOrDefault(f => f.WeixinHao == robot_info.name /*&& f.WeixinType == WeixinType.Grpc微信 */);
|
||
if (wx != null)
|
||
{
|
||
//var ipad = wx as WXClientImpl_IPAD;
|
||
//if (ipad != null)
|
||
// ipad.EditContacts(e.Member.username, EditContactsType.置顶, e.Member.usernick);
|
||
wx.EditContacts(e.Member.username, EditContactsType.置顶, e.Member.usernick);
|
||
}
|
||
}
|
||
}
|
||
|
||
return;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ApiClient.SendNoticeMessage($@"嫌疑用户警告
|
||
————
|
||
事件类型:订单检测
|
||
微信账号:{robot_info.name}
|
||
微信昵称:{robot_info.nick}
|
||
客户账号:{e.Member.username}
|
||
客户昵称:{e.Member.usernick}
|
||
警告原因:订单收货时间间隔{timeLag}小时", Config.notice_robotname);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
switch (e.OrderNoticeType)
|
||
{
|
||
case OrderNoticeType.客户订单:
|
||
if (Config.UserOrderChangeSwitch == SwitchType.开启 && !ApiClient.Setting.SystemConfig.message_warning_switch)
|
||
{
|
||
mess = _GetOrderStateMess(order.db_status, order, e.Member, point);
|
||
if (!string.IsNullOrEmpty(e.Member.username) && !string.IsNullOrEmpty(mess))
|
||
ApiClient.SendMessage(robot_info, e.Member.username, mess, order.msg_groupid);
|
||
}
|
||
return;
|
||
case OrderNoticeType.一级提成:
|
||
if (Config.AgentReceivedCommissionSwitch == SwitchType.开启)
|
||
{
|
||
if (e.Customer != null && point.AwardOne != 0)
|
||
{
|
||
if (order.db_status == SystemOrderStatus.订单维权中)
|
||
mess = Config.ClientOrderRefund_OneLevelTip;
|
||
if (order.db_status == SystemOrderStatus.订单付款)
|
||
mess = Config.OrderPaymentInform_OneLevelTip;
|
||
else if (order.db_status == SystemOrderStatus.订单失效)
|
||
mess = Config.OrderCountermandInform_OneLevelTip;
|
||
else if (order.db_status == SystemOrderStatus.订单结算)
|
||
mess = Config.OrderSettlement_OneLevelTip;
|
||
}
|
||
}
|
||
break;
|
||
case OrderNoticeType.二级提成:
|
||
if (Config.AgentReceivedCommissionSwitch == SwitchType.开启)
|
||
{
|
||
if (e.Customer != null)
|
||
{
|
||
if (order.db_status == SystemOrderStatus.订单维权中)
|
||
mess = Config.ClientOrderRefund_TwoLevelTip;
|
||
if (order.db_status == SystemOrderStatus.订单付款)
|
||
mess = Config.OrderPaymentInform_TwoLevelTip;
|
||
else if (order.db_status == SystemOrderStatus.订单失效)
|
||
mess = Config.OrderCountermandInform_TwoLevelTip;
|
||
else if (order.db_status == SystemOrderStatus.订单结算)
|
||
mess = Config.OrderSettlement_TwoLevelTip;
|
||
}
|
||
}
|
||
break;
|
||
case OrderNoticeType.三级提成:
|
||
if (Config.AgentReceivedCommissionSwitch == SwitchType.开启)
|
||
{
|
||
if (e.Customer != null)
|
||
{
|
||
if (order.db_status == SystemOrderStatus.订单维权中)
|
||
mess = Config.ClientOrderRefund_ThreeLevelTip;
|
||
if (order.db_status == SystemOrderStatus.订单付款)
|
||
mess = Config.OrderPaymentInform_ThreeLevelTip;
|
||
else if (order.db_status == SystemOrderStatus.订单失效)
|
||
mess = Config.OrderCountermandInform_ThreeLevelTip;
|
||
else if (order.db_status == SystemOrderStatus.订单结算)
|
||
mess = Config.OrderSettlement_ThreeLevelTip;
|
||
}
|
||
}
|
||
break;
|
||
case OrderNoticeType.群主分成:
|
||
if (Config.PrincipalReceivedCommissionSwitch == SwitchType.开启)
|
||
{
|
||
if (e.Customer != null)
|
||
{
|
||
if (order.db_status == SystemOrderStatus.订单维权中)
|
||
mess = Config.ClientOrderRefund_LeaderTip;
|
||
if (order.db_status == SystemOrderStatus.订单付款)
|
||
mess = Config.OrderPaymentInform_LeaderTip;
|
||
else if (order.db_status == SystemOrderStatus.订单失效)
|
||
mess = Config.OrderCountermandInform_LeaderTip;
|
||
else if (order.db_status == SystemOrderStatus.订单结算)
|
||
mess = Config.OrderSettlement_LeaderTip;
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
if (!ApiClient.Setting.SystemConfig.message_warning_switch && !string.IsNullOrEmpty(e.Member.username) && !string.IsNullOrWhiteSpace(mess))
|
||
{
|
||
ApiClient.SendMessage(robot_info, e.Member.username, new VariateReplace().CommonReplace(mess, order, e.Member, point).Replace("[下级昵称]", e.Customer.realnick ?? ""));
|
||
}
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog($"唯品会订单通知异常:{ex.Message},{ex.StackTrace}");
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 消息事件处理
|
||
private void SDK_ReciveIMEvent(object sender, ReciveIMEvent e)
|
||
{
|
||
Compute compute = null;
|
||
var goodsName = string.Empty;
|
||
try
|
||
{
|
||
//过滤表情xml和卡片xml
|
||
if (((e.Message.Contains(@"<appmsg appid=") && !e.Message.Contains("唯品")) || e.Message.StartsWith("[声音=") || e.Message.Contains(@"<msg><emoji")) && !e.Message.Contains(@"点击链接,再选择浏览器咑閞")) return;
|
||
if (!OrderHelper.IsCurrentCpsMess(e.Message, CpsType.唯品联盟)) return;
|
||
|
||
string message = e.Message;
|
||
|
||
var session = ApiClient.GetSession();
|
||
var member = e.GetMemberinfo();
|
||
#region 唯品会订单绑定
|
||
var messTmp = e.Message.Trim();
|
||
if (Regex.IsMatch(e.Message.Trim(), @"^\d{14}$"))
|
||
{
|
||
int i = 0;
|
||
Next:
|
||
var orderid = e.Message.Trim();
|
||
|
||
//通过宝贝的id 和 订单号 进行查询 查看是否存在
|
||
var orders = session.Find<fl_order_weipinhui>("select * from fl_order_weipinhui where orderSn = @orderSn", new { orderSn = orderid });
|
||
if (orders != null && orders.Count != 0)
|
||
{
|
||
var notices = new List<OrderNoticeEvent>();
|
||
var downWeipinhuiTimer = new DownWeipinhuiTimer();
|
||
foreach (var order in orders)
|
||
{
|
||
if (order.db_userid != 0 && order.db_userid != member.id)
|
||
{
|
||
e.SendMessage(Config.OccupyOrderErrorTip.Replace("[订单号]", orderid));
|
||
return;
|
||
}
|
||
|
||
if (order.db_userid != 0)
|
||
{
|
||
var point = HttpHelper.JsonToObject<ItemPoint>(order.db_point) as ItemPoint;
|
||
member = e.GetMemberinfo(true);
|
||
if (order.db_status == SystemOrderStatus.订单付款)
|
||
e.SendMessage(new VariateReplace().CommonReplace(Config.OrderRepetBindTip, order, member, point));
|
||
else
|
||
e.SendMessage(_GetOrderStateMess(order.db_status, order, member, point));
|
||
}
|
||
else
|
||
{
|
||
if (Util.GetDateTime(order.orderTime) < ApiClient.Setting.SystemConfig.allow_bind_create_order_time)
|
||
{
|
||
e.SendMessage($"订单:{orderid},已经过了有效绑定时间!");
|
||
return;
|
||
}
|
||
|
||
if (order.db_status == SystemOrderStatus.订单结算)
|
||
order.db_endtime = DateTime.Now.AddMinutes(-5);//重新结算的话,需要将订单的冻结时间重新赋值,让后台处理
|
||
//用户绑定订单
|
||
order.db_robotname = e.RobotName;
|
||
order.db_robottype = e.ChatType;
|
||
order.msg_groupid = e.Groupid;
|
||
order.db_userid = member.id;
|
||
session.SaveOrUpdate(order);
|
||
|
||
if (member != null)
|
||
{
|
||
member.bind_order++;
|
||
member = session.UpdateMemberGroup(member);
|
||
}
|
||
|
||
#region 首次付款时间
|
||
var record = session.FindStatisticsRecord(member.id);
|
||
if (record == null)
|
||
{
|
||
record = new fl_statistics_record() { uid = member.id, ex2 = 0, ex4 = CsharpHttpHelper.HttpExtend.GetTimeStamp(DateTime.Now) };
|
||
session.Saveable<fl_statistics_record>(record).ExecuteCommand();
|
||
}
|
||
else
|
||
{
|
||
if (record.ex2 == 0 && record.ex4 == 0)
|
||
{
|
||
record.ex4 = CsharpHttpHelper.HttpExtend.GetTimeStamp(DateTime.Now);
|
||
session.Saveable<fl_statistics_record>(record).ExecuteCommand();
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
downWeipinhuiTimer.UpdateOrder(order, session, notices, isFrontData: true);
|
||
}
|
||
}
|
||
#region 触发通知上级获得下级的提成奖励
|
||
if (!ApiClient.Setting.SystemConfig.message_warning_switch && notices.Count != 0)
|
||
{
|
||
var tasks = TimerTask.GetTimer<Update_NoticeQueue>() as Update_NoticeQueue;
|
||
foreach (var item in notices)
|
||
{
|
||
//if (item.IsRewards)
|
||
tasks.Add(item);
|
||
//else
|
||
//SDK_OrderNoticeEvent(this, item);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
e.Cancel = true;
|
||
}
|
||
else
|
||
{
|
||
if (i < 1)
|
||
{
|
||
CpsClient.UpdateOrder(CpsType.唯品联盟, DateTime.Now.AddMinutes(-30), DateTime.Now, orderid);
|
||
i++;
|
||
goto Next;
|
||
}
|
||
e.SendMessage(Config.NotFoundOrderErrorTip.Replace("[订单号]", orderid));
|
||
e.Cancel = true;
|
||
return;
|
||
}
|
||
}
|
||
|
||
if (OrderHelper.IsOrderId(e.Message.Trim()))
|
||
return;
|
||
#endregion
|
||
|
||
#region 关键词解析、链接解析、标题查找 临时注释
|
||
var wphinfoTemps = session.FindWphInfoTempGroups();
|
||
var wphInfoTemp = wphinfoTemps.FirstOrDefault(f => f.name == e.RobotInfo.name && f.onoff == false);
|
||
if (wphInfoTemp == null) return;
|
||
|
||
var item_id = WPHHelper.GetWphGoodsID(message);
|
||
if (string.IsNullOrWhiteSpace(item_id))
|
||
return;
|
||
|
||
fl_cps_member wph_cps = null;
|
||
var pid = string.Empty;//使用的推广位
|
||
|
||
var isDefault = true;
|
||
if (!string.IsNullOrWhiteSpace(e.Groupid))//群pid
|
||
{
|
||
var groupAdzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType.唯品联盟 && f.custom_type == PrivateAdzoneCustomType.群pid.ToString() && f.group_id == e.Groupid);
|
||
if (groupAdzone != null && !string.IsNullOrWhiteSpace(groupAdzone.adzone_pid))
|
||
{
|
||
string username = groupAdzone.adzone_pid_cps_name;
|
||
pid = groupAdzone.adzone_pid;
|
||
wph_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.唯品联盟 && f.username == username);
|
||
isDefault = false;
|
||
}
|
||
}
|
||
|
||
if (isDefault)//私人pid
|
||
{
|
||
var memberAdzone = session.FindAdzoneInfos().FirstOrDefault(f => f.alliance_id == (int)CpsType.唯品联盟 && f.custom_type == PrivateAdzoneCustomType.用户私人pid.ToString() && f.member_id == member.id);
|
||
if (memberAdzone != null && !string.IsNullOrWhiteSpace(memberAdzone.adzone_pid))//私人推广位
|
||
{
|
||
string username = memberAdzone.adzone_pid_cps_name;
|
||
wph_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.唯品联盟 && f.username == username);
|
||
pid = memberAdzone.adzone_pid;
|
||
isDefault = false;
|
||
}
|
||
}
|
||
|
||
if (isDefault)//默认推广位
|
||
{
|
||
wph_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.唯品联盟 && f.username == ((member.buy_point >= Config.Point && member.finish_order >= Config.OrderNum) ? wphInfoTemp.pid_chief_cps_name : wphInfoTemp.pid_deputy_cps_name));//通过判断用户的购物积分,来判断用户使用哪个推广位
|
||
pid = ((member.buy_point >= Config.Point && member.finish_order >= Config.OrderNum) ? wphInfoTemp.pid_chief : wphInfoTemp.pid_deputy);
|
||
}
|
||
|
||
if (wph_cps == null) throw new Exception("@唯品联盟推广位异常,请检测后重试!");
|
||
if (string.IsNullOrWhiteSpace(pid)) throw new Exception("@唯品联盟推广位为空,请检测后重试!");
|
||
|
||
if (!wph_cps.is_valid)
|
||
return;
|
||
|
||
var api = CpsClient.CreateWeipinhuiRequest(wph_cps);
|
||
if (api == null) throw new Exception("@创建唯品联盟API请求失败");
|
||
|
||
|
||
#region 判断商品Id是否为屏蔽的商品
|
||
if (Class1.Config.ItemIDRestrictList.Contains(item_id))
|
||
{
|
||
e.SendMessage(Config.ItemIDRestrictTip.Replace("[商品ID]", item_id));
|
||
return;
|
||
}
|
||
#endregion
|
||
|
||
if (!ApiClient.Setting.SystemConfig.message_warning_switch)
|
||
e.SendMessage(Config.SearchingTip);//正在搜索提示
|
||
|
||
try
|
||
{
|
||
//Dictionary<string, object> privilege = null;
|
||
|
||
//var chanTag = Util.EncryptDES($"r={e.RobotInfo.id} t={(int)e.ChatType} u={e.GetMemberinfo().id} p={pid}");
|
||
var chanTag = Util.EncryptDES($"r={e.RobotInfo.id} t={(int)e.ChatType} un={e.GetMemberinfo().username} p={pid}");
|
||
|
||
var wphGInfo = api.SendWeipinhui<WphGoodsInfo>("com.vip.adp.api.open.service.UnionGoodsService-1.0.0#getByGoodsIdsWithOauth", new { goodsIdList = new List<string> { item_id }, requestId = Util.GetUUID(), chanTag = chanTag });
|
||
|
||
if (wphGInfo == null || wphGInfo.result == null || wphGInfo.returnCode == null || wphGInfo.returnCode != "0")
|
||
throw new Exception("@..");
|
||
|
||
foreach (var item in wphGInfo.result)
|
||
{
|
||
if (item.commissionRate == "0")
|
||
{
|
||
throw new Exception("@商品佣金为0");
|
||
}
|
||
|
||
#region 判断店铺ID是否为屏蔽的店铺
|
||
if (item.storeInfo != null)
|
||
{
|
||
if (Config.SellerIDRestrictlist.Contains(item.storeInfo.storeId))
|
||
{
|
||
e.SendMessage(Config.SellerIDRestrictTip.Replace("[店铺ID]", item.storeInfo.storeId).Replace("[店铺名称]", item.storeInfo.storeName));
|
||
return;
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
//优惠券金额
|
||
var coupon_price = 0.00d;
|
||
|
||
bool isHideCoupon = false;//是否为隐藏优惠券
|
||
var hideUrl = string.Empty;//隐藏优惠券的地址
|
||
//优惠券地址
|
||
//var coupon_click_url = string.Empty;
|
||
if (Config.NoCouponModeSwitch != SwitchType.开启)
|
||
{
|
||
if (item.exclusiveCoupon != null)//隐藏优惠券
|
||
{
|
||
var nowTime = Util.GetTimeSpan(DateTime.Now, true);
|
||
if (item.exclusiveCoupon.activateBeginTime <= nowTime && nowTime < item.exclusiveCoupon.activateEndTime)
|
||
{
|
||
var buy = double.Parse(item.exclusiveCoupon.buy);//使用门槛
|
||
if (double.Parse(item.vipPrice) >= buy)
|
||
{
|
||
coupon_price = double.Parse(item.exclusiveCoupon.fav);//优惠金额
|
||
isHideCoupon = true;
|
||
hideUrl = item.exclusiveCoupon.receiveUrl;
|
||
}
|
||
}
|
||
}
|
||
|
||
if (!isHideCoupon && item.couponInfo != null)//有券
|
||
{
|
||
//优惠券没有过期
|
||
if (item.couponInfo.useEndTime >= Util.GetTimeSpan(DateTime.Now, true))
|
||
{
|
||
coupon_price = double.Parse(item.couponInfo.fav);
|
||
//coupon_click_url = item.couponInfo.receiveUrl;
|
||
}
|
||
}
|
||
}
|
||
//商品标题//< >&"© <,>,&,",©;
|
||
goodsName = item.goodsName.Replace("", "").Replace("<", "<").Replace(">", ">").Replace("&", "&").Replace(""", "\"").Replace(" ©", "©");
|
||
|
||
var vipPrice = double.Parse(item.vipPrice);
|
||
|
||
var endPrice = vipPrice;
|
||
if (coupon_price != 0)
|
||
endPrice = (double)((decimal)vipPrice - (decimal)coupon_price);
|
||
|
||
//佣金比例
|
||
var commissionRate = double.Parse(item.commissionRate);
|
||
|
||
//券后 总佣金
|
||
var useCoupon_totalCommFee = Math.Round(endPrice * (commissionRate / 100.00), 2);
|
||
//用券后 给用户的佣金
|
||
var useCoupon_commFee = session.FindItemPoint(member, useCoupon_totalCommFee, 1, CpsType.唯品联盟, out compute);
|
||
|
||
Compute compute1 = null;
|
||
|
||
//不用券 佣金
|
||
var unuseCoupon_totalCommFee = Math.Round(vipPrice * (commissionRate / 100.00), 2);
|
||
//不用券 给用户的佣金
|
||
var unuseCoupon_commFee = session.FindItemPoint(member, unuseCoupon_totalCommFee, 1, CpsType.唯品联盟, out compute1);
|
||
|
||
if (compute == null)
|
||
compute = compute1;
|
||
|
||
var storeName = item.storeInfo == null ? string.Empty : item.storeInfo.storeName;
|
||
|
||
WPHCpsUrl result = null;
|
||
if (isHideCoupon && !string.IsNullOrWhiteSpace(hideUrl))//这里隐藏优惠券
|
||
{
|
||
result = new WPHHelper().GetCpsUrl_Hide(api, new { urlList = new List<string>() { hideUrl }, chanTag = pid, requestId = Util.GetUUID(), statParam = chanTag });
|
||
}
|
||
else
|
||
{
|
||
result = new WPHHelper().GetCpsUrl(api, new { goodsIdList = new List<string>() { item_id }, chanTag = pid, requestId = Util.GetUUID(), statParam = chanTag });
|
||
}
|
||
if (result == null || result.returnCode == null || result.returnCode != "0")
|
||
throw new Exception($"唯品会转链异常,是否隐藏券:{(isHideCoupon ? "是" : "否")}," + HttpHelper.ObjectToJson(result));
|
||
|
||
var couponUrl = (result.result != null && result.result.urlInfoList.Count != 0) ? result.result.urlInfoList[0].url : string.Empty;
|
||
|
||
#region 正常订单
|
||
//有券的情况
|
||
if (coupon_price != 0)
|
||
{
|
||
var mess = string.Empty;
|
||
if (e.ChatType == ChatType.微信 || e.ChatType == ChatType.企业微信 || (e.ChatType == ChatType.QQ && string.IsNullOrWhiteSpace(Config.QQSearchSuccessWithCouponTip)))
|
||
mess = Config.SearchSuccessWithCouponTip;
|
||
else
|
||
mess = Config.QQSearchSuccessWithCouponTip;
|
||
|
||
e.SendMessage(mess
|
||
.Replace("劵", "券")
|
||
.Replace("[商品标题]", mess.Contains("<appmsg") ? goodsName.Replace("<", "").Replace(">", "") : goodsName)
|
||
.Replace("[商品原价]", string.Format("{0:F}", vipPrice))
|
||
.Replace("[商品主图]", $"[图片={item.goodsMainPicture}]")
|
||
.Replace("[图片地址]", item.goodsMainPicture)
|
||
.Replace("[店铺名称]", storeName)
|
||
.Replace("[券后返利]", string.Format("{0:F}", useCoupon_commFee.UserPoint))
|
||
.Replace("[弃券返利]", string.Format("{0:F}", unuseCoupon_commFee.UserPoint))
|
||
.Replace("[券后价]", string.Format("{0:F}", endPrice))
|
||
.Replace("[优惠券金额]", string.Format("{0:F}", coupon_price))
|
||
.Replace("[购买地址]", couponUrl)
|
||
.Replace("[共节省]", ((decimal)coupon_price + (decimal)useCoupon_commFee.UserPoint).ToString())
|
||
.Replace("[商品图片]", mess.Contains("[商品图片]") ? "[图片=" + ApiClient.GetQRImage(goodsName, string.Format("{0:F}", vipPrice), string.Format("{0:F}", coupon_price), string.Format("{0:F}", endPrice), item.goodsMainPicture, couponUrl, ApiClient.QrImageType.模板B, CpsType.唯品联盟) + "]" : string.Empty)
|
||
);
|
||
}
|
||
else//没有券的情况
|
||
{
|
||
var mess = string.Empty;
|
||
if (e.ChatType == ChatType.微信 || e.ChatType == ChatType.企业微信 || (e.ChatType == ChatType.QQ && string.IsNullOrWhiteSpace(Config.QQSearchSuccessWithoutCouponTip)))
|
||
mess = Config.SearchSuccessWithoutCouponTip;
|
||
else
|
||
mess = Config.QQSearchSuccessWithoutCouponTip;
|
||
|
||
e.SendMessage(mess
|
||
.Replace("[商品标题]", mess.Contains("<appmsg") ? goodsName.Replace("<", "").Replace(">", "") : goodsName)
|
||
.Replace("[商品原价]", string.Format("{0:F}", vipPrice))
|
||
.Replace("[商品主图]", $"[图片={item.goodsMainPicture}]")
|
||
.Replace("[图片地址]", item.goodsMainPicture)
|
||
.Replace("[店铺名称]", storeName)
|
||
.Replace("[返利积分]", string.Format("{0:F}", unuseCoupon_commFee.UserPoint))
|
||
.Replace("[购买地址]", couponUrl)
|
||
.Replace("[共节省]", string.Format("{0:F}", useCoupon_commFee.UserPoint))
|
||
.Replace("[商品图片]", mess.Contains("[商品图片]") ? "[图片=" + ApiClient.GetQRImage(goodsName, string.Format("{0:F}", vipPrice), "0", string.Format("{0:F}", vipPrice), item.goodsMainPicture, couponUrl, ApiClient.QrImageType.模板B, CpsType.唯品联盟) + "]" : string.Empty)
|
||
);
|
||
}
|
||
#endregion
|
||
|
||
#region 记录用户信息,宝贝信息,平台信息,查询时间等
|
||
session.Insertable(new fl_query_hist()
|
||
{
|
||
crt_time = DateTime.Now,
|
||
type = CpsType.唯品联盟,
|
||
itemid = item_id,
|
||
groupid = e.Groupid,
|
||
robot_name = e.RobotName,
|
||
robot_type = e.ChatType,
|
||
userid = member.id,
|
||
title = goodsName,
|
||
adzoneid = pid,
|
||
mallid = item.storeInfo == null ? string.Empty : item.storeInfo.storeId,
|
||
compute_configdic = compute == null ? string.Empty : JsonConvert.SerializeObject(compute)
|
||
}).ExecuteCommand();
|
||
session.UpdateRecord(member.id);
|
||
|
||
var shared = new Dictionary<string, object>();
|
||
shared["msg_type"] = "查询宝贝";
|
||
shared["cps_type"] = CpsType.唯品联盟;
|
||
shared["msg_username"] = member.username;
|
||
shared["price"] = string.Format("{0:F}", vipPrice);
|
||
shared["title"] = goodsName;
|
||
shared["coupon_price"] = string.Format("{0:F}", (coupon_price != 0 ? coupon_price : 0));
|
||
shared["user_point"] = coupon_price != 0 ? string.Format("{0:F}", useCoupon_commFee.UserPoint) : string.Format("{0:F}", unuseCoupon_commFee.UserPoint);
|
||
shared["economize"] = string.Format("{0:F}", (coupon_price != 0 ? ((decimal)coupon_price + (decimal)useCoupon_commFee.UserPoint) : (decimal)useCoupon_commFee.UserPoint));
|
||
|
||
var sharedEvent = new SharedEvents(shared);
|
||
EventClient.OnEvent(sender, sharedEvent);
|
||
#endregion
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
e.SendMessage(Config.SearchNoCommissionTip.Replace("[关键词]", goodsName).Replace("[商品标题]", goodsName));//未搜索到提示语
|
||
|
||
var db = ApiClient.GetSession();
|
||
db.UpdateRecord(e.GetMemberinfo().id);
|
||
var shared = new Dictionary<string, object>();
|
||
shared["msg_type"] = "查询宝贝";
|
||
shared["cps_type"] = CpsType.唯品联盟;
|
||
shared["msg_username"] = e.GetMemberinfo().username;
|
||
shared["price"] = "未知";
|
||
shared["title"] = goodsName;
|
||
shared["coupon_price"] = "未知";
|
||
shared["user_point"] = "未知";
|
||
shared["economize"] = "未知";
|
||
|
||
var sharedEvent = new SharedEvents(shared);
|
||
EventClient.OnEvent(sender, sharedEvent);
|
||
throw ex;
|
||
}
|
||
#endregion
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
if (ex.Message.StartsWith("@"))
|
||
this.OnLog($"W :({e.RobotInfo.nick}【{e.RobotInfo.name}】){ex.Message.Replace("@", "")}");
|
||
else
|
||
this.OnLog($"W:({e.RobotInfo.nick}【{e.RobotInfo.name}】){ex.Message} - {ex.StackTrace}");
|
||
this.OnLog(ApiClient.Setting.SystemConfig.msg_error);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
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
|
||
{
|
||
SessionExt.Clear();
|
||
if (mainForm != null)
|
||
{
|
||
mainForm.CloseForm();
|
||
mainForm = null;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.OnLog(ex.Message);
|
||
}
|
||
}
|
||
|
||
#region 变量替换
|
||
/// <summary>
|
||
/// 订单状态 提示语替换
|
||
/// </summary>
|
||
/// <param name="order"></param>
|
||
/// <param name="objs"></param>
|
||
/// <returns></returns>
|
||
private string _GetOrderStateMess(SystemOrderStatus order, params object[] objs)
|
||
{
|
||
|
||
var mess = string.Empty;
|
||
switch (order)
|
||
{
|
||
case SystemOrderStatus.订单付款:
|
||
mess = new VariateReplace().CommonReplace(Config.OrderPaymentTip, objs);
|
||
break;
|
||
case SystemOrderStatus.订单失效:
|
||
mess = new VariateReplace().CommonReplace(Config.OrderFailureTip, objs);
|
||
break;
|
||
case SystemOrderStatus.全额退款:
|
||
case SystemOrderStatus.部分退款:
|
||
case SystemOrderStatus.订单维权中:
|
||
mess = new VariateReplace().CommonReplace(Config.OrderRefundTip, objs);
|
||
break;
|
||
case SystemOrderStatus.订单结算:
|
||
mess = new VariateReplace().CommonReplace(Config.OrderSettlementTip, objs);
|
||
break;
|
||
case SystemOrderStatus.订单冻结:
|
||
mess = new VariateReplace().CommonReplace(Config.OrderFreezeTip, objs);
|
||
break;
|
||
}
|
||
return mess;
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
} |