|
|
|
|
@ -115,26 +115,34 @@ class H5ReservationController extends Controller
|
|
|
|
|
|
|
|
|
|
[$bookingType, $peopleCount] = $this->resolveBookingTypeAndPeopleCount($mode, $data, $minPeople, $maxPeople);
|
|
|
|
|
|
|
|
|
|
$reservation = DB::transaction(function () use ($request, $activity, $day, $data, $peopleCount, $bookingType) {
|
|
|
|
|
$wechatUser = $this->authWechatUser($request);
|
|
|
|
|
|
|
|
|
|
$reservation = DB::transaction(function () use ($activity, $day, $data, $peopleCount, $bookingType, $wechatUser) {
|
|
|
|
|
$day->refresh();
|
|
|
|
|
$available = (int) $day->day_quota - (int) $day->booked_count;
|
|
|
|
|
if ($available < $peopleCount) {
|
|
|
|
|
throw ValidationException::withMessages(['activity_day_id' => ['该日期余票不足']]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 去重规则:同活动同活动日同手机号只能预约一单(未取消)
|
|
|
|
|
$dupByPhone = Reservation::query()
|
|
|
|
|
// 去重:同一活动、同一活动日,同一用户只能有一单未取消预约(取消后可再约)
|
|
|
|
|
// — 按手机号;已登录时同时按微信用户,避免换手机号重复占坑
|
|
|
|
|
$dup = Reservation::query()
|
|
|
|
|
->where('activity_id', $activity->id)
|
|
|
|
|
->where('activity_day_id', $day->id)
|
|
|
|
|
->where('visitor_phone', $data['visitor_phone'])
|
|
|
|
|
->where('status', '!=', 'cancelled')
|
|
|
|
|
->where(function ($q) use ($data, $wechatUser) {
|
|
|
|
|
$q->where('visitor_phone', $data['visitor_phone']);
|
|
|
|
|
if ($wechatUser) {
|
|
|
|
|
$q->orWhere('wechat_user_id', $wechatUser->id);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
->exists();
|
|
|
|
|
if ($dupByPhone) {
|
|
|
|
|
throw ValidationException::withMessages(['visitor_phone' => ['该手机号在该活动日期已预约过']]);
|
|
|
|
|
if ($dup) {
|
|
|
|
|
throw ValidationException::withMessages([
|
|
|
|
|
'activity_day_id' => ['您在该活动该日期已有未取消的预约,请先取消原预约后再预约'],
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$wechatUser = $this->authWechatUser($request);
|
|
|
|
|
|
|
|
|
|
$row = Reservation::create([
|
|
|
|
|
'venue_id' => $activity->venue_id,
|
|
|
|
|
'activity_id' => $activity->id,
|
|
|
|
|
|