From 9173f6e5b34a12c01804676d76842031e9ec6724 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期三, 26 六月 2024 11:52:16 +0800
Subject: [PATCH] Merge branch 'master' of http://47.108.235.38:8080/r/baifenbaishop

---
 CoreCms.Net.Web.Admin/Controllers/Distribution/CoreCmsDistributionController.cs |  237 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 223 insertions(+), 14 deletions(-)

diff --git a/CoreCms.Net.Web.Admin/Controllers/Distribution/CoreCmsDistributionController.cs b/CoreCms.Net.Web.Admin/Controllers/Distribution/CoreCmsDistributionController.cs
index 26eb665..1e7836d 100644
--- a/CoreCms.Net.Web.Admin/Controllers/Distribution/CoreCmsDistributionController.cs
+++ b/CoreCms.Net.Web.Admin/Controllers/Distribution/CoreCmsDistributionController.cs
@@ -27,10 +27,12 @@
 using CoreCms.Net.Utility.Extensions;
 using CoreCms.Net.Utility.Helper;
 using CoreCms.Net.Web.Admin.Infrastructure;
+using Essensoft.Paylink.Alipay.Domain;
 using Microsoft.AspNetCore.Authorization;
 using Microsoft.AspNetCore.Hosting;
 using Microsoft.AspNetCore.Mvc;
 using Microsoft.CodeAnalysis.Operations;
+using NPOI.SS.Formula.Functions;
 using SqlSugar;
 using ZstdSharp.Unsafe;
 
@@ -316,7 +318,7 @@
         {
             var jm = new AdminUiCallBack();
 
-            var user = await _userServices.QueryByClauseAsync(p => p.mobile == entity.registeredUserMobile);
+            var user = await _userServices.QueryByClauseAsync(p => p.id == entity.userId);
             if (user == null)
             {
                 jm.msg = "鎻愪氦鐨勩�愬凡娉ㄥ唽鎵嬫満鍙枫�戞湭鏌ヨ鍒版敞鍐岀敤鎴�";
@@ -326,27 +328,130 @@
             var isDistribution = await _coreCmsDistributionServices.ExistsAsync(p => p.userId == user.id);
             if (isDistribution)
             {
-                jm.msg = "鎻愪氦鐨勩�愬凡娉ㄥ唽鎵嬫満鍙枫�戝凡缁忔槸缁忛攢鍟嗕簡銆�";
+                jm.msg = "鎻愪氦鐨勭敤鎴峰凡缁忔湁缁忛攢鍟嗚褰曪紝璇锋壘鍒扮浉鍏抽」杩涜瀹℃牳";
                 return jm;
             }
             var model = new CoreCmsDistribution();
 
-            model.userId = user.id;
-            model.mobile = entity.registeredUserMobile;
+            model.userId = user.id;       
             model.name = entity.name;
             model.gradeId = entity.gradeId;
             model.mobile = string.IsNullOrEmpty(entity.mobile) ? user.mobile : entity.mobile;
-            model.weixin = entity.weixin;
-            model.qq = entity.qq;
+            model.profession = entity.profession;
+            model.storeCoordinate = entity.storeCoordinate;
+            model.storeLogo = entity.storeBanner;
+            model.storeName= entity.storeName;
+            model.sales=entity.sales;
+            model.areaCode=entity.areaCode;
+            model.address=entity.address;
             model.verifyStatus = entity.verifyStatus;
             model.createTime = DateTime.Now;
             model.isDelete = false;
-            if (model.verifyStatus == (int)GlobalEnumVars.DistributionVerifyStatus.VerifyYes) model.verifyTime = DateTime.Now;
+            try
+            {
+                _unitOfWork.BeginTran();
+                if (model.verifyStatus == (int)GlobalEnumVars.DistributionVerifyStatus.VerifyYes)
+                {
+                    model.verifyTime = DateTime.Now;
+                    //鑰佹ā鍨嬫湭閫氳繃瀹℃牳锛屾柊妯″瀷鏈�氳繃瀹℃牳锛岄偅涔堜负瀹℃牳閫氳繃杩囩▼
+                    var allConfigs = await _coreCmsSettingServices.GetConfigDictionaries();
+                    var kc = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.DictionaryUserGroupKey);
+              
+                    var group = await _userGradeServices.GetUserGradeByValueKey(kc);
+                    if (group != null)
+                    {
 
-            var id = await _coreCmsDistributionServices.InsertAsync(model);
+                        //鍏宠仈缁忛攢鍟嗙敤鎴风瓑绾�
+                        if (user != null)
+                        {
+                            user.grade = group.id;
+                            user.updataTime = DateTime.Now;
+                            await _userServices.UpdateAsync(user);
 
-            jm.code = id > 0 ? 0 : 1;
-            jm.msg = id > 0 ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
+                        }
+                    }
+                    //澶勭悊搴楅摵
+                    if (entity.profession == "鏂囧叿搴�")
+                    {
+
+                        //鏂板缓搴楅摵鍚嶇О
+
+                        var store = await _coreCmsStoreServices.QueryByClauseAsync(x => x.userID == model.userId);
+                        if (store != null)
+                        {
+                            //瀛樺湪搴楅摵
+                            store.coordinate = entity.storeCoordinate;
+                            store.storeName = entity.storeName;
+                            //鐢╨ogo浠f浛闂ㄥご鐓х墖
+                            store.logoImage = model.storeLogo;
+                            store.en = true;
+                            store.updateTime = DateTime.Now;
+                            await _coreCmsStoreServices.UpdateAsync(store);
+
+
+                        }
+                        else
+                        {
+                            var areaCode = model.areaCode.Split(',').OrderByDescending(x => x).FirstOrDefault();
+                            var db = _unitOfWork.GetDbClient();
+                            string[] lat = [];
+                            if (!string.IsNullOrEmpty(model.storeCoordinate))
+                                lat = model.storeCoordinate.Split(",");
+                            //鏂板缓鍦伴摵
+                            store = new CoreCmsStore
+                            {
+                                userID = model.userId,
+                                address = model.address,
+                                areaId = areaCode.ToInt32OrDefault(510000),
+                                storeName = model.storeName,
+                                coordinate = model.storeCoordinate,
+                                createTime = DateTime.Now,
+                                mobile = model.mobile,
+                                linkMan = user.nickName,
+
+
+
+                            };
+                            if (lat.Length == 2)
+                            {
+                                store.latitude = lat[0];
+                                store.longitude = lat[1];
+                            }
+                            var storeid = await _unitOfWork.GetDbClient().Insertable(store).ExecuteReturnIdentityAsync();
+
+                            //灏嗚嚜宸辫缃负搴楀憳
+                            CoreCmsClerk clerk = new CoreCmsClerk()
+                            {
+                                createTime = DateTime.Now,
+                                storeId = storeid,
+                                userId = entity.userId,
+
+                            };
+                            await _coreCmsClerkServices.InsertAsync(clerk);
+
+
+
+
+                        }
+
+                    }
+
+                }
+
+                
+                await _coreCmsDistributionServices.InsertAsync(model);
+
+                _unitOfWork.CommitTran();
+            }
+            catch (Exception)
+            {
+                _unitOfWork.RollbackTran();
+                throw;
+            }
+          
+
+            jm.code = 1;
+            jm.msg =  GlobalConstVars.CreateSuccess ;
             return jm;
         }
         #endregion
