//樂透無派彩自動派彩 public double WaitballAutoPay(H5Games h5) { double b = 0; try { if (h5 == null) { throw new Exception("error"); } //亂數產生 int[] randomArray = new int[5]; Random rnd = new Random(); //產生亂數初始值 for (int i = 0; i < 5; i++) { randomArray[i] = rnd.Next(1, 37); //亂數產生,亂數產生的範圍是1~9 for (int j = 0; j < i; j++) { while (randomArray[j] == randomArray[i]) //檢查是否與前面產生的數值發生重複,如果有就重新產生 { j = 0; //如有重複,將變數j設為0,再次檢查 (因為還是有重複的可能) randomArray[i] = rnd.Next(1, 37); //重新產生,存回陣列,亂數產生的範圍是1~9 } } } //1:A-K 2:樂透 foreach (var rd in randomArray) { GameNumberRecord gnr = new GameNumberRecord { gameSn = h5.id, number = rd, inpdate = DateTime.Now, }; //寫入牌記錄 this.GNCreate(gnr); } //派彩 var player = this.PlayerGetAll(h5.id); int[] ary = new int[] { 0, 0, 0, 0 }; int[] bonus = new int[] { 50, 30, 20, 70 }; var ucm = new List <BallGameModel>(); //確認多少中獎 foreach (var p in player) { var number = this.NumberGetAll(p.id); int count = 0; var uc = new BallGameModel(); foreach (var n in number) { foreach (var rd in randomArray) { if (rd == n.Number) { count += 1; } } } if (count >= 2) { ary[count - 2] += 1; uc.gamebets = p; uc.count = count; ucm.Add(uc); } //確認正解 p.valid = 2; this.betsUpdate(p); } double total = (h5.totallottery != null) ? (double)h5.totallottery : 0; double ball = 18326000 + total; double totalbets = this.PlayerGetAll(h5.id).Sum(x => (double)x.money); double deduction = 0; foreach (var c in ucm) { double?rm = (c.count != 5) ? (totalbets * bonus[c.count - 2] / 100) / ary[c.count - 2] : ball + (totalbets * bonus[c.count - 2] / 100) / ary[c.count - 2]; if (c.count == 5) { h5.bingo = 1; deduction = totalbets + total; //deduction += total + (totalbets * 25 / 100) / ary[c.count - 2]; } else { deduction = totalbets; } //派彩記錄 H5payouts h5p = new H5payouts { gameSn = h5.id, userId = c.gamebets.userId, betSn = c.gamebets.id, Odds = c.gamebets.Odds, money = c.gamebets.money, readlMoney = rm * (100 - h5.rake) / 100, createDate = DateTime.Now, modiDate = DateTime.Now, rake = h5.rake }; this.Payouts(h5p); //玩家加錢和記錄 AssetsRecord assr = new AssetsRecord { UserId = h5p.userId, unitSn = 1, gameSn = h5.id, assets = (double)h5p.readlMoney, type = 15, h5forValue = h5.gameModel }; new AssetsRepository().Addh5gameByAssets(assr); } //開盤資料更新 h5.gameStatus = 0; h5.payDate = DateTime.Now; this.H5GameUpdate(h5); var ak = this.H5GetAll(2).Where(x => x.gameStatus == 1).ToList(); if (ak.Count == 0) { double m = DateTime.Now.Minute; double h = DateTime.Now.Hour; DateTime dtn = DateTime.Now; double md = (m < 30) ? 30 : 00; double hd = (m < 30) ? h : h + 1; int result = 0; result = Convert.ToInt16(Math.Floor(m / 3)) + 10; string dt = dtn.Year + "-" + dtn.Month + "-" + dtn.Day + " " + hd + ":" + md + ":" + dtn.Second; b = totalbets + total - deduction; H5Games h5g = new H5Games { title = "樂透", gameModel = 2, gameStatus = 1, valid = 1, rake = 20, createDate = DateTime.Now, totallottery = b, endTime = Convert.ToDateTime(dt) }; //h5g.totallottery = 500; new H5GameRepository().GameCreate(h5g); } } catch { } return(b); }
//樂透自動派彩 public double ballAutoPay(H5Games h5) { string url = "https://api.random.org/json-rpc/2/invoke"; Random r = new Random(); int id = r.Next(0, 100); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/json"; request.Method = "POST"; using (var streamWriter = new StreamWriter(request.GetRequestStream())) { string json = "{\"jsonrpc\":\"2.0\"," + "\"method\":\"generateIntegers\"," + "\"params\":{" + "\"apiKey\":\"3d80c333-78f2-4ed1-b4e1-80e07eb9f041\"," + "\"n\":5," + "\"min\":0," + "\"max\":35," + "\"replacement\":false}," + "\"id\":" + id + "}" ; streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)request.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); RandomObject ro = JsonConvert.DeserializeObject <RandomObject>(result); //1:A-K 2:樂透 foreach (var rd in ro.result.random.data) { GameNumberRecord gnr = new GameNumberRecord { gameSn = h5.id, number = rd, inpdate = DateTime.Now, }; //寫入牌記錄 this.GNCreate(gnr); } //派彩 var player = this.PlayerGetAll(h5.id); int[] ary = new int[] { 0, 0, 0, 0 }; var ucm = new List <BallGameModel>(); //確認多少中獎 foreach (var p in player) { var number = this.NumberGetAll(p.id); int count = 0; var uc = new BallGameModel(); foreach (var n in number) { foreach (var rd in ro.result.random.data) { if (rd == n.Number) { count += 1; } } } if (count >= 2) { ary[count - 2] += 1; uc.gamebets = p; uc.count = count; ucm.Add(uc); } //確認正解 p.valid = 2; this.betsUpdate(p); } double total = (h5.totallottery != null) ? (double)h5.totallottery:0; double ball = 500000 + total; double totalbets = this.PlayerGetAll(h5.id).Sum(x => (double)x.money); double deduction = 0; foreach (var c in ucm) { double?rm = (c.count != 5)?(totalbets * 25 / 100) / ary[c.count - 2]: ball + (totalbets * 25 / 100) / ary[c.count - 2]; if (c.count == 5) { h5.bingo = 1; deduction += total + (totalbets * 25 / 100) / ary[c.count - 2]; } else { deduction += (double)rm; } //派彩記錄 H5payouts h5p = new H5payouts { gameSn = h5.id, userId = c.gamebets.userId, betSn = c.gamebets.id, Odds = c.gamebets.Odds, money = c.gamebets.money, readlMoney = rm * (100 - h5.rake) / 100, createDate = DateTime.Now, modiDate = DateTime.Now, rake = h5.rake }; this.Payouts(h5p); //玩家加錢和記錄 AssetsRecord assr = new AssetsRecord { UserId = h5p.userId, unitSn = 1, gameSn = h5.id, assets = (double)h5p.readlMoney, type = 15, h5forValue = h5.gameModel }; new AssetsRepository().Addh5gameByAssets(assr); } //開盤資料更新 h5.gameStatus = 0; h5.payDate = DateTime.Now; this.H5GameUpdate(h5); return(totalbets + total - deduction); } }
//樂透自動派彩 public double ballAutoPay(H5Games h5) { double b = 0; /*try * { * string url = "https://api.random.org/json-rpc/2/invoke"; * Random r = new Random(); * int id = r.Next(0, 100); * * * HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); * request.ContentType = "application/json"; * request.Method = "POST"; * using (var streamWriter = new StreamWriter(request.GetRequestStream())) * { * string json = "{\"jsonrpc\":\"2.0\"," + * "\"method\":\"generateIntegers\"," + * "\"params\":{" + * "\"apiKey\":\"3d80c333-78f2-4ed1-b4e1-80e07eb9f041\"," + * "\"n\":5," + * "\"min\":0," + * "\"max\":35," + * "\"replacement\":false}," + * "\"id\":" + id + "}" * * ; * * streamWriter.Write(json); * streamWriter.Flush(); * streamWriter.Close(); * } * var httpResponse = (HttpWebResponse)request.GetResponse(); * * using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) * { * var result = streamReader.ReadToEnd(); * RandomObject ro = JsonConvert.DeserializeObject<RandomObject>(result); * * //1:A-K 2:樂透 * foreach (var rd in ro.result.random.data) * { * GameNumberRecord gnr = new GameNumberRecord * { * gameSn = h5.id, * number = rd, * inpdate = DateTime.Now, * }; * //寫入牌記錄 * this.GNCreate(gnr); * * } * * //派彩 * var player = this.PlayerGetAll(h5.id); * int[] ary = new int[] { 0, 0, 0, 0 }; * var ucm = new List<BallGameModel>(); * //確認多少中獎 * foreach (var p in player) * { * var number = this.NumberGetAll(p.id); * int count = 0; * var uc = new BallGameModel(); * * foreach (var n in number) * { * * foreach (var rd in ro.result.random.data) * { * if (rd == n.Number) * { * count += 1; * } * * } * * } * if (count >= 2) * { * ary[count - 2] += 1; * uc.gamebets = p; * uc.count = count; * ucm.Add(uc); * } * //確認正解 * p.valid = 2; * this.betsUpdate(p); * * * * * } * double total = (h5.totallottery != null) ? (double)h5.totallottery : 0; * double ball = 500000 + total; * double totalbets = this.PlayerGetAll(h5.id).Sum(x => (double)x.money); * * double deduction = 0; * * foreach (var c in ucm) * { * double? rm = (c.count != 5) ? (totalbets * 25 / 100) / ary[c.count - 2] : ball + (totalbets * 25 / 100) / ary[c.count - 2]; * * * if (c.count == 5) * { * h5.bingo = 1; * deduction += total + (totalbets * 25 / 100) / ary[c.count - 2]; * } * else * { * deduction += (double)rm; * } * * * //派彩記錄 * H5payouts h5p = new H5payouts * { * gameSn = h5.id, * userId = c.gamebets.userId, * betSn = c.gamebets.id, * Odds = c.gamebets.Odds, * money = c.gamebets.money, * readlMoney = rm * (100 - h5.rake) / 100, * createDate = DateTime.Now, * modiDate = DateTime.Now, * rake = h5.rake * * }; * * this.Payouts(h5p); * //玩家加錢和記錄 * AssetsRecord assr = new AssetsRecord * { * UserId = h5p.userId, * unitSn = 1, * gameSn = h5.id, * assets = (double)h5p.readlMoney, * type = 15, * h5forValue = h5.gameModel * * * }; * * new AssetsRepository().Addh5gameByAssets(assr); * * } * * * * * * * //開盤資料更新 * h5.gameStatus = 0; * h5.payDate = DateTime.Now; * this.H5GameUpdate(h5); * * * b = totalbets + total - deduction; * H5Games h5g = new H5Games * { * title = "樂透", * gameModel = 2, * gameStatus = 1, * valid = 1, * rake = 20, * createDate = DateTime.Now, * totallottery = b, * endTime = DateTime.Now.AddMinutes(30) * }; * //h5g.totallottery = 500; * new H5GameRepository().GameCreate(h5g); * //new H5GameRepository().akAutoPay(ak.LastOrDefault()); * * * * } * * } * catch { * var ak = this.H5GetAll(2).Where(x => x.gameStatus == 1).ToList(); * if (ak.Count == 1) * b = ballAutoPay(h5); * * }*/ try { if (h5 == null) { throw new Exception("error"); } //亂數產生 int[] randomArray = new int[5]; Random rnd = new Random(); //產生亂數初始值 for (int i = 0; i < 5; i++) { randomArray[i] = rnd.Next(1, 37); //亂數產生,亂數產生的範圍是1~9 for (int j = 0; j < i; j++) { while (randomArray[j] == randomArray[i]) //檢查是否與前面產生的數值發生重複,如果有就重新產生 { j = 0; //如有重複,將變數j設為0,再次檢查 (因為還是有重複的可能) randomArray[i] = rnd.Next(1, 37); //重新產生,存回陣列,亂數產生的範圍是1~9 } } } //1:A-K 2:樂透 foreach (var rd in randomArray) { GameNumberRecord gnr = new GameNumberRecord { gameSn = h5.id, number = rd, inpdate = DateTime.Now, }; //寫入牌記錄 this.GNCreate(gnr); } //派彩 var player = this.PlayerGetAll(h5.id); int[] ary = new int[] { 0, 0, 0, 0 }; int[] bonus = new int[] { 50, 30, 20, 70 }; var ucm = new List <BallGameModel>(); //確認多少中獎 foreach (var p in player) { var number = this.NumberGetAll(p.id); int count = 0; var uc = new BallGameModel(); foreach (var n in number) { foreach (var rd in randomArray) { if (rd == n.Number) { count += 1; } } } if (count >= 2) { ary[count - 2] += 1; uc.gamebets = p; uc.count = count; ucm.Add(uc); } //確認正解 p.valid = 2; this.betsUpdate(p); } double total = (h5.totallottery != null) ? (double)h5.totallottery : 0; double ball = 18326000 + total; double totalbets = this.PlayerGetAll(h5.id).Sum(x => (double)x.money); double deduction = 0; foreach (var c in ucm) { double?rm = (c.count != 5) ? (totalbets * bonus[c.count - 2] / 100) / ary[c.count - 2] : ball + (totalbets * bonus[c.count - 2] / 100) / ary[c.count - 2]; if (c.count == 5) { h5.bingo = 1; deduction = totalbets + total; //deduction += total + (totalbets * 25 / 100) / ary[c.count - 2]; } else { deduction = totalbets; } //派彩記錄 H5payouts h5p = new H5payouts { gameSn = h5.id, userId = c.gamebets.userId, betSn = c.gamebets.id, Odds = c.gamebets.Odds, money = c.gamebets.money, readlMoney = rm * (100 - h5.rake) / 100, createDate = DateTime.Now, modiDate = DateTime.Now, rake = h5.rake }; this.Payouts(h5p); //玩家加錢和記錄 AssetsRecord assr = new AssetsRecord { UserId = h5p.userId, unitSn = 1, gameSn = h5.id, assets = (double)h5p.readlMoney, type = 15, h5forValue = h5.gameModel }; new AssetsRepository().Addh5gameByAssets(assr); } //開盤資料更新 h5.gameStatus = 0; h5.payDate = DateTime.Now; this.H5GameUpdate(h5); b = totalbets + total - deduction; H5Games h5g = new H5Games { title = "樂透", gameModel = 2, gameStatus = 1, valid = 1, rake = 20, createDate = DateTime.Now, totallottery = b, endTime = DateTime.Now.AddMinutes(30) }; //h5g.totallottery = 500; new H5GameRepository().GameCreate(h5g); //new H5GameRepository().akAutoPay(ak.LastOrDefault()); } catch { var ak = this.H5GetAll(2).Where(x => x.gameStatus == 1).ToList(); if (ak.Count == 1) { b = ballAutoPay(h5); } } return(b); }