123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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());
- // OtherMySqlConn.connstr =
- 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.RPop<string>("StoreApplyQueue");
- if(!string.IsNullOrEmpty(data))
- {
- function.WriteLog("data:" + data, "分仓向总仓申请机具日志");
- JsonData jsonObj = JsonMapper.ToObject(data);
- if(jsonObj["Kind"].ToString() == "1")
- {
- function.WriteLog("1", "分仓向总仓申请机具日志");
- int OrderId = int.Parse(jsonObj["Data"]["OrderId"].ToString());
- Orders order = db.Orders.FirstOrDefault(m => m.Id == OrderId);
- if(order != null)
- {
- function.WriteLog("2", "分仓向总仓申请机具日志");
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == order.UserId);
- if (account == null)
- {
- account = db.UserAccount.Add(new UserAccount()
- {
- Id = order.UserId,
- UserId = order.UserId,
- }).Entity;
- db.SaveChanges();
- }
- decimal TotalPrice = order.TotalPrice * 2;
- decimal BeforeTotalAmount = account.TempAmount; //变更前总金额
- account.TempAmount += TotalPrice;
- account.ValidAmount += TotalPrice;
- decimal AfterTotalAmount = account.TempAmount; //变更后总金额
- StoreHouseAmountRecord record = db.StoreHouseAmountRecord.Add(new StoreHouseAmountRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- OperateType = 1,
- AmountType = 1,
- AfterAmount = AfterTotalAmount,
- BeforeAmount = BeforeTotalAmount,
- UseAmount = TotalPrice,
- UserId = order.UserId,
- QueryCount = order.Id,
- }).Entity;
- db.SaveChanges();
- }
- }
- db.SaveChanges();
- }
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "分仓向总仓申请机具线程异常");
- }
- db.Dispose();
- }
- }
- }
|