LogicUtils.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. using System.Data;
  2. using Common;
  3. using Database;
  4. using Database.Database;
  5. using Microsoft.EntityFrameworkCore.Internal;
  6. using MyKungKangWorker.Utils;
  7. using Newtonsoft.Json;
  8. using Quartz;
  9. namespace CMS.Worker;
  10. public class LogicUtils
  11. {
  12. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(LogicUtils));
  13. //public static async Task<bool> AddingPointForUserAsync(
  14. // IConfiguration configuration,
  15. // ModelContext dbContext,
  16. // string msisdn,
  17. // decimal point,
  18. // Term term,
  19. // Prize prize
  20. //)
  21. //{
  22. // try
  23. // {
  24. // // calculate prize for user with
  25. // PaymentTransaction paymentTransaction = new PaymentTransaction()
  26. // {
  27. // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "payment_transaction_seq"),
  28. // TransactionId = CommonLogic.GenerateUUID(),
  29. // Money = prize.Amount,
  30. // Status = "1",
  31. // CreatedTime = DateTime.Now,
  32. // PartnerTransactionId = "0"
  33. // };
  34. // dbContext.PaymentTransactions.Add(paymentTransaction);
  35. // await dbContext.SaveChangesAsync();
  36. // TermUserPrize termUserPrize = new TermUserPrize()
  37. // {
  38. // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "term_user_prize_seq"),
  39. // Msisdn = msisdn,
  40. // Priority = prize.Priority,
  41. // TermId = term.Id,
  42. // PrizeId = prize.Id,
  43. // TimeCalculate = DateTime.Now,
  44. // Status = CommonErrorCode.AddPointWaiting,
  45. // TotalPoints = point,
  46. // PaymentTransactionId = paymentTransaction.Id
  47. // };
  48. // dbContext.TermUserPrizes.Add(termUserPrize);
  49. // await dbContext.SaveChangesAsync();
  50. // AddDataReq request = new AddDataReq
  51. // {
  52. // refTrans = paymentTransaction.TransactionId,
  53. // msisdn = msisdn,
  54. // packageCode = prize.Code
  55. // };
  56. // string bodyString = JsonConvert.SerializeObject(request);
  57. // PaymentTransactionLog paymentTransactionLog = new PaymentTransactionLog()
  58. // {
  59. // Id = (decimal)await DbLogic.GenIdAsync(dbContext, "payment_transaction_log_seq"),
  60. // PaymentTransactionId = paymentTransaction.Id,
  61. // Type = "REQUEST",
  62. // RequestUrl = configuration.GetSection("UrlAddData").Value ?? "",
  63. // RequestBody = bodyString
  64. // };
  65. // // add point to user
  66. // var addPointRes = AddingPointLogic.AddingPointHandler(
  67. // log,
  68. // configuration,
  69. // msisdn,
  70. // paymentTransaction.TransactionId,
  71. // prize.Code
  72. // );
  73. // // var addPointRes = new AddDataRes("{\"success\":\"true\", \"result\":{\"id\":\"1\"}}");
  74. // if (addPointRes != null && addPointRes.success == true)
  75. // {
  76. // termUserPrize.Status = CommonErrorCode.AddPointSuccess;
  77. // termUserPrize.TimeReceived = DateTime.Now;
  78. // paymentTransaction.Status = "0";
  79. // paymentTransaction.PartnerTransactionId = addPointRes.result!.id!;
  80. // // send sms to user
  81. // var msg = dbContext
  82. // .Configs.Where(
  83. // x => x.ParamName == (CommonConstants.Weekly + "_" + prize.Amount)
  84. // )
  85. // .FirstOrDefault();
  86. // if (msg != null)
  87. // {
  88. // List<List<DateTime>> timeWeekly = CommonLogic.GetTimeWeekly(1);
  89. // string? message = null;
  90. // string? messageData =
  91. // msg.ParamValueFr != null ? msg.ParamValueFr : msg.ParamValue;
  92. // if (messageData != null)
  93. // {
  94. // message = messageData
  95. // .Replace(
  96. // "%from%",
  97. // timeWeekly[0][0].ToString(CommonConstants.DateTimeFormar12)
  98. // )
  99. // .Replace(
  100. // "%to%",
  101. // timeWeekly[0][1].ToString(CommonConstants.DateTimeFormar12)
  102. // );
  103. // }
  104. // await CommonLogic.SendMtToUserAsync(dbContext, msisdn, message);
  105. // }
  106. // }
  107. // else
  108. // {
  109. // termUserPrize.Status = CommonErrorCode.AddPointFailure;
  110. // }
  111. // paymentTransactionLog.Status =
  112. // addPointRes != null && addPointRes.success == true ? "0" : "-1";
  113. // paymentTransactionLog.ResponseBody = JsonConvert.SerializeObject(addPointRes);
  114. // dbContext.TermUserPrizes.Update(termUserPrize);
  115. // dbContext.PaymentTransactions.Update(paymentTransaction);
  116. // dbContext.PaymentTransactionLogs.Add(paymentTransactionLog);
  117. // await dbContext.SaveChangesAsync();
  118. // return true;
  119. // }
  120. // catch (Exception ex)
  121. // {
  122. // log.Error("Exception: ", ex);
  123. // }
  124. // return true;
  125. //}
  126. }