52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Client;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Crm\Customer;
|
|
use App\Models\Service\ServiceExecution;
|
|
use App\Models\Service\ServiceOrder;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ServiceController extends Controller
|
|
{
|
|
/**
|
|
* 我的服务订单(分页)
|
|
*/
|
|
public function orders(Request $request): JsonResponse
|
|
{
|
|
/** @var Customer $customer */
|
|
$customer = $request->user();
|
|
|
|
$query = ServiceOrder::withoutGlobalScope('store')
|
|
->where('customer_id', $customer->id)
|
|
->with('package:id,name', 'item:id,name');
|
|
|
|
if ($request->filled('status')) {
|
|
$query->where('status', (int) $request->input('status'));
|
|
}
|
|
|
|
return $this->paginate(
|
|
$query->orderByDesc('id')->paginate(15)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 服务执行记录(分页)
|
|
*/
|
|
public function executions(Request $request): JsonResponse
|
|
{
|
|
/** @var Customer $customer */
|
|
$customer = $request->user();
|
|
|
|
$query = ServiceExecution::withoutGlobalScope('store')
|
|
->whereHas('order', fn ($q) => $q->where('customer_id', $customer->id))
|
|
->with('technician:id,name', 'order:id,status');
|
|
|
|
return $this->paginate(
|
|
$query->orderByDesc('executed_at')->paginate(15)
|
|
);
|
|
}
|
|
}
|