소스 검색

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

Lyyyi 2 일 전
부모
커밋
fef62a1974

+ 119 - 1
OASystem/OASystem.Api/Controllers/MarketCustomerResourcesController.cs

@@ -9,6 +9,8 @@ using OASystem.Infrastructure.Repositories.CRM;
 using OASystem.RedisRepository;
 using System.Collections;
 using System.Data;
+using System.Net;
+using UAParser;
 
 namespace OASystem.API.Controllers
 {
@@ -65,7 +67,7 @@ namespace OASystem.API.Controllers
         /// </summary>
         /// <returns></returns>
         [HttpPost]
-        [ApiLog("Crm_NewClientData", OperationEnum.List)]
+        //[ApiLog("Crm_NewClientData", OperationEnum.List)]
         [ProducesResponseType(typeof(JsonView), StatusCodes.Status200OK)]
         public async Task<IActionResult> QueryNewClientData(NewClientDataQueryDto dto)
         {
@@ -78,6 +80,8 @@ namespace OASystem.API.Controllers
             #endregion
 
             JsonView jw = new JsonView();
+            var startTime = DateTime.UtcNow; 
+
             try
             {
                 Result resultData = await _clientDataRepository.QueryNewClientData(dto);
@@ -98,6 +102,94 @@ namespace OASystem.API.Controllers
             {
                 jw = JsonView(false, "程序错误!");
             }
+            finally
+            {
+                using var ssg = _sqlSugar.CopyNew();
+                var status = HttpContext.Response.StatusCode.ToString();
+                _ = Task.Run(async () =>
+                {
+                    try
+                    {
+                        string remoteIp = string.Empty,
+                               location = string.Empty;
+
+                        // 检查请求头中的X-Forwarded-For,以获取真实的客户端IP地址
+                        if (HttpContext.Request.Headers.ContainsKey("X-Forwarded-For"))
+                        {
+                            remoteIp = HttpContext.Request.Headers["X-Forwarded-For"].ToString().Split(',', StringSplitOptions.RemoveEmptyEntries)[0];
+                        }
+                        else
+                        {
+                            remoteIp = HttpContext.Connection.RemoteIpAddress?.ToString();
+                        }
+
+                        var task = GetIpInfo(remoteIp);
+
+                        string deviceType = string.Empty, browser = string.Empty, os = string.Empty;
+                        var userAgent = HttpContext.Request.Headers["User-Agent"].FirstOrDefault();
+                        if (!string.IsNullOrEmpty(userAgent))
+                        {
+                            // 解析User-Agent头
+                            var parser = Parser.GetDefault();
+                            var client = parser.Parse(userAgent);
+
+                            // 提取浏览器信息
+                            browser = client.UA.Family; // 浏览器名称
+                            var browserVersion = client.UA.Major + "." + client.UA.Minor + "." + client.UA.Patch; // 浏览器版本
+                            browser += $"({browserVersion})";
+
+                            // 提取操作系统信息
+                            os = client.OS.Family; // 操作系统名称
+
+                            var osVersion = string.Empty; // 操作系统版本
+                            if (!string.IsNullOrEmpty(client.OS.Major)) osVersion += client.OS.Major;
+                            if (!string.IsNullOrEmpty(client.OS.Minor)) osVersion += "." + client.OS.Minor;
+                            if (!string.IsNullOrEmpty(client.OS.Patch)) osVersion += "." + client.OS.Patch;
+
+                            if (!string.IsNullOrEmpty(osVersion)) os += $"({osVersion})";
+
+                            // 提取设备信息
+                            deviceType = client.Device.Family; // 设备类型,如 'mobile', 'tablet', 'desktop' 等
+
+                        }
+
+                        // 记录请求结束时间
+                        var endTime = DateTime.UtcNow;
+                        // 计算耗时
+                        var duration = (long)(endTime - startTime).TotalMilliseconds;
+
+                        //等待任务进行
+                        (remoteIp, location) = await task;
+
+                        //单独记录操作
+                        var logInfo = new Crm_TableOperationRecord()
+                        {
+                            TableName = "Crm_NewClientData",
+                            PortType = dto.PortType,
+                            OperationItem = OperationEnum.List,
+                            DataId = 0,
+                            RequestUrl = "/api/MarketCustomerResources/QueryNewClientData",
+                            RemoteIp = remoteIp,
+                            Location = location,
+                            RequestParam = JsonConvert.SerializeObject(dto),
+                            ReturnResult = JsonConvert.SerializeObject(jw),
+                            Elapsed = duration,
+                            Status = status,
+                            CreateUserId = dto.OperationUserId,
+                            UpdatePreData = "",
+                            UpdateBefData = "",
+                            Browser = browser,
+                            Os = os,
+                            DeviceType = deviceType,
+                        };
+                        // 存储到数据库
+                        await ssg.Insertable(logInfo).ExecuteCommandAsync();
+                    }
+                    catch (Exception ex)
+                    {
+                    }
+                });
+            }
 
             return Ok(jw);
         }
@@ -1466,6 +1558,32 @@ namespace OASystem.API.Controllers
             return count > 0 ? Ok(JsonView(true, "分配成功!", count)) : Ok(JsonView(false, "分配失败!"));
         }
 
+        /// <summary>
+        /// 获取IP信息
+        /// </summary>
+        /// <param name="ip">ipv4 or ipv6</param>
+        /// <returns></returns>
+        private async Task<(string ip, string local)> GetIpInfo(string ip)
+        {
+            string local = string.Empty;
+
+            if (IPAddress.TryParse(ip, out _))
+            {
+                using HttpClient _httpClient = new HttpClient();
+                var response = await _httpClient.GetAsync($"https://api.vore.top/api/IPdata?ip={ip}");
+                response.EnsureSuccessStatusCode();
+                var json = await response.Content.ReadAsStringAsync();
+                var ipInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(json);
+                if (ipInfo.code == 200)
+                {
+                    ip = ipInfo.ipinfo.text;
+                    local = $"{ipInfo.adcode.o}";
+                }
+            }
+
+            return (ip, local);
+        }
+
         #region 回滚数据记录
 
 

+ 52 - 0
OASystem/OASystem.Infrastructure/Repositories/Groups/DecreasePaymentsRepository.cs

@@ -349,6 +349,58 @@ namespace OASystem.Infrastructure.Repositories.Groups
                     }
                     #endregion
 
