public void AddBonusDistribute(BonusDistributeEntity entity)
 {
     entity.DistributeTime = DateTime.Now;
     persistence.Add(entity);
 }
        public void DistributeBonus(string gameName, string issueNumber)
        {
            try
            {
                using (ILHDBTran tran = BeginTran())
                {
                    BonusManager bonusManger = new BonusManager(tran);
                    UserManager userManager = new UserManager(tran);

                    BonusEntity bonusEntity = bonusManger.GetBonus(gameName, issueNumber);
                    if (bonusEntity == null)
                    {
                        throw new Exception("要分派的奖期信息不存在 - " + gameName + ":" + issueNumber);
                    }
                    if (bonusEntity.IsDistributed)
                    {
                        throw new Exception("此奖期已经派奖 - " + gameName + ":" + issueNumber);
                    }
                    IList<BonusDetailEntity> bonusDetailList = bonusManger.GetBonusDetailList(gameName, issueNumber);
                    TicketManager ticketManager = new TicketManager(tran);
                    foreach (BonusDetailEntity bonusDetail in bonusDetailList)
                    {
                        TicketEntity ticket = ticketManager.GetTicket(bonusDetail.TicketId);
                        if (ticket != null)
                        {
                            BonusDistributeEntity bonusDistribute = new BonusDistributeEntity();
                            bonusDistribute.TicketId = bonusDetail.TicketId;
                            bonusDistribute.BonusLevel = bonusDetail.BonusLevel;
                            bonusDistribute.UserId = ticket.UserId;
                            bonusDistribute.GameName = bonusDetail.GameName;
                            bonusDistribute.IssuseNumber = bonusDetail.IssuseNumber;
                            bonusDistribute.PlayType = bonusDetail.PlayType;
                            bonusDistribute.IsBombBonus = bonusDetail.IsBombBonus;
                            bonusDistribute.BonusSize = bonusDetail.Size;
                            bonusDistribute.Money = bonusDetail.Money;

                            bonusManger.AddBonusDistribute(bonusDistribute);

                            UserBalanceEntity balanceEntity = userManager.GetBalance(ticket.UserId);
                            if (balanceEntity == null)
                            {
                                throw new Exception("异常 - 彩民的账户不存在 - " + ticket.UserId);
                            }
                            if (!balanceEntity.Balance.HasValue)
                            {
                                throw new Exception("异常 - 彩民的账户为空 - " + ticket.UserId);
                            }
                            balanceEntity.Balance += bonusDetail.Money;
                            userManager.ModifyBalance(balanceEntity);
                        }
                    }
                    bonusEntity.IsDistributed = true;
                    bonusManger.ModifyBonusDistrbite(bonusEntity);

                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                string errMsg = "派奖失败 - " + gameName + ":" + issueNumber;
                throw HandleException(LogCategory.Distribute, errMsg, ex);
            }
        }
 public void AddBonusDistribute(BonusDistributeEntity entity)
 {
     entity.DistributeTime = DateTime.Now;
     persistence.Add(entity);
 }