| | |
| | | |
| | | using Admin.NET.Core; |
| | | using Admin.NET.Core.Service; |
| | | using Aop.Api.Domain; |
| | | using Dm.util; |
| | | using Furion; |
| | | using Furion.DependencyInjection; |
| | | using Furion.DynamicApiController; |
| | | using Furion.FriendlyException; |
| | | using FZCTB.NET.API.Application.Auth; |
| | | using FZCTB.NET.API.Application.Auth.DTO; |
| | | using FZCTB.NET.API.Application.User.DTO; |
| | | using FZCZTB.Net.CustomerSYSTem; |
| | | using FZCZTB.NET.MD.ConfigMd; |
| | | using FZCZTB.NET.MD.CutomerMd; |
| | | using FZCZTB.NET.MD.CutomerMd.Extend; |
| | | using FZCZTB.NET.SYSService.CustomerSYS; |
| | | using Lazy.Captcha.Core.Generator.Image.Gif; |
| | | using Mapster; |
| | | using MapsterMapper; |
| | | using Microsoft.AspNetCore.Authorization; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.AspNetCore.Mvc.ViewComponents; |
| | | using NewLife; |
| | | using OfficeOpenXml.FormulaParsing.ExpressionGraph.FunctionCompilers; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | /// 客户控制 |
| | | /// </summary> |
| | | [ApiDescriptionSettings("FZCAPISYS", Order = 149)] |
| | | public class CustomerService: IDynamicApiController |
| | | public class CustomerService: IDynamicApiController,IScoped |
| | | { |
| | | private readonly CustomerManagerS _customerManager; |
| | | |
| | | 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; |
| | | private readonly SqlSugarRepository<FBS_CustormerUsers> _fBS_CustormerUsersRep; |
| | | |
| | | /// <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 ) |
| | | , SqlSugarRepository<FBS_EnterpriseType> fbsenrep,IMapper mapper, |
| | | SqlSugarRepository<FBS_ExRole> exroles , |
| | | SqlSugarRepository<FBS_CusExtend> cusrep, |
| | | SqlSugarRepository<FBS_CoutomerExRole> cexrrep |
| | | , SqlSugarRepository<FBS_CustormerUsers> cusUser |
| | | ) |
| | | { |
| | | _sysCacheService= cacheService; |
| | | _customerManager = managerS; |
| | | _fBS_CustomerRep = repository; |
| | | _fBS_EnterpriseTypeRep = fbsenrep; |
| | | _fBS_ExRoleRep = exroles; |
| | | _fBS_CusExtendRep = cusrep; |
| | | _mapper = mapper; |
| | | _fBS_CustomerExRoleRep = cexrrep; |
| | | _fBS_CustormerUsersRep = cusUser; |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | /// <returns></returns> |
| | | [AllowAnonymous] |
| | | [HttpPost] |
| | | public async Task<bool> CustomerRegistration(CustomerRDto param ) |
| | | public async Task<string> CustomerRegistration(FBS_CusExtendVm param ) |
| | | { |
| | | //_customerManager. |
| | | var ExRole= (await _customerManager.GetExRole()).Where(x => x.Code == param.ExRoleCode).FirstOrDefault(); |
| | |
| | | throw Oops.Oh("请选择一个有效的角色进行注册"); |
| | | } |
| | | |
| | | //已选角色,请选择一个注册角色 |
| | | var data= await _fBS_CustomerRep.AsQueryable().Includes(X => X.CoutomerExRols,y=>y.ExRole).Where(x => x.Account == param.Account).FirstAsync(); |
| | | if (data != null) |
| | | { |
| | | if (data.CoutomerExRols.Any(x => x.ExRole.Code == param.ExRoleCode)) |
| | | { |
| | | throw Oops.Oh("已经注册了该角色请勿重复注册"); |
| | | } |
| | | // //已选角色,请选择一个注册角色 |
| | | //var data= await _fBS_CustomerRep.AsQueryable().Includes(X => X.CoutomerExRols,y=>y.ExRole).Where(x => x.Account == param.Account).FirstAsync(); |
| | | // if (data != null) |
| | | // { |
| | | // if (data.CoutomerExRols.Any(x => x.ExRole.Code == param.ExRoleCode)) |
| | | // { |
| | | // throw Oops.Oh("已经注册了该角色请勿重复注册"); |
| | | // } |
| | | |
| | | else |
| | | { |
| | | throw Oops.Oh("该用户名重复,如果需要对该用户添加相应角色,请登录任意角色后添加"); |
| | | } |
| | | // else |
| | | // { |
| | | // throw Oops.Oh("该用户名重复,如果需要对该用户添加相应角色,请登录任意角色后添加"); |
| | | // } |
| | | |
| | | } |
| | | var vcode= _sysCacheService.Get<string>($"{CacheConst.KeyPhoneVerCode}{param.Phone}"); |
| | | // } |
| | | |
| | | |
| | | var vcode= _sysCacheService.Get<string>($"{CacheConst.KeyPhoneVerCode}{param.OperatorPhone}"); |
| | | if(param.PhoneVCode!="TEST") |
| | | if(vcode!=param.PhoneVCode) |
| | | { |
| | | //手机验证码错误 |
| | | throw Oops.Oh("手机验证码错误,请输入正确的手机验证码"); |
| | | } |
| | | |
| | | |
| | | //使用后立即删除 |
| | | _sysCacheService.Remove($"{CacheConst.KeyPhoneVerCode}{param.Phone}"); |
| | | var dd = param.Adapt<FBS_Customer>(); |
| | | dd.RealName = dd.NickName; |
| | | |
| | | dd.Account = dd.Phone; |
| | | dd.Password = ""; |
| | | dd.TenantId = 1300000000001; |
| | | _sysCacheService.Remove($"{CacheConst.KeyPhoneVerCode}{param.OperatorPhone}"); |
| | | |
| | | |
| | | var cusex = await _fBS_CusExtendRep.GetFirstAsync(x => x.UnifiedSocialCreditCode == param.UnifiedSocialCreditCode); |
| | | if(cusex!=null) |
| | | { |
| | | throw Oops.Oh("该企业已经注册"); |
| | | } |
| | | var dd = param.Adapt<FBS_CusExtend>(); |
| | | |
| | | dd.TransactionCode = param.ExRoleCode; |
| | | |
| | | dd.CreateTime = DateTime.Now; |
| | | dd.CreateUserId = 0; |
| | | dd.CreateUserName = dd.NickName; |
| | | dd.CoutomerExRols = new List<FBS_CoutomerExRole>() |
| | | dd.CreateUserName = "用户注册"; |
| | | await _fBS_CusExtendRep.AsTenant().BeginTranAsync(); |
| | | try |
| | | { |
| | | new FBS_CoutomerExRole |
| | | dd = await _fBS_CusExtendRep.InsertReturnEntityAsync(dd); |
| | | |
| | | FBS_CoutomerExRole rulse = new FBS_CoutomerExRole |
| | | { |
| | | ExRoleId= ExRole?.Id??0 |
| | | |
| | | |
| | | } |
| | | CusExtendId = dd.Id, |
| | | ExRoleId = ExRole.Id ?? 0, |
| | | steps = CusExtendStep.UNExamine, |
| | | CreateTime = DateTime.Now, |
| | | CreateUserName = "企业用户:" + ThisUser?.Name, |
| | | CreateUserId = ThisUser?.Id |
| | | |
| | | |
| | | }; |
| | | await _fBS_CustomerExRoleRep.InsertAsync(rulse); |
| | | |
| | | FBS_CustormerUsers user = new FBS_CustormerUsers |
| | | { |
| | | CusExtendId = dd.Id, |
| | | PhoneNumber = dd.OperatorPhone, |
| | | IsEn = true, |
| | | IsManager = true, |
| | | JobTitle = param.JobTitle, |
| | | Name = dd.OperatorName, |
| | | Nickname = param.Nickname, |
| | | CreateTime = dd.CreateTime, |
| | | CreateUserId = 0, |
| | | CreateUserName = "用户注册", |
| | | |
| | | }; |
| | | await _fBS_CustormerUsersRep.InsertAsync(user); |
| | | |
| | | await _fBS_CusExtendRep.AsTenant().CommitTranAsync(); |
| | | |
| | | return "注册成功"; |
| | | } |
| | | catch (Exception) |
| | | { |
| | | await _fBS_CusExtendRep.AsTenant().RollbackTranAsync(); |
| | | throw; |
| | | }; |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | await _fBS_CustomerRep.AsSugarClient().InsertNav(dd).Include(x=>x.CoutomerExRols).ExecuteCommandAsync(); |
| | | |
| | | |
| | | |
| | | |
| | | return true; |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 注册登录可选角色 |
| | |
| | | [AllowAnonymous] |
| | | public async Task<List<EnterpriseTypeVM>> EnterpriseTypes() |
| | | { |
| | | return await _fBS_EnterpriseTypeRep.AsQueryable().Select<EnterpriseTypeVM>().ToTreeAsync(x=>x.Child,x=>x.ParentId,null,x=>x.Id); |
| | | return await _fBS_EnterpriseTypeRep.AsQueryable().Select<EnterpriseTypeVM>().ToTreeAsync(x=>x.Child,x=>x.ParentId,0,x=>x.Id); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 注册角色用户资料 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpGet] |
| | | public async Task<bool> CreaterExRolsInformation(string RuleCode) |
| | | { |
| | | |
| | | var id = App.User.FindFirst(ClaimConst.UserId)?.Value.ToLong() ?? 0; |
| | | if (id == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | var user=await _customerManager.GetCustomer(id); |
| | | if(user==null) |
| | | { |
| | | throw Oops.Oh("用户不存在"); |
| | | } |
| | | var data = await _fBS_ExRoleRep.AsQueryable().ToListAsync(); |
| | | var rols= await _fBS_ExRoleRep.GetFirstAsync(x => x.Code == RuleCode && x.Status == StatusEnum.Enable); |
| | | if(rols==null) |
| | | { |
| | | throw Oops.Oh("交易主体不存在"); |
| | | } |
| | | var ExRoles = await _fBS_CustomerExRoleRep.GetListAsync(x => x.CusExtendId == user.CusExtendId); |
| | | if (ExRoles != null) |
| | | { |
| | | if (ExRoles?.Any(x => x.ExRoleId == rols.Id ) == true) |
| | | { |
| | | throw Oops.Oh("用户已经注册了该主体"); |
| | | } |
| | | |
| | | } |
| | | |
| | | //增加用户角色 |
| | | await _fBS_CustomerExRoleRep.InsertAsync(new FBS_CoutomerExRole |
| | | { |
| | | ExRoleId = rols.Id, |
| | | CusExtendId = user.CusExtendId, |
| | | steps= CusExtendStep.UNExamine, |
| | | |
| | | CreateTime = DateTime.Now, |
| | | CreateUserName = "企业用户:" + ThisUser?.Name, |
| | | CreateUserId = ThisUser?.Id, |
| | | }); |
| | | |
| | | |
| | | |
| | | |
| | | return true; |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 获取 个人中心数据? |
| | | /// </summary> |
| | | [HttpPost] |
| | | public async Task<CusExtendDto> GetCusExtendInfo() |
| | | { |
| | | var id = App.User.FindFirst(ClaimConst.UserId)?.Value.ToLong() ?? 0; |
| | | if (id == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | // |
| | | var typeCode = App.User.FindFirst(ClaimConst.CustomerLogoinType)?.Value ; |
| | | if (typeCode == null) |
| | | { |
| | | throw Oops.Oh("登录交易主体错误"); |
| | | |
| | | } |
| | | var user = await _customerManager.GetCustomer(id); |
| | | if (user == null) |
| | | { |
| | | throw Oops.Oh("用户不存在"); |
| | | } |
| | | var rols = await _fBS_ExRoleRep.GetFirstAsync(x => x.Code == typeCode && x.Status == StatusEnum.Enable); |
| | | if (rols == null) |
| | | { |
| | | throw Oops.Oh("登录交易主体无效"); |
| | | } |
| | | |
| | | |
| | | return await _fBS_CusExtendRep.AsQueryable().Where(x => x.Id == user.CusExtendId).Includes(x => x.ExRoles, y => y.ExRole).Select(x => new CusExtendDto |
| | | { |
| | | ExRoles = x.ExRoles.Adapt<List<FBS_CoutomerExRoleOutput>>() |
| | | }, true).FirstAsync(); |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改个人中心数据 |
| | | /// </summary> |
| | | [HttpPost] |
| | | public async Task<bool> ChangeCusExtend(CusExtendDto InParam) |
| | | { |
| | | var id = App.User.FindFirst(ClaimConst.UserId)?.Value.ToLong() ?? 0; |
| | | if (id == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | // |
| | | var typeCode = App.User.FindFirst(ClaimConst.CustomerLogoinType)?.Value; |
| | | if (typeCode == null) |
| | | { |
| | | throw Oops.Oh("登录交易主体错误"); |
| | | |
| | | } |
| | | var user = await _customerManager.GetCustomer(id); |
| | | if (user == null) |
| | | { |
| | | throw Oops.Oh("用户不存在"); |
| | | } |
| | | var rols = await _fBS_ExRoleRep.GetFirstAsync(x => x.Code == typeCode && x.Status == StatusEnum.Enable); |
| | | if (rols == null) |
| | | { |
| | | throw Oops.Oh("登录交易主体无效"); |
| | | } |
| | | var tab = await _fBS_CusExtendRep.GetFirstAsync(x => x.Id == user.CusExtendId ); |
| | | if (tab == null) |
| | | { |
| | | throw Oops.Oh("没有完成信息录入"); |
| | | } |
| | | |
| | | bool isChangeData = false; |
| | | |
| | | |
| | | |
| | | //法人 |
| | | if (tab.LegalRepresentativeIdCard != InParam.LegalRepresentativeIdCard) |
| | | { |
| | | tab.LegalRepresentativeIdCard = InParam.LegalRepresentativeIdCard; |
| | | tab.LegalRepresentativeIdNumber = InParam.LegalRepresentativeIdNumber; |
| | | tab.LegalRepresentativeName = InParam.LegalRepresentativeName; |
| | | tab.LegalRepresentativePhone = InParam.LegalRepresentativePhone; |
| | | //重新审核? |
| | | isChangeData=true; |
| | | } |
| | | |
| | | |
| | | //企业信息 |
| | | if (tab.BusinessLicense != InParam.BusinessLicense) |
| | | { |
| | | tab.EstablishmentTime = tab.EstablishmentTime; |
| | | tab.RegisteredCapital = tab.RegisteredCapital; |
| | | tab.Residence = tab.Residence; |
| | | tab.MainBusiness = InParam.MainBusiness; |
| | | |
| | | tab.EnterpriseName = InParam.EnterpriseName; |
| | | tab.BusinessLicense = InParam.BusinessLicense; |
| | | //重新审核? |
| | | isChangeData = true; |
| | | } |
| | | if (tab.EnterpriseType != InParam.EnterpriseType) |
| | | { |
| | | tab.EnterpriseType = InParam.EnterpriseType; |
| | | |
| | | } |
| | | |
| | | //联系电话 |
| | | tab.EnterprisePhone = InParam.EnterprisePhone; |
| | | tab.EnterpriseEmail = InParam.EnterpriseEmail; |
| | | |
| | | if (tab.BankAccount != InParam.BankAccount) |
| | | { |
| | | |
| | | tab.BankAccount = InParam.BankAccount; |
| | | isChangeData = true; |
| | | |
| | | } |
| | | if (tab.BankName != InParam.BankName) |
| | | { |
| | | tab.BankName = InParam.BankName; |
| | | isChangeData = true; |
| | | } |
| | | //银行是否需要修改 |
| | | //tab.BankAccount = InParam.BankAccount; |
| | | //tab.BankName = InParam.BankName; |
| | | |
| | | // 经办人 |
| | | if (tab.OperatorIdCard != InParam.OperatorIdCard) |
| | | { |
| | | tab.OperatorIdCard = InParam.OperatorIdCard; |
| | | |
| | | tab.OperatorIdNumber = InParam.OperatorIdNumber; |
| | | tab.OperatorName = InParam.OperatorName; |
| | | tab.OperatorPhone = InParam.OperatorPhone; |
| | | isChangeData = true; |
| | | } |
| | | |
| | | |
| | | await _fBS_CusExtendRep.AsTenant().BeginTranAsync(); |
| | | try |
| | | { |
| | | if(!isChangeData) |
| | | { |
| | | //是更改,需要更该所有roles的值 |
| | | var exrolerep= await _fBS_CustomerExRoleRep.GetListAsync(x=>x.CusExtendId==user.CusExtendId); |
| | | foreach (var item in exrolerep) |
| | | { |
| | | |
| | | item.steps = CusExtendStep.Change; |
| | | |
| | | |
| | | } |
| | | await _fBS_CustomerExRoleRep.UpdateRangeAsync(exrolerep); |
| | | } |
| | | |
| | | await _fBS_CusExtendRep.UpdateAsync(tab); |
| | | await _fBS_CusExtendRep.AsTenant().CommitTranAsync(); |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | await _fBS_CusExtendRep.AsTenant().RollbackTranAsync(); |
| | | throw; |
| | | } |
| | | |
| | | return true; |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取账户列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpGet] |
| | | public async Task<List<FBS_CustormerUsersOutput> > GetCustormerUsersList() |
| | | { |
| | | var id = App.User.FindFirst(ClaimConst.CustomerExId)?.Value.ToLong() ?? 0; |
| | | if (id == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | if (!await isManger()) |
| | | throw Oops.Oh("用户没有权限"); |
| | | return (await _fBS_CustormerUsersRep.GetListAsync(x => x.CusExtendId == id)).Adapt<List<FBS_CustormerUsersOutput>>(); |
| | | } |
| | | public FBS_CustormerUsers? ThisUser { get; set; } |
| | | /// <summary> |
| | | /// 新建员工数据 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<bool> CreatCustormerUsers(FBS_CustormerUsersVM param) |
| | | { |
| | | if (!await isManger()) |
| | | throw Oops.Oh("用户没有权限"); |
| | | var cid = App.User.FindFirst(ClaimConst.CustomerExId)?.Value.ToLong() ?? 0; |
| | | if (cid == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | var count = await _fBS_CustormerUsersRep.CountAsync(x=>x.CusExtendId== cid); |
| | | if(count>10) |
| | | { |
| | | throw Oops.Oh("同一组织机构最多可以建立10个用户"); |
| | | } |
| | | |
| | | var User = await _fBS_CustormerUsersRep.GetFirstAsync(x => x.CusExtendId == cid && x.PhoneNumber == param.PhoneNumber); |
| | | if(User!=null) |
| | | { |
| | | throw Oops.Oh("同一家公司账户不能同时出现相同的电话号码"); |
| | | } |
| | | |
| | | User = param.Adapt<FBS_CustormerUsers>(); |
| | | User.CusExtendId = cid; |
| | | User.IsManager = false; |
| | | User.CreateTime = DateTime.Now; |
| | | User.CreateUserName ="企业用户:"+ ThisUser?.Name; |
| | | User.CreateUserId = ThisUser?.Id; |
| | | return await _fBS_CustormerUsersRep.InsertAsync(User); |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 更改管理员 |
| | | /// </summary> |
| | | /// <param name="CustormerUserId"> UserList 的ID</param> |
| | | /// <returns></returns> |
| | | [HttpGet] |
| | | public async Task<bool> ChangeManager(long CustormerUserId ) |
| | | { |
| | | if (!await isManger()) |
| | | throw Oops.Oh("用户没有权限"); |
| | | var cid = App.User.FindFirst(ClaimConst.CustomerExId)?.Value.ToLong() ?? 0; |
| | | if (cid == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | var uid = App.User.FindFirst(ClaimConst.UserId)?.Value.ToLong() ?? 0; |
| | | if (uid == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | if(CustormerUserId== uid) |
| | | return true; |
| | | if (ThisUser==null) |
| | | { |
| | | |
| | | ThisUser = await _fBS_CustormerUsersRep.GetFirstAsync(x => x.Id == uid && x.CusExtendId == cid && x.IsEn == true); |
| | | |
| | | } |
| | | var User = await _fBS_CustormerUsersRep.GetFirstAsync(x =>x.CusExtendId==ThisUser.CusExtendId &&x.Id== CustormerUserId); |
| | | if (User == null) |
| | | { |
| | | throw Oops.Oh("用户不存在"); |
| | | } |
| | | if(User.IsEn==false) |
| | | throw Oops.Oh("无效用户不可设置为管理员"); |
| | | |
| | | User.IsManager = !User.IsManager; |
| | | User.UpdateTime = DateTime.Now; |
| | | User.UpdateUserName= "企业用户:" + ThisUser?.Name; |
| | | User.UpdateUserId = ThisUser.Id; |
| | | |
| | | //ThisUser.IsManager = false; |
| | | //ThisUser.UpdateTime = DateTime.Now; |
| | | //ThisUser.UpdateUserName = "企业用户:" + ThisUser?.Name; //不互斥 |
| | | //ThisUser.UpdateUserId = ThisUser.Id; |
| | | await _fBS_CustormerUsersRep.AsTenant().BeginTranAsync(); |
| | | try |
| | | { |
| | | await _fBS_CustormerUsersRep.UpdateAsync(User); |
| | | //await _fBS_CustormerUsersRep.UpdateAsync(ThisUser); //不互斥 |
| | | await _fBS_CustormerUsersRep.AsTenant().CommitTranAsync(); |
| | | return false; |
| | | |
| | | } |
| | | catch (Exception) |
| | | { |
| | | await _fBS_CustormerUsersRep.AsTenant().RollbackTranAsync(); |
| | | throw; |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更改员工信息 |
| | | /// </summary> |
| | | /// <param name="CustormerUserId"> UserList 的ID</param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<bool> UpdataCustormerUsers( FBS_CustormerUsersVM Param) |
| | | { |
| | | if (!await isManger()) |
| | | throw Oops.Oh("用户没有权限"); |
| | | var cid = App.User.FindFirst(ClaimConst.CustomerExId)?.Value.ToLong() ?? 0; |
| | | if (cid == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | var uid = App.User.FindFirst(ClaimConst.UserId)?.Value.ToLong() ?? 0; |
| | | if (uid == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | if(Param.Id==null) |
| | | { |
| | | throw Oops.Oh("Id错误"); |
| | | } |
| | | if(Param.CusExtendId!= cid) |
| | | { |
| | | throw Oops.Oh("组织机构不同不可修改"); |
| | | } |
| | | |
| | | var User = await _fBS_CustormerUsersRep.GetFirstAsync(x => x.CusExtendId == Param.CusExtendId && x.Id == Param.Id); |
| | | if (User == null) |
| | | { |
| | | throw Oops.Oh("用户不存在"); |
| | | } |
| | | User = _mapper.Map(Param, User); |
| | | |
| | | User.CreateTime = DateTime.Now; |
| | | User.CreateUserName = "企业用户:" + ThisUser?.Name; |
| | | User.CreateUserId = ThisUser?.Id; |
| | | |
| | | return await _fBS_CustormerUsersRep.UpdateAsync(User); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除员工 |
| | | /// </summary> |
| | | /// <param name="CustormerUserId"> UserList 的ID</param> |
| | | /// <returns></returns> |
| | | [HttpDelete] |
| | | public async Task<bool> DelCustormerUsers(long CustormerUserId) |
| | | { |
| | | if (!await isManger()) |
| | | throw Oops.Oh("用户没有权限"); |
| | | var cid = App.User.FindFirst(ClaimConst.CustomerExId)?.Value.ToLong() ?? 0; |
| | | if (cid == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | var uid = App.User.FindFirst(ClaimConst.UserId)?.Value.ToLong() ?? 0; |
| | | if (uid == 0) |
| | | { |
| | | |
| | | |
| | | } |
| | | if (CustormerUserId == uid) |
| | | throw Oops.Oh("自己不可删除自己"); |
| | | if (ThisUser == null) |
| | | { |
| | | |
| | | ThisUser = await _fBS_CustormerUsersRep.GetFirstAsync(x => x.Id == uid && x.CusExtendId == cid && x.IsEn == true); |
| | | |
| | | } |
| | | var User = await _fBS_CustormerUsersRep.GetFirstAsync(x => x.CusExtendId == ThisUser.CusExtendId && x.Id == CustormerUserId); |
| | | if (User == null) |
| | | { |
| | | throw Oops.Oh("用户不存在"); |
| | | } |
| | | return await _fBS_CustormerUsersRep.DeleteByIdAsync(CustormerUserId); |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 权限验证是否是管理员 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [NonAction] |
| | | public async Task< bool> isManger() |
| | | { |
| | | |
| | | if (ThisUser != null) |
| | | return ThisUser.IsManager; |
| | | //用户ID |
| | | |
| | | var id = App.User.FindFirst(ClaimConst.UserId)?.Value.ToLong() ?? 0; |
| | | if (id == 0) |
| | | { |
| | | throw Oops.Oh("用户凭证错误"); |
| | | |
| | | } |
| | | //企业ID |
| | | var CExid = App.User.FindFirst(ClaimConst.CustomerExId)?.Value.ToLong() ?? 0; |
| | | if (id == 0) |
| | | { |
| | | throw Oops.Oh("企业资料不匹配"); |
| | | |
| | | } |
| | | |
| | | |
| | | var user= await _fBS_CustormerUsersRep.GetFirstAsync(x => x.Id == id && x.CusExtendId == CExid && x.IsEn == true); |
| | | if(user==null) |
| | | { |
| | | throw Oops.Oh("用户不匹配"); |
| | | } |
| | | ThisUser = user; |
| | | if (user.IsManager) |
| | | |
| | | return true; |
| | | |
| | | else return false; |
| | | |
| | | |
| | | |
| | | } |
| | | } |