public bool MergeContact(long fromConId, long toConId, long userId, bool isDelete = false) { crm_contact fromCon = GetContact(fromConId); crm_contact toCon = GetContact(toConId); if (fromCon == null || toCon == null || fromConId == toConId) { return(false); } CompanyBLL accBll = new CompanyBLL(); // 商机// 销售订单 OpportunityBLL oppoBll = new OpportunityBLL(); List <crm_opportunity> oppoList = new OpportunityBLL().GetOppoBySql($"SELECT * from crm_opportunity where delete_time =0 and contact_id = {fromConId.ToString()} "); if (oppoList != null && oppoList.Count > 0) { oppoList.ForEach(_ => { _.contact_id = toConId; oppoBll.EdotOpportunity(_, userId); }); } // 待办 // 活动 ActivityBLL actBll = new ActivityBLL(); List <com_activity> activityList = new ActivityBLL().GetToListBySql($"select * from com_activity where delete_time =0 and contact_id = {fromConId.ToString()} and (status_id <> {(int)DicEnum.ACTIVITY_STATUS.COMPLETED} or status_id is null)"); if (activityList != null && activityList.Count > 0) { activityList.ForEach(_ => { _.contact_id = toConId; actBll.EditActivity(_, userId); }); } // 工单 // 任务 TicketBLL taskBll = new TicketBLL(); List <sdk_task> ticketList = accBll.GetBySql <sdk_task>($"SELECT * from sdk_task where type_id in (1809,1807) and delete_time = 0 and contact_id = {fromConId.ToString()}"); if (ticketList != null && ticketList.Count > 0) { ticketList.ForEach(_ => { _.contact_id = toConId; taskBll.EditTicket(_, userId); }); } // 调查 // 联系人群组 List <crm_contact_group> groupList = accBll.GetBySql <crm_contact_group>($"SELECT ccg.* from crm_contact_group ccg INNER JOIN crm_contact_group_contact ccgc on ccg.id = ccgc.contact_group_id where ccg.delete_time =0 and ccgc.delete_time = 0 and ccgc.contact_id = {fromConId.ToString()}"); crm_contact_group_contact_dal ccgcDal = new crm_contact_group_contact_dal(); if (groupList != null && groupList.Count > 0) { groupList.ForEach(_ => { var list = GetGroupContactByGroup(_.id); if (list != null && list.Count > 0) { var from = list.FirstOrDefault(l => l.contact_id == toConId); if (from != null) { if (list.Any(l => l.contact_id == toConId)) // 删除源 { ccgcDal.SoftDelete(from, userId); } else // 更改源 { from.contact_id = toConId; ccgcDal.Update(from); } } } }); } // 合同 ContractBLL contractBll = new ContractBLL(); List <ctt_contract> contractList = accBll.GetBySql <ctt_contract>($"SELECT id, name from ctt_contract where delete_time = 0 and contact_id = { fromConId.ToString()}"); if (contractList != null && contractList.Count > 0) { contractList.ForEach(_ => { _.contact_id = toConId; contractBll.EditContractOnly(_, userId); }); } if (isDelete) { DeleteContact(fromConId, userId); } return(true); }