35 lines
1.0 KiB
PHP
35 lines
1.0 KiB
PHP
<?
|
|
namespace App\Services;
|
|
|
|
use App\Models\CustomerVoucherList;
|
|
|
|
class VoucherService
|
|
{
|
|
private $customer_voucher_list;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->customer_voucher_list = new CustomerVoucherList();
|
|
}
|
|
|
|
public function checkVoucherAvailability($customer_voucher_list_id, $order_type, $customer_id)
|
|
{
|
|
$customer_voucher = $this->customer_voucher_list->where('id', $customer_voucher_list_id)->where('customer_id', $customer_id)->first();
|
|
|
|
if(empty($customer_voucher)){
|
|
return ['status' => 400, 'result' => 'Customer voucher not found.'];
|
|
}
|
|
|
|
$current_date = date('Y-m-d');
|
|
|
|
|
|
if($current_date > $customer_voucher['voucher_expiry_date']){
|
|
return ['status' => 400, 'result' => 'Voucher already expired.'];
|
|
}
|
|
|
|
if($customer_voucher['voucher_status'] != 'active'){
|
|
return ['status' => 400, 'result' => 'Voucher already ' . $customer_voucher['voucher_status'] . '.'];
|
|
}
|
|
}
|
|
}
|
|
?>
|