master
lion 1 week ago
parent 11db2fbd13
commit bf7be0de37

@ -12,7 +12,6 @@ use App\Models\TicketGrabEvent;
use App\Models\Venue; use App\Models\Venue;
use App\Support\ActivityH5View; use App\Support\ActivityH5View;
use App\Support\CalendarDateFormat; use App\Support\CalendarDateFormat;
use Carbon\Carbon;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
class H5HomeController extends Controller class H5HomeController extends Controller
@ -170,39 +169,45 @@ class H5HomeController extends Controller
]; ];
}); });
$controller = $this; $controller = $this;
$today = Carbon::now((string) config('app.timezone'))->toDateString(); $hotActivities = $actRows
$hotActivities = $actRows->merge($tgRows)->sort(function (array $x, array $y) use ($today, $controller) { ->merge($tgRows)
$hx = (($x['list_kind'] ?? 'activity') === 'activity' && ! empty($x['is_hot'])) ? 0 : 1; ->filter(fn (array $row) => ($row['schedule_status'] ?? '') !== 'ended')
$hy = (($y['list_kind'] ?? 'activity') === 'activity' && ! empty($y['is_hot'])) ? 0 : 1; ->values()
if ($hx !== $hy) { ->sort(function (array $x, array $y) use ($controller) {
return $hx <=> $hy; $hx = (($x['list_kind'] ?? 'activity') === 'activity' && ! empty($x['is_hot'])) ? 0 : 1;
} $hy = (($y['list_kind'] ?? 'activity') === 'activity' && ! empty($y['is_hot'])) ? 0 : 1;
$sx = $controller->homeScheduleRank($x['start_at'] ?? null, $x['end_at'] ?? null, $today); if ($hx !== $hy) {
$sy = $controller->homeScheduleRank($y['start_at'] ?? null, $y['end_at'] ?? null, $today); return $hx <=> $hy;
if ($sx !== $sy) {
return $sx <=> $sy;
}
$a = $x['start_at'] ?? '';
$b = $y['start_at'] ?? '';
if ($a !== $b) {
if ($a === '') {
return 1;
} }
if ($b === '') { $sx = $controller->homeScheduleRankFromStatus($x['schedule_status'] ?? null);
return -1; $sy = $controller->homeScheduleRankFromStatus($y['schedule_status'] ?? null);
if ($sx !== $sy) {
return $sx <=> $sy;
} }
$a = $x['start_at'] ?? '';
$b = $y['start_at'] ?? '';
if ($a !== $b) {
if ($a === '') {
return 1;
}
if ($b === '') {
return -1;
}
return strcmp((string) $a, (string) $b); return strcmp((string) $a, (string) $b);
} }
$tx = $this->homeActivityTicketPaidRank($x); $tx = $this->homeActivityTicketPaidRank($x);
$ty = $this->homeActivityTicketPaidRank($y); $ty = $this->homeActivityTicketPaidRank($y);
if ($tx !== $ty) { if ($tx !== $ty) {
return $tx <=> $ty; return $tx <=> $ty;
} }
return (int) $y['id'] <=> (int) $x['id']; return (int) $y['id'] <=> (int) $x['id'];
})->values()->take(5)->values(); })
->values()
->take(5)
->values();
$rankings = $hotActivities->take(2)->values(); $rankings = $hotActivities->take(2)->values();
@ -281,22 +286,15 @@ class H5HomeController extends Controller
} }
/** /**
* 与活动列表 H5 混合排序0 进行中/未结束, 1 未开始, 2 已结束。 * 0=进行中 1=未开始 2=已结束,与 {@see Activity::computeScheduleStatusForDisplay} 口径一致。
* (热门区已过滤 ended此处仅用于未开始/进行中 的先后。)
*/ */
private function homeScheduleRank(?string $startIso, ?string $endIso, string $today): int private function homeScheduleRankFromStatus(?string $scheduleStatus): int
{ {
$s = $startIso ? Carbon::parse($startIso)->toDateString() : null; return match ($scheduleStatus) {
$e = $endIso ? Carbon::parse($endIso)->toDateString() : null; 'not_started' => 1,
if (! $e && ! $s) { 'ended' => 2,
return 0; default => 0,
} };
if ($e && $e < $today) {
return 2;
}
if ($s && $s > $today) {
return 1;
}
return 0;
} }
} }

Loading…
Cancel
Save