added api for tracking
This commit is contained in:
57
app/Http/Controllers/ApiController.php
Normal file
57
app/Http/Controllers/ApiController.php
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Requests;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\ApiModel;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Illuminate\Support\Facades\Input;
|
||||||
|
|
||||||
|
class ApiController extends Controller
|
||||||
|
{
|
||||||
|
|
||||||
|
public function login(Request $request)
|
||||||
|
{
|
||||||
|
$ApiModel = new ApiModel;
|
||||||
|
$post = $request->all();
|
||||||
|
$response = $ApiModel->loginProductionUser($post['username'], $post['password']);
|
||||||
|
if (!$response) {
|
||||||
|
return response()->json(['status' => false, 'message' => "Invalid user"], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(['status' => true, 'data' => $response[0]], 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function insert(Request $request)
|
||||||
|
{
|
||||||
|
$ApiModel = new ApiModel;
|
||||||
|
$post = $request->json()->all();
|
||||||
|
|
||||||
|
$data = array(
|
||||||
|
"StepId" => $post['StepId'],
|
||||||
|
"ScannedBy" => $post['ScannedBy'],
|
||||||
|
"InvoiceNumber" => $post['invoice'],
|
||||||
|
"Timezone" => $post['timezone'],
|
||||||
|
"TimezoneOffset" => date('H:i:s',strtotime($post['timezoneOffset'])),
|
||||||
|
"DeviceId" =>$post['deviceId'],
|
||||||
|
"created_at" => date('Y-m-d H:i:s', strtotime($post['datetime']))
|
||||||
|
);
|
||||||
|
$response = $ApiModel->insertTracking($data);
|
||||||
|
if (!$response) {
|
||||||
|
return response()->json(['status' => false, 'message' => "Something went wrong."], 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->json(['status' => true, 'message' => 'Successfully updated.'], 201);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTrackingStatus()
|
||||||
|
{
|
||||||
|
$ApiModel = new ApiModel;
|
||||||
|
$invoice = Input::get('invoice');
|
||||||
|
$response = $ApiModel->getTrackingStatus($invoice);
|
||||||
|
return response()->json(['status' => true, 'data' => $response], 200);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,7 @@ use Illuminate\Http\Request;
|
|||||||
use App\Models\MainModel;
|
use App\Models\MainModel;
|
||||||
// use Illuminate\Support\Facades\Request;
|
// use Illuminate\Support\Facades\Request;
|
||||||
use Analytics;
|
use Analytics;
|
||||||
use Session;
|
use Illuminate\Support\Facades\Session;
|
||||||
|
|
||||||
class MainController extends Controller {
|
class MainController extends Controller {
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use Illuminate\Http\Request;
|
|||||||
use Netshell\Paypal\Facades\Paypal;
|
use Netshell\Paypal\Facades\Paypal;
|
||||||
use App\Models\teamstore\TeamStoreModel;
|
use App\Models\teamstore\TeamStoreModel;
|
||||||
use App\Models\user\UserModel;
|
use App\Models\user\UserModel;
|
||||||
|
use App\Models\ApiModel;
|
||||||
use App\Models\paypal\PayPalModel;
|
use App\Models\paypal\PayPalModel;
|
||||||
// use Auth;
|
// use Auth;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@@ -19,7 +20,6 @@ use Illuminate\Support\Facades\Redirect;
|
|||||||
use Illuminate\Support\Facades\Mail;
|
use Illuminate\Support\Facades\Mail;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PaypalController extends Controller
|
class PaypalController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -74,8 +74,6 @@ class PaypalController extends Controller
|
|||||||
$payer = PayPal::Payer();
|
$payer = PayPal::Payer();
|
||||||
$payer->setPaymentMethod('paypal');
|
$payer->setPaymentMethod('paypal');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$m = new TeamStoreModel;
|
$m = new TeamStoreModel;
|
||||||
$paypal_model = new PayPalModel;
|
$paypal_model = new PayPalModel;
|
||||||
$last_id = $paypal_model->getLastIdPaymentDetails();
|
$last_id = $paypal_model->getLastIdPaymentDetails();
|
||||||
@@ -382,6 +380,17 @@ class PaypalController extends Controller
|
|||||||
});
|
});
|
||||||
// end email sending
|
// end email sending
|
||||||
|
|
||||||
|
|
||||||
|
$insertTracking = array(
|
||||||
|
"StepId" => 1,
|
||||||
|
"ScannedBy" => 1,
|
||||||
|
"InvoiceNumber" => $invoice_number,
|
||||||
|
"created_at" => date('Y-m-d H:i:s')
|
||||||
|
);
|
||||||
|
|
||||||
|
$ApiModel = new ApiModel;
|
||||||
|
$ApiModel->insertTracking($insertTracking);
|
||||||
|
|
||||||
$request->session()->forget('cartkey'); // clear session for cartkey
|
$request->session()->forget('cartkey'); // clear session for cartkey
|
||||||
|
|
||||||
// redirect to thank you page.
|
// redirect to thank you page.
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ class Kernel extends HttpKernel {
|
|||||||
'teamstoresession' => 'App\Http\Middleware\CheckTeamStorePassword',
|
'teamstoresession' => 'App\Http\Middleware\CheckTeamStorePassword',
|
||||||
'admin' => '\App\Http\Middleware\IsAdmin',
|
'admin' => '\App\Http\Middleware\IsAdmin',
|
||||||
'normaluser' => '\App\Http\Middleware\IsUser',
|
'normaluser' => '\App\Http\Middleware\IsUser',
|
||||||
|
'isAuthorized' => '\App\Http\Middleware\isAuthorized',
|
||||||
|
'cors' => 'App\Http\Middleware\Cors',
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
28
app/Http/Middleware/Cors.php
Normal file
28
app/Http/Middleware/Cors.php
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
class Cors
|
||||||
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
header("Access-Control-Allow-Origin: *");
|
||||||
|
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
|
||||||
|
header("Access-Control-Allow-Headers: *");
|
||||||
|
// header('Access-Control-Allow-Credentials: true');
|
||||||
|
|
||||||
|
if (!$request->isMethod('options')) {
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,8 +13,22 @@ class VerifyCsrfToken extends BaseVerifier {
|
|||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
protected $except = [
|
||||||
|
"api/*",
|
||||||
|
];
|
||||||
|
|
||||||
|
// public function handle($request, Closure $next)
|
||||||
|
// {
|
||||||
|
// return parent::handle($request, $next);
|
||||||
|
// }
|
||||||
|
|
||||||
public function handle($request, Closure $next)
|
public function handle($request, Closure $next)
|
||||||
{
|
{
|
||||||
|
foreach($this->except as $route) {
|
||||||
|
if ($request->is($route)) {
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
return parent::handle($request, $next);
|
return parent::handle($request, $next);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
23
app/Http/Middleware/isAuthorized.php
Normal file
23
app/Http/Middleware/isAuthorized.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Closure;
|
||||||
|
|
||||||
|
class isAuthorized {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle an incoming request.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param \Closure $next
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function handle($request, Closure $next)
|
||||||
|
{
|
||||||
|
if(isset(getallheaders()['token']) && getallheaders()['token']=="1HHIaIsT4pvO2S39vMzlVfGWi3AhAz6F5xGBNKil") {
|
||||||
|
return $next($request);
|
||||||
|
}else{
|
||||||
|
return response()->json(['status' => false,'error' => "Invalid request"], 503);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -185,3 +185,9 @@ Route::get('cliparts/index', 'cliparts\ClipartsController@index');
|
|||||||
// Route::get('analytics', function (){
|
// Route::get('analytics', function (){
|
||||||
// $analyticsData = LaravelAnalytics::getVisitorsAndPageViews(7);
|
// $analyticsData = LaravelAnalytics::getVisitorsAndPageViews(7);
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
Route::group(array('middleware' => ['isAuthorized', 'cors'], 'prefix' => 'api'), function (){
|
||||||
|
Route::post('login', 'ApiController@login');
|
||||||
|
Route::post('insert', 'ApiController@insert');
|
||||||
|
Route::get('tracking', 'ApiController@getTrackingStatus');
|
||||||
|
});
|
||||||
34
app/Models/ApiModel.php
Normal file
34
app/Models/ApiModel.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class ApiModel extends Model
|
||||||
|
{
|
||||||
|
|
||||||
|
function loginProductionUser($username, $password){
|
||||||
|
$i = DB::table('production_user')
|
||||||
|
->where('Username', $username)
|
||||||
|
->where('Password', $password)
|
||||||
|
->get();
|
||||||
|
return $i;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTrackingStatus($invoice)
|
||||||
|
{
|
||||||
|
$i = DB::table('tracking')->select('tracking.Id', 'tracking.InvoiceNumber', 'tracking_steps.StepLabel', 'production_user.Name', DB::raw('DATE_FORMAT(tracking.created_at, "%b %d, %Y") AS date'), DB::raw('DATE_FORMAT(tracking.created_at, "%H:%i") AS time'))
|
||||||
|
->leftjoin('tracking_steps', 'tracking_steps.Id', '=', 'tracking.StepId')
|
||||||
|
->leftjoin('production_user', 'production_user.Id', '=', 'tracking.ScannedBy')
|
||||||
|
->where('tracking.InvoiceNumber', '=', $invoice)
|
||||||
|
->orderBy('tracking.created_at', 'DESC')
|
||||||
|
->get();
|
||||||
|
return $i;
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertTracking($data){
|
||||||
|
$i = DB::table('tracking')->insert($data);
|
||||||
|
return $i;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php namespace App\Models;
|
<?php namespace App\Models;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class MainModel extends Model {
|
class MainModel extends Model {
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
|
||||||
|
class CreateApiModelsTable extends Migration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('api_models', function(Blueprint $table)
|
||||||
|
{
|
||||||
|
$table->increments('id');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::drop('api_models');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user