+ Add nano credit demands durations route
This commit is contained in:
parent
5015476aef
commit
5cd3893176
|
@ -65,14 +65,20 @@ class NanoCreditController extends Controller
|
|||
return $this->errorResponse(trans('errors.no_ilink_network'));
|
||||
}
|
||||
|
||||
if (!$config->has_nano_credit)
|
||||
return $this->errorResponse(trans('errors.nano_credit_not_available'));
|
||||
|
||||
$taxes = array_values(array_filter($config->taxes->all(), function ($tax) {
|
||||
return $tax->categorie == 'nano_credit';
|
||||
}));
|
||||
|
||||
$paliers = array_values($config->paliers_config_nano_credits->all());
|
||||
$paliers = array_values(array_filter($config->paliers_config_nano_credits->all(), function ($taux) {
|
||||
return $taux->type == 'nano_credit';
|
||||
}));
|
||||
|
||||
$demande_credit = new UsersDemandesCredit();
|
||||
$demande_credit->fill($request->all());
|
||||
$demande_credit->id_network = $config->id_network;
|
||||
|
||||
// Derniere demande de nano credit
|
||||
$last_demand = UsersDemandesCredit::where('id_user', $request->id_user)->where('etat', 'VALIDE')->first();
|
||||
|
@ -330,15 +336,41 @@ class NanoCreditController extends Controller
|
|||
return $sommeEpargnes - $sommeCredits;
|
||||
}
|
||||
|
||||
public function getDureeMois($id_user)
|
||||
{
|
||||
|
||||
$user = User::findOrFail($id_user);
|
||||
|
||||
$init_country = $user->network->country->id;
|
||||
$result = ConfigWallet::join('networks', 'networks.id', '=', 'configWallet.id_network')
|
||||
->where('networks.country_id', $init_country)->where('configWallet.type', 'ilink')
|
||||
->select('configWallet.id')->first();
|
||||
if ($result) {
|
||||
$config = ConfigWallet::findOrFail($result->id);
|
||||
} else {
|
||||
return $this->
|
||||
errorResponse(trans('errors.no_ilink_network'));
|
||||
}
|
||||
|
||||
if (!$config->has_nano_credit)
|
||||
return $this->errorResponse(trans('errors.nano_credit_not_available'));
|
||||
|
||||
$paliers = array_values(array_filter($config->paliers_config_nano_credits->all(), function ($taux) {
|
||||
return $taux->type == 'nano_credit';
|
||||
}));
|
||||
|
||||
$mois = array_map(function ($palier) {
|
||||
return $palier->duree_mois;
|
||||
}, $paliers);
|
||||
|
||||
return $this->successResponse($mois);
|
||||
}
|
||||
|
||||
// Calculer les frais
|
||||
private function calculateFees(array $paliers, $montant, $duree)
|
||||
{
|
||||
$size = sizeof($paliers);
|
||||
if ($size > 0) {
|
||||
// $mois = array_map(function ($palier) {
|
||||
// return $palier->duree_mois;
|
||||
// },$paliers);
|
||||
|
||||
$palier = null;
|
||||
foreach ($paliers as $p) {
|
||||
if ($p->duree_mois == $duree) {
|
||||
|
|
|
@ -396,7 +396,6 @@ ug.date_creation as date_creation_groupe , ug.createur , ug.sponsor1 , ug.sponso
|
|||
if ($demand) {
|
||||
unset($demand->date_creation);
|
||||
return $this->successResponse($demand);
|
||||
|
||||
} else
|
||||
return $this->errorResponse(trans('errors.model_not_found', ['model' => 'groupValidationDemand']), Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
* @property int $id_user
|
||||
* @property int $id_wallet_agent
|
||||
* @property bool $retrait_cash
|
||||
* @property int id_network
|
||||
* @property Carbon $date_creation
|
||||
*
|
||||
* @package App\Models
|
||||
|
@ -42,7 +43,8 @@ class UsersDemandesCredit extends Model
|
|||
'taxe' => 'float',
|
||||
'id_user' => 'int',
|
||||
'id_wallet_agent' => 'int',
|
||||
'retrait_cash' => 'bool'
|
||||
'retrait_cash' => 'bool',
|
||||
'id_network' => 'int'
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
|
@ -66,6 +68,7 @@ class UsersDemandesCredit extends Model
|
|||
'id_user',
|
||||
'id_wallet_agent',
|
||||
'retrait_cash',
|
||||
'id_network',
|
||||
'date_creation'
|
||||
];
|
||||
}
|
||||
|
|
|
@ -87,5 +87,6 @@ $router->group(['prefix' => '/groups'], function () use ($router) {
|
|||
$router->post('askNanoCredit', 'NanoCreditController@askNanoCredit');
|
||||
$router->post('guaranteeNanoCredit', 'NanoCreditController@cautionnerCredit');
|
||||
$router->post('refundNanoCredit', 'NanoCreditController@rembourserCredit');
|
||||
$router->get('durations/{id_user}', 'NanoCreditController@getDureeMois');
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue