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 3.5 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 XExten.Advance.LinqFramework;
  11. namespace HKCardOUT.Logic.Service
  12. {
  13. public class HKCore
  14. {
  15. /// <summary>
  16. /// 刷卡消费
  17. /// </summary>
  18. /// <param name="input"></param>
  19. /// <returns></returns>
  20. public bool DeviceSale(SaleLog input)
  21. {
  22. try
  23. {
  24. //if (RemoteService.CheckCardStuatas(input.CardNo) != 1) return false;
  25. if (!DataBus.IsTest)
  26. if (!Main.GetInstance.GetIsSwipe(input.Location.AsInt())) return false;
  27. var Old = DbContext.Context.Queryable<SaleLog>().Where(t => t.CardNo == input.CardNo).Where(t => t.CreateTime.Day == DateTime.Now.Day).ToList();
  28. if (Old.Count > 3) return false;
  29. var AM = DataBus.AM.Split(",").Select(t => t.AsInt()).ToList();
  30. var PM = DataBus.PM.Split(",").Select(t => t.AsInt()).ToList();
  31. var AT = DataBus.AT.Split(",").Select(t => t.AsInt()).ToList();
  32. var condition1 = (DateTime.Now.Hour >= AM[0] && DateTime.Now.Hour < AM[1]);
  33. var condition2 = (DateTime.Now.Hour >= PM[0] && DateTime.Now.Hour < PM[1]);
  34. var condition3 = (DateTime.Now.Hour >= AT[0] && DateTime.Now.Hour < AT[1]);
  35. if (condition1 || condition2 || condition1)
  36. {
  37. var AMDay = Old.Where(t => t.CreateTime.Hour >= AM[0] && t.CreateTime.Hour < AM[1]).Count();
  38. if (AMDay > 0) return false;
  39. var PMDay = Old.Where(t => t.CreateTime.Hour >= PM[0] && t.CreateTime.Hour < PM[1]).Count();
  40. if (PMDay > 0) return false;
  41. var ATDay = Old.Where(t => t.CreateTime.Hour >= AT[0] && t.CreateTime.Hour < AT[1]).Count();
  42. if (ATDay > 0) return false;
  43. var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity();
  44. if (entity.Id != Guid.Empty)
  45. {
  46. var res = RemoteService.SyncSaleLog(input.CardNo, input.Location);
  47. if (!DataBus.IsTest)
  48. Main.GetInstance.Start(input.Location.AsInt());
  49. DbContext.Context.Updateable<SaleLog>().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand();
  50. return res;
  51. }
  52. else return false;
  53. }
  54. else return false;
  55. }
  56. catch (Exception ex)
  57. {
  58. HKLog.HKLogImport.WriteError(ex);
  59. return false;
  60. }
  61. }
  62. /// <summary>
  63. /// 获取当天消费前100条展示
  64. /// </summary>
  65. /// <returns></returns>
  66. public List<SaleLog> PullDaySaleLog()
  67. {
  68. var Begin = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
  69. var End = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
  70. return DbContext.Context.Queryable<SaleLog>()
  71. .Where(t => t.CreateTime >= Begin)
  72. .Where(t => t.CreateTime < End)
  73. .OrderByDescending(t => t.CreateTime).ToPageList(0, 100);
  74. }
  75. }
  76. }