|
|
|
|
using System.Collections;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
using DS.WMS.Common.Enum;
|
|
|
|
|
using DS.WMS.Core.System.Dtos;
|
|
|
|
|
using DS.WMS.Core.System.Entity;
|
|
|
|
|
using DS.WMS.Core.System.Interface;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.System.Method;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class CompanyService : ICompanyService
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
public CompanyService(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取客户信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult GetClientInfo()
|
|
|
|
|
{
|
|
|
|
|
var userId = user.UserId;
|
|
|
|
|
var companyId = db.Queryable<tb_User>().First(x => x.Gid == Guid.Parse(userId)).CompanyId;
|
|
|
|
|
var licenseFiles = db.Queryable<INFO_FILES>().Where(x => x.PID == companyId && x.FILETYPE == "营业执照")
|
|
|
|
|
.Select(it => new fileinfo
|
|
|
|
|
{
|
|
|
|
|
FileName = it.FILENAME,
|
|
|
|
|
FilePath = it.IMGPATH
|
|
|
|
|
}).ToArray();
|
|
|
|
|
var cardFiles = db.Queryable<INFO_FILES>().Where(x => x.PID == companyId && x.FILETYPE == "法人身份证")
|
|
|
|
|
.Select(it => new fileinfo
|
|
|
|
|
{
|
|
|
|
|
FileName = it.FILENAME,
|
|
|
|
|
FilePath = it.IMGPATH
|
|
|
|
|
}).ToArray();
|
|
|
|
|
var data = db.Queryable<OP_YARD_COMPANY>()
|
|
|
|
|
.Where(x => x.GID == companyId)
|
|
|
|
|
.Select<CompanyViewModel>()
|
|
|
|
|
.Mapper(it =>
|
|
|
|
|
{
|
|
|
|
|
//只能写在Select后面
|
|
|
|
|
it.licensefiles = licenseFiles;
|
|
|
|
|
it.cardfiles = cardFiles;
|
|
|
|
|
})
|
|
|
|
|
.First();
|
|
|
|
|
return DataResult.Successed("获取数据成功", data);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 维护客户公司信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult EditClientCompany(CompanyInput model)
|
|
|
|
|
{
|
|
|
|
|
var exitCompany = db.Queryable<OP_YARD_COMPANY>().First(x=>x.GID == model.GID);
|
|
|
|
|
|
|
|
|
|
if (exitCompany.AuditStatus == AuditStatus.Approve.ToEnumInt() || exitCompany.AuditStatus == AuditStatus.Auditing.ToEnumInt())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("审核通过或待审批状态不能提交!");
|
|
|
|
|
}
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//开启事务
|
|
|
|
|
db.Ado.BeginTran();
|
|
|
|
|
var company = model.MapTo<CompanyInput, OP_YARD_COMPANY>();
|
|
|
|
|
db.Updateable(company).IgnoreColumns(x=>x.LOGINPASSWORD).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
var gid = model.GID; //写入
|
|
|
|
|
#region 处理文件
|
|
|
|
|
|
|
|
|
|
#region 处理法人身份证
|
|
|
|
|
//先删除 法人身份证
|
|
|
|
|
var existCards = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE == "法人身份证").Select(n=>n.IMGPATH).ToArray();
|
|
|
|
|
var cardFiles = model.cardfiles.Select(x => x.FilePath).ToArray();
|
|
|
|
|
IEnumerable<string> delCards = existCards.AsQueryable().Except(cardFiles);
|
|
|
|
|
if (delCards.Count()>0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in delCards)
|
|
|
|
|
{
|
|
|
|
|
var existInfo = db.Queryable<INFO_FILES>()
|
|
|
|
|
.Where(x => x.PID == gid && x.IMGPATH == item).First();
|
|
|
|
|
db.Deleteable(existInfo).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//2.添加新的法人身份证
|
|
|
|
|
IEnumerable<string> addCards = cardFiles.AsQueryable().Except(existCards);
|
|
|
|
|
if (addCards.Count()>0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in addCards)
|
|
|
|
|
{
|
|
|
|
|
var infoFile = new INFO_FILES
|
|
|
|
|
{
|
|
|
|
|
GID = Guid.NewGuid(),
|
|
|
|
|
PID = gid,
|
|
|
|
|
FILENAME = model.cardfiles.Where(x=>x.FilePath ==item).Select(x=>x.FileName).First(),
|
|
|
|
|
IMGPATH = item,
|
|
|
|
|
FILETYPE = "法人身份证",
|
|
|
|
|
CORPID = gid.ToString(),
|
|
|
|
|
CreateDate = DateTime.Now,
|
|
|
|
|
ModifyDate = DateTime.Now,
|
|
|
|
|
UPLOADEMPLY = ""
|
|
|
|
|
};
|
|
|
|
|
db.Insertable(infoFile).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
#region 处理营业执照
|
|
|
|
|
//先删除 营业执照
|
|
|
|
|
var existLicenses = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE == "营业执照").Select(n=>n.IMGPATH).ToArray();
|
|
|
|
|
var licenseFiles = model.licensefiles.Select(x => x.FilePath).ToArray();
|
|
|
|
|
IEnumerable<string> delLicenses = existLicenses.AsQueryable().Except(licenseFiles);
|
|
|
|
|
if (delLicenses.Count()>0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in delLicenses)
|
|
|
|
|
{
|
|
|
|
|
var existInfo = db.Queryable<INFO_FILES>()
|
|
|
|
|
.Where(x => x.PID == gid && x.IMGPATH == item).First();
|
|
|
|
|
db.Deleteable(existInfo).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//2.添加新的营业执照
|
|
|
|
|
IEnumerable<string> addLicenses = licenseFiles.AsQueryable().Except(existLicenses);
|
|
|
|
|
if (addLicenses.Count()>0)
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in addLicenses)
|
|
|
|
|
{
|
|
|
|
|
var infoFile = new INFO_FILES
|
|
|
|
|
{
|
|
|
|
|
GID = Guid.NewGuid(),
|
|
|
|
|
PID = gid,
|
|
|
|
|
FILENAME = model.licensefiles.Where(x=>x.FilePath ==item).Select(x=>x.FileName).First(),
|
|
|
|
|
IMGPATH = item,
|
|
|
|
|
FILETYPE = "营业执照",
|
|
|
|
|
CORPID = gid.ToString(),
|
|
|
|
|
CreateDate = DateTime.Now,
|
|
|
|
|
ModifyDate = DateTime.Now,
|
|
|
|
|
UPLOADEMPLY = ""
|
|
|
|
|
};
|
|
|
|
|
db.Insertable(infoFile).ExecuteCommand();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
db.Ado.CommitTran();
|
|
|
|
|
return DataResult.Successed("更新成功!");
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
db.Ado.RollbackTran();
|
|
|
|
|
return DataResult.Failed("更新失败!" + ex);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 提交审核
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public DataResult SubmitCompany(string id)
|
|
|
|
|
{
|
|
|
|
|
var gid = Guid.Parse(id); //写入
|
|
|
|
|
var exitCompany = db.Queryable<OP_YARD_COMPANY>().First(x=>x.GID == gid);
|
|
|
|
|
if (exitCompany == null)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("公司信息不存在,请先保存再提交!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (exitCompany.AuditStatus == AuditStatus.Approve.ToEnumInt() || exitCompany.AuditStatus == AuditStatus.Auditing.ToEnumInt())
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("审核通过或待审批状态不能提交!");
|
|
|
|
|
}
|
|
|
|
|
var licensefiles = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE =="营业执照").ToList();
|
|
|
|
|
if (licensefiles.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("营业执照认证资料未上传不能提交!");
|
|
|
|
|
}
|
|
|
|
|
var cardfiles = db.Queryable<INFO_FILES>().Where(x => x.PID == gid && x.FILETYPE =="法人身份证").ToList();
|
|
|
|
|
if (cardfiles.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
return DataResult.Failed("营业执照认证资料未上传不能提交!");
|
|
|
|
|
}
|
|
|
|
|
//更新状态为待审批
|
|
|
|
|
exitCompany.AuditStatus = AuditStatus.Auditing.ToEnumInt();
|
|
|
|
|
db.Updateable(exitCompany).ExecuteCommand();
|
|
|
|
|
|
|
|
|
|
return DataResult.Successed("提交成功");
|
|
|
|
|
}
|
|
|
|
|
}
|