-
Notifications
You must be signed in to change notification settings - Fork 2
/
MakeOrder.php
135 lines (126 loc) · 5.19 KB
/
MakeOrder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
require_once("Autoloader.php");
class MakeOrder{
private $Session;
private $Config;
public function __construct()
{
$this->Config = Config::getInstance();
$this->PaymentService = new PaymentService;
$this->TicketService = new TicketService;
$this->HistoricRepository = new HistoricRepository;
$this->DanceRepository = new DanceRepository;
$this->JazzRepository = new JazzRepository;
$this->FoodRepository = new FoodRepository;
$this->Session = new Session;
}
public function Order($orderInfo, $items)
{
usleep(5);
$uniqueCode = $orderInfo["OrderNumber"];
if($orderInfo["OrderNumber"] == ""){
$uniqueCode = microtime();
$uniqueCode = str_replace(".","",$uniqueCode);
$uniqueCode = str_replace(" ","",$uniqueCode);
}
$orderId = $this->PaymentService->CreateOrder($orderInfo, $uniqueCode);
foreach($items as $item)
{
if(array_key_exists("Amount" , $item)){
for($i = 0; $i < $item['Amount']; $i++){
$price = $this->GetEventPrice($item['EventId'], $item["TypeEvent"]);
$ticketId = $this->ticket($item['EventId'], $item['TypeEvent'], $price);
$this->PaymentService->CreateOrderLine($orderId, $ticketId);
}
}
if (array_key_exists("AdultAmount", $item)) {
for ($i = 0; $i < $item['AdultAmount']; $i++) {
$price = $this->GetEventPrice($item['EventId'], $item["TypeEvent"], "Adult");
$ticketId = $this->ticket($item['EventId'], $item['TypeEvent'], $price);
$this->PaymentService->CreateOrderLine($orderId, $ticketId);
}
for ($i = 0; $i < $item['ChildAmount']; $i++) {
$price = $this->GetEventPrice($item['EventId'], $item["TypeEvent"], "Child");
$ticketId = $this->ticket($item['EventId'], $item['TypeEvent'], $price);
$this->PaymentService->CreateOrderLine($orderId, $ticketId);
}
}
}
//$this->Session->CleanCart();
return $orderId;
}
public function ticket($eventId, $typeEvent, $price)
{
$uniqueCode = microtime(true);
$uniqueCode = str_replace(".","",$uniqueCode);
$ticketId = $this->PaymentService->CreateTicket($eventId, $typeEvent, $uniqueCode, $price);
if ($typeEvent == 1) {
$this->TicketService->RemoveAvailableTicketFood($eventId);
}
if ($typeEvent == 2) {
$this->TicketService->RemoveAvailableTicketDance($eventId);
}
if ($typeEvent == 4) {
$this->TicketService->RemoveAvailableTicketJazz($eventId);
}
if ($typeEvent == 3) {
$this->TicketService->RemoveAvailableTicketTour($eventId);
}
usleep(5);
return $ticketId;
}
public function GetPrice()
{
$items = EncryptionHelper::Decrypt($_SESSION['Tickets']);
$amountPay = 0;
foreach($items as $item){
switch ($item['TypeEvent']) {
case 1:
$event = $this->FoodRepository->GetEventInfoFood($item['EventId']);
$amountPay += doubleval(10) * doubleval($item['ChildAmount']);
$amountPay += doubleval(10) * doubleval($item['AdultAmount']);
break;
case 2:
$event = $this->DanceRepository->GetEventInfoDance($item['EventId']);
$amountPay += doubleval($event['Price']) * doubleval($item['Amount']);
break;
case 3:
$event = $this->HistoricRepository->GetEventInfoHistoric($item['EventId']);
$amountPay += doubleval($event['Price']) * doubleval($item['Amount']);
break;
case 4:
$event = $this->JazzRepository->GetEventInfoJazz($item['EventId']);
$amountPay += doubleval($event['Price']) * doubleval($item['Amount']);
break;
}
}
return number_format($amountPay, 2, '.', '');
}
public function GetEventPrice($eventId, $typeEvent, $typeTicket = "")
{
switch ($typeEvent) {
case 1:
$event = $this->FoodRepository->GetEventInfoFood($eventId);
if ($typeTicket == "Child") {
return doubleval($event['ChildPrice']);
}
else {
return doubleval($event['AdultPrice']);
}
break;
case 2:
$event = $this->DanceRepository->GetEventInfoDance($eventId);
return doubleval($event['Price']);
break;
case 3:
$event = $this->HistoricRepository->GetEventInfoHistoric($eventId);
return doubleval($event['Price']);
break;
case 4:
$event = $this->JazzRepository->GetEventInfoJazz($eventId);
return doubleval($event['Price']);
break;
}
}
}
?>