mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
New voucher CIEFPC30 setup with new business logic
This commit is contained in:
@@ -118,9 +118,12 @@ class CreateVoucherLogic extends AbstractControllerLogic
|
||||
//Process request input
|
||||
$userParam = User::where('id', $request->input('userId'))->first();
|
||||
$voucherCodeInput = $request->input('voucherCode');
|
||||
$voucherCampaign = VoucherCampaign::where('name', $voucherCodeInput)->where('is_voucher_code_unique', true)->first();
|
||||
|
||||
$userRewardObject = new CreateVoucherObject(
|
||||
$voucherCodeInput,
|
||||
$userParam,
|
||||
$voucherCampaign !== null ? true : false,
|
||||
);
|
||||
$this->canCreateVoucher->passes($userRewardObject);
|
||||
|
||||
@@ -142,7 +145,7 @@ class CreateVoucherLogic extends AbstractControllerLogic
|
||||
}
|
||||
|
||||
//Voucherify - creates new voucher at voucherify
|
||||
if ($voucherCodeInput === Vouchers::SORRY_50 || $voucherCodeInput === Vouchers::SORRY_100 || $voucherCodeInput === Vouchers::SORRY_200 || $voucherCodeInput === Vouchers::CIEFPC30) {
|
||||
if ($voucherCampaign) {
|
||||
$result = $this->newVoucherifyVoucherIssuanceHandler($voucherCodeInput);
|
||||
}
|
||||
else //Voucherify - validates existing voucher at voucherify
|
||||
|
||||
@@ -13,15 +13,20 @@ class CreateVoucherObject implements DataTransferObject
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/** @var bool */
|
||||
private $isVoucherCodeUnique;
|
||||
|
||||
/**
|
||||
* CreateVoucherObject constructor.
|
||||
* @param string $voucherCode
|
||||
* @param null|User $user
|
||||
* @param bool $isVoucherCodeUnique
|
||||
*/
|
||||
public function __construct(string $voucherCode, ?User $user)
|
||||
public function __construct(string $voucherCode, ?User $user, bool $isVoucherCodeUnique = false)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->voucherCode = $voucherCode;
|
||||
$this->isVoucherCodeUnique = $isVoucherCodeUnique;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,4 +46,12 @@ class CreateVoucherObject implements DataTransferObject
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function getIsVoucherCodeUnique(): bool
|
||||
{
|
||||
return $this->isVoucherCodeUnique;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,16 +31,19 @@ class CanCreateVoucher extends AbstractRule
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
$isAuthorized = true;
|
||||
switch ($object->getVoucherCode()) {
|
||||
case Vouchers::SORRY_50:
|
||||
case Vouchers::SORRY_100:
|
||||
case Vouchers::SORRY_200:
|
||||
// $isAuthorized = Auth::user()->can('add voucher');
|
||||
$isAuthorized = in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES);
|
||||
break;
|
||||
default:
|
||||
$isAuthorized = true;
|
||||
break;
|
||||
// switch ($object->getVoucherCode()) {
|
||||
// case Vouchers::SORRY_50:
|
||||
// case Vouchers::SORRY_100:
|
||||
// case Vouchers::SORRY_200:
|
||||
// // $isAuthorized = Auth::user()->can('add voucher');
|
||||
// $isAuthorized = in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES);
|
||||
// break;
|
||||
// default:
|
||||
// $isAuthorized = true;
|
||||
// break;
|
||||
// }
|
||||
if($object->getIsVoucherCodeUnique()){
|
||||
$isAuthorized = in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES);
|
||||
}
|
||||
return $isAuthorized;
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddIsVoucherCodeUniqueToVoucherCampaignsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('voucher_campaigns', function (Blueprint $table) {
|
||||
$table->boolean('is_voucher_code_unique')->default(false)->after('is_display');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('voucher_campaigns', function (Blueprint $table) {
|
||||
$table->dropColumn('is_voucher_code_unique');
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user