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.

109 rivejä
4.0 KiB

  1. using HKCardOUT.Helper;
  2. using HKCardOUT.Logic.Model;
  3. using HKCardOUT.Logic.Service;
  4. using HKLib.Dto;
  5. using Logic.RemoteModel;
  6. using Newtonsoft.Json.Linq;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.IO;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Markup;
  14. using UHFHelper;
  15. using XExten.Advance.HttpFramework.MultiCommon;
  16. using XExten.Advance.HttpFramework.MultiFactory;
  17. using XExten.Advance.LinqFramework;
  18. using XExten.Advance.StaticFramework;
  19. namespace HKCardOUT.Logic
  20. {
  21. public class RemoteService
  22. {
  23. /// <summary>
  24. /// 获取所有卡状态和卡号
  25. /// </summary>
  26. /// <param name="input"></param>
  27. public static int GetCardStuatas()
  28. {
  29. var res = IHttpMultiClient.HttpMulti.AddNode(t =>
  30. {
  31. t.NodePath = ApiRoute.CheckCardStatus;
  32. t.ReqType = MultiType.GET;
  33. }).Build().RunStringFirst();
  34. var data = res.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<CardInfo>>();
  35. var entity = data.Select(t => new CardStutas
  36. {
  37. CardNo = t.CardNum,
  38. Stutas = t.State
  39. }).ToList();
  40. HKCore.AddCard(entity);
  41. return data != null ? data.ToString().AsInt() : 0;
  42. }
  43. /// <summary>
  44. /// 同步时间段
  45. /// </summary>
  46. public static void SyncTime()
  47. {
  48. /*
  49. {"statusCode":200,"data":{"isSuccess":true,"msg":null,"data":{"amStartTime":"17:50","amEndTime":"17:50","pmStartTime":"17:50","pmEndTime":"17:50","atStartTime":"17:50","atEndTime":"17:50"}},"succeeded":true,"errors":null,"extras":null,"timestamp":1665654784093}
  50. */
  51. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  52. {
  53. t.NodePath = ApiRoute.GetTime;
  54. t.ReqType = MultiType.GET;
  55. }).Build().RunStringFirst();
  56. DataBus.Times = data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<TimeSpilte>();
  57. }
  58. /// <summary>
  59. /// 同步消费记录
  60. /// </summary>
  61. /// <param name="CardNo"></param>
  62. /// <param name="Money"></param>
  63. public static bool SyncSaleLog(string CardNo, string StallId)
  64. {
  65. try
  66. {
  67. var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == StallId.AsInt())?.GateId;
  68. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  69. {
  70. t.ReqType = MultiType.POST;
  71. t.JsonParam = (new { GateId = GateId, Type = -1, CardNum = CardNo }).ToJson();
  72. t.NodePath = ApiRoute.SyncSaleLog;
  73. }).Build().RunStringFirst();
  74. HKLog.HKLogImport.WriteInfo($"同步消费时候调用:{data}");
  75. return bool.Parse(data.ToModel<JObject>()["data"].ToString());
  76. }
  77. catch (Exception ex)
  78. {
  79. HKLog.HKLogImport.WriteError(ex);
  80. return false;
  81. }
  82. }
  83. /// <summary>
  84. /// 获取店铺信息
  85. /// </summary>
  86. public static void PullShopInfo()
  87. {
  88. if (DataBus.NetWordState)
  89. {
  90. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  91. {
  92. t.NodePath = ApiRoute.PullShopInfo;
  93. }).Build().RunStringFirst()
  94. .ToModel<JObject>()["data"].ToJson().ToModel<StoreInfoResponse>();
  95. DataBus.StoreInfo = data;
  96. var storeinfo = SyncStatic.CreateFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StoreInfo.json"));
  97. SyncStatic.WriteFile(Encoding.UTF8.GetBytes(data.ToJson()), storeinfo);
  98. }
  99. else
  100. {
  101. DataBus.StoreInfo = SyncStatic.ReadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StoreInfo.json")).ToModel<StoreInfoResponse>();
  102. }
  103. }
  104. }
  105. }