|  | @@ -2,6 +2,7 @@
 | 
	
		
			
				|  |  |  using AutoMapper.Execution;
 | 
	
		
			
				|  |  |  using MySqlX.XDevAPI.Relational;
 | 
	
		
			
				|  |  |  using OASystem.Domain;
 | 
	
		
			
				|  |  | +using OASystem.Domain.Dtos;
 | 
	
		
			
				|  |  |  using OASystem.Domain.Dtos.CRM;
 | 
	
		
			
				|  |  |  using OASystem.Domain.Entities.Customer;
 | 
	
		
			
				|  |  |  using OASystem.Domain.Entities.Resource;
 | 
	
	
		
			
				|  | @@ -359,7 +360,7 @@ namespace OASystem.Infrastructure.Repositories.CRM
 | 
	
		
			
				|  |  |              return result;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        public async Task<Result> QueryUserSelect()
 | 
	
		
			
				|  |  | +        public Result QueryUserSelect()
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              Result result = new Result() { Code = -2, Msg = "未知错误" };
 | 
	
		
			
				|  |  |              try
 | 
	
	
		
			
				|  | @@ -393,32 +394,67 @@ namespace OASystem.Infrastructure.Repositories.CRM
 | 
	
		
			
				|  |  |          public async Task<Result> NewClientOp(NewClientOpDto dto)
 | 
	
		
			
				|  |  |          {
 | 
	
		
			
				|  |  |              Result result = new Result() { Code = -2, Msg = "未知错误" };
 | 
	
		
			
				|  |  | +            bool istrue = false;
 | 
	
		
			
				|  |  | +            int AddReturnId = -1;
 | 
	
		
			
				|  |  | +            
 | 
	
		
			
				|  |  | +            string BirthdayStr = string.Empty;
 | 
	
		
			
				|  |  | +            if (!string.IsNullOrWhiteSpace(dto.Birthday))
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                DateTime Birthday = new DateTime();
 | 
	
		
			
				|  |  | +                var isParse = DateTime.TryParse(dto.Birthday, out Birthday);
 | 
	
		
			
				|  |  | +                BirthdayStr = isParse ? Birthday.ToString("yyyy-MM-dd") : "";
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |              try
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | +                BeginTran();
 | 
	
		
			
				|  |  |                  if (dto.Status == 1)//添加
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    string selectSql = string.Format(@"select * from Crm_NewClientData where Client='{0}' Contact='{1}' And IsDel={2}"
 | 
	
		
			
				|  |  | +                    string selectSql = string.Format(@"select * from Crm_NewClientData where Client='{0}' And Contact='{1}' And IsDel={2}"
 | 
	
		
			
				|  |  |                                                         , dto.Client, dto.Contact, 0);
 | 
	
		
			
				|  |  |                      var NewClientData = await _sqlSugar.SqlQueryable<Crm_NewClientData>(selectSql).FirstAsync();//查询是否存在
 | 
	
		
			
				|  |  | -                    if (NewClientData != null)
 | 
	
		
			
				|  |  | +                    if (NewClientData == null)
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  | -                        return result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
 | 
	
		
			
				|  |  | +                        if (string.IsNullOrWhiteSpace(dto.PassportDate))
 | 
	
		
			
				|  |  | +                        {
 | 
	
		
			
				|  |  | +                            dto.PassportDate = null;
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -                    }
 | 
	
		
			
				|  |  | -                    else//不存在,可添加
 | 
	
		
			
				|  |  | -                    {
 | 
	
		
			
				|  |  |                          Crm_NewClientData _NewClientData = _mapper.Map<Crm_NewClientData>(dto);
 | 
	
		
			
				|  |  | -                        int id = await AddAsyncReturnId(_NewClientData);
 | 
	
		
			
				|  |  | +                        _NewClientData.Birthday = BirthdayStr;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        int id = await AddAsyncReturnId(_NewClientData); //添加市场客户资料表数据
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                          if (id == 0)
 | 
	
		
			
				|  |  |                          {
 | 
	
		
			
				|  |  | -                            return result = new Result() { Code = -1, Msg = "添加失败!" };
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | +                            result = new Result() { Code = -1, Msg = "添加失败!" };
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +                        else
 | 
	
		
			
				|  |  | +                        {
 | 
	
		
			
				|  |  | +                            result = new Result() { Code = 0, Msg = "添加成功!"};
 | 
	
		
			
				|  |  | +                            istrue = true;
 | 
	
		
			
				|  |  | +                            AddReturnId = id;
 | 
	
		
			
				|  |  | +                            CommitTran();
 | 
	
		
			
				|  |  |                          }
 | 
	
		
			
				|  |  | -                        return result = new Result() { Code = 0, Msg = "添加成功!", Data = new { Id = id } };
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | +                    else
 | 
	
		
			
				|  |  | +                    {
 | 
	
		
			
				|  |  | +                        result = new Result() { Code = -1, Msg = "该信息已存在,请勿重复添加!" };
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  else if (dto.Status == 2)//修改
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | +                    DateTime? PassportDate = null;
 | 
	
		
			
				|  |  | +                    try
 | 
	
		
			
				|  |  | +                    {
 | 
	
		
			
				|  |  | +                        PassportDate = DateTime.Parse(dto.PassportDate);
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    catch (Exception)
 | 
	
		
			
				|  |  | +                    {
 | 
	
		
			
				|  |  | +                        PassportDate = null;
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |                      bool res = await UpdateAsync(a => a.Id == dto.Id, a => new Crm_NewClientData
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  |                          Number = dto.Number,
 | 
	
	
		
			
				|  | @@ -429,14 +465,14 @@ namespace OASystem.Infrastructure.Repositories.CRM
 | 
	
		
			
				|  |  |                          Contact = dto.Contact,
 | 
	
		
			
				|  |  |                          Gender = dto.Gender,
 | 
	
		
			
				|  |  |                          Passport = dto.Passport,
 | 
	
		
			
				|  |  | -                        PassportDate = dto.PassportDate,
 | 
	
		
			
				|  |  | +                        PassportDate = PassportDate,
 | 
	
		
			
				|  |  |                          Job = dto.Job,
 | 
	
		
			
				|  |  |                          Telephone = dto.Telephone,
 | 
	
		
			
				|  |  |                          Phone = dto.Phone,
 | 
	
		
			
				|  |  |                          Email = dto.Email,
 | 
	
		
			
				|  |  |                          Location = dto.Location,
 | 
	
		
			
				|  |  |                          Address = dto.Address,
 | 
	
		
			
				|  |  | -                        Birthday = dto.Birthday,
 | 
	
		
			
				|  |  | +                        Birthday = BirthdayStr,
 | 
	
		
			
				|  |  |                          OtherInfo = dto.Otherinfo,
 | 
	
		
			
				|  |  |                          Wechat = dto.Wechat,
 | 
	
		
			
				|  |  |                          Category = dto.Category,
 | 
	
	
		
			
				|  | @@ -444,19 +480,68 @@ namespace OASystem.Infrastructure.Repositories.CRM
 | 
	
		
			
				|  |  |                          FinlishedDele = dto.FinlishedDele,
 | 
	
		
			
				|  |  |                          Remark = dto.Remark,
 | 
	
		
			
				|  |  |                      });
 | 
	
		
			
				|  |  | -                    if (!res)
 | 
	
		
			
				|  |  | +                    if (res)
 | 
	
		
			
				|  |  | +                    {
 | 
	
		
			
				|  |  | +                        istrue = true;
 | 
	
		
			
				|  |  | +                        AddReturnId = dto.Id == 0 ? -1 : dto.Id;
 | 
	
		
			
				|  |  | +                        if (AddReturnId != -1)
 | 
	
		
			
				|  |  | +                        {
 | 
	
		
			
				|  |  | +                            await _sqlSugar.Updateable<Crm_ClientDataAndUser>().Where(x=>x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndUser()
 | 
	
		
			
				|  |  | +                            {
 | 
	
		
			
				|  |  | +                                IsDel = 1,
 | 
	
		
			
				|  |  | +                                DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
 | 
	
		
			
				|  |  | +                            }).ExecuteCommandAsync();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                            await _sqlSugar.Updateable<Crm_ClientDataAndBusiness>().Where(x => x.NewClientDataId == AddReturnId).SetColumns(a => new Crm_ClientDataAndBusiness()
 | 
	
		
			
				|  |  | +                            {
 | 
	
		
			
				|  |  | +                                IsDel = 1,
 | 
	
		
			
				|  |  | +                                DeleteTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
 | 
	
		
			
				|  |  | +                            }).ExecuteCommandAsync();
 | 
	
		
			
				|  |  | +                        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                        result = new Result() { Code = 0, Msg = "修改成功!" };
 | 
	
		
			
				|  |  | +                    }
 | 
	
		
			
				|  |  | +                    else
 | 
	
		
			
				|  |  |                      {
 | 
	
		
			
				|  |  | -                        return result = new Result() { Code = -1, Msg = "修改失败!" };
 | 
	
		
			
				|  |  | +                        result = new Result() { Code = -1, Msg = "修改失败!" };
 | 
	
		
			
				|  |  |                      }
 | 
	
		
			
				|  |  | -                    return result = new Result() { Code = 0, Msg = "修改成功!" };
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  else
 | 
	
		
			
				|  |  |                  {
 | 
	
		
			
				|  |  | -                    return result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
 | 
	
		
			
				|  |  | +                    result = new Result() { Code = -1, Msg = "请传入Status参数,1添加 2修改!" };
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                if (istrue)
 | 
	
		
			
				|  |  | +                {
 | 
	
		
			
				|  |  | +                    Adds<Crm_ClientDataAndUser>(dto.AscribedUser.Select(x => new Crm_ClientDataAndUser
 | 
	
		
			
				|  |  | +                    {
 | 
	
		
			
				|  |  | +                        CreateTime = DateTime.Now,
 | 
	
		
			
				|  |  | +                        CreateUserId = dto.CreateUserId,
 | 
	
		
			
				|  |  | +                        IsDel = 0,
 | 
	
		
			
				|  |  | +                        NewClientDataId = AddReturnId,
 | 
	
		
			
				|  |  | +                        usersId = x
 | 
	
		
			
				|  |  | +                    }).ToList());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    Adds<Crm_ClientDataAndBusiness>(dto.AscribedDepartment.Select(x => new Crm_ClientDataAndBusiness
 | 
	
		
			
				|  |  | +                    {
 | 
	
		
			
				|  |  | +                        CreateUserId = dto.CreateUserId,
 | 
	
		
			
				|  |  | +                        IsDel = 0,
 | 
	
		
			
				|  |  | +                        CreateTime = DateTime.Now,
 | 
	
		
			
				|  |  | +                        NewClientDataId = AddReturnId,
 | 
	
		
			
				|  |  | +                        SetDataId = x,
 | 
	
		
			
				|  |  | +                    }).ToList());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +                    CommitTran();
 | 
	
		
			
				|  |  | +                    result.Data = new { Id = AddReturnId };
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                else
 | 
	
		
			
				|  |  | +                {
 | 
	
		
			
				|  |  | +                    RollbackTran();
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              catch (Exception)
 | 
	
		
			
				|  |  |              {
 | 
	
		
			
				|  |  | +                RollbackTran();
 | 
	
		
			
				|  |  |                  result = new Result() { Code = -2, Msg = "未知错误" };
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              return result;
 | 
	
	
		
			
				|  | @@ -570,5 +655,38 @@ namespace OASystem.Infrastructure.Repositories.CRM
 | 
	
		
			
				|  |  |              return rest;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        /// <summary>
 | 
	
		
			
				|  |  | +        /// 删除市场客户资料数据
 | 
	
		
			
				|  |  | +        /// </summary>
 | 
	
		
			
				|  |  | +        /// <param name="dto"></param>
 | 
	
		
			
				|  |  | +        /// <returns></returns>
 | 
	
		
			
				|  |  | +        public async Task<Result> DelNewClientData(DelBaseDto dto)
 | 
	
		
			
				|  |  | +        {
 | 
	
		
			
				|  |  | +            Result AcrionResult = new Result();
 | 
	
		
			
				|  |  | +            BeginTran();
 | 
	
		
			
				|  |  | +            var DBresult = await SoftDeleteByIdAsync<Crm_NewClientData>(dto.Id.ToString(), dto.DeleteUserId);
 | 
	
		
			
				|  |  | +            try
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                if (DBresult)
 | 
	
		
			
				|  |  | +                {
 | 
	
		
			
				|  |  | +                    AcrionResult.Code = 0;
 | 
	
		
			
				|  |  | +                    string sqlSet = $"isdel = 1, DeleteUserId = {dto.DeleteUserId} ,DeleteTime = '{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}'";
 | 
	
		
			
				|  |  | +                    string sql = $" update Crm_ClientDataAndUser set {sqlSet} where NewClientDataId = {dto.Id} ";
 | 
	
		
			
				|  |  | +                    await ExecuteCommandAsync(sql);
 | 
	
		
			
				|  |  | +                    sql = $" update Crm_ClientDataAndBusiness set {sqlSet} where NewClientDataId = {dto.Id} ";
 | 
	
		
			
				|  |  | +                    await ExecuteCommandAsync(sql);
 | 
	
		
			
				|  |  | +                    CommitTran();
 | 
	
		
			
				|  |  | +                    AcrionResult.Code = 0;
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            catch (Exception ex)
 | 
	
		
			
				|  |  | +            {
 | 
	
		
			
				|  |  | +                RollbackTran();
 | 
	
		
			
				|  |  | +                AcrionResult.Msg = ex.Message;
 | 
	
		
			
				|  |  | +                AcrionResult.Code = -1;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            return AcrionResult;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |