+ 10 Last transactions for wallet
This commit is contained in:
parent
e3046e4bee
commit
71b934ee24
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\AgentPlus;
|
||||||
|
use App\Models\DemandeCredit;
|
||||||
|
use App\Models\Wallet;
|
||||||
|
use App\Models\WalletAgent;
|
||||||
|
use App\Traits\ApiResponser;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class CreditController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponser;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new controller instance.
|
||||||
|
*a
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
public function treatDemand($id_demand){
|
||||||
|
$demand = DemandeCredit::where('id',$id_demand)->firstOrFail();
|
||||||
|
if($demand->status == 1)
|
||||||
|
return $this->errorResponse('Demande deja traitée',Response::HTTP_BAD_REQUEST);
|
||||||
|
|
||||||
|
$parrain = AgentPlus::where('code_membre',$demand->code_parrain)->firstOrFail();
|
||||||
|
|
||||||
|
$walletAgentParrain = WalletAgent::where('agent_id',$parrain->id)->firstOrFail();
|
||||||
|
|
||||||
|
$walletAgent = Wallet::where('id_networkAgent',$demand->network_agent_id)->firstOrFail();
|
||||||
|
$walletParrain = Wallet::findOrFail($walletAgentParrain->wallet_id);
|
||||||
|
|
||||||
|
if($walletParrain->balance_princ < $demand->montant)
|
||||||
|
return $this->errorResponse('Solde principal du parrain inférieur au montant de la demande',Response::HTTP_BAD_REQUEST);
|
||||||
|
|
||||||
|
$walletAgent->balance_princ += $demand->montant;
|
||||||
|
$walletParrain->balance_princ -= $demand->montant;
|
||||||
|
|
||||||
|
DB::update('UPDATE demandeCredits SET status = 1 WHERE ( id = ? );',[$demand->id]);
|
||||||
|
$walletAgent->save();
|
||||||
|
$walletParrain->save();
|
||||||
|
return $this->successResponse($walletAgent);
|
||||||
|
}
|
||||||
|
}
|
|
@ -146,4 +146,10 @@ class TransactionController extends Controller
|
||||||
$transaction->save();
|
$transaction->save();
|
||||||
return $this->successResponse($walletAgent);
|
return $this->successResponse($walletAgent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function lastTransactions($id_wallet){
|
||||||
|
$transactions = WalletTransaction::where('id_wallet',$id_wallet)->orderBy('date','desc')->limit(10)
|
||||||
|
->get(['id', 'montant' ,'numCarte' ,'commission_ag', 'type' ,'date']);
|
||||||
|
return $this->successResponse($transactions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,62 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Reliese Model.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class DemandeCredit
|
||||||
|
*
|
||||||
|
* @property string $reseau
|
||||||
|
* @property int $id
|
||||||
|
* @property float $montant
|
||||||
|
* @property int $network_agent_id
|
||||||
|
* @property Carbon $date_creation
|
||||||
|
* @property Carbon $date_modification
|
||||||
|
* @property int $status
|
||||||
|
* @property string $phone
|
||||||
|
* @property string $code_membre
|
||||||
|
* @property string $code_parrain
|
||||||
|
* @property string $category
|
||||||
|
* @property string $name
|
||||||
|
*
|
||||||
|
* @package App\Models
|
||||||
|
*/
|
||||||
|
class DemandeCredit extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'demande_credit';
|
||||||
|
public $incrementing = false;
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
protected $casts = [
|
||||||
|
'id' => 'int',
|
||||||
|
'montant' => 'float',
|
||||||
|
'network_agent_id'=>'int',
|
||||||
|
'status' => 'int'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $dates = [
|
||||||
|
'date_creation',
|
||||||
|
'date_modification'
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'reseau',
|
||||||
|
'id',
|
||||||
|
'montant',
|
||||||
|
'network_agent_id',
|
||||||
|
'date_creation',
|
||||||
|
'date_modification',
|
||||||
|
'status',
|
||||||
|
'phone',
|
||||||
|
'code_membre',
|
||||||
|
'code_parrain',
|
||||||
|
'category',
|
||||||
|
'name'
|
||||||
|
];
|
||||||
|
}
|
|
@ -15,7 +15,17 @@
|
||||||
// return $router->app->version();
|
// return $router->app->version();
|
||||||
//});
|
//});
|
||||||
|
|
||||||
$router->post('/transactions','TransactionController@add');
|
// Transactions routes
|
||||||
|
$router->group(['prefix' => '/transactions'] , function () use ($router){
|
||||||
|
$router->post('','TransactionController@add');
|
||||||
|
$router->get('{id_wallet}','TransactionController@lastTransactions');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Credits routes
|
||||||
|
$router->group(['prefix' => '/credits'] , function () use ($router){
|
||||||
|
$router->put('treatDemand/{id_demand}','CreditController@treatDemand');
|
||||||
|
});
|
||||||
|
|
||||||
$router->post('/virement','CommissionController@virement');
|
$router->post('/virement','CommissionController@virement');
|
||||||
|
|
||||||
// Wallets routes
|
// Wallets routes
|
||||||
|
|
Loading…
Reference in New Issue