FeeAuditRepository.cs 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093
  1. using EyeSoft.Extensions;
  2. using OASystem.Domain;
  3. using OASystem.Domain.Entities.Groups;
  4. using OASystem.Domain.Entities.Resource;
  5. using OASystem.Domain.ViewModels.Groups;
  6. namespace OASystem.Infrastructure.Repositories.Groups
  7. {
  8. /// <summary>
  9. /// 费用审核仓储
  10. /// </summary>
  11. public class FeeAuditRepository : BaseRepository<EntityBase, ViewBase>
  12. {
  13. public FeeAuditRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
  14. {
  15. }
  16. /// <summary>
  17. /// 费用自动审核
  18. /// </summary>
  19. /// <param name="feeType">
  20. /// 1.酒店 76
  21. /// 2.op 79
  22. /// 3.其他费用-出行物资 98
  23. /// 4.保险 82
  24. /// 5.机票 85
  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. var groupDetails = _sqlSugar.Queryable<Grp_DelegationInfo>().Where(x => x.IsDel == 0 && x.Id == diId).First();
  35. if (groupDetails == null)
  36. {
  37. _view.Msg = $"团组信息为空,不可自动审核!";
  38. return _view;
  39. }
  40. var stids = new List<int>() { 17, 66, 91 };
  41. var setData = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && stids.Contains(x.STid)).ToList();
  42. var groupInfo = new Grp_GroupCostParameter();
  43. string _teamCurrency = string.Empty;
  44. decimal _teamRate = 1.0000M;
  45. var costContents = new List<GroupCostAuditView>();
  46. var subFeeTypeIds = new int[] {
  47. 4, // 保险 82
  48. 5, // 机票 85
  49. };
  50. if (!subFeeTypeIds.Contains(feeType))
  51. {
  52. groupInfo = _sqlSugar.Queryable<Grp_GroupCostParameter>().Where(x => x.IsDel == 0 && x.DiId == diId).First();
  53. if (groupInfo == null) { _view.Msg = $"团组成本信息未填写!"; return _view; }
  54. _teamCurrency = groupInfo.Currency;
  55. _teamRate = groupInfo.Rate;
  56. //币种验证 统一为currencycode三字码
  57. if (int.TryParse(_teamCurrency, out int currency)) _teamCurrency = setData.Find(x => x.Id == currency)?.Name ?? "";
  58. string costContentSql = $"Select * From Grp_GroupCost";
  59. costContents = _sqlSugar.SqlQueryable<GroupCostAuditView>(costContentSql).Where(x => x.IsDel == 0 && x.Diid == diId).ToList();
  60. if (costContents.Count < 1) { _view.Msg = $"团组成本信息未填写!"; return _view; }
  61. //处理 成本详细信息 日期为空
  62. for (int i = 0; i < costContents.Count; i++)
  63. {
  64. if (string.IsNullOrEmpty(costContents[i].Date))
  65. {
  66. int index = i - 1;
  67. if (index >= 0)
  68. {
  69. costContents[i].Date = costContents[index].Date;
  70. var dtBool = DateTime.TryParse(costContents[i].Date, out DateTime _dateTime);
  71. if (dtBool)
  72. {
  73. costContents[i].CurrTime = _dateTime;
  74. }
  75. }
  76. }
  77. else
  78. {
  79. var dtBool = DateTime.TryParse(costContents[i].Date, out DateTime _dateTime);
  80. if (dtBool)
  81. {
  82. costContents[i].CurrTime = _dateTime;
  83. }
  84. }
  85. }
  86. }
  87. if (feeType == 1)
  88. {
  89. //1089 对冲账或其他 不在审核范围
  90. var hotelCostInfo = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId && x.CheckType != 1089).First();
  91. var hotelCostDetails = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(x => x.IsDel == 0 && x.DiId == diId && x.HrId == dataId).ToList();
  92. if (hotelCostInfo == null)
  93. {
  94. _view.Msg = $"酒店费用数据未填写";
  95. QuashAudit(76, diId, dataId);
  96. return _view;
  97. }
  98. //酒店费用金额 == 0 不自动审核
  99. if (hotelCostInfo.CardPrice == 0.0000M)
  100. {
  101. _view.Msg = $"酒店费用金额 == 0 不自动审核";
  102. QuashAudit(76, diId, dataId);
  103. return _view;
  104. }
  105. //获取C表汇率
  106. decimal _rate = 1.0000M;
  107. var roomFeeInfo = hotelCostDetails.Where(x => x.PriceType == 1).First();
  108. if (roomFeeInfo == null)
  109. {
  110. _view.Msg = $"酒店房间费用付款数据未填写";
  111. return _view;
  112. }
  113. _rate = roomFeeInfo.Rate == 0.0000M ? 1.0000M : roomFeeInfo.Rate;
  114. bool isAutoAudit = true; //是否自动审核
  115. DateTime checkIn = Convert.ToDateTime(hotelCostInfo.CheckInDate),
  116. checkOut = Convert.ToDateTime(hotelCostInfo.CheckOutDate);
  117. if (checkOut > checkIn) checkOut = checkOut.AddDays(-1); //房费计算,结束日期为前一天
  118. var hotelCostInfos = costContents.Where(x => x.CurrTime >= checkIn && x.CurrTime <= checkOut).ToList();
  119. if (hotelCostInfos.Count < 1) isAutoAudit = false;
  120. #region 其他费用(早餐、地税、城市税) 按照个人计算 2025-07-01 14:07:25
  121. decimal otherFee = hotelCostDetails.Where(x => x.PriceType != 1).Sum(x => x.Price * (x.Rate == 0.0000M ? 1.0000M : x.Rate));
  122. int guestCount = 0;
  123. if (hotelCostInfo.GuestName.Contains(',')) guestCount = hotelCostInfo.GuestName.Split(",").Length;
  124. else guestCount = 1;
  125. if (otherFee > 0) otherFee /= guestCount;
  126. #endregion
  127. var hotelCostInfosGroup = hotelCostInfos.GroupBy(x => x.Date);
  128. foreach (var item in hotelCostInfosGroup)
  129. {
  130. var hotelSingleRoomFee = item.Sum(x => x.HotelSingleRoomFee) * _teamRate; //成本单间费用
  131. var hotelDoubleRoomFee = item.Sum(x => x.HotelDoubleRoomFee) * _teamRate; //成本双人间费用
  132. var hotelSuiteFee = item.Sum(x => x.HotelSuiteFee) * _teamRate; //成本套房费用
  133. var hotelSuiteRoomFee = item.Sum(x => x.HotelSuiteRoomFee) * _teamRate; //成本其他房型间费用
  134. //1.判断费用是否 <= 成本费用
  135. //1.1 判断单间费用
  136. if (hotelCostInfo.SingleRoomPrice > 0)
  137. {
  138. decimal singleRoomPrice = (hotelCostInfo.SingleRoomPrice + otherFee) * _rate; //酒店录入费用
  139. if (singleRoomPrice > hotelSingleRoomFee) isAutoAudit = false;
  140. }
  141. //1.2 判断双人间费用
  142. if (hotelCostInfo.DoubleRoomPrice > 0)
  143. {
  144. decimal doubleRoomPrice = (hotelCostInfo.DoubleRoomPrice + otherFee) * _rate;//酒店录入费用
  145. if (doubleRoomPrice > hotelDoubleRoomFee) isAutoAudit = false;
  146. }
  147. //1.3 判断套房费用
  148. if (hotelCostInfo.SuiteRoomPrice > 0)
  149. {
  150. decimal suiteRoomPrice = (hotelCostInfo.SuiteRoomPrice + otherFee) * _rate;//酒店录入费用
  151. if (suiteRoomPrice > hotelSuiteFee) isAutoAudit = false;
  152. }
  153. //1.4 判断其他房型费用
  154. if (hotelCostInfo.OtherRoomPrice > 0)
  155. {
  156. decimal otherRoomPrice = (hotelCostInfo.OtherRoomPrice + otherFee) * _rate;//酒店录入费用
  157. if (otherRoomPrice > hotelSuiteRoomFee) isAutoAudit = false;
  158. }
  159. }
  160. //2.判断是否自动审核
  161. if (isAutoAudit)
  162. {
  163. var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  164. .SetColumns(it => it.IsAuditGM == 3)
  165. .SetColumns(it => it.AuditGMOperate == 4)
  166. .SetColumns(it => it.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  167. .Where(s => s.DIId == diId && s.CTable == 76 && s.CId == dataId)
  168. .ExecuteCommand();
  169. if (ccpUpdate > 0)
  170. {
  171. _view.Code = 200;
  172. _view.Msg = "自动审核执行成功";
  173. return _view;
  174. }
  175. }
  176. else
  177. {
  178. //撤销该条数据的自动审核 --> 该条数据的审核状态是自动审核 3 --> 0
  179. var quashStatus = QuashAudit(76, diId, dataId);
  180. if (quashStatus)
  181. {
  182. _view.Code = 200;
  183. _view.Msg = "费用超团组成本,自动审核撤销成功!";
  184. return _view;
  185. }
  186. }
  187. }
  188. else if (feeType == 2)
  189. {
  190. //1.基础数据参数验证
  191. var priceType = new List<int>() {
  192. 1062 //1062 尾款
  193. };
  194. var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  195. .Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId && !priceType.Contains(x.PriceType))
  196. .First();
  197. //var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  198. // .Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId )
  199. // .First();
  200. if (opinfos == null)
  201. {
  202. _view.Msg = $"OP费用费用类型属于“尾款”或者 内容未填写";
  203. return _view;
  204. }
  205. //1.含超时费用/超支费用 手动审核
  206. if (opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支") || opinfos.SelectCheck.Contains("尾款"))
  207. {
  208. _view.Msg = @$"OP费用含尾款/超支/超时费用,请手动审核";
  209. return _view;
  210. }
  211. //1.参数验证
  212. var opCheckPriceTyeps = opinfos.SelectCheck.Split(',');
  213. var opCheckPriceTyepIds = setData.Where(x => opinfos.SelectCheck.Split(',').Contains(x.Name)).Select(x => x.Id).ToList();
  214. var opContents = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  215. .Where(x => x.IsDel == 0 && x.DiId == diId && x.CTGGRId == dataId && opCheckPriceTyepIds.Contains(x.SId))
  216. .OrderBy(x => x.DatePrice, OrderByType.Asc)
  217. .ToList();
  218. if (opContents.Count < 1)
  219. {
  220. _view.Msg = $"OP费用费用内容未填写";
  221. return _view;
  222. }
  223. //获取C表汇率
  224. decimal _opRate = 1.0000M;
  225. decimal _opPayPercentage = 1.0000M;
  226. var payInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.IsDel == 0 && x.DIId == diId && x.CTable == 79 && x.CId == dataId).First();
  227. if (payInfo == null)
  228. {
  229. _view.Msg = $"OP费用付款数据未填写";
  230. return _view;
  231. }
  232. _opRate = payInfo.DayRate;
  233. _opPayPercentage = payInfo.PayPercentage / 100.00M;
  234. string opCurrencyName = setData.Find(x => x.Id == opContents[0].Currency)?.Name ?? "";
  235. //团组、OP币种 验证是否一致(一致:只比较金额,不计算汇率(2024-04-18))
  236. if (opCurrencyName.Equals(_teamCurrency))
  237. {
  238. _opRate = payInfo.DayRate;
  239. _teamRate = payInfo.DayRate;
  240. }
  241. var opBasicDatas = setData.Where(x => x.STid == 17).ToList(); //费用类型基础数据
  242. bool isAutoAudit = true;
  243. if (!DateTime.TryParse(opinfos.ServiceStartTime, out DateTime startDt1) || !DateTime.TryParse(opinfos.ServiceEndTime, out DateTime endDt1))
  244. {
  245. _view.Msg = $"OP费用服务起止日期格式不正确!";
  246. return _view;
  247. }
  248. DateTime startDt = startDt1;
  249. DateTime endDt = endDt1;
  250. var opCostDatas = costContents.Where(it => Convert.ToDateTime(it.Date) >= startDt && Convert.ToDateTime(it.Date) <= endDt).ToList();
  251. if (opCostDatas.Count < 1)
  252. {
  253. _view.Msg = $"该时间段内团组成本未填写!";
  254. return _view;
  255. }
  256. var noAuditFeeTypeIds = new List<int> {
  257. 982 ,//982 车超时费 -- 暂无
  258. 96 ,//96 接送机费 -- 暂无
  259. 97 ,//97 其他费用 -- 暂无
  260. 992 ,//992 住补费用 -- 暂无
  261. 1059,//1059 导游超时费用 -- 暂无
  262. 1070,//1070 尾款金额 -- 暂无
  263. 1071,//1071 其他额外费用 -- 暂无
  264. 1073,//1073 翻译超时费 -- 暂无
  265. 1074,//1074 早餐超支费用 -- 暂无
  266. 1075,//1075 午餐超支费用 -- 暂无
  267. 1076,//1076 晚餐超支费用 -- 暂无
  268. };
  269. //费用类型筛选 包含 feeTypeIds && 包含这些类型费用大于0
  270. var noAuditFeeContents = opContents.Where(x => x.Price > 0 && noAuditFeeTypeIds.Contains(x.SId)).ToList();
  271. if (noAuditFeeContents.Count > 0)
  272. {
  273. _view.Msg = @$"OP费用含尾款/超支/超时费用,请手动审核";
  274. return _view;
  275. }
  276. //2.按天按项 检查费用是否超过预算
  277. var opDayContent = opContents.GroupBy(x => x.DatePrice);
  278. foreach (var item in opDayContent)
  279. {
  280. var opCostInfo = opCostDatas.Where(x => Convert.ToDateTime(x.Date) == item.Key).ToList();
  281. if (opCostInfo.Count < 1) continue;
  282. //车费 91
  283. var opCarCost = item.FirstOrDefault(x => x.SId == 91);
  284. if (opCarCost != null)
  285. if (opCarCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.CarFee) * _opPayPercentage) isAutoAudit = false;
  286. //982 车超时费 -- 暂无
  287. //92 导游费
  288. var opGuideCost = item.FirstOrDefault(x => x.SId == 92);
  289. if (opGuideCost != null)
  290. if (opGuideCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.GuideFee) * _opPayPercentage) isAutoAudit = false;
  291. //94 导游景点费
  292. var opGuideScenicCost = item.FirstOrDefault(x => x.SId == 94);
  293. if (opGuideScenicCost != null)
  294. if (opGuideScenicCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.GuideScenicFee) * _opPayPercentage) isAutoAudit = false;
  295. //95 导游小费
  296. var opGuideTipCost = item.FirstOrDefault(x => x.SId == 95);
  297. if (opGuideTipCost != null)
  298. if (opGuideTipCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.GuideTipFee) * _opPayPercentage) isAutoAudit = false;
  299. //983 导游餐补
  300. var opGuideMealCost = item.FirstOrDefault(x => x.SId == 983);
  301. if (opGuideMealCost != null)
  302. if (opGuideMealCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.GuideMealFee) * _opPayPercentage) isAutoAudit = false;
  303. //984 导游房补
  304. var opGuideRoomCost = item.FirstOrDefault(x => x.SId == 984);
  305. if (opGuideRoomCost != null)
  306. if (opGuideRoomCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.GuideRoomFee) * _opPayPercentage) isAutoAudit = false;
  307. //985 导游交通
  308. var opGuideTrafficCost = item.FirstOrDefault(x => x.SId == 985);
  309. if (opGuideTrafficCost != null)
  310. if (opGuideTrafficCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.GuideTrafficFee) * _opPayPercentage) isAutoAudit = false;
  311. //96 接送机费 -- 暂无
  312. //97 其他费用 -- 暂无
  313. //979 司机工资
  314. var opDriverCost = item.FirstOrDefault(x => x.SId == 979);
  315. if (opDriverCost != null)
  316. if (opDriverCost.Price * _opRate > _teamRate * _opPayPercentage * opCostInfo.Sum(x => x.DriverFee) * _opPayPercentage) isAutoAudit = false;
  317. //980 司机小费
  318. var opDriverTipCost = item.FirstOrDefault(x => x.SId == 980);
  319. if (opDriverTipCost != null)
  320. if (opDriverTipCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.DriverTipFee) * _opPayPercentage) isAutoAudit = false;
  321. //981 司机餐补
  322. var opDriverMealCost = item.FirstOrDefault(x => x.SId == 981);
  323. if (opDriverMealCost != null)
  324. if (opDriverMealCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.DriverMealFee) * _opPayPercentage) isAutoAudit = false;
  325. //988 客户早餐费用
  326. var opClientBreakfastCost = item.FirstOrDefault(x => x.SId == 988);
  327. if (opClientBreakfastCost != null)
  328. if (opClientBreakfastCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.ClientBreakfastFee) * _opPayPercentage) isAutoAudit = false;
  329. //93 客户午餐费用
  330. var opClientLunchCost = item.FirstOrDefault(x => x.SId == 93);
  331. if (opClientLunchCost != null)
  332. if (opClientLunchCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.ClientLunchFee) * _opPayPercentage) isAutoAudit = false;
  333. //989 客户晚餐费用
  334. var opClientDinnerCost = item.FirstOrDefault(x => x.SId == 989);
  335. if (opClientDinnerCost != null)
  336. if (opClientDinnerCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.ClientDinnerFee) * _opPayPercentage) isAutoAudit = false;
  337. //990 景点门票费
  338. var opScenicTicketCost = item.FirstOrDefault(x => x.SId == 990);
  339. if (opScenicTicketCost != null)
  340. if (opScenicTicketCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.ScenicTicketFee) * _opPayPercentage) isAutoAudit = false;
  341. //991 饮料/零食/水果
  342. var opDrinkSnackFruitCost = item.FirstOrDefault(x => x.SId == 991);
  343. if (opDrinkSnackFruitCost != null)
  344. if (opDrinkSnackFruitCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.DrinkSnackFruitFee) * _opPayPercentage) isAutoAudit = false;
  345. //992 住补费用 -- 暂无
  346. //994 翻译费
  347. var opTranslatorCost = item.FirstOrDefault(x => x.SId == 994);
  348. if (opTranslatorCost != null)
  349. if (opTranslatorCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.TranslatorFee) * _opPayPercentage) isAutoAudit = false;
  350. //1059 导游超时费用 -- 暂无
  351. //1070 尾款金额 -- 暂无
  352. //1071 其他额外费用 -- 暂无
  353. //1073 翻译超时费 -- 暂无
  354. //1074 早餐超支费用 -- 暂无
  355. //1075 午餐超支费用 -- 暂无
  356. //1076 晚餐超支费用 -- 暂无
  357. //1556 零用金
  358. var opCashCost = item.FirstOrDefault(x => x.SId == 1556);
  359. if (opCashCost != null)
  360. if (opCashCost.Price * _opRate * _opPayPercentage > _teamRate * opCostInfo.Sum(x => x.CashFee) * _opPayPercentage) isAutoAudit = false;
  361. }
  362. //更改审核状态
  363. if (isAutoAudit)
  364. {
  365. var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  366. .SetColumns(it => it.IsAuditGM == 3)
  367. .SetColumns(it => it.AuditGMOperate == 4)
  368. .SetColumns(it => it.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  369. .Where(s => s.DIId == diId && s.CTable == 79 && s.CId == dataId)
  370. .ExecuteCommand();
  371. if (ccpUpdate > 0)
  372. {
  373. _view.Code = 200;
  374. _view.Msg = "自动审核执行成功!";
  375. return _view;
  376. }
  377. }
  378. else
  379. {
  380. //撤销该条数据的自动审核 --> 该条数据的审核状态是自动审核 3 --> 0
  381. if (QuashAudit(79, diId, dataId))
  382. {
  383. _view.Code = 200;
  384. _view.Msg = "费用超团组成本,自动审核撤销成功!";
  385. return _view;
  386. }
  387. }
  388. }
  389. else if (feeType == 3)
  390. {
  391. #region 出行物资的功能及相关费用自动审核
  392. var isAutoAudit = false;
  393. var currModule = 98; //其他款项
  394. int groupSize = groupDetails.VisitPNumber;
  395. decimal otherSubTotal = costContents.Sum(x => x.TeFee);
  396. decimal groupCostCNYTotal = costContents.Sum(x => x.TeFee) * _teamRate * groupSize; //团组成本出行物资总金额
  397. if (groupCostCNYTotal <= 0.00M)
  398. {
  399. _view.Msg = $"团组成本出行物资费用数据未填写";
  400. QuashAudit(currModule, diId, dataId);
  401. return _view;
  402. }
  403. var teNames = setData.Where(x => x.STid == 91).Select(x => x.Name).ToList();
  404. var otherFeeDatas = _sqlSugar.Queryable<Grp_DecreasePayments>()
  405. .InnerJoin<Grp_CreditCardPayment>((dp, ccp) => dp.Id == ccp.CId && ccp.CTable == 98 && ccp.IsDel == 0)
  406. .Where((dp, ccp) => dp.IsDel == 0 && ccp.IsDel == 0 && dp.DiId == diId)
  407. .ToList();
  408. var ids = new List<int>();
  409. foreach (var item in otherFeeDatas)
  410. {
  411. if (item.PriceName.Contains('、'))
  412. {
  413. var priceNames = item.PriceName.Split('、');
  414. foreach (var priceName in priceNames)
  415. {
  416. if (teNames.Contains(priceName))
  417. {
  418. ids.Add(item.Id);
  419. continue;
  420. }
  421. }
  422. }
  423. else if (teNames.Contains(item.PriceName))
  424. {
  425. ids.Add(item.Id);
  426. }
  427. }
  428. ids = ids.Distinct().ToList();
  429. //验证该费用是不是出行物资费用 是:审核 不是:不审核
  430. if (!ids.Contains(dataId))
  431. {
  432. _view.Msg = $"该费用不属于出行物资,不执行自动审核!";
  433. QuashAudit(currModule, diId, dataId);
  434. return _view;
  435. }
  436. decimal otherFeeCNYTotal = otherFeeDatas.Where(x => ids.Contains(x.Id)).Sum(x => x.FeeTotal); //其他费用出行物资总金额
  437. if (otherFeeCNYTotal <= 0.00M)
  438. {
  439. _view.Msg = $"其他款项出行物资费用数据未填写";
  440. QuashAudit(currModule, diId, dataId);
  441. return _view;
  442. }
  443. if (otherFeeCNYTotal > groupCostCNYTotal)
  444. {
  445. _view.Msg = $"其他款项出行物资费用超出团组成本物资费用";
  446. QuashAudit(currModule, diId, dataId);
  447. return _view;
  448. }
  449. isAutoAudit = true;
  450. //2.判断是否自动审核
  451. if (isAutoAudit)
  452. {
  453. var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  454. .SetColumns(it => it.IsAuditGM == 3)
  455. .SetColumns(it => it.AuditGMOperate == 4)
  456. .SetColumns(it => it.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  457. .Where(s => s.DIId == diId && s.CTable == currModule && s.CId == dataId)
  458. .ExecuteCommand();
  459. if (ccpUpdate > 0)
  460. {
  461. _view.Code = 200;
  462. _view.Msg = "自动审核执行成功";
  463. return _view;
  464. }
  465. }
  466. else
  467. {
  468. //撤销该条数据的自动审核 --> 该条数据的审核状态是自动审核 3 --> 0
  469. var quashStatus = QuashAudit(currModule, diId, dataId);
  470. if (quashStatus)
  471. {
  472. _view.Code = 200;
  473. _view.Msg = "费用超团组成本,自动审核撤销成功!";
  474. return _view;
  475. }
  476. }
  477. #endregion
  478. }
  479. else if (feeType == 4)
  480. {
  481. #region 保险费用录入自动审核
  482. var currModule = 82;
  483. var insuranceCountryCostData = _sqlSugar.Queryable<Res_BasicInsuranceCost>().Where(x => x.IsDel == 0).ToList();
  484. if (!insuranceCountryCostData.Any())
  485. {
  486. _view.Msg = $"保险国家费用信息为空,不可自动审核!";
  487. return _view;
  488. }
  489. var insuranceType = _sqlSugar.Queryable<Grp_InsuranceCost>().Where(x => x.IsDel == 0 && x.Id != 2).Select(x => x.Id).ToList();
  490. var insuranceCostData1 = _sqlSugar.Queryable<Grp_Customers>()
  491. .LeftJoin<Grp_CreditCardPayment>((c, ccp) => c.Id == ccp.CId && ccp.CTable == 82)
  492. .Where((c, ccp) => c.IsDel == 0 && c.DiId == diId)
  493. .Select((c, ccp) => new
  494. {
  495. c.Id,
  496. c.Iid,
  497. ccpId = ccp.Id,
  498. CNYPrice = ccp.PayMoney * ccp.DayRate
  499. })
  500. .ToList();
  501. if (!insuranceCostData1.Any())
  502. {
  503. _view.Msg = $"暂无保险数据,不可自动审核!";
  504. return _view;
  505. }
  506. if (insuranceCostData1.Where(x => x.Iid == 2).ToList().Any())
  507. {
  508. _view.Msg = $"保险数据为类型为“新数据请不要选此项”,不可自动审核!";
  509. return _view;
  510. }
  511. #region 处理已审核通过的 “新数据请不要选此项” 数据
  512. var insuranceCostData2 = insuranceCostData1.Where(x => x.Iid == 2).ToList();
  513. if (insuranceCostData2.Any())
  514. {
  515. //_view.Msg = $"保险数据为类型为“新数据请不要选此项”,不可自动审核!";
  516. //return _view;
  517. var ccpIds = insuranceCostData2.Select(x => x.ccpId).ToList();
  518. var auditCcpIds = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.IsDel == 0 && ccpIds.Contains(x.Id) && x.IsAuditGM == 3).Select(x => x.Id).ToList();
  519. if (auditCcpIds.Any())
  520. {
  521. var ccpUpd = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  522. .SetColumns(it => it.IsAuditGM == 0)
  523. .SetColumns(it => it.AuditGMOperate == 0)
  524. .SetColumns(it => it.AuditGMDate == string.Empty)
  525. .Where(s => auditCcpIds.Contains(s.Id))
  526. .ExecuteCommand();
  527. }
  528. }
  529. #endregion
  530. //var insuranceCostData = insuranceCostData1.Where(x => insuranceType.Contains(x.Iid)).ToList();
  531. var insuranceCostData = insuranceCostData1.ToList();
  532. var currInsuranceInfo = insuranceCostData.Where(x => x.Id == dataId).FirstOrDefault();
  533. if (!insuranceCostData.Any() && currInsuranceInfo == null)
  534. {
  535. _view.Msg = $"暂无保险数据,不可自动审核!";
  536. return _view;
  537. }
  538. if (currInsuranceInfo.CNYPrice == 0.00M)
  539. {
  540. _view.Msg = $"保险数据未录入费用信息,不可自动审核!";
  541. QuashAudit(currModule, diId, dataId);
  542. return _view;
  543. }
  544. var groupPeopleNum = groupDetails.VisitPNumber;
  545. var visitCountrys = groupDetails.VisitCountry.Split("|").ToList();
  546. if (!visitCountrys.Any())
  547. {
  548. _view.Msg = $"出访国家为空,不可自动审核!";
  549. return _view;
  550. }
  551. var basicCountrys = insuranceCountryCostData.Select(x => x.CountryName).ToList();
  552. var schengenCountry = visitCountrys.Intersect(basicCountrys); //申根国
  553. var unSchengenCountry = visitCountrys.Except(basicCountrys); //非申根国
  554. var schengenCost = insuranceCountryCostData.Where(x => schengenCountry.Contains(x.CountryName)).Sum(x => x.Cost); // 申根国费用
  555. var unSchengenCost = unSchengenCountry.Count() * 35; // 非申根国费用
  556. var groupBudgetCost = (schengenCost + unSchengenCost) * groupPeopleNum;
  557. var groupActialCost = insuranceCostData.Sum(x => x.CNYPrice);
  558. if (groupActialCost > groupBudgetCost)
  559. {
  560. _view.Msg = $"保险费用超出团组成本费用";
  561. QuashAudit(currModule, diId, dataId);
  562. return _view;
  563. }
  564. //自动审核
  565. var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  566. .SetColumns(it => it.IsAuditGM == 3)
  567. .SetColumns(it => it.AuditGMOperate == 4)
  568. .SetColumns(it => it.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  569. .Where(s => s.DIId == diId && s.CTable == currModule && s.CId == dataId)
  570. .ExecuteCommand();
  571. if (ccpUpdate > 0)
  572. {
  573. _view.Code = 200;
  574. _view.Msg = "自动审核执行成功";
  575. }
  576. else _view.Msg = "自动审核执行失败";
  577. return _view;
  578. #endregion
  579. }
  580. else if (feeType == 5)
  581. {
  582. #region 机票费用自动审核只处理舱位相关的费用
  583. var currModule = 85;
  584. var auditFeeTypeIds = new List<int>() {
  585. 457, //头等舱
  586. 458, //公务舱
  587. 459, //超经舱
  588. 460, //经济舱
  589. 1430, //公务舱(实际经济舱)
  590. 1431, //头等舱(实际公务舱)
  591. 1432, //头等舱(实际经济舱)
  592. };
  593. var airInfo = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  594. .InnerJoin<Grp_CreditCardPayment>((x, y) => x.Id == y.CId && y.CTable == currModule && y.IsDel == 0)
  595. .Where((x, y) => x.Id == dataId && x.IsDel == 0 && auditFeeTypeIds.Contains(x.CType))
  596. .Select((x, y) => new
  597. {
  598. x.Id,
  599. CcpId = y.Id,
  600. x.Price,
  601. x.CType,
  602. x.ClientNum,
  603. x.DIId
  604. })
  605. .FirstAsync();
  606. if (airInfo == null)
  607. {
  608. _view.Msg = $"机票信息为空或费用类型不在自动审核范围内,不可自动审核!";
  609. return _view;
  610. }
  611. //团组成本 经济舱、头等舱、公务舱
  612. int ecoPaxCount = groupInfo.JJCRS, //经济舱人数
  613. firstClassCnt = groupInfo.TDCRS, //头等舱人数
  614. bizClassCnt = groupInfo.GWCRS; //公务舱人数
  615. decimal ecoCost = groupInfo.JJCCB, //经济舱成本费用
  616. firstCost = groupInfo.TDCCB, //头等舱成本费用
  617. bizCost = groupInfo.GWCCB; //公务舱成本费用
  618. decimal ecoTotalCost = ecoPaxCount * ecoCost, //经济舱成本费用合计
  619. firstTotalCost = firstClassCnt * firstCost, //头等舱成本费用合计
  620. bizTotalCost = bizClassCnt * bizCost; //公务舱成本费用合计
  621. int currAirType = airInfo.CType; //当前舱位类型
  622. int currAirTypeCnt = 0; //当前舱位人数
  623. //decimal currAirFee = 0.00M; //当前舱位录入费用
  624. decimal currAirCost = 0.00M; //当前舱位成本费用
  625. switch (airInfo.CType)
  626. {
  627. //头等舱
  628. case 457:
  629. currAirTypeCnt = groupInfo.TDCRS; //头等舱人数
  630. currAirCost = currAirTypeCnt * groupInfo.TDCCB; //头等舱成本费用合计
  631. break;
  632. //公务舱
  633. case 458:
  634. currAirTypeCnt = groupInfo.GWCRS; //公务舱人数
  635. currAirCost = currAirTypeCnt * groupInfo.GWCCB; //公务舱成本费用合计
  636. break;
  637. case 459: //超经舱
  638. currAirTypeCnt = groupInfo.JJCRS; //经济舱人数
  639. currAirCost = currAirTypeCnt * groupInfo.JJCCB; //经济舱成本费用合计
  640. break;
  641. case 460: //经济舱
  642. currAirTypeCnt = groupInfo.JJCRS; //经济舱人数
  643. currAirCost = currAirTypeCnt * groupInfo.JJCCB; //经济舱成本费用合计
  644. break;
  645. case 1430: //公务舱(实际经济舱)
  646. currAirTypeCnt = groupInfo.GWCRS; //公务舱人数
  647. currAirCost = currAirTypeCnt * groupInfo.GWCCB; //公务舱成本费用合计
  648. break;
  649. case 1431: //头等舱(实际公务舱)
  650. currAirTypeCnt = groupInfo.TDCRS; //头等舱人数
  651. currAirCost = currAirTypeCnt * groupInfo.TDCCB; //头等舱成本费用合计
  652. break;
  653. case 1432: //头等舱(实际经济舱)
  654. currAirTypeCnt = groupInfo.TDCRS; //头等舱人数
  655. currAirCost = currAirTypeCnt * groupInfo.TDCCB; //头等舱成本费用合计
  656. break;
  657. default:
  658. _view.Msg = $"机票费用类型不在自动审核范围内,不可自动审核!";
  659. return _view;
  660. }
  661. var currAirTypeDatas = await _sqlSugar.Queryable<Grp_AirTicketReservations>()
  662. .Where(x => x.IsDel == 0 && x.DIId == diId && x.CType == airInfo.CType && x.ClientNum == currAirTypeCnt)
  663. .ToListAsync();
  664. var airTypeText = airInfo.CType switch
  665. {
  666. 457 => "头等舱",
  667. 458 => "公务舱",
  668. 459 => "超经舱",
  669. 460 => "经济舱",
  670. 1430 => "公务舱(实际经济舱)",
  671. 1431 => "头等舱(实际公务舱)",
  672. 1432 => "头等舱(实际经济舱)",
  673. _ => "未知舱位"
  674. };
  675. if (!currAirTypeDatas.Any())
  676. {
  677. _view.Msg = $"{airTypeText}机票费用数据未填写或者舱位人数不匹配,不可自动审核!";
  678. return _view;
  679. }
  680. //验证费用类型
  681. if (!currAirTypeDatas.Any(x => x.Id == airInfo.Id))
  682. {
  683. _view.Msg = $"机票费用({airTypeText})超出团组成本费用";
  684. return _view;
  685. }
  686. //验证是否超出舱位成本费用
  687. decimal currAirTypeFee = currAirTypeDatas.Sum(x => x.Price);
  688. if (currAirTypeFee > currAirCost)
  689. {
  690. _view.Msg = $"机票费用({airTypeText})超出团组成本费用";
  691. QuashAudit(currModule, diId, currAirTypeDatas.Select(x => x.Id).ToArray());
  692. return _view;
  693. }
  694. //执行自动审核及相关字段更改
  695. var upd = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  696. .SetColumns(x => x.IsAuditGM == 3)
  697. .SetColumns(x => x.AuditGMOperate == 4)
  698. .SetColumns(x => x.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
  699. .Where(x => x.Id == airInfo.CcpId)
  700. .ExecuteCommand();
  701. if (upd > 0)
  702. {
  703. _view.Code = StatusCodes.Status200OK;
  704. _view.Msg = "自动审核执行成功";
  705. return _view;
  706. }
  707. _view.Msg = "自动审核执行失败";
  708. return _view;
  709. #endregion
  710. }
  711. else _view.Msg = $"请传入有效的feeType参数";
  712. return _view;
  713. }
  714. /// <summary>
  715. /// hotel、op 撤销自动审核的数据
  716. /// </summary>
  717. /// <param name="type">
  718. /// 酒店 76
  719. /// op 79
  720. /// </param>
  721. /// <param name="diId"></param>
  722. /// <param name="dataId"></param>
  723. /// <returns></returns>
  724. private bool QuashAudit(int type, int diId, int dataId)
  725. {
  726. //撤销该条数据的自动审核 --> 该条数据的审核状态是自动审核 3 --> 0
  727. var ccpInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>()
  728. .Where(s => s.DIId == diId && s.CTable == type && s.CId == dataId && s.IsAuditGM == 3)
  729. .First();
  730. if (ccpInfo != null)
  731. {
  732. var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
  733. .SetColumns(it => it.IsAuditGM == 0)
  734. .SetColumns(it => it.AuditGMOperate == 0)
  735. .SetColumns(it => it.AuditGMDate == string.Empty)
  736. .Where(s => s.Id == ccpInfo.Id)
  737. .ExecuteCommand();
  738. if (ccpUpdate > 0)
  739. {
  740. return true;
  741. }
  742. }
  743. return false;
  744. }
  745. /// <summary>
  746. /// air 撤销自动审核的数据
  747. /// </summary>
  748. /// <param name="type">
  749. /// 机票
  750. /// </param>
  751. /// <param name="diId"></param>
  752. /// <param name="dataId"></param>
  753. /// <returns></returns>
  754. private bool QuashAudit(int type, int diId, int[] dataId)
  755. {
  756. //撤销该条数据的自动审核 --> 该条数据的审核状态是自动审核 3 --> 0
  757. var ccpInfos = _sqlSugar.Queryable<Grp_CreditCardPayment>()
  758. .Where(s => s.DIId == diId && s.CTable == type && dataId.Contains(s.CId) && s.IsAuditGM == 3)
  759. .ToList();
  760. if (ccpInfos.Any())
  761. {
  762. ccpInfos.ForEach(x =>
  763. {
  764. x.IsAuditGM = 0;
  765. x.AuditGMOperate = 0;
  766. x.AuditGMDate = string.Empty;
  767. });
  768. var ccpUpd = _sqlSugar.Updateable(ccpInfos)
  769. .UpdateColumns(x => new { x.IsAuditGM, x.AuditGMOperate, x.AuditGMDate })
  770. .ExecuteCommand();
  771. if (ccpUpd > 0)
  772. {
  773. return true;
  774. }
  775. }
  776. return false;
  777. }
  778. /// <summary>
  779. /// 费用自动审核
  780. /// </summary>
  781. /// <param name="feeType">
  782. /// 1.酒店 76
  783. /// 2.op 79
  784. /// </param>
  785. /// <param name="diId">团组Id</param>
  786. /// <param name="dataId">数据Id(模块类型主表Id)</param>
  787. /// <returns></returns>
  788. public string IsOverBudget(int feeType, int diId, int dataId)
  789. {
  790. string _view = "-";
  791. if (diId < 1) { return _view; }
  792. if (dataId < 1) { return _view; }
  793. List<int> stids = new() { 17, 66 };
  794. var setData = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && stids.Contains(x.STid)).ToList();
  795. string _teamCurrency = string.Empty;
  796. var groupInfo = _sqlSugar.Queryable<Grp_GroupCostParameter>().Where(x => x.IsDel == 0 && x.DiId == diId).First();
  797. if (groupInfo == null) { return _view; }
  798. _teamCurrency = groupInfo.Currency;
  799. //币种验证 统一为currencycode三字码
  800. if (int.TryParse(_teamCurrency, out int currency)) _teamCurrency = setData.Find(x => x.Id == currency)?.Name ?? "";
  801. string costContentSql = $"Select * From Grp_GroupCost";
  802. var costContents = _sqlSugar.SqlQueryable<GroupCostAuditView>(costContentSql).Where(x => x.IsDel == 0 && x.Diid == diId).ToList();
  803. if (costContents.Count < 1) { return _view; }
  804. //处理 成本详细信息 日期为空
  805. for (int i = 0; i < costContents.Count; i++)
  806. {
  807. if (string.IsNullOrEmpty(costContents[i].Date))
  808. {
  809. int index = i - 1;
  810. if (index >= 0)
  811. {
  812. costContents[i].Date = costContents[index].Date;
  813. }
  814. }
  815. }
  816. if (feeType == 1)
  817. {
  818. var hotelCostInfo = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId).First();
  819. var hotelCostDetails = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(x => x.IsDel == 0 && x.DiId == diId && x.HrId == dataId).ToList();
  820. if (hotelCostInfo == null) return _view;
  821. //获取C表汇率
  822. decimal _rate = 1.0000M;
  823. var roomFeeInfo = hotelCostDetails.Where(x => x.PriceType == 1).First();
  824. if (roomFeeInfo == null) return _view;
  825. _rate = roomFeeInfo.Rate == 0.0000M ? 1.0000M : roomFeeInfo.Rate;
  826. bool isAutoAudit = true; //是否自动审核
  827. DateTime checkIn = Convert.ToDateTime(hotelCostInfo.CheckInDate),
  828. checkOut = Convert.ToDateTime(hotelCostInfo.CheckOutDate);
  829. if (checkOut > checkIn) checkOut = checkOut.AddDays(-1); //房费计算,结束日期为前一天
  830. var hotelCostInfos = costContents.Where(x => Convert.ToDateTime(x.Date) >= checkIn && Convert.ToDateTime(x.Date) <= checkOut).ToList();
  831. if (hotelCostInfos.Count < 1) isAutoAudit = false;
  832. decimal otherFee = hotelCostDetails.Where(x => x.PriceType != 1).Sum(x => x.Price * (x.Rate == 0.0000M ? 1.0000M : x.Rate));
  833. if (otherFee > 0) { otherFee /= (checkOut - checkIn).Days; }
  834. var hotelCostInfosGroup = hotelCostInfos.GroupBy(x => x.Date);
  835. foreach (var item in hotelCostInfosGroup)
  836. {
  837. decimal hotelSingleRoomFee = item.Sum(x => x.HotelSingleRoomFee);
  838. decimal hotelDoubleRoomFee = item.Sum(x => x.HotelDoubleRoomFee);
  839. decimal hotelSuiteFee = item.Sum(x => x.HotelSuiteFee);
  840. decimal hotelSuiteRoomFee = item.Sum(x => x.HotelSuiteRoomFee);
  841. //1.判断费用是否 <= 成本费用
  842. //1.1 判断单间费用
  843. decimal singleRoomPrice = (hotelCostInfo.SingleRoomPrice + otherFee) * _rate;
  844. if (singleRoomPrice > 0) if (singleRoomPrice > hotelSingleRoomFee * _rate) isAutoAudit = false;
  845. //1.2 判断双人间费用
  846. decimal doubleRoomPrice = (hotelCostInfo.DoubleRoomPrice + otherFee) * _rate;
  847. if (doubleRoomPrice > 0) if (doubleRoomPrice > hotelDoubleRoomFee * _rate) isAutoAudit = false;
  848. //1.3 判断套房费用
  849. decimal suiteRoomPrice = (hotelCostInfo.SuiteRoomPrice + otherFee) * _rate;
  850. if (suiteRoomPrice > 0) if (suiteRoomPrice > hotelSuiteFee * _rate) isAutoAudit = false;
  851. //1.4 判断其他房型费用
  852. decimal otherRoomPrice = (hotelCostInfo.OtherRoomPrice + otherFee) * _rate;
  853. if (otherRoomPrice > 0) if (otherRoomPrice > hotelSuiteRoomFee * _rate) isAutoAudit = false;
  854. }
  855. //2.判断是否自动审核
  856. if (isAutoAudit)
  857. {
  858. return $"未超预算";
  859. }
  860. }
  861. else if (feeType == 2)
  862. {
  863. //1.基础数据参数验证
  864. var priceType = new List<int>() { 1062 };
  865. var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  866. .Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId && !priceType.Contains(x.PriceType))
  867. .First();
  868. //var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
  869. // .Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId )
  870. // .First();
  871. if (opinfos == null) return _view;
  872. //1.含超时费用/超支费用 手动审核
  873. if (opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支") || opinfos.SelectCheck.Contains("尾款")) return _view;
  874. //1.参数验证
  875. var opCheckPriceTyeps = opinfos.SelectCheck.Split(',');
  876. var opCheckPriceTyepIds = setData.Where(x => opinfos.SelectCheck.Split(',').Contains(x.Name)).Select(x => x.Id).ToList();
  877. var opContents = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
  878. .Where(x => x.IsDel == 0 && x.DiId == diId && x.CTGGRId == dataId && opCheckPriceTyepIds.Contains(x.SId))
  879. .OrderBy(x => x.DatePrice, OrderByType.Asc)
  880. .ToList();
  881. if (opContents.Count < 1) return _view;
  882. //获取C表汇率
  883. decimal _rate = 1.0000M;
  884. var payInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>().Where(x => x.IsDel == 0 && x.DIId == diId && x.CTable == 79 && x.Id == dataId).First();
  885. if (payInfo == null) return _view;
  886. _rate = payInfo.DayRate;
  887. string opCurrencyName = setData.Find(x => x.Id == opContents[0].Currency)?.Name ?? "";
  888. var opBasicDatas = setData.Where(x => x.STid == 17).ToList(); //费用类型基础数据
  889. bool isAutoAudit = true;
  890. if (!DateTime.TryParse(opinfos.ServiceStartTime, out DateTime startDt1) || !DateTime.TryParse(opinfos.ServiceEndTime, out DateTime endDt1)) return _view;
  891. DateTime startDt = startDt1;
  892. DateTime endDt = endDt1;
  893. var opCostDatas = costContents.Where(it => Convert.ToDateTime(it.Date) >= startDt && Convert.ToDateTime(it.Date) <= endDt).ToList();
  894. if (opCostDatas.Count < 1) return _view;
  895. var noAuditFeeTypeIds = new List<int> {
  896. 982 ,//982 车超时费 -- 暂无
  897. 96 ,//96 接送机费 -- 暂无
  898. 97 ,//97 其他费用 -- 暂无
  899. 992 ,//992 住补费用 -- 暂无
  900. 1059,//1059 导游超时费用 -- 暂无
  901. 1070,//1070 尾款金额 -- 暂无
  902. 1071,//1071 其他额外费用 -- 暂无
  903. 1073,//1073 翻译超时费 -- 暂无
  904. 1074,//1074 早餐超支费用 -- 暂无
  905. 1075,//1075 午餐超支费用 -- 暂无
  906. 1076,//1076 晚餐超支费用 -- 暂无
  907. };
  908. //费用类型筛选 包含 feeTypeIds && 包含这些类型费用大于0
  909. var noAuditFeeContents = opContents.Where(x => x.Price > 0 && noAuditFeeTypeIds.Contains(x.SId)).ToList();
  910. if (noAuditFeeContents.Count > 0) return _view;
  911. //2.按天按项 检查费用是否超过预算
  912. var opDayContent = opContents.GroupBy(x => x.DatePrice);
  913. foreach (var item in opDayContent)
  914. {
  915. var opCostInfo = opCostDatas.Where(x => Convert.ToDateTime(x.Date) == item.Key).ToList();
  916. if (opCostInfo.Count < 1) continue;
  917. //车费 91
  918. var opCarCost = item.FirstOrDefault(x => x.SId == 91);
  919. if (opCarCost != null) if (opCarCost.Price * _rate > _rate * opCostInfo.Sum(x => x.CarFee)) isAutoAudit = false;
  920. //982 车超时费 -- 暂无
  921. //92 导游费
  922. var opGuideCost = item.FirstOrDefault(x => x.SId == 92);
  923. if (opGuideCost != null) if (opGuideCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideFee)) isAutoAudit = false;
  924. //94 导游景点费
  925. var opGuideScenicCost = item.FirstOrDefault(x => x.SId == 94);
  926. if (opGuideScenicCost != null) if (opGuideScenicCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideScenicFee)) isAutoAudit = false;
  927. //95 导游小费
  928. var opGuideTipCost = item.FirstOrDefault(x => x.SId == 95);
  929. if (opGuideTipCost != null) if (opGuideTipCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideTipFee)) isAutoAudit = false;
  930. //983 导游餐补
  931. var opGuideMealCost = item.FirstOrDefault(x => x.SId == 983);
  932. if (opGuideMealCost != null) if (opGuideMealCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideMealFee)) isAutoAudit = false;
  933. //984 导游房补
  934. var opGuideRoomCost = item.FirstOrDefault(x => x.SId == 984);
  935. if (opGuideRoomCost != null) if (opGuideRoomCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideRoomFee)) isAutoAudit = false;
  936. //985 导游交通
  937. var opGuideTrafficCost = item.FirstOrDefault(x => x.SId == 985);
  938. if (opGuideTrafficCost != null) if (opGuideTrafficCost.Price * _rate > _rate * opCostInfo.Sum(x => x.GuideTrafficFee)) isAutoAudit = false;
  939. //96 接送机费 -- 暂无
  940. //97 其他费用 -- 暂无
  941. //979 司机工资
  942. var opDriverCost = item.FirstOrDefault(x => x.SId == 979);
  943. if (opDriverCost != null) if (opDriverCost.Price * _rate > _rate * opCostInfo.Sum(x => x.DriverFee)) isAutoAudit = false;
  944. //980 司机小费
  945. var opDriverTipCost = item.FirstOrDefault(x => x.SId == 980);
  946. if (opDriverTipCost != null) if (opDriverTipCost.Price * _rate > _rate * opCostInfo.Sum(x => x.DriverTipFee)) isAutoAudit = false;
  947. //981 司机餐补
  948. var opDriverMealCost = item.FirstOrDefault(x => x.SId == 981);
  949. if (opDriverMealCost != null) if (opDriverMealCost.Price * _rate > _rate * opCostInfo.Sum(x => x.DriverMealFee)) isAutoAudit = false;
  950. //988 客户早餐费用
  951. var opClientBreakfastCost = item.FirstOrDefault(x => x.SId == 988);
  952. if (opClientBreakfastCost != null) if (opClientBreakfastCost.Price * _rate > _rate * opCostInfo.Sum(x => x.ClientBreakfastFee)) isAutoAudit = false;
  953. //93 客户午餐费用
  954. var opClientLunchCost = item.FirstOrDefault(x => x.SId == 93);
  955. if (opClientLunchCost != null) if (opClientLunchCost.Price * _rate > _rate * opCostInfo.Sum(x => x.ClientLunchFee)) isAutoAudit = false;
  956. //989 客户晚餐费用
  957. var opClientDinnerCost = item.FirstOrDefault(x => x.SId == 989);
  958. if (opClientDinnerCost != null) if (opClientDinnerCost.Price * _rate > _rate * opCostInfo.Sum(x => x.ClientDinnerFee)) isAutoAudit = false;
  959. //990 景点门票费
  960. var opScenicTicketCost = item.FirstOrDefault(x => x.SId == 990);
  961. if (opScenicTicketCost != null) if (opScenicTicketCost.Price * _rate > _rate * opCostInfo.Sum(x => x.ScenicTicketFee)) isAutoAudit = false;
  962. //991 饮料/零食/水果
  963. var opDrinkSnackFruitCost = item.FirstOrDefault(x => x.SId == 991);
  964. if (opDrinkSnackFruitCost != null) if (opDrinkSnackFruitCost.Price * _rate > _rate * opCostInfo.Sum(x => x.DrinkSnackFruitFee)) isAutoAudit = false;
  965. //992 住补费用 -- 暂无
  966. //994 翻译费
  967. var opTranslatorCost = item.FirstOrDefault(x => x.SId == 994);
  968. if (opTranslatorCost != null) if (opTranslatorCost.Price * _rate > _rate * opCostInfo.Sum(x => x.TranslatorFee)) isAutoAudit = false;
  969. //1059 导游超时费用 -- 暂无
  970. //1070 尾款金额 -- 暂无
  971. //1071 其他额外费用 -- 暂无
  972. //1073 翻译超时费 -- 暂无
  973. //1074 早餐超支费用 -- 暂无
  974. //1075 午餐超支费用 -- 暂无
  975. //1076 晚餐超支费用 -- 暂无
  976. }
  977. //更改审核状态
  978. if (isAutoAudit) return _view;
  979. }
  980. else return _view;
  981. return _view;
  982. }
  983. }
  984. }