+                    #region 会务成本自动审核处理
+
+                    if (false)
+                    {
+                        var main = _sqlSugar.Queryable<Grp_ConferenceAffairsCost>()
+                                            .First(x => x.Diid == dto.DiId && x.IsDel == 0);
+
+                        if (main != null)
+                        {
+
+                            var chiArr = _sqlSugar.Queryable<Grp_ConferenceAffairsCostChild>()
+                                .Where(x => x.Diid == dto.DiId && x.ConferenceAffairsCostId == main.Id && x.IsDel == 0)
+                                .ToList();
+                            var find = chiArr.FirstOrDefault(x => x.PriceName == dto.PriceName && x.ReviewStatus == 1);
+                            var isAuto = false;
+
+                            //存在已审的会务成本
+                            if (find != null)
+                            {
+
+                                //币种不同情况
+                                if (find.Currency != dto.Currency)
+                                {
+                                    //币种全转换为人民币
+                                    var rate = teamRates.Where(it => it.CurrencyId == grp_Decrease.Currency).FirstOrDefault();
+                                    if (rate != null)
+                                    {
+                                        //dto.Price *= rate.Rate;
+                                        grp_Decrease.FeeTotal *= rate.Rate;
+                                    }
+
+                                    var ConferenceAffairsCostFeeTotal = 0.00M;
+                                    var ConferenceAffairsCostRate = teamRates.Where(it => it.CurrencyId == find.Currency).FirstOrDefault();
+                                    if (rate != null)
+                                    {
+                                        //dto.Price *= rate.Rate;
+                                        ConferenceAffairsCostFeeTotal = rate.Rate * find.CostPrice * find.Count;
+                                    }
+
+                                }
+                                else
+                                {
+                                    isAuto = find.CostPrice >= dto.Price && find.Count >= dto.Quantity;
+                                }
+                            }
+
+                            if (isAuto) { }
+                        }
+                    }
+
+                    #endregion
+
                     CommitTran();
                     var data = new { ccpId = cId, sign = 1, dataId = id };
                     return new JsonView() { Code = 200, Msg = "添加成功!", Data = data };