123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using MySystem.Models.Main;
- using Library;
- using LitJson;
- using System.Text.RegularExpressions;
- using System.Threading;
- namespace MySystem
- {
- public class ProfitShareService
- {
- public readonly static ProfitShareService Instance = new ProfitShareService();
- private ProfitShareService()
- { }
- public void Start()
- {
- Thread th = new Thread(StartListen);
- th.IsBackground = true;
- th.Start();
- }
- public void StartListen()
- {
- while (true)
- {
- WebCMSEntities db = new WebCMSEntities();
- DateTime checkDate = DateTime.Now.AddMinutes(-2);
- var list = db.ConsumerOrders.Select(m => new { m.Id, m.DivideDate, m.DivideFlag, m.IsAct, m.PayMode }).Where(m => m.DivideFlag == 1 && m.IsAct == 1 && m.DivideDate < checkDate).OrderBy(m => m.Id).Take(100).ToList();
- foreach (var sub in list)
- {
- RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + sub.PayMode + ":List", sub.Id.ToString());
- ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == sub.Id);
- if (order != null)
- {
- order.DivideFlag = 2;
- db.SaveChanges();
- }
- }
- db.Dispose();
- Thread.Sleep(5000);
- }
- }
- public void StartDo(string content)
- {
- try
- {
- JsonData jsonObj = JsonMapper.ToObject(content);
- string ApplyNo = jsonObj["ApplyNo"].ToString(); //微信订单号
- string MchtNo = jsonObj["MchtNo"].ToString(); //商户订单号
- string OrderNo = jsonObj["OrderNo"].ToString(); //商户订单号
- WebCMSEntities db = new WebCMSEntities();
- ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.OrderNo == OrderNo && m.Status == 2);
- MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
- JsonData result = JsonMapper.ToObject(HaoDaHelper.Instance.OrderDivideAccountsQuery(ApplyNo, MchtNo, merchantAdd.BrandId));
- string state = result["data"]["status"].ToString();
- if (result["data"]["status"].ToString() == "0")
- {
- if (order != null)
- {
- RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
- }
- db.Dispose();
- }
- else
- {
- RedisDbconn.Instance.AddList("ProfitShareHdQueue", content);
- }
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "分账队列异常");
- }
- }
- // public void StartListen()
- // {
- // while (true)
- // {
- // string content = RedisDbconn.Instance.RPop<string>("ProfitShareHdQueue");
- // if (!string.IsNullOrEmpty(content))
- // {
- // StartDo(content);
- // }
- // else
- // {
- // Thread.Sleep(2000);
- // }
- // }
- // }
- // public void StartDo(string content)
- // {
- // try
- // {
- // JsonData jsonObj = JsonMapper.ToObject(content);
- // string ApplyNo = jsonObj["ApplyNo"].ToString(); //微信订单号
- // string MchtNo = jsonObj["MchtNo"].ToString(); //商户订单号
- // string OrderNo = jsonObj["OrderNo"].ToString(); //商户订单号
- // JsonData result = JsonMapper.ToObject(HaoDaHelper.Instance.OrderDivideAccountsQuery(ApplyNo, MchtNo));
- // string state = result["data"]["status"].ToString();
- // if (result["data"]["status"].ToString() == "0")
- // {
- // WebCMSEntities db = new WebCMSEntities();
- // ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.OrderNo == OrderNo && m.Status == 2);
- // if (order != null)
- // {
- // RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
- // }
- // db.Dispose();
- // }
- // else
- // {
- // RedisDbconn.Instance.AddList("ProfitShareHdQueue", content);
- // }
- // }
- // catch (Exception ex)
- // {
- // LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "分账队列异常");
- // }
- // }
- }
- }
|