add rest application and discount-status rest method - lastXdays fix
This commit is contained in:
parent
767211d6c7
commit
7ec1a95a07
@ -24,59 +24,61 @@ class CustomerController extends RestController
|
|||||||
* @return array
|
* @return array
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function actionDiscountStatus($number , $lastXDays = 0 ){
|
public function actionDiscountStatus($number, $lastXDays = null)
|
||||||
|
{
|
||||||
|
|
||||||
$number = Helper::fixAsciiChars( $number );
|
$number = Helper::fixAsciiChars($number);
|
||||||
|
|
||||||
$query = Card::find();
|
$query = Card::find();
|
||||||
$query->andWhere(['or',
|
$query->andWhere(['or',
|
||||||
['and',[ 'in','card.number' , [$number]],"trim(coalesce(card.number, '')) <>'' " ],
|
['and', ['in', 'card.number', [$number]], "trim(coalesce(card.number, '')) <>'' "],
|
||||||
['and', ['in','card.rfid_key' ,[ $number] ],"trim(coalesce(card.rfid_key, '')) <>'' "],
|
['and', ['in', 'card.rfid_key', [$number]], "trim(coalesce(card.rfid_key, '')) <>'' "],
|
||||||
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$card = $query->one();
|
$card = $query->one();
|
||||||
|
|
||||||
if ( !isset($card)){
|
if (!isset($card)) {
|
||||||
throw new NotFoundHttpException("Kártya nem található");
|
throw new NotFoundHttpException("Kártya nem található");
|
||||||
}
|
}
|
||||||
|
|
||||||
$customer = $card->customer;
|
$customer = $card->customer;
|
||||||
|
|
||||||
if ( !isset($customer) ){
|
if (!isset($customer)) {
|
||||||
throw new NotFoundHttpException("Vendég nem található");
|
throw new NotFoundHttpException("Vendég nem található");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isset($lastXDays) ){
|
if (isset($lastXDays)) {
|
||||||
if (!is_numeric($lastXDays)){
|
if (!is_numeric($lastXDays)) {
|
||||||
throw new BadRequestHttpException("lastXDays paraméter hibás");
|
throw new BadRequestHttpException("lastXDays paraméter hibás");
|
||||||
}
|
}
|
||||||
if ( $lastXDays > 6 || $lastXDays < 1){
|
if ($lastXDays > 6 || $lastXDays < 1) {
|
||||||
throw new BadRequestHttpException("lastXDays paraméter érték hibás");
|
throw new BadRequestHttpException("lastXDays paraméter érték hibás");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if has valid ticket today
|
// check if has valid ticket today
|
||||||
/** @var \common\models\Card $card */
|
/** @var \common\models\Card $card */
|
||||||
$tickets = Ticket::readActive($card );
|
$tickets = Ticket::readActive($card);
|
||||||
$hasValidTicket = count($tickets) > 0;
|
$hasValidTicket = count($tickets) > 0;
|
||||||
|
|
||||||
// try to find any valid ticket in the lastXDays
|
if (isset($lastXDays)) {
|
||||||
$minusDay = 1;
|
// try to find any valid ticket in the lastXDays
|
||||||
while ( !$hasValidTicket && $minusDay <= $lastXDays ){
|
$minusDay = 1;
|
||||||
/** @var integer $minusDay */
|
while (!$hasValidTicket && $minusDay <= $lastXDays) {
|
||||||
$day = $this->getDateMinusDays($minusDay);
|
/** @var integer $minusDay */
|
||||||
$tickets = Ticket::readActive($card, $day );
|
$day = $this->getDateMinusDays($minusDay);
|
||||||
$hasValidTicket = count($tickets) > 0;
|
$tickets = Ticket::readActive($card, $day);
|
||||||
$minusDay = $minusDay + 1;
|
$hasValidTicket = count($tickets) > 0;
|
||||||
|
$minusDay = $minusDay + 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$result = [
|
||||||
$result = [
|
|
||||||
'discount' => $hasValidTicket
|
'discount' => $hasValidTicket
|
||||||
];
|
];
|
||||||
|
|
||||||
if ( isset($customer) ){
|
if (isset($customer)) {
|
||||||
$result['card_number'] = $card->number;
|
$result['card_number'] = $card->number;
|
||||||
$result['name'] = $customer->name;
|
$result['name'] = $customer->name;
|
||||||
}
|
}
|
||||||
@ -89,10 +91,11 @@ class CustomerController extends RestController
|
|||||||
* @return \DateTime
|
* @return \DateTime
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
private function getDateMinusDays($minusDays){
|
private function getDateMinusDays($minusDays)
|
||||||
|
{
|
||||||
$date = new \DateTime('now');
|
$date = new \DateTime('now');
|
||||||
$date->sub(new \DateInterval('P'.$minusDays.'D'));
|
$date->sub(new \DateInterval('P' . $minusDays . 'D'));
|
||||||
$date->setTime(0,0,0);
|
$date->setTime(0, 0, 0);
|
||||||
return $date;
|
return $date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user