public HPResponseInfo DoBuy(UserInfo user, string gameName, string issueNumber
                                    , BuyType buyType, List <string> anteCodes, decimal money, int multiple)
        {
            try
            {
                HPBuyRequestInfo requestInfo  = new HPBuyRequestInfo();
                string           messengerId  = GetAgenceAccountUserName();
                string           userPassword = GetAgenceAccountPassword();
                string           messageId    = messengerId + DateTime.Now.ToString("yyyyMMdd") + PostManager.EightSerialNumber;
                string           timestamp    = DateTime.Now.ToString("yyyyMMddHHmmss");

                IssueMappingInfo issueInfo = new IssueMappingInfo();
                issueInfo.GameName = gameName;
                issueInfo.Number   = issueNumber;

                TicketMappingInfo ticket = new TicketMappingInfo();
                ticket.TicketId    = messengerId + DateTime.Now.ToString("yyyyMMdd") + PostManager.EightSerialNumber;
                ticket.BuyType     = buyType;
                ticket.Money       = money;
                ticket.Amount      = multiple;
                ticket.AnteCodes   = anteCodes;
                ticket.IssueInfo   = issueInfo;
                ticket.UserProfile = GetAgencyUserProfileInfo();

                HPBuyRequestInfo.Body requestBody = new HPBuyRequestInfo.Body();
                requestBody._Request            = new HPBuyRequestInfo.Body.Request();
                requestBody._Request.TicketList = new XmlMappingList <TicketMappingInfo>();
                requestBody._Request.TicketList.Add(ticket);

                string bodyXml = requestBody.ToXmlString("body");

                CommunicationObject.RequestHeaderObject requestHeader = new CommunicationObject.RequestHeaderObject();
                requestHeader.MessengerId     = GetAgenceAccountUserName();
                requestHeader.Timestamp       = timestamp;
                requestHeader.TransactionType = TranType.Request103;
                requestHeader.Digest          = PostManager.MD5(messageId + timestamp + userPassword + bodyXml, "gb2312");

                string headerXml   = requestHeader.ToXmlString("header");
                string requestXml  = "<?xml version=\"1.0\" encoding=\"GBK\"?><message version=\"1.0\" id=\"" + messageId + "\">" + headerXml + bodyXml + "</message>";
                string requestText = "transType=" + (int)TranType.Request103 + "&transMessage=" + requestXml;

                BuyTicket(ticket, user);
                string         xml  = PostManager.Post(GateWayManager.HPIssueQuery_GateWay, requestText, 1200);
                HPResponseInfo info = XmlAnalyzer.AnalyseResponse <HPResponseInfo>(xml);
                UpdateTicketStatus(ticket, user, info);

                return(info);
            }
            catch (Exception ex)
            {
                throw HandleException(LogCategory.Ticket, "认购失败!", ex);
            }
        }
        /// <summary>
        /// 更新投注响应状态
        /// </summary>
        public void UpdateTicketStatus(TicketMappingInfo ticket, UserInfo user, HPResponseInfo response)
        {
            try
            {
                using (ILHDBTran tran = BeginTran())
                {
                    UserManager   userManager   = new UserManager(tran);
                    TicketManager ticketManager = new TicketManager(tran);

                    TicketDetailEntity tmp = ticketManager.GetFreezeTicketDetail(ticket.TicketId, user.UserId);
                    if (tmp == null || tmp.Status != (int)TicketStatus.Requesting)
                    {
                        throw new FacadeException("帐户数据错误,请联系系统管理员!");
                    }
                    UserBalanceEntity balance = userManager.GetBalance(user.UserId);
                    if (balance == null)
                    {
                        throw new FacadeException("帐户不存在,请先充值!");
                    }
                    TicketEntity entity = ticketManager.GetTicket(ticket.TicketId);
                    if (entity == null)
                    {
                        throw new FacadeException("出票数据错误,请联系管理员!");
                    }
                    if (response.Code == "0000")
                    {
                        entity.Status = (int)TicketStatus.Determinate;

                        TicketDetailEntity detail = new TicketDetailEntity();
                        detail.UserId        = user.UserId;
                        detail.TicketId      = ticket.TicketId;
                        detail.BalanceBefore = tmp.BalanceAfter;
                        detail.FreezeBefore  = tmp.FreezeAfter;
                        detail.PayMoney      = tmp.PayMoney;
                        detail.BalanceAfter  = tmp.BalanceAfter - tmp.PayMoney;
                        detail.FreezeAfter   = tmp.FreezeAfter - tmp.PayMoney;
                        detail.Status        = (int)TicketStatus.Determinate;
                        detail.Message       = "落地 - 更新金额并解冻" + tmp.PayMoney;
                        detail.CurrentTime   = DateTime.Now;
                        // 添加彩票购买明细日志记录 - 状态为落地
                        ticketManager.AddTicketDetail(detail);

                        balance.Balance -= tmp.PayMoney;
                        balance.Freeze  -= tmp.PayMoney;
                        userManager.ModifyBalance(balance);
                    }
                    else
                    {
                        entity.Status = (int)TicketStatus.Error;

                        TicketDetailEntity detail = new TicketDetailEntity();
                        detail.UserId        = user.UserId;
                        detail.TicketId      = ticket.TicketId;
                        detail.BalanceBefore = tmp.BalanceAfter;
                        detail.FreezeBefore  = tmp.FreezeAfter;
                        detail.PayMoney      = tmp.PayMoney;
                        detail.BalanceAfter  = tmp.BalanceAfter;
                        detail.FreezeAfter   = tmp.FreezeAfter - tmp.PayMoney;
                        detail.Status        = (int)TicketStatus.Error;
                        detail.Message       = "错误 - " + response.Message + " - 恢复冻结金额" + ticket.Money;
                        detail.CurrentTime   = DateTime.Now;
                        // 添加彩票购买明细日志记录 - 状态为错误
                        ticketManager.AddTicketDetail(detail);

                        balance.Freeze -= tmp.PayMoney;
                        userManager.ModifyBalance(balance);
                    }
                    entity.ResponseCode    = response.Code;
                    entity.ResponseMessage = response.Message;
                    entity.ResponseTime    = DateTime.Now;

                    ticketManager.ModifyTicket(entity);
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                throw HandleException(LogCategory.Ticket, "更新投注状态失败! - " + ex.Message, ex, ticket, response);
            }
        }
        /// <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);
            }
        }
        /// <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);
            }
        }
        /// <summary>
        /// 更新投注响应状态
        /// </summary>
        public void UpdateTicketStatus(TicketMappingInfo ticket, UserInfo user, HPResponseInfo response)
        {
            try
            {
                using (ILHDBTran tran = BeginTran())
                {
                    UserManager userManager = new UserManager(tran);
                    TicketManager ticketManager = new TicketManager(tran);

                    TicketDetailEntity tmp = ticketManager.GetFreezeTicketDetail(ticket.TicketId, user.UserId);
                    if (tmp == null || tmp.Status != (int)TicketStatus.Requesting)
                    {
                        throw new FacadeException("帐户数据错误,请联系系统管理员!");
                    }
                    UserBalanceEntity balance = userManager.GetBalance(user.UserId);
                    if (balance == null)
                    {
                        throw new FacadeException("帐户不存在,请先充值!");
                    }
                    TicketEntity entity = ticketManager.GetTicket(ticket.TicketId);
                    if (entity == null)
                    {
                        throw new FacadeException("出票数据错误,请联系管理员!");
                    }
                    if (response.Code == "0000")
                    {
                        entity.Status = (int)TicketStatus.Determinate;

                        TicketDetailEntity detail = new TicketDetailEntity();
                        detail.UserId = user.UserId;
                        detail.TicketId = ticket.TicketId;
                        detail.BalanceBefore = tmp.BalanceAfter;
                        detail.FreezeBefore = tmp.FreezeAfter;
                        detail.PayMoney = tmp.PayMoney;
                        detail.BalanceAfter = tmp.BalanceAfter - tmp.PayMoney;
                        detail.FreezeAfter = tmp.FreezeAfter - tmp.PayMoney;
                        detail.Status = (int)TicketStatus.Determinate;
                        detail.Message = "落地 - 更新金额并解冻" + tmp.PayMoney;
                        detail.CurrentTime = DateTime.Now;
                        // 添加彩票购买明细日志记录 - 状态为落地
                        ticketManager.AddTicketDetail(detail);

                        balance.Balance -= tmp.PayMoney;
                        balance.Freeze -= tmp.PayMoney;
                        userManager.ModifyBalance(balance);
                    }
                    else
                    {
                        entity.Status = (int)TicketStatus.Error;

                        TicketDetailEntity detail = new TicketDetailEntity();
                        detail.UserId = user.UserId;
                        detail.TicketId = ticket.TicketId;
                        detail.BalanceBefore = tmp.BalanceAfter;
                        detail.FreezeBefore = tmp.FreezeAfter;
                        detail.PayMoney = tmp.PayMoney;
                        detail.BalanceAfter = tmp.BalanceAfter;
                        detail.FreezeAfter = tmp.FreezeAfter - tmp.PayMoney;
                        detail.Status = (int)TicketStatus.Error;
                        detail.Message = "错误 - " + response.Message + " - 恢复冻结金额" + ticket.Money;
                        detail.CurrentTime = DateTime.Now;
                        // 添加彩票购买明细日志记录 - 状态为错误
                        ticketManager.AddTicketDetail(detail);

                        balance.Freeze -= tmp.PayMoney;
                        userManager.ModifyBalance(balance);
                    }
                    entity.ResponseCode = response.Code;
                    entity.ResponseMessage = response.Message;
                    entity.ResponseTime = DateTime.Now;

                    ticketManager.ModifyTicket(entity);
                    tran.Commit();
                }
            }
            catch (Exception ex)
            {
                throw HandleException(LogCategory.Ticket, "更新投注状态失败! - " + ex.Message, ex, ticket, response);
            }
        }
        public HPResponseInfo DoBuy(UserInfo user, string gameName, string issueNumber
            , BuyType buyType, List<string> anteCodes, decimal money, int multiple)
        {
            try
            {
                HPBuyRequestInfo requestInfo = new HPBuyRequestInfo();
                string messengerId = GetAgenceAccountUserName();
                string userPassword = GetAgenceAccountPassword();
                string messageId = messengerId + DateTime.Now.ToString("yyyyMMdd") + PostManager.EightSerialNumber;
                string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");

                IssueMappingInfo issueInfo = new IssueMappingInfo();
                issueInfo.GameName = gameName;
                issueInfo.Number = issueNumber;

                TicketMappingInfo ticket = new TicketMappingInfo();
                ticket.TicketId = messengerId + DateTime.Now.ToString("yyyyMMdd") + PostManager.EightSerialNumber;
                ticket.BuyType = buyType;
                ticket.Money = money;
                ticket.Amount = multiple;
                ticket.AnteCodes = anteCodes;
                ticket.IssueInfo = issueInfo;
                ticket.UserProfile = GetAgencyUserProfileInfo();

                HPBuyRequestInfo.Body requestBody = new HPBuyRequestInfo.Body();
                requestBody._Request = new HPBuyRequestInfo.Body.Request();
                requestBody._Request.TicketList = new XmlMappingList<TicketMappingInfo>();
                requestBody._Request.TicketList.Add(ticket);

                string bodyXml = requestBody.ToXmlString("body");

                CommunicationObject.RequestHeaderObject requestHeader = new CommunicationObject.RequestHeaderObject();
                requestHeader.MessengerId = GetAgenceAccountUserName();
                requestHeader.Timestamp = timestamp;
                requestHeader.TransactionType = TranType.Request103;
                requestHeader.Digest = PostManager.MD5(messageId + timestamp + userPassword + bodyXml, "gb2312");

                string headerXml = requestHeader.ToXmlString("header");
                string requestXml = "<?xml version=\"1.0\" encoding=\"GBK\"?><message version=\"1.0\" id=\"" + messageId + "\">" + headerXml + bodyXml + "</message>";
                string requestText = "transType=" + (int)TranType.Request103 + "&transMessage=" + requestXml;

                BuyTicket(ticket, user);
                string xml = PostManager.Post(GateWayManager.HPIssueQuery_GateWay, requestText, 1200);
                HPResponseInfo info = XmlAnalyzer.AnalyseResponse<HPResponseInfo>(xml);
                UpdateTicketStatus(ticket, user, info);

                return info;
            }
            catch (Exception ex)
            {
                throw HandleException(LogCategory.Ticket, "认购失败!", ex);
            }
        }
