2020-04-15 23:08:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use App\Models\ConfigWallet;
|
|
|
|
use App\Models\Network;
|
|
|
|
use App\Models\NetworksAgent;
|
|
|
|
use App\Models\Wallet;
|
|
|
|
use App\Models\WalletTransaction;
|
|
|
|
use App\Traits\ApiResponser;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\Response;
|
2020-06-01 18:31:25 +00:00
|
|
|
use Illuminate\Support\Facades\Date;
|
|
|
|
use Illuminate\Support\Facades\Mail;
|
2020-04-15 23:08:09 +00:00
|
|
|
|
|
|
|
class CommissionController extends Controller
|
|
|
|
{
|
|
|
|
use ApiResponser;
|
|
|
|
/**
|
|
|
|
* Create a new controller instance.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2020-04-27 13:13:15 +00:00
|
|
|
public function virement($id_wallet)
|
2020-04-15 23:08:09 +00:00
|
|
|
{
|
2020-04-27 13:13:15 +00:00
|
|
|
$wallet = Wallet::findOrFail($id_wallet);
|
|
|
|
|
|
|
|
if($wallet->balance_com <=0 )
|
2020-04-28 16:12:05 +00:00
|
|
|
return $this->errorResponse(trans('messages.empty_com_balance') , Response::HTTP_BAD_REQUEST);
|
2020-04-15 23:08:09 +00:00
|
|
|
|
|
|
|
$wallet->balance_princ += $wallet->balance_com;
|
|
|
|
$wallet->balance_com = 0;
|
2020-04-27 13:13:15 +00:00
|
|
|
$wallet->save();
|
2020-04-15 23:08:09 +00:00
|
|
|
|
2020-04-27 13:13:15 +00:00
|
|
|
return $this->successResponse($wallet);
|
2020-04-15 23:08:09 +00:00
|
|
|
|
|
|
|
}
|
2020-06-01 18:31:25 +00:00
|
|
|
|
|
|
|
public function sendMail(){
|
|
|
|
|
|
|
|
$recipients = ['dietchidjery@gmail.com'];
|
|
|
|
Mail::mailer('smtp')->raw('Message test.', function ($message) use ($recipients) {
|
|
|
|
$message->subject('This is a test to see if emails are working');
|
|
|
|
$message->to($recipients);
|
|
|
|
});
|
|
|
|
return $this->successResponse("mail envoye");
|
|
|
|
}
|
|
|
|
|
|
|
|
public function fileUpload(Request $request) {
|
|
|
|
|
|
|
|
// if ($request->hasFile('image')) {
|
|
|
|
// $image = $request->file('image');
|
|
|
|
// $name = time().'.'.$image->getClientOriginalExtension();
|
|
|
|
// $destinationPath = storage_path('/storage');
|
|
|
|
// $image->move($destinationPath, $name);
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// return $this->successResponse("image envoye");
|
|
|
|
// }
|
|
|
|
|
|
|
|
$response = null;
|
|
|
|
$user = (object) ['image' => ""];
|
|
|
|
|
|
|
|
if ($request->hasFile('image')) {
|
|
|
|
$original_filename = $request->file('image')->getClientOriginalName();
|
|
|
|
$original_filename_arr = explode('.', $original_filename);
|
|
|
|
$file_ext = end($original_filename_arr);
|
|
|
|
$destination_path = './upload/user/';
|
|
|
|
$image = 'U-' . time() . '.' . $file_ext;
|
2020-06-05 17:00:16 +00:00
|
|
|
// File info
|
|
|
|
// $fileName = basename($_FILES["image"]["name"]);
|
|
|
|
// $imageUploadPath = $uploadPath . $fileName;
|
|
|
|
// $fileType = pathinfo($imageUploadPath, PATHINFO_EXTENSION);
|
|
|
|
|
|
|
|
// Allow certain file formats
|
|
|
|
$allowTypes = array('jpg','png','jpeg','gif');
|
|
|
|
if(in_array(strtolower($file_ext), $allowTypes)){
|
|
|
|
// Image temp source
|
|
|
|
// $imageTemp = $_FILES["image"]["tmp_name"];
|
|
|
|
|
|
|
|
// Compress size and upload image
|
|
|
|
$compressedImage = $this->compressImage($request->file('image'), '/'. $image, 80);
|
|
|
|
if($compressedImage){
|
|
|
|
return $this->successResponse("Image compressed successfully.");
|
|
|
|
}else{
|
|
|
|
return $this->errorResponse( "Image compress failed!");
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
return $this->errorResponse('Sorry, only JPG, JPEG, PNG, & GIF files are allowed to upload.');
|
2020-06-01 18:31:25 +00:00
|
|
|
}
|
2020-06-05 17:00:16 +00:00
|
|
|
|
|
|
|
// if ($request->file('image')->move($destination_path, $image)) {
|
|
|
|
// $user->image = '/upload/user/' . $image;
|
|
|
|
// return $this->successResponse($user);
|
|
|
|
// } else {
|
|
|
|
// return $this->errorResponse('Cannot upload file');
|
|
|
|
// }
|
2020-06-01 18:31:25 +00:00
|
|
|
} else {
|
|
|
|
return $this->errorResponse('File not found');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-06-05 17:00:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Custom function to compress image size and
|
|
|
|
* upload to the server using PHP
|
|
|
|
*/
|
|
|
|
function compressImage($source, $destination, $quality) {
|
|
|
|
// Get image info
|
|
|
|
$imgInfo = getimagesize($source);
|
|
|
|
$mime = $imgInfo['mime'];
|
|
|
|
|
|
|
|
// Create a new image from file
|
|
|
|
switch($mime){
|
|
|
|
case 'image/jpeg':
|
|
|
|
$image = imagecreatefromjpeg($source);
|
|
|
|
break;
|
|
|
|
case 'image/png':
|
|
|
|
$image = imagecreatefrompng($source);
|
|
|
|
break;
|
|
|
|
case 'image/gif':
|
|
|
|
$image = imagecreatefromgif($source);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$image = imagecreatefromjpeg($source);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save image
|
|
|
|
imagejpeg($image, $destination, $quality);
|
|
|
|
|
|
|
|
// Return compressed image
|
|
|
|
return $destination;
|
|
|
|
}
|
2020-04-15 23:08:09 +00:00
|
|
|
}
|