You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HKCore.cs 9.9 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using HandyControl.Controls;
  2. using HKCardOUT.Helper;
  3. using HKCardOUT.Logic.Model;
  4. using HKControl;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using UHFHelper;
  11. using XExten.Advance.LinqFramework;
  12. namespace HKCardOUT.Logic.Service
  13. {
  14. public class HKCore
  15. {
  16. List<SaleLog> Commom(SaleLog input)
  17. {
  18. if (DataBus.StartDevice)
  19. if (!Main.GetInstance.GetIsSwipe(input.Location.AsInt())) return null;
  20. var Old = DbContext.Context.Queryable<SaleLog>()
  21. .Where(t => t.CardNo == input.CardNo)
  22. .Where(t => t.CreateTime.Year == DateTime.Now.Year)
  23. .Where(t => t.CreateTime.Month == DateTime.Now.Month)
  24. .Where(t => t.CreateTime.Day == DateTime.Now.Day).ToList();
  25. if (DataBus.Cancel)
  26. if (Old.Count > 3) return null;
  27. return Old;
  28. }
  29. bool GetCardStutas(string CardNo)
  30. {
  31. var data = DbContext.Context.Queryable<CardStutas>().First(t => t.CardNo == CardNo);
  32. if (data == null) return false;
  33. if (data.Stutas != 1) return false;
  34. return true;
  35. }
  36. public static void AddCard(List<CardStutas> input)
  37. {
  38. DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteCommand();
  39. }
  40. /// <summary>
  41. /// 早上消费
  42. /// </summary>
  43. /// <param name="input"></param>
  44. /// <returns></returns>
  45. public bool DeviceSaleAM(SaleLog input)
  46. {
  47. try
  48. {
  49. if(!GetCardStutas(input.CardNo)) return false;
  50. var Old = Commom(input);
  51. if (Old == null) return false;
  52. var AMDay = Old.Where(t => t.CreateTime >= DataBus.Times.ATStartTime && t.CreateTime < DataBus.Times.AMEndTime)
  53. .Where(t => t.CreateTime.Year == DateTime.Now.Year)
  54. .Where(t => t.CreateTime.Month == DateTime.Now.Month)
  55. .Where(t => t.CreateTime.Day == DateTime.Now.Day)
  56. .Count();
  57. HKLog.HKLogImport.WriteInfo($"卡号{input.CardNo}上午消费次数:{AMDay}");
  58. if (AMDay < DataBus.Count)
  59. {
  60. var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
  61. if (entity.Id != Guid.Empty)
  62. {
  63. ////有网络直接同步
  64. //if (DataBus.NetWordState)
  65. //{
  66. // //先出餐后推数据
  67. // if (DataBus.StartDevice)
  68. // {
  69. // Main.GetInstance.Start(input.Location.AsInt());
  70. // UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
  71. // }
  72. // var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
  73. // if (res)
  74. // DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
  75. // return res;
  76. //}
  77. //else
  78. //{
  79. //}
  80. if (DataBus.StartDevice)
  81. {
  82. Main.GetInstance.Start(input.Location.AsInt());
  83. UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
  84. }
  85. return true;
  86. }
  87. }
  88. return false;
  89. }
  90. catch (Exception ex)
  91. {
  92. HKLog.HKLogImport.WriteError(ex);
  93. return false;
  94. }
  95. }
  96. /// <summary>
  97. /// 中午消费
  98. /// </summary>
  99. /// <param name="input"></param>
  100. /// <param name="Old"></param>
  101. /// <returns></returns>
  102. public bool DeviceSalePM(SaleLog input)
  103. {
  104. try
  105. {
  106. if (!GetCardStutas(input.CardNo)) return false;
  107. var Old = Commom(input);
  108. if (Old == null) return false;
  109. var PMDay = Old.Where(t => t.CreateTime >= DataBus.Times.PMStartTime && t.CreateTime < DataBus.Times.PMEndTime).
  110. Where(t => t.CreateTime.Year == DateTime.Now.Year)
  111. .Where(t => t.CreateTime.Month == DateTime.Now.Month)
  112. .Where(t => t.CreateTime.Day == DateTime.Now.Day)
  113. .Count();
  114. HKLog.HKLogImport.WriteInfo($"卡号{input.CardNo}中午消费次数:{PMDay}");
  115. if (PMDay < DataBus.Count)
  116. {
  117. var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
  118. if (entity.Id != Guid.Empty)
  119. {
  120. ////有网络直接同步
  121. //if (DataBus.NetWordState)
  122. //{
  123. // //先出餐后推数据
  124. // if (DataBus.StartDevice)
  125. // {
  126. // Main.GetInstance.Start(input.Location.AsInt());
  127. // UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
  128. // }
  129. // var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
  130. // if (res)
  131. // DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
  132. // return res;
  133. //}
  134. //else
  135. //{
  136. if (DataBus.StartDevice)
  137. {
  138. Main.GetInstance.Start(input.Location.AsInt());
  139. UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
  140. }
  141. return true;
  142. //}
  143. }
  144. }
  145. return false;
  146. }
  147. catch (Exception ex)
  148. {
  149. HKLog.HKLogImport.WriteError(ex);
  150. return false;
  151. }
  152. }
  153. /// <summary>
  154. /// 晚上
  155. /// </summary>
  156. /// <param name="input"></param>
  157. /// <param name="Old"></param>
  158. /// <returns></returns>
  159. public bool DeviceSaleAT(SaleLog input)
  160. {
  161. try
  162. {
  163. if (!GetCardStutas(input.CardNo)) return false;
  164. var Old = Commom(input);
  165. if (Old == null) return false;
  166. var ATDay = Old.Where(t => t.CreateTime >= DataBus.Times.ATStartTime && t.CreateTime < DataBus.Times.ATEndTime)
  167. .Where(t => t.CreateTime.Year == DateTime.Now.Year)
  168. .Where(t => t.CreateTime.Month == DateTime.Now.Month)
  169. .Where(t => t.CreateTime.Day == DateTime.Now.Day)
  170. .Count();
  171. HKLog.HKLogImport.WriteInfo($"卡号{input.CardNo}下午消费次数:{ATDay}");
  172. if (ATDay < DataBus.Count)
  173. {
  174. var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
  175. if (entity.Id != Guid.Empty)
  176. {
  177. ////有网络直接同步
  178. //if (DataBus.NetWordState)
  179. //{
  180. // //先出餐后推数据
  181. // if (DataBus.StartDevice)
  182. // {
  183. // Main.GetInstance.Start(input.Location.AsInt());
  184. // UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
  185. // }
  186. // var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
  187. // if (res)
  188. // DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
  189. // return res;
  190. //}
  191. //else
  192. //{
  193. if (DataBus.StartDevice)
  194. {
  195. Main.GetInstance.Start(input.Location.AsInt());
  196. UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt());
  197. }
  198. return true;
  199. //}
  200. }
  201. }
  202. return false;
  203. }
  204. catch (Exception ex)
  205. {
  206. HKLog.HKLogImport.WriteError(ex);
  207. return false;
  208. }
  209. }
  210. /// <summary>
  211. /// 获取当天消费前100条展示
  212. /// </summary>
  213. /// <returns></returns>
  214. public List<SaleLog> PullDaySaleLog()
  215. {
  216. var Begin = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
  217. var End = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  218. var data = DbContext.Context.Queryable<SaleLog>()
  219. .Where(t => t.CreateTime >= Begin)
  220. .Where(t => t.CreateTime < End)
  221. .OrderByDescending(t => t.CreateTime).ToPageList(0, 100);
  222. return data.GroupBy(t => t.CardNo).Select(t => new SaleLog
  223. {
  224. CardNo = t.Key,
  225. Location = String.Join(",", t.Select(m => m.Location)),
  226. Count = t.Count()
  227. }).ToList();
  228. }
  229. }
  230. }