1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- using System;
- using System.Collections.Generic;
- using Library;
- using LitJson;
- using System.Linq;
- using System.Data;
- using MySystem.PxcModels;
- namespace MySystem
- {
- public class StatTimerService
- {
- public readonly static StatTimerService Instance = new StatTimerService();
- private StatTimerService()
- { }
- public void Start(JobMqMsg jobInfo)
- {
- try
- {
- dosomething();
- // string Msg = "success";
- // jobInfo.Status = Msg == "success" ? 1 : 0;
- // jobInfo.Msg = Msg == "success" ? "执行完成" : Msg;
- // RabbitMQClient.Instance.SendMsg(Newtonsoft.Json.JsonConvert.SerializeObject(jobInfo), "PublicBack");
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + ":" + ex.ToString(), "public_service");
- }
- }
- public void dosomething()
- {
- WebCMSEntities db = new WebCMSEntities();
- string yesterday = DateTime.Now.AddDays(-2).ToString("yyyy-MM-dd HH:mm:ss");
- string today = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- // 统计商户激活数据
- DataTable dt = dbconn.dtable("select UserId,BrandId,MerStandardDate from PosMerchantInfo where MerStandardDate>='" + yesterday + "' and MerStandardDate<'" + today + "' and QueryCount=0");
- dbconn.op("update PosMerchantInfo set QueryCount=1 where MerStandardDate>='" + yesterday + "' and MerStandardDate<'" + today + "' and QueryCount=0");
- foreach (DataRow dr in dt.Rows)
- {
- DateTime date = DateTime.Parse(dr["MerStandardDate"].ToString());
- string TradeMonth = date.ToString("yyyyMM");
- string TradeDate = date.ToString("yyyyMMdd");
- int UserId = int.Parse(dr["UserId"].ToString()); //创客ID
- int BrandId = int.Parse(dr["BrandId"].ToString()); //品牌
- int MerchantCount = 1;
- int Level = 0;
- while (UserId > 0)
- {
- Level += 1;
- Users user = db.Users.FirstOrDefault(m => m.Id == UserId);
- if (user != null)
- {
- if (user.AuthFlag == 1)
- {
- if (Level == 1)
- {
- RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
- RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
- RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
- RedisDbconn.Instance.AddInt("TotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
- }
- RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
- RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
- RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeDate, MerchantCount); //累计激活POS机商户
- RedisDbconn.Instance.AddInt("TeamTotalPosMerchant:" + UserId + ":" + BrandId + ":" + TradeMonth, MerchantCount); //累计激活POS机商户
- }
- UserId = user.ParentUserId;
- }
- else
- {
- UserId = 0;
- }
- }
- }
- db.Dispose();
- }
- }
- }
|