예제 #1
0
        /// <summary>
        /// 活的用户已经持有的当前期彩票
        /// </summary>
        /// <param name="lotteryBuyer"></param>
        /// <returns></returns>
        public IList <LotteryTicketModel> GetCurrentLotteysByBuyer(LotteryBuyer lotteryBuyer)
        {
            var issue = _issueRepository.Table.OrderByDescending(i => i.CreatedOn).FirstOrDefault();

            if (issue.Stat == (int)IssueStat.Accomplish)
            {
                throw new Exception("当前期没有生成。");
            }
            List <LotteryTicketModel> models = new List <LotteryTicketModel>();

            if (issue.PoolCmd == 0)
            {
                var lp0s = _pool0Repository.Table.Where(pl0 => pl0.BuyerId == lotteryBuyer.Id).ToList();
                foreach (var lp0 in lp0s)
                {
                    LotteryTicketModel model = new LotteryTicketModel()
                    {
                        A       = lp0.A,
                        B       = lp0.B,
                        C       = lp0.C,
                        D       = lp0.D,
                        BuyerId = lp0.BuyerId,
                        Id      = lp0.Id,
                        IssueId = issue.Id,
                        OrderOn = lp0.OrderTime,
                        PoolCmd = issue.PoolCmd,
                        Stat    = lp0.Stat,
                        Type    = lp0.Type
                    };
                    models.Add(model);
                }
            }
            else if (issue.PoolCmd == 1)
            {
                var lp1s = _pool1Repository.Table.Where(pl1 => pl1.BuyerId == lotteryBuyer.Id).ToList();
                foreach (var lp1 in lp1s)
                {
                    LotteryTicketModel model = new LotteryTicketModel()
                    {
                        A       = lp1.A,
                        B       = lp1.B,
                        C       = lp1.C,
                        D       = lp1.D,
                        BuyerId = lp1.BuyerId,
                        Id      = lp1.Id,
                        IssueId = issue.Id,
                        OrderOn = lp1.OrderTime,
                        PoolCmd = issue.PoolCmd,
                        Stat    = lp1.Stat,
                        Type    = lp1.Type
                    };
                    models.Add(model);
                }
            }
            else
            {
                throw new Exception("奖池命令错误!");
            }
            return(models);
        }
예제 #2
0
        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);
        }
예제 #3
0
        /// <summary>
        /// 增加用户
        /// </summary>
        /// <param name="BuyerChId"></param>
        /// <param name="BuyerChName"></param>
        /// <param name="Weixin"></param>
        /// <param name="ChannelId"></param>
        /// <returns></returns>
        public LotteryBuyer AddBuyer(string BuyerChId, string BuyerChName, string Weixin, int ChannelId)
        {
            var now      = DateTime.Now;
            var newBuyer = new LotteryBuyer()
            {
                ChannelId    = ChannelId,
                BuyerChName  = BuyerChName,
                Weixin       = Weixin,
                ChannelSysId = BuyerChId,
                CreatedOn    = now
            };

            _buyerRepository.Insert(newBuyer);
            return(newBuyer);
        }