Browse Source

1、自动审核 op 逻辑代码编写
2、op费用录入 自动审核相关代码编写
3、费用审核 自动审核相关代码编写

leiy 8 months ago
parent
commit
d141bb2fd7

+ 16 - 1
OASystem/OASystem.Api/Controllers/GroupsController.cs

@@ -1826,7 +1826,17 @@ namespace OASystem.API.Controllers
                     if (entity.ExceedBudget == -1)
                         overBudgetStr = sdPriceName.Name + "尚无预算";
                     else if (entity.ExceedBudget == 0)
-                        overBudgetStr = "未超预算";
+                    {
+                        if (entity.CTable == 76 || entity.CTable == 79)
+                        {
+                            if (entity.IsAuditGM == 3) overBudgetStr = "未超预算";
+                            else overBudgetStr = "超预算";
+                        }
+                        else
+                        {
+                            overBudgetStr = "未超预算";
+                        }
+                    }
                     else
                         overBudgetStr = entity.ExceedBudget.ToString("P");
                     _detail.OverBudget = overBudgetStr;
@@ -5851,6 +5861,9 @@ namespace OASystem.API.Controllers
                     return Ok(JsonView(false, groupData.Msg));
                 }
 
+                //自动审核
+                await _feeAuditRep.FeeAutomaticAudit(2,dto.DiId,dto.CTGGRId);
+                
                 #region 应用推送
                 try
                 {
@@ -5858,6 +5871,8 @@ namespace OASystem.API.Controllers
                     int sign = groupData.Data.GetType().GetProperty("sign").GetValue(groupData.Data, null);
 
                     await AppNoticeLibrary.SendChatMsg_GroupStatus_ApplyFee(ccpId, sign, QiyeWeChatEnum.GuoJiaoLeaderChat);
+
+
                 }
                 catch (Exception ex)
                 {

+ 13 - 5
OASystem/OASystem.Domain/ViewModels/Groups/FeeAuditView.cs

@@ -14,7 +14,7 @@ namespace OASystem.Domain.ViewModels.Groups
     /// <summary>
     /// GroupCostView
     /// </summary>
-    public class GroupCostView: Grp_GroupCost
+    public class GroupCostAuditView: Grp_GroupCost
     {
         #region OP 自动审核相关
 
@@ -88,7 +88,9 @@ namespace OASystem.Domain.ViewModels.Groups
         /// </summary>
         public decimal DriverFee { get { return CFS; } set { CFS = value; } }
 
-        //自动审核 - 司机小费
+        /// <summary>
+        /// 自动审核 - 司机小费
+        /// </summary>
         public decimal DriverTipFee { get { return DRVTips; } set { DRVTips = value; } }
 
         /// <summary>
@@ -160,13 +162,19 @@ namespace OASystem.Domain.ViewModels.Groups
         /// </summary>
         public decimal HotelSingleRoomFee { get { return SGR; } set { SGR = value; } }
 
-        //酒店双间费用
+        /// <summary>
+        /// 酒店双间费用
+        /// </summary>
         public decimal HotelDoubleRoomFee { get { return TBR; } set { TBR = value; } }
 
-        //酒店小套房/豪华套房费用
+        /// <summary>
+        /// 酒店小套房/豪华套房费用
+        /// </summary>
         public decimal HotelSuiteRoomFee { get { return JS_ES; } set { JS_ES = value; } }
 
-        //酒店套房费用
+        /// <summary>
+        /// 酒店套房费用
+        /// </summary>
         public decimal HotelSuiteFee { get { return Suite; } set { Suite = value; } }
 
         #endregion

+ 197 - 26
OASystem/OASystem.Infrastructure/Repositories/Groups/FeeAuditRepository.cs

@@ -1,6 +1,7 @@
 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;
@@ -48,7 +49,9 @@ namespace OASystem.Infrastructure.Repositories.Groups
                 _teamCurrency = setData.Find(x => x.Id == currency)?.Name ?? "";
             }
             _rate = groupInfo.Rate;
-            var costContents =  _sqlSugar.Queryable<Grp_GroupCost>().Where(x => x.IsDel == 0 && x.Diid == diId).ToList();
+
+            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; }
 
             //处理 成本详细信息 日期为空
@@ -80,7 +83,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                 {
                     if (!hotelCurrency.Equals("CNY"))
                     {
-                        _view.Msg = $"币种不一致";
+                        _view.Msg = $"酒店预订费用币种与团组成本币种不一致,请手动审核";
                         return _view;
                     }
                 }
