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-07-04 10:48:06 +00:00
|
|
|
use App\Models\NetworksAgent;
|
2020-06-25 16:54:46 +00:00
|
|
|
use App\Models\User;
|
2020-07-04 10:48:06 +00:00
|
|
|
use App\Models\Wallet;
|
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-08-24 16:29:50 +00:00
|
|
|
use App\Traits\Helper;
|
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;
|
2020-08-24 16:29:50 +00:00
|
|
|
use Helper;
|
2020-06-19 13:48:27 +00:00
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2020-06-28 10:45:17 +00:00
|
|
|
public function countries()
|
2020-06-19 13:48:27 +00:00
|
|
|
{
|
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',
|
2020-07-04 10:48:06 +00:00
|
|
|
'id_wallet_agent' => 'required_without:id_wallet_user|integer|min:0|not_in:0',
|
|
|
|
'id_wallet_user' => 'required_without:id_wallet_agent|integer|min:0|not_in:0',
|
2020-06-24 15:49:41 +00:00
|
|
|
]);
|
|
|
|
|
2020-07-04 10:48:06 +00:00
|
|
|
if (isset($request->id_wallet_agent)) {
|
|
|
|
$walletAgent = Wallet::findOrFail($request->get('id_wallet_agent'));
|
|
|
|
$network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent);
|
|
|
|
$init_country = $network_agent->network->country->id;
|
|
|
|
// Configuratrion du wallet
|
|
|
|
$config = ConfigWallet::where('id_network', $network_agent->network_id)->firstOrFail();
|
|
|
|
} elseif (isset($request->id_wallet_user)) {
|
|
|
|
$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'));
|
|
|
|
}
|
2020-06-24 15:49:41 +00:00
|
|
|
}
|
2020-07-04 10:48:06 +00:00
|
|
|
|
2020-06-24 15:49:41 +00:00
|
|
|
$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-28 10:45:17 +00:00
|
|
|
if($request->id_country == $init_country ){
|
|
|
|
$currentNetwork = new \stdClass();
|
|
|
|
$currentNetwork->id = $config->network->id;
|
|
|
|
$currentNetwork->name = $config->network->name;
|
|
|
|
$currentNetwork->type = 'ilink-world';
|
|
|
|
array_unshift($networks,$currentNetwork);
|
|
|
|
}
|
2020-06-21 21:49:24 +00:00
|
|
|
return $this->successResponse($networks);
|
|
|
|
}
|
|
|
|
|
2020-07-04 10:20:26 +00:00
|
|
|
public function other_paying_networks(Request $request)
|
|
|
|
{
|
|
|
|
$this->validate($request,[
|
|
|
|
'id_country' => 'required|integer|min:0|not_in:0',
|
2020-07-04 10:48:06 +00:00
|
|
|
'id_wallet_agent' => 'required|integer|min:0|not_in:0',
|
2020-07-04 10:20:26 +00:00
|
|
|
]);
|
|
|
|
|
2020-07-04 10:48:06 +00:00
|
|
|
$walletAgent = Wallet::findOrFail($request->get('id_wallet_agent'));
|
|
|
|
$network_agent = NetworksAgent::findOrFail($walletAgent->id_networkAgent);
|
|
|
|
// Configuratrion du wallet
|
|
|
|
$config = ConfigWallet::where('id_network', $network_agent->network_id)->firstOrFail();
|
|
|
|
|
2020-07-04 10:20:26 +00:00
|
|
|
$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)
|
2020-07-04 10:48:06 +00:00
|
|
|
AND status = 1 AND c.type <> \'ilink\' AND country_id = :id_country;',['id_country'=>$request->id_country, 'id_config'=> $config->id]);
|
2020-07-04 10:20:26 +00:00
|
|
|
return $this->successResponse($networks);
|
|
|
|
}
|
|
|
|
|
2020-06-21 21:49:24 +00:00
|
|
|
public function country($code_dial){
|
|
|
|
return $this->successResponse(Country::where('code_dial',$code_dial)->firstOrFail());
|
|
|
|
}
|
2020-06-25 16:54:46 +00:00
|
|
|
|
|
|
|
public function init(){
|
|
|
|
//Mettre a jour tous les utilisateurs qui n'ont pas de wallet iLink
|
|
|
|
$users = User::whereNull('user_code')->orWhere('user_code','')->get();
|
|
|
|
foreach ($users as $user){
|
|
|
|
do{
|
|
|
|
$user_code=$this->generateUserCode();
|
|
|
|
$result = collect(DB::select('SELECT * FROM users WHERE user_code = :code',['code'=>$user_code]));
|
|
|
|
$codeCorrect=sizeof($result)<0;
|
|
|
|
}while($codeCorrect);
|
|
|
|
$user->user_code = $user_code;
|
|
|
|
DB::insert('INSERT INTO wallets_users (idUser) VALUES (?);', [$user->id]);
|
|
|
|
$user->save();
|
|
|
|
}
|
|
|
|
return $this->successResponse('OK :-) , Have a nice day dear ! ');
|
|
|
|
}
|
|
|
|
|
|
|
|
private function generateUserCode($length = 10) {
|
|
|
|
$characters = '23456789abcdefghjkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ';
|
|
|
|
$charactersLength = strlen($characters);
|
|
|
|
$randomString = '';
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
|
|
}
|
|
|
|
return $randomString;
|
|
|
|
}
|
2020-06-19 13:48:27 +00:00
|
|
|
}
|