DepositReturnService.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.Models;
  9. namespace MySystem
  10. {
  11. public class DepositReturnService
  12. {
  13. public readonly static DepositReturnService Instance = new DepositReturnService();
  14. private DepositReturnService()
  15. { }
  16. public void Start()
  17. {
  18. Thread th = new Thread(StartListen);
  19. th.IsBackground = true;
  20. th.Start();
  21. }
  22. public void StartListen()
  23. {
  24. while(true)
  25. {
  26. try
  27. {
  28. string content = RedisDbconn.Instance.RPop<string>("ToAlipayAccountQueue");
  29. if(!string.IsNullOrEmpty(content))
  30. {
  31. string[] idlist = content.Split(',');
  32. foreach(string id in idlist)
  33. {
  34. int IdNum = int.Parse(id);
  35. StartListenDo(IdNum);
  36. }
  37. }
  38. else
  39. {
  40. Thread.Sleep(60000);
  41. }
  42. }
  43. catch(Exception ex)
  44. {
  45. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "退还押金到支付宝余额异常");
  46. Thread.Sleep(600000);
  47. }
  48. }
  49. }
  50. public void StartListenDo(int Id)
  51. {
  52. WebCMSEntities db = new WebCMSEntities();
  53. MerchantDepositReturns item = db.MerchantDepositReturns.FirstOrDefault(m => m.Id == Id);
  54. if(item != null)
  55. {
  56. PosMerchantInfo mer = db.PosMerchantInfo.FirstOrDefault(m => m.Id == item.MerchantId) ?? new PosMerchantInfo();
  57. string Name = item.OperateMan;
  58. string AccountNo = item.AlipayAccountNo;
  59. decimal ReturnAmount = item.ReturnAmount * 0.92M;
  60. // decimal ReturnAmount = item.ReturnAmount / 1000;
  61. // if(ReturnAmount < 0.1M)
  62. // {
  63. // ReturnAmount = 0.1M;
  64. // }
  65. string Amount = ReturnAmount.ToString("f2");
  66. PublicAccountSet set = db.PublicAccountSet.FirstOrDefault() ?? new PublicAccountSet();
  67. string result = new Alipay.AlipayPublicMethod().TransferToAccount(set.AlipayAppId, set.AlipayPrivateKey,set.AlipayPublicKey, AccountNo, Amount, "达标奖到账", Name, "机具SN:" + mer.KqSnNo + ";商户姓名:" + mer.MerRealName);
  68. if(result.StartsWith("success"))
  69. {
  70. item.Status = 1;
  71. mer.StandardStatus = 1;
  72. }
  73. else
  74. {
  75. item.Status = 2;
  76. item.SeoDescription = result;
  77. mer.StandardStatus = 101;
  78. mer.SeoDescription = result;
  79. }
  80. db.SaveChanges();
  81. }
  82. db.Dispose();
  83. }
  84. }
  85. }