FeeAuditRepository.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using NPOI.SS.Formula.Functions;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Entities.Groups;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace OASystem.Infrastructure.Repositories.Groups
  10. {
  11. /// <summary>
  12. /// 费用审核仓储
  13. /// </summary>
  14. public class FeeAuditRepository:BaseRepository<EntityBase,ViewBase>
  15. {
  16. public FeeAuditRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
  17. {
  18. }
  19. /// <summary>
  20. /// 费用自动审核
  21. /// </summary>
  22. /// <param name="feeType">
  23. /// 1.酒店 76
  24. /// 2.op 79
  25. /// </param>
  26. /// <param name="diId">团组Id</param>
  27. /// <param name="dataId">数据Id(模块类型主表Id)</param>
  28. /// <returns></returns>
  29. public async Task<JsonView> FeeAutomaticAudit(int feeType, int diId, int dataId)
  30. {
  31. var _view = new JsonView() { Code = 201, Msg = "自动审核操作失败" };
  32. if (diId < 1) { _view.Msg = MsgTips.DiId; return _view; }
  33. if (dataId < 1) { _view.Msg = MsgTips.Id; return _view; }
  34. List<int> stids = new List<int>() { 17, 66 };
  35. var setData = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && stids.Contains(x.STid)).ToList();
  36. string _teamCurrency = string.Empty;
  37. decimal _rate = 0.00M;
  38. var groupInfo = _sqlSugar.Queryable< Grp_GroupCostParameter >().Where(x => x.IsDel ==0 && x.DiId == diId).First();
  39. if (groupInfo == null) { _view.Msg = $"团组成本信息未填写!"; return _view; }
  40. _teamCurrency = groupInfo.Currency;
  41. //币种验证 统一为currencycode三字码
  42. if (int.TryParse(_teamCurrency,out int currency))
  43. {
  44. _teamCurrency = setData.Find(x => x.Id == currency)?.Name ?? "";
  45. }
  46. _rate = groupInfo.Rate;
  47. var costContents = _sqlSugar.Queryable<Grp_GroupCost>().Where(x => x.IsDel == 0 && x.Diid == diId).ToList();
  48. if (costContents.Count < 1) { _view.Msg = $"团组成本信息未填写!"; return _view; }
  49. //处理 成本详细信息 日期为空
  50. for (int i = 0; i < costContents.Count; i++)
  51. {
  52. if (string.IsNullOrEmpty( costContents[i].Date))
  53. {
  54. int index = i - 1;
  55. if (index >= 0)
  56. {
  57. costContents[i].Date = costContents[index].Date;
  58. }
  59. }
  60. }
  61. if (feeType == 1)
  62. {
  63. var hotelCostInfo = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId).First();
  64. var hotelCostDetails = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(x => x.IsDel == 0 && x.DiId == diId && x.HrId == dataId).ToList();
  65. if (hotelCostInfo == null)
  66. {
  67. _view.Msg = $"酒店费用数据未填写";
  68. return _view;
  69. }
  70. //验证币种是否相等
  71. string hotelCurrency = setData.Find(x => x.Id == hotelCostInfo.CardPriceCurrency)?.Name ?? "";
  72. if (hotelCurrency != _teamCurrency)
  73. {
  74. if (!hotelCurrency.Equals("CNY"))
  75. {
  76. _view.Msg = $"币种不一致";
  77. return _view;
  78. }
  79. }
  80. else _rate = 1.0000M;
  81. bool isAutoAudit = true; //是否自动审核
  82. DateTime checkIn = Convert.ToDateTime(hotelCostInfo.CheckInDate),
  83. checkOut = Convert.ToDateTime(hotelCostInfo.CheckOutDate);
  84. var hotelCostInfos = costContents.Where(x => Convert.ToDateTime(x.Date) >= checkIn && Convert.ToDateTime(x.Date) <= checkOut).ToList();
  85. if (hotelCostInfos.Count < 1) isAutoAudit = false;
  86. decimal otherFee = hotelCostDetails.Where(x => x.PriceType != 1).Sum(x => x.Price);
  87. if (otherFee > 0) { otherFee /= 3; }
  88. foreach (var item in hotelCostInfos)
  89. {
  90. //1.判断费用是否 <= 成本费用
  91. //1.1 判断单间费用
  92. if (item.SGR > 0)
  93. {
  94. decimal singleRoomPrice = hotelCostInfo.SingleRoomPrice + otherFee;
  95. if (singleRoomPrice > item.SGR * _rate) isAutoAudit = false;
  96. }
  97. //1.2 判断双人间费用
  98. if (item.TBR > 0)
  99. {
  100. decimal doubleRoomPrice = hotelCostInfo.DoubleRoomPrice + otherFee;
  101. if (doubleRoomPrice > item.TBR * _rate) isAutoAudit = false;
  102. }
  103. //1.3 判断套房费用
  104. if (item.Suite > 0)
  105. {
  106. decimal suiteRoomPrice = hotelCostInfo.SuiteRoomPrice + otherFee;
  107. if (suiteRoomPrice > item.Suite * _rate) isAutoAudit = false;
  108. }
  109. //1.4 判断其他房型费用
  110. if (item.JS_ES > 0)
  111. {
  112. decimal otherRoomPrice = hotelCostInfo.OtherRoomPrice + otherFee;
  113. if (otherRoomPrice > item.JS_ES * _rate) isAutoAudit = false;
  114. }
  115. }
  116. //2.判断是否自动审核
  117. if (isAutoAudit)
  118. {
  119. var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  120. .SetColumns(it => it.IsAuditGM == 3)
  121. .SetColumns(it => it.AuditGMOperate == 4)
  122. .SetColumns(it => it.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  123. .Where(s => s.DIId == diId && s.CTable == 76 && s.CId == dataId)
  124. .ExecuteCommand();
  125. if (ccpUpdate > 0)
  126. {
  127. _view.Code = 200;
  128. _view.Msg = "审核成功";
  129. return _view;
  130. }
  131. }
  132. else {
  133. //撤销该条数据的自动审核 --> 该条数据的审核状态是自动审核 3 --> 0
  134. var ccpInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>()
  135. .Where(s => s.DIId == diId && s.CTable == 76 && s.CId == dataId && s.IsAuditGM == 3)
  136. .First();
  137. if (ccpInfo != null)
  138. {
  139. var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  140. .SetColumns(it => it.IsAuditGM == 0)
  141. .SetColumns(it => it.AuditGMOperate == 0)
  142. .SetColumns(it => it.AuditGMDate == string.Empty)
  143. .Where(s => s.Id == ccpInfo.Id)
  144. .ExecuteCommand();
  145. }
  146. }
  147. }
  148. else if (feeType == 2)
  149. {
  150. //1.含超时费用 手动审核
  151. }
  152. else _view.Msg = $"请传入有效的feeType参数";
  153. return _view;
  154. }
  155. }
  156. }