rinvex / laravel-bookings
Rinvex Bookings 是一个通用的 Laravel 资源预订系统,提供了运行你的 SAAS 类服务的所需工具,以高效运行。它具有简单的架构,并拥有强大的底层支持,为你的业务提供坚实的基础。
Requires
- php: ^8.0.0
- illuminate/console: ^9.0.0 || ^10.0.0
- illuminate/database: ^9.0.0 || ^10.0.0
- illuminate/support: ^9.0.0 || ^10.0.0
- rinvex/laravel-support: ^6.0.0
- spatie/eloquent-sortable: ^4.0.0
- spatie/laravel-schemaless-attributes: ^2.3.0
- spatie/laravel-sluggable: ^3.3.0
- spatie/laravel-translatable: ^5.2.0
Requires (Dev)
- codedungeon/phpunit-result-printer: ^0.31.0
- illuminate/container: ^9.0.0 || ^10.0.0
- phpunit/phpunit: ^9.5.0
README
⚠️ 此包已被弃用且不再维护。没有推荐替代包。 ⚠️
👉 如果你有兴趣成为此包的主要维护者,请 联系我!
Rinvex Bookings 是一个通用的 Laravel 资源预订系统,提供了运行你的 SAAS 类服务的所需工具,以高效运行。它具有简单的架构,并拥有强大的底层支持,为你的业务提供坚实的基础。
考虑事项
- Rinvex Bookings 是为可预订资源设计的,与价格计划和订阅无关。如果你在寻找订阅管理系统,你可能需要查看 rinvex/laravel-subscriptions.
- Rinvex Bookings 假设你的资源模型至少有三个字段,
price
为十进制字段,最后是unit
字符串字段,分别接受(分钟、小时、天、月)中的一个。 - 支付和订单不在 Rinvex Bookings 的范围之内,因此你需要自己处理这个问题。预订价格由此包计算,因此你可能需要挂钩到该过程或监听已保存的预订以开出发票或触发支付流程。
- 你可以扩展 Rinvex Bookings 的功能以添加例如最小和最大单位等特性。这些特性可能在未来的某个时间点原生支持。
安装
-
使用 composer 安装此包
composer require rinvex/laravel-bookings
-
发布资源(迁移和配置文件)
php artisan rinvex:publish:bookings
-
通过以下命令执行迁移
php artisan rinvex:migrate:bookings
-
完成!
使用
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 Bookings 足够智能,可以检测时间格式并在需要时进行转换。上面的示例显示了显式正确的格式,但您仍然可以写像“上午 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()
。
⚠️ 文档尚未完成,该软件包正在开发中,部分内容可能需要重构!⚠️
路线图
寻找贡献者!
以下是一系列待改进的限制或待实施的功能请求,所有Pull Requests都欢迎 😊
变更日志
请参阅变更日志以了解项目的完整历史。
支持
以下支持渠道随时可用
贡献 & 协议
感谢您考虑为该项目做出贡献!贡献指南可在CONTRIBUTING.md中找到。
欢迎提交错误报告、功能请求和Pull Requests。
安全漏洞
如果您在此项目中发现安全漏洞,请发送电子邮件至help@rinvex.com。所有安全漏洞都将得到及时处理。
关于Rinvex
Rinvex是一家成立于2016年6月的埃及亚历山大市的企业级软件解决方案初创公司。我们相信,我们的动力“价值、范围和影响”是我们区别于其他公司的因素,并通过软件的力量释放我们哲学的无限可能性。我们喜欢称之为“生活节奏的创新”。这就是我们如何为推动人类进步做出贡献的方式。
许可
本软件根据MIT许可 (MIT)发布。
© 2016-2022 Rinvex LLC,部分权利保留。