rinvex/bookings

此包已被弃用且不再维护。作者建议使用 rinvex/laravel-bookings 包。

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

v0.0.4 2018-09-29 02:13 UTC

This package is auto-updated.

Last update: 2022-02-01 13:09:39 UTC


README

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

⚠️ 此包已被重命名,现在在 rinvex/laravel-bookings 维护,作者建议使用新包。旧包支持 Laravel v5.6,而新包支持 Laravel v5.7+。

Packagist Scrutinizer Code Quality Code Climate Travis StyleCI License

考虑事项

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

安装

  1. 通过 composer 安装包

    composer require rinvex/bookings
  2. 执行以下命令执行迁移

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

使用方法

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);
$bookableAvailability = app('rinvex.bookings.bookable-booking');

// 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
$bookableAvailability->make(['starts_at' => \Carbon\Carbon::now(), 'ends_at' => \Carbon\Carbon::tomorrow()])
        ->customer()->associate($customer)
        ->bookable()->associate($room)
        ->save();

备注

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

查询预订模型

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

$bookableAvailability = app('rinvex.bookings.bookable-booking')->find(1);

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

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

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

$pastBookings = app('rinvex.bookings.bookable-booking')->past(); // Get the past bookings
$futureBookings = app('rinvex.bookings.bookable-booking')->future(); // Get the future bookings
$currentBookings = app('rinvex.bookings.bookable-booking')->current(); // Get the current bookings
$cancelledBookings = app('rinvex.bookings.bookable-booking')->cancelled(); // Get the cancelled bookings

$bookableAvailabilitysSAfter = app('rinvex.bookings.bookable-booking')->startsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$bookableAvailabilitysStartsBefore = app('rinvex.bookings.bookable-booking')->startsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$bookableAvailabilitysSBetween = app('rinvex.bookings.bookable-booking')->startsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$bookableAvailabilitysEndsAfter = app('rinvex.bookings.bookable-booking')->endsAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$bookableAvailabilitysEndsBefore = app('rinvex.bookings.bookable-booking')->endsBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$bookableAvailabilitysEndsBetween = app('rinvex.bookings.bookable-booking')->endsBetween('2017-06-21 19:28:51', '2017-07-01 12:00:00')->get(); // Get bookings starts between the given dates

$bookableAvailabilitysCancelledAfter = app('rinvex.bookings.bookable-booking')->cancelledAfter('2017-06-21 19:28:51')->get(); // Get bookings starts after the given date
$bookableAvailabilitysCancelledBefore = app('rinvex.bookings.bookable-booking')->cancelledBefore('2017-06-21 19:28:51')->get(); // Get bookings starts before the given date
$bookableAvailabilitysCancelledBetween = app('rinvex.bookings.bookable-booking')->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);
$bookableAvailabilitysOfBookable = app('rinvex.bookings.bookable-booking')->ofBookable($room)->get(); // Get bookings of the given resource

$customer = \App\Models\Customer::find(1);
$bookableAvailabilitysOfCustomer = app('rinvex.bookings.bookable-booking')->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);
$bookableRate = app('rinvex.bookings.bookable-rate');
$bookableRate->make(['percentage' => '15', 'operator' => '^', 'amount' => 2])
     ->bookable()->associate($room)
     ->save();

以下是预订费率关系

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

备注

  • 所有预订费率百分比绝对不应该包含%符号,众所周知,此字段已经是百分比。
  • 当添加具有正百分比的新的预订费率时,+符号不是必需的,并且如果输入了也会被省略。

创建新的自定义价格

自定义价格是根据特定的时间标准设定的。例如,假设您经营一个共享办公空间业务,并且您的一个房间是会议室,您希望周一和周三收取不同的费用。假设周一上午9:00至下午5:00是高峰时段,因此您需要收取更高的费用,而周三上午11:30至下午3: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足够智能,可以检测时间格式并在需要时进行转换。以上示例显示了显式正确的格式,但您仍然可以写类似于“上午9: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)下发布。

(c) 2016-2018 Rinvex LLC,部分权利保留。