@@ -94,34 +97,29 @@ namespace OASystem.Infrastructure.Repositories.Groups
 
                 decimal otherFee = hotelCostDetails.Where(x => x.PriceType != 1).Sum(x => x.Price);
                 if (otherFee > 0) { otherFee /= 3; }
-
-                foreach (var item in hotelCostInfos)
+                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);
                     //1.判断费用是否 <= 成本费用
                     //1.1 判断单间费用
-                    if (item.SGR > 0)
-                    {
-                        decimal singleRoomPrice = hotelCostInfo.SingleRoomPrice + otherFee;
-                        if (singleRoomPrice > item.SGR * _rate) isAutoAudit = false;
-                    }
+                    decimal singleRoomPrice = hotelCostInfo.SingleRoomPrice + otherFee;
+                    if (singleRoomPrice > 0) if (singleRoomPrice > hotelSingleRoomFee * _rate) isAutoAudit = false;
+
                     //1.2 判断双人间费用
-                    if (item.TBR > 0)
-                    { 
-                        decimal doubleRoomPrice = hotelCostInfo.DoubleRoomPrice + otherFee;
-                        if (doubleRoomPrice > item.TBR * _rate) isAutoAudit = false;
-                    }
+                    decimal doubleRoomPrice = hotelCostInfo.DoubleRoomPrice + otherFee;
+                    if (doubleRoomPrice > 0) if (doubleRoomPrice > hotelDoubleRoomFee * _rate) isAutoAudit = false;
+
                     //1.3 判断套房费用
-                    if (item.Suite > 0)
-                    { 
-                        decimal suiteRoomPrice = hotelCostInfo.SuiteRoomPrice + otherFee;
-                        if (suiteRoomPrice > item.Suite * _rate) isAutoAudit = false;
-                    }
+                    decimal suiteRoomPrice = hotelCostInfo.SuiteRoomPrice + otherFee;
+                    if (suiteRoomPrice > 0) if (suiteRoomPrice > hotelSuiteFee * _rate) isAutoAudit = false;
+
                     //1.4 判断其他房型费用
-                    if (item.JS_ES > 0)
-                    { 
-                        decimal otherRoomPrice = hotelCostInfo.OtherRoomPrice + otherFee;
-                        if (otherRoomPrice > item.JS_ES * _rate) isAutoAudit = false;
-                    }
+                    decimal otherRoomPrice = hotelCostInfo.OtherRoomPrice + otherFee;
+                    if (otherRoomPrice > 0) if (otherRoomPrice > hotelSuiteRoomFee * _rate) isAutoAudit = false;
                 }
 
                 //2.判断是否自动审核
@@ -136,7 +134,7 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     if (ccpUpdate > 0)
                     {
                         _view.Code = 200;
-                        _view.Msg = "审核成功";
+                        _view.Msg = "自动审核执行成功";
                         return _view;
                     }
                 }
