1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using System.Threading;
- using MySystem.PxcModels;
- using Library;
- using LitJson;
- namespace MySystem
- {
- public class OperateAddService
- {
- public readonly static OperateAddService Instance = new OperateAddService();
- private OperateAddService()
- { }
- public void Start()
- {
- Thread th = new Thread(ready);
- th.IsBackground = true;
- th.Start();
- }
-
- private void ready()
- {
- bool op = true;
- while (op)
- {
- string content = RedisDbconn.Instance.RPop<string>("OperateAddServiceQueue");
- if (!string.IsNullOrEmpty(content))
- {
- try
- {
- dosomething(int.Parse(function.CheckInt(content)));
- }
- catch(Exception ex)
- {
- function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "添加运营中心合伙人异常");
- }
- }
- else
- {
- Thread.Sleep(2000);
- }
- }
- }
- public void dosomething(int Id)
- {
- WebCMSEntities db = new WebCMSEntities();
- OpModels.WebCMSEntities opdb = new OpModels.WebCMSEntities();
- OpModels.SysAdmin edit = opdb.SysAdmin.FirstOrDefault(m => m.Id == Id);
- if (edit != null)
- {
- UserRankItem orderUser = PosCouponPrizeService.Instance.GetUserLevel(db, edit.UserId);
- string ParentNav = orderUser.ParentNav + "," + orderUser.Id + ",";
- string[] ParentNavList = ParentNav.Trim(',').Replace(",,", ",").Split(',');
- Array.Reverse(ParentNavList);
- int index = 0;
- bool PrizeFlag = false; //奖励发放标识
- foreach(string ParentId in ParentNavList)
- {
- UserRankItem parentUser = PosCouponPrizeService.Instance.GetUserLevel(db, int.Parse(ParentId));
- index += 1;
- if(parentUser.OperateLevel > 1 && PosCouponPrizeService.Instance.CheckOpReserve(opdb, 16000M, parentUser.Id) && !PrizeFlag)
- {
- //扣减备用金
- PosCouponPrizeService.Instance.OperateAmountChange(opdb, parentUser.Id, 16000, 2, 1, "购买运营中心", true);
- //返回到余额
- PosCouponPrizeService.Instance.OperateAmountChange(opdb, parentUser.Id, 16000, 1, 2, "购买运营中心", true);
- //发放5888推荐奖励
- PosCouponPrizeService.Instance.OpAccount(db, parentUser.Id, parentUser.Id, 5888, 1);
- PrizeFlag = true;
- }
- }
- }
- db.Dispose();
- opdb.Dispose();
- }
- }
- }
|