Ejemplo n.º 1
0
 public void AddTicket(TicketEntity ticket)
 {
     persistence.Add(ticket);
 }
Ejemplo n.º 2
0
 public void ModifyTicket(TicketEntity ticket)
 {
     persistence.Modify(ticket);
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 投注购票
        /// </summary>
        public void BuyTicket(TicketMappingInfo ticket, UserInfo user)
        {
            try
            {
                using (ILHDBTran tran = BeginTran())
                {
                    UserManager userManager = new UserManager(tran);
                    TicketManager ticketManager = new TicketManager(tran);

                    UserBalanceEntity balance = userManager.GetBalance(user.UserId);
                    if (balance == null)
                    {
                        throw new FacadeException("帐户不存在,请先充值!");
                    }
                    decimal balanceMoney = balance.Balance.HasValue ? balance.Balance.Value : 0;
                    decimal freezeMoney = balance.Freeze.HasValue ? balance.Freeze.Value : 0;
                    decimal enableMoney = balanceMoney - freezeMoney;
                    if (enableMoney < ticket.Money)
                    {
                        throw new FacadeException("帐户余额不足,请先充值!");
                    }

                    TicketDetailEntity detail = new TicketDetailEntity();
                    detail.UserId = user.UserId;
                    detail.TicketId = ticket.TicketId;
                    detail.BalanceBefore = balanceMoney;
                    detail.FreezeBefore = freezeMoney;
                    detail.PayMoney = ticket.Money;
                    detail.BalanceAfter = balanceMoney;
                    detail.FreezeAfter = freezeMoney + ticket.Money;
                    detail.Status = (int)TicketStatus.Requesting;
                    detail.Message = "投注 - 冻结金额" + ticket.Money;
                    detail.CurrentTime = DateTime.Now;
                    // 添加彩票购买明细日志记录 - 状态为请求中
                    ticketManager.AddTicketDetail(detail);
                    // 更新用户余额 - 冻结金额
                    balance.Freeze += ticket.Money;
                    userManager.ModifyBalance(balance);

                    TicketEntity entity = new TicketEntity();
                    entity.TicketId = ticket.TicketId;
                    entity.BuyType = (int)ticket.BuyType;
                    entity.Amount = ticket.Amount;
                    entity.Money = ticket.Money;
                    entity.UserId = user.UserId;
                    entity.GameName = ticket.IssueInfo.GameName;
                    entity.IssuseNumber = ticket.IssueInfo.Number;
                    entity.Status = (int)TicketStatus.Requesting;
                    entity.RequestTime = DateTime.Now;
                    ticketManager.AddTicket(entity);
                    foreach (string code in ticket.AnteCodes)
                    {
                        TicketAnteCodeEntity anteCode = new TicketAnteCodeEntity();
                        anteCode.TicketId = ticket.TicketId;
                        anteCode.AnteCode = code;
                        ticketManager.AddAnteCode(anteCode);
                    }
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                throw HandleException(LogCategory.Ticket, "投注购票失败!", ex, ticket, user);
            }
        }