Beispiel #1
0
 public RetailRespProcessor(Amo amo, ProcessQueue processQueue, CancellationToken token, int entityNumber, Log log, Type type, int oldResp, int modResp)
 {
     _leadRepo     = amo.GetAccountById(28395871).GetRepo <Lead>();
     _contRepo     = amo.GetAccountById(28395871).GetRepo <Contact>();
     _processQueue = processQueue;
     _token        = token;
     _entityNumber = entityNumber;
     _log          = log;
     _type         = type;
     _oldResp      = oldResp;
     _modResp      = modResp;
 }
Beispiel #2
0
        public SendToRetProcessor(Amo amo, Log log, ProcessQueue processQueue, int leadNumber, CancellationToken token)
        {
            _log          = log;
            _leadNumber   = leadNumber;
            _processQueue = processQueue;
            _token        = token;

            _leadRepo = amo.GetAccountById(28395871).GetRepo <Lead>();
            _contRepo = amo.GetAccountById(28395871).GetRepo <Contact>();

            _sourceLeadRepo = amo.GetAccountById(19453687).GetRepo <Lead>();
            _sourceContRepo = amo.GetAccountById(19453687).GetRepo <Contact>();
        }
Beispiel #3
0
        public IActionResult Get()
        {
            //var repo = _amo.GetAccountById(29490250).GetRepo<Lead>();
            var repo = _amo.GetAccountById(28395871).GetRepo <Lead>();

            //var repo = _amo.GetAccountById(19453687).GetRepo<Lead>();

            return(Ok(JsonConvert.SerializeObject(repo.GetTags(), Formatting.Indented, new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            })));

            int i = 0;

            while (i < 12)
            {
                i++;
                UberLead lead = new() {
                    leadId   = i,
                    leadName = $"Новая сделка {i}",
                    leadUri  = $"https://mzpoeducationsale.amocrm.ru/leads/detail/{i}"
                };

                _uber.AddToQueue(lead);

                //Task.Delay(TimeSpan.FromSeconds(1)).Wait();
            }

            return(Ok("𓅮 𓃟 𓏵 𓀠𓀡"));
        }
Beispiel #4
0
        public List <Amo_id> Run()
        {
            try
            {
                if (_client1C.amo_ids is not null)
                {
                    foreach (var c in _client1C.amo_ids)
                    {
                        if (!_filter.CheckEntityIsValid(c.entity_id))
                        {
                            continue;
                        }

                        UpdateContactInAmo(_client1C, _amo.GetAccountById(c.account_id).GetRepo <Contact>(), c.entity_id, c.account_id, _filter);

                        _log.Add($"Updated contact {c.entity_id} in amo {c.account_id}.");
                    }
                }
            }
            catch (Exception e)
            {
                _log.Add($"Unable to update contact in amo from 1C: {e.Message}");
            }

            return(_client1C.amo_ids);
        }
