コード例 #1
0
        public static LeadEntry ManageLeadFromAction(ActionModel model)
        {
            CCSubmitDirect db = model.Database;

            if (db == null)
            {
                db = CCSubmitDirect.Instance;
            }

            int?      leadid    = db.LoadInt("SELECT leadID FROM [].tm_lead_action WHERE actionid=" + model.ActionID);
            LeadEntry leadEntry = null;

            if (leadid.HasValue)
            {
                // this action has valid lead, so we update values

                leadEntry = new LeadEntry(leadid.Value, db);
                leadEntry.CheckValue("first_name", model.FirstName);
                leadEntry.CheckValue("last_name", model.LastName);
                leadEntry.CheckValue("msisdn", model.Msisdn);
                leadEntry.CheckValue("email", model.Email);
                leadEntry.CheckValue("address", model.Address);
                leadEntry.CheckValue("zip", model.Zip);
                leadEntry.CheckValue("country", model.Country);
                leadEntry.CheckValue("city", model.City);
            }
            else
            {
                // this action does not have valid lead, so we need to create/find new one
                // we try to find it by email, msisdn
                leadid = LeadManager.GetLeadID(model.Msisdn, model.Email, db);
                if (leadid.HasValue)
                {
                    // if we find it, we try to update values

                    leadEntry = new LeadEntry(leadid.Value, db);
                    leadEntry.CheckValue("first_name", model.FirstName);
                    leadEntry.CheckValue("last_name", model.LastName);
                    leadEntry.CheckValue("address", model.Address);
                    leadEntry.CheckValue("email", model.Email);
                    leadEntry.CheckValue("zip", model.Zip);
                    leadEntry.CheckValue("country", model.Country);
                    leadEntry.CheckValue("city", model.City);
                    leadEntry.CheckValue("msisdn", model.Msisdn);
                    leadEntry.UpdateSql += "actions_count=actions_count+1,";
                }
                else
                {
                    // if not, we create new one
                    leadid    = CreateLead(model.Msisdn, model.Email, model.FirstName, model.LastName, model.Country, model.Address, model.City, model.Zip, model.device_model, model.carrier, model.device_mf, model.device_os, 1);
                    leadEntry = new LeadEntry(leadid.Value, db);
                }

                db.Transactional.Execute("UPDATE [].tm_lead_action SET leadid={0} WHERE actionid={1}", leadid.Value, model.ActionID);
            }

            leadEntry.FinishUpdateSql();
            return(leadEntry);
        }
コード例 #2
0
        public static int?ExecuteActionImplementation(ActionModel model)
        {
            if (model.ActionID == -1)
            {
                int?actionID = Create(model);
                if (!actionID.HasValue)
                {
                    return(null);
                }

                model.ActionID = actionID.Value;
            }

            DirectContainer dc        = model.Database.LoadContainer("SELECT * FROM [].tm_lead_action WHERE actionid=" + model.ActionID);
            LeadEntry       leadEntry = LeadManager.ManageLeadFromAction(model);

            if ((model.Event == ActionModelEvent.Redirection || model.Event == ActionModelEvent.InputEmail) && !dc.GetBoolean("input_redirect"))
            {
                ActionManager.Update(model, "input_redirect", "1", dc);
            }
            if (model.Event == ActionModelEvent.Create)
            {
                ActionManager.Update(model, "input_redirect", "1", dc);
            }
            if ((model.Event == ActionModelEvent.InputEmail && !dc.GetBoolean("input_email")) || (dc.GetBoolean("input_email") == false && !string.IsNullOrEmpty(leadEntry.Container.GetString("email"))))
            {
                ActionManager.Update(model, "input_email", "1", dc);
            }
            if ((model.Event == ActionModelEvent.InputContact && !dc.GetBoolean("input_contact")) || (dc.GetBoolean("input_contact") == false && !string.IsNullOrEmpty(leadEntry.Container.GetString("first_name")) && !string.IsNullOrEmpty(leadEntry.Container.GetString("last_name"))))
            {
                ActionManager.Update(model, "input_contact", "1", dc);
            }
            if (model.Event == ActionModelEvent.Subscribe)
            {
                ActionManager.Update(model, "has_subscription", "1", dc);
            }
            if (model.Event == ActionModelEvent.Chargeback)
            {
                ActionManager.Update(model, "has_chargeback", "1", dc);
            }
            if (model.Event == ActionModelEvent.Refund)
            {
                ActionManager.Update(model, "has_refund", "1", dc);
            }
            if (model.Event == ActionModelEvent.Charge)
            {
                ActionManager.Update(model, "times_charged", "++", dc);
            }
            if (model.Event == ActionModelEvent.Upsell)
            {
                ActionManager.Update(model, "times_upsell", "++", dc);
            }
            if (model.Event == ActionModelEvent.EndFlow)
            {
                ActionManager.Update(model, "provider_redirection", model.ProviderRedirection, dc);
                ActionManager.Update(model, "has_redirectedToProvider", "1", dc);
            }

            if (model.Service != ActionService.Default && (!dc.GetInt("serviceid").HasValue || (int)model.Service != dc.GetInt("serviceid").Value))
            {
                ActionManager.Update(model, "serviceid", ((int)model.Service).ToString(), dc);
            }
            if (!string.IsNullOrEmpty(model.ClickID) && !dc.GetString("clickid").Equals(model.ClickID))
            {
                ActionManager.Update(model, "clickid", model.ClickID, dc);
            }
            if (model.AffID.HasValue && (!dc.GetInt("affid").HasValue || (dc.GetInt("affid").HasValue&& model.AffID.Value != dc.GetInt("affid").Value)))
            {
                ActionManager.Update(model, "affid", model.AffID.ToString(), dc);
            }
            if (!string.IsNullOrEmpty(model.PubID) && !dc.GetString("pubid").Equals(model.PubID))
            {
                ActionManager.Update(model, "pubid", model.PubID, dc, true);
            }
            if (!string.IsNullOrEmpty(model.LanderUrl) && (string.IsNullOrEmpty(dc.GetString("lander_url")) || !dc.GetString("lander_url").Equals(model.LanderUrl)))
            {
                ActionManager.Update(model, "lander_url", model.LanderUrl, dc, true);
            }

            int?landerID = CCSubmitCacheManager.GetLanderID(model.LanderName, model.Database);

            if (landerID.HasValue && dc.GetInt("landerid").HasValue&& dc.GetInt("landerid").Value != landerID.Value)
            {
                ActionManager.Update(model, "landerid", landerID.Value.ToString(), dc);
            }

            model.SQLUpdateQuery = "UPDATE [].tm_lead_action SET " + model.SQLUpdateQuery + " updated=CURRENT_TIMESTAMP WHERE actionid=" + model.ActionID + ";";
            model.Database.Transactional.Execute(model.SQLUpdateQuery);
            model.Database.Transactional.Run();

            return(model.ActionID);
        }