From 3f91a6737fc06b45461ce11eae5660cbbf766f7e Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期二, 29 十月 2024 16:20:02 +0800
Subject: [PATCH] 推广人员-》地推权限   创建时间-》注册时间

---
 CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs |  346 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 336 insertions(+), 10 deletions(-)

diff --git a/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs b/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs
index f2fcbb1..a6f48b9 100644
--- a/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs
+++ b/CoreCms.Net.Web.Admin/Controllers/Com/ToolsController.cs
@@ -1,10 +1,10 @@
 锘�/***********************************************************************
- *            Project: CoreCms
- *        ProjectName: 鏍稿績鍐呭绠$悊绯荤粺                                
- *                Web: https://www.corecms.net                      
- *             Author: 澶х伆鐏�                                          
- *              Email: jianweie@163.com                                
- *         CreateTime: 2021/1/31 21:45:10
+ *            Project: baifenBinfa
+ *        ProjectName: 鐧惧垎鍏垫硶绠$悊绯荤粺                               
+ *                Web: http://chuanyin.com                     
+ *             Author:                                        
+ *              Email:                               
+ *         CreateTime: 202403/02   
  *        Description: 鏆傛棤
  ***********************************************************************/
 
@@ -37,8 +37,13 @@
 using COSXML.Auth;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.IdentityModel.Tokens;
 using Newtonsoft.Json;
+using NPOI.HSSF.UserModel;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
 using SKIT.FlurlHttpClient.Wechat.Api;
 using SKIT.FlurlHttpClient.Wechat.Api.Models;
 using SqlSugar;
@@ -89,6 +94,7 @@
         private readonly IWeChatApiHttpClientFactory _weChatApiHttpClientFactory;
 
         private readonly SemaphoreSlim _semaphore;
+        private readonly ICoreCmsPlanOrderServices _coreCmsPlanOrderServices;
 
         /// <summary>
         ///     鏋勯�犲嚱鏁�
@@ -111,7 +117,8 @@
             , ISysUserRoleServices sysUserRoleServices
             , ISysOrganizationServices sysOrganizationServices,
             ICoreCmsLogisticsServices logisticsServices, ISysLoginRecordServices sysLoginRecordServices, ISysNLogRecordsServices sysNLogRecordsServices, ICoreCmsBillPaymentsServices paymentsServices, ICoreCmsBillDeliveryServices billDeliveryServices, ICoreCmsUserServices userServices, ICoreCmsOrderServices orderServices, ICoreCmsBillAftersalesServices aftersalesServices, ICoreCmsSettingServices settingServices, ICoreCmsProductsServices productsServices, ICoreCmsServicesServices servicesServices, ISysRoleMenuServices sysRoleMenuServices
