public CrmBaseData <CRMUserData> Login() { CrmBaseData <CRMUserData> returndata = new CrmBaseData <CRMUserData>(); string url = _crmApiHost + _loginUrl; object data = new { device = _device, version_code = _versionCode, login = _login, password = _password }; string postdatastr = Newtonsoft.Json.JsonConvert.SerializeObject(data); string result = HttpHelper.DoPostJson(url, postdatastr); if (!string.IsNullOrEmpty(result)) { returndata = Newtonsoft.Json.JsonConvert.DeserializeObject <CrmBaseData <CRMUserData> >(result); } return(returndata); }
/// <summary> /// 客户模块 /// </summary> /// <param name="usertoken"></param> /// <param name="modelConfig"></param> /// <returns></returns> public List <CrmData> GetCustomerList(string usertoken, CrmApiData modelConfig) { List <CrmData> crmdata = new List <CrmData>(); if (modelConfig == null) { return(crmdata); } string starttime = modelConfig.CurrentTime; string endtime = modelConfig.CurrentTime; int pagesize = modelConfig.PageSize; int pageindex = modelConfig.PageIndex; string url = _crmApiHost + _customersUrl + $"?user_token={usertoken}&version_code={_versionCode}&device={_device}&start_date={starttime}&end_date={endtime}&per_page={pagesize}&page={pageindex}&date=other"; string result = HttpHelper.GetData(url); if (!string.IsNullOrEmpty(result)) { CrmBaseData <CRMNewIndexBoxData> returndata = Newtonsoft.Json.JsonConvert.DeserializeObject <CrmBaseData <CRMNewIndexBoxData> >(result); if (returndata != null && returndata.data.revisit_logs != null && returndata.data.revisit_logs.Count > 0) { if (modelConfig.TotalPageSize <= 0) { modelConfig.TotalPageSize = Convert.ToInt32(Math.Ceiling(returndata.data.total_count / Convert.ToDecimal(returndata.data.per_page))); base.Update(modelConfig, "totalpagesize"); } foreach (CRMNewIndexData item in returndata.data.revisit_logs) { CrmBaseData <CRMLeadsData> leaddata = GetCrmfilterLeads(usertoken, item.loggable_id); if (leaddata == null || leaddata.data == null || leaddata.data.address == null) { continue; } CrmData data = new CrmData(); data.phone = leaddata.data.address.tel; data.content = item.content; data.statecontent = leaddata.data.status_mapped; data.name = item.user.name; data.AddTime = item.real_revisit_at; crmdata.Add(data); } } } return(crmdata); }
public void CrmService() { CrmBaseData <CRMUserData> logininfo = Login(); if (logininfo != null && logininfo.data != null && !string.IsNullOrEmpty(logininfo.data.user_token)) { GetCrmLeadsList(logininfo.data.user_token); CrmApiData modelConfig = base.GetModel(1); DateTime nowtime = DateTime.Parse(DateTime.Now.ToShortDateString()); DateTime currenttime = DateTime.Parse(modelConfig.CurrentTime); if (nowtime.CompareTo(currenttime) > 0) { List <CrmData> crmdata = GetNewIndex(logininfo.data.user_token, modelConfig); SaveLog(crmdata, modelConfig); } } else { log4net.LogHelper.WriteInfo(this.GetType(), "获取crm服务登陆信息失败" + Newtonsoft.Json.JsonConvert.SerializeObject(logininfo)); } }
public CrmBaseData <CRMLeadsData> GetCrmfilterLeads(string usertoken, int id) { CrmLeads model = CrmLeadsBLL.SingleModel.GetModelLeadId(id); if (model != null) { CrmBaseData <CRMLeadsData> returndata = new CrmBaseData <CRMLeadsData>(); returndata.data = new CRMLeadsData(); returndata.data.address = new CRMAddressData(); returndata.data.address.tel = model.Phone; returndata.data.status_mapped = model.StateContent; return(returndata); } //string url = _crmApiHost + _leadsUrl + $"/{id}?user_token={usertoken}&version_code={_versionCode}&device={_device}"; //string result = HttpHelper.GetData(url); //if (!string.IsNullOrEmpty(result) && result != "Retry later\n") //{ // returndata = Newtonsoft.Json.JsonConvert.DeserializeObject<CrmBaseData<CRMLeadsData>>(result); //} return(new CrmBaseData <CRMLeadsData>()); }
public void GetCrmLeadsList(string usertoken) { TransactionModel tran = new TransactionModel(); CrmApiData modelConfig = base.GetModel(2); if (modelConfig == null) { return; } string url = _crmApiHost + _leadsUrl + $"?user_token={usertoken}&version_code={_versionCode}&device={_device}&source=4264341&per_page={modelConfig.PageSize}&page={modelConfig.PageIndex}&updated_at={modelConfig.CurrentTime}"; string result = HttpHelper.GetData(url); if (string.IsNullOrEmpty(result)) { return; } CrmBaseData <CRMLeadsBoxData> datalist = new CrmBaseData <CRMLeadsBoxData>(); try { datalist = Newtonsoft.Json.JsonConvert.DeserializeObject <CrmBaseData <CRMLeadsBoxData> >(result); } catch (Exception ex) { return; } if (datalist == null || datalist.data == null || datalist.data.leads == null || datalist.data.total_count <= 0) { return; } if (modelConfig.TotalPageSize <= 0) { modelConfig.TotalPageSize = Convert.ToInt32(Math.Ceiling(datalist.data.total_count / Convert.ToDecimal(datalist.data.per_page))); base.Update(modelConfig, "totalpagesize"); } foreach (CRMLeadsData item in datalist.data.leads) { CrmLeads model = CrmLeadsBLL.SingleModel.GetModelLeadId(item.id); if (model == null) { model = new CrmLeads(); model.AddTime = item.created_at; model.UpdateTime = item.updated_at; model.Phone = item.address.tel; model.LeadId = item.id; model.Name = item.name; int state = 0; int.TryParse(item.status, out state); model.State = state; model.StateContent = item.status_mapped; //CrmLeadsBLL.SingleModel.Add(model); tran.Add(CrmLeadsBLL.SingleModel.BuildAddSql(model)); } else { model.AddTime = item.created_at; model.UpdateTime = item.updated_at; model.Phone = item.address.tel; model.LeadId = item.id; model.Name = item.name; int state = 0; int.TryParse(item.status, out state); model.State = state; model.StateContent = item.status_mapped; //CrmLeadsBLL.SingleModel.Update(model); tran.Add(CrmLeadsBLL.SingleModel.BuildUpdateSql(model)); } } if (tran.sqlArray.Length > 0) { bool isok = base.ExecuteTransaction(tran.sqlArray); if (!isok) { log4net.LogHelper.WriteInfo(this.GetType(), "更新crm系统线索数据失败"); } } modelConfig.PageIndex += 1; if (modelConfig.PageIndex > modelConfig.TotalPageSize) { modelConfig.PageIndex = 1; modelConfig.TotalPageSize = 0; base.Update(modelConfig, "pageindex,TotalPageSize"); } else { base.Update(modelConfig, "pageindex"); } }