allcaretravel/laravel-bookings

Rinvex Bookings 是一个通用的 Laravel 资源预订系统,它提供了运行您的 SAAS 类服务所需的所有工具,以便高效地运行。它具有简单的架构,并拥有强大的底层支持,为您的企业提供坚实的平台。

v5.0.1 2020-12-25 01:40 UTC

README

Rinvex Bookings 是一个通用的 Laravel 资源预订系统,它提供了运行您的 SAAS 类服务所需的所有工具,以便高效地运行。它具有简单的架构,并拥有强大的底层支持,为您的企业提供坚实的平台。

Packagist Scrutinizer Code Quality Travis StyleCI License

注意事项

  • Rinvex Bookings 适用于可预订资源,与价格计划和订阅无关。如果您正在寻找订阅管理系统,您可能需要查看 rinvex/laravel-subscriptions.
  • Rinvex Bookings 假设您的资源模型至少有三个字段,price 作为十进制字段,最后是 unit 作为字符串字段,分别接受 (minute, hour, day, month) 中的一个。
  • Rinvex Bookings 不包括支付和订单功能,因此您必须自行处理。预订价格由此包计算,因此您可能需要挂钩到流程或监听已保存的预订以开具发票或触发支付流程。
  • 您可以通过扩展 Rinvex Bookings 功能来添加最小和最大单位等功能。这些功能可能在未来的某个时点得到原生支持。

安装

  1. 通过 composer 安装包

    composer require rinvex/laravel-bookings
  2. 发布资源(迁移和配置文件)

    php artisan rinvex:publish:bookings
  3. 使用以下命令执行迁移

    php artisan rinvex:migrate:bookings
  4. 完成!

用法

Rinvex Bookings 是专门为 Eloquent 和简洁性而设计的,在 Laravel 相关的任何其他方面都高度重视简洁性。

为资源模型添加可预订功能

要为资源模型添加可预订功能,只需像这样使用 \Rinvex\Bookings\Traits\Bookable 特性

namespace App\Models;

use Rinvex\Bookings\Traits\Bookable;
use Illuminate\Database\Eloquent\Model;

class Room extends Model
{
    use Bookable;
}

就是这样,您只需在 Room 模型中使用该特性即可!现在您的房间将是可预订的。

为客户模型添加可预订功能

要为客户模型添加可预订功能,只需像这样使用 \Rinvex\Bookings\Traits\HasBookings 特性

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Rinvex\Bookings\Traits\HasBookings;

class Customer extends Model
{
    use HasBookings;
}

再次,这就是您需要做的所有事情!现在您的 Customer 模型可以预订资源。

创建新的预订

创建新的预订很简单,可以通过多种方式完成。让我们看看如何做到这一点

$room = \App\Models\Room::find(1);
$customer = \App\Models\Customer::find(1);

// Extends \Rinvex\Bookings\Models\BookableBooking
$serviceBooking = new \App\Models\ServiceBooking;

// Create a new booking via resource model (customer, starts, ends)
$room->newBooking($customer, '2017-07-05 12:44:12', '2017-07-10 18:30:11');

// Create a new booking via customer model (resource, starts, ends)
$customer->newBooking($room, '2017-07-05 12:44:12', '2017-07-10 18:30:11');

// Create a new booking explicitly
$serviceBooking->make(['starts_at' => \Carbon\Carbon::now(), 'ends_at' => \Carbon\Carbon::tomorrow()])
        ->customer()->associate($customer)
        ->bookable()->associate($room)
        ->save();

注意

  • 如您所见,有多种创建新预订的方法,请使用适合您上下文的方法。
  • 预订价格将根据资源价格、自定义价格和可预订费率自动计算。
  • Rinvex Bookings 足够智能,可以检测日期格式并在需要时进行转换。上面的示例显示了显式正确的格式,但您仍然可以写一些像“明天下午1点”这样的东西,它会自动为您转换。

查询预订模型

您可以通过以下方式获取有关特定预订的更多信息

// Extends \Rinvex\Bookings\Models\BookableBooking
$serviceBooking = \App\Models\ServiceBooking::find(1);

