Browse Source

Merge branch 'develop' of http://132.232.92.186:3000/XinXiBu/OA2023 into develop

amigotrip 10 months ago
parent
commit
037f2d2587

+ 219 - 0
OASystem/OASystem.Api/Controllers/FinancialController.cs

@@ -44,6 +44,8 @@ using System.Data.OleDb;
 using Org.BouncyCastle.Crypto;
 using OfficeOpenXml;
 using Org.BouncyCastle.Asn1.Crmf;
+using EyeSoft.Extensions;
+using System.Collections;
 
 namespace OASystem.API.Controllers
 {
@@ -4510,5 +4512,222 @@ Group by PriceType ", dto.diId);
 
 
         #endregion
+
+        #region 提成计算
+        /// <summary>
+        /// 提成计算
+        /// </summary>
+        /// <param name="dto"></param>
+        /// <returns></returns>
+        [HttpPost]
+        public IActionResult ComputeRoyalties(ComputeRoyaltiesDto dto)
+        {
+            var jw = JsonView(false);
+            var userId = dto.UserId;
+            var user =  _sqlSugar.Queryable<Sys_Users>().First(x=>x.Id == userId);
+            if (user == null)
+            {
+                jw.Msg = "暂无该用户!";
+                return Ok(jw);
+            }
+            if (!DateTime.TryParse(dto.StartDate,out DateTime StartDateTime))
+            {
+                jw.Msg = "开始时间格式有误!";
+                return Ok(jw);
+            }
+            if (!DateTime.TryParse(dto.EndDate, out DateTime EndDateTime))
+            {
+                jw.Msg = "结束时间格式有误!";
+                return Ok(jw);
+            }
+            if (DateTime.Compare(StartDateTime,EndDateTime) > 0)
+            {
+                jw.Msg = "开始时间大于结束时间!";
+                return Ok(jw);
+            }
+
+            //机票 职位表id 24
+            int[] AirTicket = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 24).Select(x => x.Id).ToArray();
+
+            //酒店 职位表id 25
+            int[] Hotel = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 25).Select(x => x.Id).ToArray();
+
+            //OP 职位表id 28 
+            int [] OP = _sqlSugar.Queryable<Sys_Users>().Where(x=>x.IsDel == 0 && x.JobPostId == 28).Select(x=>x.Id).ToArray();
+
+            //商邀 职位表id 27
+            int [] Invitation = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 27).Select(x => x.Id).ToArray();
+
+            //签证 职位表id 26
+            int[] Visa = _sqlSugar.Queryable<Sys_Users>().Where(x => x.IsDel == 0 && x.JobPostId == 26 ).Select(x => x.Id).ToArray();
+
+            //主管职位
+            //string[] Manager = { "149", "283" };
+
+            ArrayList resultArr = new ArrayList();
+
+            var teamLv = _sqlSugar.Queryable<Sys_SetData>().Where(x => x.STid == 56 && x.IsDel == 0).ToList();
+
+            if (AirTicket.Contains(userId))
+            {
+                var listAir = _sqlSugar.Queryable<Grp_AirTicketReservations, Grp_DelegationInfo, Grp_CreditCardPayment>((x, a, b) => new
+                JoinQueryInfos(
+                    JoinType.Left, a.Id == x.DIId ,
+                    JoinType.Left, b.CTable == 85 && b.CId == x.Id )
+                ).Where((x, a, b) => x.IsDel == 0 && x.CreateUserId == userId  && (b.IsAuditGM == 1 || b.IsAuditGM == 3)
+                    && a.IsDel == 0 && a.VisitDate > StartDateTime && a.VisitDate < EndDateTime && b.IsDel == 0)
+                    .Select((x, a, b) => new
+                    {
+                        x.FlightsDescription,
+                        a.Id,
+                        a.TeamName,
+                        a.VisitDate,
+                        a.TeamLevSId,
+                        a.VisitPNumber,
+                        x.Price,
+                        x.ClientName,
+                        x.ClientNum,
+                        x.FlightsCode,
+                    }).ToList();
+
+                var groupByid = listAir.GroupBy(x => x.Id);
+                foreach (var airArr in groupByid)
+                {
+                    var groupAirCount = 0; //团组航段数量
+                    var infos = new ArrayList();
+                    foreach (var air in airArr)
+                    {
+                        var airCount = 0; // 单条航段数量
+
+                        if (air.FlightsDescription.IsNullOrWhiteSpace())
+                        {
+                            continue;
+                        }
+
+                        if (air.ClientName.Contains("-1") || air.ClientName.Contains("行程单") || air.FlightsCode.Contains("行程单"))
+                        {
+                            continue;
+                        }
+
+                        string errMsg = string.Empty;
+
+                        if (air.FlightsDescription.Contains("\r\n"))
+                        {
+                            var rowCode = Regex.Split(air.FlightsDescription, "\\d+\\.", RegexOptions.IgnoreCase).Where(x=>!string.IsNullOrWhiteSpace(x)).ToArray();
+                            for (int i = 0; i < rowCode.Length; i++)
+                            {
+                                if (i != 0)
+                                {
+                                    try
+                                    {
+                                        var columnValue = rowCode[i].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
+                                        string day = columnValue[2].Substring(2, 2);//日
+                                        string monthAbbreviations = columnValue[2].Substring(4, 3).ToUpper();//月份
+                                        monthAbbreviations = GeneralMethod.GetLonger(monthAbbreviations);
+                                        string EndHHmm = columnValue[5].Substring(0, 2) + ":" + columnValue[5].Substring(2, 2);
+                                        DateTime EndData = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations}-{day} {EndHHmm}");//当前班次
+
+                                        var spDotandEmpty1 = rowCode[i - 1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
+                                        string day1 = spDotandEmpty1[2].Substring(2, 2);//日
+                                        string monthAbbreviations1 = spDotandEmpty1[2].Substring(4, 3).ToUpper();//月份
+                                        monthAbbreviations1 = GeneralMethod.GetLonger(monthAbbreviations1);
+                                        string HHmm = spDotandEmpty1[6].Substring(0, 2) + ":" + spDotandEmpty1[6].Substring(2, 2);
+                                        DateTime data = DateTime.Parse($"{DateTime.Now.Year}-{monthAbbreviations1}-{day1} {HHmm}");//上个班次
+
+                                        TimeSpan t3 = EndData - data;  //两个时间相减 。默认得到的是 两个时间之间的天数   得到:365.00:00:00  
+                                        double getHour = t3.TotalHours;
+
+                                        if (getHour >= 6)
+                                        {
+                                            if (air.Price > 0)
+                                            {
+                                                airCount += 1;
+                                            }
+                                            else
+                                            {
+                                                airCount -= 1;
+                                            }
+                                        }
+                                    }
+                                    catch (Exception ex)
+                                    {
+                                        errMsg  = "机票行程代码格式有误!解析失败!" + $"({ex.Message})";
+                                        break;
+                                    }
+                                }
+                                else
+                                {
+                                    if (air.Price > 0)
+                                    {
+                                        airCount += 1;
+                                    }
+                                    else
+                                    {
+                                        airCount -= 1;
+                                    }
+                                }
+                            }
+                        }
+                        else
+                        {
+                            if (air.Price > 0)
+                            {
+                                airCount++;
+                            }
+                            else
+                            {
+                                airCount--;
+                            }
+                        }
+
+                        string info = $"航班{air.FlightsCode} {(air.Price > 0 ? "" : "此笔为退费!")} 人数为{air.ClientNum} 有效段数为{airCount} 总段数为{airCount * air.ClientNum}";
+                        if (!string.IsNullOrWhiteSpace(errMsg))
+                        {
+                            info = $"航班{air.FlightsCode} " + errMsg ;
+                        }
+                        infos.Add(info); 
+                        groupAirCount += airCount * air.ClientNum;
+                    }
+                    var groupinfo = listAir.First(x => x.Id == airArr.Key);
+                    string temp = "本团人数" + Convert.ToInt32(groupinfo.VisitPNumber) + ",该人员" + user.CnName + "共订航段数" + groupAirCount.ToString() + ",每程航班提成为10元," + user.CnName + "提成共" + (groupAirCount * 10).ToString("#0.00");
+                    resultArr.Add(new
+                    {
+                        groupinfo.TeamName,
+                        groupinfo.Id,
+                        chiArr = infos,
+                        teamLvStr = teamLv.Find(x=>x.Id == groupinfo.TeamLevSId)?.Name,
+                        groupinfo.VisitDate,
+                        temp,
+                        price = (groupAirCount * 10),
+                    }) ;
+                }
+            }
+            else if (Hotel.Contains(userId))
+            {
+                var listHotel = _sqlSugar.Queryable<Grp_HotelReservations, Grp_DelegationInfo>((x, a) => x.DiId == a.Id)
+                    .Where((x, a) => x.IsDel == 0 && x.CreateUserId == userId && a.VisitDate > StartDateTime && a.VisitDate < EndDateTime && a.IsDel == 0).ToList();
+
+            }
+            else if (OP.Contains(userId))
+            {
+
+
+            }
+
+            jw.Data = resultArr;
+            if (resultArr.Count > 0)
+            {
+                jw.Code = 200;
+                jw.Msg = "success!";
+            }
+            else
+            {
+                jw.Msg = "暂无数据!";
+            }
+
+            return Ok(jw);
+        
+        }
+        #endregion
     }
 }

+ 17 - 0
OASystem/OASystem.Domain/Dtos/Financial/ComputeRoyaltiesDto.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OASystem.Domain.Dtos.Financial
+{
+    public class ComputeRoyaltiesDto
+    {
+        public int UserId { get; set; }
+
+        public string StartDate { get; set; }
+        public string EndDate { get; set; }
+
+    }
+}