OrderFromMachine.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using Castle.Components.DictionaryAdapter.Xml;
  2. using Edge.Core.Domain.FccOrderInfo;
  3. using Edge.Core.Domain.FccStationInfo.Output;
  4. using Edge.Core.Parser.BinaryParser.MessageEntity;
  5. using Microsoft.EntityFrameworkCore.Metadata.Internal;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Runtime.InteropServices;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. namespace HengshanPaymentTerminal.MessageEntity.Incoming
  13. {
  14. /// <summary>
  15. /// 油机推送订单信息数据对象
  16. /// </summary>
  17. public class OrderFromMachine:CommonMessage
  18. {
  19. /// <summary>
  20. /// 枪号
  21. /// </summary>
  22. public int nozzleNum { get; set; }
  23. /// <summary>
  24. /// 交易流水号
  25. /// </summary>
  26. public int ttc { get; set; }
  27. /// <summary>
  28. /// 加油时间
  29. /// </summary>
  30. public DateTime dispenserTime { get; set; }
  31. /// <summary>
  32. /// 挂枪时间
  33. /// </summary>
  34. public DateTime endTime { get; set; }
  35. /// <summary>
  36. /// 油品代码
  37. /// </summary>
  38. public string oilCode { get; set; }
  39. /// <summary>
  40. /// 付款方式/地点
  41. /// </summary>
  42. public byte payType { get; set; }
  43. /// <summary>
  44. /// 价格
  45. /// </summary>
  46. public decimal price { get; set; }
  47. /// <summary>
  48. /// 金额
  49. /// </summary>
  50. public decimal amount { get; set; }
  51. /// <summary>
  52. /// 升数
  53. /// </summary>
  54. public decimal volume { get; set; }
  55. /// <summary>
  56. /// 泵码
  57. /// </summary>
  58. public decimal pumpCode { get; set; }
  59. public override byte[] ToCommonByteArray()
  60. {
  61. byte[] content = new byte[] { 0x55, this.Handle, (byte)this.nozzleNum, ((byte)RESULT.OVER) };
  62. return content2data(content);
  63. }
  64. public override CommonMessage ToObject(byte[] datas)
  65. {
  66. getBaseData(datas);
  67. this.nozzleNum = datas[7];
  68. this.ttc = Bytes2Number<int>(datas, 8, 4);
  69. Span<byte> dispenserSpan = datas.AsSpan(12, 7);
  70. this.dispenserTime = bytes2DateTime(dispenserSpan.ToArray());
  71. Span<byte> endSpan = datas.AsSpan(19, 7);
  72. this.endTime = bytes2DateTime(endSpan.ToArray());
  73. Span<byte> oilCodeSpan = datas.AsSpan(26, 2);
  74. this.oilCode = BitConverter.ToString(oilCodeSpan.ToArray()).Replace("-", "");
  75. this.payType = datas[28];
  76. ushort priceShort = Bytes2Number<ushort>(datas,29, 2);
  77. this.price = priceShort / 100m;
  78. uint amountInt = Bytes2Number<uint>(datas, 31, 3);
  79. this.amount = amountInt / 100m;
  80. uint volumeInt = Bytes2Number<uint>(datas, 34, 3);
  81. this.volume = volumeInt / 100m;
  82. int punpCodeInt = Bytes2Number<int>(datas, 37, 4);
  83. this.pumpCode = punpCodeInt / 100m;
  84. return this;
  85. }
  86. public FccOrderInfo ToComponent(string? oilName)
  87. {
  88. return new FccOrderInfo
  89. {
  90. Ttc = this.ttc,
  91. AuthorizationTime = this.dispenserTime,
  92. EndTime = this.endTime,
  93. PaymentTime = null,
  94. NozzleNum = this.nozzleNum,
  95. OilName = oilName ?? "",
  96. PaymentStatus = 0,
  97. //PayType = 0x21,
  98. CloundOrderId = null,
  99. Amount = this.amount,
  100. Volume = this.volume,
  101. //AmountPayable = this.amount,
  102. UploadState = 0,
  103. IsDelete = 0,
  104. Price = this.price,
  105. //RefundAmount = 0,
  106. UserName = "",
  107. PhoneNumber = "",
  108. PaymentName = "",
  109. PumpCode = this.pumpCode
  110. };
  111. }
  112. /// <summary>
  113. /// 补充授权订单数据
  114. /// </summary>
  115. /// <param name="order">当前数据库中订单数据</param>
  116. /// <returns></returns>
  117. public FccOrderInfo PaddingAuthorizationOrderData(FccOrderInfo order)
  118. {
  119. order.AuthorizationTime = this.dispenserTime;
  120. order.EndTime = this.endTime;
  121. order.Amount = this.amount;
  122. order.Volume = this.volume;
  123. order.Price = this.price;
  124. return order;
  125. }
  126. }
  127. }