12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- 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<string>("TradeFilterQueue");
- if (!string.IsNullOrEmpty(data))
- {
- try
- {
- 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.Dispose();
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "训练营拦截奖励异常");
- }
- }
- else
- {
- Thread.Sleep(500);
- }
- }
- }
- }
- }
|