FeeAuditRepository.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. using EyeSoft.Logging;
  2. using NPOI.SS.Formula.Functions;
  3. using OASystem.Domain;
  4. using OASystem.Domain.Entities.Groups;
  5. using OASystem.Domain.ViewModels.Groups;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. namespace OASystem.Infrastructure.Repositories.Groups
  12. {
  13. /// <summary>
  14. /// 费用审核仓储
  15. /// </summary>
  16. public class FeeAuditRepository:BaseRepository<EntityBase,ViewBase>
  17. {
  18. public FeeAuditRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
  19. {
  20. }
  21. /// <summary>
  22. /// 费用自动审核
  23. /// </summary>
  24. /// <param name="feeType">
  25. /// 1.酒店 76
  26. /// 2.op 79
  27. /// </param>
  28. /// <param name="diId">团组Id</param>
  29. /// <param name="dataId">数据Id(模块类型主表Id)</param>
  30. /// <returns></returns>
  31. public async Task<JsonView> FeeAutomaticAudit(int feeType, int diId, int dataId)
  32. {
  33. var _view = new JsonView() { Code = 201, Msg = "自动审核操作失败" };
  34. if (diId < 1) { _view.Msg = MsgTips.DiId; return _view; }
  35. if (dataId < 1) { _view.Msg = MsgTips.Id; return _view; }
  36. List<int> stids = new List<int>() { 17, 66 };
  37. var setData = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && stids.Contains(x.STid)).ToList();
  38. string _teamCurrency = string.Empty;
  39. var groupInfo = _sqlSugar.Queryable<Grp_GroupCostParameter>().Where(x => x.IsDel == 0 && x.DiId == diId).First();
  40. if (groupInfo == null) { _view.Msg = $"团组成本信息未填写!"; return _view; }
  41. _teamCurrency = groupInfo.Currency;
  42. decimal _teamRate = groupInfo.Rate;
  43. //币种验证 统一为currencycode三字码
  44. if (int.TryParse(_teamCurrency,out int currency)) _teamCurrency = setData.Find(x => x.Id == currency)?.Name ?? "";
  45. string costContentSql = $"Select * From Grp_GroupCost";
  46. var costContents = _sqlSugar.SqlQueryable<GroupCostAuditView>(costContentSql).Where(x => x.IsDel == 0 && x.Diid == diId).ToList();
  47. if (costContents.Count < 1) { _view.Msg = $"团组成本信息未填写!"; return _view; }
  48. //处理 成本详细信息 日期为空
  49. for (int i = 0; i < costContents.Count; i++)
  50. {
  51. if (string.IsNullOrEmpty( costContents[i].Date))
  52. {
  53. int index = i - 1;
  54. if (index >= 0)
  55. {
  56. costContents[i].Date = costContents[index].Date;
  57. }
  58. }
  59. }
  60. if (feeType == 1)
  61. {
  62. //1089 对冲账或其他 不在审核范围
  63. var hotelCostInfo = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId && x.CheckType != 1089).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. QuashAudit(76, diId, dataId);
  69. return _view;
  70. }
  71. //酒店费用金额 == 0 不自动审核
  72. if (hotelCostInfo.CardPrice == 0.0000M)
  73. {
  74. _view.Msg = $"酒店费用金额 == 0 不自动审核";
  75. QuashAudit(76, diId, dataId);
  76. return _view;
  77. }
  78. //获取C表汇率
  79. decimal _rate = 1.0000M;
  80. var roomFeeInfo = hotelCostDetails.Where(x => x.PriceType == 1).First();
  81. if (roomFeeInfo == null)
  82. {
  83. _view.Msg = $"酒店房间费用付款数据未填写";
  84. return _view;
  85. }
  86. _rate = roomFeeInfo.Rate == 0.0000M ? 1.0000M : roomFeeInfo.Rate;
  87. bool isAutoAudit = true; //是否自动审核
  88. DateTime checkIn = Convert.ToDateTime(hotelCostInfo.CheckInDate),
  89. checkOut = Convert.ToDateTime(hotelCostInfo.CheckOutDate);
  90. if (checkOut > checkIn) checkOut = checkOut.AddDays(-1); //房费计算,结束日期为前一天
  91. var hotelCostInfos = costContents.Where(x => Convert.ToDateTime(x.Date) >= checkIn && Convert.ToDateTime(x.Date) <= checkOut).ToList();
  92. if (hotelCostInfos.Count < 1) isAutoAudit = false;
  93. decimal otherFee = hotelCostDetails.Where(x => x.PriceType != 1).Sum(x => x.Price * (x.Rate == 0.0000M ? 1.0000M : x.Rate));
  94. if (otherFee > 0) { otherFee /= (checkOut-checkIn).Days; }
  95. var hotelCostInfosGroup = hotelCostInfos.GroupBy(x => x.Date);
  96. foreach (var item in hotelCostInfosGroup)
  97. {
  98. decimal hotelSingleRoomFee = item.Sum(x => x.HotelSingleRoomFee);
  99. decimal hotelDoubleRoomFee = item.Sum(x => x.HotelDoubleRoomFee);
  100. decimal hotelSuiteFee = item.Sum(x => x.HotelSuiteFee);
  101. decimal hotelSuiteRoomFee = item.Sum(x => x.HotelSuiteRoomFee);
  102. //1.判断费用是否 <= 成本费用
  103. //1.1 判断单间费用
  104. decimal singleRoomPrice = (hotelCostInfo.SingleRoomPrice + otherFee) * _rate;
  105. if (singleRoomPrice > 0) if (singleRoomPrice > hotelSingleRoomFee * _rate) isAutoAudit = false;
  106. //1.2 判断双人间费用
  107. decimal doubleRoomPrice = (hotelCostInfo.DoubleRoomPrice + otherFee) * _rate;
  108. if (doubleRoomPrice > 0) if (doubleRoomPrice > hotelDoubleRoomFee * _rate) isAutoAudit = false;
  109. //1.3 判断套房费用
  110. decimal suiteRoomPrice = (hotelCostInfo.SuiteRoomPrice + otherFee) * _rate;
  111. if (suiteRoomPrice > 0) if (suiteRoomPrice > hotelSuiteFee * _rate) isAutoAudit = false;
  112. //1.4 判断其他房型费用
  113. decimal otherRoomPrice = (hotelCostInfo.OtherRoomPrice + otherFee) * _rate;
  114. if (otherRoomPrice > 0) if (otherRoomPrice > hotelSuiteRoomFee * _rate) isAutoAudit = false;
  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 quashStatus = QuashAudit(76,diId,dataId);
  135. if (quashStatus)
  136. {
  137. _view.Code = 200;
  138. _view.Msg = "费用超团组成本,自动审核撤销成功!";
  139. return _view;
  140. }
  141. }
  142. }
  143. else if (feeType == 2)
  144. {
  145. //1.基础数据参数验证
  146. var priceType = new List<int>() { 1062 };
  147. var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  148. .Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId && !priceType.Contains(x.PriceType))
  149. .First();
  150. //var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  151. // .Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId )
  152. // .First();
  153. if (opinfos == null)
  154. {
  155. _view.Msg = $"OP费用费用类型属于“尾款”或者 内容未填写";
  156. return _view;
  157. }
  158. //1.含超时费用/超支费用 手动审核
  159. if (opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支") || opinfos.SelectCheck.Contains("尾款"))
  160. {
  161. _view.Msg = @$"OP费用含尾款/超支/超时费用,请手动审核";
  162. return _view;
  163. }
  164. //1.参数验证
  165. var opCheckPriceTyeps = opinfos.SelectCheck.Split(',');
  166. var opCheckPriceTyepIds = setData.Where(x => opinfos.SelectCheck.Split(',').Contains(x.Name)).Select(x=>x.Id).ToList();
  167. var opContents = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  168. .Where(x => x.IsDel == 0 && x.DiId == diId && x.CTGGRId == dataId && opCheckPriceTyepIds.Contains(x.SId))
  169. .OrderBy(x => x.DatePrice, OrderByType.Asc)
  170. .ToList();
  171. if (opContents.Count < 1)
  172. {
  173. _view.Msg = $"OP费用费用内容未填写";
  174. return _view;
  175. }
  176. //获取C表汇率
  177. decimal _opRate = 1.0000M;
  178. var payInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.IsDel == 0 && x.DIId == diId && x.CTable == 79 && x.CId == dataId).First();
  179. if (payInfo == null)
  180. {
  181. _view.Msg = $"OP费用付款数据未填写";
  182. return _view;
  183. }
  184. _opRate = payInfo.DayRate;
  185. string opCurrencyName = setData.Find(x => x.Id == opContents[0].Currency)?.Name ?? "";
  186. //团组、OP币种 验证是否一致
  187. if (opCurrencyName.Equals(_teamCurrency))
  188. {
  189. _opRate = payInfo.DayRate;
  190. _teamRate = payInfo.DayRate;
  191. }
  192. var opBasicDatas = setData.Where(x => x.STid == 17).ToList(); //费用类型基础数据
  193. bool isAutoAudit = true;
  194. if (!DateTime.TryParse(opinfos.ServiceStartTime, out DateTime startDt1) || !DateTime.TryParse(opinfos.ServiceEndTime, out DateTime endDt1))
  195. {
  196. _view.Msg = $"OP费用服务起止日期格式不正确!";
  197. return _view;
  198. }
  199. DateTime startDt = startDt1;
  200. DateTime endDt = endDt1;
  201. var opCostDatas = costContents.Where(it => Convert.ToDateTime(it.Date) >= startDt && Convert.ToDateTime(it.Date) <= endDt).ToList();
  202. if (opCostDatas.Count < 1)
  203. {
  204. _view.Msg = $"该时间段内团组成本未填写!";
  205. return _view;
  206. }
  207. var noAuditFeeTypeIds = new List<int> {
  208. 982 ,//982 车超时费 -- 暂无
  209. 96 ,//96 接送机费 -- 暂无
  210. 97 ,//97 其他费用 -- 暂无
  211. 992 ,//992 住补费用 -- 暂无
  212. 1059,//1059 导游超时费用 -- 暂无
  213. 1070,//1070 尾款金额 -- 暂无
  214. 1071,//1071 其他额外费用 -- 暂无
  215. 1073,//1073 翻译超时费 -- 暂无
  216. 1074,//1074 早餐超支费用 -- 暂无
  217. 1075,//1075 午餐超支费用 -- 暂无
  218. 1076,//1076 晚餐超支费用 -- 暂无
  219. };
  220. //费用类型筛选 包含 feeTypeIds && 包含这些类型费用大于0
  221. var noAuditFeeContents = opContents.Where(x => x.Price > 0 && noAuditFeeTypeIds.Contains(x.SId)).ToList();
  222. if (noAuditFeeContents.Count > 0)
  223. {
  224. _view.Msg = @$"OP费用含尾款/超支/超时费用,请手动审核";
  225. return _view;
  226. }
  227. //2.按天按项 检查费用是否超过预算
  228. var opDayContent = opContents.GroupBy(x => x.DatePrice);
  229. foreach (var item in opDayContent)
  230. {
  231. var opCostInfo = opCostDatas.Where(x => Convert.ToDateTime(x.Date) == item.Key).ToList();
  232. if (opCostInfo.Count < 1) continue;
  233. //车费 91
  234. var opCarCost = item.FirstOrDefault(x => x.SId == 91);
  235. if (opCarCost != null) if (opCarCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.CarFee)) isAutoAudit = false;
  236. //982 车超时费 -- 暂无
  237. //92 导游费
  238. var opGuideCost = item.FirstOrDefault(x => x.SId == 92);
  239. if (opGuideCost != null) if (opGuideCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.GuideFee)) isAutoAudit = false;
  240. //94 导游景点费
  241. var opGuideScenicCost = item.FirstOrDefault(x => x.SId == 94);
  242. if (opGuideScenicCost != null) if (opGuideScenicCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.GuideScenicFee)) isAutoAudit = false;
  243. //95 导游小费
  244. var opGuideTipCost = item.FirstOrDefault(x => x.SId == 95);
  245. if (opGuideTipCost != null) if (opGuideTipCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.GuideTipFee)) isAutoAudit = false;
  246. //983 导游餐补
  247. var opGuideMealCost = item.FirstOrDefault(x => x.SId == 983);
  248. if (opGuideMealCost != null) if (opGuideMealCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.GuideMealFee)) isAutoAudit = false;
  249. //984 导游房补
  250. var opGuideRoomCost = item.FirstOrDefault(x => x.SId == 984);
  251. if (opGuideRoomCost != null) if (opGuideRoomCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.GuideRoomFee)) isAutoAudit = false;
  252. //985 导游交通
  253. var opGuideTrafficCost = item.FirstOrDefault(x => x.SId == 985);
  254. if (opGuideTrafficCost != null) if (opGuideTrafficCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.GuideTrafficFee)) isAutoAudit = false;
  255. //96 接送机费 -- 暂无
  256. //97 其他费用 -- 暂无
  257. //979 司机工资
  258. var opDriverCost = item.FirstOrDefault(x => x.SId == 979);
  259. if (opDriverCost != null) if (opDriverCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.DriverFee)) isAutoAudit = false;
  260. //980 司机小费
  261. var opDriverTipCost = item.FirstOrDefault(x => x.SId == 980);
  262. if (opDriverTipCost != null) if (opDriverTipCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.DriverTipFee)) isAutoAudit = false;
  263. //981 司机餐补
  264. var opDriverMealCost = item.FirstOrDefault(x => x.SId == 981);
  265. if (opDriverMealCost != null) if (opDriverMealCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.DriverMealFee)) isAutoAudit = false;
  266. //988 客户早餐费用
  267. var opClientBreakfastCost = item.FirstOrDefault(x => x.SId == 988);
  268. if (opClientBreakfastCost != null) if (opClientBreakfastCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.ClientBreakfastFee)) isAutoAudit = false;
  269. //93 客户午餐费用
  270. var opClientLunchCost = item.FirstOrDefault(x => x.SId == 93);
  271. if (opClientLunchCost != null) if (opClientLunchCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.ClientLunchFee)) isAutoAudit = false;
  272. //989 客户晚餐费用
  273. var opClientDinnerCost = item.FirstOrDefault(x => x.SId == 989);
  274. if (opClientDinnerCost != null) if (opClientDinnerCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.ClientDinnerFee)) isAutoAudit = false;
  275. //990 景点门票费
  276. var opScenicTicketCost = item.FirstOrDefault(x => x.SId == 990);
  277. if (opScenicTicketCost != null) if (opScenicTicketCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.ScenicTicketFee)) isAutoAudit = false;
  278. //991 饮料/零食/水果
  279. var opDrinkSnackFruitCost = item.FirstOrDefault(x => x.SId == 991);
  280. if (opDrinkSnackFruitCost != null) if (opDrinkSnackFruitCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.DrinkSnackFruitFee)) isAutoAudit = false;
  281. //992 住补费用 -- 暂无
  282. //994 翻译费
  283. var opTranslatorCost = item.FirstOrDefault(x => x.SId == 994);
  284. if (opTranslatorCost != null) if (opTranslatorCost.Price * _opRate > _teamRate * opCostInfo.Sum(x => x.TranslatorFee)) isAutoAudit = false;
  285. //1059 导游超时费用 -- 暂无
  286. //1070 尾款金额 -- 暂无
  287. //1071 其他额外费用 -- 暂无
  288. //1073 翻译超时费 -- 暂无
  289. //1074 早餐超支费用 -- 暂无
  290. //1075 午餐超支费用 -- 暂无
  291. //1076 晚餐超支费用 -- 暂无
  292. }
  293. //更改审核状态
  294. if (isAutoAudit)
  295. {
  296. var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  297. .SetColumns(it => it.IsAuditGM == 3)
  298. .SetColumns(it => it.AuditGMOperate == 4)
  299. .SetColumns(it => it.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  300. .Where(s => s.DIId == diId && s.CTable == 79 && s.CId == dataId)
  301. .ExecuteCommand();
  302. if (ccpUpdate > 0)
  303. {
  304. _view.Code = 200;
  305. _view.Msg = "自动审核执行成功!";
  306. return _view;
  307. }
  308. }
  309. else
  310. {
  311. //撤销该条数据的自动审核 --> 该条数据的审核状态是自动审核 3 --> 0
  312. if (QuashAudit(79,diId,dataId))
  313. {
  314. _view.Code = 200;
  315. _view.Msg = "费用超团组成本,自动审核撤销成功!";
  316. return _view;
  317. }
  318. }
  319. }
  320. else _view.Msg = $"请传入有效的feeType参数";
  321. return _view;
  322. }
  323. /// <summary>
  324. /// hotel、op 撤销自动审核的数据
  325. /// </summary>
  326. /// <param name="type">
  327. /// 酒店 76
  328. /// op 79
  329. /// </param>
  330. /// <param name="diId"></param>
  331. /// <param name="dataId"></param>
  332. /// <returns></returns>
  333. private bool QuashAudit(int type, int diId, int dataId)
  334. {
  335. //撤销该条数据的自动审核 --> 该条数据的审核状态是自动审核 3 --> 0
  336. var ccpInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>()
  337. .Where(s => s.DIId == diId && s.CTable == type && s.CId == dataId && s.IsAuditGM == 3)
  338. .First();
  339. if (ccpInfo != null)
  340. {
  341. var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  342. .SetColumns(it => it.IsAuditGM == 0)
  343. .SetColumns(it => it.AuditGMOperate == 0)
  344. .SetColumns(it => it.AuditGMDate == string.Empty)
  345. .Where(s => s.Id == ccpInfo.Id)
  346. .ExecuteCommand();
  347. if (ccpUpdate > 0)
  348. {
  349. return true;
  350. }
  351. }
  352. return false;
  353. }
  354. //
  355. /// <summary>
  356. /// 费用自动审核
  357. /// </summary>
  358. /// <param name="feeType">
  359. /// 1.酒店 76
  360. /// 2.op 79
  361. /// </param>
  362. /// <param name="diId">团组Id</param>
  363. /// <param name="dataId">数据Id(模块类型主表Id)</param>
  364. /// <returns></returns>
  365. public string IsOverBudget(int feeType, int diId, int dataId)
  366. {
  367. string _view ="-";
  368. if (diId < 1) { return _view; }
  369. if (dataId < 1) { return _view; }
  370. List<int> stids = new List<int>() { 17, 66 };
  371. var setData = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && stids.Contains(x.STid)).ToList();
  372. string _teamCurrency = string.Empty;
  373. var groupInfo = _sqlSugar.Queryable<Grp_GroupCostParameter>().Where(x => x.IsDel == 0 && x.DiId == diId).First();
  374. if (groupInfo == null) { return _view; }
  375. _teamCurrency = groupInfo.Currency;
  376. //币种验证 统一为currencycode三字码
  377. if (int.TryParse(_teamCurrency, out int currency)) _teamCurrency = setData.Find(x => x.Id == currency)?.Name ?? "";
  378. string costContentSql = $"Select * From Grp_GroupCost";
  379. var costContents = _sqlSugar.SqlQueryable<GroupCostAuditView>(costContentSql).Where(x => x.IsDel == 0 && x.Diid == diId).ToList();
  380. if (costContents.Count < 1) { return _view; }
  381. //处理 成本详细信息 日期为空
  382. for (int i = 0; i < costContents.Count; i++)
  383. {
  384. if (string.IsNullOrEmpty(costContents[i].Date))
  385. {
  386. int index = i - 1;
  387. if (index >= 0)
  388. {
  389. costContents[i].Date = costContents[index].Date;
  390. }
  391. }
  392. }
  393. if (feeType == 1)
  394. {
  395. var hotelCostInfo = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId).First();
  396. var hotelCostDetails = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(x => x.IsDel == 0 && x.DiId == diId && x.HrId == dataId).ToList();
  397. if (hotelCostInfo == null) return _view;
  398. //获取C表汇率
  399. decimal _rate = 1.0000M;
  400. var roomFeeInfo = hotelCostDetails.Where(x => x.PriceType == 1).First();
  401. if (roomFeeInfo == null) return _view;
  402. _rate = roomFeeInfo.Rate == 0.0000M ? 1.0000M : roomFeeInfo.Rate;
  403. bool isAutoAudit = true; //是否自动审核
  404. DateTime checkIn = Convert.ToDateTime(hotelCostInfo.CheckInDate),
  405. checkOut = Convert.ToDateTime(hotelCostInfo.CheckOutDate);
  406. if (checkOut > checkIn) checkOut = checkOut.AddDays(-1); //房费计算,结束日期为前一天
  407. var hotelCostInfos = costContents.Where(x => Convert.ToDateTime(x.Date) >= checkIn && Convert.ToDateTime(x.Date) <= checkOut).ToList();
  408. if (hotelCostInfos.Count < 1) isAutoAudit = false;
  409. decimal otherFee = hotelCostDetails.Where(x => x.PriceType != 1).Sum(x => x.Price * (x.Rate == 0.0000M ? 1.0000M : x.Rate));
  410. if (otherFee > 0) { otherFee /= (checkOut - checkIn).Days; }
  411. var hotelCostInfosGroup = hotelCostInfos.GroupBy(x => x.Date);
  412. foreach (var item in hotelCostInfosGroup)
  413. {
  414. decimal hotelSingleRoomFee = item.Sum(x => x.HotelSingleRoomFee);
  415. decimal hotelDoubleRoomFee = item.Sum(x => x.HotelDoubleRoomFee);
  416. decimal hotelSuiteFee = item.Sum(x => x.HotelSuiteFee);
  417. decimal hotelSuiteRoomFee = item.Sum(x => x.HotelSuiteRoomFee);
  418. //1.判断费用是否 <= 成本费用
  419. //1.1 判断单间费用
  420. decimal singleRoomPrice = (hotelCostInfo.SingleRoomPrice + otherFee) * _rate;
  421. if (singleRoomPrice > 0) if (singleRoomPrice > hotelSingleRoomFee * _rate) isAutoAudit = false;
  422. //1.2 判断双人间费用
  423. decimal doubleRoomPrice = (hotelCostInfo.DoubleRoomPrice + otherFee) * _rate;
  424. if (doubleRoomPrice > 0) if (doubleRoomPrice > hotelDoubleRoomFee * _rate) isAutoAudit = false;
  425. //1.3 判断套房费用
  426. decimal suiteRoomPrice = (hotelCostInfo.SuiteRoomPrice + otherFee) * _rate;
  427. if (suiteRoomPrice > 0) if (suiteRoomPrice > hotelSuiteFee * _rate) isAutoAudit = false;
  428. //1.4 判断其他房型费用
  429. decimal otherRoomPrice = (hotelCostInfo.OtherRoomPrice + otherFee) * _rate;
  430. if (otherRoomPrice > 0) if (otherRoomPrice > hotelSuiteRoomFee * _rate) isAutoAudit = false;
  431. }
  432. //2.判断是否自动审核
  433. if (isAutoAudit)
  434. {
  435. return $"未超预算";
  436. }
  437. }
  438. else if (feeType == 2)
  439. {
  440. //1.基础数据参数验证
  441. var priceType = new List<int>() { 1062 };
  442. var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  443. .Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId && !priceType.Contains(x.PriceType))
  444. .First();
  445. //var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  446. // .Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId )
  447. // .First();
  448. if (opinfos == null) return _view;
  449. //1.含超时费用/超支费用 手动审核
  450. if (opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支") || opinfos.SelectCheck.Contains("尾款")) return _view;
  451. //1.参数验证
  452. var opCheckPriceTyeps = opinfos.SelectCheck.Split(',');
  453. var opCheckPriceTyepIds = setData.Where(x => opinfos.SelectCheck.Split(',').Contains(x.Name)).Select(x => x.Id).ToList();
  454. var opContents = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  455. .Where(x => x.IsDel == 0 && x.DiId == diId && x.CTGGRId == dataId && opCheckPriceTyepIds.Contains(x.SId))
  456. .OrderBy(x => x.DatePrice, OrderByType.Asc)
  457. .ToList();
  458. if (opContents.Count < 1) return _view;
  459. //获取C表汇率
  460. decimal _rate = 1.0000M;
  461. var payInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.IsDel == 0 && x.DIId == diId && x.CTable == 79 && x.Id == dataId).First();
  462. if (payInfo == null) return _view;
  463. _rate = payInfo.DayRate;
  464. string opCurrencyName = setData.Find(x => x.Id == opContents[0].Currency)?.Name ?? "";
  465. var opBasicDatas = setData.Where(x => x.STid == 17).ToList(); //费用类型基础数据
  466. bool isAutoAudit = true;
  467. if (!DateTime.TryParse(opinfos.ServiceStartTime, out DateTime startDt1) || !DateTime.TryParse(opinfos.ServiceEndTime, out DateTime endDt1)) return _view;
  468. DateTime startDt = startDt1;
  469. DateTime endDt = endDt1;
  470. var opCostDatas = costContents.Where(it => Convert.ToDateTime(it.Date) >= startDt && Convert.ToDateTime(it.Date) <= endDt).ToList();
  471. if (opCostDatas.Count < 1) return _view;
  472. var noAuditFeeTypeIds = new List<int> {
  473. 982 ,//982 车超时费 -- 暂无
  474. 96 ,//96 接送机费 -- 暂无
  475. 97 ,//97 其他费用 -- 暂无
  476. 992 ,//992 住补费用 -- 暂无
  477. 1059,//1059 导游超时费用 -- 暂无
  478. 1070,//1070 尾款金额 -- 暂无
  479. 1071,//1071 其他额外费用 -- 暂无
  480. 1073,//1073 翻译超时费 -- 暂无
  481. 1074,//1074 早餐超支费用 -- 暂无
  482. 1075,//1075 午餐超支费用 -- 暂无
  483. 1076,//1076 晚餐超支费用 -- 暂无
  484. };
  485. //费用类型筛选 包含 feeTypeIds && 包含这些类型费用大于0
  486. var noAuditFeeContents = opContents.Where(x => x.Price > 0 && noAuditFeeTypeIds.Contains(x.SId)).ToList();
  487. if (noAuditFeeContents.Count > 0) return _view;
  488. //2.按天按项 检查费用是否超过预算
  489. var opDayContent = opContents.GroupBy(x => x.DatePrice);
  490. foreach (var item in opDayContent)
  491. {
  492. var opCostInfo = opCostDatas.Where(x => Convert.ToDateTime(x.Date) == item.Key).ToList();
  493. if (opCostInfo.Count < 1) continue;
  494. //车费 91
  495. var opCarCost = item.FirstOrDefault(x => x.SId == 91);
  496. if (opCarCost != null) if (opCarCost.Price * _rate > _rate * opCostInfo.Sum(x => x.CarFee)) isAutoAudit = false;
  497. //982 车超时费 -- 暂无
  498. //92 导游费
  499. var opGuideCost = item.FirstOrDefault(x => x.SId == 92);
  500. if (opGuideCost != null) if (opGuideCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideFee)) isAutoAudit = false;
  501. //94 导游景点费
  502. var opGuideScenicCost = item.FirstOrDefault(x => x.SId == 94);
  503. if (opGuideScenicCost != null) if (opGuideScenicCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideScenicFee)) isAutoAudit = false;
  504. //95 导游小费
  505. var opGuideTipCost = item.FirstOrDefault(x => x.SId == 95);
  506. if (opGuideTipCost != null) if (opGuideTipCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideTipFee)) isAutoAudit = false;
  507. //983 导游餐补
  508. var opGuideMealCost = item.FirstOrDefault(x => x.SId == 983);
  509. if (opGuideMealCost != null) if (opGuideMealCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideMealFee)) isAutoAudit = false;
  510. //984 导游房补
  511. var opGuideRoomCost = item.FirstOrDefault(x => x.SId == 984);
  512. if (opGuideRoomCost != null) if (opGuideRoomCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideRoomFee)) isAutoAudit = false;
  513. //985 导游交通
  514. var opGuideTrafficCost = item.FirstOrDefault(x => x.SId == 985);
  515. if (opGuideTrafficCost != null) if (opGuideTrafficCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideTrafficFee)) isAutoAudit = false;
  516. //96 接送机费 -- 暂无
  517. //97 其他费用 -- 暂无
  518. //979 司机工资
  519. var opDriverCost = item.FirstOrDefault(x => x.SId == 979);
  520. if (opDriverCost != null) if (opDriverCost.Price * _rate > _rate * opCostInfo.Sum(x => x.DriverFee)) isAutoAudit = false;
  521. //980 司机小费
  522. var opDriverTipCost = item.FirstOrDefault(x => x.SId == 980);
  523. if (opDriverTipCost != null) if (opDriverTipCost.Price * _rate > _rate * opCostInfo.Sum(x => x.DriverTipFee)) isAutoAudit = false;
  524. //981 司机餐补
  525. var opDriverMealCost = item.FirstOrDefault(x => x.SId == 981);
  526. if (opDriverMealCost != null) if (opDriverMealCost.Price * _rate > _rate * opCostInfo.Sum(x => x.DriverMealFee)) isAutoAudit = false;
  527. //988 客户早餐费用
  528. var opClientBreakfastCost = item.FirstOrDefault(x => x.SId == 988);
  529. if (opClientBreakfastCost != null) if (opClientBreakfastCost.Price * _rate > _rate * opCostInfo.Sum(x => x.ClientBreakfastFee)) isAutoAudit = false;
  530. //93 客户午餐费用
  531. var opClientLunchCost = item.FirstOrDefault(x => x.SId == 93);
  532. if (opClientLunchCost != null) if (opClientLunchCost.Price * _rate > _rate * opCostInfo.Sum(x => x.ClientLunchFee)) isAutoAudit = false;
  533. //989 客户晚餐费用
  534. var opClientDinnerCost = item.FirstOrDefault(x => x.SId == 989);
  535. if (opClientDinnerCost != null) if (opClientDinnerCost.Price * _rate > _rate * opCostInfo.Sum(x => x.ClientDinnerFee)) isAutoAudit = false;
  536. //990 景点门票费
  537. var opScenicTicketCost = item.FirstOrDefault(x => x.SId == 990);
  538. if (opScenicTicketCost != null) if (opScenicTicketCost.Price * _rate > _rate * opCostInfo.Sum(x => x.ScenicTicketFee)) isAutoAudit = false;
  539. //991 饮料/零食/水果
  540. var opDrinkSnackFruitCost = item.FirstOrDefault(x => x.SId == 991);
  541. if (opDrinkSnackFruitCost != null) if (opDrinkSnackFruitCost.Price * _rate > _rate * opCostInfo.Sum(x => x.DrinkSnackFruitFee)) isAutoAudit = false;
  542. //992 住补费用 -- 暂无
  543. //994 翻译费
  544. var opTranslatorCost = item.FirstOrDefault(x => x.SId == 994);
  545. if (opTranslatorCost != null) if (opTranslatorCost.Price * _rate > _rate * opCostInfo.Sum(x => x.TranslatorFee)) isAutoAudit = false;
  546. //1059 导游超时费用 -- 暂无
  547. //1070 尾款金额 -- 暂无
  548. //1071 其他额外费用 -- 暂无
  549. //1073 翻译超时费 -- 暂无
  550. //1074 早餐超支费用 -- 暂无
  551. //1075 午餐超支费用 -- 暂无
  552. //1076 晚餐超支费用 -- 暂无
  553. }
  554. //更改审核状态
  555. if (isAutoAudit) return _view;
  556. }
  557. else return _view;
  558. return _view;
  559. }
  560. }
  561. }