123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- using System;
- using System.Collections.Generic;
- using Library;
- using LitJson;
- using System.Linq;
- using MySystem.PxcModels;
- namespace MySystem
- {
- public class ConsumerOrdersStatService
- {
- public readonly static ConsumerOrdersStatService Instance = new ConsumerOrdersStatService();
- private ConsumerOrdersStatService()
- { }
- public void Start(JobMqMsg jobInfo)
- {
- string content = "";
- 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)
- {
- if (!string.IsNullOrEmpty(content))
- {
- Dictionary<string, string> data = new Dictionary<string, string>();
- data.Add("ErrTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
- data.Add("ErrMsg", ex.ToString());
- TendisDbconn.Instance.AddList("public_err", data);
- }
- else
- {
- TendisDbconn.Instance.AddList("public_service", DateTime.Now.ToString() + ":" + ex.ToString());
- }
- }
- }
- public void dosomething()
- {
- bool op = true;
- while (op)
- {
- int OrderId = TendisDbconn.Instance.RPop<int>("ConsumerOrdersStat");
- if (OrderId > 0)
- {
- WebCMSEntities db = new WebCMSEntities();
- using (var tran = db.Database.BeginTransaction())
- {
- try
- {
- ConsumerOrders order = db.ConsumerOrders.FirstOrDefault(m => m.Id == OrderId);
- if (order != null)
- {
- order.PayMoney = order.PayMoney * 10000M;
- string TradeMonth = order.UpdateDate.Value.ToString("yyyyMM");
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == order.MerchantId);
- if (merchant != null)
- {
- merchant.LastConsumeDate = order.UpdateDate;
- merchant.TotalConsumeCount += 1;
- merchant.TotalOrder += 1;
- db.SaveChanges();
- BothdisDbconn.Instance.AddNumber("TotalAmount:" + merchant.UserId, order.PayMoney);
- decimal TotalAmount = BothdisDbconn.Instance.Get<decimal>("TotalAmount:" + merchant.UserId);
- BothdisDbconn.Instance.AddNumber("TotalAmount:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
- // 微信/支付宝
- if (order.PayMode == 1)
- {
- BothdisDbconn.Instance.AddInt("TotalOrder:Alipay:" + merchant.UserId + ":" + TradeMonth);
- }
- else
- {
- BothdisDbconn.Instance.AddInt("TotalOrder:WeChat:" + merchant.UserId + ":" + TradeMonth);
- }
- // 活动、非活动
- if (order.IsAct == 1)
- {
- BothdisDbconn.Instance.AddNumber("TotalAmount:Active:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
- }
- else
- {
- BothdisDbconn.Instance.AddNumber("TotalAmount:UnActive:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
- }
- // 遍历上级,累加团队数据
- int UserId = merchant.UserId;
- int Level = 0;
- while (UserId > 0)
- {
- Level += 1;
- Users user = db.Users.FirstOrDefault(m => m.Id == UserId);
- if (user != null)
- {
- if (Level >= 1)
- {
- BothdisDbconn.Instance.AddNumber("TeamTotalAmount:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
- // 微信/支付宝
- if (order.PayMode == 1)
- {
- BothdisDbconn.Instance.AddInt("TeamTotalOrder:Alipay:" + merchant.UserId + ":" + TradeMonth);
- }
- else
- {
- BothdisDbconn.Instance.AddInt("TeamTotalOrder:WeChat:" + merchant.UserId + ":" + TradeMonth);
- }
- // 活动、非活动
- if (order.IsAct == 1)
- {
- BothdisDbconn.Instance.AddNumber("TeamTotalAmount:Active:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
- }
- else
- {
- BothdisDbconn.Instance.AddNumber("TeamTotalAmount:UnActive:" + merchant.UserId + ":" + TradeMonth, order.PayMoney);
- }
- }
- UserId = user.ParentUserId;
- }
- else
- {
- UserId = 0;
- }
- }
- // 判断激活商户,从绑定音箱码开始,30天内,活动交易额满1000为激活
- if (merchant.BindStatus == 1 && merchant.BindDate > DateTime.Now.AddDays(-30) && TotalAmount >= 1000)
- {
- merchant.ActivationStatus = 1;
- merchant.ActivationDate = DateTime.Now;
- db.SaveChanges();
- BothdisDbconn.Instance.AddInt("TotalActMerchant:" + merchant.UserId + ":" + DateTime.Now.ToString("yyyyMM"));
- }
- }
- tran.Commit();
- }
- }
- catch (Exception ex)
- {
- tran.Rollback();
- TendisDbconn.Instance.AddList("public_service", DateTime.Now.ToString() + ":" + ex.ToString());
- }
- }
- db.Dispose();
- }
- else
- {
- op = false;
- }
- }
- }
- }
- }
|