136 lines
3.5 KiB
PHP
136 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Admin\app\Http\Controllers;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\SerialNumberCheck;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Response;
|
|
use App\Traits\HasFilterRequest;
|
|
use App\Traits\HasOrderByRequest;
|
|
use JsonException;
|
|
|
|
class SNCheckController extends Controller
|
|
{
|
|
use HasOrderByRequest;
|
|
use HasFilterRequest;
|
|
public function __construct()
|
|
{
|
|
// module check model exist and table
|
|
if (!class_exists(SerialNumberCheck::class)) {
|
|
throw new JsonException("SerialNumberCheck table not exist");
|
|
}
|
|
;
|
|
}
|
|
public function get(Request $request)
|
|
{
|
|
$history = SerialNumberCheck::getHistoryWithUserInfo();
|
|
|
|
// Order by
|
|
$this->orderByRequest($history, $request);
|
|
|
|
// Filter
|
|
$this->filterRequest(
|
|
builder: $history,
|
|
request: $request,
|
|
filterKeys: [
|
|
'keyword' => [
|
|
'type' => self::F_TEXT,
|
|
'column' => 'serial_number_check.keyword'
|
|
],
|
|
'email' => [
|
|
'type' => self::F_TEXT,
|
|
'column' => 'users.email'
|
|
],
|
|
'status' => [
|
|
'type' => self::F_NOT_CONTAIN,
|
|
'column' => 'serial_number_check.status'
|
|
],
|
|
'from_date' => [
|
|
'type' => self::F_THAN_EQ_DATETIME,
|
|
'column' => 'serial_number_check.created_at'
|
|
],
|
|
'to_date' => [
|
|
'type' => self::F_LESS_EQ_DATETIME,
|
|
'column' => 'serial_number_check.created_at'
|
|
],
|
|
]
|
|
);
|
|
|
|
$responseData = array_merge(
|
|
$history->paginate($request->get('per_page'))->toArray(),
|
|
['status' => true]
|
|
);
|
|
|
|
return response()->json($responseData);
|
|
}
|
|
|
|
public function showDetail(Request $request)
|
|
{
|
|
$id = $request->input('id');
|
|
$searchRow = SerialNumberCheck::find($id);
|
|
if ($searchRow) {
|
|
$user = $searchRow->user()->get();
|
|
$tracking = $searchRow->tracking()->get();
|
|
$trackingDetail = $tracking->map(function ($item) {
|
|
return [
|
|
'current_point' => $item->current_point,
|
|
'use_point' => $item->use_point,
|
|
'created_at' => $item->created_at
|
|
];
|
|
});
|
|
|
|
$response = [
|
|
'data_search' => $searchRow,
|
|
'user' => $user[0],
|
|
'tracking' => $trackingDetail
|
|
];
|
|
|
|
return response()->json(['data' => $response, 'status' => true]);
|
|
}else{
|
|
return response()->json(['data' => [], 'status' => false]);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request): RedirectResponse
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the specified resource.
|
|
*/
|
|
public function show($id)
|
|
{
|
|
return view('admin::show');
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
return view('admin::edit');
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, $id): RedirectResponse
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
}
|