Beispiel #5
0
        public Guid Run()
        {
            try
            {
                var compRepo = _amo.GetAccountById(_amo_acc).GetRepo <Company>();

                #region Checking if company exists in 1C and updating if possible
                Guid company_id_1C = default;

                Company company = compRepo.GetById(_companyId);

                if (company.custom_fields_values is not null &&
                    company.custom_fields_values.Any(x => x.field_id == FieldLists.Companies[_amo_acc]["company_id_1C"]) &&
                    Guid.TryParse((string)company.custom_fields_values.First(x => x.field_id == FieldLists.Companies[_amo_acc]["company_id_1C"]).values[0].value, out company_id_1C))
                {
                    UpdateCompanyIn1C(company, company_id_1C, _amo_acc, _repo1C);
                    _log.Add($"Updated company in 1C {company_id_1C}.");
                }
                #endregion

                return(company_id_1C);
            }
            catch (Exception e)
            {
                _log.Add($"Unable to update company {_companyId} in 1C: {e.Message}");
                return(default);
Beispiel #6
0
        public List <Amo_id> Run()
        {
            try
            {
                int amo_acc = 28395871;
                if (_lead1C.is_corporate)
                {
                    amo_acc = 19453687;
                }
                if (_lead1C.organization == "ООО «Первый Профессиональный Институт Эстетики»")
                {
                    amo_acc = 29490250;
                }

                var leadRepo = _amo.GetAccountById(amo_acc).GetRepo <Lead>();

                if (_lead1C.amo_ids.Any(x => x.account_id == amo_acc))
                {
                    UpdateLeadInAmo(_lead1C, leadRepo, _lead1C.amo_ids.First().entity_id, amo_acc, _filter);
                }

                _log.Add($"Updated lead {_lead1C.amo_ids.First().entity_id} in amo {amo_acc}.");
            }
            catch (Exception e)
            {
                _log.Add($"Unable to update lead {_lead1C.lead_id_1C} in amo: {e.Message}");
            }

            return(_lead1C.amo_ids);
        }
Beispiel #7
0
        public Guid Run()
        {
            try
            {
                var leadRepo = _amo.GetAccountById(_amo_acc).GetRepo <Lead>();

                var lead = leadRepo.GetById(_leadId);

                if (lead is null ||
                    lead == default)
                {
                    throw new Exception("No lead returned from amo.");
                }

                Guid lead_id_1C = default;

                if (lead.custom_fields_values is not null &&
                    lead.custom_fields_values.Any(x => x.field_id == FieldLists.Leads[_amo_acc]["lead_id_1C"]) &&
                    Guid.TryParse((string)lead.custom_fields_values.First(x => x.field_id == FieldLists.Leads[_amo_acc]["lead_id_1C"]).values[0].value, out lead_id_1C))
                {
                    UpdateLeadIn1C(_amo, _log, lead, lead_id_1C, _amo_acc, _cred1C);
                    _log.Add($"Updated lead in 1C {lead_id_1C}.");
                }

                return(lead_id_1C);
            }
            catch (Exception e)
            {
                _log.Add($"Unable to update lead {_leadId} in 1C: {e.Message}");
                return(default);
Beispiel #8
0
        public Course1C Run(Guid course_id)
        {
            var course1C = _repo1C.GetCourse(course_id);

            if (course1C.amo_ids is not null &&
                course1C.amo_ids.Count == 3)
            {
                return(course1C);
            }

            try
            {
                //amo_ids.AddRange(new CreateOrUpdateAmoCourse(course1C, _amo, _log).Run());
                course1C.amo_ids.Add(CreateCourseInAmo(course1C, _amo.GetAccountById(29490250).GetRepo <Lead>(), 29490250));

                if (course1C.amo_ids.Count < 3)
                {
                    throw new Exception("Created less than 3 courses in amoCRM.");
                }
            }
            catch (Exception e) { throw new Exception($"Unable to create courses in amoCRM: {e}"); }

            try { _repo1C.UpdateCourse(course1C); }
            catch (Exception e) { throw new Exception($"Unable to save amo_ids in 1C: {e}"); }

            return(course1C);
        }
Beispiel #9
0
 public RetailCourseProcessor(Amo amo, ProcessQueue processQueue, CancellationToken token, int leadNumber, Log log)
 {
     _repo         = amo.GetAccountById(28395871).GetRepo <Lead>();
     _processQueue = processQueue;
     _token        = token;
     _leadNumber   = leadNumber;
     _log          = log;
 }
Beispiel #10
0
 public CreateOrUpdateAmoCompany(Company1C company1C, Amo amo, Log log, RecentlyUpdatedEntityFilter filter)
 {
     _amo       = amo;
     _log       = log;
     _company1C = company1C;
     _compRepo  = _amo.GetAccountById(19453687).GetRepo <Company>();
     _amo_acc   = 19453687;
     _filter    = filter;
 }
Beispiel #11
0
        public IActionResult LeadProcessor(string id)                                                                                                      //Передаём вручную сделку в процессор (в дальнейшем заменить на POST)
        {
            if (!Int32.TryParse(id, out int leadNumber))
            {
                return(BadRequest("Incorrect lead number."));
            }

            Task task;
            var  acc = _amo.GetAccountById(28395871);
            CancellationTokenSource cts           = new();
            CancellationToken       token         = cts.Token;
            Lazy <ILeadProcessor>   leadProcessor = new(() =>                                                                                   //Создаём экземпляр процессора сделки
                                                        new InitialLeadProcessor(leadNumber, acc, _amo, _gSheets, _processQueue, _log, token));

            task = Task.Run(() => leadProcessor.Value.Run());
            _processQueue.AddTask(task, cts, $"initial_{leadNumber}", acc.name, "WebHook");                                                 //Запускаем и добавляем в очередь
            return(Ok());
        }
Beispiel #12
0
        public RetailPaidProcessor(Amo amo, Log log, ProcessQueue processQueue, CancellationToken token, GSheets gSheets, string taskName, string phone, string email, string price)
        {
            _log          = log;
            _processQueue = processQueue;
            _token        = token;
            _taskName     = taskName;
            _phone        = phone.Trim().Replace("+", "").Replace("-", "").Replace(" ", "").Replace("(", "").Replace(")", "");
            _email        = email.Trim().Replace(" ", "");
            int.TryParse(price, out _price);

            var acc = amo.GetAccountById(28395871);

            _contRepo = acc.GetRepo <Contact>();
        }
Beispiel #13
0
        public SiteFormRetailProcessor(Amo amo, Log log, FormRequest formRequest, ProcessQueue processQueue, CancellationToken token, GSheets gSheets, string taskName)
        {
            _amo          = amo;
            _log          = log;
            _formRequest  = formRequest;
            _processQueue = processQueue;
            _token        = token;
            _gSheets      = gSheets;
            _taskname     = taskName;

            var acc = amo.GetAccountById(28395871);

            _leadRepo = acc.GetRepo <Lead>();
            _contRepo = acc.GetRepo <Contact>();
        }
Beispiel #14
0
        public ConferencePaidProcessor(Amo amo, Log log, ProcessQueue processQueue, CancellationToken token, GSheets gSheets, string taskName, string phone, string email)
        {
            _amo          = amo;
            _log          = log;
            _processQueue = processQueue;
            _token        = token;
            _gSheets      = gSheets;
            _taskName     = taskName;
            _phone        = phone.Trim().Replace("+", "").Replace("-", "").Replace(" ", "").Replace("(", "").Replace(")", "");
            _email        = email.Trim().Replace(" ", "");

            var acc = amo.GetAccountById(19453687);

            _leadRepo = acc.GetRepo <Lead>();
            _contRepo = acc.GetRepo <Contact>();
            _compRepo = acc.GetRepo <Company>();
        }
Beispiel #15
0
        public List <Amo_id> Run()
        {
            try
            {
                if (_course1C.amo_ids is not null)
                {
                    foreach (var a in _course1C.amo_ids)
                    {
                        UpdateCourseInAmo(_course1C, _amo.GetAccountById(a.account_id).GetRepo <Lead>(), a.entity_id, a.account_id);

                        _log.Add($"Updated course {_course1C.short_name} in amo {a.account_id}.");
                    }
                }
            }
            catch (Exception e)
            {
                _log.Add($"Unable to update course in amo: {e.Message}");
            }

            return(_course1C.amo_ids);
        }
Beispiel #16
0
        public IActionResult UpdateClient1C()
        {
            var col = Request.Form;

            if (!col.Any(x => x.Value.ToString() == "client_id_1C"))
            {
                return(Ok());
            }

            AmoAccount acc;

            if (!Int32.TryParse(col["account[id]"], out int accNumber))
            {
                return(BadRequest("Incorrect account number."));
            }

            try { acc = _amo.GetAccountById(accNumber); }
            catch (Exception e) { _log.Add(e.Message); return(Ok()); }

            if (!col.ContainsKey("contacts[update][0][id]"))
            {
                return(BadRequest("Unexpected request."));
            }
            if (!Int32.TryParse(col["contacts[update][0][id]"], out int contactNumber))
            {
                return(BadRequest("Incorrect contact number."));
            }

            if (!_filter.CheckEntityIsValid(contactNumber))
            {
                return(Ok());
            }

            var task = Task.Run(() => new Update1CClient(_amo, _log, contactNumber, accNumber, _cred1C, _filter).Run());

            return(Ok());
        }
Beispiel #17
0
        public Guid Run()
        {
            try
            {
                #region Getting contact
                var contRepo = _amo.GetAccountById(_amo_acc).GetRepo <Contact>();

                var contact = contRepo.GetById(_contactId);

                if (contact.custom_fields_values is null)
                {
                    throw new Exception($"No suitable contacts to add to 1C at contact {_contactId}");
                }
                #endregion

                #region Check for UIDs
                Guid client_id_1C = default;

                if (contact.custom_fields_values.Any(x => x.field_id == FieldLists.Contacts[_amo_acc]["client_id_1C"]) &&
                    Guid.TryParse((string)contact.custom_fields_values.First(x => x.field_id == FieldLists.Contacts[_amo_acc]["client_id_1C"]).values[0].value, out client_id_1C))
                {
                    var client1C = UpdateClientIn1C(client_id_1C, contact, _amo_acc, _repo1C);
                    _log.Add($"Updated client in 1C {client_id_1C}.");

                    _filter.AddEntity(_contactId);

                    new UpdateAmoContact(client1C, _amo, _log, _filter).Run();
                }
                #endregion

                return(client_id_1C);
            }
            catch (Exception e)
            {
                _log.Add($"Unable to update client in 1C from contact {_contactId}: {e.Message}");
                return(default);
Beispiel #18
0
 public LeadTasksController(Amo amo)
 {
     _amo      = amo;
     _leadRepo = amo.GetAccountById(28395871).GetRepo <Lead>();
 }
Beispiel #19
0
        public List <Amo_id> Run()
        {
            if (_lead1C.amo_ids is null)
            {
                _lead1C.amo_ids = new();
            }

            try
            {
                int amo_acc = 28395871;
                if (_lead1C.is_corporate)
                {
                    amo_acc = 19453687;
                }
                if (_lead1C.organization == "ООО «Первый Профессиональный Институт Эстетики»")
                {
                    amo_acc = 29490250;
                }

                var leadRepo = _amo.GetAccountById(amo_acc).GetRepo <Lead>();

                #region Checking if lead already linked to entity an updating if possible
                if (_lead1C.amo_ids.Any(x => x.account_id == amo_acc))
                {
                    try
                    {
                        UpdateLeadInAmo(_lead1C, leadRepo, _lead1C.amo_ids.First().entity_id, amo_acc, _filter);

                        _log.Add($"Updated lead {_lead1C.amo_ids.First().entity_id} in amo {amo_acc}.");

                        return(_lead1C.amo_ids);
                    }
                    catch (Exception e)
                    {
                        _log.Add($"Unable to update existing lead {_lead1C.amo_ids.First().entity_id} in amo. Creating new.");
                    }
                }
                #endregion

                #region Getting connected entitites ids
                Client1C  client1C  = new ClientRepository(_cred1C).GetClient((Guid)_lead1C.client_id_1C);
                Course1C  course1C  = new CourseRepository(_cred1C).GetCourse((Guid)_lead1C.product_id_1C);
                Company1C company1C = null;
                if (_lead1C.is_corporate)
                {
                    company1C = new CompanyRepository(_cred1C).GetCompany((Guid)_lead1C.company_id_1C);
                }

                var contact_id = 0;
                var course_id  = 0;
                var company_id = 0;

                if (client1C.amo_ids is not null &&
                    client1C.amo_ids.Any(x => x.account_id == amo_acc))
                {
                    contact_id = client1C.amo_ids.First(x => x.account_id == amo_acc).entity_id;
                }

                if (course1C.amo_ids is not null &&
                    course1C.amo_ids.Any(x => x.account_id == amo_acc))
                {
                    course_id = course1C.amo_ids.First(x => x.account_id == amo_acc).entity_id;
                }

                if (company1C is not null &&
                    company1C.amo_ids is not null &&
                    company1C.amo_ids.Any(x => x.account_id == amo_acc))
                {
                    company_id = company1C.amo_ids.First(x => x.account_id == amo_acc).entity_id;
                }
                #endregion

                #region Creating new lead
                var lead_id = CreateLeadInAmo(_lead1C, leadRepo, amo_acc, contact_id, course_id, company_id, _filter);
                _lead1C.amo_ids.Add(new()
                {
                    account_id = amo_acc,
                    entity_id  = lead_id
                });

                _log.Add($"Created lead {lead_id} in amo {amo_acc}.");
                #endregion
            }
            catch (Exception e)
            {
                _log.Add($"Unable to create or update lead {_lead1C.lead_id_1C} in amo: {e.Message}");
            }

            return(_lead1C.amo_ids);
        }
Beispiel #20
0
        public Guid Run()
        {
            try
            {
                var compRepo = _amo.GetAccountById(_amo_acc).GetRepo <Company>();

                #region Retrieving company
                Lead lead = _amo.GetAccountById(_amo_acc).GetRepo <Lead>().GetById(_leadId);

                if (lead._embedded is null ||
                    lead._embedded.companies is null ||
                    !lead._embedded.companies.Any())
                {
                    throw new Exception($"Unable to update company in 1C, no company linked to lead {_leadId}.");
                }

                Company company = compRepo.GetById(lead._embedded.companies.First().id);
                #endregion

                #region Checking if company exists in 1C and updating if possible
                if (company.custom_fields_values is not null &&
                    company.custom_fields_values.Any(x => x.field_id == FieldLists.Companies[_amo_acc]["company_id_1C"]) &&
                    Guid.TryParse((string)company.custom_fields_values.First(x => x.field_id == FieldLists.Companies[_amo_acc]["company_id_1C"]).values[0].value, out Guid company_id_1C))
                {
                    UpdateCompanyIn1C(company, company_id_1C, _amo_acc, _repo1C);

                    _log.Add($"Updated company in 1C {company_id_1C}.");

                    return(company_id_1C);
                }
                #endregion

                #region Creating company in 1C
                var result = CreateCompanyIn1C(company, _amo_acc, _repo1C);

                Company updatedCompany = new()
                {
                    id = company.id,
                    custom_fields_values = new()
                    {
                        new()
                        {
                            field_id = FieldLists.Companies[_amo_acc]["company_id_1C"],
                            values   = new Custom_fields_value.Values[] { new Custom_fields_value.Values()
                                                                          {
                                                                              value = result.ToString("D")
                                                                          } }
                        }
                    }
                };

                _log.Add($"Created company in 1C {result}.");
                #endregion

                _filter.AddEntity(company.id);
                compRepo.Save(updatedCompany);

                return(result);
            }
            catch (Exception e)
            {
                _log.Add($"Unable to create or update company from lead {_leadId} in 1C: {e.Message}");
                return(default);