| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using CommonObj.common;
- using CommonObj.lotoModel;
- using ResfullApi.Models.bet;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using System.Data;
- namespace ApiProcessToken.Models.common
- {
- public class FunctionThaiLan
- {
- public static string getGuiId()
- {
- string _key = Guid.NewGuid().ToString();
- return _key;
- }
- public static List<string> getListTicketFree(redisConnection _redis, int total, string randomId)
- {
- List<string> _result = new List<string>();
- try
- {
- List<string> _allTernFree = _redis.getAllkeyByPatternRegex(_redis.DB_INDEX_DATA_TICKET_UNIQUE_FREE, "*");
- if (_allTernFree == null)
- return null;
- if(_allTernFree.Count> total)
- {
- Random rand = new Random();
- int position = rand.Next(_allTernFree.Count - 1);
- string _code;
-
- for (int i = 0; i < total; i++)
- {
- _code = _allTernFree[position];
- _result.Add(_code);
- if (position + 1 >= _allTernFree.Count)
- position = 0;
- else
- position++;
- }
- }
- else
- {
- for (int i = 0; i < _allTernFree.Count; i++)
- {
- string _code = _allTernFree[i];
- _result.Add(_code);
- }
- }
-
- }
- catch (Exception)
- {
- }
- return _result;
- }
- public static List<string> getListTicketBuy(redisConnection _redis, buyTicketObj _ticketBuy,string randomId)
- {
- List<string> _result = new List<string>();
- try
- {
- for (int i = 0; i < _ticketBuy.ticket.Length; i++)
- {
- string _code = _ticketBuy.ticket[i].code;
- if (CommonFunction.check_THAILAN_IS_BUY_CACHE(_redis, _code, randomId) || CommonFunction.IsFixTicket(_redis, _code))
- {
- //da mua trong cache
- //Neu trong cache chua co thi add vao list
- if (!_result.Contains(_code))
- {
- _result.Add(_code);
- }
- }
-
- }
- }
- catch (Exception)
- {
-
- }
- return _result;
- }
- //Ham nay check trong cache va trong DB
- public static List<string> getListTicketBuyCacheDB(redisConnection _redis, buyTicketObj _ticketBuy, string randomId)
- {
- List<string> _result = new List<string>();
- try
- {
- for (int i = 0; i < _ticketBuy.ticket.Length; i++)
- {
- string _code = _ticketBuy.ticket[i].code;
- if (CommonFunction.check_THAILAN_IS_BUY_CACHE(_redis, _code, randomId))
- {
- //da mua trong cache
- //Neu trong cache chua co thi add vao list
- if (!_result.Contains(_code))
- {
- _result.Add(_code);
- }
- }
- else
- {
- //Truong hop nay khong ton tai trong cache da mua ve.
- // Neu day la cac so co phan cuoi trung voi he thong fix gia thi bat buoc phai vao DB kiem tra laij
- string _isCheckDB = _redis.getByKey(_redis.DB_INDEX_PARAM_CAMPAIGN, _redis.REDIS_IS_CHECK_TICKET_DB);
- if (!string.IsNullOrEmpty(_isCheckDB)) _isCheckDB = "1";
- if (_isCheckDB == "1")
- {
- if (IsTicketBuyDB(_code, randomId))
- {
- //da mua trong DB
- //Neu trong cache chua co thi add vao list
- TimeSpan _timeSpam = new TimeSpan(0, 0, 864000000); //Time out trong 10 ngay
- _redis.setByKey(_redis.DB_INDEX_DATA_TICKET_UNIQUE_BUY, _code + "_" + randomId, _code, _timeSpam);
- if (!_result.Contains(_code))
- {
- _result.Add(_code);
- }
- }
- }
- else
- {
- if (CommonFunction.IsFixTicket(_redis, _code))
- {
- //Truong hop nay bat buoc phai check DB
- if (IsTicketBuyDB(_code, randomId))
- {
- //da mua trong DB
- //Neu trong cache chua co thi add vao list
- TimeSpan _timeSpam = new TimeSpan(0, 0, 864000000); //Time out trong 10 ngay
- _redis.setByKey(_redis.DB_INDEX_DATA_TICKET_UNIQUE_BUY, _code + "_" + randomId, _code, _timeSpam);
- if (!_result.Contains(_code))
- {
- _result.Add(_code);
- }
- }
- }
- }
- }
- }
- }
- catch (Exception)
- {
- }
- return _result;
- }
-
- /// <summary>
- /// true: da mua ticket trong DB
- /// false: chua mua trong DB
- /// </summary>
- /// <param name="_ticket"></param>
- /// <param name="_random"></param>
- /// <returns></returns>
- public static bool IsTicketBuyDB(string _ticket,string _random)
- {
- bool _result = true;
- try
- {
- DataSet ds = lotoDataAccess.ThaiLan_checkTicketBuy(_ticket, _random);
- if(ds!=null && ds.Tables[0].Rows.Count>0)
- {
- string status = ds.Tables[0].Rows[0]["status"].ToString();
- if (status == "0")
- return false;
- else
- return true;
- }
- }
- catch (Exception)
- {
- }
- return _result;
- }
- public static bool systemIsOK(redisConnection _redis)
- {
- bool _result = false;
- try
- {
- if(_redis.isConnet())
- {
- DataSet ds = lotoDataAccess.checkDB("1");
- if(ds!=null & ds.Tables[0].Rows.Count>0)
- {
- return true;
- }
- }
- }
- catch (Exception)
- {
- }
- return _result;
- }
- }
- }
|