1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Linq;
- using System.Data;
- using MySystem;
- using MySystem.PxcModels;
- using Library;
- using LitJson;
- public class StoreApplyHelper
- {
- public readonly static StoreApplyHelper Instance = new StoreApplyHelper();
- private StoreApplyHelper()
- {
- }
- public void Start()
- {
- Thread th = new Thread(DoWorks);
- th.IsBackground = true;
- th.Start();
- }
- private void DoWorks()
- {
- while (true)
- {
- WebCMSEntities db = new WebCMSEntities();
- try
- {
- if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 0 && DateTime.Now.Hour < 3)
- {
- string check = function.ReadInstance("/StoreApply/" + DateTime.Now.ToString("yyyyMM") + ".txt");
- if(string.IsNullOrEmpty(check))
- {
- function.WritePage("/StoreApply/", DateTime.Now.ToString("yyyyMM") + ".txt", DateTime.Now.ToString());
- db.SaveChanges();
- }
- }
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "计算分仓申请机具额度异常");
- }
- db.Dispose();
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "计算分仓申请机具额度日志");
- Thread.Sleep(60000);
- }
- }
- public void StartEverTime()
- {
- Thread th = new Thread(StartEverTimeDo);
- th.IsBackground = true;
- th.Start();
- }
- private void StartEverTimeDo()
- {
- while (true)
- {
- WebCMSEntities db = new WebCMSEntities();
- try
- {
- string data = RedisDbconn.Instance.Get<string>("StoreApplyQueue");
- if(!string.IsNullOrEmpty(data))
- {
- JsonData jsonObj = JsonMapper.ToObject(data);
- if(jsonObj["Kind"].ToString() == "1")
- {
- int OrderId = int.Parse(jsonObj["Data"]["OrderId"].ToString());
- Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
- if(order != null)
- {
- decimal TotalPrice = order.TotalPrice;
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId);
- if(account != null)
- {
- account.TempAmount += TotalPrice;
- account.ValidAmount += TotalPrice;
- }
- }
- }
- db.SaveChanges();
- }
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "分仓向总仓申请机具线程异常");
- }
- db.Dispose();
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "分仓向总仓申请机具线程日志");
- Thread.Sleep(60000);
- }
- }
- }
|