123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- using NPOI.SS.Formula.Functions;
- using OASystem.Domain;
- using OASystem.Domain.Entities.Groups;
- using OASystem.Domain.ViewModels.Groups;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OASystem.Infrastructure.Repositories.Groups
- {
-
-
-
- public class FeeAuditRepository:BaseRepository<EntityBase,ViewBase>
- {
- public FeeAuditRepository(SqlSugarClient sqlSugar) : base(sqlSugar)
- {
-
- }
-
-
-
-
-
-
-
-
-
-
- public async Task<JsonView> FeeAutomaticAudit(int feeType, int diId, int dataId)
- {
- var _view = new JsonView() { Code = 201, Msg = "自动审核操作失败" };
- if (diId < 1) { _view.Msg = MsgTips.DiId; return _view; }
- if (dataId < 1) { _view.Msg = MsgTips.Id; return _view; }
- List<int> stids = new List<int>() { 17, 66 };
- var setData = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.IsDel == 0 && stids.Contains(x.STid)).ToList();
- string _teamCurrency = string.Empty;
- decimal _rate = 0.00M;
- var groupInfo = _sqlSugar.Queryable< Grp_GroupCostParameter >().Where(x => x.IsDel ==0 && x.DiId == diId).First();
- if (groupInfo == null) { _view.Msg = $"团组成本信息未填写!"; return _view; }
- _teamCurrency = groupInfo.Currency;
-
- if (int.TryParse(_teamCurrency,out int currency))
- {
- _teamCurrency = setData.Find(x => x.Id == currency)?.Name ?? "";
- }
- _rate = groupInfo.Rate;
- string costContentSql = $"Select * From Grp_GroupCost";
- var costContents = _sqlSugar.SqlQueryable<GroupCostAuditView>(costContentSql).Where(x => x.IsDel == 0 && x.Diid == diId).ToList();
- if (costContents.Count < 1) { _view.Msg = $"团组成本信息未填写!"; return _view; }
-
- for (int i = 0; i < costContents.Count; i++)
- {
- if (string.IsNullOrEmpty( costContents[i].Date))
- {
- int index = i - 1;
- if (index >= 0)
- {
- costContents[i].Date = costContents[index].Date;
- }
- }
- }
- if (feeType == 1)
- {
- var hotelCostInfo = _sqlSugar.Queryable<Grp_HotelReservations>().Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId).First();
- var hotelCostDetails = _sqlSugar.Queryable<Grp_HotelReservationsContent>().Where(x => x.IsDel == 0 && x.DiId == diId && x.HrId == dataId).ToList();
- if (hotelCostInfo == null)
- {
- _view.Msg = $"酒店费用数据未填写";
- return _view;
- }
-
- string hotelCurrency = setData.Find(x => x.Id == hotelCostInfo.CardPriceCurrency)?.Name ?? "";
- if (hotelCurrency != _teamCurrency)
- {
- if (!hotelCurrency.Equals("CNY"))
- {
- _view.Msg = $"酒店预订费用币种与团组成本币种不一致,请手动审核";
- return _view;
- }
- }
- else _rate = 1.0000M;
- bool isAutoAudit = true;
- DateTime checkIn = Convert.ToDateTime(hotelCostInfo.CheckInDate),
- checkOut = Convert.ToDateTime(hotelCostInfo.CheckOutDate);
- if (checkOut > checkIn) checkOut = checkOut.AddDays(-1);
- var hotelCostInfos = costContents.Where(x => Convert.ToDateTime(x.Date) >= checkIn && Convert.ToDateTime(x.Date) <= checkOut).ToList();
- if (hotelCostInfos.Count < 1) isAutoAudit = false;
- decimal otherFee = hotelCostDetails.Where(x => x.PriceType != 1).Sum(x => x.Price);
- if (otherFee > 0) { otherFee /= (checkOut-checkIn).Days; }
- var hotelCostInfosGroup = hotelCostInfos.GroupBy(x => x.Date);
- foreach (var item in hotelCostInfosGroup)
- {
- decimal hotelSingleRoomFee = item.Sum(x => x.HotelSingleRoomFee);
- decimal hotelDoubleRoomFee = item.Sum(x => x.HotelDoubleRoomFee);
- decimal hotelSuiteFee = item.Sum(x => x.HotelSuiteFee);
- decimal hotelSuiteRoomFee = item.Sum(x => x.HotelSuiteRoomFee);
-
-
- decimal singleRoomPrice = hotelCostInfo.SingleRoomPrice + otherFee;
- if (singleRoomPrice > 0) if (singleRoomPrice > hotelSingleRoomFee * _rate) isAutoAudit = false;
-
- decimal doubleRoomPrice = hotelCostInfo.DoubleRoomPrice + otherFee;
- if (doubleRoomPrice > 0) if (doubleRoomPrice > hotelDoubleRoomFee * _rate) isAutoAudit = false;
-
- decimal suiteRoomPrice = hotelCostInfo.SuiteRoomPrice + otherFee;
- if (suiteRoomPrice > 0) if (suiteRoomPrice > hotelSuiteFee * _rate) isAutoAudit = false;
-
- decimal otherRoomPrice = hotelCostInfo.OtherRoomPrice + otherFee;
- if (otherRoomPrice > 0) if (otherRoomPrice > hotelSuiteRoomFee * _rate) isAutoAudit = false;
- }
-
- if (isAutoAudit)
- {
- var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
- .SetColumns(it => it.IsAuditGM == 3)
- .SetColumns(it => it.AuditGMOperate == 4)
- .SetColumns(it => it.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
- .Where(s => s.DIId == diId && s.CTable == 76 && s.CId == dataId)
- .ExecuteCommand();
- if (ccpUpdate > 0)
- {
- _view.Code = 200;
- _view.Msg = "自动审核执行成功";
- return _view;
- }
- }
- else {
-
- var ccpInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>()
- .Where(s => s.DIId == diId && s.CTable == 76 && s.CId == dataId && s.IsAuditGM == 3)
- .First();
- if (ccpInfo != null)
- {
- var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
- .SetColumns(it => it.IsAuditGM == 0)
- .SetColumns(it => it.AuditGMOperate == 0)
- .SetColumns(it => it.AuditGMDate == string.Empty)
- .Where(s => s.Id == ccpInfo.Id)
- .ExecuteCommand();
- if (ccpUpdate > 0)
- {
- _view.Code = 200;
- _view.Msg = "费用超团组成本,自动审核撤销成功!";
- return _view;
- }
- }
- }
- }
- else if (feeType == 2)
- {
-
- var priceType = new List<int>() { 1062 };
- var opinfos = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservations>()
- .Where(x => x.IsDel == 0 && x.DiId == diId && x.Id == dataId && !priceType.Contains(x.PriceType))
- .First();
-
-
-
- if (opinfos == null)
- {
- _view.Msg = $"OP费用费用类型属于“尾款”或者 内容未填写";
- return _view;
- }
-
- if (opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支") || opinfos.SelectCheck.Contains("尾款"))
- {
- _view.Msg = @$"OP费用含尾款/超支/超时费用,请手动审核";
- return _view;
- }
-
- var opCheckPriceTyeps = opinfos.SelectCheck.Split(',');
- var opCheckPriceTyepIds = setData.Where(x => opinfos.SelectCheck.Split(',').Contains(x.Name)).Select(x=>x.Id).ToList();
- var opContents = _sqlSugar.Queryable<Grp_CarTouristGuideGroundReservationsContent>()
- .Where(x => x.IsDel == 0 && x.DiId == diId && x.CTGGRId == dataId && opCheckPriceTyepIds.Contains(x.SId))
- .OrderBy(x => x.DatePrice, OrderByType.Asc)
- .ToList();
- if (opContents.Count < 1)
- {
- _view.Msg = $"OP费用费用内容未填写";
- return _view;
- }
- string opCurrencyName = setData.Find(x => x.Id == opContents[0].Currency)?.Name ?? "";
-
- if (!opCurrencyName.Equals(_teamCurrency))
- {
- if (!opCurrencyName.Equals("CNY"))
- {
- _view.Msg = $"OP费用币种与团组成本币种不一致,请手动审核";
- return _view;
- }
- }
- else _rate = 1.0000M;
- var opBasicDatas = setData.Where(x => x.STid == 17).ToList();
- bool isAutoAudit = true;
- if (!DateTime.TryParse(opinfos.ServiceStartTime, out DateTime startDt1) || !DateTime.TryParse(opinfos.ServiceEndTime, out DateTime endDt1))
- {
- _view.Msg = $"OP费用服务起止日期格式不正确!";
- return _view;
- }
- DateTime startDt = startDt1;
- DateTime endDt = endDt1;
- var opCostDatas = costContents.Where(it => Convert.ToDateTime(it.Date) >= startDt && Convert.ToDateTime(it.Date) <= endDt).ToList();
- if (opCostDatas.Count < 1)
- {
- _view.Msg = $"该时间段内团组成本未填写!";
- return _view;
- }
- var noAuditFeeTypeIds = new List<int> {
- 982 ,
- 96 ,
- 97 ,
- 992 ,
- 1059,
- 1070,
- 1071,
- 1073,
- 1074,
- 1075,
- 1076,
- };
-
- var noAuditFeeContents = opContents.Where(x => x.Price > 0 && noAuditFeeTypeIds.Contains(x.SId)).ToList();
- if (noAuditFeeContents.Count > 0)
- {
- _view.Msg = @$"OP费用含尾款/超支/超时费用,请手动审核";
- return _view;
- }
-
- var opDayContent = opContents.GroupBy(x => x.DatePrice);
- foreach (var item in opDayContent)
- {
- var opCostInfo = opCostDatas.Where(x => Convert.ToDateTime(x.Date) == item.Key).ToList();
- if (opCostInfo.Count < 1) continue;
-
- var opCarCost = item.FirstOrDefault(x => x.SId == 91);
- if (opCarCost != null) if (opCarCost.Price > _rate * opCostInfo.Sum(x => x.CarFee)) isAutoAudit = false;
-
-
- var opGuideCost = item.FirstOrDefault(x => x.SId == 92);
- if (opGuideCost != null) if (opGuideCost.Price > _rate * opCostInfo.Sum(x => x.GuideFee)) isAutoAudit = false;
-
- var opGuideScenicCost = item.FirstOrDefault(x => x.SId == 94);
- if (opGuideScenicCost != null) if (opGuideScenicCost.Price > _rate * opCostInfo.Sum(x => x.GuideScenicFee)) isAutoAudit = false;
-
- var opGuideTipCost = item.FirstOrDefault(x => x.SId == 95);
- if (opGuideTipCost != null) if (opGuideTipCost.Price > _rate * opCostInfo.Sum(x => x.GuideTipFee)) isAutoAudit = false;
-
- var opGuideMealCost = item.FirstOrDefault(x => x.SId == 983);
- if (opGuideMealCost != null) if (opGuideMealCost.Price > _rate * opCostInfo.Sum(x => x.GuideMealFee)) isAutoAudit = false;
-
- var opGuideRoomCost = item.FirstOrDefault(x => x.SId == 984);
- if (opGuideRoomCost != null) if (opGuideRoomCost.Price > _rate * opCostInfo.Sum(x => x.GuideRoomFee)) isAutoAudit = false;
-
- var opGuideTrafficCost = item.FirstOrDefault(x => x.SId == 985);
- if (opGuideTrafficCost != null) if (opGuideTrafficCost.Price > _rate * opCostInfo.Sum(x => x.GuideTrafficFee)) isAutoAudit = false;
-
-
-
- var opDriverCost = item.FirstOrDefault(x => x.SId == 979);
- if (opDriverCost != null) if (opDriverCost.Price > _rate * opCostInfo.Sum(x => x.DriverFee)) isAutoAudit = false;
-
- var opDriverTipCost = item.FirstOrDefault(x => x.SId == 980);
- if (opDriverTipCost != null) if (opDriverTipCost.Price > _rate * opCostInfo.Sum(x => x.DriverTipFee)) isAutoAudit = false;
-
- var opDriverMealCost = item.FirstOrDefault(x => x.SId == 981);
- if (opDriverMealCost != null) if (opDriverMealCost.Price > _rate * opCostInfo.Sum(x => x.DriverMealFee)) isAutoAudit = false;
-
- var opClientBreakfastCost = item.FirstOrDefault(x => x.SId == 988);
- if (opClientBreakfastCost != null) if (opClientBreakfastCost.Price > _rate * opCostInfo.Sum(x => x.ClientBreakfastFee)) isAutoAudit = false;
-
- var opClientLunchCost = item.FirstOrDefault(x => x.SId == 93);
- if (opClientLunchCost != null) if (opClientLunchCost.Price > _rate * opCostInfo.Sum(x => x.ClientLunchFee)) isAutoAudit = false;
-
- var opClientDinnerCost = item.FirstOrDefault(x => x.SId == 989);
- if (opClientDinnerCost != null) if (opClientDinnerCost.Price > _rate * opCostInfo.Sum(x => x.ClientDinnerFee)) isAutoAudit = false;
-
- var opScenicTicketCost = item.FirstOrDefault(x => x.SId == 990);
- if (opScenicTicketCost != null) if (opScenicTicketCost.Price > _rate * opCostInfo.Sum(x => x.ScenicTicketFee)) isAutoAudit = false;
-
- var opDrinkSnackFruitCost = item.FirstOrDefault(x => x.SId == 991);
- if (opDrinkSnackFruitCost != null) if (opDrinkSnackFruitCost.Price > _rate * opCostInfo.Sum(x => x.DrinkSnackFruitFee)) isAutoAudit = false;
-
-
- var opTranslatorCost = item.FirstOrDefault(x => x.SId == 994);
- if (opTranslatorCost != null) if (opTranslatorCost.Price > _rate * opCostInfo.Sum(x => x.TranslatorFee)) isAutoAudit = false;
-
-
-
-
-
-
-
- }
-
- if (isAutoAudit)
- {
- var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
- .SetColumns(it => it.IsAuditGM == 3)
- .SetColumns(it => it.AuditGMOperate == 4)
- .SetColumns(it => it.AuditGMDate == DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))
- .Where(s => s.DIId == diId && s.CTable == 79 && s.CId == dataId)
- .ExecuteCommand();
- if (ccpUpdate > 0)
- {
- _view.Code = 200;
- _view.Msg = "自动审核执行成功!";
- return _view;
- }
- }
- else
- {
-
- var ccpInfo = _sqlSugar.Queryable<Grp_CreditCardPayment>()
- .Where(s => s.DIId == diId && s.CTable == 79 && s.CId == dataId && s.IsAuditGM == 3)
- .First();
- if (ccpInfo != null)
- {
- var ccpUpdate = _sqlSugar.Updateable<Grp_CreditCardPayment>()
- .SetColumns(it => it.IsAuditGM == 0)
- .SetColumns(it => it.AuditGMOperate == 0)
- .SetColumns(it => it.AuditGMDate == string.Empty)
- .Where(s => s.Id == ccpInfo.Id)
- .ExecuteCommand();
- if (ccpUpdate > 0)
- {
- _view.Code = 200;
- _view.Msg = "费用超团组成本,自动审核撤销成功!";
- return _view;
- }
- }
- }
- }
- else _view.Msg = $"请传入有效的feeType参数";
- return _view;
- }
- }
- }
|