@@ -153,12 +151,185 @@ namespace OASystem.Infrastructure.Repositories.Groups
                                        .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)
             {
-                //1.含超时费用 手动审核
+                //1.基础数据参数验证
+                var priceType = setData.Where(x => x.Name.Contains("尾款")).Select(x =>x.Id).ToList();
+                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;
+                }
+                //1.含超时费用/超支费用 手动审核
+                if (opinfos.SelectCheck.Contains("超时") || opinfos.SelectCheck.Contains("超支"))
+                {
+                    _view.Msg = $"OP费用含超时费用,请手动审核";
+                    return _view;
+                }
+                //1.参数验证
+                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 ?? "";
+                //1.1币种验证
+                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;
+                }
+
+                //2.按天按项 检查费用是否超过预算 
+                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;
+
+                    //车费 91
+                    var opCarCost = item.FirstOrDefault(x => x.SId == 91);
+                    if (opCarCost != null) if (opCarCost.Price > _rate * opCostInfo.Sum(x => x.CarFee)) isAutoAudit = false;
+
+                    //982 车超时费 -- 暂无
+
+                    //92  导游费
+                    var opGuideCost = item.FirstOrDefault(x => x.SId == 92);
+                    if (opGuideCost != null) if (opGuideCost.Price > _rate * opCostInfo.Sum(x => x.GuideFee)) isAutoAudit = false;
+                    //94  导游景点费
+                    var opGuideScenicCost = item.FirstOrDefault(x => x.SId == 94);
+                    if (opGuideScenicCost != null) if (opGuideScenicCost.Price > _rate * opCostInfo.Sum(x => x.GuideScenicFee)) isAutoAudit = false;
+                    //95  导游小费
+                    var opGuideTipCost = item.FirstOrDefault(x => x.SId == 95);
+                    if (opGuideTipCost != null) if (opGuideTipCost.Price > _rate * opCostInfo.Sum(x => x.GuideTipFee)) isAutoAudit = false;
+                    //983 导游餐补
+                    var opGuideMealCost = item.FirstOrDefault(x => x.SId == 983);
+                    if (opGuideMealCost != null) if (opGuideMealCost.Price > _rate * opCostInfo.Sum(x => x.GuideMealFee)) isAutoAudit = false;
+                    //984 导游房补
+                    var opGuideRoomCost = item.FirstOrDefault(x => x.SId == 984);
+                    if (opGuideRoomCost != null) if (opGuideRoomCost.Price > _rate * opCostInfo.Sum(x => x.GuideRoomFee)) isAutoAudit = false;
+                    //985 导游交通
+                    var opGuideTrafficCost = item.FirstOrDefault(x => x.SId == 985);
+                    if (opGuideTrafficCost != null) if (opGuideTrafficCost.Price > _rate * opCostInfo.Sum(x => x.GuideTrafficFee)) isAutoAudit = false;
+                    //96  接送机费 -- 暂无
+                    //97  其他费用 -- 暂无
+                    //979 司机工资
+                    var opDriverCost = item.FirstOrDefault(x => x.SId == 979);
+                    if (opDriverCost != null) if (opDriverCost.Price > _rate * opCostInfo.Sum(x => x.DriverFee)) isAutoAudit = false;
+                    //980 司机小费
+                    var opDriverTipCost = item.FirstOrDefault(x => x.SId == 980);
+                    if (opDriverTipCost != null) if (opDriverTipCost.Price > _rate * opCostInfo.Sum(x => x.DriverTipFee)) isAutoAudit = false;
+                    //981 司机餐补
+                    var opDriverMealCost = item.FirstOrDefault(x => x.SId == 981);
+                    if (opDriverMealCost != null) if (opDriverMealCost.Price > _rate * opCostInfo.Sum(x => x.DriverMealFee)) isAutoAudit = false;
+                    //988 客户早餐费用
+                    var opClientBreakfastCost = item.FirstOrDefault(x => x.SId == 988);
+                    if (opClientBreakfastCost != null) if (opClientBreakfastCost.Price > _rate * opCostInfo.Sum(x => x.ClientBreakfastFee)) isAutoAudit = false;
+                    //93  客户午餐费用
+                    var opClientLunchCost = item.FirstOrDefault(x => x.SId == 93);
+                    if (opClientLunchCost != null) if (opClientLunchCost.Price > _rate * opCostInfo.Sum(x => x.ClientLunchFee)) isAutoAudit = false;
+                    //989 客户晚餐费用
+                    var opClientDinnerCost = item.FirstOrDefault(x => x.SId == 989);
+                    if (opClientDinnerCost != null) if (opClientDinnerCost.Price > _rate * opCostInfo.Sum(x => x.ClientDinnerFee)) isAutoAudit = false;
+                    //990 景点门票费
+                    var opScenicTicketCost = item.FirstOrDefault(x => x.SId == 990);
+                    if (opScenicTicketCost != null) if (opScenicTicketCost.Price > _rate * opCostInfo.Sum(x => x.ScenicTicketFee)) isAutoAudit = false;
+                    //991 饮料/零食/水果
+                    var opDrinkSnackFruitCost = item.FirstOrDefault(x => x.SId == 991);
+                    if (opDrinkSnackFruitCost != null) if (opDrinkSnackFruitCost.Price > _rate * opCostInfo.Sum(x => x.DrinkSnackFruitFee)) isAutoAudit = false;
+                    //992 住补费用 -- 暂无
+                    //994 翻译费
+                    var opTranslatorCost = item.FirstOrDefault(x => x.SId == 994);
+                    if (opTranslatorCost != null) if (opTranslatorCost.Price > _rate * opCostInfo.Sum(x => x.TranslatorFee)) isAutoAudit = false;
+                    //1059    导游超时费用
+                    //1070    尾款金额
+                    //1071    其他额外费用
+                    //1073    翻译超时费
+                    //1074    早餐超支费用
+                    //1075    午餐超支费用
+                    //1076    晚餐超支费用
+                }
+
+                //更改审核状态
+                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
+                {
+                    //撤销该条数据的自动审核 --> 该条数据的审核状态是自动审核  3 --> 0
+                    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参数";