From 80aa425c4ca51f7c0224a6245968cdd08940321b Mon Sep 17 00:00:00 2001
From: 移动系统liao <liaoxujun@qq.com>
Date: 星期四, 13 六月 2024 10:17:30 +0800
Subject: [PATCH] 修改校园代理 完成

---
 CoreCms.Net.Services/baifenbingfa/BfbfComAPIService.cs |   85 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/CoreCms.Net.Services/baifenbingfa/BfbfComAPIService.cs b/CoreCms.Net.Services/baifenbingfa/BfbfComAPIService.cs
index 0b5c19e..9f355f2 100644
--- a/CoreCms.Net.Services/baifenbingfa/BfbfComAPIService.cs
+++ b/CoreCms.Net.Services/baifenbingfa/BfbfComAPIService.cs
@@ -4,6 +4,8 @@
 using CoreCms.Net.IServices.baifenbingfa;
 using CoreCms.Net.Model.Entities;
 using CoreCms.Net.Utility.Helper;
+using Nest;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -71,5 +73,88 @@
                 return 0;
             return count * 1;
         }
+
+        public List<DistributorSort> orderedDistributors(List<DistributorSort> DataList, string latitude, string longitude)
+        {
+          
+
+            GeoCoordinate inputLocation = new GeoCoordinate(double.Parse(longitude), double.Parse(latitude)); // 杈撳叆鐨勭粡绾害
+
+            var sortedDistributors = DataList.OrderBy(d => CalculateDistance(inputLocation, new GeoCoordinate(double.Parse(d.longitude), double.Parse(d.latitude))))
+                                                 .ToList();
+            return sortedDistributors;
+        }
+
+
+        /// <summary>
+        /// 璁$畻缁忕含杈捐窛绂�
+        /// </summary>
+        /// <param name="location1"></param>
+        /// <param name="location2"></param>
+        /// <returns></returns>
+        private static double CalculateDistance(GeoCoordinate location1, GeoCoordinate location2)
+        {
+            const double earthRadiusKm = 6371;
+            var dLat = ToRadians(location2.Latitude - location1.Latitude);
+            var dLon = ToRadians(location2.Longitude - location1.Longitude);
+
+            var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
+                    Math.Cos(ToRadians(location1.Latitude)) * Math.Cos(ToRadians(location2.Latitude)) *
+                    Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
+            var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
+            var distance = earthRadiusKm * c;
+
+            return distance;
+        }
+
+        private static double ToRadians(double degree)
+        {
+            return degree * Math.PI / 180;
+        }
+
+        /// <summary>
+        /// 鑾峰彇鏈夋晥鏍″洯浠g悊
+        /// </summary>
+        /// <param name="PIds"></param>
+        /// <returns></returns>
+        public async Task< List<DistributorSort>> GetDistributorsList(List<int> PIds)
+        {
+          var blist=  await  _unitOfWork.GetDbClient().Queryable<CoreCmsDistribution>().Where(x=>x.profession=="鏍″洯浠g悊"&&x.verifyStatus== (int)GlobalEnumVars.DistributionVerifyStatus.VerifyYes).ToListAsync();
+            List < DistributorSort > retlist=new List<DistributorSort>();            
+            foreach (var item in blist)
+            {
+                if (string.IsNullOrEmpty(item.storeCoordinate) || item.storeCoordinate == ",")
+                    //娌℃湁瀹氫綅锛屼笉鍔犲叆
+                    continue;
+                var ldinate=   item.storeCoordinate.Split(',');
+                retlist.Add(   new DistributorSort()
+                {
+                    id = item.id,
+                    latitude = ldinate[0],
+                    longitude = ldinate[1],
+                    name = item.schoolName + ":" + item.name
+
+
+
+                });
+            }
+            return retlist;
+        }
+
+
+
+        public async Task< List< int>> GetOderProductsIDs(string[] OderIds)
+        {
+          var list=   await  _unitOfWork.GetDbClient().Queryable<CoreCmsOrder>().Where(x => OderIds.Contains(x.orderId))              
+                .Select(x =>  new { items = SqlFunc.Subqueryable<CoreCmsOrderItem>().Where(it => it.orderId == x.orderId).ToList() }).ToListAsync();
+            var li=new List<int>();
+            foreach (var item in list)
+            {
+                li.AddRange(item.items.Select(x=>x.id).ToList());
+
+
+            }
+            return li;
+        }
     }
 }

--
Gitblit v1.9.1