Copy tarifas and promos on user registration
When a new user registers with a referral code, their tarifas and promos are now copied from the referring user. Also refactored Usuario_promo and Usuario_tarifa models to use fillable attributes and improved method formatting. Added Swiper CSS/JS to app layout.
This commit is contained in:
@@ -6,6 +6,8 @@ use App\Http\Controllers\Controller;
|
||||
use App\Models\Role;
|
||||
use App\Models\Saldo;
|
||||
use App\Models\User;
|
||||
use App\Models\Usuario_promo;
|
||||
use App\Models\Usuario_tarifa;
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Illuminate\Auth\Events\Registered;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -42,7 +44,6 @@ class RegisteredUserController extends Controller
|
||||
'password.confirmed' => 'La confirmación de la contraseña no coincide.',
|
||||
'password.min' => 'La contraseña debe tener al menos 8 caracteres.',
|
||||
'referral_code.required' => 'El código de referido es obligatorio.',
|
||||
|
||||
'password.confirmed' => 'Las contraseñas no coinciden.',
|
||||
]);
|
||||
|
||||
@@ -54,15 +55,12 @@ class RegisteredUserController extends Controller
|
||||
// Determinar el rol del nuevo usuario
|
||||
if ($referralUser) {
|
||||
if ($referralUser->rol->nombre === 'super') {
|
||||
// Si el referido es "super", asignar "cliente"
|
||||
$rolCliente = Role::where('nombre', 'cliente')->first();
|
||||
$rol_id = $rolCliente ? $rolCliente->id : null;
|
||||
} else {
|
||||
// Si no es super, tomar el mismo rol del referido
|
||||
$rol_id = $referralUser->rol_id;
|
||||
}
|
||||
} else {
|
||||
// Si no tiene referral_code, asignar rol por defecto (cliente)
|
||||
$rolCliente = Role::where('nombre', 'cliente')->first();
|
||||
$rol_id = $rolCliente ? $rolCliente->id : null;
|
||||
}
|
||||
@@ -75,6 +73,32 @@ class RegisteredUserController extends Controller
|
||||
'parent_id' => $referralUser ? $referralUser->id : null,
|
||||
]);
|
||||
|
||||
if ($referralUser) {
|
||||
// Tarifas
|
||||
$tarifas = $referralUser->usuario_tarifas;
|
||||
foreach ($tarifas as $tarifa) {
|
||||
Usuario_tarifa::create([
|
||||
'usuario_id' => $user->id,
|
||||
'tarifa_id' => $tarifa->tarifa_id,
|
||||
'precio' => $tarifa->precio,
|
||||
'visible' => $tarifa->visible,
|
||||
'utilidad' => $tarifa->utilidad,
|
||||
]);
|
||||
}
|
||||
|
||||
// Promos
|
||||
$promos = $referralUser->usuario_promos;
|
||||
foreach ($promos as $promo) {
|
||||
Usuario_promo::create([
|
||||
'usuario_id' => $user->id,
|
||||
'promocion_id' => $promo->promocion_id,
|
||||
'precio' => $promo->precio,
|
||||
'visible' => $promo->visible,
|
||||
'utilidad' => $promo->utilidad,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Saldo::create([
|
||||
'usuario_id' => $user->id,
|
||||
'valor' => 0,
|
||||
|
||||
Reference in New Issue
Block a user