|
@@ -1,4 +1,5 @@
|
|
|
using AutoMapper;
|
|
|
+using MathNet.Numerics.Distributions;
|
|
|
using OASystem.Domain;
|
|
|
using OASystem.Domain.Dtos.CRM;
|
|
|
using OASystem.Domain.Dtos.Groups;
|
|
@@ -9,6 +10,7 @@ using OASystem.Infrastructure.Tools;
|
|
|
using Org.BouncyCastle.Utilities.Encoders;
|
|
|
using StackExchange.Redis;
|
|
|
using System;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Globalization;
|
|
|
using System.Linq;
|
|
@@ -618,6 +620,258 @@ namespace OASystem.Infrastructure.Repositories.Groups
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public async Task<Result> OperMultiple(List<TourClientListProcessInfo> _TourClientListInfos , int diid,int userId)
|
|
|
+ {
|
|
|
+ if (diid < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = string.Format(@"请传入有效的团组Id参数!");
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+ if (_TourClientListInfos == null || _TourClientListInfos.Count < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = string.Format(@"接团客户名单信息集合为空,不执行批量添加!");
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+
|
|
|
+ _sqlSugar.BeginTran();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _sqlSugar.Updateable<Grp_TourClientList>().SetColumns(x=> new Grp_TourClientList { IsDel = 1 } ).Where(x=>x.DiId == diid).ExecuteCommand();
|
|
|
+
|
|
|
+ foreach (var item in _TourClientListInfos)
|
|
|
+ {
|
|
|
+ //客户信息
|
|
|
+ var clientInfo = await _sqlSugar.Queryable<Crm_DeleClient>().Where(it => it.IsDel == 0 &&
|
|
|
+ it.LastName.Equals(item.LastName) &&
|
|
|
+ it.FirstName.Equals(item.FirstName) &&
|
|
|
+ it.Phone.Equals(item.Phone)
|
|
|
+ ).FirstAsync();
|
|
|
+
|
|
|
+
|
|
|
+ Crm_CustomerCompany _CustomerCompany = new Crm_CustomerCompany()
|
|
|
+ {
|
|
|
+ CompanyFullName = item.CompanyFullName,
|
|
|
+ LastedOpUserId = userId,
|
|
|
+ CreateUserId = userId
|
|
|
+ };
|
|
|
+
|
|
|
+ Crm_CustomerCert _CustomerCert = new Crm_CustomerCert()
|
|
|
+ {
|
|
|
+ SdId = 773,
|
|
|
+ CertNo = item.IDCardNo,
|
|
|
+ CreateUserId = userId
|
|
|
+ };
|
|
|
+
|
|
|
+ Crm_DeleClient _DeleClient = new Crm_DeleClient()
|
|
|
+ {
|
|
|
+ LastName = item.LastName,
|
|
|
+ FirstName = item.FirstName,
|
|
|
+ Pinyin = item.Pinyin,
|
|
|
+ Phone = item.Phone,
|
|
|
+ Sex = item.Sex,
|
|
|
+ BirthDay = item.BirthDay,
|
|
|
+ Job = item.Job,
|
|
|
+ CreateUserId = userId
|
|
|
+ };
|
|
|
+
|
|
|
+ int clientId = -1;
|
|
|
+ int crmCompanyId = -1;
|
|
|
+
|
|
|
+ //客户单位/公司 操作
|
|
|
+ //1.添加 or 修改 公司基本信息
|
|
|
+ if (clientInfo == null)
|
|
|
+ {
|
|
|
+ var companyInfo = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0 &&
|
|
|
+ it.CompanyFullName.Equals(item.CompanyFullName)
|
|
|
+ ).FirstAsync();
|
|
|
+ if (companyInfo != null) crmCompanyId = companyInfo.Id;
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var companyAdd = await _sqlSugar.Insertable(_CustomerCompany).ExecuteReturnIdentityAsync();
|
|
|
+ if (companyAdd < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = "客户公司信息添加失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+ crmCompanyId = companyAdd;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var companyInfo = await _sqlSugar.Queryable<Crm_CustomerCompany>().Where(it => it.IsDel == 0 &&
|
|
|
+ it.Id == clientInfo.CrmCompanyId
|
|
|
+ ).FirstAsync();
|
|
|
+ if (companyInfo != null)
|
|
|
+ {
|
|
|
+ crmCompanyId = companyInfo.Id;
|
|
|
+ if (!companyInfo.CompanyFullName.Equals(item.CompanyFullName))
|
|
|
+ {
|
|
|
+ companyInfo.CompanyFullName = item.CompanyFullName;
|
|
|
+ var companyEdit = await _sqlSugar.Updateable(companyInfo).UpdateColumns(it =>
|
|
|
+ new
|
|
|
+ {
|
|
|
+ it.CompanyFullName,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .Where(it => it.Id == companyInfo.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (companyEdit < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = "客户公司信息修改失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var companyAdd = await _sqlSugar.Insertable(_CustomerCompany).ExecuteReturnIdentityAsync();
|
|
|
+ if (companyAdd < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = "客户公司信息添加失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+ crmCompanyId = companyAdd;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //客户人员 操作
|
|
|
+ //2.添加 or 修改 客户基本信息
|
|
|
+ if (clientInfo != null) //该客户存在 修改信息
|
|
|
+ {
|
|
|
+ clientId = clientInfo.Id;
|
|
|
+ var clientEdit = await _sqlSugar.Updateable(_DeleClient).UpdateColumns(it =>
|
|
|
+ new
|
|
|
+ {
|
|
|
+ it.LastName,
|
|
|
+ it.FirstName,
|
|
|
+ it.Pinyin,
|
|
|
+ it.Sex,
|
|
|
+ it.Phone,
|
|
|
+ it.BirthDay
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .Where(it => it.Id == clientId)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (clientEdit < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = "客户基础信息修改失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else //不存在添加 客户信息
|
|
|
+ {
|
|
|
+ _DeleClient.CrmCompanyId = crmCompanyId;
|
|
|
+ var clientAdd = await _sqlSugar.Insertable(_DeleClient).ExecuteReturnIdentityAsync();
|
|
|
+ if (clientAdd < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = "客户基本信息添加失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+ clientId = clientAdd;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //客户身份证操作
|
|
|
+ //3.添加 or 修改 身份证信息
|
|
|
+ _CustomerCert.DcId = clientId;
|
|
|
+ if (clientInfo == null)
|
|
|
+ {
|
|
|
+ var certInfo = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 &&
|
|
|
+ it.SdId == 773 && //卡类型 身份证
|
|
|
+ it.CertNo == item.IDCardNo //人员Id
|
|
|
+ ).FirstAsync();
|
|
|
+ if (certInfo == null)
|
|
|
+ {
|
|
|
+ var certAdd = await _sqlSugar.Insertable(_CustomerCert).ExecuteReturnIdentityAsync();
|
|
|
+ if (certAdd < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = "客户身份证添加失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var certInfo = await _sqlSugar.Queryable<Crm_CustomerCert>().Where(it => it.IsDel == 0 &&
|
|
|
+ it.SdId == 773 && //卡类型 身份证
|
|
|
+ it.DcId == clientInfo.Id //人员Id
|
|
|
+ ).FirstAsync();
|
|
|
+ if (certInfo == null)
|
|
|
+ {
|
|
|
+
|
|
|
+ var certAdd = await _sqlSugar.Insertable(_CustomerCert).ExecuteReturnIdentityAsync();
|
|
|
+ if (certAdd < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = "客户身份证添加失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var certEdit = await _sqlSugar.Updateable(_CustomerCert).UpdateColumns(it =>
|
|
|
+ new
|
|
|
+ {
|
|
|
+ it.CertNo,
|
|
|
+ }
|
|
|
+ )
|
|
|
+ .Where(it => it.Id == certInfo.Id)
|
|
|
+ .ExecuteCommandAsync();
|
|
|
+ if (certEdit < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = "客户身份证修改失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //团组客户信息名单操作
|
|
|
+ Grp_TourClientList _TourClientList = new Grp_TourClientList()
|
|
|
+ {
|
|
|
+ DiId = diid,
|
|
|
+ ClientId = clientId,
|
|
|
+ ShippingSpaceTypeId = item.ShippingSpaceTypeId,
|
|
|
+ ShippingSpaceSpecialNeeds = item.ShippingSpaceSpecialNeeds,
|
|
|
+ HotelSpecialNeeds = item.HotelSpecialNeeds,
|
|
|
+ MealSpecialNeeds = item.MealSpecialNeeds,
|
|
|
+ Remark = item.Remark,
|
|
|
+ CreateUserId = userId,
|
|
|
+ };
|
|
|
+
|
|
|
+ var tourClientAdd = await _sqlSugar.Insertable(_TourClientList).ExecuteReturnIdentityAsync();
|
|
|
+ if (tourClientAdd < 0)
|
|
|
+ {
|
|
|
+ _result.Msg = "接团客户名单添加失败!";
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ _result.Code = 0;
|
|
|
+ _sqlSugar.CommitTran();
|
|
|
+
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+
|
|
|
+ _sqlSugar.RollbackTran();
|
|
|
+ _result.Msg = "程序异常 -- " + ex.Message;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ return _result;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Del
|
|
|
/// </summary>
|