12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- 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 ResetSmallStoreHelper
- {
- public readonly static ResetSmallStoreHelper Instance = new ResetSmallStoreHelper();
- private ResetSmallStoreHelper()
- {
- }
- public void Start()
- {
- Thread th = new Thread(DoWorks);
- th.IsBackground = true;
- th.Start();
- }
- // 每月1号小分仓额度,额度为上个月实际发放的总分润
- private void DoWorks()
- {
- while (true)
- {
- function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "\n\n", "计算小分仓额度日志");
- WebCMSEntities db = new WebCMSEntities();
- OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
- try
- {
- if(DateTime.Now.Day == 1 && DateTime.Now.Hour > 0 && DateTime.Now.Hour < 3)
- {
- string check = function.ReadInstance("/ResetSmallStore/" + DateTime.Now.ToString("yyyyMM") + ".txt");
- if(string.IsNullOrEmpty(check))
- {
- function.WritePage("/ResetSmallStore/", DateTime.Now.ToString("yyyyMM") + ".txt", DateTime.Now.ToString());
- string Month = DateTime.Now.ToString("yyyyMM");
- DataTable dt = OtherMySqlConn.dtable("select UserId,sum(ProfitAmount) from ProfitRecord where SeoTitle='" + Month + "' group by UserId");
- int index = 0;
- foreach(DataRow dr in dt.Rows)
- {
- index += 1;
- int UserId = int.Parse(function.CheckInt(dr["UserId"].ToString()));
- decimal ProfitAmount = decimal.Parse(function.CheckNum(dr[1].ToString()));
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == UserId);
- if (account == null)
- {
- account = db.UserAccount.Add(new UserAccount()
- {
- Id = UserId,
- UserId = UserId,
- }).Entity;
- db.SaveChanges();
- }
- account.ThisMonthPreAmount = ProfitAmount;
- account.ValidPreAmount = ProfitAmount;
- if(index % 200 == 0)
- {
- db.SaveChanges();
- }
- }
- 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);
- }
- }
- }
|