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"); } }
public ActionResult SaveData([FromBody] FormDataModel model) { bool result = true; using (var trans = _ctx.Database.BeginTransaction()) { try { string createdBy = _ctx.AspNetUsers.Where(x => x.DeletedFlag == false && x.CompanyCode == 1).Select(x => x.Id).FirstOrDefault(); int processTypeId = _ctx.CrmProcesse.Select(x => x.Id).FirstOrDefault(); int actionId = _ctx.CrmActions.Where(x => x.ProcessCode == processTypeId && x.LeadStartFlag == true).Select(x => x.Id).FirstOrDefault(); List <CrmLeads> leadsList = new List <CrmLeads>(); int LeadId = _ctx.CrmLeads.Select(x => x.Id).ToList().Max() + 1; int FollowupsId = _ctx.CrmProcessFollowUps.Select(x => x.Id).ToList().Max() + 1; foreach (var item in model.FormData) { if (string.IsNullOrEmpty(item.LeadSubject)) { continue; } // var findLead=_ctx.CrmLeads.Where(x=>x.Subject.ToLowerInvariant()==item.LeadSubject.ToLowerInvariant() &&x.CustomerId) var cus = _ctx.CrmCustomers.FirstOrDefault(x => x.Email == item.CustomerEmail && x.MobileNo == item.CustomerPhone && x.DeletedFlag == false); var findLead = _ctx.CrmLeads.Where(x => x.Subject.ToLowerInvariant() == item.LeadSubject.ToLowerInvariant() && x.CustomerId.ToString() == cus.CustomerId).FirstOrDefault(); if (findLead != null) { continue; } if (cus == null) { cus = new CrmCustomers(); cus.CreatedBy = createdBy; cus.FirstName = item.CustomerName; cus.MobileNo = item.CustomerPhone; cus.Email = item.CustomerEmail; cus.DeletedFlag = false; cus.CreatedDate = DateTime.Now; cus.TagFlag = false; cus.CompanyCode = 1; cus.LastKnownMartialStatus = true; InsertCustomer(cus); } var leads = new CrmLeads(); leads.Id = LeadId; leads.CreatedBy = createdBy; leads.CreatedDate = DateTime.Now; leads.DeletedFlag = false; leads.CustomerId = cus.Id; leads.CompanyCode = 1; leads.ProcessTypeId = processTypeId; leads.LeadValue = "0"; leads.AgentId = Convert.ToInt32(model.AgentId); leads.Rating = Convert.ToInt32(model.RatingId); leads.ProductId = Convert.ToInt32(model.ProductId); leads.Description = item.LeadDescription; leads.CompletionDate = DateTime.Now; leads.LeadDate = DateTime.Now; leads.Subject = item.LeadSubject; leads.CrmProcessFollowUps = new List <CrmProcessFollowUps>() { new CrmProcessFollowUps() { Id = FollowupsId, CreatedBy = createdBy, CreatedDate = DateTime.Now, DeletedFlag = false, ProcessNo = 1, LeadNo = LeadId, ProcessTypeId = processTypeId, AgentId = Convert.ToInt32(model.AgentId), StartDate = DateTime.Now, EstdValue = 0, CompanyCode = 1, ActionId = actionId } }; leadsList.Add(leads); LeadId++; FollowupsId++; } _ctx.CrmLeads.AddRange(leadsList); _ctx.SaveChanges(); trans.Commit(); } catch (Exception ex) { trans.Rollback(); throw; } } return(Json(result)); }