Exemplo n.º 1
0
        private async Task <bool> WinnerUpdateAsync(AppDbContext ltctx, mWinner winner)
        {
            var _result = false;

            try
            {
                ltctx.Database.BeginTransaction();

                var _record = ltctx.tb_lion_winner
                              .Where(w => w.SequenceNo == winner.SequenceNo)
                              .SingleOrDefault();

                if (_record != null)
                {
                    ltctx.Entry(_record).CurrentValues.SetValues(winner);
                }
                else
                {
                    ltctx.tb_lion_winner.Add(winner);
                }

                await ltctx.SaveChangesAsync();

                ltctx.Database.CommitTransaction();
                _result = true;
            }
            catch (Exception ex)
            {
                ltctx.Database.RollbackTransaction();

                _logger.LogError(ex, "receiver.winner");
            }

            return(_result);
        }
Exemplo n.º 2
0
        public async Task <mWinner> ReadWinnerBall(int sequnce_no)
        {
            var _result = (mWinner)null;

            var _html_document = await GetHtmlDocument(sequnce_no);

            {
                var _winner_ball = GetWinnerBall(_html_document, sequnce_no);
                var _winner_info = GetWinnerInfo(_html_document, sequnce_no);

                var _issue_day = GetIssueDateBySequenceNo(sequnce_no);

                _result = new mWinner()
                {
                    SequenceNo = sequnce_no,

                    IssueDate   = _issue_day,
                    PaymentDate = _issue_day.AddYears(1),

                    Digit1 = Convert.ToInt16(_winner_ball[0]),
                    Digit2 = Convert.ToInt16(_winner_ball[1]),
                    Digit3 = Convert.ToInt16(_winner_ball[2]),
                    Digit4 = Convert.ToInt16(_winner_ball[3]),
                    Digit5 = Convert.ToInt16(_winner_ball[4]),
                    Digit6 = Convert.ToInt16(_winner_ball[5]),
                    Digit7 = Convert.ToInt16(_winner_ball[6]),

                    AutoSelect = Convert.ToInt16(_winner_info[0]),

                    Count1 = Convert.ToInt32(_winner_info[6]),
                    Count2 = Convert.ToInt32(_winner_info[13]),
                    Count3 = Convert.ToInt32(_winner_info[20]),
                    Count4 = Convert.ToInt32(_winner_info[27]),
                    Count5 = Convert.ToInt32(_winner_info[34]),

                    Amount1 = Convert.ToDecimal(_winner_info[7]),
                    Amount2 = Convert.ToDecimal(_winner_info[14]),
                    Amount3 = Convert.ToDecimal(_winner_info[21]),
                    Amount4 = Convert.ToDecimal(_winner_info[28]),
                    Amount5 = Convert.ToDecimal(_winner_info[35]),

                    Remark = ""
                };
            }

            return(_result);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetPrizeBySeqNo(int sequence_no)
        {
            return(await CProxy.UsingAsync(() =>
            {
                var _result = (success : false, message : "ok");

                var _winner = (mWinner)null;
                if (sequence_no >= 1 && sequence_no <= __winner_reader.GetThisWeekSequenceNo())
                {
                    _winner = __db_context.tb_lion_winner
                              .Where(w => w.SequenceNo == sequence_no)
                              .SingleOrDefault();

                    if (_winner == null)
                    {
                        _result.message = $"해당 회차'{sequence_no}'의 추첨 정보가 없습니다";

                        _winner = new mWinner()
                        {
                            SequenceNo = sequence_no,
                            IssueDate = __winner_reader.GetIssueDateBySequenceNo(sequence_no),
                            PaymentDate = __winner_reader.GetPaymentDateBySequenceNo(sequence_no)
                        };
                    }
                    else
                    {
                        _result.success = true;
                    }
                }
                else
                {
                    _result.message = "추첨 회차가 범위를 벗어 났습니다";
                }

                return Ok(new
                {
                    _result.success,
                    _result.message,

                    result = _winner
                });
            }));
        }
Exemplo n.º 4
0
        public int SelectScoring(AppDbContext ltctx, mWinner winner, mFactor factor, List <short> winner_digits)
        {
            var _no_jackpot = 0;

            // clear
            {
                factor.NoJackpot1     = 0;
                factor.WinningAmount1 = 0;

                factor.NoJackpot2     = 0;
                factor.WinningAmount2 = 0;

                factor.NoJackpot3     = 0;
                factor.WinningAmount3 = 0;

                factor.NoJackpot4     = 0;
                factor.WinningAmount4 = 0;

                factor.NoJackpot5     = 0;
                factor.WinningAmount5 = 0;
            }

            var _selects = ltctx.tb_lion_select
                           .Where(x => x.SequenceNo == winner.SequenceNo && x.Ranking == 0)
                           .ToList();

            foreach (var _s in _selects)
            {
                var _select_digits = new List <short>();
                {
                    _select_digits.Add(_s.Digit1);
                    _select_digits.Add(_s.Digit2);
                    _select_digits.Add(_s.Digit3);
                    _select_digits.Add(_s.Digit4);
                    _select_digits.Add(_s.Digit5);
                    _select_digits.Add(_s.Digit6);
                }

                var _match_count = 0;
                foreach (var _x in _select_digits)
                {
                    if (winner_digits.Exists(x => x == _x) == true)
                    {
                        _match_count++;
                    }
                }

                _no_jackpot++;

                if (_match_count >= 6)
                {
                    _s.Ranking = 1;
                    _s.Amount  = winner.Amount1;

                    factor.NoJackpot1++;
                    factor.WinningAmount1 += winner.Amount1;
                }
                else if (_match_count >= 5)
                {
                    if (_select_digits.Exists(x => x == winner.Digit7) == true)
                    {
                        _s.Ranking = 2;
                        _s.Amount  = winner.Amount2;

                        factor.NoJackpot2++;
                        factor.WinningAmount2 += winner.Amount2;
                    }
                    else
                    {
                        _s.Ranking = 3;
                        _s.Amount  = winner.Amount3;

                        factor.NoJackpot3++;
                        factor.WinningAmount3 += winner.Amount3;
                    }
                }
                else if (_match_count >= 4)
                {
                    _s.Ranking = 4;
                    _s.Amount  = winner.Amount4;

                    factor.NoJackpot4++;
                    factor.WinningAmount4 += winner.Amount4;
                }
                else if (_match_count >= 3)
                {
                    _s.Ranking = 5;
                    _s.Amount  = winner.Amount5;

                    factor.NoJackpot5++;
                    factor.WinningAmount5 += winner.Amount5;
                }
                else
                {
                    _no_jackpot--;

                    // 낙첨(6위) select(추출) 번호는 삭제 함
                    ltctx.tb_lion_select.Remove(_s);
                }
            }

            return(_no_jackpot);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ltctx"></param>
        /// <param name="winner"></param>
        /// <param name="winner_digits"></param>
        /// <param name="login_id">로그인 사용자 아이디</param>
        public int ChoiceScoring(AppDbContext ltctx, mWinner winner, mJackpot jackpot, List <short> winner_digits, string login_id)
        {
            var _no_jackpot = 0;

            // clear
            {
                jackpot.NoJackpot     = 0;
                jackpot.WinningAmount = 0;
            }

            var _choices = ltctx.tb_lion_choice
                           .Where(x => x.SequenceNo == winner.SequenceNo && x.LoginId == login_id && x.Ranking == 0)
                           .ToList();

            foreach (var _c in _choices)
            {
                var _choice_digits = new List <short>();
                {
                    _choice_digits.Add(_c.Digit1);
                    _choice_digits.Add(_c.Digit2);
                    _choice_digits.Add(_c.Digit3);
                    _choice_digits.Add(_c.Digit4);
                    _choice_digits.Add(_c.Digit5);
                    _choice_digits.Add(_c.Digit6);
                }

                var _match_count = 0;
                foreach (var _x in _choice_digits)
                {
                    if (winner_digits.Exists(x => x == _x) == true)
                    {
                        _match_count++;
                    }
                }

                _no_jackpot++;

                if (_match_count >= 6)
                {
                    _c.Ranking = 1;
                    _c.Amount  = winner.Amount1;

                    jackpot.NoJackpot++;
                    jackpot.WinningAmount += _c.Amount;
                }
                else if (_match_count >= 5)
                {
                    if (_choice_digits.Exists(x => x == winner.Digit7) == true)
                    {
                        _c.Ranking = 2;
                        _c.Amount  = winner.Amount2;
                    }
                    else
                    {
                        _c.Ranking = 3;
                        _c.Amount  = winner.Amount3;
                    }

                    jackpot.NoJackpot++;
                    jackpot.WinningAmount += _c.Amount;
                }
                else if (_match_count >= 4)
                {
                    _c.Ranking = 4;
                    _c.Amount  = winner.Amount4;

                    jackpot.NoJackpot++;
                    jackpot.WinningAmount += _c.Amount;
                }
                else if (_match_count >= 3)
                {
                    _c.Ranking = 5;
                    _c.Amount  = winner.Amount5;

                    jackpot.NoJackpot++;
                    jackpot.WinningAmount += _c.Amount;
                }
                else
                {
                    _no_jackpot--;

                    _c.Ranking = 6;
                    _c.Amount  = 0;

                    // 낙첨(6위) select(추출) 번호는 삭제 함
                    //ltctx.tb_lion_choice.Remove(_c);
                }
            }

            return(_no_jackpot);
        }
Exemplo n.º 6
0
        private async Task <int> NextGameSenderAsync(AppDbContext ltctx, mWinner winner, mMember member, dChoice choice)
        {
            var _result = 0;

            try
            {
                ltctx.Database.BeginTransaction();

                if (member.MailError == false)
                {
                    var _choices = ltctx.tb_lion_choice
                                   .Where(c => c.SequenceNo == choice.sequence_no && c.LoginId == choice.login_id &&
                                          (c.IsMailSent == false || choice.resend == true))
                                   .OrderBy(c => c.Digit1).ThenBy(c => c.Digit2).ThenBy(c => c.Digit3)
                                   .ThenBy(c => c.Digit4).ThenBy(c => c.Digit5).ThenBy(c => c.Digit6)
                                   .ToArray();

                    choice.no_choice = _choices.Length;

                    // 해당 회차에 처리하고자 하는 회원에게 메일 발송이 안된 entity만을 처리 합니다.
                    if (choice.no_choice > 0)
                    {
                        var _verify = await _mailSender.TestMailServerConnectionAsync(member);

                        if (_verify.error_code == SmtpError.GENERIC_SUCCESS)
                        {
                            var _curr_factor = _winnerSelector.GetFactor(ltctx, choice.sequence_no - 0);
                            var _last_factor = _winnerSelector.GetFactor(ltctx, choice.sequence_no - 1);

                            // 선택 번호들을 이미지 처리 함, 최종 zip(압축) 파일로 생성 합니다.
                            var _zip_file = _printOut.SaveLottoSheet(_choices, choice);

                            var _last_jackpot = _winnerScoring.GetJackpot(ltctx, member, choice.sequence_no - 1, member.MaxSelectNumber);

                            // zip 파일을 첨부 하여 메일 발송 합니다.
                            await _mailSender.SendLottoZipFile(_zip_file, choice, winner, member, _curr_factor, _last_factor, _last_jackpot);

                            // 메일 발송 했음을 표기 함
                            _choices
                            .ToList()
                            .ForEach(c => c.IsMailSent = true);

                            _result = choice.no_choice;
                        }
                        else
                        {
                            WriteMember(choice.sequence_no, choice.login_id, $"mail error '{member.EmailAddress}', {_verify.error_code}, {_verify.error_message}");
                        }

                        await ltctx.SaveChangesAsync();
                    }
                }

                ltctx.Database.CommitTransaction();
            }
            catch (Exception ex)
            {
                ltctx.Database.RollbackTransaction();

                _logger.LogError(ex, "receiver.choicer");
            }

            return(_result);
        }
Exemplo n.º 7
0
        public async Task SendLottoZipFile(string zip_file_path, dChoice choice, mWinner winner, mMember member, mFactor curr_factor, mFactor last_factor, mJackpot last_jackpot)
        {
            var _message = new MimeMessage();
            {
                _message.From.Add(new MailboxAddress(MailSenderName, MailSenderAddress));
                _message.To.Add(new MailboxAddress(member.LoginName, member.EmailAddress));

                _message.Subject = $"[로또번호] {member.LoginName} 님을 위한 [{choice.sequence_no}]회차 로또645 예측 번호 제공 {(member.IsDirectSend ? "D" : "I")}";
            }

            var _curr_no_combination = curr_factor.LNoCombination + curr_factor.RNoCombination;
            var _curr_no_extraction  = curr_factor.LNoExtraction + curr_factor.RNoExtraction;
            var _last_no_extraction  = last_factor.LNoExtraction + last_factor.RNoExtraction;

            var _builder = new BodyBuilder();

            {
                _builder.HtmlBody = $"<div>"
                                    + $"<h4>안녕하세요 '{member.LoginName}'님, '로또645 예측 번호 제공 서비스' 입니다.</h4>"
                                    + $"<p></p>"
                                    + $"<h4>A. [{last_jackpot.SequenceNo}]회 추첨 결과</h4>"
                                    + $"<p>당첨번호: <strong>{winner.Digit1}, {winner.Digit2}, {winner.Digit3}, {winner.Digit4}, {winner.Digit5}, {winner.Digit6} ({winner.Digit7})</strong></p>"
                                    + $"<p>예측결과: {_last_no_extraction:#,##0} 게임</p>"
                                    + $"<ul>"
                                    + $"<li>1등: {last_factor.NoJackpot1,10:#,##0} 게임, {last_factor.WinningAmount1,15:#,##0} 원</li>"
                                    + $"<li>2등: {last_factor.NoJackpot2,10:#,##0} 게임, {last_factor.WinningAmount2,15:#,##0} 원</li>"
                                    + $"<li>3등: {last_factor.NoJackpot3,10:#,##0} 게임, {last_factor.WinningAmount3,15:#,##0} 원</li>"
                                    + $"<li>4등: {last_factor.NoJackpot4,10:#,##0} 게임, {last_factor.WinningAmount4,15:#,##0} 원</li>"
                                    + $"<li>5등: {last_factor.NoJackpot5,10:#,##0} 게임, {last_factor.WinningAmount5,15:#,##0} 원</li>"
                                    + $"</ul>"
                                    + $"<p>회원결과: {last_jackpot.NoChoice} 게임</p>"
                                    + $"<ul>"
                                    + $"<li>지난 주 발송 된 번호 중 {last_jackpot.NoJackpot} 게임, <strong>{last_jackpot.WinningAmount:#,##0}원</strong>이 당첨 되었습니다.</li>"
                                    + $"</ul>"
                                    + $"<h4>B. [{choice.sequence_no}]회 예측 번호</h4>"
                                    + $"<ul>"
                                    + $"<li>전체 45개의 번호 중 <strong>{_curr_no_combination:#,##0}개의 게임</strong>을 조합 했습니다.</li>"
                                    + $"<li>그 중 확률적으로 의미 있는 <strong>{_curr_no_extraction:#,##0}개의 게임</strong>이 추출 되었습니다.</li>"
                                    + $"<li>'{member.LoginName}'님에게 추출 된 {_curr_no_extraction:#,##0}개의 게임 중, 엄선해서 <strong>{choice.no_choice:#,##0}개의 게임</strong>을 보내 드립니다.</li>"
                                    + $"<li>특별히 원하시는 번호(3개 까지)를 아래 [운영자] 메일로 알려 주시면, 해당 번호가 포함 되어 있는 게임만 받을 수 있습니다.</li>"
                                    + $"<li> <a href='https://play.google.com/store/apps/details?id=kr.co.odinsoftware.LION'>로또사자(Android)</a>, "
                                    + $"<a href='https://itunes.apple.com/us/app/%EB%A1%9C%EB%98%90%EC%82%AC%EC%9E%90-lottolion/id1236106275?l=ko&ls=1&mt=8'>로또사자(iOS)</a> "
                                    + $"앱을 설치 하시면, 당첨내역과 이력 조회 및 게임 수 변경, 번호 지정이 가능 합니다.</li>"
                                    + $"</ul>"
                                    + $"<h4>C. 출력 방법</h4>"
                                    + $"<ul>"
                                    + $"<li>이미지 파일을 A4 프린터로 출력 후 로또 용지 크기와 동일하게 절단 합니다.</li>"
                                    + $"<li>A4 한장 당 최대 로또 용지 3장이 출력 됩니다.</li>"
                                    + $"<li>절취선에 맞춰 절단 후 로또 판매점에서 별도로 작성 하지 않고, 출력하신 용지로 바로 구매 가능 합니다.</li>"
                                    + $"<li>절취시 잘못 절단 하면 로또 판매점의 리더기에서 오류가 발생 할 수 있습니다.</li>"
                                    + $"<li>실제 로또 용지와 크기가 동일하게 절단하는 것이 중요 합니다.</li>"
                                    + $"<li>길이(19cm) 및 높이(8.2cm)는 같거나 조금 작아야 오류가 없습니다.</li>"
                                    + $"</ul>"
                                    + $"<h4>D. 회원 가입</h4>"
                                    + $"<ul>"
                                    + $"<li>매주 무료 예측 번호를 원하시는 주변 분이 있는 경우 '메일주소'와 '닉네임'을 아래 [운영자] 메일로 보내 주세요.</li>"
                                    + $"<li>메일 수신을 원하지 않는 경우에도 [운영자]에게 제목을 '수신거부'로 메일 보내 주시면 바로 중단 해 드립니다.</li>"
                                    + $"</ul>"
                                    + $"<h4>E. 연락처</h4>"
                                    + $"<ul>"
                                    + $"<li>회사명: {ServiceProvider}</li>"
                                    + $"<li>연락처: {ServiceProviderPhone}</li>"
                                    + $"<li>사이트: <a href='{ServiceProviderHomePage}'>{ServiceProviderHomePage}</a></li>"
                                    + $"<li>운영자: <a href='mailto:{ServiceProviderMailTo}'>{ServiceProviderMailTo}</a></li>"
                                    + $"</ul>"
                                    + "</div>"
                ;

                _builder.Attachments.Add(zip_file_path);
            }

            _message.Body = _builder.ToMessageBody();

            if (member.IsDirectSend == false)
            {
                using (var _client = new SmtpClient())
                {
                    _client.ServerCertificateValidationCallback = (s, c, h, e) => true;

                    _client.Connect(MailDeliveryServer, MailDeliveryPort, false);

                    // Note: since we don't have an OAuth2 token, disable
                    // the XOAUTH2 authentication mechanism.
                    _client.AuthenticationMechanisms.Remove("XOAUTH2");

                    // Note: only needed if the SMTP server requires authentication
                    _client.Authenticate(MailDeliveryUserName, MailDeliveryUserPassword);

                    _client.Send(_message);
                    _client.Disconnect(true);
                }
            }
            else
            {
                await __smtp_direct.SendMailAsync(_message);
            }
        }