1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- using System;
- using System.Collections.Generic;
- using Library;
- using LitJson;
- using System.Linq;
- using System.Data;
- using System.Threading;
- using MySystem.PxcModels;
- 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)
- {
- decimal ChangeAmount = 10;
- if(pos.BrandId == 14)
- {
- ChangeAmount = 19 * 0.15M;
- }
- 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 += ChangeAmount;
- account.TotalAmount += ChangeAmount;
- 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 = ChangeAmount, //变更金额
- BeforeTotalAmount = BeforeTotalAmount, //变更前总金额
- AfterTotalAmount = AfterTotalAmount, //变更后总金额
- BeforeFreezeAmount = BeforeFreezeAmount, //变更前冻结金额
- AfterFreezeAmount = AfterFreezeAmount, //变更后冻结金额
- BeforeBalanceAmount = BeforeBalanceAmount, //变更前余额
- AfterBalanceAmount = AfterBalanceAmount, //变更后余额
- QueryCount = PosId,
- }).Entity;
- db.SaveChanges();
- }
- db.Dispose();
- }
- catch (Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "大盟主奖励异常");
- }
- Thread.Sleep(100);
- }
- else
- {
- Thread.Sleep(60000);
- }
- }
- }
- }
- }
|