yanselmask/bookings

Yanselmask Bookings 是一个通用的资源预订系统,适用于 Laravel,包含运行您的 SAAS 服务的必要工具,以提高效率。它具有简单的架构,强大的底层支持,为您的企业提供稳定的平台。

dev-main 2024-08-05 16:03 UTC

This package is auto-updated.

Last update: 2024-09-30 10:17:53 UTC


README

Yanselmask Bookings 是一个通用的资源预订系统,适用于 Laravel,包含运行您的 SAAS 服务的必要工具,以提高效率。它具有简单的架构,强大的底层支持,为您的企业提供稳定的平台。

考虑事项

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

Composer.json

    "minimum-stability": "dev",
    "prefer-stable": true

安装

  1. 通过 composer 安装包

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

    php artisan yanselmask:publish:bookings
  3. 通过以下命令执行迁移

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

用法

Yanselmask Bookings 是专门为 Eloquent 和简洁性而制作的,在 Laravel 的任何其他相关方面都非常注重简洁性。

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

要将可预订功能添加到您的资源模型,只需使用 \Yanselmask\Bookings\Traits\Bookable 特性,如下所示

namespace App\Models;

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

class Room extends Model
{
    use Bookable;
}

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

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

要将可预订功能添加到您的客户模型,只需使用 \Yanselmask\Bookings\Traits\HasBookings 特性,如下所示

namespace App\Models;

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

class Customer extends Model
{
    use HasBookings;
}

同样,您只需要这样做!现在您的 Customer 模型可以预订资源了。

$table->bookings 添加到您的模型可预订中(可选)

   $table->bookings();

创建一个新的预订

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

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

// Extends \Yanselmask\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();

备注

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

查询预订模型

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

// Extends \Yanselmask\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 \Yanselmask\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 \Yanselmask\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('monday', '09:00:00', '17:00:00', '26'); // Increase pricing on Monday from 09:00 am to 05:00 pm by 26%
$room->newPrice('wednesday', '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

备注

  • 如果您不创建任何自定义价格,则资源将按默认资源价格预订。
  • Yanselmask预订非常智能,可以检测时间格式并在需要时进行转换,上述示例显示了明确正确的格式,但您仍然可以写类似“上午09:00”的内容,它将自动为您转换。

创建一个新的自定义可用性

要创建自定义可用性,请按照以下步骤操作

$room = \App\Models\Room::find(1);
$room->newAvailability('monday', ['09:00-12:00', '13:00-18:00']); //Add the use at the top of each file where you want to use
$room->availabilitiesRange($time = new DateTime('now')); // This will allow you to display things like 
echo "It's open since ".$range->start()."\n";
echo "It will close at ".$range->end()."\n";
echo "It's closed since ".$openingHours->previousClose($now)->format('l H:i')."\n";
echo "It will re-open at ".$openingHours->nextOpen($now)->format('l H:i')."\n";

备注

  • newAvailability($range, $data, $bookeable, $priority)
  • string $range
  • array $data
  • bool $bookeable = true
  • int $priority = 10

函数

$room->AvailabilityIsOpenOn('monday'); //The object can be queried for a day in the week, which will return a result based on the regular schedule
$room->AvailabilityIsOpenAt(new DateTime('2016-12-25')); //It can also be queried for a specific date and time
$room->AvailabilityForDay(new DateTime('2016-12-25')); //OpeningHoursForDay object for the regular schedule
$room->AvailabilityForWeek(); //OpeningHoursForDay[] for the regular schedule, keyed by day name
$room->AvailabilityForWeekCombined(); //Array of day with same schedule for the regular schedule, keyed by day name, days combined by working hours
$room->AvailabilityForDate(new DateTime('2016-12-25')); //OpeningHoursForDay object for a specific day
$room->AvailabilityExceptions(); //OpeningHoursForDay object for a specific day
$room->AvailabilityNextOpen($time); //It can also return the next open or close DateTime from a given DateTime
$room->AvailabilityNextClose($time); //It can also return the next open or close DateTime from a given DateTime
$room->AvailabilityIsClosedOn('sunday'); //Checks if the business is closed on a day in the regular schedule.
$room->AvailabilityIsClosedAt(new DateTime('2016-12-25')); //Checks if the business is closed on a specific day, at a specific time.
$room->AvailabilityIsClosed(); //Checks if the business is open right now.
$room = \App\Models\Room::find(1);
$room->availabilities(); //All
$room->availabilitiesBookable(); //Only bookable (is_bookable = true)
$room->availabilitiesNotBookable(); //Only not bookable (is_bookable = false)

查询资源模型

您可以使用直观的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@yanselmask.com。所有安全漏洞都将得到及时处理。

关于Yanselmask

Yanselmask是一家软件解决方案初创公司,自2016年6月成立以来,专注于为埃及亚历山大市的中型企业提供一体化解决方案。我们相信,我们的动力——价值、范围和影响力是我们区别于其他公司的特点,通过软件的力量释放我们哲学的无限可能性。我们喜欢称之为“与生活同步的创新”。这就是我们如何为推进人类文明做出贡献的方式。

致谢

许可证

本软件基于MIT许可证(MIT)发布。

(c) 2024 Yanselmask,Inc.,部分权利保留。