$bookable = $serviceBooking->bookable; // Get the owning resource model
$customer = $serviceBooking->customer; // Get the owning customer model

$serviceBooking->isPast(); // Check if the booking is past
$serviceBooking->isFuture(); // Check if the booking is future
$serviceBooking->isCurrent(); // Check if the booking is current
$serviceBooking->isCancelled(); // Check if the booking is cancelled

如预期的那样,您还可以按日期查询预订

// Extends \Rinvex\Bookings\Models\BookableBooking
$serviceBooking = new \App\Models\ServiceBooking;

$pastBookings = $serviceBooking->past(); // Get the past bookings
$futureBookings = $serviceBooking->future(); // Get the future bookings
$currentBookings = $serviceBooking->current(); // Get the current bookings
$cancelledBookings = $serviceBooking->cancelled(); // Get the cancelled bookings

$serviceBookingsAfter = $serviceBooking->startsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$serviceBookingsStartsBefore = $serviceBooking->startsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$serviceBookingsBetween = $serviceBooking->startsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$serviceBookingsEndsAfter = $serviceBooking->endsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$serviceBookingsEndsBefore = $serviceBooking->endsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$serviceBookingsEndsBetween = $serviceBooking->endsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$serviceBookingsCancelledAfter = $serviceBooking->cancelledAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$serviceBookingsCancelledBefore = $serviceBooking->cancelledBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$serviceBookingsCancelledBetween = $serviceBooking->cancelledBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$room = \App\Models\Room::find(1);
$serviceBookingsOfBookable = $serviceBooking->ofBookable($room)->get(); // Get bookings of the given resource

$customer = \App\Models\Customer::find(1);
$serviceBookingsOfCustomer = $serviceBooking->ofCustomer($customer)->get(); // Get bookings of the given customer

创建新的预订费率

可预订价格是用于修改默认预订价格的特定标准。例如,假设你有一个按小时收费的资源,你需要为前“2”小时设置更高的价格以覆盖某些成本,如果预订超过“5”小时则进行折扣定价。这完全可以通过可预订价格实现。只需设置应用此标准的单位数量,并使用加减符号说明你希望从默认价格增加或减少的百分比,例如 -10%,当然,你还可以从以下选项中选择操作符:(^ 表示前 X 个单位,< 表示预订少于 X 个单位时,> 表示预订超过 X 个单位时)。允许的百分比在 -100% 和 +100% 之间。

要创建新的预订价格,请按照以下步骤操作

$room = \App\Models\Room::find(1);
$room->newRate('15', '^', 2); // Increase unit price by 15% for the first 2 units
$room->newRate('-10', '>', 5); // Decrease unit price by 10% if booking is greater than 5 units

或者你可以明确创建新的预订价格,如下所示

$room = \App\Models\Room::find(1);

// Extends \Rinvex\Bookings\Models\BookableRate
$serviceRate = new \App\Models\ServiceRate;

$serviceRate->make(['percentage' => '15', 'operator' => '^', 'amount' => 2])
     ->bookable()->associate($room)
     ->save();

以下是预订价格关系

$bookable = $serviceRate->bookable; // Get the owning resource model

注意

  • 所有预订价格百分比绝不应该包含 % 符号,已知此字段是用于百分比的。
  • 当添加具有正百分比的新的预订价格时,+ 符号不是必需的,并且如果输入将会被忽略。

创建新的自定义价格

自定义价格是根据特定的时间标准设置的。例如,假设你有一个共享办公空间业务,其中一个房间是会议室,你希望对周一和周三分别收取不同的费用。假设周一从上午 09:00 到下午 05:00 是高峰时段,因此你需要收取更多费用,而周三从上午 11:30 到下午 03:45 是淡时段,因此你想收取较少的费用!这完全可以通过自定义价格实现,在那里你可以设置时间范围和它们的价格,使用加减百分比。它与 可预订价格 的工作方式相同,但基于时间标准。很棒,不是吗?

要创建自定义价格,请按照以下步骤操作

