saber13812002/laravel-bookings

v6.0.0 2021-08-22 00:46 UTC

README

⚠️ 此包已被弃用且不再维护。没有建议的替代包。⚠️

👉 如果你对成为此包的主要维护者感兴趣,请 联系我

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

Packagist Scrutinizer Code Quality Travis StyleCI License

注意事项

  • Rinvex Bookings 用于可预订资源,与价格计划和订阅无关。如果您正在寻找订阅管理系统,您可能需要查看 rinvex/laravel-subscriptions.
  • Rinvex Bookings 假设您的资源模型至少有三个字段,price 为十进制字段,最后是 unit 为字符串字段,分别接受(分钟、小时、天、月)之一。
  • 支付和订购不在 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

注意

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

创建一个新的自定义价格

自定义价格是根据特定的时间标准设置的。例如,假设您有一个共享办公空间业务,其中一个房间是会议室,您希望对周一和周三分别收费。假设周一从上午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()

⚠️文档尚未完成,该包处于开发中,某些部分可能需要重构!⚠️

路线图

寻找贡献者!

以下是一系列待改进的限制或功能请求,寻找贡献者来实现,所有PR都欢迎😊

  • 添加取消预订的功能(#43)
  • 完成可预订可用性的实现,并对其进行文档化(#32,#4)
  • 改进文档,完成缺失的功能,并为每个添加一个可工作的示例。

变更日志

请参考项目的完整历史记录,见变更日志

支持

以下支持渠道尽在您的指尖:

贡献与协议

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

欢迎提交bug报告、功能请求和pull请求。

安全漏洞

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

关于Rinvex

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

许可

本软件根据MIT许可(MIT)发布。

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