|
@@ -1,11 +1,11 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
-using MySystem.Models.Main;
|
|
|
-using Library;
|
|
|
-using LitJson;
|
|
|
using System.Text.RegularExpressions;
|
|
|
using System.Threading;
|
|
|
+using Library;
|
|
|
+using LitJson;
|
|
|
+using MySystem.Models.Main;
|
|
|
|
|
|
namespace MySystem
|
|
|
{
|
|
@@ -26,74 +26,135 @@ namespace MySystem
|
|
|
{
|
|
|
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)
|
|
|
+ // 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);
|
|
|
+
|
|
|
+ string content = RedisDbconn.Instance.RPop<string>("PartOrderStatusQueue");
|
|
|
+ if(!string.IsNullOrEmpty(content))
|
|
|
{
|
|
|
- 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();
|
|
|
- }
|
|
|
+ StartExcute(content);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Thread.Sleep(60000);
|
|
|
}
|
|
|
- db.Dispose();
|
|
|
- Thread.Sleep(5000);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void StartDo(string content)
|
|
|
+ public void StartExcute(string content)
|
|
|
{
|
|
|
- try
|
|
|
+ JsonData jsonData = JsonMapper.ToObject(content);
|
|
|
+ string applyNo = jsonData["applyNo"].ToString();
|
|
|
+ string mchtNo = jsonData["mchtNo"].ToString();
|
|
|
+ string status = jsonData["status"].ToString();
|
|
|
+ string payTime = jsonData["payTime"].ToString();
|
|
|
+ string desc = jsonData["desc"].ToString();
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.TradePayNo == applyNo);
|
|
|
+ if(order != null)
|
|
|
{
|
|
|
- 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();
|
|
|
+ if(status == "0")
|
|
|
+ {
|
|
|
+ order.DivideFlag = 2;
|
|
|
+ order.DivideDate = DateTime.Now;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ order.DivideFlag = -1;
|
|
|
+ }
|
|
|
+ order.DivideLog = desc;
|
|
|
+ db.SaveChanges();
|
|
|
+ RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
|
|
|
- JsonData result = JsonMapper.ToObject(HaoDaHelper.Instance.OrderDivideAccountsQuery(ApplyNo, MchtNo, merchantAdd.BrandId));
|
|
|
- string state = result["data"]["status"].ToString();
|
|
|
- if (result["data"]["status"].ToString() == "0")
|
|
|
+ public void StartCheck()
|
|
|
+ {
|
|
|
+ Thread th = new Thread(StartCheckListen);
|
|
|
+ th.IsBackground = true;
|
|
|
+ th.Start();
|
|
|
+ }
|
|
|
+ public void StartCheckListen()
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ try
|
|
|
{
|
|
|
- if (order != null)
|
|
|
+ if(DateTime.Now.Hour > 0 && DateTime.Now.Hour < 20)
|
|
|
{
|
|
|
- RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
|
|
|
+ string CheckDate = DateTime.Now.ToString("yyyyMMdd");
|
|
|
+ string check = function.ReadInstance("/CheckYesterdayPartOrder/" + CheckDate + ".txt");
|
|
|
+ if (string.IsNullOrEmpty(check))
|
|
|
+ {
|
|
|
+ function.WritePage("/CheckYesterdayPartOrder/", CheckDate + ".txt", DateTime.Now.ToString());
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+ DateTime checkDate = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
|
|
|
+ var list = db.ConsumerOrders.Select(m => new { m.Id, m.DivideDate, m.DivideFlag, m.IsAct, m.PayMode }).Where(m => m.DivideFlag < 2 && m.IsAct == 1 && m.DivideDate < checkDate).OrderBy(m => m.Id).Take(100).ToList();
|
|
|
+ foreach (var sub in list)
|
|
|
+ {
|
|
|
+ StartCheckDo(sub.Id);
|
|
|
+ }
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
}
|
|
|
- db.Dispose();
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "分账复核头天订单异常");
|
|
|
+ }
|
|
|
+ Thread.Sleep(3600000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void StartCheckDo(int Id)
|
|
|
+ {
|
|
|
+ WebCMSEntities db = new WebCMSEntities();
|
|
|
+
|
|
|
+ ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == Id) ?? new ConsumerOrders();
|
|
|
+ MerchantAddInfo merchantAdd = db.MerchantAddInfo.FirstOrDefault(m => m.Id == order.MerchantId) ?? new MerchantAddInfo();
|
|
|
+
|
|
|
+ JsonData result = JsonMapper.ToObject(HaoDaHelper.Instance.OrderDivideAccountsQuery(order.TradePayNo, merchantAdd.OutMchtNo, merchantAdd.BrandId));
|
|
|
+ if(result["resultCode"].ToString() == "1")
|
|
|
+ {
|
|
|
+ string status = result["data"]["status"].ToString();
|
|
|
+ string desc = result["data"]["desc"].ToString();
|
|
|
+ if (status == "0")
|
|
|
+ {
|
|
|
+ order.DivideFlag = 2;
|
|
|
+ order.DivideDate = DateTime.Now;
|
|
|
+ RedisDbconn.Instance.AddList("ConsumerOrdersHd:Divi:" + order.PayMode + ":List", order.Id.ToString());
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- RedisDbconn.Instance.AddList("ProfitShareHdQueue", content);
|
|
|
+ order.DivideFlag = -1;
|
|
|
}
|
|
|
+ order.DivideLog = desc;
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ else
|
|
|
{
|
|
|
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "分账队列异常");
|
|
|
+ string errorCode = result["errorCode"].ToString();
|
|
|
+ string errorDesc = result["errorDesc"].ToString();
|
|
|
+ order.DivideFlag = -1;
|
|
|
+ order.DivideLog = errorCode + ":" + errorDesc;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
+ db.SaveChanges();
|
|
|
|
|
|
- // public void StartListen()
|
|
|
- // {
|
|
|
- // while (true)
|
|
|
- // {
|
|
|
- // string content = RedisDbconn.Instance.RPop<string>("ProfitShareHdQueue");
|
|
|
- // if (!string.IsNullOrEmpty(content))
|
|
|
- // {
|
|
|
- // StartDo(content);
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // Thread.Sleep(2000);
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
+ db.Dispose();
|
|
|
+ }
|
|
|
|
|
|
// public void StartDo(string content)
|
|
|
// {
|