added new api

This commit is contained in:
Frank John Begornia
2020-12-11 21:47:36 +08:00
parent 43de35a66c
commit 852593ecfb
3 changed files with 173 additions and 12 deletions

View File

@@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use App\Models\ApiModel; use App\Models\ApiModel;
use ArrayObject;
use Carbon\Carbon; use Carbon\Carbon;
use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Input;
@@ -18,10 +19,14 @@ class ApiController extends Controller
$ApiModel = new ApiModel; $ApiModel = new ApiModel;
$post = $request->all(); $post = $request->all();
$response = $ApiModel->loginProductionUser($post['username'], $post['password']); $response = $ApiModel->loginProductionUser($post['username'], $post['password']);
if (!$response) { if (!$response) {
return response()->json(['status' => false, 'message' => "Invalid user"], 401); return response()->json(['status' => false, 'message' => "Invalid user"], 401);
} }
$selectTrackingStepLabel = $ApiModel->selectTrackingStepLabel($response[0]->StepId);
$response[0]->AssignedStep = $selectTrackingStepLabel[0]->StepLabel;
return response()->json(['status' => true, 'data' => $response[0]], 200); return response()->json(['status' => true, 'data' => $response[0]], 200);
} }
@@ -29,29 +34,99 @@ class ApiController extends Controller
{ {
$ApiModel = new ApiModel; $ApiModel = new ApiModel;
$post = $request->json()->all(); $post = $request->json()->all();
$data = array( $data = array(
"StepId" => $post['StepId'], "StepId" => $post['StepId'],
"ScannedBy" => $post['ScannedBy'], "ScannedBy" => $post['ScannedBy'],
"InvoiceNumber" => $post['invoice'], "InvoiceNumber" => $post['invoice'],
"OrdersId" => $post['ordersId'],
"ProductId" => $post['productId'],
"QuantityCounter" => $post['quantityCounter'],
"Timezone" => $post['timezone'], "Timezone" => $post['timezone'],
"TimezoneOffset" => date('H:i:s',strtotime($post['timezoneOffset'])), "TimezoneOffset" => date('H:i:s', strtotime($post['timezoneOffset'])),
"DeviceId" =>$post['deviceId'], "DeviceId" => $post['deviceId'],
"created_at" => date('Y-m-d H:i:s', strtotime($post['datetime'])) "created_at" => date('Y-m-d H:i:s', strtotime($post['datetime']))
); );
$checkIfTrackExist = $ApiModel->checkIfTrackExist($post['StepId'], $post['productId'], $post['ordersId'], $post['invoice'], $post['quantityCounter']);
if ($checkIfTrackExist) {
return response()->json(['status' => false, 'message' => "Already scanned."], 500);
}
// $selectNextStep = $ApiModel->selectNextStep($post['invoice']);
// if(($selectNextStep->StepId + 1) != $post['StepId']){
// return response()->json(['status' => false, 'message' => "Your account is not allowed to update this item."], 401);
// }
$response = $ApiModel->insertTracking($data); $response = $ApiModel->insertTracking($data);
if (!$response) { if (!$response) {
return response()->json(['status' => false, 'message' => "Something went wrong."], 401); return response()->json(['status' => false, 'message' => "Something went wrong."], 500);
} }
return response()->json(['status' => true, 'message' => 'Successfully updated.'], 201); 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);
// }
public function getTrackingStatus() public function getTrackingStatus()
{ {
$ApiModel = new ApiModel; $ApiModel = new ApiModel;
$invoice = Input::get('invoice'); $invoice = Input::get('invoice');
$response = $ApiModel->getTrackingStatus($invoice);
return response()->json(['status' => true, 'data' => $response], 200); // $response = $ApiModel->getTrackingStatus($invoice);
$selectPaymentDetails = $ApiModel->selectPaymentDetails($invoice);
if (!$selectPaymentDetails) {
return response()->json(['status' => false, 'message' => "Not found."], 404);
}
$selectOrderList = $ApiModel->selectOrderList($selectPaymentDetails[0]->CartKey);
$getCurrentTrackingSteps = $ApiModel->getCurrentTrackingSteps($invoice);
$selectPaymentDetails[0]->tracking_steps = $getCurrentTrackingSteps;
foreach ($selectOrderList as $k => $order) {
$table_fields[] = $ApiModel->selectOrderListTableFields($order->CartKey, $order->ProductId);
$product_images[] = $ApiModel->selectProductImages($order->ProductId);
$selectOrderList[$k]->table_fields = $table_fields[$k];
$selectOrderList[$k]->product_images = $product_images[$k];
}
return response()->json([
'status' => true,
'payment_details' => $selectPaymentDetails[0],
'order_list' => $selectOrderList
], 200);
} }
public function getOrderStatus()
{
$ApiModel = new ApiModel;
$invoice = Input::get('invoice');
$productid = Input::get('productid');
$orderid = Input::get('orderid');
$qcounter = Input::get('qcounter');
$getStatus = $ApiModel->getStatus($invoice, $productid, $orderid, $qcounter);
if (!$getStatus) {
return response()->json(['status' => false, 'data' => ""], 404);
}
return response()->json([
'status' => true,
'data' => $getStatus[0]
], 200);
}
} }

