Improve Event management

This commit is contained in:
Roland Schneider
2019-01-15 07:28:43 +01:00
parent e3b6bc08a7
commit 8decd1bc79
15 changed files with 695 additions and 278 deletions

View File

@@ -26,28 +26,22 @@ class CustomerController extends RestController
*/
public function actionDiscountStatus($number, $lastXDays = null)
{
$number = Helper::fixAsciiChars($number);
$query = Card::find();
$query->andWhere(['or',
['and', ['in', 'card.number', [$number]], "trim(coalesce(card.number, '')) <>'' "],
['and', ['in', 'card.rfid_key', [$number]], "trim(coalesce(card.rfid_key, '')) <>'' "],
]);
/** @var \common\models\Card $card */
$card = $query->one();
if (!isset($card)) {
throw new NotFoundHttpException("Kártya nem található");
}
$customer = $card->customer;
if (!isset($customer)) {
throw new NotFoundHttpException("Vendég nem található");
}
if (isset($lastXDays)) {
if (!is_numeric($lastXDays)) {
throw new BadRequestHttpException("lastXDays paraméter hibás");
@@ -56,12 +50,10 @@ class CustomerController extends RestController
throw new BadRequestHttpException("lastXDays paraméter érték hibás");
}
}
// check if has valid ticket today
/** @var \common\models\Card $card */
$tickets = Ticket::readActive($card);
$hasValidTicket = count($tickets) > 0;
if (isset($lastXDays)) {
// try to find any valid ticket in the lastXDays
$minusDay = 1;
@@ -73,17 +65,14 @@ class CustomerController extends RestController
$minusDay = $minusDay + 1;
}
}
$result = [
'discount' => $hasValidTicket
];
if (isset($customer)) {
$result['card_number'] = $card->number;
$result['name'] = $customer->name;
$result['provider'] = \Yii::$app->id;
}
return $result;
}