+ Update get actives wallet method

This commit is contained in:
DJERY-TOM 2020-05-05 21:42:57 +01:00
parent 7cbf402758
commit 59e291b7b8
1 changed files with 10 additions and 2 deletions

View File

@ -24,16 +24,19 @@ class WalletController extends Controller
public function activated($id_agent) public function activated($id_agent)
{ {
$networks = DB::select('SELECT ne.name as network , countries.name AS country, w.id, na.id AS id_networkAgent FROM agents ag $networks = DB::select('SELECT ne.name as network , countries.name AS country, w.id, na.id AS id_networkAgent , cg.category FROM agents ag
INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id INNER JOIN configWallet cw ON ne.id = cw.id_network INNER JOIN networks_agents na ON ag.id=na.agent_id INNER JOIN codeGenerer cg ON cg.id=na.codeGenerer_id INNER JOIN networks ne ON ne.id=na.network_id INNER JOIN configWallet cw ON ne.id = cw.id_network
INNER JOIN countries ON ne.country_id=countries.id LEFT JOIN wallets w ON na.id = w.id_networkAgent WHERE ag.id= :id AND network_id IN ( INNER JOIN countries ON ne.country_id=countries.id LEFT JOIN wallets w ON na.id = w.id_networkAgent WHERE ag.id= :id AND network_id IN (
SELECT networks.id FROM networks LEFT JOIN configWallet ON configWallet.id_network = networks.id WHERE status = 1 AND id_network IS NOT NULL)', ['id' => $id_agent]); SELECT networks.id FROM networks LEFT JOIN configWallet ON configWallet.id_network = networks.id WHERE status = 1 AND id_network IS NOT NULL)', ['id' => $id_agent]);
// Create wallet if is not exist // Create wallet if is not exist
$category = null;
if($networks){ if($networks){
$reload = false; $reload = false;
$id = $id_agent; $id = $id_agent;
foreach ($networks as $network){ foreach ($networks as $network){
$category = $network->category;
// Create wallet if is not exist
if(!$network->id){ if(!$network->id){
DB::insert('INSERT INTO wallets (id_networkAgent) VALUES (?);', [$network->id_networkAgent]); DB::insert('INSERT INTO wallets (id_networkAgent) VALUES (?);', [$network->id_networkAgent]);
$reload = true; $reload = true;
@ -42,6 +45,11 @@ class WalletController extends Controller
if($reload) if($reload)
return $this->activated($id); return $this->activated($id);
} }
// Return only single wallet if it is hypervisor or supervisor
if(in_array( $category , ['hyper','super']))
return $this->successResponse(collect($networks)->first());
else
return $this->successResponse($networks); return $this->successResponse($networks);
} }