@@ -635,11 +740,76 @@
                 jm.msg = GlobalConstVars.DataisNo;
                 return jm;
             }
+            try
+            {
+                _unitOfWork.BeginTran();
+                
+                    //濡傛灉鏄彇娑堝鏍�
 
-            var bl = await _coreCmsDistributionServices.DeleteByIdAsync(entity.id);
-            jm.code = bl ? 0 : 1;
-            jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
-            return jm;
+                    var allConfigs = await _coreCmsSettingServices.GetConfigDictionaries();
+                    var kc = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.DictionaryUserGroupKey);
+                var group = await _userGradeServices.GetUserGradeByValueKey(kc);
+                var defgroup = await _userGradeServices.GetDefaultUserGrade();
+                    if (defgroup != null)
+                    {
+                        var olduser = await _userServices.QueryByIdAsync(model.userId);
+                        if (olduser != null)
+                        {//澶勭悊鐢ㄦ埛绛夌骇
+                            if (olduser.grade == group.id)
+                            {
+                                if (defgroup != null)
+                                {
+                                    olduser.grade = defgroup.id;
+                                }
+                                else
+                                {
+
+                                    olduser.grade = 0;
+                                }
+
+                                olduser.updataTime = DateTime.Now;
+                                await _userServices.UpdateAsync(olduser);
+
+                            }
+                        }
+                        var store = await _coreCmsStoreServices.QueryByClauseAsync(x => x.userID == model.userId);
+                        //澶勭悊搴楅摵  鍙栨秷宸叉湁搴楅摵鐨勪娇鑳�
+                       if(store != null )
+                           
+                        {
+
+
+                        // var clerk= await _unitOfWork.GetDbClient().Queryable<CoreCmsClerk>().Where(x => x.storeId == store.id).ToListAsync();
+                        //鍒犻櫎搴楅摵鍛樺伐
+                         await _unitOfWork.GetDbClient().Deleteable<CoreCmsClerk>().Where(x=>x.storeId==store.id).ExecuteCommandAsync();
+                        //鍒犻櫎搴楅摵
+                        await _coreCmsStoreServices.DeleteByIdAsync(store.id);
+                       
+                      
+
+                    }
+
+
+                    }
+                var  bl = await _coreCmsDistributionServices.DeleteByIdAsync(entity.id);
+
+                _unitOfWork.CommitTran();
+                jm.code = bl ? 0 : 1;
+                    jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
+
+                    return jm;
+
+            }
+            catch (Exception)
+            {
+
+                _unitOfWork.RollbackTran();
+                jm.code = 1;
+                jm.msg = GlobalConstVars.DeleteFailure;
+
+                return jm;
+            }
+        
 
         }
 
@@ -680,5 +850,44 @@
         }
 
         #endregion
+
+
+        #region 棰勮鏁版嵁============================================================
+
+        // POST: Api/CoreCmsDistribution/GetDetailsAchievement/10
+        /// <summary>
+        ///     棰勮鏁版嵁
+        /// </summary>
+        /// <param name="entity"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Description("棰勮鏁版嵁")]
+        public async Task<AdminUiCallBack> GetDetailsAchievement([FromBody] FMIntId entity)
+        {
+            var jm = new AdminUiCallBack();
+
+            var model = await _coreCmsDistributionServices.QueryByIdAsync(entity.id);
+            if (model == null)
+            {
+                jm.msg = "涓嶅瓨鍦ㄦ淇℃伅";
+                return jm;
+            }
+            var  distributionRankingDTOs = _coreCmsDistributionServices.QueryAchievement(model.userId);
+
+
+
+
+            jm.code = 0;
+            jm.data = distributionRankingDTOs;
+
+            return jm;
+        }
+
+        #endregion
+
+
+
+
+      
     }
 }
\ No newline at end of file

--
Gitblit v1.9.1