FeeAuditRepository.cs 35 KB

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