public LotteryTicketModel SellLottery(LotteryBuyer lotteryBuyer, LotteryType lotteryType) { var issue = GetlatestIssue(); if (issue == null) { throw new Exception("没有找到本期数据。"); } if (issue.Stat != (int)IssueStat.Establish) { throw new Exception("本期已经结束。"); } var buyerIssue = _buyerIssueRepository.Table.Where(bi => bi.BuyerId == lotteryBuyer.Id && bi.IssueId == issue.Id).FirstOrDefault(); if (buyerIssue == null) { buyerIssue = new BuyerIssue() { BuyerId = lotteryBuyer.Id, IssueId = issue.Id, PurchaseQuantity = 0 }; _buyerIssueRepository.Insert(buyerIssue); } buyerIssue.PurchaseQuantity = buyerIssue.PurchaseQuantity + 1; LotteryTicketModel model = SendLotteryTicket(buyerIssue, issue, (int)lotteryType); return(model); }
private LotteryTicketModel SendLotteryTicket(BuyerIssue buyerIssue, LotteryIssue lotteryIssue, int sellType) { if (lotteryIssue.Stat != (int)IssueStat.Establish) { throw new Exception("当期已经结束,不再接受订单。"); } Random rd0 = new Random(); int a0 = rd0.Next(100) % 52; int b0 = rd0.Next(100) % 52; int c0 = rd0.Next(100) % 52; int d0 = rd0.Next(100) % 52; if (lotteryIssue.PoolCmd == 0) { var lp0 = GetTicketInLotteryPool0(a0, b0, c0, d0, buyerIssue.BuyerId, sellType); LotteryTicketModel model = new LotteryTicketModel() { A = lp0.A, B = lp0.B, C = lp0.C, D = lp0.D, BuyerId = lp0.BuyerId, PoolCmd = 0, Stat = lp0.Stat, Type = lp0.Type, OrderOn = DateTime.Now }; return(model); } else if (lotteryIssue.PoolCmd == 1) { var lp1 = GetTicketInLotteryPool1(a0, b0, c0, d0, buyerIssue.BuyerId, sellType); LotteryTicketModel model = new LotteryTicketModel() { A = lp1.A, B = lp1.B, C = lp1.C, D = lp1.D, BuyerId = lp1.BuyerId, PoolCmd = 1, Stat = lp1.Stat, Type = lp1.Type, OrderOn = DateTime.Now }; return(model); } throw new Exception("数据命令不匹配500244,不接受订单。"); }