移动系统liao
4 天以前 2d8739b04f86ab5e73ec7b0d3152e702a90a450b
Admin.NET/FZCTB.NET.API.Application/User/CustomerService.cs
@@ -6,16 +6,20 @@
using Admin.NET.Core;
using Admin.NET.Core.Service;
using Furion;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using FZCTB.NET.API.Application.User.DTO;
using FZCZTB.NET.MD.ConfigMd;
using FZCZTB.NET.MD.CutomerMd;
using FZCZTB.NET.MD.CutomerMd.Extend;
using FZCZTB.NET.SYSService.CustomerSYS;
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;
@@ -39,15 +43,23 @@
    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 )
        , SqlSugarRepository<FBS_EnterpriseType> fbsenrep,IMapper mapper,SqlSugarRepository<FBS_ExRole> exroles , SqlSugarRepository<FBS_CusExtend> cusrep)
    {
        _sysCacheService= cacheService;
         _customerManager = managerS;
        _fBS_CustomerRep = repository;
        _fBS_EnterpriseTypeRep = fbsenrep;
        _fBS_ExRoleRep = exroles;
        _fBS_CusExtendRep = cusrep;
        _mapper = mapper;
    }
    /// <summary>
@@ -137,6 +149,180 @@
        return await _fBS_EnterpriseTypeRep.AsQueryable().Select<EnterpriseTypeVM>().ToTreeAsync(x=>x.Child,x=>x.ParentId,null,x=>x.Id);
    }
    /// <summary>
    /// 注册角色用户资料
    /// </summary>
    /// <returns></returns>
    [HttpPost]
    public async Task<bool> CreaterExRolsInformation(CusExtendDto cusExtend )
    {
        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 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)
        {
            throw Oops.Oh("用户已经注册了该主体");
        }
        var data= cusExtend.Adapt<FBS_CusExtend>();
        data.steps = CusExtendStep.UNExamine;
        data.CustomerId = id;
        data.CreateTime = DateTime.Now;
        data.CreateUserName = user.NickName;
        data.TransactionCode = rols.Code;
      return   await _fBS_CusExtendRep.InsertAsync(data);
    }
    /// <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("登录交易主体无效");
        }
       var tab= (await _fBS_CusExtendRep.GetFirstAsync(x => x.CustomerId == id && x.TransactionCode == typeCode)).Adapt<CusExtendDto>();
        if(tab==null)
        {
            throw Oops.Oh("没有完成信息录入");
        }
        return tab;
    }
    /// <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.CustomerId == id && x.TransactionCode == typeCode);
        if (tab == null)
        {
            throw Oops.Oh("没有完成信息录入");
        }
        //法人
        if (tab.LegalRepresentativeIdCard != InParam.LegalRepresentativeIdCard)
        {
            tab.LegalRepresentativeIdCard = InParam.LegalRepresentativeIdCard;
            tab.LegalRepresentativeIdNumber = InParam.LegalRepresentativeIdNumber;
            tab.LegalRepresentativeName = InParam.LegalRepresentativeName;
            tab.LegalRepresentativePhone = InParam.LegalRepresentativePhone;
            //重新审核?
            tab.steps = CusExtendStep.Change;
        }
        //企业信息
        if (tab.BusinessLicense != InParam.BusinessLicense)
        {
            tab.EstablishmentTime = tab.EstablishmentTime;
            tab.RegisteredCapital = tab.RegisteredCapital;
            tab.Residence = tab.Residence;
            tab.MainBusiness = InParam.MainBusiness;
            tab.EnterpriseType = InParam.EnterpriseType;
            tab.EnterpriseName = InParam.EnterpriseName;
            tab.BusinessLicense = InParam.BusinessLicense;
            //重新审核?
            tab.steps = CusExtendStep.Change;
        }
        //联系电话
        tab.EnterprisePhone = InParam.EnterprisePhone;
        tab.EnterpriseEmail = InParam.EnterpriseEmail;
        //银行是否需要修改
        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;
        }
        return await _fBS_CusExtendRep.UpdateAsync(tab);
    }
}