LotteryNumberController.cs 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069
  1. using Lottomat.Application.Busines.BaseManage;
  2. using Lottomat.Application.Busines.CommonManage;
  3. using Lottomat.Application.Busines.LotteryNumberManage;
  4. using Lottomat.Application.Cache;
  5. using Lottomat.Application.Code;
  6. using Lottomat.Application.Entity.BaseManage;
  7. using Lottomat.Application.Entity.BaseManage.Parameter;
  8. using Lottomat.Application.Entity.CommonEntity;
  9. using Lottomat.Application.Entity.LotteryNumberManage.Parameter;
  10. using Lottomat.Application.Entity.LotteryNumberManage.ViewModel;
  11. using Lottomat.Application.Entity.SystemManage.ViewModel;
  12. using Lottomat.SOA.API.Controllers.Base;
  13. using Lottomat.Util;
  14. using Lottomat.Util.Extension;
  15. using Lottomat.Utils;
  16. using Lottomat.Utils.Date;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Data;
  20. using System.Linq;
  21. using System.Net.Http;
  22. using System.Text;
  23. using System.Threading.Tasks;
  24. using System.Web.Http;
  25. namespace Lottomat.SOA.API.Controllers.V1
  26. {
  27. /// <summary>
  28. /// 开奖号相关接口
  29. /// </summary>
  30. public class LotteryNumberController : BaseApiController
  31. {
  32. #region 实例
  33. /// <summary>
  34. /// 锁
  35. /// </summary>
  36. private static readonly object _lock = new Object();
  37. /// <summary>
  38. /// 公共BLL
  39. /// </summary>
  40. private static readonly CommonBLL commonBll = new CommonBLL();
  41. /// <summary>
  42. /// 字典缓存BLL
  43. /// </summary>
  44. private static readonly DataItemCache dataItemCache = new DataItemCache();
  45. private static QGFC3DBLL qgfc3Dbll = new QGFC3DBLL();
  46. private static readonly BannerBLL bannerBLL = new BannerBLL();
  47. /// <summary>
  48. /// 彩种编码
  49. /// </summary>
  50. // QGC|全国彩,DFC|地方彩,GPC11X5|11选5,GPCK3|快3,GPCKL12|快乐十二,GPCKLSF|快乐十分,GPCSSC|时时彩,GPCQTC|其他彩种
  51. private static readonly string LotteryTypeCodeStr = ConfigHelper.GetValue("LotteryCategoryCodingMapping");
  52. #endregion 实例
  53. #region 获取系统热门、推荐彩种列表
  54. /// <summary>
  55. /// 获取系统热门、推荐彩种列表
  56. /// </summary>
  57. /// <param name="arg"></param>
  58. /// <returns></returns>
  59. [HttpPost]
  60. public HttpResponseMessage GetRecommendationAndHotLottery(BaseParameterEntity arg)
  61. {
  62. BaseJson<List<RecommendationAndHotLotteryViewEntity>> resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  63. Task task = Task.Factory.StartNew(() =>
  64. {
  65. Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取系统热门、推荐彩种列表-GetRecommendationAndHotLottery", () =>
  66. {
  67. if (!string.IsNullOrEmpty(arg.t))
  68. {
  69. if (arg.t.CheckTimeStamp())
  70. {
  71. string codeList = GetCodeList();
  72. //获取所有彩种
  73. List<DataItemModel> cache = dataItemCache.GetDataItemList(codeList).OrderBy(d => d.SortCode ?? 0).ToList();
  74. List<RecommendationAndHotLotteryViewEntity> res = new List<RecommendationAndHotLotteryViewEntity>();
  75. //筛选推荐
  76. List<LotteryItems> lotteryItemsesRecommend = (from model in cache
  77. where model.IsRecommend
  78. select new LotteryItems
  79. {
  80. Id = model.ItemDetailId,
  81. Code = model.ItemValue,
  82. Name = model.ItemName,
  83. EnumCode = model.SimpleSpelling
  84. }).ToList();
  85. RecommendationAndHotLotteryViewEntity Recommend = new RecommendationAndHotLotteryViewEntity
  86. {
  87. Type = 0,
  88. Desc = "推荐",
  89. LotteryItemses = lotteryItemsesRecommend
  90. };
  91. res.Add(Recommend);
  92. //筛选热门
  93. List<LotteryItems> lotteryItemsesHot = (from model in cache
  94. where model.IsHot
  95. select new LotteryItems
  96. {
  97. Id = model.ItemDetailId,
  98. Code = model.ItemValue,
  99. Name = model.ItemName,
  100. EnumCode = model.SimpleSpelling
  101. }).ToList();
  102. RecommendationAndHotLotteryViewEntity Hot = new RecommendationAndHotLotteryViewEntity
  103. {
  104. Type = 1,
  105. Desc = "热门",
  106. LotteryItemses = lotteryItemsesHot
  107. };
  108. res.Add(Hot);
  109. resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>>
  110. {
  111. Status = (int)JsonObjectStatus.Success,
  112. Data = res,
  113. Message = JsonObjectStatus.Success.GetEnumText(),
  114. BackUrl = null
  115. };
  116. }
  117. else
  118. {
  119. resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>>
  120. {
  121. Status = (int)JsonObjectStatus.Fail,
  122. Data = null,
  123. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  124. BackUrl = null
  125. };
  126. }
  127. }
  128. else
  129. {
  130. resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>>
  131. {
  132. Status = (int)JsonObjectStatus.Fail,
  133. Data = null,
  134. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  135. BackUrl = null
  136. };
  137. }
  138. }, e =>
  139. {
  140. resultMsg = new BaseJson<List<RecommendationAndHotLotteryViewEntity>>
  141. {
  142. Status = (int)JsonObjectStatus.Exception,
  143. Data = null,
  144. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  145. BackUrl = null
  146. };
  147. });
  148. });
  149. task.Wait();
  150. return resultMsg.TryToJson().ToHttpResponseMessage();
  151. }
  152. #endregion 获取系统热门、推荐彩种列表
  153. #region 彩票大厅
  154. /// <summary>
  155. /// 彩票大厅
  156. /// </summary>
  157. /// <returns></returns>
  158. [HttpPost]
  159. public HttpResponseMessage GetAllLotteryList(BaseParameterEntity arg)
  160. {
  161. BaseJson<List<AllLotteryListViewEntity>> resultMsg = new BaseJson<List<AllLotteryListViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  162. Task task = Task.Factory.StartNew(() =>
  163. {
  164. Logger(typeof(LotteryNumberController), arg.TryToJson(), "彩票大厅-GetAllLotteryList", () =>
  165. {
  166. if (!string.IsNullOrEmpty(arg.t))
  167. {
  168. if (arg.t.CheckTimeStamp())
  169. {
  170. List<AllLotteryListViewEntity> res = new List<AllLotteryListViewEntity>();
  171. string[] lotteryTypeCodeArr = LotteryTypeCodeStr.Split(",".ToCharArray());
  172. foreach (string code in lotteryTypeCodeArr)
  173. {
  174. string[] arr = code.Split("|".ToCharArray());
  175. List<LotteryItems> items = new List<LotteryItems>();
  176. //获取对应彩种
  177. List<DataItemModel> cache = dataItemCache.GetDataItemList(arr[0]);
  178. foreach (DataItemModel model in cache)
  179. {
  180. LotteryItems temp = new LotteryItems
  181. {
  182. Id = model.ItemDetailId,
  183. Code = model.ItemValue,
  184. Name = model.ItemName,
  185. EnumCode = model.SimpleSpelling
  186. };
  187. items.Add(temp);
  188. }
  189. res.Add(new AllLotteryListViewEntity
  190. {
  191. TypeCode = arr[0],
  192. TypeName = arr[1],
  193. LotteryItemses = items
  194. });
  195. }
  196. resultMsg = new BaseJson<List<AllLotteryListViewEntity>>
  197. {
  198. Status = (int)JsonObjectStatus.Success,
  199. Data = res,
  200. Message = JsonObjectStatus.Success.GetEnumText(),
  201. BackUrl = null
  202. };
  203. }
  204. else
  205. {
  206. resultMsg = new BaseJson<List<AllLotteryListViewEntity>>
  207. {
  208. Status = (int)JsonObjectStatus.Fail,
  209. Data = null,
  210. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  211. BackUrl = null
  212. };
  213. }
  214. }
  215. else
  216. {
  217. resultMsg = new BaseJson<List<AllLotteryListViewEntity>>
  218. {
  219. Status = (int)JsonObjectStatus.Fail,
  220. Data = null,
  221. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数type为空。",
  222. BackUrl = null
  223. };
  224. }
  225. }, e =>
  226. {
  227. resultMsg = new BaseJson<List<AllLotteryListViewEntity>>
  228. {
  229. Status = (int)JsonObjectStatus.Exception,
  230. Data = null,
  231. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  232. BackUrl = null
  233. };
  234. });
  235. });
  236. task.Wait();
  237. //Tasks.Add(task);
  238. return resultMsg.TryToJson().ToHttpResponseMessage();
  239. }
  240. #endregion 彩票大厅
  241. #region 获取首页展示详细开奖信息的彩种
  242. /// <summary>
  243. /// 获取首页展示详细开奖信息的彩种
  244. /// </summary>
  245. /// <returns></returns>
  246. [HttpPost]
  247. public HttpResponseMessage GetHomeLotteryList(BaseParameterEntity arg)
  248. {
  249. BaseJson<List<HomeLotteryListViewEntity>> resultMsg = new BaseJson<List<HomeLotteryListViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  250. Task task = Task.Factory.StartNew(() =>
  251. {
  252. Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取首页展示详细开奖信息的彩种-GetHomeLotteryList", () =>
  253. {
  254. if (!string.IsNullOrEmpty(arg.t))
  255. {
  256. if (arg.t.CheckTimeStamp())
  257. {
  258. lock (_lock)
  259. {
  260. string codeList = GetCodeList();
  261. //获取所有彩种
  262. List<DataItemModel> cache = dataItemCache.GetDataItemList(codeList).OrderBy(d => d.SortCode ?? 0).ToList();
  263. //获取类型码-枚举码字典
  264. Dictionary<string, SCCLottery> dictionary = GetTypeCodeAndEnumCodeDict(cache, true);
  265. //结果集合
  266. List<HomeLotteryListViewEntity> res = GetRealData(dictionary);
  267. resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
  268. {
  269. Status = (int)JsonObjectStatus.Success,
  270. Data = res,
  271. Message = JsonObjectStatus.Success.GetEnumText(),
  272. BackUrl = null
  273. };
  274. }
  275. }
  276. else
  277. {
  278. resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
  279. {
  280. Status = (int)JsonObjectStatus.Fail,
  281. Data = null,
  282. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  283. BackUrl = null
  284. };
  285. }
  286. }
  287. else
  288. {
  289. resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
  290. {
  291. Status = (int)JsonObjectStatus.Fail,
  292. Data = null,
  293. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  294. BackUrl = null
  295. };
  296. }
  297. }, e =>
  298. {
  299. resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
  300. {
  301. Status = (int)JsonObjectStatus.Exception,
  302. Data = null,
  303. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  304. BackUrl = null
  305. };
  306. });
  307. });
  308. task.Wait();
  309. return resultMsg.TryToJson().ToHttpResponseMessage();
  310. }
  311. /// <summary>
  312. /// 根据彩种编码获取对应推荐的彩种开奖详情
  313. /// </summary>
  314. /// <param name="arg"></param>
  315. /// <returns></returns>
  316. [HttpPost]
  317. public HttpResponseMessage GetHomeLotteryListByTypeCode(HomeLotteryListByTypeCodeArgEntity arg)
  318. {
  319. BaseJson<List<HomeLotteryListViewEntity>> resultMsg = new BaseJson<List<HomeLotteryListViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  320. Task task = Task.Factory.StartNew(() =>
  321. {
  322. Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取首页展示详细开奖信息的彩种-GetHomeLotteryList", () =>
  323. {
  324. if (!string.IsNullOrEmpty(arg.t) && !string.IsNullOrEmpty(arg.TypeCode))
  325. {
  326. if (arg.t.CheckTimeStamp())
  327. {
  328. lock (_lock)
  329. {
  330. //获取所有彩种
  331. List<DataItemModel> cache = dataItemCache.GetDataItemList(arg.TypeCode).OrderBy(d => d.SortCode ?? 0).ToList();
  332. //获取类型码-枚举码字典
  333. Dictionary<string, SCCLottery> dictionary = GetTypeCodeAndEnumCodeDict(cache, false, true, false, arg.TypeCode);
  334. //结果集合
  335. List<HomeLotteryListViewEntity> res = GetRealData(dictionary);
  336. resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
  337. {
  338. Status = (int)JsonObjectStatus.Success,
  339. Data = res,
  340. Message = JsonObjectStatus.Success.GetEnumText(),
  341. BackUrl = null
  342. };
  343. }
  344. }
  345. else
  346. {
  347. resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
  348. {
  349. Status = (int)JsonObjectStatus.Fail,
  350. Data = null,
  351. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  352. BackUrl = null
  353. };
  354. }
  355. }
  356. else
  357. {
  358. resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
  359. {
  360. Status = (int)JsonObjectStatus.Fail,
  361. Data = null,
  362. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  363. BackUrl = null
  364. };
  365. }
  366. }, e =>
  367. {
  368. resultMsg = new BaseJson<List<HomeLotteryListViewEntity>>
  369. {
  370. Status = (int)JsonObjectStatus.Exception,
  371. Data = null,
  372. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  373. BackUrl = null
  374. };
  375. });
  376. });
  377. task.Wait();
  378. return resultMsg.TryToJson().ToHttpResponseMessage();
  379. }
  380. /// <summary>
  381. /// 获取彩种编码
  382. /// </summary>
  383. /// <returns></returns>
  384. private static string GetCodeList()
  385. {
  386. string codeList = String.Empty;
  387. string[] lotteryTypeCodeArr = LotteryTypeCodeStr.Split(",".ToCharArray());
  388. codeList = lotteryTypeCodeArr.Select(code => code.Split("|".ToCharArray())).Aggregate(codeList, (current, arr) => current + (arr[0] + "|"));
  389. codeList = StringHelper.DelLastChar(codeList, "|");
  390. return codeList;
  391. }
  392. /// <summary>
  393. /// 组装开奖号
  394. /// </summary>
  395. /// <param name="data">最新一期开奖详情</param>
  396. /// <param name="enumCode">枚举码</param>
  397. /// <param name="ballItems">开奖号集合</param>
  398. private static void GetOpenCodeValue(DataRow data, string enumCode, out List<LotteryBallItem> ballItems)
  399. {
  400. List<LotteryBallItem> temp = new List<LotteryBallItem>();
  401. int[] codeArr = LotteryBallTypeDict[enumCode];
  402. //正常球个数
  403. int normal = codeArr[0];
  404. //蓝球个数
  405. int blue = codeArr[1];
  406. //生肖球个数
  407. int zodiac = codeArr[2];
  408. //季节球个数
  409. int season = codeArr[3];
  410. //方位球个数
  411. int position = codeArr[4];
  412. #region 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0
  413. //总球数
  414. int total = normal + blue + zodiac + season + position;
  415. List<int> ballList = new List<int>();
  416. for (int i = 1; i <= total; i++)
  417. {
  418. ballList.Add(data["OpenCode" + i].TryToInt32());
  419. }
  420. //取出当前最大开奖号
  421. //TODO 此做法欠妥,如果当前彩种开奖号取值在0-20之间,有可能某一期开奖号全部都小于10
  422. int max = ballList.Max();
  423. //是否需要添加0
  424. bool hasAppendZero = (!enumCode.Equals(SCCLottery.ShanDongKLPK3.ToString()) && max >= 10) || enumCode.Equals(SCCLottery.GuangDongHC1.ToString());
  425. #endregion 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0
  426. #region 正常球
  427. if (normal > 0)
  428. {
  429. for (int i = 1; i <= normal; i++)
  430. {
  431. int openCode = ballList[i - 1];//data["OpenCode" + i].TryToInt32();
  432. temp.Add(new LotteryBallItem
  433. {
  434. BallType = LotteryBallType.Normal,
  435. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  436. });
  437. }
  438. }
  439. #endregion 正常球
  440. #region 蓝球
  441. if (blue > 0)
  442. {
  443. int index = normal;
  444. //for (int i = blue; i >= 1; i--)
  445. for (int i = 1; i <= blue; i++)
  446. {
  447. int openCode = ballList[index + i - 1];//data["OpenCode" + (normal + i)].TryToInt32();
  448. temp.Add(new LotteryBallItem
  449. {
  450. BallType = LotteryBallType.Blue,
  451. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  452. });
  453. }
  454. }
  455. #endregion 蓝球
  456. #region 生肖球
  457. if (zodiac > 0)
  458. {
  459. int index = normal + blue;
  460. for (int i = zodiac; i >= 1; i--)
  461. {
  462. int openCode = ballList[index + i - 1];//data["OpenCode" + (normal + blue + i)].TryToInt32();
  463. temp.Add(new LotteryBallItem
  464. {
  465. BallType = LotteryBallType.Zodiac,
  466. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  467. });
  468. }
  469. }
  470. #endregion 生肖球
  471. #region 季节球
  472. if (season > 0)
  473. {
  474. int index = normal + blue + zodiac;
  475. for (int i = season; i >= 1; i--)
  476. {
  477. int openCode = ballList[index + i - 1];//data["OpenCode" + (normal + blue + zodiac + i)].TryToInt32();
  478. temp.Add(new LotteryBallItem
  479. {
  480. BallType = LotteryBallType.Season,
  481. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  482. });
  483. }
  484. }
  485. #endregion 季节球
  486. #region 方位球
  487. if (position > 0)
  488. {
  489. int index = normal + blue + zodiac + season;
  490. for (int i = position; i >= 1; i--)
  491. {
  492. int openCode = ballList[index + i - 1];//data["OpenCode" + (normal + blue + zodiac + season + i)].TryToInt32();
  493. temp.Add(new LotteryBallItem
  494. {
  495. BallType = LotteryBallType.Position,
  496. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  497. });
  498. }
  499. }
  500. #endregion 方位球
  501. ballItems = temp;
  502. }
  503. /// <summary>
  504. /// 计算下一次开奖时间
  505. /// </summary>
  506. /// <param name="config">彩种配置文件</param>
  507. /// <param name="currentOpenTime">最新一期开奖时间</param>
  508. /// <param name="openThePrizeOnTheDayOfTheWeek">每周那几天开奖数组</param>
  509. /// <param name="now">当前时间</param>
  510. /// <returns></returns>
  511. private DateTime GetNextOpenTime(SCCConfig config, DateTime currentOpenTime, string[] openThePrizeOnTheDayOfTheWeek, DateTime now)
  512. {
  513. //今天是星期几
  514. string week = DateTimeHelper.Now.DayOfWeek.ToString("d");
  515. //今天星期在数组中的索引
  516. int pointer = Array.IndexOf(openThePrizeOnTheDayOfTheWeek, week);
  517. //间隔时间
  518. int interval = config.Interval;
  519. //每天期数
  520. int timesPerDay = config.TimesPerDay;
  521. //当前彩种今天真实开始开奖时间
  522. DateTime todayRealStartOpentime = (DateTimeHelper.Now.ToString("yyyy-MM-dd") + " " + config.StartHour + ":" + config.StartMinute).TryToDateTime();
  523. //下次开奖时间
  524. DateTime nextOpenTime = default(DateTime);
  525. //今天将要开奖,计算出将要开奖时间
  526. if (pointer != -1)
  527. {
  528. //如果当前时间小于将要开奖时间,说明还未开奖,返回将要开奖时间
  529. if (now < todayRealStartOpentime)
  530. {
  531. //Modify By 大师兄 解决高频彩问题
  532. if (interval > 0 && timesPerDay > 1)
  533. {
  534. //计算真实开始开奖时间到现在时间已经开了多少期
  535. TimeSpan span = now - todayRealStartOpentime;
  536. int total = (int)Math.Floor(span.TotalMinutes * 1.0 / interval) + 1;
  537. nextOpenTime = todayRealStartOpentime.AddMinutes(total * interval);
  538. }
  539. else
  540. {
  541. nextOpenTime = todayRealStartOpentime;
  542. }
  543. }
  544. else
  545. {
  546. if (interval > 0 && timesPerDay > 1)
  547. {
  548. //Modify By 大师兄 解决偶尔开奖号未抓取到,导致中间少了
  549. //判断当前时间是否大于数据库最新一条记录开奖时间,如果大于,说明数据正常;如果小于,则说明数据库数据存在异常
  550. if (now > currentOpenTime)
  551. {
  552. //计算当前时间到当前最新一期开奖时间已经开了多少期
  553. TimeSpan span = now - currentOpenTime;
  554. int total = (int)Math.Floor(Math.Abs(span.TotalMinutes) * 1.0 / interval) + 1;
  555. nextOpenTime = currentOpenTime.AddMinutes(total * interval);
  556. }
  557. else
  558. {
  559. //Modify By 大师兄 解决当前最新一期开奖时间大于当前时间问题
  560. //矫正开奖时间
  561. #region 此算法较粗糙,可能会出现当天开奖时间有误差的情况
  562. //计算真实开始开奖时间到现在时间已经开了多少期
  563. //TimeSpan span = now - todayRealStartOpentime;
  564. //int total = (int)Math.Floor(span.TotalMinutes * 1.0 / interval) + 1;
  565. //nextOpenTime = todayRealStartOpentime.AddMinutes(total * interval);
  566. #endregion 此算法较粗糙,可能会出现当天开奖时间有误差的情况
  567. //计算当前最新一期开奖时间到现在已经开了多少期
  568. TimeSpan span = currentOpenTime - now;
  569. int total = (int)Math.Floor(Math.Abs(span.TotalMinutes) * 1.0 / interval) + 1;
  570. nextOpenTime = currentOpenTime.AddMinutes(total * interval);
  571. }
  572. }
  573. else
  574. {
  575. if (openThePrizeOnTheDayOfTheWeek.Length > pointer + 1)
  576. {
  577. pointer++;
  578. }
  579. else
  580. {
  581. pointer = 0;
  582. }
  583. //解决星期天的问题
  584. int week_n = openThePrizeOnTheDayOfTheWeek[pointer].TryToInt32() == 0 ? 7 : openThePrizeOnTheDayOfTheWeek[pointer].TryToInt32();
  585. int days = Math.Abs(week_n - week.TryToInt32());
  586. nextOpenTime = todayRealStartOpentime.AddDays(days);
  587. }
  588. }
  589. }
  590. else
  591. {
  592. //今天不开奖,计算出下一次开奖时间
  593. int week_t = week.TryToInt32();
  594. for (int i = 0; i < 7; i++)
  595. {
  596. week_t++;
  597. week_t = week_t.TryToInt32() <= 6 ? week_t.TryToInt32() : 0;
  598. int index = Array.IndexOf(openThePrizeOnTheDayOfTheWeek, week_t.ToString());
  599. if (index >= 0)
  600. {
  601. //解决星期天的问题
  602. int week_n = openThePrizeOnTheDayOfTheWeek[index].TryToInt32() == 0 ? 7 : openThePrizeOnTheDayOfTheWeek[index].TryToInt32();
  603. int days = Math.Abs(week_n - week.TryToInt32());
  604. nextOpenTime = todayRealStartOpentime.AddDays(days);
  605. break;
  606. }
  607. }
  608. }
  609. return nextOpenTime.AddMinutes(1);
  610. }
  611. /// <summary>
  612. /// 组装开奖详情
  613. /// </summary>
  614. /// <param name="data">最新一期开奖详情</param>
  615. /// <param name="type">彩票类型</param>
  616. /// <param name="typeCode">类型码</param>
  617. /// <returns></returns>
  618. private HomeLotteryListViewEntity GetOpenCodeRealDataItem(DataTable data, SCCLottery type, string typeCode)
  619. {
  620. //枚举码
  621. string enumCode = type.ToString();
  622. List<LotteryBallItem> ballItems = new List<LotteryBallItem>();
  623. //有特殊球的情况下
  624. if (LotteryBallTypeDict.ContainsKey(enumCode))
  625. {
  626. GetOpenCodeValue(data.Rows[0], enumCode, out ballItems);
  627. }
  628. else
  629. {
  630. //总共球个数
  631. int total = type.GetEnumText().TryToInt32();
  632. #region 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0
  633. List<int> ballList = new List<int>();
  634. for (int i = 1; i <= total; i++)
  635. {
  636. var OpenCode = data.Rows[0]["OpenCode" + i].TryToInt32();
  637. ballList.Add(OpenCode);
  638. }
  639. //取出当前最大开奖号
  640. //TODO 此做法欠妥,如果当前彩种开奖号取值在0-20之间,有可能某一期开奖号全部都小于10
  641. int max = ballList.Max();
  642. //是否需要添加0
  643. bool hasAppendZero = (type != SCCLottery.ShanDongKLPK3 && max >= 10) || type == SCCLottery.GuangDongHC1;
  644. #endregion 如果当前彩种最大开奖号大于10,则小于10的开奖号需要在前面加0
  645. for (int i = 1; i <= total; i++)
  646. {
  647. int openCode = ballList[i - 1];//data.Rows[0]["OpenCode" + i].TryToInt32();
  648. ballItems.Add(new LotteryBallItem
  649. {
  650. //山东快乐扑克3为特殊球
  651. BallType = type == SCCLottery.ShanDongKLPK3 ? LotteryBallType.Poker : LotteryBallType.Normal,
  652. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  653. });
  654. }
  655. }
  656. //获取当前彩种配置信息
  657. SCCConfig config = LotteryConfig.FirstOrDefault(s => s.EnumCode.Equals(enumCode));
  658. //当前最新一期已经开奖时间
  659. DateTime currentOpenTime = data.Rows[0]["OpenTime"].TryToDateTime();
  660. //期数
  661. string term = data.Rows[0]["Term"].ToStringEx();
  662. //开奖详情
  663. string spare = data.Rows[0]["Spare"].ToString().Trim();
  664. //当前时间
  665. DateTime nowTime = DateTimeHelper.Now;
  666. if (config != null)
  667. {
  668. //当前彩种每周开奖时间
  669. string[] openThePrizeOnTheDayOfTheWeek = config.KJTime.Split(",".ToCharArray());
  670. //下一次开奖时间
  671. DateTime nextOpenTime = GetNextOpenTime(config, currentOpenTime, openThePrizeOnTheDayOfTheWeek, nowTime);
  672. //彩种名称
  673. string lotteryName = string.IsNullOrEmpty(config.LotteryName) ? type.GetEnumDescription() : config.LotteryName;
  674. //组装三要素,描述
  675. string keywords, desc;
  676. #region 从配置文件里面获取三要素(暂时弃用)
  677. ////组装三要素
  678. //string keywords = string.Format(ConfigHelper.GetValue("LotteryDetailElementsKeywords"), lotteryName, term);
  679. ////组装描述
  680. //string desc = string.Format(ConfigHelper.GetValue("LotteryDetailElementsDescription"), lotteryName, config.KJRate, lotteryName);
  681. #endregion 从配置文件里面获取三要素(暂时弃用)
  682. #region 从数据库获取三要素
  683. List<SystemTdkViewEntity> tdkData = GetTDKData();
  684. //Key
  685. string key = "LotteryTDK_" + enumCode;
  686. SystemTdkViewEntity tdk = tdkData.FirstOrDefault(t => t.LotteryCode.Equals(key));
  687. if (tdk != null)
  688. {
  689. desc = tdk.Desc;
  690. keywords = tdk.Title;
  691. }
  692. else
  693. {
  694. keywords = string.Format(ConfigHelper.GetValue("LotteryDetailElementsKeywords"), lotteryName, term);
  695. desc = string.Format(ConfigHelper.GetValue("LotteryDetailElementsDescription"), lotteryName, config.KJRate, lotteryName);
  696. }
  697. #endregion 从数据库获取三要素
  698. //组装最终结果
  699. HomeLotteryListViewEntity res = new HomeLotteryListViewEntity
  700. {
  701. TypeCode = typeCode,
  702. CurrentTerm = term,
  703. EnumCode = enumCode,
  704. Cid=GetCid(enumCode),
  705. CurrentOpenTime = currentOpenTime.ToString("yyyy-MM-dd HH:mm"),
  706. ServerTime = nowTime.ToString("yyyy-MM-dd HH:mm:ss"),
  707. NextOpenTime = nextOpenTime.ToString("yyyy-MM-dd HH:mm"),
  708. //CurrentTotalTerm = config.TimesPerDay,
  709. LotteryName = lotteryName,
  710. LotteryBallItems = ballItems,
  711. //Interval = config.Interval,
  712. KJRate = config.KJRate,
  713. //OpenThePrizeOnTheDayOfTheWeek = openThePrizeOnTheDayOfTheWeek,
  714. //StartThePrizeTimeEveryDay = config.StartHour.RepairZero() + ":" + config.StartMinute.RepairZero(),
  715. Keywords = keywords,
  716. Desc = desc,
  717. Spare = spare
  718. };
  719. return res;
  720. }
  721. else
  722. {
  723. //TODO 容错处理,仅返回开奖号、开奖时间
  724. //彩种名称
  725. string lotteryName = type.GetEnumDescription();
  726. //组装三要素
  727. string keywords = string.Format(ConfigHelper.GetValue("LotteryDetailElementsKeywords"), lotteryName, term);
  728. //组装描述
  729. string desc = string.Format(ConfigHelper.GetValue("LotteryDetailElementsDescription"), lotteryName, "", lotteryName);
  730. //组装最终结果
  731. HomeLotteryListViewEntity res = new HomeLotteryListViewEntity
  732. {
  733. TypeCode = typeCode,
  734. CurrentTerm = term,
  735. EnumCode = enumCode,
  736. CurrentOpenTime = currentOpenTime.ToString("yyyy-MM-dd HH:mm"),
  737. ServerTime = nowTime.ToString("yyyy-MM-dd HH:mm:ss"),
  738. NextOpenTime = nowTime.ToString("yyyy-MM-dd HH:mm"),
  739. //CurrentTotalTerm = 1,
  740. LotteryName = lotteryName,
  741. LotteryBallItems = ballItems,
  742. //Interval = 1,
  743. KJRate = "",
  744. //OpenThePrizeOnTheDayOfTheWeek = new[] { "" },
  745. //StartThePrizeTimeEveryDay = "",
  746. Keywords = keywords,
  747. Desc = desc,
  748. Spare = spare
  749. };
  750. return res;
  751. }
  752. }
  753. /// <summary>
  754. /// 组装最终数据
  755. /// </summary>
  756. /// <param name="dictionary">彩票类型码-枚举码</param>
  757. /// <returns></returns>
  758. private List<HomeLotteryListViewEntity> GetRealData(Dictionary<string, SCCLottery> dictionary)
  759. {
  760. List<HomeLotteryListViewEntity> res = new List<HomeLotteryListViewEntity>();
  761. foreach (KeyValuePair<string, SCCLottery> pair in dictionary)
  762. {
  763. string typeCode = pair.Key;
  764. SCCLottery lottery = pair.Value;
  765. //组装查询语句
  766. string sql = GetSeleteSQL(lottery);
  767. //查询结果
  768. DataTable o = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
  769. if (o.Rows.Count > 0)
  770. {
  771. //Trace.WriteLine(o.Rows[0].ItemArray);
  772. if (int.Parse(o.Rows[0]["OpenCode1"].ToString()) == -1)
  773. {
  774. sql = GetSeleteSQL(lottery,true);
  775. o = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
  776. }
  777. res.Add(GetOpenCodeRealDataItem(o, lottery, typeCode));
  778. }
  779. }
  780. return res;
  781. }
  782. /// <summary>
  783. /// 获取类型码-枚举码字典
  784. /// </summary>
  785. /// <param name="model">系统字典集合</param>
  786. /// <param name="TypeCode"></param>
  787. /// <returns></returns>
  788. private Dictionary<string, SCCLottery> GetTypeCodeAndEnumCodeDict(List<DataItemModel> model, bool IsRecommend = false, bool IsShowHomePage = false, bool IsHot = false, string TypeCode = "")
  789. {
  790. string key = IsRecommend ? "__IsRecommend___" : IsShowHomePage ? "__IsShowHomePage__" : IsHot ? "__IsHot__" : "__Public__";
  791. if (!string.IsNullOrEmpty(TypeCode))
  792. key += TypeCode + "__";
  793. //类型码-枚举
  794. //Dictionary<string, SCCLottery> dictionary = Cache.Factory.CacheFactory.Cache().GetCache<Dictionary<string, SCCLottery>>(CacheKeyEnum.TypeCodeAndEnumCodeDict.ToString() + key);
  795. Dictionary<string, SCCLottery> dictionary = webCache.GetObject<Dictionary<string, SCCLottery>>(CacheKeyEnum.TypeCodeAndEnumCodeDict.ToString() + key);
  796. if (dictionary == null || dictionary.Count == 0)
  797. {
  798. dictionary = new Dictionary<string, SCCLottery>();
  799. //枚举码
  800. List<string> enumCode = new List<string>();
  801. //类型码
  802. List<string> typeCode = new List<string>();
  803. //筛选推荐
  804. if (IsRecommend)
  805. {
  806. enumCode = model.Where(d => d.IsRecommend).Select(d => d.SimpleSpelling).ToList();
  807. typeCode = model.Where(d => d.IsRecommend).Select(d => d.ItemValue).ToList();
  808. }
  809. //筛选二级首页显示彩种
  810. if (IsShowHomePage)
  811. {
  812. enumCode = model.Where(d => d.IsShowHomePage).Select(d => d.SimpleSpelling).ToList();
  813. typeCode = model.Where(d => d.IsShowHomePage).Select(d => d.ItemValue).ToList();
  814. }
  815. //筛选热门
  816. if (IsHot)
  817. {
  818. enumCode = model.Where(d => d.IsHot).Select(d => d.SimpleSpelling).ToList();
  819. typeCode = model.Where(d => d.IsHot).Select(d => d.ItemValue).ToList();
  820. }
  821. //枚举列表
  822. List<SCCLottery> lotteryType = enumCode.Select(s => (SCCLottery)Enum.Parse(typeof(SCCLottery), s, true)).ToList();
  823. for (int i = 0; i < typeCode.Count; i++)
  824. {
  825. if (!dictionary.ContainsKey(typeCode[i]))
  826. {
  827. dictionary.Add(typeCode[i], lotteryType[i]);
  828. }
  829. }
  830. //Cache.Factory.CacheFactory.Cache().WriteCache(dictionary, CacheKeyEnum.TypeCodeAndEnumCodeDict.ToString() + key, DateTimeHelper.Now.AddDays(30));
  831. webCache.AddObject(CacheKeyEnum.TypeCodeAndEnumCodeDict.ToString() + key, dictionary, (int)CacheTime.Data);
  832. }
  833. return dictionary;
  834. }
  835. #endregion 获取首页展示详细开奖信息的彩种
  836. #region 根据彩票枚举码获取最新一期开奖详情
  837. /// <summary>
  838. /// 根据彩票枚举码获取最新一期开奖详情
  839. /// </summary>
  840. /// <returns></returns>
  841. [HttpPost]
  842. public HttpResponseMessage GetTheLatestAwardByEnumCode(TheLatestAwardArgEntity arg)
  843. {
  844. BaseJson<HomeLotteryListViewEntity> resultMsg = new BaseJson<HomeLotteryListViewEntity> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  845. Logger(typeof(LotteryNumberController), arg.TryToJson(), "根据彩票枚举码获取最新一期开奖详情-GetTheLatestAwardByEnumCode", () =>
  846. {
  847. if (!string.IsNullOrEmpty(arg.t))
  848. {
  849. if (arg.t.CheckTimeStamp())
  850. {
  851. //通过枚举码查询
  852. if (!string.IsNullOrEmpty(arg.EnumCode))
  853. {
  854. bool isSucc = Enum.TryParse<SCCLottery>(arg.EnumCode, true, out SCCLottery type);
  855. //SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), arg.EnumCode, true);
  856. if (!isSucc)
  857. {
  858. resultMsg = new BaseJson<HomeLotteryListViewEntity>
  859. {
  860. Status = (int)JsonObjectStatus.Fail,
  861. Data = null,
  862. Message = $"参数值{arg.EnumCode}无效。",
  863. BackUrl = null
  864. };
  865. }
  866. else
  867. {
  868. //查询SQL
  869. string sql = !string.IsNullOrEmpty(arg.Term) ? GetSeleteSQL(type, arg.Term) : GetSeleteSQL(type);
  870. //查询结果
  871. DataTable o = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
  872. if (o.Rows.Count > 0)
  873. {
  874. HomeLotteryListViewEntity entity = GetOpenCodeRealDataItem(o, type, "");
  875. resultMsg = new BaseJson<HomeLotteryListViewEntity>
  876. {
  877. Status = (int)JsonObjectStatus.Success,
  878. Data = entity,
  879. Message = JsonObjectStatus.Success.GetEnumText(),
  880. BackUrl = null
  881. };
  882. }
  883. else
  884. {
  885. resultMsg = new BaseJson<HomeLotteryListViewEntity>
  886. {
  887. Status = (int)JsonObjectStatus.Success,
  888. Data = null,
  889. Message = JsonObjectStatus.Success.GetEnumText(),
  890. BackUrl = null
  891. };
  892. }
  893. }
  894. }
  895. else
  896. {
  897. resultMsg = new BaseJson<HomeLotteryListViewEntity>
  898. {
  899. Status = (int)JsonObjectStatus.Fail,
  900. Data = null,
  901. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数EnumCode为空。",
  902. BackUrl = null
  903. };
  904. }
  905. }
  906. else
  907. {
  908. resultMsg = new BaseJson<HomeLotteryListViewEntity>
  909. {
  910. Status = (int)JsonObjectStatus.Fail,
  911. Data = null,
  912. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  913. BackUrl = null
  914. };
  915. }
  916. }
  917. else
  918. {
  919. resultMsg = new BaseJson<HomeLotteryListViewEntity>
  920. {
  921. Status = (int)JsonObjectStatus.Fail,
  922. Data = null,
  923. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  924. BackUrl = null
  925. };
  926. }
  927. }, e =>
  928. {
  929. resultMsg = new BaseJson<HomeLotteryListViewEntity>
  930. {
  931. Status = (int)JsonObjectStatus.Exception,
  932. Data = null,
  933. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  934. BackUrl = null
  935. };
  936. });
  937. return resultMsg.TryToJson().ToHttpResponseMessage();
  938. }
  939. #endregion 根据彩票枚举码获取最新一期开奖详情
  940. #region 获取开机号、试机号
  941. /// <summary>
  942. /// 获取开机号、试机号
  943. /// </summary>
  944. /// <returns></returns>
  945. [HttpPost]
  946. public HttpResponseMessage GetLotteryKJHAndSJH(LotteryKJHAndSJHArgEntity arg)
  947. {
  948. BaseJson<List<LotteryKJHAndSJHViewEntity>> resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  949. Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取开机号、试机号-GetLotteryKJHAndSJH", () =>
  950. {
  951. if (!string.IsNullOrEmpty(arg.t))
  952. {
  953. if (arg.t.CheckTimeStamp())
  954. {
  955. //TODO 加上缓存
  956. List<LotteryKJHAndSJHViewEntity> list = new List<LotteryKJHAndSJHViewEntity>();
  957. string[] enumArr = arg.EnumCode.Split("|".ToCharArray());
  958. foreach (string s in enumArr)
  959. {
  960. bool isSucc = Enum.TryParse<SCCLottery>(s, true, out SCCLottery type);
  961. //SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), arg.EnumCode, true);
  962. if (!isSucc) continue;
  963. //组装查询语句
  964. string sql = GetSeleteSQL(type, arg);
  965. //查询结果
  966. DataTable data = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
  967. if (data.Rows.Count > 0)
  968. {
  969. for (int i = 0; i < data.Rows.Count; i++)
  970. {
  971. LotteryKJHAndSJHViewEntity res = new LotteryKJHAndSJHViewEntity
  972. {
  973. EnumCode = s,
  974. Term = data.Rows[i]["Term"].ToStringEx(),
  975. Addtime = data.Rows[i]["OpenTime"].TryToDateTimeToString("yyyy-MM-dd"),
  976. KjhAndSjhItems = GetKjhAndSjhItems(data.Rows[i], type)
  977. };
  978. list.Add(res);
  979. }
  980. }
  981. }
  982. list = list.OrderByDescending(l => l.Term).ToList();
  983. resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
  984. {
  985. Status = (int)JsonObjectStatus.Success,
  986. Data = list,
  987. Message = JsonObjectStatus.Success.GetEnumText(),
  988. BackUrl = null
  989. };
  990. }
  991. else
  992. {
  993. resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
  994. {
  995. Status = (int)JsonObjectStatus.Fail,
  996. Data = null,
  997. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  998. BackUrl = null
  999. };
  1000. }
  1001. }
  1002. else
  1003. {
  1004. resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
  1005. {
  1006. Status = (int)JsonObjectStatus.Fail,
  1007. Data = null,
  1008. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  1009. BackUrl = null
  1010. };
  1011. }
  1012. }, e =>
  1013. {
  1014. resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
  1015. {
  1016. Status = (int)JsonObjectStatus.Exception,
  1017. Data = null,
  1018. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  1019. BackUrl = null
  1020. };
  1021. });
  1022. return resultMsg.TryToJson().ToHttpResponseMessage();
  1023. }
  1024. /// <summary>
  1025. /// 查询开机号、试机号
  1026. /// </summary>
  1027. /// <param name="arg"></param>
  1028. /// <returns></returns>
  1029. [HttpPost]
  1030. public HttpResponseMessage QueryLotteryKJHAndSJH(QueryLotteryKJHAndSJHArgEntity arg)
  1031. {
  1032. BaseJson<List<LotteryKJHAndSJHViewEntity>> resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  1033. Logger(typeof(LotteryNumberController), arg.TryToJson(), "查询开机号、试机号-QueryLotteryKJHAndSJH", () =>
  1034. {
  1035. if (!string.IsNullOrEmpty(arg.t))
  1036. {
  1037. if (arg.t.CheckTimeStamp())
  1038. {
  1039. //TODO 加上缓存
  1040. List<LotteryKJHAndSJHViewEntity> list = new List<LotteryKJHAndSJHViewEntity>();
  1041. bool isSucc = Enum.TryParse<SCCLottery>(arg.EnumCode, true, out SCCLottery type);
  1042. //SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), arg.EnumCode, true);
  1043. if (!isSucc)
  1044. {
  1045. resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
  1046. {
  1047. Status = (int)JsonObjectStatus.Fail,
  1048. Data = null,
  1049. Message = $"参数值{arg.EnumCode}无效。",
  1050. BackUrl = null
  1051. };
  1052. }
  1053. else
  1054. {
  1055. //组装查询语句
  1056. string sql = GetSeleteSQL(type, arg);
  1057. //查询结果
  1058. DataTable data = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
  1059. if (data.Rows.Count > 0)
  1060. {
  1061. for (int i = 0; i < data.Rows.Count; i++)
  1062. {
  1063. LotteryKJHAndSJHViewEntity res = new LotteryKJHAndSJHViewEntity
  1064. {
  1065. Term = data.Rows[i]["Term"].ToStringEx(),
  1066. Addtime = data.Rows[i]["Addtime"].ToStringEx(),
  1067. KjhAndSjhItems = GetKjhAndSjhItems(data.Rows[i], type)
  1068. };
  1069. list.Add(res);
  1070. }
  1071. }
  1072. list = list.OrderByDescending(l => l.Term).ToList();
  1073. resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
  1074. {
  1075. Status = (int)JsonObjectStatus.Success,
  1076. Data = list,
  1077. Message = JsonObjectStatus.Success.GetEnumText(),
  1078. BackUrl = null
  1079. };
  1080. }
  1081. }
  1082. else
  1083. {
  1084. resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
  1085. {
  1086. Status = (int)JsonObjectStatus.Fail,
  1087. Data = null,
  1088. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  1089. BackUrl = null
  1090. };
  1091. }
  1092. }
  1093. else
  1094. {
  1095. resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
  1096. {
  1097. Status = (int)JsonObjectStatus.Fail,
  1098. Data = null,
  1099. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  1100. BackUrl = null
  1101. };
  1102. }
  1103. }, e =>
  1104. {
  1105. resultMsg = new BaseJson<List<LotteryKJHAndSJHViewEntity>>
  1106. {
  1107. Status = (int)JsonObjectStatus.Exception,
  1108. Data = null,
  1109. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  1110. BackUrl = null
  1111. };
  1112. });
  1113. return resultMsg.TryToJson().ToHttpResponseMessage();
  1114. }
  1115. private List<LotteryBallItem> AppendKJHAndSJHBall(string sjh, SCCLottery enumCode)
  1116. {
  1117. List<LotteryBallItem> res = new List<LotteryBallItem>();
  1118. string[] sjhArr = sjh.Split(",".ToCharArray());
  1119. #region 是否需要添加0的彩种
  1120. //是否需要添加0
  1121. bool hasAppendZero = enumCode == SCCLottery.SSQ || enumCode == SCCLottery.DLT;
  1122. #endregion 是否需要添加0的彩种
  1123. //有特殊球的情况下
  1124. if (LotteryBallTypeDict.ContainsKey(enumCode.ToString()))
  1125. {
  1126. int[] codeArr = LotteryBallTypeDict[enumCode.ToString()];
  1127. //正常球个数
  1128. int normal = codeArr[0];
  1129. //蓝球个数
  1130. int blue = codeArr[1];
  1131. #region 正常球
  1132. if (normal > 0)
  1133. {
  1134. for (int i = 1; i <= normal; i++)
  1135. {
  1136. int openCode = sjhArr[i - 1].TryToInt32();
  1137. res.Add(new LotteryBallItem
  1138. {
  1139. BallType = LotteryBallType.Normal,
  1140. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  1141. });
  1142. }
  1143. }
  1144. #endregion 正常球
  1145. #region 蓝球
  1146. if (blue > 0)
  1147. {
  1148. for (int i = blue; i >= 1; i--)
  1149. {
  1150. int openCode = sjhArr[normal + i - 1].TryToInt32();
  1151. res.Add(new LotteryBallItem
  1152. {
  1153. BallType = LotteryBallType.Blue,
  1154. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  1155. });
  1156. }
  1157. }
  1158. #endregion 蓝球
  1159. }
  1160. else
  1161. {
  1162. //总共球个数
  1163. int total = enumCode.GetEnumText().TryToInt32();
  1164. for (int i = 1; i <= total; i++)
  1165. {
  1166. int openCode = sjhArr[i - 1].TryToInt32();
  1167. res.Add(new LotteryBallItem
  1168. {
  1169. BallType = LotteryBallType.Normal,
  1170. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  1171. });
  1172. }
  1173. }
  1174. return res;
  1175. }
  1176. private List<KJHAndSJHItem> GetKjhAndSjhItems(DataRow data, SCCLottery type)
  1177. {
  1178. List<KJHAndSJHItem> res = new List<KJHAndSJHItem>();
  1179. string sjh = data["ShiJiHao"].ToString();
  1180. string kjh = data["KaiJiHao"].ToString();
  1181. //开机号
  1182. if (!string.IsNullOrEmpty(kjh) && !kjh.Contains("-1"))
  1183. {
  1184. //15 17 20 24 27 33 + 11
  1185. if (kjh.Contains("+"))
  1186. {
  1187. kjh = kjh.Trim().Replace(" + ", ",").Replace(" ", ",");
  1188. }
  1189. string[] sjhArr = kjh.Split(",".ToCharArray());
  1190. List<int> code = sjhArr.Select(s => s.TryToInt32()).ToList();
  1191. KJHAndSJHItem item = new KJHAndSJHItem
  1192. {
  1193. Which = 1,
  1194. TypeName = "开机号",
  1195. LotteryBallItems = AppendKJHAndSJHBall(kjh, type),
  1196. SizeRatio = LotteryUtils.GetProportionOfDX(code, GetSizeRatioSplitNumber(type)),
  1197. ParityRatio = LotteryUtils.GetProportionOfJO(code),
  1198. SumValue = LotteryUtils.GetSum(code, GetSumNumberCount(type)).ToString()
  1199. };
  1200. res.Add(item);
  1201. }
  1202. //试机号
  1203. if (!string.IsNullOrEmpty(sjh) && !sjh.Contains("-1"))
  1204. {
  1205. if (sjh.Contains("+"))
  1206. {
  1207. sjh = sjh.Trim().Replace(" + ", ",").Replace(" ", ",");
  1208. }
  1209. string[] sjhArr = sjh.Split(",".ToCharArray());
  1210. List<int> code = sjhArr.Select(s => s.TryToInt32()).ToList();
  1211. KJHAndSJHItem item = new KJHAndSJHItem
  1212. {
  1213. Which = 2,
  1214. TypeName = "试机号",
  1215. LotteryBallItems = AppendKJHAndSJHBall(sjh, type),
  1216. SizeRatio = LotteryUtils.GetProportionOfDX(code, GetSizeRatioSplitNumber(type)),
  1217. ParityRatio = LotteryUtils.GetProportionOfJO(code),
  1218. SumValue = LotteryUtils.GetSum(code, GetSumNumberCount(type)).ToString()
  1219. };
  1220. res.Add(item);
  1221. }
  1222. //开奖号
  1223. res.Add(GetOpenCode(data, type));
  1224. return res;
  1225. }
  1226. private KJHAndSJHItem GetOpenCode(DataRow data, SCCLottery type)
  1227. {
  1228. //枚举码
  1229. string enumCode = type.ToString();
  1230. List<LotteryBallItem> ballItems = new List<LotteryBallItem>();
  1231. //总共球个数
  1232. int total = type.GetEnumText().TryToInt32();
  1233. //有特殊球的情况下
  1234. if (LotteryBallTypeDict.ContainsKey(enumCode))
  1235. {
  1236. GetOpenCodeValue(data, enumCode, out ballItems);
  1237. }
  1238. else
  1239. {
  1240. #region 是否需要添加0的彩种
  1241. //是否需要添加0
  1242. bool hasAppendZero = type == SCCLottery.SSQ || type == SCCLottery.DLT;
  1243. #endregion 是否需要添加0的彩种
  1244. for (int i = 1; i <= total; i++)
  1245. {
  1246. int openCode = data["OpenCode" + i].TryToInt32();
  1247. ballItems.Add(new LotteryBallItem
  1248. {
  1249. //山东快乐扑克3为特殊球
  1250. BallType = type == SCCLottery.ShanDongKLPK3 ? LotteryBallType.Poker : LotteryBallType.Normal,
  1251. OpenCode = hasAppendZero ? openCode.RepairZero() : openCode.ToString()
  1252. });
  1253. }
  1254. }
  1255. List<int> openCodeList = new List<int>();
  1256. for (int i = 1; i <= total; i++)
  1257. {
  1258. int openCode = data["OpenCode" + i].TryToInt32();
  1259. openCodeList.Add(openCode);
  1260. }
  1261. KJHAndSJHItem itemOpencode = new KJHAndSJHItem
  1262. {
  1263. Which = 3,
  1264. TypeName = "开奖号",
  1265. LotteryBallItems = ballItems,
  1266. SizeRatio = LotteryUtils.GetProportionOfDX(openCodeList, GetSizeRatioSplitNumber(type)),
  1267. ParityRatio = LotteryUtils.GetProportionOfJO(openCodeList),
  1268. SumValue = LotteryUtils.GetSum(openCodeList, GetSumNumberCount(type)).ToString()
  1269. };
  1270. return itemOpencode;
  1271. }
  1272. #endregion 获取开机号、试机号
  1273. /// <summary>
  1274. /// 获取彩种id
  1275. /// </summary>
  1276. /// <param name="EnumCode"></param>
  1277. /// <returns></returns>
  1278. private int GetCid(string EnumCode)
  1279. {
  1280. Enum.TryParse<SCCLottery>(EnumCode, true, out SCCLottery type);
  1281. var Cid = type.GetCid();
  1282. return Cid;
  1283. }
  1284. #region 首页获取各分类的推荐彩种以及开奖信息
  1285. /// <summary>
  1286. /// 获取各分类的推荐彩种以及开奖信息
  1287. /// </summary>
  1288. /// <param name="arg"></param>
  1289. /// <returns></returns>
  1290. [HttpPost]
  1291. public HttpResponseMessage GetRecommendLotteryAndAwardInformation(BaseParameterEntity arg)
  1292. {
  1293. BaseJson<List<LotteryRecommendViewEntity>> resultMsg = new BaseJson<List<LotteryRecommendViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  1294. Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取各分类的推荐彩种以及开奖信息-GetRecommendLotteryAndAwardInformation", () =>
  1295. {
  1296. if (!string.IsNullOrEmpty(arg.t))
  1297. {
  1298. if (arg.t.CheckTimeStamp())
  1299. {
  1300. var Lottery = new List<LotteryRecommendViewEntity>();
  1301. //var Lottery = Cache.Factory.CacheFactory.Cache().GetCache<List<LotteryRecommendViewEntity>>("__RecommendLottery");
  1302. //if (Lottery == null)
  1303. //{
  1304. string codeList = GetCodeList();
  1305. //获取所有推荐的彩种
  1306. List<DataItemModel> LotteryList = dataItemCache.GetDataItemList().Where(o => o.IsRecommend).OrderBy(d => d.SortCode ?? 0).ToList();
  1307. //获取类型码-枚举码字典
  1308. Dictionary<string, SCCLottery> dictionary = GetTypeCodeAndEnumCodeDict(LotteryList, false, true, false, "");
  1309. //结果集合
  1310. List<HomeLotteryListViewEntity> res = GetRealData(dictionary);
  1311. //获取所有推荐彩种以及对应的信息 开奖号,期数,奖池
  1312. List<LotteryItem> cache = res.Select(o =>
  1313. new LotteryItem
  1314. {
  1315. TypeName = o.TypeCode.Substring(0, 3),
  1316. Name = o.LotteryName,
  1317. Cid = GetCid(o.EnumCode),
  1318. EnumCode = o.EnumCode,
  1319. PeriodsNum = o.CurrentTerm,
  1320. Date = o.CurrentOpenTime,
  1321. Spare = o.Spare,
  1322. LotteryBallItems = o.LotteryBallItems
  1323. }
  1324. ).ToList();
  1325. ///彩种分类后的信息
  1326. Lottery = cache.GroupBy(o => o.TypeName).Select(o => new LotteryRecommendViewEntity
  1327. {
  1328. LotteryType = o.Key,
  1329. LotteryItems = o.ToList().Count() < 7 ? o.ToList() : o.Take(6).ToList(),
  1330. }).ToList();
  1331. // Cache.Factory.CacheFactory.Cache().WriteCache<List<LotteryRecommendViewEntity>>(Lottery, "__RecommendLottery", DateTime.Now.AddMinutes(10));
  1332. //}
  1333. resultMsg = new BaseJson<List<LotteryRecommendViewEntity>>
  1334. {
  1335. Status = (int)JsonObjectStatus.Success,
  1336. Data = Lottery,
  1337. Message = JsonObjectStatus.Success.GetEnumText(),
  1338. BackUrl = null
  1339. };
  1340. }
  1341. else
  1342. {
  1343. resultMsg = new BaseJson<List<LotteryRecommendViewEntity>>
  1344. {
  1345. Status = (int)JsonObjectStatus.Fail,
  1346. Data = null,
  1347. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  1348. BackUrl = null
  1349. };
  1350. }
  1351. }
  1352. else
  1353. {
  1354. resultMsg = new BaseJson<List<LotteryRecommendViewEntity>>
  1355. {
  1356. Status = (int)JsonObjectStatus.Fail,
  1357. Data = null,
  1358. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  1359. BackUrl = null
  1360. };
  1361. }
  1362. }, e =>
  1363. {
  1364. resultMsg = new BaseJson<List<LotteryRecommendViewEntity>>
  1365. {
  1366. Status = (int)JsonObjectStatus.Exception,
  1367. Data = null,
  1368. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  1369. BackUrl = null
  1370. };
  1371. });
  1372. return resultMsg.TryToJson().ToHttpResponseMessage();
  1373. }
  1374. #endregion
  1375. #region 获取最新一期的开机号、试机号(双色球、排列三、大乐透、福彩3D)
  1376. /// <summary>
  1377. /// 获取开机号、试机号(双色球、排列三、大乐透,福彩3D)
  1378. /// TotalRecord若为空则查询最近一期的数据,若有就查询多少条
  1379. /// </summary>
  1380. /// <returns></returns>
  1381. [HttpPost]
  1382. public HttpResponseMessage GetThisLotteryKJHAndSJH(LotteryKJHAndSJHArgEntity arg)
  1383. {
  1384. BaseJson<List<KJH_SJHItem>> resultMsg = new BaseJson<List<KJH_SJHItem>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  1385. Logger(typeof(LotteryNumberController), arg.TryToJson(), " 获取开机号、试机号(双色球、排列三、大乐透、福彩3D)-GetThisLotteryKJHAndSJH", () =>
  1386. {
  1387. if (!string.IsNullOrEmpty(arg.t))
  1388. {
  1389. if (arg.t.CheckTimeStamp())
  1390. {
  1391. //因为只需要最近一期的试机号开奖号,所以给默认赋值1
  1392. arg.TotalRecord = arg.TotalRecord == 0 ? 1 : arg.TotalRecord;
  1393. List<KJH_SJHItem> list = new List<KJH_SJHItem>();
  1394. string[] enumArr = { SCCLottery.SSQ.ToString(), SCCLottery.PL3.ToString(), SCCLottery.DLT.ToString(), SCCLottery.FC3D.ToString() };
  1395. foreach (string s in enumArr)
  1396. {
  1397. bool isSucc = Enum.TryParse<SCCLottery>(s, true, out SCCLottery type);
  1398. if (!isSucc) continue;
  1399. //组装查询语句
  1400. string sql = GetSeleteSQL(type, arg);
  1401. //查询结果
  1402. DataTable data = commonBll.ExcuteSqlDataTable(sql, DatabaseLinksEnum.LotteryNumber, null);
  1403. if (data.Rows.Count > 0)
  1404. {
  1405. for (int i = 0; i < data.Rows.Count; i++)
  1406. {
  1407. var Term = data.Rows[i]["Term"].ToStringEx();
  1408. var kjh_sjh = GetKjhAndSjhItems(data.Rows[i], type).Where(o => o.Which != 3);
  1409. foreach (var kjhitem in kjh_sjh)
  1410. {
  1411. KJH_SJHItem item = new KJH_SJHItem();
  1412. item.LotteryBallItems = kjhitem.LotteryBallItems;
  1413. item.Which = kjhitem.Which;
  1414. item.Term = Term;
  1415. item.
  1416. EnumCode = s;
  1417. item.LotteryName = type.GetEnumDescription();
  1418. list.Add(item);
  1419. }
  1420. }
  1421. }
  1422. }
  1423. list = list.OrderByDescending(l => l.Term).ToList();
  1424. resultMsg = new BaseJson<List<KJH_SJHItem>>
  1425. {
  1426. Status = (int)JsonObjectStatus.Success,
  1427. Data = list,
  1428. Message = JsonObjectStatus.Success.GetEnumText(),
  1429. BackUrl = null
  1430. };
  1431. }
  1432. else
  1433. {
  1434. resultMsg = new BaseJson<List<KJH_SJHItem>>
  1435. {
  1436. Status = (int)JsonObjectStatus.Fail,
  1437. Data = null,
  1438. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  1439. BackUrl = null
  1440. };
  1441. }
  1442. }
  1443. else
  1444. {
  1445. resultMsg = new BaseJson<List<KJH_SJHItem>>
  1446. {
  1447. Status = (int)JsonObjectStatus.Fail,
  1448. Data = null,
  1449. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  1450. BackUrl = null
  1451. };
  1452. }
  1453. }, e =>
  1454. {
  1455. resultMsg = new BaseJson<List<KJH_SJHItem>>
  1456. {
  1457. Status = (int)JsonObjectStatus.Exception,
  1458. Data = null,
  1459. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  1460. BackUrl = null
  1461. };
  1462. });
  1463. return resultMsg.TryToJson().ToHttpResponseMessage();
  1464. }
  1465. #endregion
  1466. #region 获取最新一期地方彩的开奖信息
  1467. /// <summary>
  1468. /// 获取地方彩今日开奖信息
  1469. /// </summary>
  1470. /// <param name="arg"></param>
  1471. /// <returns></returns>
  1472. [HttpPost]
  1473. public HttpResponseMessage GetDFCLotteryAwardInfo(BaseParameterEntity arg)
  1474. {
  1475. BaseJson<List<TodaysLotteryViewEntity>> resultMsg = new BaseJson<List<TodaysLotteryViewEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  1476. Logger(typeof(LotteryNumberController), arg.TryToJson(), "获取最新一期地方彩的开奖信息-GetDFCLotteryAwardInfo", () =>
  1477. {
  1478. if (!string.IsNullOrEmpty(arg.t))
  1479. {
  1480. if (arg.t.CheckTimeStamp())
  1481. {
  1482. // var Lottery = Cache.Factory.CacheFactory.Cache().GetCache<List<TodaysLotteryViewEntity>>("__DFCRecommendLottery");
  1483. var Lottery = webCache.GetObject<List<TodaysLotteryViewEntity>>("__DFCRecommendLottery");
  1484. if (Lottery == null)
  1485. {
  1486. Dictionary<string, SCCConfig> dict = GetTodayLotteryDict();
  1487. List<TodaysLotteryViewEntity> obj = new List<TodaysLotteryViewEntity>();
  1488. foreach (KeyValuePair<string, SCCConfig> pair in dict)
  1489. {
  1490. SCCConfig config = pair.Value;
  1491. SCCLottery type = (SCCLottery)Enum.Parse(typeof(SCCLottery), config.EnumCode, true);
  1492. //当前彩种今天真实开始开奖时间
  1493. DateTime todayRealStartOpentime = (DateTimeHelper.Now.ToString("yyyy-MM-dd") + " " + config.StartHour + ":" + config.StartMinute).TryToDateTime();
  1494. ////如果当前时间大于当前彩种今天真实开始开奖时间,则忽略
  1495. //if (DateTimeHelper.Now < todayRealStartOpentime)
  1496. //{
  1497. string lastTerm = qgfc3Dbll.GetNewTermByTableName(type.GetSCCLotteryTableName());
  1498. obj.Add(new TodaysLotteryViewEntity
  1499. {
  1500. KJRate = config.KJRate,
  1501. LotteryName = config.LotteryName,
  1502. CurrentTerm = lastTerm,
  1503. OpenTime = todayRealStartOpentime,
  1504. MainUrl = config.MainUrl,
  1505. EnumCode = config.EnumCode,
  1506. Cid = GetCid(config.EnumCode),
  1507. });
  1508. //}
  1509. }
  1510. Lottery = obj.OrderBy(o => o.OpenTime).ToList();
  1511. //Cache.Factory.CacheFactory.Cache().WriteCache<List<TodaysLotteryViewEntity>>(Lottery, "__DFCRecommendLottery", DateTime.Now.AddHours(1));
  1512. webCache.AddObject("__DFCRecommendLottery", Lottery, (int)CacheTime.Data);
  1513. }
  1514. resultMsg = new BaseJson<List<TodaysLotteryViewEntity>>
  1515. {
  1516. Status = (int)JsonObjectStatus.Success,
  1517. Data = Lottery,
  1518. Message = JsonObjectStatus.Success.GetEnumText(),
  1519. BackUrl = null
  1520. };
  1521. }
  1522. else
  1523. {
  1524. resultMsg = new BaseJson<List<TodaysLotteryViewEntity>>
  1525. {
  1526. Status = (int)JsonObjectStatus.Fail,
  1527. Data = null,
  1528. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  1529. BackUrl = null
  1530. };
  1531. }
  1532. }
  1533. else
  1534. {
  1535. resultMsg = new BaseJson<List<TodaysLotteryViewEntity>>
  1536. {
  1537. Status = (int)JsonObjectStatus.Fail,
  1538. Data = null,
  1539. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  1540. BackUrl = null
  1541. };
  1542. }
  1543. }, e =>
  1544. {
  1545. resultMsg = new BaseJson<List<TodaysLotteryViewEntity>>
  1546. {
  1547. Status = (int)JsonObjectStatus.Exception,
  1548. Data = null,
  1549. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  1550. BackUrl = null
  1551. };
  1552. });
  1553. return resultMsg.TryToJson().ToHttpResponseMessage();
  1554. }
  1555. /// <summary>
  1556. /// 获取今日开奖彩种
  1557. /// </summary>
  1558. /// <returns></returns>
  1559. private static Dictionary<string, SCCConfig> GetTodayLotteryDict()
  1560. {
  1561. Dictionary<string, SCCConfig> dictionary = new Dictionary<string, SCCConfig>();
  1562. //当前时间
  1563. DateTime now = DateTimeHelper.Now;
  1564. //今天是星期几
  1565. string week = now.DayOfWeek.ToString("d");
  1566. //获取当前彩种配置信息(全国彩和地方彩) || s.Name.Contains("QGC_")
  1567. List<SCCConfig> configList = LotteryConfig.Where(s => s.Name.Contains("DFC_")).OrderBy(s => s.LotteryName.Length).ToList();
  1568. foreach (SCCConfig config in configList)
  1569. {
  1570. //当前彩种每周开奖时间
  1571. string[] openThePrizeOnTheDayOfTheWeek = config.KJTime.Split(",".ToCharArray());
  1572. //今天星期在数组中的索引
  1573. int pointer = Array.IndexOf(openThePrizeOnTheDayOfTheWeek, week.ToString());
  1574. if (pointer != -1)//今天要开奖
  1575. {
  1576. if (!dictionary.ContainsKey(config.EnumCode))
  1577. {
  1578. dictionary.Add(config.EnumCode, config);
  1579. }
  1580. }
  1581. }
  1582. return dictionary;
  1583. }
  1584. #endregion
  1585. #region 首页新闻滚动展示
  1586. /// <summary>
  1587. /// 首页新闻滚动展示内容
  1588. /// </summary>
  1589. /// <param name="arg"></param>
  1590. /// <returns></returns>
  1591. [HttpPost]
  1592. public HttpResponseMessage GetNewsInfo(BannerParameterArgEntity arg)
  1593. {
  1594. BaseJson<List<BannerEntity>> resultMsg = new BaseJson<List<BannerEntity>> { Status = (int)JsonObjectStatus.Error, Message = "服务器未知错误。", Data = null };
  1595. Logger(typeof(LotteryNumberController), arg.TryToJson(), "首页新闻滚动展示-GetNewsInfo", () =>
  1596. {
  1597. if (!string.IsNullOrEmpty(arg.t))
  1598. {
  1599. if (arg.t.CheckTimeStamp())
  1600. {
  1601. //var Lottery = Cache.Factory.CacheFactory.Cache().GetCache<List<BannerEntity>>("__NewsInfo");
  1602. var Lottery = webCache.GetObject<List<BannerEntity>>("__NewsInfo");
  1603. if (Lottery == null)
  1604. {
  1605. Lottery = bannerBLL.GetList("").ToList().Take(arg.TotolCount).Select(o => new BannerEntity { Id = o.Id, Title = o.Title, ImageUrl = o.ImageUrl, Content = o.Content }).ToList();
  1606. //Cache.Factory.CacheFactory.Cache().WriteCache<List<BannerEntity>>(Lottery, "__NewsInfo", DateTime.Now.AddHours(1));
  1607. webCache.AddObject("__NewsInfo", Lottery, (int)CacheTime.Data);
  1608. }
  1609. resultMsg = new BaseJson<List<BannerEntity>>
  1610. {
  1611. Status = (int)JsonObjectStatus.Success,
  1612. Data = Lottery,
  1613. Message = JsonObjectStatus.Success.GetEnumText(),
  1614. BackUrl = null
  1615. };
  1616. }
  1617. else
  1618. {
  1619. resultMsg = new BaseJson<List<BannerEntity>>
  1620. {
  1621. Status = (int)JsonObjectStatus.Fail,
  1622. Data = null,
  1623. Message = JsonObjectStatus.Fail.GetEnumText() + ",无效参数。",
  1624. BackUrl = null
  1625. };
  1626. }
  1627. }
  1628. else
  1629. {
  1630. resultMsg = new BaseJson<List<BannerEntity>>
  1631. {
  1632. Status = (int)JsonObjectStatus.Fail,
  1633. Data = null,
  1634. Message = JsonObjectStatus.Fail.GetEnumText() + ",请求参数为空。",
  1635. BackUrl = null
  1636. };
  1637. }
  1638. }, e =>
  1639. {
  1640. resultMsg = new BaseJson<List<BannerEntity>>
  1641. {
  1642. Status = (int)JsonObjectStatus.Exception,
  1643. Data = null,
  1644. Message = JsonObjectStatus.Exception.GetEnumText() + ",异常信息:" + e.Message,
  1645. BackUrl = null
  1646. };
  1647. });
  1648. return resultMsg.TryToJson().ToHttpResponseMessage();
  1649. }
  1650. #endregion
  1651. #region 公共私有方法
  1652. /// <summary>
  1653. /// 组装查询语句
  1654. /// </summary>
  1655. /// <param name="type">枚举码</param>
  1656. /// <returns></returns>
  1657. private string GetSeleteSQL(SCCLottery type)
  1658. {
  1659. //string res = Cache.Factory.CacheFactory.Cache().GetCache<string>(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString());
  1660. string res=webCache.GetObject<string>(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString());
  1661. if (string.IsNullOrEmpty(res))
  1662. {
  1663. StringBuilder builder = new StringBuilder();
  1664. int total = type.GetEnumText().TryToInt32();
  1665. string tableName = type.GetSCCLotteryTableName();
  1666. for (int i = 1; i <= total; i++)
  1667. {
  1668. builder.Append("[OpenCode" + i + "],");
  1669. }
  1670. res = string.Format(GetLotterySqlByTableName, StringHelper.DelLastChar(builder.ToString(), ","), tableName);
  1671. //存入缓存
  1672. //Cache.Factory.CacheFactory.Cache().WriteCache(res, CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString(), DateTimeHelper.Now.AddDays(30));
  1673. webCache.AddObject(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString(), res, (int)CacheTime.Data);
  1674. }
  1675. return res;
  1676. }
  1677. /// <summary>
  1678. /// 若是开奖号为-1的情况
  1679. /// </summary>
  1680. /// <param name="type"></param>
  1681. /// <param name="again"></param>
  1682. /// <returns></returns>
  1683. private string GetSeleteSQL(SCCLottery type,bool again)
  1684. {
  1685. // string res = Cache.Factory.CacheFactory.Cache().GetCache<string>(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString());
  1686. string res = webCache.GetObject<string>(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString());
  1687. if (string.IsNullOrEmpty(res))
  1688. {
  1689. StringBuilder builder = new StringBuilder();
  1690. int total = type.GetEnumText().TryToInt32();
  1691. string tableName = type.GetSCCLotteryTableName();
  1692. for (int i = 1; i <= total; i++)
  1693. {
  1694. builder.Append("[OpenCode" + i + "],");
  1695. }
  1696. res = string.Format(GetLotterySqlAgainByTableName, StringHelper.DelLastChar(builder.ToString(), ","), tableName);
  1697. //存入缓存
  1698. //Cache.Factory.CacheFactory.Cache().WriteCache(res, CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString(), DateTimeHelper.Now.AddDays(30));
  1699. webCache.AddObject(CacheKeyEnum.QueryNewestLotteryDataSQLByTableName.ToString() + "_" + type.ToString(), res, (int)CacheTime.Data);
  1700. }
  1701. return res;
  1702. }
  1703. /// <summary>
  1704. /// 组装查询语句
  1705. /// </summary>
  1706. /// <param name="type">枚举码</param>
  1707. /// <param name="term">期数</param>
  1708. /// <returns></returns>
  1709. private string GetSeleteSQL(SCCLottery type, string term)
  1710. {
  1711. StringBuilder builder = new StringBuilder();
  1712. int total = type.GetEnumText().TryToInt32();
  1713. string tableName = type.GetSCCLotteryTableName();
  1714. for (int i = 1; i <= total; i++)
  1715. {
  1716. builder.Append("[OpenCode" + i + "],");
  1717. }
  1718. string res = string.Format(GetLotterySqlByTerm, StringHelper.DelLastChar(builder.ToString(), ","), tableName, term);
  1719. return res;
  1720. }
  1721. /// <summary>
  1722. /// 组装查询语句
  1723. /// </summary>
  1724. /// <param name="type">枚举码</param>
  1725. /// <param name="arg"></param>
  1726. /// <returns></returns>
  1727. private string GetSeleteSQL(SCCLottery type, LotteryKJHAndSJHArgEntity arg)
  1728. {
  1729. string res = String.Empty;
  1730. string tableName = type.GetSCCLotteryTableName();
  1731. StringBuilder builder = new StringBuilder();
  1732. int total = type.GetEnumText().TryToInt32();
  1733. for (int i = 1; i <= total; i++)
  1734. {
  1735. builder.Append("[OpenCode" + i + "],");
  1736. }
  1737. if (arg.TotalRecord > 0)
  1738. {
  1739. if (!string.IsNullOrEmpty(arg.StartTime))
  1740. {
  1741. string time = arg.StartTime.CheckDateTime()
  1742. ? arg.StartTime
  1743. : DateTimeHelper.Now.AddDays(-7).ToString("yyyy-MM-dd");
  1744. res = string.Format(GetLotterySqlByTableNameWithStartTimeAndTop, tableName, time, StringHelper.DelLastChar(builder.ToString(), ","), arg.TotalRecord);
  1745. }
  1746. else
  1747. {
  1748. res = string.Format(GetLotterySqlByTableNameWithTop, arg.TotalRecord, tableName, StringHelper.DelLastChar(builder.ToString(), ","));
  1749. }
  1750. }
  1751. else if (!string.IsNullOrEmpty(arg.StartTime))
  1752. {
  1753. string time = arg.StartTime.CheckDateTime()
  1754. ? arg.StartTime
  1755. : DateTimeHelper.Now.AddDays(-7).ToString("yyyy-MM-dd");
  1756. res = string.Format(GetLotterySqlByTableNameWithStartTime, tableName, time, StringHelper.DelLastChar(builder.ToString(), ","));
  1757. }
  1758. else
  1759. {
  1760. res = string.Format(GetLotterySqlByTableNameWithTop, "20", tableName, StringHelper.DelLastChar(builder.ToString(), ","));
  1761. }
  1762. return res;
  1763. }
  1764. /// <summary>
  1765. /// 组装查询语句
  1766. /// </summary>
  1767. /// <param name="type">枚举码</param>
  1768. /// <param name="arg"></param>
  1769. /// <returns></returns>
  1770. private string GetSeleteSQL(SCCLottery type, QueryLotteryKJHAndSJHArgEntity arg)
  1771. {
  1772. string res = String.Empty;
  1773. string sql = "SELECT {3} [ID],[Term],[ShiJiHao],[KaiJiHao],[Addtime],{0} FROM [dbo].[{1}] WHERE [Term] = {2} ORDER BY Term DESC";
  1774. string tableName = type.GetSCCLotteryTableName();
  1775. StringBuilder builder = new StringBuilder();
  1776. int total = type.GetEnumText().TryToInt32();
  1777. for (int i = 1; i <= total; i++)
  1778. {
  1779. builder.Append("[OpenCode" + i + "],");
  1780. }
  1781. if (!string.IsNullOrEmpty(arg.Term))
  1782. {
  1783. res = string.Format(sql, StringHelper.DelLastChar(builder.ToString(), ","), tableName, arg.Term, "");
  1784. }
  1785. else if (!string.IsNullOrEmpty(arg.Year))
  1786. {
  1787. int.TryParse(arg.Year, out int year);
  1788. year = year == 0 ? DateTime.Now.Year : year <= DateTime.Now.Year ? year : DateTime.Now.Year;
  1789. sql = "SELECT TOP {3} [ID],[Term],[ShiJiHao],[KaiJiHao],[Addtime],{0} FROM [dbo].[{1}] WHERE [OpenTime] LIKE '%{2}%' ORDER BY Term DESC";
  1790. res = string.Format(sql, StringHelper.DelLastChar(builder.ToString(), ","), tableName, year.ToString(), arg.TotalRecord == 0 ? 30 : arg.TotalRecord);
  1791. }
  1792. else if (!string.IsNullOrEmpty(arg.StartTerm) && !string.IsNullOrEmpty(arg.EndTerm))
  1793. {
  1794. long start = arg.StartTerm.TryToInt64();
  1795. long end = arg.EndTerm.TryToInt64();
  1796. sql = "SELECT [ID],[Term],[ShiJiHao],[KaiJiHao],[Addtime],{0} FROM [dbo].[{1}] WHERE Term BETWEEN {2} AND {3} ORDER BY Term DESC";
  1797. if (start <= end)
  1798. {
  1799. //WHERE Term BETWEEN 2018064 AND 2018067
  1800. res = string.Format(sql, StringHelper.DelLastChar(builder.ToString(), ","), tableName, start, end);
  1801. }
  1802. else
  1803. {
  1804. res = string.Format(sql, StringHelper.DelLastChar(builder.ToString(), ","), tableName, end, start);
  1805. }
  1806. }
  1807. return res;
  1808. }
  1809. #endregion 公共私有方法
  1810. #region SQL语句
  1811. /// <summary>
  1812. /// 通过表名查询数据为校验后的最新一条数据
  1813. /// </summary>
  1814. private static string GetLotterySqlByTableName = @"SELECT TOP 1 [ID],[Term],[OpenTime],[Spare],{0} FROM [dbo].[{1}] ORDER BY Term DESC ";//WHERE [IsChecked] = 1 AND [IsPassed] = 1
  1815. /// <summary>
  1816. /// 查询最新两天数据
  1817. /// </summary>
  1818. private static string GetLotterySqlAgainByTableName = @"SELECT TOP 2 [ID],[Term],[OpenTime],[Spare],{0} FROM [dbo].[{1}] ORDER BY Term DESC WHERE [OpenCode1] != -1";
  1819. /// <summary>
  1820. /// 通过开奖时间查询数据为校验后的所有数据
  1821. /// </summary>
  1822. private static string GetLotterySqlByTableNameWithStartTime = @"SELECT [ID],[Term],[ShiJiHao],[KaiJiHao],[OpenTime],{2} FROM [dbo].[{0}] WHERE DATEDIFF(DAY,'{1}',OpenTime) >= 0 ORDER BY Term DESC";
  1823. /// <summary>
  1824. /// 通过开奖时间查询数据为校验后的所有数据
  1825. /// </summary>
  1826. private static string GetLotterySqlByTableNameWithStartTimeAndTop = @"SELECT TOP {3} [ID],[Term],[ShiJiHao],[KaiJiHao],[OpenTime],{2} FROM [dbo].[{0}] WHERE DATEDIFF(DAY,'{1}',OpenTime) >= 0 ORDER BY Term DESC";
  1827. /// <summary>
  1828. /// 通过表名查询数据为校验后的前n行数据
  1829. /// </summary>
  1830. private static string GetLotterySqlByTableNameWithTop = @"SELECT TOP {0} [ID],[Term],[ShiJiHao],[KaiJiHao],[OpenTime],{2} FROM [dbo].[{1}] ORDER BY Term DESC ";
  1831. /// <summary>
  1832. /// 通过期数查询数据为校验后的一条数据
  1833. /// </summary>
  1834. private static string GetLotterySqlByTerm = @"SELECT [ID],[Term],[OpenTime],[Spare],{0} FROM [dbo].[{1}] WHERE [Term]='{2}'";//[IsChecked] = 1 AND [IsPassed] = 1 AND
  1835. #endregion SQL语句
  1836. }
  1837. }