| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- 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 WifiTradeHelper
- {
- public readonly static WifiTradeHelper Instance = new WifiTradeHelper();
- private WifiTradeHelper()
- {
- }
- public void Start()
- {
- Thread th = new Thread(DoWorks);
- th.IsBackground = true;
- th.Start();
- }
- private void DoWorks()
- {
- while (true)
- {
- try
- {
- string Month = DateTime.Now.ToString("yyyyMM");
- string chk = function.ReadInstance("/wifi/trade" + Month + ".txt");
- if(string.IsNullOrEmpty(chk))
- {
- function.WritePage("/wifi/", "trade" + Month + ".txt", DateTime.Now.ToString());
- DoSomething(Month);
- }
- Thread.Sleep(3600000);
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "WIFI发放交易额异常");
- }
- }
- }
- public void DoSomething(string Month)
- {
- WebCMSEntities db = new WebCMSEntities();
- List<WifiTradeRecord> trades = db.WifiTradeRecord.Where(m => m.Duration > m.DoMonths && m.LastMonth != Month).ToList();
- foreach(WifiTradeRecord trade in trades)
- {
- if(trade.Unit == "m" && trade.Duration > 0)
- {
- decimal TradeAmt = trade.TradeAmount / trade.Duration;
- DateTime StartMonth = DateTime.Parse(DateTime.Now.ToString("yyyy-MM") + "-01 00:00:00");
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.PosSn == trade.SnNo) ?? new PosMachinesTwo();
- SycnSpTradeWifiService.Instance.StatTrade(db, pos.BuyUserId, pos.BrandId, StartMonth.ToString("yyyyMM"), TradeAmt);
- if (pos.BindingTime < trade.CreateDate.Value.AddMonths(-9))
- {
- SycnSpTradeWifiService.Instance.StatTradeBefore(db, pos.BuyUserId, pos.BrandId, StartMonth.ToString("yyyyMM"), TradeAmt);
- }
- else
- {
- SycnSpTradeWifiService.Instance.StatTradeAfter(db, pos.BuyUserId, pos.BrandId, StartMonth.ToString("yyyyMM"), TradeAmt);
- }
- WifiTradeRecord edit = db.WifiTradeRecord.FirstOrDefault(m => m.Id == trade.Id);
- if(edit != null)
- {
- edit.DoMonths += 1;
- edit.LastMonth = Month;
- }
- }
- db.SaveChanges();
- }
- db.Dispose();
- }
- }
|