-            , IWeChatApiHttpClientFactory weChatApiHttpClientFactory, ICoreCmsPagesServices pagesServices, IToolsServices toolsServices, ICoreCmsReportsServices reportsServices, ICoreCmsGoodsCategoryServices goodsCategoryServices)
+            , IWeChatApiHttpClientFactory weChatApiHttpClientFactory, ICoreCmsPagesServices pagesServices, IToolsServices toolsServices, ICoreCmsReportsServices reportsServices, ICoreCmsGoodsCategoryServices goodsCategoryServices
+            , ICoreCmsPlanOrderServices  coreCmsPlanOrderServices )
         {
             _user = user;
             _webHostEnvironment = webHostEnvironment;
@@ -148,6 +155,7 @@
             _toolsServices = toolsServices;
             _reportsServices = reportsServices;
             _goodsCategoryServices = goodsCategoryServices;
+            _coreCmsPlanOrderServices = coreCmsPlanOrderServices;
 
             //鏈�澶氬厑璁�2涓嚎绋嬪悓鏃惰闂�;
             _semaphore = new SemaphoreSlim(2);
@@ -362,6 +370,311 @@
         #endregion
 
         //閫氱敤鎿嶄綔=========================================================================
+
+        #region 璁″垝璁㈠崟涓婁紶鎺ュ彛====================================================
+
+        /// <summary>
+        /// 璁″垝璁㈠崟涓婁紶鎺ュ彛
+        /// </summary>
+        /// <returns></returns>
+        [Authorize]
+        [HttpPost]
+        public async Task<AdminUiCallBack> UploadFilesXls()
+        {
+
+            var jm = new AdminUiCallBack();
+            await _semaphore.WaitAsync();
+            try
+            {
+                var filesStorageOptions = await _coreCmsSettingServices.GetFilesStorageOptions();
+
+                //鍒濆鍖栦笂浼犲弬鏁�
+                var maxSize = 1024 * 1024 * filesStorageOptions.MaxSize; //涓婁紶澶у皬5M
+
+                var file = Request.Form.Files["file"];
+                if (file == null)
+                {
+                    jm.msg = "璇烽�夋嫨鏂囦欢";
+                    return jm;
+                }
+
+                var fileName = file.FileName;
+                var fileExt = Path.GetExtension(fileName).ToLowerInvariant();
+
+                //妫�鏌ュぇ灏�
+                if (file.Length > maxSize)
+                {
+                    jm.msg = "涓婁紶鏂囦欢澶у皬瓒呰繃闄愬埗锛屾渶澶у厑璁镐笂浼�" + filesStorageOptions.MaxSize + "M";
+                    return jm;
+                }
+
+                //妫�鏌ユ枃浠舵墿灞曞悕
+                if (string.IsNullOrEmpty(fileExt) ||
+                    Array.IndexOf(filesStorageOptions.FileTypes.Split(','), fileExt.Substring(1).ToLower()) == -1)
+                {
+                    jm.msg = "涓婁紶鏂囦欢鎵╁睍鍚嶆槸涓嶅厑璁哥殑鎵╁睍鍚�,璇蜂笂浼犲悗缂�鍚嶄负锛�" + filesStorageOptions.FileTypes;
+                    return jm;
+                }
+                var lie = new List<JiHuaOrder>();
+                using (var fileStream = file.OpenReadStream())
+                {
+
+                    // 浣跨敤HSSFWorkbook鎵撳紑.xls鏍煎紡鐨勬枃浠�
+                    IWorkbook workbook = new XSSFWorkbook(fileStream);
+
+                    // 鑾峰彇绗竴涓伐浣滆〃
+                    ISheet sheet = workbook.GetSheetAt(0);
+
+                
+
+                    // 杩唬宸ヤ綔琛ㄤ腑鐨勬墍鏈夎
+                    for (int i = 1; i <= sheet.LastRowNum; i++)
+                    {
+                        var hang = new JiHuaOrder();
+                        IRow row = sheet.GetRow(i);
+                        if (row == null) continue; // 璺宠繃绌鸿
+
+
+                        ICell cell0 = row.GetCell(0);
+                        if (cell0 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "甯備笉鑳戒负绌�";
+                            return jm;
+                        }
+                        hang.shi = getcellvalue(cell0);
+
+                        ICell cell1 = row.GetCell(1);
+                        if (cell1 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "鍖哄幙涓嶈兘涓虹┖";
+                            return jm;
+                        }
+                        hang.quxian = getcellvalue(cell1);
+
+                        ICell cell2 = row.GetCell(2);
+                        if (cell2 == null)
+                        {
+                            jm.msg ="绗�" +(i+1) + "鐗囧尯涓嶈兘涓虹┖";
+                            return jm;
+                        }
+                        hang.pianqu = getcellvalue(cell2);
+
+                        ICell cell3 = row.GetCell(3);
+                        if (cell3 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "瀛︽牎涓嶈兘涓虹┖";
+                            return jm;
+                        }
+                        hang.shipAddress = getcellvalue(cell3);
+
+                        ICell cell4 = row.GetCell(4);
+                        if (cell4 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "鑱旂郴浜轰笉鑳戒负绌�"; 
+                            return jm;
+                        }
+                        hang.shipName = getcellvalue(cell4);
+
+                        ICell cell5 = row.GetCell(5);
+                        if (cell5 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "鑱旂郴鐢佃瘽涓嶈兘涓虹┖"; 
+                            return jm;
+                        }
+                        hang.shipMobile = getcellvalue(cell5);
+
+                        ICell cell6 = row.GetCell(6);
+                        if (cell6 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "鏀惰揣鍦板潃涓嶈兘涓虹┖";   
+                            return jm;
+                        }
+                        hang.shouhuoAddress = getcellvalue(cell6);
+
+                        ICell cell7 = row.GetCell(7);
+                        if (cell7 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "鍟嗗搧鍚嶇О涓嶈兘涓虹┖";
+                            return jm;
+                        }
+                        hang.name = getcellvalue(cell7);
+
+                        ICell cell8 = row.GetCell(8);
+                        if (cell8 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "瑙勬牸涓嶈兘涓虹┖"; 
+                            return jm;
+                        }
+                        hang.specification = getcellvalue(cell8);
+
+
+                        ICell cell9 = row.GetCell(9);
+                        if (cell9 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "鍗曚环锛堝厓锛変笉鑳戒负绌�";    
+                            return jm;
+                        }
+                        hang.price = decimal.Parse(getcellvalue(cell9));
+
+
+                        ICell cell10 = row.GetCell(10);
+                        if (cell10 == null)
+                        {
+                            jm.msg = "绗�" + (i + 1) + "鏁伴噺涓嶈兘涓虹┖";
+                            return jm;
+                        }
+                        hang.nums = int.Parse(getcellvalue(cell10));
+
+                        lie.Add(hang);
+
+                    }
+                }
+               // lie = lie.OrderBy(x => x.shipAddress).ThenBy(x => x.specification).ToList();
+                string url = string.Empty;
+                url = "121212";
+                string pianqu = "";
+                if (lie!=null && lie.Count > 0)
+                {
+                   var  order = new List<JiHuaOrder>();
+                    for(int i=0;i< lie.Count; i++)
+                    {
+                        if (i == 0 )
+                        {
+                          
+                            order.Add(lie[i]);
+                            pianqu = lie[i].pianqu;
+                            //if(lie.Count == 1)
+                            //{
+                            //    //淇濆瓨璁㈠崟
+                            //    jm = await  _coreCmsPlanOrderServices.ToAddJiHua(lie,_user.ID, _user.Name);
+                            //    if (jm.code == 1)
+                            //    {
+                            //        return jm;
+                            //    }
+                            //}
+                        }
+                        else
+                        {
+                            if(string.IsNullOrEmpty(lie[i].shipAddress))
+                            {
+                                order.Add(lie[i]);
+                            }
+                            else
+                            {
+                                //淇濆瓨璁㈠崟
+                                jm = await _coreCmsPlanOrderServices.ToAddJiHua(order, _user.ID, _user.Name);
+                                if (jm.code == 1)
+                                {
+                                    return jm;
+                                }
+                                order = new List<JiHuaOrder>();
+                                if (string.IsNullOrEmpty(lie[i].shi))
+                                {
+                                    lie[i].shi = lie[0].shi;
+                                }
+                                if (string.IsNullOrEmpty(lie[i].quxian))
+                                {
+                                    lie[i].quxian = lie[0].quxian;
+                                }
+                                if (string.IsNullOrEmpty(lie[i].pianqu))
+                                {
+                                    lie[i].pianqu = pianqu;
+                                }
+                                else
+                                {
+                                    pianqu = lie[i].pianqu;
+                                }
+                                order.Add(lie[i]);
+                            }
+                        }
+
+                        if (i == lie.Count - 1)
+                        {
+                            //淇濆瓨璁㈠崟
+                            jm = await _coreCmsPlanOrderServices.ToAddJiHua(order, _user.ID, _user.Name);
+                            if (jm.code == 1)
+                            {
+                                return jm;
+                            }
+                        }
+                    }
+
+
+                }
+                else
+                {
+                    jm.code =1;
+                    jm.msg = "琛ㄦ牸鏃犳暟鎹�";
+                    jm.data = new
+                    {
+                        fileUrl = url,
+                        src = url
+                    };
+                }
+
+              
+
+              
+                var bl = !string.IsNullOrEmpty(url);
+                jm.code = bl ? 0 : 1;
+                jm.msg = bl ? "涓婁紶鎴愬姛!" : "涓婁紶澶辫触";
+                jm.data = new
+                {
+                    fileUrl = url,
+                    src = url
+                };
+            }
+            catch (Exception e)
+            {
+                jm.code = 1;
+                jm.msg = "鏁版嵁寮傚父";
+                jm.data = e;
+            }
+            finally
+            {
+                _semaphore.Release(); // 閲婃斁璁块棶
+            }
+
+            return jm;
+        }
+
+
+        /// <summary>
+        /// 璁″垝璁㈠崟涓婁紶鎺ュ彛
+        /// </summary>
+        /// <returns></returns>
+        public string getcellvalue(ICell cell)
+        {
+            string cellvalue = "";
+            switch (cell.CellType)
+            {
+                case CellType.String:
+                    // Console.WriteLine(cell.StringCellValue);
+                    cellvalue = cell.StringCellValue.Trim();
+                    break;
+                case CellType.Numeric:
+                    //Console.WriteLine(cell.NumericCellValue);
+                    cellvalue = cell.NumericCellValue.ToString().Trim();
+                    break;
+                case CellType.Boolean:
+                    //Console.WriteLine(cell.BooleanCellValue);
+                    cellvalue = cell.BooleanCellValue.ToString().Trim();
+                    break;
+                case CellType.Error:
+                    // Console.WriteLine(cell.ErrorCellValue);
+                    cellvalue = cell.ErrorCellValue.ToString().Trim();
+                    break;
+                    // 鍙互娣诲姞鍏朵粬绫诲瀷鐨刢ase
+            }
+
+            return cellvalue;
+        }
+
+
+
+
+        #endregion
+
 
         #region 閫氱敤涓婁紶鎺ュ彛====================================================
 
@@ -934,11 +1247,11 @@
 
         #endregion
 
-        #region 鍚庡彴鐢熸垚鍒嗛攢鍟嗗皬绋嬪簭鐮�============================================================
+        #region 鍚庡彴鐢熸垚缁忛攢鍟嗗皬绋嬪簭鐮�============================================================
 
         // POST: Api/Tools/GetDistributionWxCode
         /// <summary>
-        ///     鍚庡彴鐢熸垚鍒嗛攢鍟嗗皬绋嬪簭鐮�
+        ///     鍚庡彴鐢熸垚缁忛攢鍟嗗皬绋嬪簭鐮�
         /// </summary>
         /// <returns></returns>
         [HttpPost]
@@ -1641,17 +1954,30 @@
                                 await _areaServices.QueryListByClauseAsync(p => p.parentId == model.info.parentId);
                         res.Add(model);
                     }
+                    else
+                    {
+                        //淇敼涓嶅彲浠ヤ换鎰忛�夋嫨灞傜骇鐨刡ug
+                        model2.thisList = await _areaServices.QueryListByClauseAsync(p => p.parentId == 0);
+                    }
 
                     res.Add(model2);
                 }
+                else
+                    if(model3.info!=null&&model3.info.parentId==0)
+                        {
+                    //淇敼涓嶅彲浠ヤ换鎰忛�夋嫨灞傜骇鐨刡ug
+                    model3.thisList = await _areaServices.QueryListByClauseAsync(p => p.parentId == 0);
+                }
+
 
                 res.Add(model3);
             }
             else
             {
+                //淇敼涓嶅彲浠ヤ换鎰忛�夋嫨灞傜骇鐨刡ug
                 var model4 = new AreasDtoForAdminEdit();
                 model4.list = await _areaServices.QueryListByClauseAsync(p => p.parentId == 0);
-                model4.info = model4.list.FirstOrDefault();
+                model4.info = null;
                 res.Add(model4);
             }
 

--
Gitblit v1.9.1