using System; using System.Collections.Generic; using Library; using LitJson; using System.Linq; using System.Data; using System.Threading; using MySystem.PxcModels; namespace MySystem { public class TradeFilterService { public readonly static TradeFilterService Instance = new TradeFilterService(); private TradeFilterService() { } public void Start() { Thread th = new Thread(dosomething); th.IsBackground = true; th.Start(); } public void dosomething() { while (true) { string data = RedisDbconn.Instance.RPop("TradeFilterQueue"); if (!string.IsNullOrEmpty(data)) { try { function.WriteLog(data, "训练营60拦截队列日志"); JsonData jsonOj = JsonMapper.ToObject(data); int Kind = int.Parse(function.CheckInt(jsonOj["Kind"].ToString())); int OrderId = int.Parse(function.CheckInt(jsonOj["OrderId"].ToString())); int PrizeUserId = int.Parse(function.CheckInt(jsonOj["PrizeUserId"].ToString())); decimal Amount = decimal.Parse(function.CheckNum(jsonOj["Amount"].ToString())); WebCMSEntities db = new WebCMSEntities(); Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId) ?? new Orders(); Users user = db.Users.FirstOrDefault(m => m.Id == order.UserId) ?? new Users(); db.TradeFilterRecord.Add(new TradeFilterRecord() { CreateDate = DateTime.Now, IntercetpAmount = Amount, OrderDate = order.PayDate, OrderNo = order.OrderNo, OrderId = order.Id, PrizeUserId = PrizeUserId, OrderUserId = order.UserId, Kind = Kind, }); db.SaveChanges(); db.Dispose(); function.WriteLog("入库成功", "训练营60拦截队列日志"); } catch (Exception ex) { function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "训练营拦截奖励异常"); } } else { Thread.Sleep(500); } } } } }