protected void Page_Load(object sender, EventArgs e) { long id = 0; if (!string.IsNullOrEmpty(Request.QueryString["id"]) && long.TryParse(Request.QueryString["id"], out id)) { thisActivity = new ActivityBLL().GetActivity(id); } if (thisActivity == null) { Response.Write("<script>alert('为获取到相关信息!请刷新页面后重试!');window.close();</script>"); } else { if (thisActivity.account_id != null) { account = new CompanyBLL().GetCompany((long)thisActivity.account_id); } if (thisActivity.resource_id != null) { assignUser = new UserResourceBLL().GetResourceById((long)thisActivity.resource_id); } createUser = new UserResourceBLL().GetResourceById(thisActivity.create_user_id); actType = new GeneralBLL().GetSingleGeneral(thisActivity.action_type_id, true); if (thisActivity.action_type_id == (int)DTO.DicEnum.ACTIVITY_CATE.TODO) { isTodo = true; } } }
/// <summary> /// 执行联系人活动信息 /// </summary> public bool ExectueContactAction(ExexuteContactDto param, long userId) { if (string.IsNullOrEmpty(param.ids)) { return(false); } if (!param.isHasNote && !param.isHasTodo) { return(false); } var conList = GetListByIds(param.ids); if (conList == null || conList.Count == 0) { return(false); } var timeNow = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); var caDal = new com_activity_dal(); var accBll = new CompanyBLL(); foreach (var contact in conList) { if (param.isHasNote) { var thisNote = new com_activity() { id = caDal.GetNextIdCom(), cate_id = (int)DicEnum.ACTIVITY_CATE.NOTE, account_id = contact.account_id, action_type_id = param.note_action_type, contact_id = contact.id, object_id = contact.id, object_type_id = (int)DicEnum.OBJECT_TYPE.CONTACT, description = param.note_content, create_time = timeNow, update_time = timeNow, create_user_id = userId, resource_id = userId, update_user_id = userId, }; caDal.Insert(thisNote); OperLogBLL.OperLogAdd <com_activity>(thisNote, thisNote.id, userId, DicEnum.OPER_LOG_OBJ_CATE.ACTIVITY, "新增备注"); } if (param.isHasTodo) { long?resId = param.assignRes; if (resId == -1) { var thisAcc = accBll.GetCompany(contact.account_id); if (thisAcc != null) { resId = thisAcc.resource_id; } } var thisTodo = new com_activity() { id = caDal.GetNextIdCom(), cate_id = (int)DicEnum.ACTIVITY_CATE.TODO, account_id = contact.account_id, action_type_id = param.todo_action_type, contact_id = contact.id, object_id = contact.id, resource_id = resId, object_type_id = (int)DicEnum.OBJECT_TYPE.CONTACT, description = param.todo_content, create_time = timeNow, update_time = timeNow, create_user_id = userId, update_user_id = userId, start_date = param.startDate, end_date = param.endDate, }; caDal.Insert(thisTodo); OperLogBLL.OperLogAdd <com_activity>(thisTodo, thisTodo.id, userId, DicEnum.OPER_LOG_OBJ_CATE.ACTIVITY, "新增备注"); } } return(true); }
protected void Page_Load(object sender, EventArgs e) { actionTypeList = bll.GetCRMActionType(); resourceList = new UserResourceBLL().GetResourceList(); if (!IsPostBack) { long noteid; if (!string.IsNullOrEmpty(Request.QueryString["id"]) && long.TryParse(Request.QueryString["id"], out noteid)) { if (AuthBLL.GetUserTodoAuth(LoginUserId, LoginUser.security_Level_id, noteid).CanEdit == false) { Response.Write("<script>alert('您不能编辑此待办');</script>"); Response.End(); return; } note = bll.GetActivity(noteid); contactList = new ContactBLL().GetContactByCompany((long)note.account_id); opportunityList = new OpportunityBLL().GetOpportunityByCompany((long)note.account_id); #region 记录浏览历史 var accountName = ""; if (note.account_id != null) { var account = new CompanyBLL().GetCompany((long)note.account_id); accountName = account == null ? "" : account.name; } var history = new sys_windows_history() { title = "待办:" + note.description + ":" + accountName, url = Request.RawUrl, }; new IndexBLL().BrowseHistory(history, LoginUserId); #endregion } if (long.TryParse(Request.QueryString["accountId"], out accountId)) { objType = (int)DicEnum.OBJECT_TYPE.CUSTOMER; objId = accountId; } if (long.TryParse(Request.QueryString["contactId"], out contactId)) { accountId = new ContactBLL().GetContact(contactId).account_id; objType = (int)DicEnum.OBJECT_TYPE.CONTACT; objId = contactId; } if (long.TryParse(Request.QueryString["opportunityId"], out opportunityId)) { objType = (int)DicEnum.OBJECT_TYPE.OPPORTUNITY; objId = opportunityId; var opp = new OpportunityBLL().GetOpportunity(opportunityId).general; accountId = opp.account_id; if (opp.contact_id != null) { contactId = (long)opp.contact_id; } } if (long.TryParse(Request.QueryString["saleorderId"], out saleOrderId)) { objType = (int)DicEnum.OBJECT_TYPE.SALEORDER; objId = saleOrderId; var saleOrder = new SaleOrderBLL().GetSaleOrder(saleOrderId); var opp = new OpportunityBLL().GetOpportunity(saleOrder.opportunity_id).general; opportunityId = opp.id; accountId = opp.account_id; if (opp.contact_id != null) { contactId = (long)opp.contact_id; } } if (long.TryParse(Request.QueryString["ticketId"], out ticketId)) { objType = (int)DicEnum.OBJECT_TYPE.TICKETS; objId = ticketId; ticket = new DAL.sdk_task_dal().FindNoDeleteById(ticketId); accountId = ticket.account_id; if (ticket.contact_id != null) { contactId = (long)ticket.contact_id; } if (ticket.opportunity_id != null) { opportunityId = (long)ticket.opportunity_id; } } } else { com_activity activity = AssembleModel <com_activity>(); if (activity.contact_id == 0) { activity.contact_id = null; } activity.start_date = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(Request.Form["start_date2"])); activity.end_date = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(Request.Form["end_date2"])); if (!string.IsNullOrEmpty(Request.Form["is_completed"]) && Request.Form["is_completed"].Equals("on")) { activity.status_id = (int)DicEnum.ACTIVITY_STATUS.COMPLETED; activity.complete_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(Request.Form["complete_time1"])); } else { activity.status_id = (int)DicEnum.ACTIVITY_STATUS.NOT_COMPLETED; activity.complete_description = null; } if (string.IsNullOrEmpty(Request.Form["id"])) { bll.AddTodo(activity, GetLoginUserId()); } else { bll.EditTodo(activity, GetLoginUserId()); } if (Request.Form["action"] != null && Request.Form["action"].Equals("SaveNew")) { Response.Write("<script>alert('保存待办成功');window.location.href='Notes.aspx';self.opener.location.reload();</script>"); } else { Response.Write("<script>alert('保存待办成功');window.close();self.opener.location.reload();</script>"); } } }
protected void Page_Load(object sender, EventArgs e) { thisUser = new sys_resource_dal().FindNoDeleteById(GetLoginUserId()); var caDal = new com_activity_dal(); var stDal = new sdk_task_dal(); var ppDal = new pro_project_dal(); var accDal = new crm_account_dal(); var ccDal = new ctt_contract_dal(); var id = Request.QueryString["id"]; if (!string.IsNullOrEmpty(id)) { thisNote = caDal.FindNoDeleteById(long.Parse(id)); if (thisNote != null) { isAdd = false; thisNoteAtt = new com_attachment_dal().GetAttListByOid(thisNote.id); thisTicket = stDal.FindNoDeleteById(thisNote.object_id); if (thisTicket != null) { object_id = thisTicket.id; } else { thisProject = ppDal.FindNoDeleteById(thisNote.object_id); if (thisProject != null) { object_id = thisProject.id; thisAccount = accDal.FindNoDeleteById(thisProject.account_id); } else { thisContract = ccDal.FindNoDeleteById(thisNote.object_id); if (thisContract != null) { object_id = thisContract.id; thisAccount = accDal.FindNoDeleteById(thisContract.account_id); } } } } } var ticketId = Request.QueryString["ticket_id"]; if (!string.IsNullOrEmpty(ticketId)) { thisTicket = stDal.FindNoDeleteById(long.Parse(ticketId)); } if (thisTicket != null) { object_id = thisTicket.id; if (thisTicket.type_id == (int)DicEnum.TASK_TYPE.PROJECT_PHASE) { // isPhase = true; } if (thisTicket.contact_id != null) { thisContact = new crm_contact_dal().FindNoDeleteById((long)thisTicket.contact_id); } thisAccount = accDal.FindNoDeleteById(thisTicket.account_id); ticket_creator = new sys_resource_dal().FindNoDeleteById(thisTicket.create_user_id); if (!IsPostBack) { //status_id.SelectedValue = thisTicket.status_id.ToString(); } if (thisTicket.project_id != null) { thisProject = ppDal.FindNoDeleteById((long)thisTicket.project_id); if (thisProject != null && thisAccount != null) { thisAccount = accDal.FindNoDeleteById(thisProject.account_id); } } } if (thisAccount == null) { Response.End(); } else { if (thisAccount.resource_id != null) { thisAccManger = new sys_resource_dal().FindNoDeleteById((long)thisAccount.resource_id); } } if (!IsPostBack) { publish_type_id.DataTextField = "name"; publish_type_id.DataValueField = "id"; var pushList = new d_general_dal().GetGeneralByTableId((int)GeneralTableEnum.NOTE_PUBLISH_TYPE); if (pushList != null && pushList.Count > 0) { pushList = pushList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.TICKET_NOTE).ToString()).ToList(); } publish_type_id.DataSource = pushList; publish_type_id.DataBind(); status_id.DataTextField = "show"; status_id.DataValueField = "val"; status_id.DataSource = dic.FirstOrDefault(_ => _.Key == "ticket_status").Value; status_id.DataBind(); if (thisTicket != null) { status_id.SelectedValue = thisTicket.status_id.ToString(); } action_type_id.DataTextField = "name"; action_type_id.DataValueField = "id"; var actList = new d_general_dal().GetGeneralByTableId((int)GeneralTableEnum.ACTION_TYPE); actList = actList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.TASK_NOTE).ToString()).ToList(); action_type_id.DataSource = actList; action_type_id.DataBind(); if (thisNote != null) { if (!IsPostBack) { if (thisNote.publish_type_id != null) { publish_type_id.SelectedValue = thisNote.publish_type_id.ToString(); } action_type_id.SelectedValue = thisNote.action_type_id.ToString(); } } //else //{ // if (isContract) // { // publish_type_id.SelectedValue = ((int)DicEnum.NOTE_PUBLISH_TYPE.CONTRACT_INTERNA_USER).ToString(); // } //} var tempList = new sys_notify_tmpl_dal().GetTempByEvent(DicEnum.NOTIFY_EVENT.NONE); notify_id.DataTextField = "name"; notify_id.DataValueField = "id"; notify_id.DataSource = tempList; notify_id.DataBind(); } }
protected void Page_Load(object sender, EventArgs e) { thisBookMark = new IndexBLL().GetSingBook(Request.RawUrl, LoginUserId); actionTypeList = bll.GetCRMActionType(); resourceList = new UserResourceBLL().GetResourceList(); if (!IsPostBack) { long noteid; if (!string.IsNullOrEmpty(Request.QueryString["id"]) && long.TryParse(Request.QueryString["id"], out noteid)) { if (AuthBLL.GetUserNoteAuth(LoginUserId, LoginUser.security_Level_id, noteid).CanEdit == false) { Response.Write("<script>alert('您不能编辑此备注');</script>"); Response.End(); return; } note = bll.GetActivity(noteid); contactList = new ContactBLL().GetContactByCompany((long)note.account_id); opportunityList = new OpportunityBLL().GetOpportunityByCompany((long)note.account_id); var accountName = ""; if (note.account_id != null) { var account = new CompanyBLL().GetCompany((long)note.account_id); accountName = account == null ? "" : account.name; } var history = new sys_windows_history() { title = "备注:" + note.description + ":" + accountName, url = Request.RawUrl, }; new IndexBLL().BrowseHistory(history, LoginUserId); } if (long.TryParse(Request.QueryString["accountId"], out accountId)) { objType = (int)DicEnum.OBJECT_TYPE.CUSTOMER; objId = accountId; } if (long.TryParse(Request.QueryString["contactId"], out contactId)) { accountId = new ContactBLL().GetContact(contactId).account_id; objType = (int)DicEnum.OBJECT_TYPE.CONTACT; objId = contactId; } if (long.TryParse(Request.QueryString["opportunityId"], out opportunityId)) { objType = (int)DicEnum.OBJECT_TYPE.OPPORTUNITY; objId = opportunityId; var opp = new OpportunityBLL().GetOpportunity(opportunityId).general; accountId = opp.account_id; if (opp.contact_id != null) { contactId = (long)opp.contact_id; } } if (long.TryParse(Request.QueryString["saleorderId"], out saleOrderId)) { objType = (int)DicEnum.OBJECT_TYPE.SALEORDER; objId = saleOrderId; var saleOrder = new SaleOrderBLL().GetSaleOrder(saleOrderId); var opp = new OpportunityBLL().GetOpportunity(saleOrder.opportunity_id).general; opportunityId = opp.id; accountId = opp.account_id; if (opp.contact_id != null) { contactId = (long)opp.contact_id; } } } else { com_activity activity = AssembleModel <com_activity>(); if (activity.contact_id == 0) { activity.contact_id = null; } activity.start_date = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(Request.Form["start_date2"])); activity.end_date = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(Request.Form["end_date2"])); com_activity todo = null; if (!string.IsNullOrEmpty(Request.Form["action_type_id1"])) { todo = new com_activity(); todo.action_type_id = int.Parse(Request.Form["action_type_id1"]); todo.start_date = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(Request.Form["start_date1"])); todo.end_date = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(Request.Form["end_date1"])); todo.description = Request.Form["description1"]; if (!string.IsNullOrEmpty(Request.Form["resource_id1"])) { todo.resource_id = long.Parse(Request.Form["resource_id1"]); } } if (string.IsNullOrEmpty(Request.Form["id"])) { bll.AddCRMNote(activity, todo, GetLoginUserId()); } else { bll.EditCRMNote(activity, todo, GetLoginUserId()); } if (Request.Form["action"] != null && Request.Form["action"].Equals("SaveNew")) { Response.Write("<script>alert('保存备注成功');window.location.href='Notes.aspx';self.opener.location.reload();</script>"); } else { Response.Write("<script>alert('保存备注成功');window.close();self.opener.location.reload();</script>"); } } }
protected void Page_Load(object sender, EventArgs e) { try { thisUser = new sys_resource_dal().FindNoDeleteById(GetLoginUserId()); var caDal = new com_activity_dal(); var stDal = new sdk_task_dal(); var ppDal = new pro_project_dal(); var accDal = new crm_account_dal(); var ccDal = new ctt_contract_dal(); var id = Request.QueryString["id"]; if (!string.IsNullOrEmpty(id)) { thisNote = caDal.FindNoDeleteById(long.Parse(id)); if (thisNote != null) { isAdd = false; thisNoteAtt = new com_attachment_dal().GetAttListByOid(thisNote.id); thisTask = stDal.FindNoDeleteById(thisNote.object_id); if (thisTask != null) { object_id = thisTask.id; if (thisTask.type_id == (int)DicEnum.TASK_TYPE.SERVICE_DESK_TICKET) { isTicket = true; thisTask = null; thisTicket = stDal.FindNoDeleteById(thisNote.object_id); } } else { thisProject = ppDal.FindNoDeleteById(thisNote.object_id); if (thisProject != null) { isProject = true; object_id = thisProject.id; thisAccount = accDal.FindNoDeleteById(thisProject.account_id); } else { thisContract = ccDal.FindNoDeleteById(thisNote.object_id); if (thisContract != null) { isContract = true; object_id = thisContract.id; thisAccount = accDal.FindNoDeleteById(thisContract.account_id); } } } } } var taskId = Request.QueryString["task_id"]; var project_id = Request.QueryString["project_id"]; var contract_id = Request.QueryString["contract_id"]; var ticket_id = Request.QueryString["ticket_id"]; var call_id = Request.QueryString["call_id"]; if (!string.IsNullOrEmpty(taskId)) { thisTask = stDal.FindNoDeleteById(long.Parse(taskId)); } else if (!string.IsNullOrEmpty(project_id)) { thisProject = ppDal.FindNoDeleteById(long.Parse(project_id)); if (thisProject != null) { isProject = true; object_id = thisProject.id; thisAccount = accDal.FindNoDeleteById(thisProject.account_id); } } else if (!string.IsNullOrEmpty(contract_id)) { thisContract = ccDal.FindNoDeleteById(long.Parse(contract_id)); if (thisContract != null) { object_id = thisContract.id; thisAccount = accDal.FindNoDeleteById(thisContract.account_id); isContract = true; } } else if (!string.IsNullOrEmpty(ticket_id)) { thisTicket = stDal.FindNoDeleteById(long.Parse(ticket_id)); } else if (!string.IsNullOrEmpty(call_id)) { thisCall = new sdk_service_call_dal().FindNoDeleteById(long.Parse(call_id)); if (thisCall != null) { isCall = true; thisAccount = new CompanyBLL().GetCompany(thisCall.account_id); callTicketList = stDal.GetTciketByCall(thisCall.id); if (callTicketList != null && callTicketList.Count > 0) { thisTask = callTicketList[0]; if (callTicketList.Any(_ => _.id != thisTask.id && _.status_id != thisTask.status_id)) { isMantStatus = true; } if (callTicketList.Any(_ => _.id != thisTask.id && _.account_id != thisTask.account_id)) { isManyAccount = true; } if (callTicketList.Any(_ => _.id != thisTask.id && _.title != thisTask.title)) { isManyTitle = true; } } else { Response.Write("<script>alert('服务预定下暂无工单!');window.close();</script>"); return; } } } if (thisTask != null) { thisAccount = accDal.FindNoDeleteById(thisTask.account_id); object_id = thisTask.id; if (thisTask.type_id == (int)DicEnum.TASK_TYPE.PROJECT_PHASE) { isPhase = true; } task_creator = new sys_resource_dal().FindNoDeleteById(thisTask.create_user_id); if (thisTask.project_id != null) { thisProject = ppDal.FindNoDeleteById((long)thisTask.project_id); if (thisProject != null) { thisAccount = accDal.FindNoDeleteById(thisProject.account_id); } } } if (thisTicket != null) { isTicket = true; object_id = thisTicket.id; task_creator = new sys_resource_dal().FindNoDeleteById(thisTicket.create_user_id); thisAccount = accDal.FindNoDeleteById(thisTicket.account_id); if (thisTicket.contact_id != null) { thisContact = new crm_contact_dal().FindNoDeleteById((long)thisTicket.contact_id); } } if (thisAccount == null) { Response.End(); } else { if (thisAccount.resource_id != null) { thisAccManger = new sys_resource_dal().FindNoDeleteById((long)thisAccount.resource_id); } } if (!IsPostBack) { publish_type_id.DataTextField = "name"; publish_type_id.DataValueField = "id"; var pushList = new d_general_dal().GetGeneralByTableId((int)GeneralTableEnum.NOTE_PUBLISH_TYPE); if (pushList != null && pushList.Count > 0) { if (isProject) { pushList = pushList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.PROJECT_NOTE).ToString()).ToList(); } else if (isContract) { pushList = pushList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.CONTRACT_NOTE).ToString()).ToList(); } else if (isTicket) { pushList = pushList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.TASK_NOTE).ToString()).ToList(); } else { pushList = pushList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.TASK_NOTE).ToString()).ToList(); } } publish_type_id.DataSource = pushList; publish_type_id.DataBind(); status_id.DataTextField = "show"; status_id.DataValueField = "val"; var statusList = dic.FirstOrDefault(_ => _.Key == "ticket_status").Value as List <DictionaryEntryDto>; if (isMantStatus) { statusList.Add(new DictionaryEntryDto() { val = "0", show = "多个值,保持不变" }); } status_id.DataSource = statusList; status_id.DataBind(); if (isMantStatus) { status_id.SelectedValue = "0"; } else if (thisTask != null) { status_id.SelectedValue = thisTask.status_id.ToString(); } else if (thisTicket != null) { status_id.SelectedValue = thisTicket.status_id.ToString(); } action_type_id.DataTextField = "name"; action_type_id.DataValueField = "id"; var actList = new d_general_dal().GetGeneralByTableId((int)GeneralTableEnum.ACTION_TYPE); if (actList != null && actList.Count > 0) { if (isProject) { actList = actList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.PROJECT_NOTE).ToString()).ToList(); } else if (isContract) { actList = actList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.CONTRACT_NOTE).ToString()).ToList(); } else if (isTicket) { actList = actList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.TASK_NOTE).ToString()).ToList(); } else { actList = actList.Where(_ => _.ext2 == ((int)DicEnum.ACTIVITY_CATE.TASK_NOTE).ToString()).ToList(); } } action_type_id.DataSource = actList; action_type_id.DataBind(); if (thisNote != null) { if (!IsPostBack) { if (thisNote.publish_type_id != null) { publish_type_id.SelectedValue = thisNote.publish_type_id.ToString(); } action_type_id.SelectedValue = thisNote.action_type_id.ToString(); isAnnounce.Checked = thisNote.announce == 1; } } else { if (isContract) { publish_type_id.SelectedValue = ((int)DicEnum.NOTE_PUBLISH_TYPE.CONTRACT_INTERNA_USER).ToString(); } } var tempList = new sys_notify_tmpl_dal().GetTempByEvent(DicEnum.NOTIFY_EVENT.NONE); notify_id.DataTextField = "name"; notify_id.DataValueField = "id"; notify_id.DataSource = tempList; notify_id.DataBind(); } if (isProject) { tmplList = new FormTemplateBLL().GetTmplByType((int)DicEnum.FORM_TMPL_TYPE.PROJECT_NOTE, LoginUserId); } else if (isTicket && thisTicket != null) { tmplList = new FormTemplateBLL().GetTmplByType((int)DicEnum.FORM_TMPL_TYPE.TICKET_NOTE, LoginUserId); } else if (thisTask != null) { tmplList = new FormTemplateBLL().GetTmplByType((int)DicEnum.FORM_TMPL_TYPE.TASK_NOTE, LoginUserId); } } catch (Exception msg) { Response.Write(msg); Response.End(); } }
public ERROR_CODE CloseQuote(long user_id, QuoteCloseDto param) { // 此向导将会把产品、一次性折扣、配送、成本转为计费项。可选项和费用不会被转换。如果有产品,会生成销售订单。 // 报价中如果有服务 / 包或初始费用,将不会被转换为计费项,也不会创建定期服务合同 // 如果商机状态已经是“关闭”或“已实施”,将会为此商机生成重复的计费项。 // 报价项中如果有物料代码为空的,则需要设置。如果没有需要配置的,则此界面不显示 // 计费项将会生成,是否需要创建发票 // 打开新建的销售订单(链接)——如果创建了销售单才显示 // 关闭报价是关闭商机的另一种方式, // -- 必填项校验-- 根据系统设置来判断 TODO var user = UserInfoBLL.GetUserInfo(user_id); // 1.更新商机信息 #region 1.更新商机信息 // 根据系统设置来选择商机的阶段-- todo param.opportunity.status_id = (int)DicEnum.OPPORTUNITY_STATUS.CLOSED; var stageList = new d_general_dal().GetGeneralByTableId((int)GeneralTableEnum.OPPORTUNITY_STATUS); var defaultStage = stageList.FirstOrDefault(_ => _.ext1 == "1"); if (defaultStage != null) { param.opportunity.stage_id = defaultStage.id; } var old_opportunity = new crm_opportunity_dal().GetOpportunityById(param.opportunity.id); new crm_opportunity_dal().Update(param.opportunity); new sys_oper_log_dal().Insert(new sys_oper_log() { user_cate = "用户", user_id = user_id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.OPPORTUNITY, oper_object_id = param.opportunity.id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.UPDATE, oper_description = _dal.CompareValue(old_opportunity, param.opportunity), remark = "修改商机信息" }); #endregion // 2.更新客户信息 #region 2.更新客户信息 var account = new CompanyBLL().GetCompany(param.quote.account_id); if (account.type_id != (int)DicEnum.ACCOUNT_TYPE.CUSTOMER) { account.type_id = (int)DicEnum.ACCOUNT_TYPE.CUSTOMER; new crm_account_dal().Update(account); new sys_oper_log_dal().Insert(new sys_oper_log() { user_cate = "用户", user_id = user_id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.CUSTOMER, oper_object_id = param.quote.account_id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.UPDATE, oper_description = _dal.CompareValue(new CompanyBLL().GetCompany(param.quote.account_id), account), remark = "修改客户信息" }); } #endregion long?contact_id = null; if (param.opportunity.contact_id != null) { crm_contact contact = new ContactBLL().GetContact((long)param.opportunity.contact_id); if (contact.is_active == 1) { contact_id = contact.id; } } // 3.保存项目信息 #region 3.如果项目关联了项目提案,修改项目提案信息 if (param.quote.project_id != null) { var project = new pro_project_dal().GetProjectById((long)param.quote.project_id); if (project != null) { if (project.type_id != (int)PROJECT_TYPE.ACCOUNT_PROJECT) { project.type_id = (int)PROJECT_TYPE.ACCOUNT_PROJECT; project.update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now); project.update_user_id = user.id; new sys_oper_log_dal().Insert(new sys_oper_log() { user_cate = "用户", user_id = (int)user.id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.PROJECT, oper_object_id = project.id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.UPDATE, oper_description = _dal.CompareValue(new pro_project_dal().GetProjectById((long)param.quote.project_id), project), remark = "修改项目提案类型" }); new pro_project_dal().Update(project); } param.project_id = project.id; } string costIds = ""; new OpportunityBLL().InsertContract(param.dic, param.opportunity, user, null, out costIds, param.project_id, null); if (!string.IsNullOrEmpty(costIds)) { var aapBLL = new ApproveAndPostBLL(); costIds = costIds.Substring(0, costIds.Length - 1); var costList = costIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (var costId in costList) { // 审批并提交 aapBLL.Post_Charges(int.Parse(costId), int.Parse(DateTime.Now.ToString("yyyyMMdd")), user); } } } #endregion // 4.新增工单信息 #region 4.如果报价未关联项目提案,有需要转换的计费项 // todo 关联sdk_ticket #endregion // 5.转换为工单/项目成本 #region 5.转换为工单/项目成本 // todo 关联sdk_ticket_charge // 一次性折扣根据需要拆分为两行——收税的、不收税的,分别计算折扣额。计算时仍然按照全部周期为一次性的报价项,而不是排除了服务和工时等报价项。 #endregion // 将报价项转换为计费项 #region 将报价项转换为计费项并审批提交 todo-需要项目ID 或者工单ID才可以进行操作 //string costIds =""; //new OpportunityBLL().InsertContract(param.dic,param.opportunity,user,null,out costIds, param.project_id,null); //if (!string.IsNullOrEmpty(costIds)) //{ // var aapBLL = new ApproveAndPostBLL(); // costIds = costIds.Substring(0,costIds.Length-1); // var costList = costIds.Split(new char[] { ','},StringSplitOptions.RemoveEmptyEntries); // foreach (var costId in costList) // { // // 审批并提交 // aapBLL.Post_Charges(int.Parse(costId),int.Parse(DateTime.Now.ToString("yyyyMMdd")),user); // } //} #endregion // 6.新增销售订单 #region 6.当有产品/一次性折扣、成本、配送转为计费项时,销售订单就会自动生成。Crm_sales_order if (param.dic != null && param.dic.Count > 0) { var saleOrder = new crm_sales_order_dal().GetSingleSalesOrderByWhere($" and opportunity_id = {param.opportunity.id} "); if (saleOrder == null) { saleOrder = new crm_sales_order() { id = _dal.GetNextIdCom(), opportunity_id = param.opportunity.id, status_id = (int)SALES_ORDER_STATUS.OPEN, contact_id = contact_id, owner_resource_id = param.opportunity.resource_id, begin_date = DateTime.Now, create_user_id = user.id, update_user_id = user.id, create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), }; new crm_sales_order_dal().Insert(saleOrder); new sys_oper_log_dal().Insert(new sys_oper_log() { user_cate = "用户", user_id = (int)user.id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.SALE_ORDER, oper_object_id = saleOrder.id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.ADD, oper_description = _dal.AddValue(saleOrder), remark = "关闭报价,新增销售订单" }); param.saleOrderId = saleOrder.id; } } #endregion // 7.新增项目备注 #region 7.转为项目计费项时,会生成备注 if (param.quote.project_id != null) { com_activity addActivity = new com_activity() { id = _dal.GetNextIdCom(), cate_id = (int)ACTIVITY_CATE.PROJECT_NOTE, action_type_id = (int)ACTIVITY_TYPE.PROJECT_NOTE, parent_id = null, object_id = (long)param.quote.project_id, object_type_id = (int)OBJECT_TYPE.PROJECT, // todo发布范围 account_id = param.opportunity.account_id, contact_id = contact_id, resource_id = param.opportunity.resource_id, contract_id = contact_id, opportunity_id = param.opportunity.id, ticket_id = null, // todo 标题 description = $"", // todo 内容描述拼接 status_id = null, complete_description = null, complete_time = null, create_user_id = user.id, create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), update_user_id = user.id, update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), is_system_generate = 1, }; new com_activity_dal().Insert(addActivity); new sys_oper_log_dal().Insert(new sys_oper_log() { user_cate = "用户", user_id = (int)user.id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.ACTIVITY, oper_object_id = addActivity.id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.ADD, oper_description = _dal.AddValue(addActivity), remark = "商机关闭,新增项目备注" }); } #endregion // 8.新增备注(商机关闭) #region 8.商机关闭时,会自动生成备注 com_activity closeOppoActivity = new com_activity() { id = _dal.GetNextIdCom(), cate_id = (int)ACTIVITY_CATE.NOTE, action_type_id = (int)ACTIVITY_TYPE.OPPORTUNITYUPDATE, parent_id = null, object_id = param.opportunity.id, object_type_id = (int)OBJECT_TYPE.OPPORTUNITY, account_id = param.opportunity.account_id, contact_id = contact_id, resource_id = param.opportunity.resource_id, contract_id = null, // todo 如果转为合同成本,则为“合同”;否则为空 opportunity_id = param.opportunity.id, ticket_id = null, start_date = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(DateTime.Now.ToShortDateString() + " 12:00:00")), // todo 从页面获取时间,去页面时间的12:00:00 end_date = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Parse(DateTime.Now.ToShortDateString() + " 12:00:00")), description = $"关闭时间:{DateTime.Now.ToString("dd/MM/yyyy")}/r通知人:{user.email}/r主题:{param.opportunity.name}已经关闭/r内容:商机关闭向导定义", // todo 内容描述拼接 status_id = null, complete_description = null, complete_time = null, create_user_id = user.id, create_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), update_user_id = user.id, update_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), is_system_generate = 1, }; new com_activity_dal().Insert(closeOppoActivity); new sys_oper_log_dal().Insert(new sys_oper_log() { user_cate = "用户", user_id = (int)user.id, name = user.name, phone = user.mobile == null ? "" : user.mobile, oper_time = Tools.Date.DateHelper.ToUniversalTimeStamp(DateTime.Now), oper_object_cate_id = (int)OPER_LOG_OBJ_CATE.ACTIVITY, oper_object_id = closeOppoActivity.id,// 操作对象id oper_type_id = (int)OPER_LOG_TYPE.ADD, oper_description = _dal.AddValue(closeOppoActivity), remark = "新增关闭商机的备注" }); #endregion return(ERROR_CODE.SUCCESS); }