123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- using System;
- using System.Collections.Generic;
- using Library;
- using LitJson;
- using System.Linq;
- using System.Data;
- using System.Threading;
- using MySystem.Models;
- namespace MySystem
- {
- public class LeaderPrizeService
- {
- public readonly static LeaderPrizeService Instance = new LeaderPrizeService();
- private LeaderPrizeService()
- { }
- public void Start()
- {
- Thread th = new Thread(dosomething);
- th.IsBackground = true;
- th.Start();
- }
- public void dosomething()
- {
- while (true)
- {
- string data = RedisDbconn.Instance.RPop<string>("LeaderPrizeQueue");
- if (!string.IsNullOrEmpty(data))
- {
- try
- {
- int PosId = int.Parse(function.CheckInt(data));
- WebCMSEntities db = new WebCMSEntities();
- PosMachinesTwo pos = db.PosMachinesTwo.FirstOrDefault(m => m.Id == PosId);
- if (pos != null)
- {
- int LeaderUserId = pos.LeaderUserId;
- UserAccount account = db.UserAccount.FirstOrDefault(m => m.Id == LeaderUserId);
- if (account == null)
- {
- account = db.UserAccount.Add(new UserAccount()
- {
- Id = LeaderUserId,
- UserId = LeaderUserId,
- }).Entity;
- db.SaveChanges();
- }
- decimal BeforeTotalAmount = account.TotalAmount;
- decimal BeforeFreezeAmount = account.FreezeAmount;
- decimal BeforeBalanceAmount = account.BalanceAmount;
- account.BalanceAmount += 10;
- account.TotalAmount += 10;
- decimal AfterTotalAmount = account.TotalAmount;
- decimal AfterFreezeAmount = account.FreezeAmount;
- decimal AfterBalanceAmount = account.BalanceAmount;
- UserAccountRecord userAccountRecord = db.UserAccountRecord.Add(new UserAccountRecord()
- {
- CreateDate = DateTime.Now,
- UpdateDate = DateTime.Now,
- UserId = LeaderUserId,
- ChangeType = 116,
- ChangeAmount = 10,
- BeforeTotalAmount = BeforeTotalAmount,
- AfterTotalAmount = AfterTotalAmount,
- BeforeFreezeAmount = BeforeFreezeAmount,
- AfterFreezeAmount = AfterFreezeAmount,
- BeforeBalanceAmount = BeforeBalanceAmount,
- AfterBalanceAmount = AfterBalanceAmount,
- QueryCount = PosId,
- }).Entity;
- db.SaveChanges();
- }
- db.Dispose();
- }
- catch (Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "大盟主奖励异常");
- }
- Thread.Sleep(100);
- }
- else
- {
- Thread.Sleep(60000);
- }
- }
- }
- }
- }
|