2020-06-19 13:48:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-06-24 15:49:41 +00:00
|
|
|
use App\Models\ConfigWallet;
|
2020-06-21 21:49:24 +00:00
|
|
|
use App\Models\Country;
|
2020-06-24 15:49:41 +00:00
|
|
|
use App\Models\WalletsUser;
|
2020-06-19 13:48:27 +00:00
|
|
|
use App\Traits\ApiResponser;
|
2020-06-24 15:49:41 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-06-19 13:48:27 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class HelperController extends Controller
|
|
|
|
{
|
|
|
|
use ApiResponser;
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
public function countries()
|
|
|
|
{
|
2020-06-23 08:29:48 +00:00
|
|
|
$countries = DB::select('SELECT id , name , code_dial , code_country FROM countries_currencies WHERE id IN (
|
2020-06-23 05:36:12 +00:00
|
|
|
SELECT distinct c.id FROM networks n INNER JOIN countries_currencies c ON n.country_id=c.id INNER JOIN configWallet cw ON cw.id_network = n.id WHERE status = 1
|
|
|
|
);');
|
2020-06-19 13:48:27 +00:00
|
|
|
return $this->successResponse($countries);
|
|
|
|
}
|
2020-06-21 21:49:24 +00:00
|
|
|
|
2020-06-24 15:49:41 +00:00
|
|
|
public function paying_networks(Request $request)
|
2020-06-21 21:49:24 +00:00
|
|
|
{
|
2020-06-24 15:49:41 +00:00
|
|
|
$this->validate($request,[
|
|
|
|
'id_country' => 'required|integer|min:0|not_in:0',
|
|
|
|
'id_wallet_user' => 'required|integer|min:0|not_in:0',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$walletUser = WalletsUser::findOrFail($request->id_wallet_user);
|
|
|
|
$init_country = $walletUser->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'));
|
|
|
|
}
|
|
|
|
$networks = DB::select('SELECT n.id , n.name , c.type FROM networks n INNER JOIN configWallet c ON c.id_network = n.id WHERE n.id
|
|
|
|
IN ( SELECT distinct id_network FROM paying_networks WHERE id_configWallet = :id_config)
|
|
|
|
AND status = 1 AND country_id = :id_country;',['id_country'=>$request->id_country, 'id_config'=> $config->id]);
|
2020-06-23 16:21:26 +00:00
|
|
|
foreach ($networks as $network){
|
2020-06-23 08:29:48 +00:00
|
|
|
if($network->type == 'ilink')
|
|
|
|
$network->type = 'ilink-world';
|
|
|
|
}
|
2020-06-21 21:49:24 +00:00
|
|
|
return $this->successResponse($networks);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function country($code_dial){
|
|
|
|
return $this->successResponse(Country::where('code_dial',$code_dial)->firstOrFail());
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
}
|