6
0
Fork 0

管理津贴流水过滤

release
李静 2022-03-22 10:51:27 +08:00
parent d09f5d3917
commit 4f4518a780
1 changed files with 19 additions and 14 deletions

View File

@ -18,25 +18,30 @@ class ManageSubsidyLogController extends Controller
*/
public function index(Request $request)
{
$tz = now();
if ($tz->day >= 20) {
// 结算当月20号开始的管理津贴
$startAt = $tz->copy()->setDay(20)->startOfDay();
} elseif ($tz->day >= 5) {
// 结算当月5号开始的管理津贴
$startAt = $tz->copy()->setDay(5)->startOfDay();
} else {
// 结算上月20号开始的管理津贴
$startAt = $tz->copy()->subMonthNoOverflow()->setDay(20)->startOfDay();
}
$isComplted = (bool) $request->input('is_completed');
$perPage = Paginator::resolvePerPage('per_page', 20, 50);
$manageSubsidyLogs = DealerManageSubsidyLog::with(['product'])
->when($isComplted, function ($query) {
$tz = now();
if ($tz->day >= 20) {
// 结算当月20号开始的管理津贴
$startAt = $tz->copy()->setDay(20)->startOfDay();
} elseif ($tz->day >= 5) {
// 结算当月5号开始的管理津贴
$startAt = $tz->copy()->setDay(5)->startOfDay();
} else {
// 结算上月20号开始的管理津贴
$startAt = $tz->copy()->subMonthNoOverflow()->setDay(20)->startOfDay();
}
$query->where('order_completed_at', '>=', $startAt)->latest('order_completed_at');
}, function ($query) {
$query->whereNull('order_completed_at')->latest('id');
})
->where('user_id', $request->user()->id)
->where('order_completed_at', '>=', $startAt)
->latest('order_completed_at')
->simplePaginate($perPage);
return DealerManageSubsidyLogResource::collection($manageSubsidyLogs);