From 3ad8babb3a5929eadc18d3518563b6355a800681 Mon Sep 17 00:00:00 2001
From: 移动系统liao <liaoxujun@qq.com>
Date: 星期四, 07 八月 2025 12:59:24 +0800
Subject: [PATCH] no message

---
 Admin.NET/FZCTB.NET.API.Application/User/CustomerService.cs |  132 +++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 117 insertions(+), 15 deletions(-)

diff --git a/Admin.NET/FZCTB.NET.API.Application/User/CustomerService.cs b/Admin.NET/FZCTB.NET.API.Application/User/CustomerService.cs
index 9c5cf91..9635626 100644
--- a/Admin.NET/FZCTB.NET.API.Application/User/CustomerService.cs
+++ b/Admin.NET/FZCTB.NET.API.Application/User/CustomerService.cs
@@ -6,6 +6,7 @@
 
 using Admin.NET.Core;
 using Admin.NET.Core.Service;
+using Dm.util;
 using Furion;
 using Furion.DynamicApiController;
 using Furion.FriendlyException;
@@ -39,19 +40,22 @@
 
     private readonly SysCacheService _sysCacheService;
     private readonly SqlSugarRepository<FBS_ExRole> _fBS_ExRoleRep;
-
+    private readonly SqlSugarRepository<FBS_CoutomerExRole> _fBS_CustomerExRoleRep;
     private readonly SqlSugarRepository<FBS_EnterpriseType> _fBS_EnterpriseTypeRep;
     private readonly SqlSugarRepository<FBS_Customer> _fBS_CustomerRep;
     /// <summary>
     /// 鐢ㄦ埛鎵╁睍
     /// </summary>
     private readonly SqlSugarRepository<FBS_CusExtend> _fBS_CusExtendRep;
+
     private IMapper _mapper;
     /// <summary>
     /// 
     /// </summary>
     public CustomerService(SysCacheService cacheService, CustomerManagerS managerS,SqlSugarRepository<FBS_Customer>  repository
-        , SqlSugarRepository<FBS_EnterpriseType> fbsenrep,IMapper mapper,SqlSugarRepository<FBS_ExRole> exroles , SqlSugarRepository<FBS_CusExtend> cusrep)
+        , SqlSugarRepository<FBS_EnterpriseType> fbsenrep,IMapper mapper,SqlSugarRepository<FBS_ExRole> exroles ,
+        SqlSugarRepository<FBS_CusExtend> cusrep,
+        SqlSugarRepository<FBS_CoutomerExRole> cexrrep)
     {
         _sysCacheService= cacheService;
          _customerManager = managerS;
@@ -60,6 +64,7 @@
         _fBS_ExRoleRep = exroles;
         _fBS_CusExtendRep = cusrep;
         _mapper = mapper;
+        _fBS_CustomerExRoleRep = cexrrep;
     }
 
     /// <summary>
@@ -111,15 +116,26 @@
         dd.CreateTime = DateTime.Now;
         dd.CreateUserId = 0;
         dd.CreateUserName = dd.NickName;
-        dd.CoutomerExRols = new List<FBS_CoutomerExRole>()
+        if(dd.CoutomerExRols==null)
+        {
+            new List<FBS_CoutomerExRole>()
         {
             new FBS_CoutomerExRole
             {
                  ExRoleId= ExRole?.Id??0
-                  
-                  
+
+
             }
         };
+        }
+        else
+        {
+            dd.CoutomerExRols.add(new FBS_CoutomerExRole
+            {
+                ExRoleId = ExRole?.Id ?? 0
+            });
+        }
+    
             
             
          
@@ -168,18 +184,42 @@
         {
             throw Oops.Oh("鐢ㄦ埛涓嶅瓨鍦�");
         }
+  
        var rols= await  _fBS_ExRoleRep.GetFirstAsync(x => x.Code == cusExtend.TransactionCode && x.Status == StatusEnum.Enable);
         if(rols==null)
         {
             throw Oops.Oh("浜ゆ槗涓讳綋涓嶅瓨鍦�");
         }
-
-        if(user.CoutomerExRols?.Any(x=>x.ExRole.Code==cusExtend.TransactionCode&& x.HasFlsh==true)==true)
+        var ExRoles = await _fBS_CustomerExRoleRep.GetListAsync(x => x.CustomerId == id);
+        if (ExRoles != null)
         {
-            throw Oops.Oh("鐢ㄦ埛宸茬粡娉ㄥ唽浜嗚涓讳綋");
+            if (ExRoles?.Any(x => x.ExRoleId == rols.Id && x.HasFlsh == true) == true)
+            {
+                throw Oops.Oh("鐢ㄦ埛宸茬粡娉ㄥ唽浜嗚涓讳綋");
+            }
+           
         }