View File

@@ -190,4 +190,6 @@ Route::group(array('middleware' => ['isAuthorized', 'cors'], 'prefix' => 'api'),
Route::post('login', 'ApiController@login'); Route::post('login', 'ApiController@login');
Route::post('insert', 'ApiController@insert'); Route::post('insert', 'ApiController@insert');
Route::get('tracking', 'ApiController@getTrackingStatus'); Route::get('tracking', 'ApiController@getTrackingStatus');
Route::get('order-status', 'ApiController@getOrderStatus');
}); });

View File

@@ -8,12 +8,21 @@ use Illuminate\Support\Facades\DB;
class ApiModel extends Model class ApiModel extends Model
{ {
function loginProductionUser($username, $password){ function loginProductionUser($username, $password)
{
$i = DB::table('production_user') $i = DB::table('production_user')
->where('Username', $username) ->where('Username', $username)
->where('Password', $password) ->where('Password', $password)
->get(); ->get();
return $i; return $i;
}
function selectTrackingStepLabel($id)
{
$i = DB::table('tracking_steps')->select('StepLabel')
->where('Id', $id)
->get();
return $i;
} }
function getTrackingStatus($invoice) function getTrackingStatus($invoice)
@@ -27,8 +36,83 @@ class ApiModel extends Model
return $i; return $i;
} }
function insertTracking($data){ function selectPaymentDetails($invoice)
{
$i = DB::table('payment_details')
->where('InvoiceNumber', $invoice)
->get();
return $i;
}
function selectOrderList($cartKey)
{
$i = DB::table('orders')->select('ProductId', 'ProductName', 'CartKey')
->where('CartKey', $cartKey)
->groupBy('ProductId')
->get();
return $i;
}
function selectProductImages($productId)
{
$i = DB::table('teamstore_product_thumbnails')
->where('ProductId', $productId)
->get();
return $i;
}
function selectOrderListTableFields($cartKey, $productId)
{
$i = DB::table('orders')->select('Id', 'Name', 'Name2', 'Number', 'Size', 'JerseySize', 'ShortsSize', 'Quantity')
->where('CartKey', $cartKey)
->where('ProductId', $productId)
->get();
return $i;
}
function insertTracking($data)
{
$i = DB::table('tracking')->insert($data); $i = DB::table('tracking')->insert($data);
return $i; return $i;
} }
// function selectNextStep($invoice)
// {
// $i = DB::table('tracking')->select('StepId')
// ->where('InvoiceNumber', $invoice)
// ->orderBy('StepId', 'DESC')->first();
// return $i;
// }
function checkIfTrackExist($stepid, $productid, $orderid, $invoice, $qcounter)
{
$i = DB::table('tracking')
->where('StepId', $stepid)
->where('ProductId', $productid)
->where('OrdersId', $orderid)
->where('InvoiceNumber', $invoice)
->where('QuantityCounter', $qcounter)
->get();
return $i;
}
function getCurrentTrackingSteps($invoice){
$i = DB::table('tracking')->select('StepId')
->where('InvoiceNumber', $invoice)
->groupBy('StepId')
->orderBy('StepId', 'ASC')
->get();
return $i;
}
function getStatus($invoice, $productid, $orderid, $qcounter){
$i = DB::table('tracking')->select('production_user.Name', DB::raw('DATE_FORMAT(tracking.created_at, "%b %d, %Y - %H:%i") AS datetime'))
->leftjoin('production_user', 'production_user.Id', '=', 'tracking.ScannedBy')
->where('tracking.InvoiceNumber', $invoice)
->where('tracking.ProductId', $productid)
->where('tracking.OrdersId', $orderid)
->where('tracking.QuantityCounter', $qcounter)
->get();
return $i;
}
} }