PayTrx.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. using SinochemCloudClient.Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using Wayne.Lib;
  5. using Wayne.Lib.StateEngine;
  6. using Wayne.Lib.StateEngine.Generic;
  7. namespace SinochemInternetPlusApp.States.Shared
  8. {
  9. class PayTrx : TimeoutState<FuelingPoint>
  10. {
  11. protected override void Enter(StateEntry stateEntry, ref Transition transition)
  12. {
  13. base.Enter(stateEntry, ref transition);
  14. if (Main.CurrentEpsTrx != null)
  15. {
  16. Main.CurrentEpsTrx.UpdateTrxStatusToDb(EpsTrxStatus.BeforePayment);
  17. //Need Pay Cloud, delete trx from xiaofei2, avoid POS lock it
  18. Main.LockTrxInXiaofei2AsEpsTrx();
  19. MultiFusionsSupport.DeleteXiaofei2FromTargetFusion(Main.CurrentEpsTrx.Model.jihao, Main.CurrentEpsTrx.Model.liushuino, Main.DebugLogger);
  20. }
  21. Main.SendPaymentToCloudAsync();
  22. }
  23. protected override void HandleNonTimeoutEvent(StateEngineEvent stateEngineEvent, ref Transition transition)
  24. {
  25. if (stateEngineEvent.Type is EventType)
  26. {
  27. var genericEvent = stateEngineEvent as GenericEvent<PaymentResponse>;
  28. switch ((EventType)stateEngineEvent.Type)
  29. {
  30. case EventType.CloudPaymentOk:
  31. if (genericEvent != null && genericEvent.EventArgs.result != null)
  32. {
  33. Main.CurrentEpsTrx.Model.real_pay_amount = genericEvent.EventArgs.result.real_Pay_Amount;
  34. Main.CurrentEpsTrx.Model.bill_id = genericEvent.EventArgs.result.bill_ID;
  35. Main.CurrentEpsTrx.Model.shift_id = genericEvent.EventArgs.result.shift_ID;
  36. Main.CurrentEpsTrx.Model.business_date = genericEvent.EventArgs.result.business_Date;
  37. Main.CurrentEpsTrx.Model.card_no = genericEvent.EventArgs.result.card_No;
  38. Main.CurrentEpsTrx.Model.cardNo_masked = genericEvent.EventArgs.result.cardNo_Hide;
  39. Main.CurrentEpsTrx.Model.invoiceUrl = genericEvent.EventArgs.result.invoiceUrl;
  40. //Main.CurrentEpsTrx.Model.pay_url = genericEvent.EventArgs.result.pay_url;
  41. Main.CurrentEpsTrx.Model.openId = genericEvent.EventArgs.result.openId;
  42. Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.PaymentOk;
  43. //oilcard = 01, weixin = 07
  44. if (genericEvent.EventArgs.result.payMethod != null && genericEvent.EventArgs.result.payMethod.Length == 1)
  45. Main.CurrentEpsTrx.Model.payMethod = "0" + genericEvent.EventArgs.result.payMethod;
  46. else if (genericEvent.EventArgs.result.payMethod != null && genericEvent.EventArgs.result.payMethod.Length == 2)
  47. Main.CurrentEpsTrx.Model.payMethod = genericEvent.EventArgs.result.payMethod;
  48. if (Main.CurrentEpsTrx.Model.payMethod == "07")
  49. Main.CurrentEpsTrx.Model.cardType = CardType.WeiXin;
  50. else
  51. Main.CurrentEpsTrx.Model.cardType = CardType.OilCard;
  52. Main.CurrentEpsTrx.SaveToDb();
  53. transition = new Transition(this, TransitionType.CloudPaymentOk);
  54. }
  55. else
  56. {
  57. transition = HandleCloudPaymentFailed();
  58. }
  59. stateEngineEvent.Handled = true;
  60. break;
  61. case EventType.QRCodePayment:
  62. case EventType.PlainUser_Unpaid:
  63. //Main.CurrentEpsTrx.UpdateTrxStatusToDb(EpsTrxStatus.BeforePayment);
  64. if (Main.CurrentEpsTrx != null)
  65. {
  66. Main.CurrentEpsTrx.MoveBackToXiaofei2(Main.DebugLogger);
  67. // copy this failed trx to another fusion if neeeded
  68. MultiFusionsSupport.CopyXiaofei2ToTargetFusion(Main.CurrentEpsTrx.Model.jihao, Main.CurrentEpsTrx.Model.liushuino, Main.DebugLogger);
  69. if (genericEvent != null && genericEvent.EventArgs.result != null)
  70. {
  71. //Main.CurrentEpsTrx.Model.real_pay_amount = genericEvent.EventArgs.result.real_Pay_Amount;
  72. Main.CurrentEpsTrx.Model.pay_url = genericEvent.EventArgs.result.pay_url;
  73. }
  74. transition = new Transition(this, TransitionType.QRCodePayment);
  75. }
  76. else
  77. {
  78. transition = HandleCloudPaymentFailed();
  79. }
  80. stateEngineEvent.Handled = true;
  81. break;
  82. case EventType.CloudPaymentFailed:
  83. if (Main.CurrentEpsTrx != null && genericEvent != null && genericEvent.EventArgs.result != null)
  84. {
  85. //Main.CurrentEpsTrx.Model.trx_status = EpsTrxStatus.PaymentFailed;
  86. //Main.CurrentEpsTrx.Model.real_pay_amount = genericEvent.EventArgs.result.real_Pay_Amount;
  87. Main.CurrentEpsTrx.Model.bill_id = genericEvent.EventArgs.result.bill_ID;
  88. Main.CurrentEpsTrx.Model.shift_id = genericEvent.EventArgs.result.shift_ID;
  89. Main.CurrentEpsTrx.Model.business_date = genericEvent.EventArgs.result.business_Date;
  90. Main.CurrentEpsTrx.Model.card_no = genericEvent.EventArgs.result.card_No;
  91. Main.CurrentEpsTrx.Model.cardNo_masked = genericEvent.EventArgs.result.cardNo_Hide;
  92. Main.CurrentEpsTrx.Model.pay_url = genericEvent.EventArgs.result.pay_url;
  93. Main.CurrentEpsTrx.SaveToDb();
  94. }
  95. transition = HandleCloudPaymentFailed();
  96. stateEngineEvent.Handled = true;
  97. break;
  98. }
  99. }
  100. }
  101. private Transition HandleCloudPaymentFailed()
  102. {
  103. DebugLog("HandleCloudPaymentFailed");
  104. if (Main.CurrentEpsTrx != null)
  105. {
  106. DebugLog("HandleCloudPaymentFailed MoveBack To xiaofei2");
  107. Main.CurrentEpsTrx.UpdateTrxStatusToDb(EpsTrxStatus.PaymentNeedConfirm);
  108. Main.CurrentEpsTrx.MoveBackToXiaofei2(Main.DebugLogger);
  109. // copy this failed trx to another fusion if neeeded
  110. MultiFusionsSupport.CopyXiaofei2ToTargetFusion(Main.CurrentEpsTrx.Model.jihao, Main.CurrentEpsTrx.Model.liushuino, Main.DebugLogger);
  111. //Broadcast trxlist to bigScreen
  112. var validTrx = EpsTransactionQuery.GetValidCarPlateEpsTrxModels(
  113. Main.GetAllNozzlesOnThisSide(),
  114. ConfigurationValues.AlreadyDoneEpsTrxCountPerDisplay,
  115. Main.DebugLogger);
  116. if (Main.Eps.NozzleMappingGradeName() != null)
  117. {
  118. foreach (var trx in validTrx)
  119. {
  120. if (trx.trx_status == EpsTrxStatus.BeforeFueling || trx.trx_status == EpsTrxStatus.Fueling)
  121. {
  122. trx.AvailableNozzleGrade = Main.GetAvailableNozzleInfo();
  123. }
  124. }
  125. }
  126. int requestId = 0 ;
  127. var text = Main.Eps.CreateDisplayTrxCommand(validTrx, out requestId, 3);
  128. if (Main.Eps.CarPlateHandler != null)
  129. {
  130. DebugLog(text);
  131. Main.Eps.CarPlateHandler.BroadcastMessageViaFdc(text);
  132. }
  133. }
  134. return new Transition(this, TransitionType.CloudPaymentFailed);
  135. }
  136. protected override void Timeout(ref Transition transition)
  137. {
  138. transition = HandleCloudPaymentFailed();
  139. }
  140. protected override int TimeoutInterval =>
  141. TimeoutValues.GetValueInMilliSec(TimeoutValues.FuelingPoint.Shared_PayTrx, 15);
  142. }
  143. }