188 lines
7.1 KiB
C#
188 lines
7.1 KiB
C#
using Api.Framework;
|
|
using Api.Framework.Enums;
|
|
using Api.Framework.Model;
|
|
using Api.Framework.SDK;
|
|
using Api.Framework.Tools;
|
|
using Chat.Framework.WXSdk;
|
|
using Chat.Framework.WXSdk.Implement;
|
|
using CsharpHttpHelper;
|
|
using SqlSugar;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using TBRebate.Entitys;
|
|
using static TBRebate.Enums;
|
|
|
|
namespace TBRebate
|
|
{
|
|
|
|
|
|
|
|
|
|
class MonitorThread : TimerTask
|
|
{
|
|
|
|
private static Dictionary<string, cache_bind_orderid_temp> CacheBind = new Dictionary<string, cache_bind_orderid_temp>();
|
|
public static void AddCache(cache_bind_orderid_temp cache_bind)
|
|
{
|
|
try
|
|
{
|
|
lock (CacheBind)
|
|
{
|
|
if (!CacheBind.ContainsKey(cache_bind.orderId)) CacheBind.Add(cache_bind.orderId, cache_bind);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
public static void RemoveCache(cache_bind_orderid_temp cache_bind)
|
|
{
|
|
RemoveCache(cache_bind.orderId);
|
|
}
|
|
public static void RemoveCache(string orderid)
|
|
{
|
|
try
|
|
{
|
|
lock (CacheBind)
|
|
{
|
|
if (CacheBind.ContainsKey(orderid)) CacheBind.Remove(orderid);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取数据
|
|
/// </summary>
|
|
/// <param name="timeout">获取超时数据</param>
|
|
/// <returns></returns>
|
|
public static List<cache_bind_orderid_temp> GetCacheList(DateTime time_out)
|
|
{
|
|
|
|
try
|
|
{
|
|
lock (CacheBind)
|
|
{
|
|
var _list = CacheBind.Values.ToList();
|
|
if (time_out != DateTime.MaxValue) return _list.Where(f => f.bind_time < time_out).ToList();
|
|
else return _list;
|
|
|
|
//if (!CacheBind.ContainsKey(cache_bind.orderId)) CacheBind.Remove(cache_bind.orderId);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
return new List<cache_bind_orderid_temp>();
|
|
}
|
|
|
|
public static List<cache_bind_orderid_temp> GetCacheList()
|
|
{
|
|
return GetCacheList(DateTime.MaxValue);
|
|
}
|
|
public static void RemoveListCache(List<string> orders)
|
|
{
|
|
foreach (var item in orders) RemoveCache(item);
|
|
}
|
|
|
|
public override void Run(object state, bool timedOut)
|
|
{
|
|
try
|
|
{
|
|
var session = ApiClient.GetSession();
|
|
|
|
//获得缓存数据
|
|
var list = GetCacheList();
|
|
if (list != null && list.Count != 0)
|
|
{
|
|
//var delList = new List<string>();//需要删除的
|
|
var orders_temp = session.Find<fl_order_alimama>("select * from fl_order_alimama where (db_status != 1004 and db_status != 1003 and db_status != 999) and create_time > @time", new { time = DateTime.Now.AddHours(-5) });
|
|
if (orders_temp != null && orders_temp.Count != 0)
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
try
|
|
{
|
|
var order = orders_temp.FirstOrDefault(f => f.trade_parent_id == item.orderId);
|
|
if (order != null && order.db_userid != 0)
|
|
RemoveCache(item);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
EventClient.OnEvent(this, "缓存处理异常:" + ex.Message + " - " + ex.StackTrace);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
//List<fl_order_alimama> orders = null;
|
|
//foreach (var item in list)
|
|
//{
|
|
// try
|
|
// {
|
|
// orders = orders_temp.Where(f => f.trade_parent_id == item.orderId).ToList();
|
|
// foreach (var order in orders)
|
|
// {
|
|
// //用户绑定订单
|
|
// order.db_robotname = item.db_robotname;
|
|
// order.db_robottype = item.db_robottype;
|
|
// order.msg_groupid = item.groupid;
|
|
// order.db_userid = item.db_userid;
|
|
// var member = session.FindMemberinfo(item.db_userid);
|
|
// var itempoint = session.FindItemPoint(member, order.pub_share_pre_fee, order.item_num, CpsType.阿里妈妈);
|
|
// if (itempoint != null)
|
|
// {
|
|
// order.db_point = HttpHelper.ObjectToJson(itempoint);
|
|
// order.db_userpoint = itempoint.UserPoint;
|
|
// session.SaveOrUpdate(order);
|
|
|
|
// var robotInfo = session.FindRobotInfo(item.db_robotname, item.db_robottype);
|
|
|
|
// if (member != null && robotInfo != null)
|
|
// {
|
|
// ApiClient.SendMessage(robotInfo, member.username, Class1._GetOrderStateMess(order.db_status, SettleType.未结算提示, order, member, robotInfo).Replace("[返利积分]", itempoint.UserPoint.ToString()), item.groupid);
|
|
// Thread.Sleep(500);
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
// catch (Exception)
|
|
// {
|
|
// }
|
|
// //删除已存在订单
|
|
// if (orders.Count != 0) RemoveCache(item);
|
|
//}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//超过30分钟未绑定成功 - 应该给予客户提示
|
|
var time_out_list = GetCacheList(DateTime.Now.AddHours(-20));
|
|
foreach (var item in time_out_list)
|
|
{
|
|
RemoveCache(item);
|
|
|
|
//if (item.db_robottype != ChatType.微信) continue;
|
|
//var ipad = Chat.Framework.ChatClient.WXClient.FirstOrDefault(f=>f.Key == item.db_robotname).Value;
|
|
//if (ipad == null) continue;
|
|
////给予超时提示语
|
|
////ipad.SendMessage();
|
|
}
|
|
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
EventClient.OnEvent(this, $"缓存绑定异常:{ex.Message} - {ex.StackTrace}");
|
|
}
|
|
}
|
|
|
|
}
|
|
} |