PosPushDataNewHelper.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Library;
  5. using MySystem.Models.Main;
  6. namespace MySystem
  7. {
  8. public class PosPushDataNewHelper
  9. {
  10. public readonly static PosPushDataNewHelper Instance = new PosPushDataNewHelper();
  11. private PosPushDataNewHelper()
  12. { }
  13. //绑定数据
  14. // public static void Bind(MerchantAddInfo mer, PosMachinesTwo pos)
  15. // {
  16. // try
  17. // {
  18. // Dictionary<string, object> dataContent = new Dictionary<string, object>();
  19. // dataContent.Add("pos_sn", pos.PosSn); //机具sn
  20. // dataContent.Add("mer_no", mer.MchtNo); //商户号
  21. // dataContent.Add("id_card", mer.IdCardNumber); //商户身份证
  22. // dataContent.Add("mer_name", mer.CertMerchantName); //商户姓名
  23. // dataContent.Add("mer_mobile", mer.MobilePhone); //商户手机号
  24. // dataContent.Add("request_id", getRequestId(mer.Id, "bind")); //流水号
  25. // dataContent.Add("bind_time", mer.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //绑定时间
  26. // dataContent.Add("brand", 101); //品牌
  27. // Push("bind", dataContent);
  28. // }
  29. // catch (Exception ex)
  30. // {
  31. // function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送绑定数据异常");
  32. // }
  33. // }
  34. //交易数据
  35. public static void Trade(ConsumerOrders trade, MerchantAddInfo mer)
  36. {
  37. try
  38. {
  39. int QrPayFlag = 0;
  40. int BankCardType = 1;
  41. List<string> BrandIds = new List<string>();
  42. decimal TradeAmount = trade.PayMoney;
  43. Dictionary<string, object> dataContent = new Dictionary<string, object>();
  44. dataContent.Add("pos_sn", trade.SnNo); //机具sn
  45. dataContent.Add("mer_no", mer.MchtNo); //商户号
  46. dataContent.Add("request_id", trade.OrderNo); //流水号
  47. dataContent.Add("trade_amount", TradeAmount); //交易金额
  48. dataContent.Add("trade_time", trade.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss")); //交易时间
  49. dataContent.Add("brand", 101); //品牌
  50. dataContent.Add("card_type", BankCardType); //卡类型
  51. dataContent.Add("qr_pay_flag", QrPayFlag); //云闪付标记
  52. dataContent.Add("fee_rate", trade.IsAct == 1 ? 0.6M : 0.63M);
  53. dataContent.Add("fee_amt", trade.IsAct == 1 ? 0 : 3);
  54. Push("trade", dataContent);
  55. }
  56. catch (Exception ex)
  57. {
  58. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString() + "\n\n", "推送交易数据异常");
  59. }
  60. }
  61. public static void Push(string dataType, Dictionary<string, object> dataContent)
  62. {
  63. Dictionary<string, object> data = new Dictionary<string, object>();
  64. data.Add("data_type", dataType);
  65. data.Add("data_content", dataContent);
  66. KxsRedisDbconn.Instance.AddList("KxsPosDataQueue", Newtonsoft.Json.JsonConvert.SerializeObject(data));
  67. }
  68. public static string getRequestId(int id, string type)
  69. {
  70. if(id > 0)
  71. {
  72. return function.MD5_32(id.ToString() + type);
  73. }
  74. return DateTime.Now.ToString("yyyyMMddHHmmssfff") + function.get_Random(8);
  75. }
  76. }
  77. }