$room = \App\Models\Room::find(1);
$room->newPrice('mon', '09:00:00', '17:00:00', '26'); // Increase pricing on Monday from 09:00 am to 05:00 pm by 26%
$room->newPrice('wed', '11:30:00', '15:45:00', '-10.5'); // Decrease pricing on Wednesday from 11:30 am to 03:45 pm by 10.5%

小菜一碟,你只需设置日期、时间范围和加减百分比来增加或减少你的单位价格。

以下是自定义价格关系

$bookable = $room->bookable; // Get the owning resource model

注意

  • 如果你没有创建任何自定义价格,则资源将按照默认资源价格进行预订。
  • Rinvex 预订 足够智能,可以检测时间格式并在需要时进行转换,上述示例显示了显式正确的格式,但你仍然可以写像:'上午 09:00' 这样的事情,它将自动为你转换。

查询资源模型

你可以使用以下直观的 API 查询你的资源模型以获取更多详细信息

$room = \App\Models\Room::find(1);

$room->bookings; // Get all bookings
$room->pastBookings; // Get past bookings
$room->futureBookings; // Get future bookings
$room->currentBookings; // Get current bookings
$room->cancelledBookings; // Get cancelled bookings

$room->bookingsStartsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$room->bookingsStartsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$room->bookingsStartsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$room->bookingsEndsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$room->bookingsEndsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$room->bookingsEndsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$room->bookingsCancelledBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$room->bookingsCancelledAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$room->bookingsCancelledBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$customer = \App\Models\Customer::find(1);
$room->bookingsOf($customer)->get(); // Get bookings of the given customer

$room->rates; // Get all bookable Rates
$room->prices; // Get all custom prices

上述所有属性和方法实际上是关系,因此你可以像任何正常 Eloquent 关系一样调用原始关系方法并链式调用。例如 $room->bookings()->where('starts_at', '>', new \Carbon\Carbon())->first()

查询客户模型

就像查询你的资源一样,你可以查询客户以轻松获取相关的预订信息。看看以下示例

$customer = \App\Models\Customer::find(1);

$customer->bookings; // Get all bookings
$customer->pastBookings; // Get past bookings
$customer->futureBookings; // Get future bookings
$customer->currentBookings; // Get current bookings
$customer->cancelledBookings; // Get cancelled bookings

$customer->bookingsStartsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$customer->bookingsStartsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$customer->bookingsStartsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$customer->bookingsEndsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$customer->bookingsEndsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$customer->bookingsEndsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$customer->bookingsCancelledBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$customer->bookingsCancelledAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$customer->bookingsCancelledBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$room = \App\Models\Room::find(1);
$customer->isBooked($room); // Check if the customer booked the given room
$customer->bookingsOf($room)->get(); // Get bookings by the customer for the given room

就像资源模型一样,上述所有属性和方法实际上是关系,因此你可以像任何正常 Eloquent 关系一样调用原始关系方法并链式调用。例如 $customer->bookings()->where('starts_at', '>', new \Carbon\Carbon())->first()

⚠️ 文档尚未完整,该软件包正在开发中,部分内容可能需要重构!⚠️

变更日志

有关项目的完整历史记录,请参阅 变更日志

支持

以下支持渠道尽在你的指尖

贡献与协议

感谢您考虑为本项目做出贡献!贡献指南可以在CONTRIBUTING.md中找到。

欢迎提交错误报告、功能请求和拉取请求。

安全漏洞

如果您在此项目中发现安全漏洞,请发送电子邮件至help@rinvex.com。所有安全漏洞都将得到及时处理。

关于Rinvex

Rinvex是一家成立于2016年6月的开罗,埃及的软件解决方案初创公司,专注于为中小企业提供集成企业解决方案。我们相信,我们的驱动力量——价值、触达和影响力是我们与众不同的地方,通过软件的力量释放我们哲学的无限可能性。我们喜欢称之为“生活速度的创新”。这就是我们如何为人类进步贡献我们的一份力量。

许可证

本软件按照MIT许可证(MIT)发布。

版权所有 © 2016-2021 Rinvex LLC,部分权利保留。