Commit 5be16eb4 by Francisco Salazar

Modulo de forms independiente de universal3 (cuidado)

parent a26bef0c
......@@ -10,7 +10,7 @@ use Yajra\Datatables\Datatables;
use App\Notifications\WelcomeInterested;
use App\Notifications\NewInterestd;
use App\Notifications\EmailInvalid;
use App\Interested;
use Onestartup\CrmForms\Model\Interested;
use App\User;
use Jenssegers\Agent\Agent;
use Onestartup\CrmForms\Model\InterestedDetail;
......@@ -22,90 +22,37 @@ class CrmFormsController extends Controller
{
public function store(RequestInterested $request)
{
error_log("$request");
$agent = new Agent();
$agent->setUserAgent($request->header('User-Agent'));
$browser = $agent->browser();
$browser_version = $agent->version($browser);
$devise = $agent->device();
$platform = $agent->platform();
$platform_version = $agent->version($platform);
$session_time = $request->session_time;
if ($agent->isMobile()){
$devise_type = "Mobil";
}elseif($agent->isTablet()){
$devise_type = "Tablet";
}elseif($agent->isDesktop()){
$devise_type = "Desktop";
}else{
$devise_type = "Otro";
}
$agent->isMobile();
$agent->isTablet();
$user = User::find(1);
if($request->desc2 == "" && $request->email2 == "hola@onestartup.mx" && strpos($request->email, "@mail.ru") === false){
if (config('crmforms.validate_email')) { //Se activa la opcion de validar emails por API
$url = "https://apps.emaillistverify.com/api/verifyEmail?secret=".env('KEY_VERIFY')."&email=".$request->email;
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', $url);
$respuesta = $res->getBody();
if ( $respuesta == 'ok') { //Si el correo es valido
$interested = Interested::create($request->all());
$interested->notify(new WelcomeInterested());
$user->notify(new NewInterestd($interested));
$interested_details = InterestedDetail::firstOrNew(['interested_id' => $interested->id]);
$interested_details->browser = $browser;
$interested_details->browser_version = $browser_version;
$interested_details->devise = $devise;
$interested_details->platform = $platform;
$interested_details->platform_version = $platform_version;
$interested_details->session_time = $session_time;
$interested_details->devise_type = $devise_type;
$interested_details->save();
} else { // Si el correo no es valido
$user->notify(new EmailInvalid($request->all()));
return redirect()
->back()
->withInput()
->with('fail', 'fail');
}
} else { // No se valida el correo por api, va directo a la bd
$interested = Interested::create($request->all());
$interested->notify(new WelcomeInterested());
$user->notify(new NewInterestd($interested));
$interested_details = InterestedDetail::firstOrNew(['interested_id' => $interested->id]);
$interested_details->browser = $browser;
$interested_details->browser_version = $browser_version;
$interested_details->devise = $devise;
$interested_details->plataform = $platform;
$interested_details->plataform_version = $platform_version;
$interested_details->session_time = $session_time;
$interested_details->devise_type = $devise_type;
$interested_details->save();
}
if(!($request->desc2 == "" && $request->email2 == "hola@onestartup.mx" && strpos($request->email, "@mail.ru") === false)){
return redirect()->back()->withInput();
}
return redirect()
->route('crmforms.redirect', $request->landing)
->with('registrado', 'registrado')
->with('message_success', 'Hemos recibido tu solicitud, en breve nos comunicaremos contigo');
if (config('crmforms.validate_email')) { //Se activa la opcion de validar emails por API
$url = "https://apps.emaillistverify.com/api/verifyEmail?secret=".env('KEY_VERIFY')."&email=".$request->email;
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', $url);
$respuesta = $res->getBody();
if ( $respuesta == 'ok') { //Si el correo es valido
$this->createInterested($request, $user);
} else { // Si el correo no es valido
$user->notify(new EmailInvalid($request->all()));
return redirect()
->back()
->withInput()
->with('fail', 'fail');
}
} else { // No se valida el correo por api, va directo a la bd
$this->createInterested($request, $user);
}
}else{
return redirect()->back();
}
return redirect()
->route('crmforms.redirect', $request->landing)
->with('registrado', 'registrado')
->with('message_success', 'Hemos recibido tu solicitud, en breve nos comunicaremos contigo');
}
public function redirect($landing)
......@@ -128,4 +75,56 @@ class CrmFormsController extends Controller
}
}
private function createInterested($request, $user){
$agent = new Agent();
$agent->setUserAgent($request->header('User-Agent'));
$browser = $agent->browser();
$browser_version = $agent->version($browser);
$devise = $agent->device();
$platform = $agent->platform();
$platform_version = $agent->version($platform);
$session_time = $request->session_time;
if ($agent->isMobile()){
$devise_type = "Mobil";
}elseif($agent->isTablet()){
$devise_type = "Tablet";
}elseif($agent->isDesktop()){
$devise_type = "Desktop";
}else{
$devise_type = "Otro";
}
$agent->isMobile();
$agent->isTablet();
$interested = Interested::create($request->all());
$interested->notify(new WelcomeInterested());
$user->notify(new NewInterestd($interested));
$interested_details = InterestedDetail::firstOrNew(['interested_id' => $interested->id]);
$interested_details->browser = $browser;
$interested_details->browser_version = $browser_version;
$interested_details->devise = $devise;
$interested_details->platform = $platform;
$interested_details->platform_version = $platform_version;
$interested_details->session_time = $session_time;
$interested_details->devise_type = $devise_type;
$interested_details->save();
}
public static function functionName($slug) {
$slug_landing = preg_replace('/[,]|[:]|[.]|[,]|[ ]/','-',$slug);
$slug_landing = str_replace(["â","á","à","ä"],'a',$slug_landing);
$slug_landing = str_replace(["ê","é","è","ë"],'e',$slug_landing);
$slug_landing = str_replace(['í','ì','î','ï'],'i',$slug_landing);
$slug_landing = str_replace(['ó','ò','ô','ö'],'o',$slug_landing);
$slug_landing = str_replace(['ú','ù','û','ü'],'u',$slug_landing);
$slug_landing = str_replace(['ñ'],'n',$slug_landing);
$slug_landing = strtolower($slug_landing);
return $slug_landing;
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateInterestedsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('interesteds', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email');
$table->string('phone')->nullable();
$table->string('landing')->default('Main');
$table->string('origin')->default('ninguno');
$table->string('extra1', 355)->nullable();
$table->string('extra2', 355)->nullable();
$table->string('extra3', 355)->nullable();
$table->string('extra4', 355)->nullable();
$table->string('extra5', 355)->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('interesteds');
}
}
<?php
namespace Onestartup\CrmForms\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
class Interested extends Model
{
use Notifiable;
protected $table = 'interesteds';
protected $fillable = [
'name',
'email',
'phone',
'extra1',
'extra2',
'extra3',
'extra4',
'landing',
'origin'
];
public function tracings()
{
return $this->hasMany('Onestartup\Crm\Tracing', 'interested_id');
}
public function interested_detail(){
return $this->hasOne('Onestartup\CrmForms\Model\InterestedDetail', 'interested_id');
}
}
......@@ -10,6 +10,6 @@ class InterestedDetail extends Model{
protected $fillable = ["interested_id", "browser", "browser_version", "devise", "platform", "platform_version","session_time"];
public function interested(){
return $this->belongsTo('App/Interested', 'interested_id');
return $this->belongsTo('Onestartup\CrmForms\Model\Interested', 'interested_id');
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment