FeeAuditRepository.cs 34 KB

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