FeeAuditRepository.cs 35 KB

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