123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using MySystem.PxcModels;
- using Library;
- using System.Threading;
- using Microsoft.Extensions.Hosting;
- using System.Threading.Tasks;
- namespace MySystem
- {
- public class HelpProfitHelper
- {
- public readonly static HelpProfitHelper Instance = new HelpProfitHelper();
- private HelpProfitHelper()
- {
- }
-
- public void Start()
- {
- Thread th = new Thread(StartFor);
- th.IsBackground = true;
- th.Start();
- }
- public void StartFor()
- {
- while (true)
- {
- if(DateTime.Now.Day == 1 && DateTime.Now.Hour >= 2 && DateTime.Now.Hour <= 8)
- {
- StatProfitEveryDay(DateTime.Now.AddMonths(-1).ToString("yyyyMM"));
- }
- Thread.Sleep(600000);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public void StatProfitEveryDay(string Month)
- {
- string check = function.ReadInstance("/HelpProfitStat/" + Month + ".txt");
- if (!string.IsNullOrEmpty(check))
- {
- return;
- }
- function.WritePage("/HelpProfitStat/", Month + ".txt", DateTime.Now.ToString());
- WebCMSEntities db = new WebCMSEntities();
- OtherMySqlConn.connstr = Library.ConfigurationManager.AppSettings["Pxc1SqlConnStr"].ToString();
- var orders = db.Orders.Select(m => new { m.UserId, m.Status, m.ProductId }).Where(m => m.Status > 0 && m.ProductId == 34).ToList();
- DataTable list = OtherMySqlConn.dtable("select UserId,sum(TradeAmount) from HelpProfitMerchantForUser u,HelpProfitMerTradeSummay s where u.MerchantId=s.MerchantId and TradeMonth='" + Month + "' group by UserId");
- function.WriteLog("开始:" + DateTime.Now.ToString(), "助利宝分润日志");
- function.WriteLog("总数:" + list.Rows.Count, "助利宝分润日志");
- int index = 0;
- foreach (DataRow sub in list.Rows)
- {
- index += 1;
- int UserId = int.Parse(sub["UserId"].ToString());
- decimal TradeAmount = decimal.Parse(sub[1].ToString());
- Users user = db.Users.FirstOrDefault(m => m.Id == UserId) ?? new Users();
- decimal money = TradeAmount * 0.0005M;
- decimal money2 = TradeAmount * 0.00005M;
- AddProfitRecord(db, user, TradeAmount, money, Month, 1);
- db.SaveChanges();
- int ParentUserId = user.ParentUserId;
- while (ParentUserId > 0)
- {
- Users puser = db.Users.FirstOrDefault(m => m.Id == ParentUserId);
- if (puser != null)
- {
- bool checkorder = orders.Any(m => m.UserId == ParentUserId);
- if (checkorder)
- {
- AddProfitRecord(db, puser, TradeAmount, money2, Month, 112);
- db.SaveChanges();
- ParentUserId = 0;
- }
- else
- {
- ParentUserId = puser.ParentUserId;
- }
- }
- else
- {
- ParentUserId = 0;
- }
- }
- function.WriteLog(index + "--UserId:" + UserId + ";TradeAmount:" + TradeAmount + ";" + DateTime.Now.ToString(), "助利宝分润日志");
- }
- db.Dispose();
- function.WriteLog("结束:" + DateTime.Now.ToString(), "助利宝分润日志");
- }
- private void AddProfitRecord(WebCMSEntities db, Users puser, decimal TradeAmount, decimal Prize, string TradeMonth, int RewardType)
- {
- if(Prize == 0)
- {
- return;
- }
- string RewardDesc = "助利宝分润";
- if(RewardType == 112)
- {
- RewardDesc = "助利宝推荐分润";
- }
- db.HelpProfitReward.Add(new HelpProfitReward()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- TradeMonth = TradeMonth,
- UserId = puser.Id,
- RewardType = RewardType,
- CreditTradeAmt = TradeAmount,
- CreditRewardAmount = Prize,
- RewardDesc = RewardDesc,
- });
- }
- }
- }
|