old_flsystem/应用/PDDRebate/Class1.cs

1042 lines
66 KiB
C#
Raw Normal View History

2022-09-20 03:10:29 +00:00
using Api.Framework;
using Api.Framework.SDK;
using Api.Framework.Tools;
using PDDRebate.Entitys;
using PDDRebate.Properties;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Api.Framework.Model;
using Api.Framework.Enums;
using CsharpHttpHelper;
using System.Threading;
using Api.Framework.Events;
using Api.Framework.Timers;
using Chat.Framework;
using Chat.Framework.WXSdk.Implement;
using Chat.Framework.WXSdk;
using Newtonsoft.Json;
namespace PDDRebate
{
public class Class1 : Plugin
{
public Class1()
{
this.Name = Resources.PluginName;
this.Note = Resources.PluginNote;
this.Logo = Resources.;
}
#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_pddrebate_pddtgw>())
{
var pddtgws = session.Find<fl_plugin_pddrebate_pddtgw>("select * from fl_plugin_pddrebate_pddtgw").ToList();
if (pddtgws != null)
{
foreach (var item in pddtgws)
{
//插入主推广位数据
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_pddrebate_pddtgw>();
}
#endregion
//创建配置文件
Config = this.ReadConfig<Config>();
SDK.ReciveIMEvent += SDK_ReciveIMEvent;
SDK.OrderNoticeEvent += SDK_OrderNoticeEvent;
}
catch (Exception ex)
{
this.OnLog(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
{
SessionExt.Clear();
if (mainForm != null)
{
mainForm.CloseForm();
mainForm = null;
}
}
catch (Exception ex)
{
this.OnLog(ex.Message);
}
}
/// <summary>
/// 订单通知
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void SDK_OrderNoticeEvent(object sender, OrderNoticeEvent e)
{
try
{
if (e.ChatType == CpsType.)
{
//this.OnLog("拼多多订单:" + HttpHelper.ObjectToJson(e));
var session = ApiClient.GetSession();
var order_pdd = e.Order as fl_order_pinduoduo;
if (order_pdd == null) return;
if (e.Member != null)
{
//是否黑名单
if (ApiClient.IsBlackFlMemberInfo(e.Member))
{
return;
}
2022-09-20 03:10:29 +00:00
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_pdd.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_pdd.order_sn });//防止上级多次触发
if (prevent_theft_cache == null)
{
var isHint = false;
if (!string.IsNullOrWhiteSpace(order_pdd.mall_id) && e.Member.status != MemberType.)
{
#region ()
if (Class1.Config.AShop_SameCommodity_Switch)
{
var frequency = session.Find<fl_order_pinduoduo>("select * from fl_order_pinduoduo where db_userid = @db_userid and goods_id = @goods_id", new { db_userid = order_pdd.db_userid, goods_id = order_pdd.goods_id }).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_pdd, e.Member, point), order_pdd.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_pdd.goods_id;
prevent_theft_cache.mall_id = order_pdd.mall_id;
prevent_theft_cache.order_id = order_pdd.order_sn;
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_pinduoduo>("select * from fl_order_pinduoduo where db_userid = @db_userid and mall_id = @mall_id", new { db_userid = order_pdd.db_userid, mall_id = order_pdd.mall_id }).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_pdd, e.Member, point), order_pdd.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_pdd.goods_id;
prevent_theft_cache.mall_id = order_pdd.mall_id;
prevent_theft_cache.order_id = order_pdd.order_sn;
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_pdd.order_status == 2 && e.Member.status != MemberType.)
{
if (DateTime.Now != DateTime.MinValue)
{
var timeLag = (int)Math.Floor((DateTime.Now - order_pdd.order_create_time).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_pdd, e.Member, point), order_pdd.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_pdd.goods_id;
prevent_theft_cache.mall_id = order_pdd.mall_id;
prevent_theft_cache.order_id = order_pdd.order_sn;
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_pdd.db_status, order_pdd, e.Member, point);
if (!string.IsNullOrEmpty(e.Member.username) && !string.IsNullOrEmpty(mess))
ApiClient.SendMessage(robot_info, e.Member.username, mess, order_pdd.msg_groupid);
}
return;
case OrderNoticeType.:
if (Config.AgentReceivedCommissionSwitch == SwitchType.)
{
if (e.Customer != null && point.AwardOne != 0)
{
if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.ClientOrderRefund_OneLevelTip;
if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderPaymentInform_OneLevelTip;
else if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderCountermandInform_OneLevelTip;
else if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderSettlement_OneLevelTip;
}
}
break;
case OrderNoticeType.:
if (Config.AgentReceivedCommissionSwitch == SwitchType.)
{
if (e.Customer != null)
{
if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.ClientOrderRefund_TwoLevelTip;
if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderPaymentInform_TwoLevelTip;
else if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderCountermandInform_TwoLevelTip;
else if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderSettlement_TwoLevelTip;
}
}
break;
case OrderNoticeType.:
if (Config.AgentReceivedCommissionSwitch == SwitchType.)
{
if (e.Customer != null)
{
if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.ClientOrderRefund_ThreeLevelTip;
if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderPaymentInform_ThreeLevelTip;
else if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderCountermandInform_ThreeLevelTip;
else if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderSettlement_ThreeLevelTip;
}
}
break;
case OrderNoticeType.:
if (Config.PrincipalReceivedCommissionSwitch == SwitchType.)
{
if (e.Customer != null)
{
if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.ClientOrderRefund_LeaderTip;
if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderPaymentInform_LeaderTip;
else if (order_pdd.db_status == SystemOrderStatus.)
mess = Config.OrderCountermandInform_LeaderTip;
else if (order_pdd.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_pdd, e.Member, point).Replace("[下级昵称]", e.Customer.realnick ?? ""));
}
}
}
else
{
#region
var querys = session.Find<queryhist_temp>("select robot_name,type,userid from fl_query_hist where itemid=@itemid and adzoneid = @adzoneid and userid > 0 and crt_time>@time and is_multiple=@is_multiple group by userid,type,robot_name", new { itemid = order_pdd.goods_id, adzoneid = order_pdd.p_id, time = DateTime.Now.AddHours(-24).ToString("yyyy-MM-dd HH:mm:ss"), is_multiple = false });
if (querys.Count > 0)
{
for (int i = 0; i < querys.Count; i++)
{
try
{
if (querys[i].type != CpsType.) continue;
//未绑定的数量
var unbound_count = int.Parse(session.FindTable($"select count(id) as num from fl_order_pinduoduo where order_sn = @order_sn and db_userid != 0", new { order_sn = order_pdd.order_sn }).Rows[0]["num"].ToString());
if (unbound_count != 0) break;//已经被绑定直接停止
var queryhist_temp = querys[i];
var userid = queryhist_temp.userid;
var robot_name = queryhist_temp.robot_name;
var robot_info = session.Find<fl_robot_info>("select * from fl_robot_info where name = @name", new { name = robot_name }).FirstOrDefault();//机器人类型应该是没有的,直接通过机器人name查询机器人信息
if (robot_info != null)
{
Thread.Sleep(5000);
var wxbase = ChatClient.WXClient.Values.ToList().FirstOrDefault(f => f.WeixinHao == robot_name);
if (wxbase != null && wxbase.Status == WxStatus.线)
{
var member = session.FindMemberInfoById(userid);
if (member != null)
{
ApiClient.SendMessage(robot_info, member.username, Config.LotUserQueryBindTip.Replace("[商品标题]", order_pdd.goods_name));
//session.ExcuteSQL("update fl_query_hist set userid = @newuserid where itemid = @itemid and adzoneid = @adzoneid and robot_name = @robotname and userid = @userid", new { newuserid = (i - querys.Count + 1), itemid = order_pdd.goods_id, adzoneid = order_pdd.p_id, robotname = robot_name, userid = member.id });
session.ExcuteSQL("update fl_query_hist set is_multiple = @is_multiple where itemid = @itemid and adzoneid = @adzoneid and robot_name = @robotname and userid = @userid", new { is_multiple = true, itemid = order_pdd.goods_id, adzoneid = order_pdd.p_id, robotname = robot_name, userid = member.id });
}
}
}
}
catch (Exception)
{ }
}
}
#endregion
}
}
}
catch (Exception ex)
{
this.OnLog(ex.Message);
}
}
private void SDK_ReciveIMEvent(object sender, ReciveIMEvent e)
{
Compute compute = null;
string goods_name = string.Empty;
try
{
//过滤表情xml
if (e.Message.Contains(@"<msg><emoji") || e.Message.StartsWith("[声音=")) return;
if (!OrderHelper.IsCurrentCpsMess(e.Message, CpsType.)) return;
var _member = e.GetMemberinfo();
#region
if (Regex.IsMatch(e.Message.Trim(), @"^\d{6}-\d{15}$"))
{
int i = 0;
Next:
var orderid = e.Message.Trim();
//通过宝贝的id 和 订单号 进行查询 查看是否存在
var session = ApiClient.GetSession();
var order = session.FindSingle<fl_order_pinduoduo>("select * from fl_order_pinduoduo where order_sn = @order_sn", new { order_sn = orderid });
if (order != null)
{
if (order.db_userid != 0 && order.db_userid != _member.id)
{
e.SendMessage(Config.OccupyOrderErrorTip.Replace("[订单号]", orderid));
return;
}
var notices = new List<OrderNoticeEvent>();
var downPinduoduoTimer = new DownPinduoduoTimer();
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 (order.order_create_time < 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;
order.db_point = string.Empty;
2022-09-20 03:10:29 +00:00
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
downPinduoduoTimer.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
#region
string QRCodeUrl = string.Empty;
if (Config.QRCodeSearchSwitch == SwitchType.)
{
var reg_ = Regex.Match(e.Message, @"\[图片=(?<二维码图片>.+?)\]");
if (reg_.Success)
QRCodeUrl = Util.DecodeQRCode(reg_.Groups["二维码图片"].Value, Util.DecodeQRCodeType.Caoliao);//解析的二维码图片所得到的二维码内容
}
#endregion
//判断消息中是否包含拼多多链接信息
var goods_id = PDDHelper.GetPddGoodsID(string.IsNullOrEmpty(QRCodeUrl) ? e.Message.Trim() : QRCodeUrl);
if (!string.IsNullOrEmpty(goods_id))
{
//this.OnLog($"拼多多编码 = {goods_id}");
#region ID
if (Class1.Config.ItemIDRestrictList.Contains(goods_id))
{
e.SendMessage(Config.ItemIDRestrictTip.Replace("[商品ID]", goods_id));
return;
}
#endregion
var session = ApiClient.GetSession();
var pddInfoTempGroups = session.FindPddInfoTempGroups();//获取pdd数据数据集合缓存
var pddInfoTemp = pddInfoTempGroups.FirstOrDefault<pddinfo_temp>(f => f.name == e.RobotInfo.name && f.onoff == false);
if (pddInfoTemp != null)
{
var member = session.FindMemberinfo(e);//获取用户信息
fl_cps_member pdd_cps = null;
var pid = string.Empty;//使用的pid
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))
{
pid = groupAdzone.adzone_pid;
pdd_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType. && f.username == groupAdzone.adzone_pid_cps_name);
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))//私人推广位
{
pid = memberAdzone.adzone_pid;
pdd_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType. && f.username == memberAdzone.adzone_pid_cps_name);
isDefault = false;
}
}
if (isDefault)//默认推广位
{
pdd_cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType. && f.username == ((member.buy_point >= Config.Point && member.finish_order >= Config.OrderNum) ? pddInfoTemp.pid_chief_cps_name : pddInfoTemp.pid_deputy_cps_name));//通过判断用户的购物积分,来判断用户使用哪个推广位
pid = ((member.buy_point >= Config.Point && member.finish_order >= Config.OrderNum) ? pddInfoTemp.pid_chief : pddInfoTemp.pid_deputy);
}
if (pdd_cps == null) throw new Exception("拼多多推广位设置异常,请检测后重试!");
var isBind = true;
//正在搜索提示
if (!ApiClient.Setting.SystemConfig.message_warning_switch)
{
e.SendMessage(Config.SearchingTip);
Thread.Sleep(500);
}
var api = CpsClient.CreatePinduoduoRequest(pdd_cps);
ArrayList goods_details = null;
//var _temp_param = $"r={e.RobotName} t={(int)e.ChatType} u={e.Username}";
try
{
2023-04-12 09:06:04 +00:00
isBind = api.IsAuthority(pid);
//未绑定
if (!isBind)
2022-09-20 03:10:29 +00:00
{
2023-04-12 09:06:04 +00:00
//授权地址
var authUrl = api.AuthorityUrl(pid);
2022-09-20 03:10:29 +00:00
2023-04-12 09:06:04 +00:00
e.SendMessage(Config.NoRecordTip.Replace("[授权地址]", authUrl));
return;
}
2022-09-20 03:10:29 +00:00
goods_details = PDDHelper.FindSendGuideGoodsInfo(api, pid, goods_id, isBind);
}
catch (Exception ex)
{
throw new Exception("公共异常:" + ex.Message + " - " + ex.StackTrace + " - " + isBind);
}
//没有查到返利提示
2023-04-12 09:06:04 +00:00
if (goods_details == null || goods_details.Count != 1)
2022-09-20 03:10:29 +00:00
throw new Exception("商品不存在");
foreach (var item in goods_details)
{
var temp = item as Dictionary<string, object>;
string mall_id = string.Empty;
if (temp.ContainsKey("mall_id"))
{
mall_id = temp["mall_id"].ToString();
if (Config.SellerIDRestrictlist.Contains(mall_id))
{
e.SendMessage(Config.SellerIDRestrictTip.Replace("[店铺ID]", mall_id));
return;
}
}
var goods_sign = temp["goods_sign"].ToString();
goods_name = (temp["goods_name"] ?? string.Empty).ToString().Replace("", "").Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&").Replace("&quot;", "\"").Replace(" &copy;", "©"); //获取商品标签
var goods_desc = string.Empty;
if (temp.ContainsKey("goods_desc"))
goods_desc = (temp["goods_desc"] ?? string.Empty).ToString(); //商品描述
var goods_thumbnail_url = string.Empty; //商品主图
if (temp.ContainsKey("goods_thumbnail_url"))
goods_thumbnail_url = (temp["goods_thumbnail_url"] ?? string.Empty).ToString();
else if (temp.ContainsKey("goods_image_url"))
goods_thumbnail_url = (temp["goods_image_url"] ?? string.Empty).ToString();
var sales_tip = "0";//已售卖件数
if (temp.ContainsKey("sales_tip"))
sales_tip = (temp["sales_tip"] ?? string.Empty).ToString();
double min_group_price = 0d;
if (temp.ContainsKey("min_group_price"))
min_group_price = Math.Round(temp["min_group_price"] == null ? 0 : (double.Parse(temp["min_group_price"].ToString()) / 100.00), 2); //最低价sku的拼团价单位为分
double min_normal_price = 0d;
if (temp.ContainsKey("min_normal_price"))
min_normal_price = Math.Round(temp["min_normal_price"] == null ? 0 : (double.Parse(temp["min_normal_price"].ToString()) / 100.00), 2); //最低价sku的单买价单位为分
var mall_name = string.Empty;
if (temp.ContainsKey("mall_name"))
mall_name = (temp["mall_name"] ?? string.Empty).ToString(); //店铺名称
double _coupon_min_order_amount = 0d;
if (temp.ContainsKey("coupon_min_order_amount"))
_coupon_min_order_amount = temp["coupon_min_order_amount"] == null ? 0 : double.Parse(temp["coupon_min_order_amount"].ToString());
var coupon_min_order_amount = _coupon_min_order_amount == 0 ? 0 : (_coupon_min_order_amount / 100); //优惠券门槛金额,单位为分
double _coupon_discount = 0d;
if (temp.ContainsKey("coupon_discount"))
_coupon_discount = double.Parse((temp["coupon_discount"] ?? 0).ToString());
var coupon_discount = _coupon_discount == 0 ? 0 : Math.Round(_coupon_discount / 100.00, 2); //优惠券面额,单位为分
var coupon_total_quantity = string.Empty;
if (temp.ContainsKey("coupon_total_quantity"))
coupon_total_quantity = (temp["coupon_total_quantity"] ?? "0").ToString(); //优惠券总数量
var coupon_start_time = DateTime.MinValue;
if (temp.ContainsKey("coupon_start_time"))
{
var _coupon_start_time = temp["coupon_start_time"];
coupon_start_time = _coupon_start_time == null ? new DateTime() : TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(double.Parse(_coupon_start_time.ToString())); //优惠券生效时间UNIX时间戳
}
var coupon_end_time = DateTime.MinValue;
if (temp.ContainsKey("coupon_end_time"))
{
var _coupon_end_time = temp["coupon_end_time"];
coupon_end_time = _coupon_end_time == null ? new DateTime() : TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).AddSeconds(double.Parse(_coupon_end_time.ToString())); //优惠券失效时间UNIX时间戳
}
double promotion_rate = 0d;//佣金比例,千分比
if (temp.ContainsKey("promotion_rate") && temp["promotion_rate"] != null)
promotion_rate = double.Parse(temp["promotion_rate"].ToString()) / 1000.00;
promotion_rate = Math.Round(promotion_rate, 3);
//this.OnLog($@"goods_name = {goods_name}, mall_id = {mall_id}, promotion_rate = {promotion_rate}");
var groupCommisson = (min_group_price - coupon_discount) * promotion_rate;
var commission = session.GetPddComparisonFeeRate(groupCommisson);
var group = session.FindItemPoint(member, commission, 1, CpsType., out compute); //客户团购的佣金
Compute compute1 = null;
var normalCommisson = (min_normal_price - coupon_discount) * promotion_rate;
commission = session.GetPddComparisonFeeRate(normalCommisson);
var normal = session.FindItemPoint(member, commission, 1, CpsType., out compute1); //客户单买的佣金
if (compute == null)
compute = compute1;
var pdd_api = new PDDHelper();
//搜索成功有券的情况下
if (_coupon_discount != 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;
mess = new VariateReplace().CommonReplace(mess, _member);
Dictionary<string, object> oneShoppingUrlDic = null;
Dictionary<string, object> manyShoppingUrlDic = null;
if (mess.Contains("[单买地址"))
{
//oneShoppingUrlDic = pdd_api.GetShoppingUrls(api, new { p_id = pid, custom_parameters = _temp_param, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = false, generate_short_url = true, generate_weapp_webview = true, generate_authority_url = !isBind, force_duo_id = true });
oneShoppingUrlDic = pdd_api.GetShoppingUrls(api, new { p_id = pid, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = false, generate_short_url = true, /*custom_parameters = "{\"uid\":\"602172712\",\"sid\":\"jdds\"}",*/generate_weapp_webview = true, generate_authority_url = !isBind, force_duo_id = true, generate_schema_url = true });
}
if (mess.Contains("[拼团地址") || mess.Contains("[商品图片]"))
{
//manyShoppingUrlDic = pdd_api.GetShoppingUrls(api, new { p_id = pid, custom_parameters = _temp_param, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = true, generate_short_url = true, generate_weapp_webview = true, generate_authority_url = !isBind, force_duo_id = true });
manyShoppingUrlDic = pdd_api.GetShoppingUrls(api, new { p_id = pid, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = true, generate_short_url = true, generate_weapp_webview = true, generate_authority_url = !isBind, force_duo_id = true, generate_schema_url = true });
}
e.SendMessage(mess
.Replace("劵", "券")
.Replace("[商品标题]", goods_name)
.Replace("[商品描述]", goods_desc)
.Replace("[商品主图]", $"[图片={goods_thumbnail_url}]")
.Replace("[图片地址]", goods_thumbnail_url)
.Replace("[已售数量]", sales_tip)
.Replace("[店铺名称]", mall_name)
.Replace("[优惠券门槛金额]", coupon_min_order_amount.ToString())
.Replace("[优惠券金额]", string.Format("{0:F}", coupon_discount))
.Replace("[优惠券数量]", coupon_total_quantity)
.Replace("[优惠券生效日]", coupon_start_time.ToString("yyyy-MM-dd HH:mm:ss"))
.Replace("[优惠券失效日]", coupon_end_time.ToString("yyyy-MM-dd HH:mm:ss"))
.Replace("[商品单买价]", string.Format("{0:F}", min_normal_price))
.Replace("[单买返利]", (normal.UserPoint == 0 ? 0.01 : normal.UserPoint).ToString())
.Replace("[券后单买价]", ((decimal)min_normal_price - (decimal)coupon_discount).ToString())
.Replace("[单买地址跳转]", "[单买地址]")
.Replace("[单买地址]", oneShoppingUrlDic == null ? string.Empty : oneShoppingUrlDic["mobile_short_url"].ToString())
.Replace("[单买地址不跳转]", oneShoppingUrlDic == null ? string.Empty : oneShoppingUrlDic["short_url"].ToString())
.Replace("[商品拼团价]", string.Format("{0:F}", min_group_price))
.Replace("[拼团返利]", (group.UserPoint == 0 ? 0.01 : group.UserPoint).ToString())
.Replace("[券后拼团价]", ((decimal)min_group_price - (decimal)coupon_discount).ToString())
.Replace("[拼团地址跳转]", "[拼团地址]")
.Replace("[拼团地址]", manyShoppingUrlDic == null ? string.Empty : manyShoppingUrlDic["mobile_short_url"].ToString())
.Replace("[拼团地址不跳转]", manyShoppingUrlDic == null ? string.Empty : manyShoppingUrlDic["short_url"].ToString())
.Replace("[单买共节省]", "[共节省]")
.Replace("[共节省]", ((decimal)coupon_discount + (decimal)(normal.UserPoint == 0 ? 0.01 : normal.UserPoint)).ToString())
.Replace("[拼团共节省]", ((decimal)coupon_discount + (decimal)(group.UserPoint == 0 ? 0.01 : group.UserPoint)).ToString())
.Replace("[商品图片]", mess.Contains("[商品图片]") ? "[图片=" + ApiClient.GetQRImage(goods_name, min_normal_price.ToString(), coupon_discount.ToString(), ((decimal)min_normal_price - (decimal)coupon_discount).ToString(), goods_thumbnail_url, manyShoppingUrlDic == null ? string.Empty : manyShoppingUrlDic["mobile_short_url"].ToString(), 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;
//var oneShoppingUrl = string.Empty;
//var manyShoppingUrl = string.Empty;
Dictionary<string, object> oneShoppingUrlDic = null;
Dictionary<string, object> manyShoppingUrlDic = null;
if (mess.Contains("[拼团地址") || mess.Contains("[商品图片]"))
manyShoppingUrlDic = pdd_api.GetShoppingUrls(api, new { p_id = pid, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = true, generate_short_url = true, generate_weapp_webview = true, generate_authority_url = !isBind, force_duo_id = true, generate_schema_url = true });
if (mess.Contains("[单买地址"))
//oneShoppingUrlDic = pdd_api.GetShoppingUrls(api, new { p_id = (member.buy_point <= Config.Point ? pddInfoTemp.pid_deputy : pddInfoTemp.pid_chief), custom_parameters = _temp_param, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = false, generate_short_url = true, generate_weapp_webview = true, generate_authority_url = !isBind, force_duo_id = true });
oneShoppingUrlDic = pdd_api.GetShoppingUrls(api, new { p_id = (member.buy_point <= Config.Point ? pddInfoTemp.pid_deputy : pddInfoTemp.pid_chief), goods_sign_list = $"[\"{goods_sign}\"]", multi_group = false, generate_short_url = true, generate_weapp_webview = true, generate_authority_url = !isBind, force_duo_id = true, generate_schema_url = true });
e.SendMessage(mess
.Replace("[商品标题]", goods_name)
.Replace("[商品描述]", goods_desc)
.Replace("[商品主图]", $"[图片={goods_thumbnail_url}]")
.Replace("[图片地址]", goods_thumbnail_url)
.Replace("[已售数量]", sales_tip)
.Replace("[店铺名称]", mall_name)
.Replace("[商品单买价]", min_normal_price.ToString())
.Replace("[单买返利]", (normal.UserPoint == 0 ? 0.01 : normal.UserPoint).ToString())
.Replace("[单买地址跳转]", "[单买地址]")
.Replace("[单买地址]", oneShoppingUrlDic == null ? string.Empty : oneShoppingUrlDic["mobile_short_url"].ToString())
.Replace("[单买地址不跳转]", oneShoppingUrlDic == null ? string.Empty : oneShoppingUrlDic["short_url"].ToString())
.Replace("[商品拼团价]", min_group_price.ToString())
.Replace("[拼团返利]", (group.UserPoint == 0 ? 0.01 : group.UserPoint).ToString())
.Replace("[拼团地址跳转]", "[拼团地址]")
.Replace("[拼团地址]", manyShoppingUrlDic == null ? string.Empty : manyShoppingUrlDic["mobile_short_url"].ToString())
.Replace("[拼团地址不跳转]", manyShoppingUrlDic == null ? string.Empty : manyShoppingUrlDic["short_url"].ToString())
.Replace("[单买共节省]", "[共节省]")
.Replace("[共节省]", (normal.UserPoint == 0 ? 0.01 : normal.UserPoint).ToString())
.Replace("[拼团共节省]", (group.UserPoint == 0 ? 0.01 : group.UserPoint).ToString())
.Replace("[商品图片]", mess.Contains("[商品图片]") ? "[图片=" + ApiClient.GetQRImage(goods_name, min_normal_price.ToString(), coupon_discount.ToString(), ((decimal)min_normal_price - (decimal)coupon_discount).ToString(), goods_thumbnail_url, manyShoppingUrlDic == null ? string.Empty : manyShoppingUrlDic["short_url"].ToString(), ApiClient.QrImageType.B, CpsType.) + "]" : string.Empty));
}
#region ,,,
session.Insertable(new fl_query_hist()
{
crt_time = DateTime.Now,
type = CpsType.,
itemid = goods_id,
groupid = e.Groupid,
robot_name = e.RobotName,
robot_type = e.ChatType,
userid = _member.id,
title = goods_name,
adzoneid = pid,
mallid = mall_id,
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}", min_group_price);
shared["title"] = goods_name;
shared["coupon_price"] = string.Format("{0:F}", _coupon_discount != 0 ? _coupon_discount : 0);
shared["user_point"] = string.Format("{0:F}", (group.UserPoint == 0 ? 0.01 : group.UserPoint));
shared["economize"] = string.Format("{0:F}", (_coupon_discount != 0 ? ((decimal)coupon_discount + (decimal)(group.UserPoint == 0 ? 0.01 : group.UserPoint)) : (group.UserPoint == 0 ? 0.01m : (decimal)group.UserPoint)));
var sharedEvent = new SharedEvents(shared);
EventClient.OnEvent(sender, sharedEvent);
#endregion
}
}
}
#endregion
}
catch (Exception ex)
{
/*
* ,
*/
if (ex.Message.Contains("商品不存在") || ex.Message.Contains("商品非多多进宝商品"))
{
e.SendMessage(Config.SearchErrorTip);
var session = ApiClient.GetSession();
session.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"] = goods_name;
shared["coupon_price"] = "未知";
shared["user_point"] = "未知";
shared["economize"] = "未知";
var sharedEvent = new SharedEvents(shared);
EventClient.OnEvent(sender, sharedEvent);
}
else
{
this.OnLog("D:" + ex.Message);
e.SendMessage(ApiClient.Setting.SystemConfig.msg_error);
}
}
}
#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
}
}