-     
 
+        //澧炲姞鐢ㄦ埛瑙掕壊
+        await _fBS_CustomerExRoleRep.InsertAsync(new FBS_CoutomerExRole
+        {
+            ExRoleId = rols.Id,
+            CustomerId = id
+        });
+
+
+        var usdata = await _fBS_CusExtendRep.GetFirstAsync(x => x.CustomerId == id&&x.TransactionCode==cusExtend.TransactionCode);
+       
+        if (usdata!=null)
+        {
+            if (usdata.steps == CusExtendStep.Pass)
+            {
+                throw Oops.Oh("鐢ㄦ埛宸茬粡娉ㄥ唽浜嗚涓讳綋");
+
+            }
+            throw Oops.Oh("鐢ㄦ埛宸茬粡鐢宠浜嗚瑙掕壊锛岃璧颁慨鏀规祦绋�");
+        }
+       
         var data= cusExtend.Adapt<FBS_CusExtend>();
 
         data.steps = CusExtendStep.UNExamine;
@@ -270,7 +310,11 @@
             throw Oops.Oh("娌℃湁瀹屾垚淇℃伅褰曞叆");
         }
 
-
+        bool  isChangeData = false;
+        if (tab.steps== CusExtendStep.Change)
+        {
+            isChangeData = true;
+        }
 
 
 
@@ -299,14 +343,31 @@
             //閲嶆柊瀹℃牳?
             tab.steps = CusExtendStep.Change;
         }
-        tab.EnterpriseType = InParam.EnterpriseType;
+        if (tab.EnterpriseType != InParam.EnterpriseType)
+        {
+            tab.EnterpriseType = InParam.EnterpriseType;
+            tab.steps = CusExtendStep.Change;
+        }
 
         //鑱旂郴鐢佃瘽
         tab.EnterprisePhone = InParam.EnterprisePhone;
         tab.EnterpriseEmail = InParam.EnterpriseEmail;
+
+        if (tab.BankAccount != InParam.BankAccount)
+        {
+            //鑱旂郴鐢佃瘽
+            tab.BankAccount = InParam.BankAccount;
+            tab.steps = CusExtendStep.Change;
+
+        }
+        if (tab.BankName != InParam.BankName)
+        {
+            tab.BankName = InParam.BankName;
+            tab.steps = CusExtendStep.Change;
+        }
         //閾惰鏄惁闇�瑕佷慨鏀�
-        tab.BankAccount = InParam.BankAccount;
-        tab.BankName = InParam.BankName;
+        //tab.BankAccount = InParam.BankAccount;
+        //tab.BankName = InParam.BankName;
 
         // 缁忓姙浜�
         if (tab.OperatorIdCard != InParam.OperatorIdCard)
@@ -317,9 +378,50 @@
             tab.OperatorName = InParam.OperatorName;
             tab.OperatorPhone = InParam.OperatorPhone;
         }
-       
 
-        return await _fBS_CusExtendRep.UpdateAsync(tab);
+
+      await   _fBS_CusExtendRep.AsTenant().BeginTranAsync();
+        try
+        {
+            if((!isChangeData)&&tab.steps== CusExtendStep.Change)
+            {
+                //鏄洿鏀癸紝闇�瑕佸伐鏀筩er鐨勫��
+             var exrolerep=     await   _fBS_CustomerExRoleRep.GetFirstAsync(x=>x.ExRoleId== rols.Id&&x.CustomerId==tab.CustomerId);
+                if(exrolerep!=null)
+                {
+                    if (exrolerep.HasFlsh != false)
+                    {
+                        exrolerep.HasFlsh = false;
+                       
+                        //鏀瑰彉鐘舵��
+                        await _fBS_CustomerExRoleRep.UpdateAsync(exrolerep);
+                    };
+
+
+                }
+                else
+                {
+                    await _fBS_CustomerExRoleRep.InsertAsync(new FBS_CoutomerExRole
+                    {
+                        CustomerId = tab.CustomerId,
+                        ExRoleId = rols.Id,
+                        HasFlsh = false
+
+                    });
+                }
+               
+            }
+            await _fBS_CusExtendRep.UpdateAsync(tab);
+            await  _fBS_CusExtendRep.AsTenant().CommitTranAsync();
+
+        }
+        catch (Exception)
+        {
+            await _fBS_CusExtendRep.AsTenant().RollbackTranAsync();
+            throw;
+        }
+
+        return true;
 
     }
 

--
Gitblit v1.9.1