コード例 #1
0
ファイル: UserResourceBLL.cs プロジェクト: evelh/Done
        /// <summary>
        /// 转移员工(更改员工的客户,商机,待办,活动)
        /// </summary>
        public bool TransResource(long fromResId, long toResId, long userId)
        {
            if (fromResId == toResId)
            {
                return(true);
            }
            var fromRes = GetResourceById(fromResId);
            var toRes   = GetResourceById(toResId);

            if (fromRes == null || toRes == null)
            {
                return(false);
            }
            CompanyBLL         accBll  = new CompanyBLL();
            List <crm_account> accList = accBll.GetBySql <crm_account>("SELECT * from crm_account a where a.delete_time =0 and a.resource_id = " + fromResId.ToString());

            if (accList != null && accList.Count > 0)
            {
                accList.ForEach(_ => {
                    _.resource_id = toResId;
                    accBll.EditAccount(_, userId);
                });
            }

            OpportunityBLL         oppoBll  = new OpportunityBLL();
            List <crm_opportunity> oppoList = oppoBll.GetOppoBySql($"SELECT * from crm_opportunity where delete_time =0 and resource_id = {fromResId.ToString()} and status_id not in ({(int)DicEnum.OPPORTUNITY_STATUS.LOST},{(int)DicEnum.OPPORTUNITY_STATUS.CLOSED},{(int)DicEnum.OPPORTUNITY_STATUS.IMPLEMENTED})");

            if (oppoList != null && oppoList.Count > 0)
            {
                oppoList.ForEach(_ => {
                    _.resource_id = toResId;
                    oppoBll.EdotOpportunity(_, userId);
                });
            }

            ActivityBLL         actBll  = new ActivityBLL();
            List <com_activity> actList = actBll.GetToListBySql($"select id,name,description from com_activity where delete_time =0 and resource_id = {fromResId.ToString()} and (status_id <> {(int)DicEnum.ACTIVITY_STATUS.COMPLETED} or status_id is null)");

            if (actList != null && actList.Count > 0)
            {
                actList.ForEach(_ => {
                    _.resource_id = toResId;
                    actBll.EditActivity(_, userId);
                });
            }
            return(true);
        }
コード例 #2
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);
        }