Example #7
0
    private void DoBuy()
    {
        string issueIdString = HidIsuseID.Value;
        string isuseNumber = HidIsuseNumber.Value;
        string endTime = HidIsuseEndTime.Value;
        string playTypeString = Shove._Web.Utility.GetRequest("playType");
        string lotteryNumber = Shove._Web.Utility.FilteSqlInfusion(base.Request["tb_LotteryNumber"]);
        string sumMoneyString = Shove._Web.Utility.GetRequest("tb_hide_SumMoney");
        string sumNumberString = Shove._Web.Utility.GetRequest("tb_hide_SumNum");
        string lotteryIdString = Shove._Web.Utility.GetRequest("HidLotteryID");
        string multipleString = Shove._Web.Utility.GetRequest("tb_Multiple");
        if (multipleString == "")
        {
            multipleString = "1";
        }
        StringBuilder sb = new StringBuilder();
        try
        {
            HPBuyRequestInfo requestInfo = new HPBuyRequestInfo();

            decimal money = decimal.Parse(sumMoneyString);
            int multiple = int.Parse(multipleString);
            int sumNumber = int.Parse(sumNumberString);
            int playType = int.Parse(playTypeString);
            int lotteryId = int.Parse(lotteryIdString);
            long isuseId = long.Parse(issueIdString);

            string messengerId = GetAgenceAccountUserName();
            string userPassword = GetAgenceAccountPassword();
            string messageId = messengerId + DateTime.Now.ToString("yyyyMMdd") + PostManager.EightSerialNumber;
            string timestamp = DateTime.Now.ToString("yyyyMMddHHmmss");

            IssueMappingInfo issueInfo = new IssueMappingInfo();
            issueInfo.GameName = LotteryCode;
            issueInfo.Number = isuseNumber;

            List<string> anteCodes = new List<string>();
            lotteryNumber = lotteryNumber.Replace(" + ", "#").Replace(' ', ',');
            anteCodes.AddRange(lotteryNumber.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries));

            TicketMappingInfo ticket = new TicketMappingInfo();
            ticket.TicketId = messengerId + DateTime.Now.ToString("yyyyMMdd") + PostManager.EightSerialNumber;
            ticket.BuyType = BuyType.A101;   // TODO
            ticket.Money = money;
            ticket.Amount = multiple;
            ticket.AnteCodes = anteCodes;
            ticket.IssueInfo = issueInfo;
            //ticket.UserProfile = GetAgencyUserProfileInfo();

            HPBuyRequestInfo.Body requestBody = new HPBuyRequestInfo.Body();
            requestBody._Request = new HPBuyRequestInfo.Body.Request();
            requestBody._Request.TicketList = new XmlMappingList<TicketMappingInfo>();
            requestBody._Request.TicketList.Add(ticket);

            string bodyXml = requestBody.ToXmlString("body");

            CommunicationObject.RequestHeaderObject requestHeader = new CommunicationObject.RequestHeaderObject();
            requestHeader.MessengerId = GetAgenceAccountUserName();
            requestHeader.Timestamp = timestamp;
            requestHeader.TransactionType = TranType.Request103;
            requestHeader.Digest = PostManager.MD5(messageId + timestamp + userPassword + bodyXml, "gb2312");

            string headerXml = requestHeader.ToXmlString("header");

            string requestXml = "<?xml version=\"1.0\" encoding=\"GBK\"?><message version=\"1.0\" id=\"" + messageId + "\">" + headerXml + bodyXml + "</message>";

            string result = @"投注结果\n\n";
            try
            {
                string requestText = "transType=" + (int)TranType.Request103 + "&transMessage=" + requestXml;
                string xml = PostManager.Post(GateWayManager.HPIssueQuery_GateWay, requestText, 1200);
                //string xml = gateway.LotteryRequest(accountN, transType, tickets);
                HPResponseInfo info = XmlAnalyzer.AnalyseResponse<HPResponseInfo>(xml);
                result += info.Code + " - " + info.Message;
            }
            catch (Exception ex)
            {
                result += "错误 - " + ex.Message;
                LogWriter.Write(LogCategory.Lottery, "投注错误", ex);
            }
            JavaScript.Alert(this.Page, result);
            return;
        }
        catch
        {
            JavaScript.Alert(this.Page, "输入有错误,请仔细检查。");
            return;
        }
    }