Example #1
0
        /// <summary>
        /// 将联系人添加到联系人组
        /// </summary>
        public bool AddContactsToGroup(long groupId, string conIds, long userId)
        {
            var thisGroup = GetGroupById(groupId);

            if (thisGroup == null || string.IsNullOrEmpty(conIds))
            {
                return(false);
            }
            var conArr  = conIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
            var timeNow = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            var ccgcDal = new crm_contact_group_contact_dal();

            foreach (var conId in conArr)
            {
                var thisGroupCon = ccgcDal.GetByGroupContact(thisGroup.id, long.Parse(conId));
                if (thisGroupCon == null)
                {
                    thisGroupCon = new crm_contact_group_contact()
                    {
                        id = ccgcDal.GetNextIdCom(),
                        contact_group_id = thisGroup.id,
                        contact_id       = long.Parse(conId),
                        create_time      = timeNow,
                        update_time      = timeNow,
                        create_user_id   = userId,
                        update_user_id   = userId,
                    };
                    ccgcDal.Insert(thisGroupCon);
                }
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// 删除联系人组
        /// </summary>
        public bool DeleteContactGroup(long groupId, long userId)
        {
            var thisGroup            = GetGroupById(groupId);
            var ccgcDal              = new crm_contact_group_contact_dal();
            var timeNow              = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            var thisGroupContactList = ccgcDal.GetGroupContactByGroup(groupId);

            if (thisGroup != null)
            {
                new crm_contact_group_dal().SoftDelete(thisGroup, userId);
            }
            if (thisGroupContactList != null && thisGroupContactList.Count > 0)
            {
                thisGroupContactList.ForEach(_ =>
                {
                    ccgcDal.SoftDelete(_, userId);
                });
            }
            return(true);
        }
Example #3
0
        /// <summary>
        /// 从联系人组中移除联系人
        /// </summary>
        public bool RemoveContactFromGroup(long groupId, string conIds, long userId)
        {
            var thisGroup = GetGroupById(groupId);

            if (thisGroup == null || string.IsNullOrEmpty(conIds))
            {
                return(false);
            }
            var ccgcDal = new crm_contact_group_contact_dal();
            var conArr  = conIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var conId in conArr)
            {
                var thisGroupContact = ccgcDal.FindNoDeleteById(long.Parse(conId));
                if (thisGroupContact != null)
                {
                    ccgcDal.SoftDelete(thisGroupContact, userId);
                }
            }
            return(true);
        }
Example #4
0
        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);
        }
Example #5
0
        /// <summary>
        /// 客户的联系人组 联系人管理
        /// </summary>
        public bool AccountContractGroupManage(long accountId, long groupId, string ids, long userId)
        {
            var thisGroup   = GetGroupById(groupId);
            var thisAccount = new CompanyBLL().GetCompany(accountId);

            if (thisGroup == null || thisAccount == null)
            {
                return(false);
            }
            var oldConList = GetAccountGroupContact(groupId, accountId);
            var timeNow    = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now);
            var ccgcDal    = new crm_contact_group_contact_dal();

            if (oldConList != null && oldConList.Count > 0)
            {
                if (!string.IsNullOrEmpty(ids))
                {
                    var idArr = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var id in idArr)
                    {
                        var thisCon = oldConList.FirstOrDefault(_ => _.contact_group_id == groupId && _.contact_id == long.Parse(id));
                        if (thisCon != null)
                        {
                            oldConList.Remove(thisCon);
                            continue;
                        }
                        thisCon = new crm_contact_group_contact()
                        {
                            id = ccgcDal.GetNextIdCom(),
                            contact_group_id = groupId,
                            contact_id       = long.Parse(id),
                            create_time      = timeNow,
                            create_user_id   = userId,
                            update_time      = timeNow,
                            update_user_id   = userId,
                        };
                        ccgcDal.Insert(thisCon);
                    }
                    if (oldConList.Count > 0)
                    {
                        oldConList.ForEach(_ =>
                        {
                            ccgcDal.SoftDelete(_, userId);
                        });
                    }
                }
                else
                {
                    oldConList.ForEach(_ =>
                    {
                        ccgcDal.SoftDelete(_, userId);
                    });
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(ids))
                {
                    var idArr = ids.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (var id in idArr)
                    {
                        var thisCon = ccgcDal.GetByGroupContact(groupId, long.Parse(id));
                        if (thisCon != null)
                        {
                            continue;
                        }
                        thisCon = new crm_contact_group_contact()
                        {
                            id = ccgcDal.GetNextIdCom(),
                            contact_group_id = groupId,
                            contact_id       = long.Parse(id),
                            create_time      = timeNow,
                            create_user_id   = userId,
                            update_time      = timeNow,
                            update_user_id   = userId,
                        };
                        ccgcDal.Insert(thisCon);
                    }
                }
            }
            return(true);
        }