+ User history

This commit is contained in:
Djery-Tom 2020-07-10 12:22:51 +01:00
parent a35121dba8
commit a0d2ea24df
1 changed files with 37 additions and 12 deletions

View File

@ -636,6 +636,7 @@ class iLinkTransactionController extends Controller
if (!$user) if (!$user)
return $this->errorResponse(trans('errors.wallet_not_defined')); return $this->errorResponse(trans('errors.wallet_not_defined'));
$transaction->id_destinataire = $request->user_code;
$walletUser = WalletsUser::where('idUser', $user->id)->firstOrFail(); $walletUser = WalletsUser::where('idUser', $user->id)->firstOrFail();
$transaction->final_country = $final_country = $user->network->country->id; $transaction->final_country = $final_country = $user->network->country->id;
@ -898,19 +899,43 @@ class iLinkTransactionController extends Controller
} }
public function lastUserTransactions($id_wallet_user) public function lastUserTransactions($code_user)
{ {
$transactions = DB::select('SELECT tit.nom as operation , wit.montant , $user = User::where('user_code',$code_user)->firstOrFail();
CASE $wallet_user = WalletsUser::where('idUser',$user->id)->firstOrFail();
WHEN u.lastname IS NOT NULL THEN u.lastname
ELSE $transactions = DB::select('SELECT id_wallet_user , operation , id_transaction ,network_destinataire, init_country , final_country, date , id , montant , frais , taxe , pays_init , pays_final,
CASE destinataire_phone , destinataire_name , nom_destinataire, prenom_destinataire, montant_net ,montant_net_final_country FROM infos_ilink_transaction WHERE id_wallet_user = :id_wallet
WHEN wit.id_destinataire IS NULL THEN wit.nom_destinataire ORDER BY date DESC LIMIT 10;', ['id_wallet' => $wallet_user->id]);
ELSE wit.id_destinataire
END foreach ($transactions as $data){
END AS destinataire , wit.date , wit.id FROM wallet_ilink_transaction wit $date = $data->date;
INNER JOIN type_ilink_transaction tit ON wit.type = tit.id LEFT JOIN users u ON u.user_code = wit.id_destinataire WHERE wit.id_wallet_user = :id_wallet unset($data->date);
ORDER BY wit.date DESC LIMIT 10;', ['id_wallet' => $id_wallet_user]);
$user_destinataire = isset($data->id_destinataire) ? User::where('user_code',$data->id_destinataire)->first() : null ;
// $emetteur = $wallet_user ? $wallet_user->user->lastname.' '.$wallet_user->user->firstname : $data->prenom_emetteur . ' ' . $data->nom_emetteur;
$emetteur = 'Moi';
if($data->destinataire_phone){
$destinataire = $data->destinataire_name;
}else{
$destinataire = $data->prenom_destinataire ? $data->prenom_destinataire . ' ' . $data->nom_destinataire : $emetteur;
}
// $destinataire = in_array($data->type,[12,16]) ? $emetteur : ( $user_destinataire ? $user_destinataire->lastname.' '.$user_destinataire->firstname :
// $data->prenom_destinataire . ' ' . $data->nom_destinataire);
$data->emetteur = $emetteur;
$data->destinataire = $destinataire;
$data->frais = $this->toMoney($data->frais + $data->taxe, $data->init_country);
$data->montant_net_init = $this->toMoney($data->montant_net, $data->init_country);
$data->montant_net_final = $data->montant_net_final_country ? $this->toMoney($data->montant_net_final_country, $data->final_country) : $data->montant_net_init ;
$data->montant = $this->toMoney($data->montant, $data->init_country);
$data->init_country = $data->pays_init;
$data->final_country = $data->pays_final;
$data->reseau_payeur = isset($data->network_destinataire) ? $this->getNetworkName($data->network_destinataire).' '.$data->final_country : null;
$data->date = $date;
unset($data->type, $data->destinataire_name, $data->id_wallet_user,$data->network_destinataire,$data->nom_destinataire, $data->prenom_destinataire ,$data->taxe,$data->numero_carte,
$data->montant_net_final_country, $data->montant_net,$data->pays_init, $data->pays_final ,$data->id_destinataire ,$data->destinataire_phone);
}
return $this->successResponse($transactions); return $this->successResponse($transactions);
} }