1188 lines
63 KiB
C#
1188 lines
63 KiB
C#
|
using Api.Framework;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Api.Framework.Tools;
|
|||
|
using Delivery.Plugin.Model;
|
|||
|
using Api.Framework.Model;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using CsharpHttpHelper;
|
|||
|
using Api.Framework.Enums;
|
|||
|
using Api.Framework.SDK;
|
|||
|
using Api.Framework.Timers;
|
|||
|
using Api.Framework.Events;
|
|||
|
using System.Threading;
|
|||
|
using Chat.Framework;
|
|||
|
using Chat.Framework.WXSdk.Implement;
|
|||
|
using System.Collections;
|
|||
|
using System.IO;
|
|||
|
using System.Drawing;
|
|||
|
|
|||
|
namespace Delivery.Plugin
|
|||
|
{
|
|||
|
public class Class1 : Api.Framework.SDK.Plugin
|
|||
|
{
|
|||
|
public Class1()
|
|||
|
{
|
|||
|
this.Name = "配送插件";
|
|||
|
this.Logo = Properties.Resources.快递;
|
|||
|
}
|
|||
|
|
|||
|
// public static Config config;
|
|||
|
public override void Start()
|
|||
|
{
|
|||
|
// config = Util.Read<Config>();
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
//session.CodeFirst.BackupTable().InitTables(typeof(fl_plugin_delivery_group),typeof(fl_plugin_delivery_item));
|
|||
|
bool is_first = false;
|
|||
|
if (!session.TableExist<fl_plugin_delivery_kuaidi>())
|
|||
|
{
|
|||
|
is_first = true;
|
|||
|
session.CreateTable<fl_plugin_delivery_kuaidi>();
|
|||
|
session.AddIndex<fl_plugin_delivery_kuaidi>("group_id");
|
|||
|
}
|
|||
|
|
|||
|
if (!session.TableExist<fl_plugin_delivery_group>())
|
|||
|
{
|
|||
|
session.CreateTable<fl_plugin_delivery_group>();
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//首次创建fl_plugin_delivery_kuaidi 表,提取以前的快递点位置,并自动插入
|
|||
|
if (is_first)
|
|||
|
{
|
|||
|
var groups = GetGroups();
|
|||
|
foreach (var item in groups)
|
|||
|
{
|
|||
|
var list = item.position.Split(new string[] { "\r\n" }, StringSplitOptions.None).ToList();
|
|||
|
if (list != null)
|
|||
|
{
|
|||
|
int number = 0;
|
|||
|
foreach (var kuaidi in list)
|
|||
|
{
|
|||
|
if (!string.IsNullOrEmpty(kuaidi))
|
|||
|
{
|
|||
|
number++;
|
|||
|
session.Insertable<fl_plugin_delivery_kuaidi>(new fl_plugin_delivery_kuaidi() { group_id = item.id, name = kuaidi }).ExecuteCommand();
|
|||
|
}
|
|||
|
}
|
|||
|
if (number > 0)
|
|||
|
session.ExcuteSQL("update fl_plugin_delivery_group set position='' where id="+item.id);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
if (!session.TableExist<fl_plugin_delivery_item>())
|
|||
|
{
|
|||
|
session.CreateTable<fl_plugin_delivery_item>();
|
|||
|
}else if (!session.ColumnExist("fl_plugin_delivery_item", "q_location_id"))
|
|||
|
{
|
|||
|
session.AddColumn("fl_plugin_delivery_item", "q_location_id", " integer default 0");
|
|||
|
}
|
|||
|
|
|||
|
//if (!session.ColumnExist("fl_plugin_delivery_group", "upload_msg")) session.AddColumn("fl_plugin_delivery_group", "upload_msg","varchar(255) default ''");
|
|||
|
if (!session.TableExist<fl_plugin_delivery_applyfriend_info>())
|
|||
|
{
|
|||
|
session.CreateTable<fl_plugin_delivery_applyfriend_info>();
|
|||
|
session.AddIndex<fl_plugin_delivery_applyfriend_info>("robot_name", "new_friend_wxid");//增加索引.以后数据多了.查询速度会比较快
|
|||
|
session.AddUnique<fl_plugin_delivery_applyfriend_info>("robot_name", "new_friend_wxid");//增加唯一约束
|
|||
|
}
|
|||
|
|
|||
|
if (!session.TableExist<fl_plugin_delivery_hist>())
|
|||
|
{
|
|||
|
session.CreateTable<fl_plugin_delivery_hist>();
|
|||
|
session.AddUnique<fl_plugin_delivery_hist>("order_code");
|
|||
|
}
|
|||
|
|
|||
|
SDK.ReciveIMEvent += SDK_ReciveIMEvent;
|
|||
|
SDK.WebRequestEvent += SDK_WebRequestEvent;
|
|||
|
SDK.OrderNoticeEvent += SDK_OrderNoticeEvent;
|
|||
|
SDK.WXApplyFriendEvent += SDK_WXApplyFriendEvent;
|
|||
|
SDK.WXNewFriendEvent += SDK_WXNewFriendEvent;
|
|||
|
base.Start();
|
|||
|
}
|
|||
|
|
|||
|
private List<string> welcomeTip_Friends = new List<string>();
|
|||
|
private static object lock_newfriend = new object();
|
|||
|
|
|||
|
private void SDK_WXNewFriendEvent(object sender, Chat.Framework.WXSdk.Events.WXNewFriend e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
fl_plugin_delivery_applyfriend_info friend = null;
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
fl_member_info new_member = null;
|
|||
|
var robot = session.FindRobotInfo(e.Client.WeixinHao, ChatType.微信);
|
|||
|
if (robot != null)
|
|||
|
{
|
|||
|
Thread.Sleep(1100);
|
|||
|
lock (lock_newfriend)
|
|||
|
{
|
|||
|
if (!welcomeTip_Friends.Contains(e.Friend.UserName))
|
|||
|
{
|
|||
|
friend = session.Queryable<fl_plugin_delivery_applyfriend_info>().OrderBy(f => f.id, SqlSugar.OrderByType.Desc).First(f => f.new_friend_wxid == e.Friend.UserName && f.robot_name == e.Client.WeixinHao);
|
|||
|
|
|||
|
#region fl_plugin_delivery_applyfriend_info "已接受"
|
|||
|
if (friend != null && friend.state != "已接受")
|
|||
|
{
|
|||
|
friend.state = "已接受";
|
|||
|
session.Saveable(friend).ExecuteReturnEntity();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
if (welcomeTip_Friends.Count > 10000) welcomeTip_Friends.Clear();
|
|||
|
welcomeTip_Friends.Add(e.Friend.UserName);
|
|||
|
|
|||
|
new_member = session.Queryable<fl_member_info>().First(f => f.robot_type == ChatType.微信 && f.username == e.Friend.UserName);
|
|||
|
if (new_member == null)
|
|||
|
{
|
|||
|
new_member = new fl_member_info() { crt_time = DateTime.Now, usernick = 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 = session.FindGroups();
|
|||
|
if (groups.Count != 0)
|
|||
|
new_member.group_id = groups[0].id;
|
|||
|
session.SaveOrUpdate(new_member);
|
|||
|
var o = new fl_plugin_delivery_hist() //设备集合
|
|||
|
{
|
|||
|
ordertable_cratetime = DateTime.MinValue,
|
|||
|
ordertable_id = 0,
|
|||
|
userid = new_member.id,
|
|||
|
effective = true,
|
|||
|
order_code = GetRandomCode(session)//Code值
|
|||
|
};
|
|||
|
session.Insertable<fl_plugin_delivery_hist>(o).ExecuteCommand();
|
|||
|
var group = GetGroup(new_member);
|
|||
|
if (group == null) return;
|
|||
|
string qurl = string.Empty;
|
|||
|
if (group.WelcomeTip.Contains("[取件地址]"))
|
|||
|
qurl = GetURL(URLType.取件地址, new_member);
|
|||
|
ApiClient.SendMessage(robot, e.Friend.UserName, group.WelcomeTip.Replace("[免单码]", o.order_code).Replace("[取件地址]", qurl));
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
this.OnLog("NewFriend = " + ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private static readonly object applyFriendLock = new object();
|
|||
|
public static Queue<long> queue = new Queue<long>();//新加好友审核队列
|
|||
|
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.Queryable<fl_plugin_delivery_applyfriend_info>().First(f => f.id == apply_id);
|
|||
|
if (friend != null)
|
|||
|
{
|
|||
|
Thread.Sleep(3000);
|
|||
|
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)
|
|||
|
{
|
|||
|
string result = client.AgreeAddMe(HttpHelper.URLDecode(friend.token));
|
|||
|
if (string.IsNullOrEmpty(result)) friend.state = "已接受";
|
|||
|
else friend.state = result;
|
|||
|
session.Saveable(friend).ExecuteReturnEntity();
|
|||
|
}
|
|||
|
}
|
|||
|
} while (true);
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{ }
|
|||
|
finally
|
|||
|
{
|
|||
|
IsApply = false;
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 微信 - 申请添加我为好友,需要审核
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
private void SDK_WXApplyFriendEvent(object sender, Chat.Framework.WXSdk.Events.WXApplyFriend e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
lock (applyFriendLock)
|
|||
|
{
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var friend = session.FindSingle<fl_plugin_delivery_applyfriend_info>("select * from fl_plugin_delivery_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 = session.Insertable(friend = new fl_plugin_delivery_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)
|
|||
|
}).ExecuteReturnEntity();
|
|||
|
}
|
|||
|
var group = GetGroup(e.Client.WeixinHao);
|
|||
|
if (group == null) return;
|
|||
|
if (group.Accept == SwitchType.关闭) return;
|
|||
|
var robot = session.FindRobots().FirstOrDefault(f => f.name == e.Client.WeixinHao && f.type == ChatType.微信);
|
|||
|
if (robot == null) return;
|
|||
|
if (!queue.Contains(friend.id))
|
|||
|
{
|
|||
|
queue.Enqueue(friend.id);
|
|||
|
ApplyWechatFriend();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
this.OnLog("ApplyFriend = " + ex.Message + " - " + ex.StackTrace);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public override void ShowForm()
|
|||
|
{
|
|||
|
var form = new 会员数据操作();
|
|||
|
form.ShowDialog();
|
|||
|
}
|
|||
|
public enum URLType : int
|
|||
|
{
|
|||
|
取件地址 = 1,
|
|||
|
查看订单 = 2,
|
|||
|
凭证图片地址 = 3
|
|||
|
}
|
|||
|
private string GetURL(URLType type, fl_member_info info,fl_plugin_delivery_item item=null)
|
|||
|
{
|
|||
|
var result = string.Empty;
|
|||
|
switch (type)
|
|||
|
{
|
|||
|
case URLType.取件地址:
|
|||
|
result = $"http://{ApiClient.Setting.ServerConfig.Domain}/kuaidi/qujian.html?token={GetEncuserinfo(info)}";
|
|||
|
break;
|
|||
|
case URLType.查看订单:
|
|||
|
result = $"http://{ApiClient.Setting.ServerConfig.Domain}/kuaidi/peisong.html?token={GetEncuserinfo(info)}";
|
|||
|
break;
|
|||
|
case URLType.凭证图片地址:
|
|||
|
result = $"http://{ApiClient.Setting.ServerConfig.Domain}/kuaidi/image/{item.id}.jpg";
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
if (!string.IsNullOrEmpty(result)) result = ApiClient.ShortURL(result).Result;
|
|||
|
return result;
|
|||
|
}
|
|||
|
private void SDK_OrderNoticeEvent(object sender, Api.Framework.Events.OrderNoticeEvent e)
|
|||
|
{
|
|||
|
if (e.OrderNoticeType == Api.Framework.Enums.OrderNoticeType.客户订单)
|
|||
|
{
|
|||
|
#region 三个平台订单
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
base_model_order order = null;
|
|||
|
CpsType cps = CpsType.阿里妈妈;
|
|||
|
DateTime createTime = DateTime.MinValue;
|
|||
|
var title = string.Empty;
|
|||
|
var orderId = string.Empty;
|
|||
|
var orderSonId = string.Empty;
|
|||
|
var fee = 0d;
|
|||
|
|
|||
|
|
|||
|
if (e.Order is fl_order_alimama)
|
|||
|
{
|
|||
|
order = e.Order as fl_order_alimama;
|
|||
|
var tbOrder = ((fl_order_alimama)order);
|
|||
|
createTime = tbOrder.create_time;
|
|||
|
title = tbOrder.item_title;
|
|||
|
orderId = tbOrder.trade_parent_id;
|
|||
|
orderSonId = tbOrder.trade_id;
|
|||
|
fee = tbOrder.pub_share_pre_fee;
|
|||
|
cps = CpsType.阿里妈妈;
|
|||
|
}
|
|||
|
if (e.Order is fl_order_pinduoduo)
|
|||
|
{
|
|||
|
order = e.Order as fl_order_pinduoduo;
|
|||
|
var pddOrder = (fl_order_pinduoduo)order;
|
|||
|
createTime = pddOrder.order_create_time;
|
|||
|
title = pddOrder.goods_name;
|
|||
|
orderId = pddOrder.order_sn;
|
|||
|
fee = pddOrder.promotion_amount;
|
|||
|
cps = CpsType.多多进宝;
|
|||
|
}
|
|||
|
if (e.Order is fl_order_jingdong)
|
|||
|
{
|
|||
|
order = e.Order as fl_order_jingdong;
|
|||
|
var jdOrder = (fl_order_jingdong)order;
|
|||
|
createTime = jdOrder.orderTime;
|
|||
|
title = jdOrder.skuName;
|
|||
|
orderId = jdOrder.orderId.ToString();
|
|||
|
fee = jdOrder.estimateFee;
|
|||
|
cps = CpsType.京东联盟;
|
|||
|
}
|
|||
|
|
|||
|
if (order != null && order.db_userid != 0)//阿里妈妈订单
|
|||
|
{
|
|||
|
var member = session.FindMemberInfoById(order.db_userid);
|
|||
|
if (member == null) return;
|
|||
|
var robot = session.FindRobotInfo(member.robot_name, member.robot_type);
|
|||
|
if (robot == null) return;
|
|||
|
var group = GetGroup(member);
|
|||
|
if(group==null )return;
|
|||
|
var msg = string.Empty;
|
|||
|
|
|||
|
var o = session.Queryable<fl_plugin_delivery_hist>().First(f => f.ordertable_id == order.id && f.ordertable_type == cps);
|
|||
|
//付款成功赠送了一个免单码
|
|||
|
if (order.db_status == SystemOrderStatus.订单付款)
|
|||
|
{
|
|||
|
var freeCount = session.Find<fl_plugin_delivery_hist>("select * from fl_plugin_delivery_hist where userid = @userid", new { userid = order.db_userid }).Count;//判断是否为前几单,前几单不判断佣金金额
|
|||
|
if (freeCount > group.FreeCount && fee < group.ConditionPoint)//订单不满足条件
|
|||
|
{
|
|||
|
msg = group.BMsgError1
|
|||
|
.Replace("[商品标题]", title)
|
|||
|
.Replace("[订单号]", orderId);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (o != null && !o.effective)
|
|||
|
{
|
|||
|
if (o.using_userid == 0)
|
|||
|
{
|
|||
|
o.effective = true;
|
|||
|
session.Saveable(o).ExecuteCommand();
|
|||
|
}
|
|||
|
else o = null;
|
|||
|
}
|
|||
|
|
|||
|
if (o == null)
|
|||
|
{
|
|||
|
o = new fl_plugin_delivery_hist() //设备集合
|
|||
|
{
|
|||
|
ordertable_cratetime = freeCount == 0 ? DateTime.MinValue : createTime,
|
|||
|
ordertable_id = order.id,
|
|||
|
ordertable_type = cps,
|
|||
|
userid = order.db_userid,
|
|||
|
effective = true,
|
|||
|
order_code = GetRandomCode(session)//Code值
|
|||
|
};
|
|||
|
session.Insertable<fl_plugin_delivery_hist>(o).ExecuteCommand();
|
|||
|
}
|
|||
|
|
|||
|
var qurl = GetURL(URLType.取件地址, member);
|
|||
|
//成功获得免单
|
|||
|
msg = group.BMsgSuccess1
|
|||
|
.Replace("[商品标题]", title)
|
|||
|
.Replace("[订单号]", orderId)
|
|||
|
.Replace("[免单码]", o.order_code)
|
|||
|
.Replace("[取件地址]", qurl);
|
|||
|
}
|
|||
|
}
|
|||
|
//订单失效/维权 失效一个免单码
|
|||
|
//else if (order.db_status == SystemOrderStatus.订单失效 || order.db_status == SystemOrderStatus.订单维权中 || order.db_status == SystemOrderStatus.全额退款 || order.db_status == SystemOrderStatus.订单退款)//订单失败,查看是否被绑定过
|
|||
|
else if (order.db_status == SystemOrderStatus.订单失效 || order.db_status == SystemOrderStatus.订单维权中)//订单失败,查看是否被绑定过
|
|||
|
{
|
|||
|
if (o == null) return;//免单码
|
|||
|
if (!o.effective || o.using_userid != 0)//改免单码已经被使用,获取一个有效的免单码改成无效
|
|||
|
{
|
|||
|
o = session.Queryable<fl_plugin_delivery_hist>().First(f => f.userid == order.db_userid && f.effective && f.using_userid == 0);
|
|||
|
if (o == null) return;//存在有效的,进行作废操作
|
|||
|
}
|
|||
|
if (o.effective)
|
|||
|
{
|
|||
|
if (o.using_userid != 0)
|
|||
|
{
|
|||
|
o = session.Queryable<fl_plugin_delivery_hist>().First(f => f.userid == order.db_userid && f.effective && f.using_userid == 0);
|
|||
|
if (o == null) return;//存在有效的,进行作废操作
|
|||
|
}
|
|||
|
o.effective = false;
|
|||
|
session.Saveable(o).ExecuteCommand();
|
|||
|
}
|
|||
|
|
|||
|
msg = (order.db_status == SystemOrderStatus.订单维权中 ? group.BMsgError4 : group.BMsgError3)
|
|||
|
.Replace("[商品标题]", title)
|
|||
|
.Replace("[订单号]", orderId)
|
|||
|
.Replace("[免单码]", o.order_code);
|
|||
|
}
|
|||
|
|
|||
|
#region xxx
|
|||
|
//else if (order.db_status == SystemOrderStatus.部分退款)//判断维权以后订单是否满足条件
|
|||
|
//{
|
|||
|
// //获取订单维权以后的金额
|
|||
|
// if (cps == CpsType.阿里妈妈)
|
|||
|
// {
|
|||
|
// var refundOrder = session.FindSingle<fl_order_refund_alimama>("select * from fl_order_refund_alimama where tbtradeparentid = @tbtradeparentid and tbtradeid = @tbtradeid and showrefundstatus = @showrefundstatus", new { tbtradeparentid = orderId, tbtradeid = orderSonId, showrefundstatus = "维权成功" });
|
|||
|
|
|||
|
// if (refundOrder != null)
|
|||
|
// fee = fee - refundOrder.refundfee;
|
|||
|
// }
|
|||
|
|
|||
|
// if (fee >= config.Condition)//订单满足条件
|
|||
|
// {
|
|||
|
// if (o != null)
|
|||
|
// {
|
|||
|
// if (o.using_userid == 0)
|
|||
|
// {
|
|||
|
// if (!o.effective)
|
|||
|
// {
|
|||
|
// o.effective = true;
|
|||
|
// session.Saveable(o).ExecuteCommand();
|
|||
|
// }
|
|||
|
// else//该免单码没有被使用过并且为有效(似乎不存在这种情况)
|
|||
|
// { }
|
|||
|
// }
|
|||
|
// else//免单码已经被用户使用过,重新生成一个给用户
|
|||
|
// {
|
|||
|
// o = null;
|
|||
|
// }
|
|||
|
// }
|
|||
|
|
|||
|
// if (o == null)
|
|||
|
// {
|
|||
|
// o = new fl_plugin_delivery_hist() //设备集合
|
|||
|
// {
|
|||
|
// ordertable_cratetime = createTime,
|
|||
|
// ordertable_id = order.id,
|
|||
|
// ordertable_type = cps,
|
|||
|
// userid = order.db_userid,
|
|||
|
// effective = true,
|
|||
|
// order_code = GetRandomCode(session)//Code值
|
|||
|
// };
|
|||
|
// session.Insertable<fl_plugin_delivery_hist>(o).ExecuteCommand();
|
|||
|
// }
|
|||
|
|
|||
|
// var qurl = GetURL(URLType.取件地址, member);
|
|||
|
// //成功获得免单
|
|||
|
// msg = config.BMsgSuccess1
|
|||
|
// .Replace("[商品标题]", title)
|
|||
|
// .Replace("[订单号]", orderId)
|
|||
|
// .Replace("[免单码]", o.order_code)
|
|||
|
// .Replace("[取件地址]", qurl);
|
|||
|
// }
|
|||
|
//}
|
|||
|
#endregion
|
|||
|
|
|||
|
//发送消息
|
|||
|
if (!string.IsNullOrWhiteSpace(msg))
|
|||
|
{
|
|||
|
ApiClient.SendMessage(robot, member.username, msg);
|
|||
|
e.Cancel = true;
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
private static object _lock_add = new object();
|
|||
|
private void SDK_WebRequestEvent(object sender, Api.Framework.Events.WebRequestEvents e)
|
|||
|
{
|
|||
|
if (e.Param.ContainsKey("method") && e.Param.ContainsKey("token"))
|
|||
|
{
|
|||
|
var method = e.Param["method"].ToString();
|
|||
|
var delivery = e.Param["token"].ToString();
|
|||
|
try
|
|||
|
{
|
|||
|
//解密用户信息
|
|||
|
var member = GetDecuserinfo(delivery);
|
|||
|
if (member == null) throw new Exception("抱歉,您的连接已失效!");
|
|||
|
var group = GetGroup(member);
|
|||
|
if (group == null) throw new Exception("抱歉,您的连接已失效!");
|
|||
|
|
|||
|
switch (method)
|
|||
|
{
|
|||
|
case "UploadPic":
|
|||
|
{
|
|||
|
var id = int.Parse(e.Param["id"].ToString());
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var v = session.Queryable<fl_plugin_delivery_item>().Single(x=>x.id == id);
|
|||
|
if (v == null) throw new Exception("此订单已删除!");
|
|||
|
if (v.groupid != group.id) throw new Exception("非法操作!");
|
|||
|
if (!v.is_arrive)
|
|||
|
{
|
|||
|
|
|||
|
if (!string.IsNullOrEmpty(e.Param["img"]))
|
|||
|
{
|
|||
|
|
|||
|
var filename = Util.MapFile($"{id}.jpg", "wwwroot\\kuaidi\\image");
|
|||
|
var base64 = System.Web.HttpUtility.HtmlEncode(e.Param["img"]);
|
|||
|
base64 = base64.Trim().Replace("%", "").Replace(",", "").Replace(" ", "+");
|
|||
|
if (base64.Length % 4 > 0)
|
|||
|
{
|
|||
|
base64 = base64.PadRight(base64.Length + 4 - base64.Length % 4, '=');
|
|||
|
}
|
|||
|
byte[] data = Convert.FromBase64String(base64);
|
|||
|
// data = Util.AddWaterMark(data,"测试水印");
|
|||
|
File.WriteAllBytes(filename, data);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
session.ExcuteSQL("update fl_plugin_delivery_item set is_arrive = 1 where id=" + v.id);
|
|||
|
var robot = session.FindRobotInfo(member.robot_name, member.robot_type);
|
|||
|
if (robot != null)
|
|||
|
{
|
|||
|
var m = session.Queryable<fl_member_info>().Where(x => x.id == v.userid).First();
|
|||
|
if (m != null)
|
|||
|
{
|
|||
|
var pic_url = string.Empty;
|
|||
|
if (!string.IsNullOrEmpty(e.Param["img"]))
|
|||
|
{
|
|||
|
pic_url = GetURL(URLType.凭证图片地址, m, v);
|
|||
|
}
|
|||
|
var msg = group.upload_msg.Replace("[取件码]", v.q_code).Replace("[凭证图片地址]",pic_url);
|
|||
|
ApiClient.SendMessage(robot, m.username, msg);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
e.Send("保存成功!");
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
case "GetPositions":
|
|||
|
{
|
|||
|
e.Send(group.GetPositions());
|
|||
|
break;
|
|||
|
}
|
|||
|
case "GetTasks":
|
|||
|
{
|
|||
|
var key = e.Param.ContainsKey("keyword") ? e.Param["keyword"] : string.Empty;
|
|||
|
bool isadmin = group.admins.Split('|').Contains(member.id.ToString());
|
|||
|
if (isadmin)
|
|||
|
{
|
|||
|
var date_type = e.Param["date_type"].ToString();
|
|||
|
var star_time = DateTime.Parse(DateTime.Parse(e.Param["date_time"].ToString()).ToString("yyyy-MM-dd 00:00:00"));
|
|||
|
var end_time = star_time.AddDays(1);
|
|||
|
if (date_type == "2") end_time = star_time.AddHours(11);
|
|||
|
else if (date_type == "3")
|
|||
|
{
|
|||
|
star_time = star_time.AddHours(11);
|
|||
|
end_time = star_time.AddDays(1);
|
|||
|
}
|
|||
|
var location = e.Param["q_location"].ToString();
|
|||
|
List<fl_plugin_delivery_item> items;
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
if (location == "全部快递点位置")
|
|||
|
items = session.Queryable<fl_plugin_delivery_item>().Where(f=>f.groupid == group.id && f.crt_time>= star_time && f.crt_time< end_time).OrderBy(f=>f.id, SqlSugar.OrderByType.Desc).ToList();
|
|||
|
else
|
|||
|
items = session.Queryable<fl_plugin_delivery_item>().Where(f => f.crt_time >= star_time && f.crt_time < end_time && f.groupid == group.id && f.q_location ==location ).OrderBy(f => f.id, SqlSugar.OrderByType.Desc).ToList();
|
|||
|
var list = new ArrayList();
|
|||
|
foreach (var item in items) list.Add(new { real_name = item.real_name, q_location = item.q_location, crt_time = item.crt_time.ToString("yyyy-MM-dd HH:mm:ss"), is_arrive = item.is_arrive , q_code = item.q_code , real_telnumber = item.real_telnumber, s_location = item.s_location,id = item.id});
|
|||
|
e.Send(list);
|
|||
|
break;
|
|||
|
}
|
|||
|
else throw new Exception("权限不足!");
|
|||
|
}
|
|||
|
case "GetBasics":
|
|||
|
{
|
|||
|
if (!string.IsNullOrEmpty(group.stop_sumbmit_text)) throw new Exception(group.stop_sumbmit_text);
|
|||
|
var temp_times = group.lastTime.Replace(":",":").Split(':');
|
|||
|
var h = int.Parse(temp_times[0]);
|
|||
|
var m = int.Parse(temp_times[1]);
|
|||
|
|
|||
|
var is_peisong = true;
|
|||
|
if (DateTime.Now.Hour == h) is_peisong = DateTime.Now.Minute > m ? false : true;
|
|||
|
else if (DateTime.Now.Hour > h) is_peisong = false;
|
|||
|
if (!is_peisong) throw new Exception(@"明天在来提交新的取货码哦!
|
|||
|
亲爱的同学,下午" + h + "点" + m + "分后停止配送啦!");
|
|||
|
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var _q_codes = session.Queryable<fl_plugin_delivery_hist>().Where(f => f.userid == member.id && f.using_userid == 0 && f.effective).OrderBy(f => f.ordertable_cratetime, SqlSugar.OrderByType.Asc).ToPageList(0, 20);
|
|||
|
List<string> q_codes = new List<string>();
|
|||
|
foreach (var item in _q_codes) q_codes.Add(item.order_code);
|
|||
|
var q_locations = group.GetPositions();
|
|||
|
var q_hist = session.Queryable<fl_plugin_delivery_item>().Where(f => f.userid == member.id).OrderBy(f => f.crt_time, SqlSugar.OrderByType.Desc).First();
|
|||
|
var real_name = string.Empty;
|
|||
|
var telnumber = string.Empty;
|
|||
|
var s_location = string.Empty;
|
|||
|
if (q_hist != null)
|
|||
|
{
|
|||
|
real_name = q_hist.real_name;
|
|||
|
telnumber = q_hist.real_telnumber;
|
|||
|
s_location = q_hist.s_location;
|
|||
|
}
|
|||
|
e.Send(new { q_codes = q_codes, q_locations = q_locations, real_name = real_name, telnumber = telnumber, s_location = s_location });
|
|||
|
|
|||
|
break;
|
|||
|
}
|
|||
|
case "AddDelivery":
|
|||
|
{
|
|||
|
if (!string.IsNullOrEmpty(group.stop_sumbmit_text)) throw new Exception(group.stop_sumbmit_text);
|
|||
|
var temp_times = group.lastTime.Replace(":", ":").Split(':');
|
|||
|
var h = int.Parse(temp_times[0]);
|
|||
|
var m = int.Parse(temp_times[1]);
|
|||
|
|
|||
|
var is_peisong = false;
|
|||
|
if (DateTime.Now.Hour == h) is_peisong = DateTime.Now.Minute > m ? false : true;
|
|||
|
else if (DateTime.Now.Hour > h) is_peisong = false;
|
|||
|
if (is_peisong) throw new Exception(@"明天在来提交新的取货码哦!
|
|||
|
亲爱的同学,下午" + h + "点" + m + "分后停止配送啦!");
|
|||
|
|
|||
|
var real_name = e.Param["real_name"];
|
|||
|
if (string.IsNullOrEmpty(real_name)) throw new Exception("姓名为必填项!");
|
|||
|
var telnumber = e.Param["telnumber"];
|
|||
|
if (string.IsNullOrEmpty(telnumber)) throw new Exception("手机为必填项!");
|
|||
|
if (!Regex.Match(telnumber, @"^\d{11,}$").Success) throw new Exception("手机格式不对,必须为11位数字!");
|
|||
|
var qcode = e.Param["qcode"];
|
|||
|
if (string.IsNullOrEmpty(qcode)) throw new Exception("取件码为必填项!");
|
|||
|
var mcode = e.Param["mcode"];
|
|||
|
lock (_lock_add)
|
|||
|
{
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var hist = session.Queryable<fl_plugin_delivery_hist>().Where(f => f.order_code == mcode).Single();
|
|||
|
if (hist == null) throw new Exception("免单码不存在,请核实后重试!");
|
|||
|
if (!hist.effective) throw new Exception("此免单码已失效!");
|
|||
|
if (hist.using_userid != 0) throw new Exception("此免单码已被使用!");
|
|||
|
if (hist.ordertable_cratetime > DateTime.Now.AddHours(-24))
|
|||
|
throw new Exception($"此免单码{mcode},需要{Math.Round((24.00 - (DateTime.Now - hist.ordertable_cratetime).TotalHours), 2)}小时候后,才可以使用!");
|
|||
|
var q_location = e.Param["q_location"];
|
|||
|
if (!group.GetPositions().Contains(q_location)) throw new Exception("无法查询您的取件位置!");
|
|||
|
var s_location = e.Param["s_location"];
|
|||
|
if (string.IsNullOrEmpty(s_location) || s_location.Length < 5) throw new Exception("您的配送地址不够详细!");
|
|||
|
var kuaidi = session.Queryable<fl_plugin_delivery_kuaidi>().Where(f=>f.group_id == group.id && f.name == q_location).First();
|
|||
|
var data = new fl_plugin_delivery_item()
|
|||
|
{
|
|||
|
userid = member.id,
|
|||
|
crt_time = DateTime.Now,
|
|||
|
m_code = mcode,
|
|||
|
q_code = qcode,
|
|||
|
q_location = q_location,
|
|||
|
s_location = s_location,
|
|||
|
groupid = group.id,
|
|||
|
real_name = real_name,
|
|||
|
real_telnumber = telnumber,
|
|||
|
q_location_id = kuaidi!=null?kuaidi.id:0
|
|||
|
};
|
|||
|
session.Insertable<fl_plugin_delivery_item>(data).ExecuteCommand();
|
|||
|
session.ExcuteSQL($"update fl_plugin_delivery_hist set using_userid={member.id} where id={hist.id};");
|
|||
|
var robot = session.FindRobotInfo(member.robot_name, member.robot_type);
|
|||
|
if (robot != null)
|
|||
|
{
|
|||
|
var msg = group.TMsgSuccess1.Replace("[免单码]", mcode).Replace("[取件码]", qcode).Replace("[手机号]", telnumber).Replace("[收货地址]", s_location).Replace("[姓名]", real_name);
|
|||
|
ApiClient.SendMessage(robot, member.username, msg);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
e.Send("提交成功、请耐心等待配送!");
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
case "PrintOrder":
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
bool isadmin = group.admins.Split('|').Contains(member.id.ToString());
|
|||
|
if (isadmin)
|
|||
|
{
|
|||
|
|
|||
|
var id = int.Parse(e.Param["id"].ToString());
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
fl_plugin_delivery_item v = session.Queryable<fl_plugin_delivery_item>().Single(x => x.id == id);
|
|||
|
|
|||
|
if (v == null) throw new Exception("此订单已删除!");
|
|||
|
if (v.groupid != group.id) throw new Exception("非法操作!");
|
|||
|
|
|||
|
fl_plugin_delivery_kuaidi s = null;
|
|||
|
if (v.q_location_id != 0) s = session.Queryable<fl_plugin_delivery_kuaidi>().Single(x => x.id == v.q_location_id);
|
|||
|
else s = session.Queryable<fl_plugin_delivery_kuaidi>().Where(x => x.group_id == v.groupid && x.name == v.q_location).First();
|
|||
|
|
|||
|
if (s == null || string.IsNullOrEmpty(s.print_sn) || string.IsNullOrEmpty(s.print_model)) throw new Exception("该快递点,打印机已停止服务!");
|
|||
|
|
|||
|
var model = s.print_model.Replace("[姓名]",v.real_name).Replace("[手机]",v.real_telnumber).Replace("[取件码]",v.q_code).Replace("[收货位置]",v.s_location).Replace("[取件位置]",v.q_location).Replace("[编号]",v.id.ToString()).Replace("[免单码]",v.m_code);
|
|||
|
HttpHelper http = new HttpHelper();
|
|||
|
var item = http.GetItem("https://www.yprinter.com/api/Order/addOrder", "", $"secret={s.print_secret}&print_sn={s.print_sn}&print_num=1&order_content={System.Web.HttpUtility.UrlEncode(model, Encoding.UTF8)}");
|
|||
|
var html = http.GetHtml(item).Html;
|
|||
|
//{"code":104,"message":"\u5199\u5165\u65b0\u8ba2\u5355\u961f\u5217\u5931\u8d25","data":[]}
|
|||
|
var dic = HttpExtend.JsonToDictionary(html);
|
|||
|
if (dic != null)
|
|||
|
{
|
|||
|
int code = int.Parse(dic["code"].ToString());
|
|||
|
if (code != 100) throw new Exception(dic["message"].ToString());
|
|||
|
else e.Send(dic["message"].ToString());
|
|||
|
}
|
|||
|
else throw new Exception(html);
|
|||
|
//e.Send(dic==null?html:dic["message"].ToString());
|
|||
|
}
|
|||
|
else throw new Exception("权限不足!");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
e.Send(ex);
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
default:
|
|||
|
throw new Exception("暂不支持此函数!");
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
e.Send(ex);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void SDK_ReciveIMEvent(object sender, Api.Framework.SDK.ReciveIMEvent e)
|
|||
|
{ //
|
|||
|
if (string.IsNullOrEmpty(e.Groupid))
|
|||
|
{
|
|||
|
|
|||
|
//查询免单码
|
|||
|
if (e.Message == "免单码")
|
|||
|
{
|
|||
|
var group = GetGroup(e.RobotName); if (group == null) return;
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var m = e.GetMemberinfo();
|
|||
|
var count = 0;
|
|||
|
var histList = session.Queryable<fl_plugin_delivery_hist>().Where(x => x.userid == m.id && x.using_userid == 0 && x.effective).OrderBy(x => x.id, SqlSugar.OrderByType.Desc).ToPageList(0, 100, ref count);
|
|||
|
|
|||
|
StringBuilder sb = new StringBuilder();
|
|||
|
if (histList.Count == 0) sb.AppendLine("暂无");
|
|||
|
for (int i = 0; i < histList.Count; i++)
|
|||
|
{
|
|||
|
sb.AppendLine(histList[i].order_code);
|
|||
|
}
|
|||
|
var msg = group.CMsgSuccess1.Replace("[免单码列表]", sb.ToString().Trim()).Replace("[总数]", count.ToString()).Replace("[取件地址]", GetURL(URLType.取件地址, m));
|
|||
|
e.SendMessage(msg);
|
|||
|
return;
|
|||
|
}
|
|||
|
else if (e.Message == "查看订单")
|
|||
|
{
|
|||
|
var group = GetGroup(e.RobotName); if (group == null) return;
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var m = e.GetMemberinfo();
|
|||
|
if (group != null)
|
|||
|
{
|
|||
|
bool isadmin = group.admins.Split('|').Contains(m.id.ToString());
|
|||
|
if (isadmin)
|
|||
|
{
|
|||
|
e.SendMessage($"订单地址:\r\n"+GetURL(URLType.查看订单,m));
|
|||
|
e.Cancel = true;
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#region 订单绑定
|
|||
|
|
|||
|
#region 淘宝订单绑定
|
|||
|
if (Regex.IsMatch(e.Message.Trim(), @"^\d{18}$"))
|
|||
|
{
|
|||
|
var group = GetGroup(e.RobotName); if (group == null) return;
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var orderid = e.Message.Trim();//用户发送的订单号
|
|||
|
|
|||
|
var orders_temp = session.Find<fl_order_alimama>("select * from fl_order_alimama where trade_parent_id = @trade_parent_id", new { trade_parent_id = orderid });
|
|||
|
if (orders_temp != null && orders_temp.Count != 0)
|
|||
|
{
|
|||
|
var member = orders_temp.FirstOrDefault(f => f.db_userid != 0 && f.db_userid != e.GetMemberinfo().id);
|
|||
|
if (member != null)
|
|||
|
{
|
|||
|
e.SendMessage(group.BMsgError6.Replace("[订单号]", orderid));
|
|||
|
return;
|
|||
|
}
|
|||
|
var notices = new List<OrderNoticeEvent>();
|
|||
|
|
|||
|
var downAlimamaTimer = new DownAlimamaTimer();
|
|||
|
|
|||
|
#region 订单用户已经绑定 纯提示,非结算的订单也提示上级
|
|||
|
var bindOrders = orders_temp.Where(f => f.db_userid != 0).ToList();
|
|||
|
if (bindOrders != null && bindOrders.Count != 0)
|
|||
|
{
|
|||
|
foreach (var order in bindOrders)
|
|||
|
{
|
|||
|
//var point = HttpHelper.JsonToObject<ItemPoint>(order.db_point) as ItemPoint;
|
|||
|
//if (order.db_status == SystemOrderStatus.订单付款)
|
|||
|
e.SendMessage(new VariateReplace().CommonReplace(group.BMsgError5, order, e.GetMemberinfo(true)));
|
|||
|
//else
|
|||
|
// e.SendMessage(_GetOrderStateMess(order.db_status, (order.db_status == SystemOrderStatus.订单结算 ? SettleType.已结算提示 : SettleType.未结算提示), order, e.GetMemberinfo(true), point));
|
|||
|
Thread.Sleep(500);
|
|||
|
}
|
|||
|
//return;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 订单没有被绑定(两种情况 => 一个订单已经被结算 一个是订单未结算)
|
|||
|
var notBindOrders = orders_temp.Where(f => f.db_userid == 0).ToList();
|
|||
|
if (notBindOrders != null && notBindOrders.Count != 0)
|
|||
|
{
|
|||
|
foreach (var order in notBindOrders)
|
|||
|
{
|
|||
|
//if (order.db_status == SystemOrderStatus.订单结算)
|
|||
|
// order.db_endtime = DateTime.Now.AddMinutes(-5);//重新结算的话,需要将订单的冻结时间重新赋值,让后台处理
|
|||
|
|
|||
|
//没有绑定用户的订单进行绑定
|
|||
|
order.db_userid = e.GetMemberinfo().id;
|
|||
|
order.db_robotname = e.RobotName;
|
|||
|
order.db_robottype = e.RobotInfo.type;
|
|||
|
order.msg_groupid = e.Groupid;
|
|||
|
|
|||
|
#region 手动绑定,重新计算用户的返利积分 xxx
|
|||
|
//var itempoint = session.FindItemPoint(e.GetMemberinfo(), order.pub_share_pre_fee, order.item_num, CpsType.阿里妈妈);
|
|||
|
//if (itempoint != null)
|
|||
|
//{
|
|||
|
// order.db_point = HttpHelper.ObjectToJson(itempoint);
|
|||
|
// order.db_userpoint = itempoint.UserPoint;
|
|||
|
//}
|
|||
|
#endregion
|
|||
|
|
|||
|
session.SaveOrUpdate(order);
|
|||
|
|
|||
|
#region 淘宝订单尾号自动采集
|
|||
|
if (ApiClient.Setting.SystemConfig.order_alimama_last_auto_capture == SwitchType.开启)
|
|||
|
{
|
|||
|
//订单尾号和用户进行绑定
|
|||
|
if (session.FindAlimamaOrderLastnums().FirstOrDefault(f => f.userid == e.GetMemberinfo().id) == null)
|
|||
|
{
|
|||
|
session.Insertable(new fl_alimama_order_lastnum() { userid = e.GetMemberinfo().id, lastnumber = order.trade_parent_id.Substring(order.trade_parent_id.Length - 6, 6) }).ExecuteCommand();
|
|||
|
session.FindAlimamaOrderLastnums(true);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
if (order.db_status == SystemOrderStatus.订单付款 || order.db_status == SystemOrderStatus.订单失效 || order.db_status == SystemOrderStatus.订单维权中)
|
|||
|
downAlimamaTimer.UpdateOrder(order, notices, session, isFrontData: true);
|
|||
|
else
|
|||
|
{
|
|||
|
string mdcode = string.Empty;
|
|||
|
if (group.BMsgError3.Contains("[免单码]"))
|
|||
|
{
|
|||
|
var delivery_hist = session.FindSingle<fl_plugin_delivery_hist>("select * from fl_plugin_delivery_hist where userid = @userid and ordertable_id = @ordertable_id", new { userid = e.GetMemberinfo().id, ordertable_id = order.id });
|
|||
|
if (delivery_hist != null) mdcode = delivery_hist.order_code;
|
|||
|
}
|
|||
|
e.SendMessage(new VariateReplace().CommonReplace(group.BMsgError3, order, e.GetMemberinfo(true)).Replace("[免单码]", mdcode));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 触发通知上级获得下级的提成奖励
|
|||
|
if (notices.Count != 0)
|
|||
|
{
|
|||
|
foreach (var item in notices)
|
|||
|
{
|
|||
|
SDK_OrderNoticeEvent(this, item);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
e.Cancel = true;
|
|||
|
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
|
|||
|
e.SendMessage(group.BMsgError2.Replace("[订单号]", orderid));
|
|||
|
|
|||
|
//加入缓存
|
|||
|
var bind = session.FindBindCache(orderid);
|
|||
|
if (bind == null)
|
|||
|
{
|
|||
|
session.Insertable(new fl_bind_cache() { crt_time = DateTime.Now, db_robotid = e.RobotInfo.id, orderid = orderid, groupid = e.Groupid, db_userid = e.GetMemberinfo().id }).ExecuteCommand();
|
|||
|
}
|
|||
|
e.Cancel = true;
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 拼多多订单绑定
|
|||
|
if (Regex.IsMatch(e.Message.Trim(), @"^\d{6}-\d{15}$"))
|
|||
|
{
|
|||
|
var group = GetGroup(e.RobotName); if (group == null) return;
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
int i = 0;
|
|||
|
Next:
|
|||
|
var orderid = e.Message.Trim();
|
|||
|
|
|||
|
//通过宝贝的id 和 订单号 进行查询 查看是否存在
|
|||
|
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 != e.GetMemberinfo().id)
|
|||
|
{
|
|||
|
e.SendMessage(group.BMsgError6.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;
|
|||
|
//if (order.db_status == SystemOrderStatus.订单付款)
|
|||
|
e.SendMessage(new VariateReplace().CommonReplace(group.BMsgError5, order, e.GetMemberinfo(true)));
|
|||
|
//else
|
|||
|
// e.SendMessage(_GetOrderStateMess(order.db_status, order, e.GetMemberinfo(true), point));
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//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 = e.GetMemberinfo().id;
|
|||
|
session.SaveOrUpdate(order);
|
|||
|
|
|||
|
if (order.db_status == SystemOrderStatus.订单付款 || order.db_status == SystemOrderStatus.订单维权中)
|
|||
|
downPinduoduoTimer.UpdateOrder(order, session, notices, isFrontData: true);
|
|||
|
else
|
|||
|
e.SendMessage(new VariateReplace().CommonReplace(group.BMsgError3, order, e.GetMemberinfo(true)));
|
|||
|
}
|
|||
|
|
|||
|
//#region 触发通知上级获得下级的提成奖励
|
|||
|
//if (notices.Count != 0)
|
|||
|
//{
|
|||
|
// var tasks = TimerTask.GetTimer<Update_NoticeQueue>() as Update_NoticeQueue;
|
|||
|
// foreach (var item in notices)
|
|||
|
// {
|
|||
|
// 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(group.BMsgError2.Replace("[订单号]", orderid));
|
|||
|
e.Cancel = true;
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 京东订单绑定
|
|||
|
if (Regex.IsMatch(e.Message.Trim(), @"^\d{11,12}$"))
|
|||
|
{
|
|||
|
var group = GetGroup(e.RobotName); if (group == null) return;
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var orderId = e.Message.Trim(); //订单号
|
|||
|
var orders = session.Find<fl_order_jingdong>("select * from fl_order_jingdong where orderId = @orderId", new { orderId = orderId });
|
|||
|
|
|||
|
var _order = orders.FirstOrDefault(f => f.db_userid != 0 && f.db_userid != e.GetMemberinfo().id);
|
|||
|
if (_order != null)
|
|||
|
{
|
|||
|
e.SendMessage(group.BMsgError6.Replace("[订单号]", orderId));
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (orders != null && orders.Count != 0)
|
|||
|
{
|
|||
|
var notices = new List<OrderNoticeEvent>();
|
|||
|
var downJingdongTimer = new DownJingdongTimer();
|
|||
|
|
|||
|
#region 订单用户已经绑定 纯提示,非结算的订单也提示上级
|
|||
|
var bindOrders = orders.Where(f => f.db_userid != 0).ToList();
|
|||
|
if (bindOrders != null && bindOrders.Count != 0)
|
|||
|
{
|
|||
|
foreach (var order in bindOrders)
|
|||
|
{
|
|||
|
var point = HttpHelper.JsonToObject<ItemPoint>(order.db_point) as ItemPoint;
|
|||
|
//if (order.db_status == SystemOrderStatus.订单付款)
|
|||
|
e.SendMessage(new VariateReplace().CommonReplace(group.BMsgError5, order, point, e.GetMemberinfo(true)));
|
|||
|
//else
|
|||
|
// e.SendMessage(_GetOrderStateMess(order.db_status, (order.db_status == SystemOrderStatus.订单结算 ? SettleType.已结算提示 : SettleType.未结算提示), order, e.GetMemberinfo(true), point));
|
|||
|
Thread.Sleep(500);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 订单没有被绑定(两种情况 => 一个订单已经被结算 一个是订单未结算)
|
|||
|
var notBindOrders = orders.Where(f => f.db_userid == 0).ToList();
|
|||
|
if (notBindOrders != null && notBindOrders.Count != 0)
|
|||
|
{
|
|||
|
foreach (var order in notBindOrders)
|
|||
|
{
|
|||
|
//if (order.db_status == SystemOrderStatus.订单结算)
|
|||
|
// order.db_endtime = DateTime.Now.AddMinutes(-5);//重新结算的话,需要将订单的冻结时间重新赋值,让后台处理
|
|||
|
|
|||
|
//没有绑定用户的订单进行绑定
|
|||
|
order.db_userid = e.GetMemberinfo().id;
|
|||
|
order.db_robotname = e.RobotName;
|
|||
|
order.db_robottype = e.RobotInfo.type;
|
|||
|
order.msg_groupid = e.Groupid;
|
|||
|
|
|||
|
//#region 手动绑定,重新计算用户的返利积分
|
|||
|
//var itempoint = session.FindItemPoint(e.GetMemberinfo(), order.actualFee == 0 ? order.estimateFee : order.actualFee, (int)order.skuNum, CpsType.京东联盟);
|
|||
|
//if (itempoint != null)
|
|||
|
//{
|
|||
|
// order.db_point = HttpHelper.ObjectToJson(itempoint);
|
|||
|
// order.db_userpoint = itempoint.UserPoint;
|
|||
|
//}
|
|||
|
//#endregion
|
|||
|
|
|||
|
session.SaveOrUpdate(order);
|
|||
|
if (order.db_status == SystemOrderStatus.订单付款 || order.db_status == SystemOrderStatus.订单维权中)
|
|||
|
downJingdongTimer.UpdateOrder(order, session, notices, isFrontData: true);
|
|||
|
else
|
|||
|
e.SendMessage(new VariateReplace().CommonReplace(group.BMsgError3, order, e.GetMemberinfo(true)));
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 触发通知上级获得下级的提成奖励 xxx
|
|||
|
//if (notices.Count != 0)
|
|||
|
//{
|
|||
|
// var tasks = TimerTask.GetTimer<Update_NoticeQueue>() as Update_NoticeQueue;
|
|||
|
// foreach (var item in notices)
|
|||
|
// {
|
|||
|
// SDK_OrderNoticeEvent(this, item);
|
|||
|
// }
|
|||
|
//}
|
|||
|
#endregion
|
|||
|
|
|||
|
e.Cancel = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
e.SendMessage(group.BMsgError2.Replace("[订单号]", orderId));
|
|||
|
|
|||
|
//加入缓存
|
|||
|
var bind = session.FindBindCache(orderId);
|
|||
|
if (bind == null)
|
|||
|
{
|
|||
|
session.Insertable(new fl_bind_cache() { crt_time = DateTime.Now, db_robotid = e.RobotInfo.id, orderid = orderId, groupid = e.Groupid, db_userid = e.GetMemberinfo().id }).ExecuteCommand();
|
|||
|
}
|
|||
|
e.Cancel = true;
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
private static List<fl_plugin_delivery_group> _groups = null;
|
|||
|
public static List<fl_plugin_delivery_group> GetGroups(bool f5 = false)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (_groups == null || f5)
|
|||
|
{
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
_groups = session.Queryable<fl_plugin_delivery_group>().ToList();
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
}
|
|||
|
return _groups;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 获取分组信息
|
|||
|
/// </summary>
|
|||
|
/// <param name="member"></param>
|
|||
|
/// <returns></returns>
|
|||
|
private fl_plugin_delivery_group GetGroup(fl_member_info member)
|
|||
|
{
|
|||
|
var group = GetGroups().FirstOrDefault(f => f.GetWeixinhao().Contains(member.robot_name));
|
|||
|
if (group == null) throw new Exception($"找不到->{member.robot_name},机器人!");
|
|||
|
return group;
|
|||
|
}
|
|||
|
private fl_plugin_delivery_group GetGroup(string robotname)
|
|||
|
{
|
|||
|
var group = GetGroups().FirstOrDefault(f => f.GetWeixinhao().Contains(robotname));
|
|||
|
if (group == null) throw new Exception($"找不到->{robotname},机器人!");
|
|||
|
return group;
|
|||
|
}
|
|||
|
private byte[] aeskey = Encoding.UTF8.GetBytes("7b3b639bb3599aaf");
|
|||
|
private string GetEncuserinfo(fl_member_info member)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var json = HttpHelper.ObjectToJson(new { username = member.username, type = (int)member.robot_type, time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") });
|
|||
|
AESCryption enc = new AESCryption();
|
|||
|
return HttpExtend.ByteToHex(Encoding.UTF8.GetBytes(enc.AesEncrypt(json, aeskey)));
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
}
|
|||
|
return string.Empty;
|
|||
|
}
|
|||
|
private fl_member_info GetDecuserinfo(string data)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
AESCryption enc = new AESCryption();
|
|||
|
var json = Encoding.UTF8.GetString(HttpExtend.HexToByte(data));
|
|||
|
var mw = HttpExtend.JsonToDictionary(enc.AesDecrypt(json, aeskey));
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var member = session.Queryable<fl_member_info>().Where(f => f.robot_type.ToString() == mw["type"].ToString() && f.username == mw["username"].ToString()).Single();
|
|||
|
return member;
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
static string _codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";//要随机的字母
|
|||
|
public static string GetRandomCode(SqlSugar.SqlSugarClient session, int number = 6)
|
|||
|
{
|
|||
|
|
|||
|
Next:
|
|||
|
Random _rand = new Random(Guid.NewGuid().GetHashCode()); //随机类
|
|||
|
string _result = "";
|
|||
|
int length = _codes.Length;
|
|||
|
for (int i = 0; i < number; i++) //循环6次,生成6位数字,10位就循环10次
|
|||
|
{
|
|||
|
_result += _codes[_rand.Next(length)]; //通过索引下标随机
|
|||
|
|
|||
|
}
|
|||
|
var code = session.Queryable<fl_plugin_delivery_hist>().Single(f => f.order_code == _result);
|
|||
|
if (code != null) goto Next;
|
|||
|
return _result;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public override void Stop()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
this.OnLog(ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|