mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
copiada la rama presu_cliente_v2 en esta para poder hacer el merge al main
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Tarifas;
|
||||
|
||||
class TarifaEnvioModel extends \App\Models\BaseModel
|
||||
@ -17,7 +18,7 @@ class TarifaEnvioModel extends \App\Models\BaseModel
|
||||
1 => "t2.nombre",
|
||||
];
|
||||
|
||||
protected $allowedFields = ["pais_id", "nombre","deleted_at","is_deleted"];
|
||||
protected $allowedFields = ["pais_id", "nombre", "code", "comment", "deleted_at", "is_deleted"];
|
||||
protected $returnType = "App\Entities\Tarifas\TarifaEnvioEntity";
|
||||
|
||||
protected $useTimestamps = true;
|
||||
@ -73,7 +74,7 @@ class TarifaEnvioModel extends \App\Models\BaseModel
|
||||
*/
|
||||
public function getResource(string $search = "")
|
||||
{
|
||||
$builder = $this->db->table($this->table . " t1")->select("t1.id as id, t1.nombre AS nombre, t2.nombre AS pais_id");
|
||||
$builder = $this->db->table($this->table . " t1")->select("t1.id as id, t1.nombre AS nombre,t1.code AS code, t2.nombre AS pais_id");
|
||||
$builder->join("lg_paises t2", "t1.pais_id = t2.id", "left");
|
||||
|
||||
//JJO
|
||||
@ -82,43 +83,44 @@ class TarifaEnvioModel extends \App\Models\BaseModel
|
||||
return empty($search)
|
||||
? $builder
|
||||
: $builder
|
||||
->groupStart()
|
||||
->like("t1.nombre", $search)
|
||||
->orLike("t2.id", $search)
|
||||
->orLike("t1.pais_id", $search)
|
||||
->orLike("t1.nombre", $search)
|
||||
->orLike("t2.nombre", $search)
|
||||
->groupEnd();
|
||||
->groupStart()
|
||||
->like("t1.nombre", $search)
|
||||
->orLike("t2.code", $search)
|
||||
->orLike("t2.id", $search)
|
||||
->orLike("t1.pais_id", $search)
|
||||
->orLike("t1.nombre", $search)
|
||||
->orLike("t2.nombre", $search)
|
||||
->groupEnd();
|
||||
}
|
||||
|
||||
public function getTarifaEnvio($paisId, string $cp, $peso, $tipo_envio){
|
||||
public function getTarifaEnvio($paisId, string $cp, $peso, $tipo_envio)
|
||||
{
|
||||
// Si el pais es españa se tienen que tener en cuenta los postales
|
||||
// Se busca primero la tarifa a la que corresponde
|
||||
$builder = $this->db->table($this->table . " t1")
|
||||
->select("t1.id AS tarifa_envio_id, t2.importe_fijo as importe_fijo")
|
||||
->join("tarifas_envios_zonas t2", "t1.id = t2.tarifa_envio_id")
|
||||
->where("t1.pais_id", $paisId)
|
||||
->where("t1.is_deleted", 0)
|
||||
->where("t2.is_deleted", 0);
|
||||
|
||||
if($paisId == 1) {// España
|
||||
->select("t1.id AS tarifa_envio_id, t2.importe_fijo as importe_fijo")
|
||||
->join("tarifas_envios_zonas t2", "t1.id = t2.tarifa_envio_id")
|
||||
->where("t1.pais_id", $paisId)
|
||||
->where("t1.is_deleted", 0)
|
||||
->where("t2.is_deleted", 0);
|
||||
|
||||
if ($paisId == 1) { // España
|
||||
$builder->where("CAST(t2.cp_inicial AS UNSIGNED)<=", intval($cp))
|
||||
->where("CAST(t2.cp_final AS UNSIGNED) >=", intval($cp));
|
||||
->where("CAST(t2.cp_final AS UNSIGNED) >=", intval($cp));
|
||||
}
|
||||
$tarifas = $builder->get()->getResultObject();
|
||||
|
||||
$resultado = [];
|
||||
|
||||
|
||||
$model = model('App\Models\Tarifas\TarifaEnvioPrecioModel');
|
||||
foreach($tarifas as $tarifa){
|
||||
foreach ($tarifas as $tarifa) {
|
||||
$precio_tarifas = $model->getEnvioPrecio($tarifa->tarifa_envio_id, $peso, $tipo_envio);
|
||||
foreach($precio_tarifas as $precio_tarifa){
|
||||
foreach ($precio_tarifas as $precio_tarifa) {
|
||||
$precio_tarifa->importe_fijo = $tarifa->importe_fijo;
|
||||
array_push($resultado, $precio_tarifa);
|
||||
}
|
||||
}
|
||||
|
||||
return $resultado;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user