api_model.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. <?php
  2. class api_model extends Model {
  3. //private $API = 'https://szollosil.bbus.smbinfo.hu/api/index.php';
  4. //private $API = 'https://hoponticket.com/api/index.php';
  5. private $API = 'https://php82fpm.umsbox.hu/api/index.php';
  6. private $API_KEY = '92JxvN5Zeti4E1FDwKg0QPEl3md4vY63';
  7. public function getGroupsList() {
  8. $curl = curl_init();
  9. curl_setopt_array($curl, array(
  10. CURLOPT_URL => $this->API.'/affiliateapi/groups',
  11. CURLOPT_RETURNTRANSFER => true,
  12. CURLOPT_ENCODING => '',
  13. CURLOPT_MAXREDIRS => 10,
  14. CURLOPT_TIMEOUT => 0,
  15. CURLOPT_FOLLOWLOCATION => true,
  16. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  17. CURLOPT_CUSTOMREQUEST => 'GET',
  18. CURLOPT_HTTPHEADER => array(
  19. 'DOLAPIKEY: '.$this->API_KEY
  20. ),
  21. ));
  22. $response = curl_exec($curl);
  23. curl_close($curl);
  24. $groups = [];
  25. $response = json_decode($response, true);
  26. foreach ($response as $key => $item) {
  27. $group = [];
  28. $group['id'] = $key;
  29. $group['label'] = $item;
  30. $groups[] = $group;
  31. }
  32. //$data = json_encode($groups, true);
  33. return $groups;
  34. }
  35. public function getProductsList($groupID) {
  36. $curl = curl_init();
  37. curl_setopt_array($curl, array(
  38. CURLOPT_URL => $this->API.'/affiliateapi/products?group_id='.$groupID,
  39. CURLOPT_RETURNTRANSFER => true,
  40. CURLOPT_ENCODING => '',
  41. CURLOPT_MAXREDIRS => 10,
  42. CURLOPT_TIMEOUT => 0,
  43. CURLOPT_FOLLOWLOCATION => true,
  44. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  45. CURLOPT_CUSTOMREQUEST => 'GET',
  46. CURLOPT_HTTPHEADER => array(
  47. 'DOLAPIKEY: '.$this->API_KEY
  48. ),
  49. ));
  50. $response = curl_exec($curl);
  51. curl_close($curl);
  52. $products = [];
  53. $response = json_decode($response, true);
  54. foreach ($response as $group) {
  55. foreach ($group as $key => $categories) {
  56. foreach ($categories as $item) {
  57. $product = [];
  58. $product['id'] = $item['id'];
  59. $product['name'] = $item['label'];
  60. $product['price'] = $item['price'];
  61. $products[$key]['products'][] = $product;
  62. }
  63. $products[$key]['label'] = $products[$key]['products'][0]['name'];
  64. $products[$key]['key'] = $key;
  65. }
  66. }
  67. //$data = json_encode($products, true);
  68. return $products;
  69. }
  70. public function getEventsList($groupID, $eventID='') {
  71. $curl = curl_init();
  72. curl_setopt_array($curl, array(
  73. CURLOPT_URL => $this->API.'/affiliateapi/events?group_id='.$groupID.'&groupByDate=1',
  74. CURLOPT_RETURNTRANSFER => true,
  75. CURLOPT_ENCODING => '',
  76. CURLOPT_MAXREDIRS => 10,
  77. CURLOPT_TIMEOUT => 0,
  78. CURLOPT_FOLLOWLOCATION => true,
  79. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  80. CURLOPT_CUSTOMREQUEST => 'GET',
  81. CURLOPT_HTTPHEADER => array(
  82. 'DOLAPIKEY: '.$this->API_KEY
  83. ),
  84. ));
  85. $response = curl_exec($curl);
  86. curl_close($curl);
  87. $events = [];
  88. $response = json_decode($response, true);
  89. foreach ($response as $key => $item) {
  90. $event = [];
  91. $event['key'] = $key;
  92. /*if ($key != $eventID) {
  93. continue;
  94. }*/
  95. foreach ($item as $subkey => $subitem) {
  96. $sub = [];
  97. $date = explode(' ', $subkey);
  98. $sub['id'] = $subitem['id'];
  99. $sub['label'] = $subitem['label'];
  100. $sub['description'] = $subitem['description'];
  101. $sub['date'] = $date[0];
  102. $sub['time'] = substr($date[1],0,-3);
  103. $sub['max_num'] = $subitem['max_num'];
  104. $sub['participants'] = $subitem['participants'];
  105. $sub['available'] = $subitem['max_num'] - $subitem['participants'];
  106. $event['dates'][] = $sub;
  107. }
  108. $event['label'] = $event['dates'][0]['label'];
  109. $event['description'] = $event['dates'][0]['description'];
  110. $event['date'] = $event['dates'][0]['date'];
  111. $event['time'] = $event['dates'][0]['time'];
  112. $event['available'] = $event['dates'][0]['available'];
  113. $events[] = $event;
  114. }
  115. //$data = json_encode($events, true);
  116. return $events;
  117. }
  118. public function getEventsListByGroup($groupID, $eventID) {
  119. $curl = curl_init();
  120. curl_setopt_array($curl, array(
  121. CURLOPT_URL => $this->API.'/affiliateapi/events?group_id='.$groupID.'&groupByDate=1',
  122. CURLOPT_RETURNTRANSFER => true,
  123. CURLOPT_ENCODING => '',
  124. CURLOPT_MAXREDIRS => 10,
  125. CURLOPT_TIMEOUT => 0,
  126. CURLOPT_FOLLOWLOCATION => true,
  127. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  128. CURLOPT_CUSTOMREQUEST => 'GET',
  129. CURLOPT_HTTPHEADER => array(
  130. 'DOLAPIKEY: '.$this->API_KEY
  131. ),
  132. ));
  133. $response = curl_exec($curl);
  134. curl_close($curl);
  135. $events = [];
  136. $response = json_decode($response, true);
  137. foreach ($response as $key => $item) {
  138. $event = [];
  139. $event['key'] = $key;
  140. if ($key != $eventID) {
  141. continue;
  142. }
  143. foreach ($item as $subkey => $subitem) {
  144. $sub = [];
  145. $date = explode(' ', $subkey);
  146. $sub['id'] = $subitem['id'];
  147. $sub['label'] = $subitem['label'];
  148. $sub['description'] = $subitem['description'];
  149. $sub['date'] = $date[0];
  150. $sub['time'] = substr($date[1],0,-3);
  151. $sub['max_num'] = $subitem['max_num'];
  152. $sub['participants'] = $subitem['participants'];
  153. $sub['available'] = $subitem['max_num'] - $subitem['participants'];
  154. $event['dates'][] = $sub;
  155. }
  156. $event['label'] = $event['dates'][0]['label'];
  157. $event['description'] = $event['dates'][0]['description'];
  158. $event['date'] = $event['dates'][0]['date'];
  159. $event['time'] = $event['dates'][0]['time'];
  160. $event['available'] = $event['dates'][0]['available'];
  161. $events[] = $event;
  162. }
  163. //$data = json_encode($events, true);
  164. return $events;
  165. }
  166. private function getAllEventsListByGroup($groupID) {
  167. $curl = curl_init();
  168. curl_setopt_array($curl, array(
  169. CURLOPT_URL => $this->API.'/affiliateapi/events?group_id='.$groupID.'&groupByDate=1',
  170. CURLOPT_RETURNTRANSFER => true,
  171. CURLOPT_ENCODING => '',
  172. CURLOPT_MAXREDIRS => 10,
  173. CURLOPT_TIMEOUT => 0,
  174. CURLOPT_FOLLOWLOCATION => true,
  175. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  176. CURLOPT_CUSTOMREQUEST => 'GET',
  177. CURLOPT_HTTPHEADER => array(
  178. 'DOLAPIKEY: '.$this->API_KEY
  179. ),
  180. ));
  181. $response = curl_exec($curl);
  182. curl_close($curl);
  183. $eventsByKey = [];
  184. $response = json_decode($response, true);
  185. foreach ($response as $key => $item) {
  186. $event = [];
  187. $event['key'] = $key;
  188. foreach ($item as $subkey => $subitem) {
  189. $sub = [];
  190. $date = explode(' ', $subkey);
  191. $sub['id'] = $subitem['id'];
  192. $sub['label'] = $subitem['label'];
  193. $sub['description'] = $subitem['description'];
  194. $sub['date'] = $date[0];
  195. $sub['time'] = substr($date[1],0,-3);
  196. $sub['max_num'] = $subitem['max_num'];
  197. $sub['participants'] = $subitem['participants'];
  198. $sub['available'] = $subitem['max_num'] - $subitem['participants'];
  199. $event['dates'][] = $sub;
  200. }
  201. $event['label'] = $event['dates'][0]['label'];
  202. $event['description'] = $event['dates'][0]['description'];
  203. $event['date'] = $event['dates'][0]['date'];
  204. $event['time'] = $event['dates'][0]['time'];
  205. $event['available'] = $event['dates'][0]['available'];
  206. $eventsByKey[$key] = $event;
  207. }
  208. return $eventsByKey;
  209. }
  210. public function getMenusList($eventID) {
  211. $curl = curl_init();
  212. curl_setopt_array($curl, array(
  213. CURLOPT_URL => $this->API.'/affiliateapi/menus?eventDetailId='.$eventID,
  214. CURLOPT_RETURNTRANSFER => true,
  215. CURLOPT_ENCODING => '',
  216. CURLOPT_MAXREDIRS => 10,
  217. CURLOPT_TIMEOUT => 0,
  218. CURLOPT_FOLLOWLOCATION => true,
  219. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  220. CURLOPT_CUSTOMREQUEST => 'GET',
  221. CURLOPT_HTTPHEADER => array(
  222. 'DOLAPIKEY: '.$this->API_KEY
  223. ),
  224. ));
  225. $response = curl_exec($curl);
  226. curl_close($curl);
  227. $response = json_decode($response, true);
  228. foreach ($response as $key => $item) {
  229. $menu = [];
  230. $menu['id'] = $item['fk_product'];
  231. $menu['label'] = $item['label'];
  232. $menu['description'] = $item['description'];
  233. $menu['price'] = $item['price'];
  234. $menus[] = $menu;
  235. }
  236. //$data = json_encode($events, true);
  237. return $menus;
  238. }
  239. public function getEvents($packageid, $participants) {
  240. $curl = curl_init();
  241. curl_setopt_array($curl, array(
  242. CURLOPT_URL => $this->API.'/affiliateapi/events?id='.$packageid.'&participants='.$participants,
  243. CURLOPT_RETURNTRANSFER => true,
  244. CURLOPT_ENCODING => '',
  245. CURLOPT_MAXREDIRS => 10,
  246. CURLOPT_TIMEOUT => 0,
  247. CURLOPT_FOLLOWLOCATION => true,
  248. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  249. CURLOPT_CUSTOMREQUEST => 'GET',
  250. CURLOPT_HTTPHEADER => array(
  251. 'DOLAPIKEY: '.$this->API_KEY
  252. ),
  253. ));
  254. $response = curl_exec($curl);
  255. curl_close($curl);
  256. $events = [];
  257. $response = json_decode($response, true);
  258. foreach ($response as $item) {
  259. $event = [];
  260. $date_temp = explode(' ', $item['start_date']);
  261. $date_exp = explode('-',$date_temp[0]);
  262. $honap = $date_exp[1] < 10 ? str_replace('0','',$date_exp[1]) : $date_exp[1];
  263. $nap = $date_exp[2] < 10 ? str_replace('0','',$date_exp[2]) : $date_exp[2];
  264. $datum = $date_exp[0] .'-'. $honap .'-'. $nap;
  265. $timePart = substr($date_temp[1], 0, -3);
  266. $event['id'] = $item['id'];
  267. $event['date'] = $datum;
  268. $event['datum'] = $date_temp[0];
  269. $event['time'] = $timePart;
  270. $event['products'] = $item['products'];
  271. $events[] = $event;
  272. }
  273. $data = json_encode($events, true);
  274. return $data;
  275. }
  276. public function getProductImage() {
  277. $id = $this->escapeString($_REQUEST['id']);
  278. $row = $this->query("select * from azonics_products where slide_title='".$id."' AND slide_status='1';");
  279. return $row[0];
  280. }
  281. public function getServices() {
  282. $rows = $this->query("select * from azonics_services where box_status='1';");
  283. $result = [];
  284. foreach ($rows as $row) {
  285. $result[] = $row;
  286. }
  287. return $result;
  288. }
  289. public function getGroupNameByID($groupID) {
  290. $rows = $this->query("select * from azonics_services where box_status='1' AND parent_service='".$groupID."';");
  291. return $rows[0]->box_subtitle;
  292. }
  293. public function getProdutNameByID($productID) {
  294. $rows = $this->query("select * from azonics_services where box_status='1' AND parent_service='".$groupID."';");
  295. return $rows[0]->box_subtitle;
  296. }
  297. public function initializeTransaction() {
  298. $curl = curl_init();
  299. curl_setopt_array($curl, array(
  300. CURLOPT_URL => $this->API.'/affiliateapi/init',
  301. CURLOPT_RETURNTRANSFER => true,
  302. CURLOPT_ENCODING => '',
  303. CURLOPT_MAXREDIRS => 10,
  304. CURLOPT_TIMEOUT => 0,
  305. CURLOPT_FOLLOWLOCATION => true,
  306. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  307. CURLOPT_CUSTOMREQUEST => 'GET',
  308. CURLOPT_HTTPHEADER => array(
  309. 'DOLAPIKEY: '.$this->API_KEY
  310. ),
  311. ));
  312. $response = curl_exec($curl);
  313. $response = str_replace('"','',$response);
  314. curl_close($curl);
  315. return $response;
  316. }
  317. public function startReservation() {
  318. $curl = curl_init();
  319. $post_data = array(
  320. 'uuid' => $_REQUEST['uuid'],
  321. 'event_id' => $_REQUEST['event_id'],
  322. 'qty' => $_REQUEST['qty']
  323. );
  324. curl_setopt_array($curl, array(
  325. CURLOPT_URL => $this->API.'/affiliateapi/reserve',
  326. CURLOPT_RETURNTRANSFER => true,
  327. CURLOPT_ENCODING => '',
  328. CURLOPT_MAXREDIRS => 10,
  329. CURLOPT_TIMEOUT => 0,
  330. CURLOPT_FOLLOWLOCATION => true,
  331. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  332. CURLOPT_CUSTOMREQUEST => 'POST',
  333. CURLOPT_POSTFIELDS => http_build_query($post_data),
  334. CURLOPT_HTTPHEADER => array(
  335. 'DOLAPIKEY: '.$this->API_KEY
  336. ),
  337. ));
  338. $response = curl_exec($curl);
  339. curl_close($curl);
  340. return $response;
  341. }
  342. public function order() {
  343. $data = json_decode($_REQUEST['data']);
  344. $curl = curl_init();
  345. $post_data = $data;
  346. $post_data->uuid = str_replace('"','',$post_data->uuid);
  347. curl_setopt_array($curl, array(
  348. CURLOPT_URL => $this->API.'/affiliateapi/order',
  349. CURLOPT_RETURNTRANSFER => true,
  350. CURLOPT_ENCODING => '',
  351. CURLOPT_MAXREDIRS => 10,
  352. CURLOPT_TIMEOUT => 0,
  353. CURLOPT_FOLLOWLOCATION => true,
  354. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  355. CURLOPT_CUSTOMREQUEST => 'POST',
  356. CURLOPT_POSTFIELDS => json_encode($post_data),
  357. CURLOPT_HTTPHEADER => array(
  358. 'Content-Type: application/json',
  359. 'DOLAPIKEY: '.$this->API_KEY
  360. ),
  361. ));
  362. //print_r(json_encode($post_data));
  363. //die();
  364. $response = curl_exec($curl);
  365. curl_close($curl);
  366. return $response;
  367. }
  368. public function paymentstatus() {
  369. $curl = curl_init();
  370. curl_setopt_array($curl, array(
  371. CURLOPT_URL => $this->API.'/affiliateapi/paymentstatus?uuid='.$_REQUEST['uuid'],
  372. CURLOPT_RETURNTRANSFER => true,
  373. CURLOPT_ENCODING => '',
  374. CURLOPT_MAXREDIRS => 10,
  375. CURLOPT_TIMEOUT => 0,
  376. CURLOPT_FOLLOWLOCATION => true,
  377. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  378. CURLOPT_CUSTOMREQUEST => 'GET',
  379. CURLOPT_HTTPHEADER => array(
  380. 'DOLAPIKEY: '.$this->API_KEY
  381. ),
  382. ));
  383. $response = curl_exec($curl);
  384. curl_close($curl);
  385. return $response;
  386. }
  387. public function getProviderDetails() {
  388. $curl = curl_init();
  389. curl_setopt_array($curl, array(
  390. CURLOPT_URL => $this->API.'/affiliateapi/getCustomerData',
  391. CURLOPT_RETURNTRANSFER => true,
  392. CURLOPT_ENCODING => '',
  393. CURLOPT_MAXREDIRS => 10,
  394. CURLOPT_TIMEOUT => 0,
  395. CURLOPT_FOLLOWLOCATION => true,
  396. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  397. CURLOPT_CUSTOMREQUEST => 'GET',
  398. CURLOPT_HTTPHEADER => array(
  399. 'DOLAPIKEY: '.$this->API_KEY
  400. ),
  401. ));
  402. $response = curl_exec($curl);
  403. curl_close($curl);
  404. return $response;
  405. }
  406. public function getLabels($lang = 'hu') {
  407. $rows = $this->query("select
  408. setting_name,
  409. setting_value_text,
  410. setting_value_text_en,
  411. setting_status from azonics_settings where setting_status='1';");
  412. foreach ($rows as $row) {
  413. if ($lang == 'en') {
  414. $row->setting_value_text = $row->setting_value_text_en;
  415. }
  416. $results[] = $row;
  417. }
  418. return $results;
  419. }
  420. public function getGroups($lang = 'hu') {
  421. $rows = $this->query("SELECT * FROM `azonics_services` WHERE box_status=1;");
  422. foreach ($rows as $row) {
  423. if ($lang == 'en') {
  424. $row->box_subtitle = $row->box_subtitle_en;
  425. $row->box_title = $row->box_button_text_en;
  426. }
  427. $results[] = $row;
  428. }
  429. return $results;
  430. }
  431. public function getGroupID($groupKey) {
  432. $row = $this->query("SELECT * FROM `azonics_services` WHERE box_status=1 AND box_title_en='".$groupKey."';");
  433. return $row[0]->parent_service;
  434. }
  435. public function getLowestEventprice($eventID) {
  436. $events = $this->getMenusList($eventID);
  437. foreach ($events as $event) {
  438. if (!isset($lowest) || $event['price'] < $lowest) {
  439. $lowest = $event['price'];
  440. }
  441. }
  442. return formatize::currency(round($lowest));
  443. }
  444. private function fetchLowestPrices($eventIDs) {
  445. $multiHandle = curl_multi_init();
  446. $handles = [];
  447. foreach ($eventIDs as $eventID) {
  448. $ch = curl_init();
  449. curl_setopt_array($ch, array(
  450. CURLOPT_URL => $this->API.'/affiliateapi/menus?eventDetailId='.$eventID,
  451. CURLOPT_RETURNTRANSFER => true,
  452. CURLOPT_ENCODING => '',
  453. CURLOPT_MAXREDIRS => 10,
  454. CURLOPT_TIMEOUT => 30,
  455. CURLOPT_FOLLOWLOCATION => true,
  456. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  457. CURLOPT_CUSTOMREQUEST => 'GET',
  458. CURLOPT_HTTPHEADER => array(
  459. 'DOLAPIKEY: '.$this->API_KEY
  460. ),
  461. ));
  462. $handles[$eventID] = $ch;
  463. curl_multi_add_handle($multiHandle, $ch);
  464. }
  465. $running = null;
  466. do {
  467. curl_multi_exec($multiHandle, $running);
  468. curl_multi_select($multiHandle);
  469. } while ($running > 0);
  470. $prices = [];
  471. foreach ($handles as $eventID => $ch) {
  472. $response = curl_multi_getcontent($ch);
  473. $menus = json_decode($response, true);
  474. $lowest = null;
  475. if (is_array($menus)) {
  476. foreach ($menus as $item) {
  477. if ($lowest === null || $item['price'] < $lowest) {
  478. $lowest = $item['price'];
  479. }
  480. }
  481. }
  482. $prices[$eventID] = $lowest !== null ? formatize::currency(round($lowest)) : '';
  483. curl_multi_remove_handle($multiHandle, $ch);
  484. curl_close($ch);
  485. }
  486. curl_multi_close($multiHandle);
  487. return $prices;
  488. }
  489. public function getEventsData($groupID, $lang = 'hu') {
  490. $parentID = $this->getGroupID($groupID);
  491. $rows = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1 AND parent_service=".$parentID.";");
  492. if (empty($rows)) {
  493. return [];
  494. }
  495. // 1) Egyetlen API hívás az összes event date-hez (N cURL → 1 cURL)
  496. $allEventsByKey = $this->getAllEventsListByGroup($groupID);
  497. // 2) Egyetlen DB query az összes image-hez (N query → 1 query)
  498. $boxIds = [];
  499. foreach ($rows as $row) {
  500. $boxIds[] = $row->box_id;
  501. }
  502. $allImages = $this->query("SELECT * FROM `azonics_events_blocks` WHERE block_status=1 AND box_id IN (".implode(',', $boxIds).");");
  503. $imagesByBoxId = [];
  504. foreach ($allImages as $img) {
  505. $imagesByBoxId[$img->box_id][] = $img;
  506. }
  507. // 3) Párhuzamos menu API hívások az árakhoz (N szekvenciális → N párhuzamos cURL)
  508. $eventIDs = [];
  509. foreach ($rows as $row) {
  510. $eventIDs[] = $row->parent_event;
  511. }
  512. $lowestPrices = $this->fetchLowestPrices($eventIDs);
  513. $results = [];
  514. foreach ($rows as $row) {
  515. $row->parent_price = isset($lowestPrices[$row->parent_event]) ? $lowestPrices[$row->parent_event] : '';
  516. $row->images = isset($imagesByBoxId[$row->box_id]) ? $imagesByBoxId[$row->box_id] : [];
  517. $row->dates = isset($allEventsByKey[$row->parent_event]) ? [$allEventsByKey[$row->parent_event]] : [];
  518. if ($lang == 'en') {
  519. $row->box_title = $row->box_title_en;
  520. $row->box_subtitle = $row->box_subtitle_en;
  521. }
  522. if (count($row->dates) < 1) {
  523. continue;
  524. }
  525. $results[] = $row;
  526. }
  527. return $results;
  528. }
  529. public function getEventMenus($eventID, $lang = 'hu') {
  530. $rows = $this->query("SELECT * FROM `azonics_packages` WHERE box_status=1 AND parent_event=".$eventID." ORDER BY box_order ASC;");
  531. $menus = $this->getMenusList($eventID);
  532. foreach ($rows as $row) {
  533. $images = $this->query("SELECT * FROM `azonics_package_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  534. $row->images = $images;
  535. foreach ($menus as $menu) {
  536. if ($menu['id'] == $row->parent_menu) {
  537. $row->parent_price = $menu['price'];
  538. }
  539. }
  540. if ($lang == 'en') {
  541. $row->box_title = $row->box_title_en;
  542. $row->box_subtitle = $row->box_subtitle_en;
  543. }
  544. if (count($images) > 0) {
  545. $results[] = $row;
  546. }
  547. }
  548. return $results;
  549. }
  550. public function getEventName($groupID, $eventID) {
  551. $row = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1 AND parent_service=".$groupID." AND parent_event=".$eventID.";");
  552. return $row[0]->box_title;
  553. }
  554. public function getEventsRawList() {
  555. $rows = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1;");
  556. return $rows;
  557. }
  558. public function getProductsData($groupID, $lang = 'hu') {
  559. $items = $this->getProductsList($groupID);
  560. $rows = $this->query("SELECT * FROM `azonics_prods` WHERE box_status=1 AND parent_service=".$groupID.";");
  561. foreach ($rows as $row) {
  562. $images = $this->query("SELECT * FROM `azonics_prods_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  563. $row->images = $images;
  564. $row->items = $items[$row->parent_prods]['products'];
  565. if ($lang == 'en') {
  566. $row->box_title = $row->box_title_en;
  567. $row->box_subtitle = $row->box_subtitle_en;
  568. }
  569. $results[] = $row;
  570. }
  571. return $results;
  572. }
  573. public function getContent($slug, $lang = 'hu') {
  574. $row = $this->query("SELECT * FROM `azonics_blog` WHERE page_status=1 AND page_slug='".$slug."';");
  575. if ($lang == 'en') {
  576. $row[0]->page_title = $row[0]->page_title_en;
  577. $row[0]->page_content = $row[0]->page_content_en;
  578. }
  579. return $row[0];
  580. }
  581. public function getUID() {
  582. $curl = curl_init();
  583. curl_setopt_array($curl, array(
  584. CURLOPT_URL => $this->API.'/affiliateapi/init',
  585. CURLOPT_RETURNTRANSFER => true,
  586. CURLOPT_ENCODING => '',
  587. CURLOPT_MAXREDIRS => 10,
  588. CURLOPT_TIMEOUT => 0,
  589. CURLOPT_FOLLOWLOCATION => true,
  590. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  591. CURLOPT_CUSTOMREQUEST => 'GET',
  592. CURLOPT_HTTPHEADER => array(
  593. 'DOLAPIKEY: '.$this->API_KEY
  594. ),
  595. ));
  596. $response = curl_exec($curl);
  597. curl_close($curl);
  598. return $response;
  599. }
  600. public function reserveEvent($uuid, $eventID, $qty) {
  601. $curl = curl_init();
  602. $post_data = array('uuid' => $uuid, 'event_id' => $eventID, 'qty' => $qty);
  603. curl_setopt_array($curl, array(
  604. CURLOPT_URL => $this->API.'/affiliateapi/reserve',
  605. CURLOPT_RETURNTRANSFER => true,
  606. CURLOPT_ENCODING => '',
  607. CURLOPT_MAXREDIRS => 10,
  608. CURLOPT_TIMEOUT => 0,
  609. CURLOPT_FOLLOWLOCATION => true,
  610. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  611. CURLOPT_CUSTOMREQUEST => 'POST',
  612. CURLOPT_POSTFIELDS => json_encode($post_data),
  613. CURLOPT_HTTPHEADER => array(
  614. 'Content-Type:application/json',
  615. 'DOLAPIKEY: '.$this->API_KEY
  616. ),
  617. ));
  618. $response = curl_exec($curl);
  619. curl_close($curl);
  620. return json_decode($response);
  621. }
  622. public function getAllHotels() {
  623. $curl = curl_init();
  624. $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
  625. curl_setopt_array($curl, array(
  626. CURLOPT_URL => $url,
  627. CURLOPT_RETURNTRANSFER => true,
  628. CURLOPT_ENCODING => '',
  629. CURLOPT_MAXREDIRS => 10,
  630. CURLOPT_TIMEOUT => 0,
  631. CURLOPT_FOLLOWLOCATION => true,
  632. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  633. CURLOPT_CUSTOMREQUEST => 'GET',
  634. CURLOPT_HTTPHEADER => array(
  635. 'DOLAPIKEY: '.$this->API_KEY
  636. ),
  637. ));
  638. $response = curl_exec($curl);
  639. curl_close($curl);
  640. $groups = [];
  641. $response = json_decode($response, true);
  642. foreach ($response as $key => $value) {
  643. if ($allHotels === false ) {
  644. if ($value['contracted_partner'] == 1) {
  645. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  646. }
  647. }
  648. else if ($allHotels === true) {
  649. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  650. }
  651. }
  652. return $options;
  653. }
  654. public function getAllPartner() {
  655. $curl = curl_init();
  656. $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
  657. curl_setopt_array($curl, array(
  658. CURLOPT_URL => $url,
  659. CURLOPT_RETURNTRANSFER => true,
  660. CURLOPT_ENCODING => '',
  661. CURLOPT_MAXREDIRS => 10,
  662. CURLOPT_TIMEOUT => 0,
  663. CURLOPT_FOLLOWLOCATION => true,
  664. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  665. CURLOPT_CUSTOMREQUEST => 'GET',
  666. CURLOPT_HTTPHEADER => array(
  667. 'DOLAPIKEY: '.$this->API_KEY
  668. ),
  669. ));
  670. $response = curl_exec($curl);
  671. curl_close($curl);
  672. $groups = [];
  673. $response = json_decode($response, true);
  674. foreach ($response as $key => $value) {
  675. $options[] = array('id' => $value['id'], 'key' => $key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  676. }
  677. return $options;
  678. }
  679. public function getAllContractedPartner() {
  680. $curl = curl_init();
  681. $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
  682. curl_setopt_array($curl, array(
  683. CURLOPT_URL => $url,
  684. CURLOPT_RETURNTRANSFER => true,
  685. CURLOPT_ENCODING => '',
  686. CURLOPT_MAXREDIRS => 10,
  687. CURLOPT_TIMEOUT => 0,
  688. CURLOPT_FOLLOWLOCATION => true,
  689. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  690. CURLOPT_CUSTOMREQUEST => 'GET',
  691. CURLOPT_HTTPHEADER => array(
  692. 'DOLAPIKEY: '.$this->API_KEY
  693. ),
  694. ));
  695. $response = curl_exec($curl);
  696. curl_close($curl);
  697. $groups = [];
  698. $response = json_decode($response, true);
  699. foreach ($response as $key => $value) {
  700. if ($value['contracted_partner'] == 1) {
  701. $options[] = array('id' => $value['id'], 'key' => $key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  702. }
  703. }
  704. return $options;
  705. }
  706. public function getHotels($allHotels = false) {
  707. $curl = curl_init();
  708. $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
  709. curl_setopt_array($curl, array(
  710. CURLOPT_URL => $url,
  711. CURLOPT_RETURNTRANSFER => true,
  712. CURLOPT_ENCODING => '',
  713. CURLOPT_MAXREDIRS => 10,
  714. CURLOPT_TIMEOUT => 0,
  715. CURLOPT_FOLLOWLOCATION => true,
  716. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  717. CURLOPT_CUSTOMREQUEST => 'GET',
  718. CURLOPT_HTTPHEADER => array(
  719. 'DOLAPIKEY: '.$this->API_KEY
  720. ),
  721. ));
  722. $response = curl_exec($curl);
  723. curl_close($curl);
  724. $groups = [];
  725. $response = json_decode($response, true);
  726. foreach ($response as $key => $value) {
  727. if ($allHotels === false ) {
  728. if ($value['contracted_partner'] == 1) {
  729. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  730. }
  731. }
  732. else if ($allHotels === true) {
  733. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  734. }
  735. }
  736. return $options;
  737. }
  738. public function checkout($data) {
  739. $curl = curl_init();
  740. curl_setopt_array($curl, array(
  741. CURLOPT_URL => $this->API.'/affiliateapi/order',
  742. CURLOPT_RETURNTRANSFER => true,
  743. CURLOPT_ENCODING => '',
  744. CURLOPT_MAXREDIRS => 10,
  745. CURLOPT_TIMEOUT => 0,
  746. CURLOPT_FOLLOWLOCATION => true,
  747. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  748. CURLOPT_CUSTOMREQUEST => 'POST',
  749. CURLOPT_POSTFIELDS => json_encode($data),
  750. CURLOPT_HTTPHEADER => array(
  751. 'Content-Type:application/json',
  752. 'DOLAPIKEY: '.$this->API_KEY
  753. ),
  754. ));
  755. $response = curl_exec($curl);
  756. curl_close($curl);
  757. return json_decode($response);
  758. }
  759. public function getCountries() {
  760. $curl = curl_init();
  761. curl_setopt_array($curl, array(
  762. CURLOPT_URL => $this->API.'/setup/dictionary/countries?sortfield=code&sortorder=ASC&limit=3000',
  763. CURLOPT_RETURNTRANSFER => true,
  764. CURLOPT_ENCODING => '',
  765. CURLOPT_MAXREDIRS => 10,
  766. CURLOPT_TIMEOUT => 0,
  767. CURLOPT_FOLLOWLOCATION => true,
  768. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  769. CURLOPT_CUSTOMREQUEST => 'GET',
  770. CURLOPT_HTTPHEADER => array(
  771. 'DOLAPIKEY: '.$this->API_KEY
  772. ),
  773. ));
  774. $response = curl_exec($curl);
  775. curl_close($curl);
  776. $options = [];
  777. $response = json_decode($response, true);
  778. if (is_array($response)) {
  779. usort($response, function($a, $b) {
  780. $la = isset($a['label']) ? mb_strtolower($a['label'], 'UTF-8') : '';
  781. $lb = isset($b['label']) ? mb_strtolower($b['label'], 'UTF-8') : '';
  782. return $la <=> $lb;
  783. });
  784. }
  785. foreach ($response as $value) {
  786. $options[] = array('key' => $value['id'].'_'.$value['code'], 'value' => $value['label']);
  787. }
  788. return $options;
  789. }
  790. public function getPaymentStatus($uuid) {
  791. $curl = curl_init();
  792. curl_setopt_array($curl, array(
  793. CURLOPT_URL => $this->API.'/affiliateapi/paymentstatus?uuid='.$uuid,
  794. CURLOPT_RETURNTRANSFER => true,
  795. CURLOPT_ENCODING => '',
  796. CURLOPT_MAXREDIRS => 10,
  797. CURLOPT_TIMEOUT => 0,
  798. CURLOPT_FOLLOWLOCATION => true,
  799. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  800. CURLOPT_CUSTOMREQUEST => 'GET',
  801. CURLOPT_HTTPHEADER => array(
  802. 'DOLAPIKEY: '.$this->API_KEY
  803. ),
  804. ));
  805. $response = curl_exec($curl);
  806. curl_close($curl);
  807. $response = json_decode($response, true);
  808. return $response;
  809. }
  810. public function authenticateUser($username, $password) {
  811. $row = $this->query("SELECT * FROM `azonics_admin_users` WHERE admin_pass='".$password."' AND (admin_email='".$username."' OR admin_name='".$username."') AND admin_status='1';");
  812. if (count($row) == 0) {
  813. return ['success' => false];
  814. }
  815. else {
  816. return [
  817. 'success' => true,
  818. 'name' => $row[0]->admin_name,
  819. 'hotel' => $row[0]->admin_dashboard
  820. ];
  821. }
  822. }
  823. public function getMonthRevenue($hotelIDs, $actualMonth = 0) {
  824. $curl = curl_init();
  825. $postfix = '';
  826. if ($actualMonth == 1) {
  827. $postfix = '&actualMonth='.$actualMonth;
  828. }
  829. curl_setopt_array($curl, array(
  830. CURLOPT_URL => $this->API.'/affiliateapi/getAmount?hotelids='.$hotelIDs.$postfix,
  831. CURLOPT_RETURNTRANSFER => true,
  832. CURLOPT_ENCODING => '',
  833. CURLOPT_MAXREDIRS => 10,
  834. CURLOPT_TIMEOUT => 0,
  835. CURLOPT_FOLLOWLOCATION => true,
  836. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  837. CURLOPT_CUSTOMREQUEST => 'GET',
  838. CURLOPT_HTTPHEADER => array(
  839. 'DOLAPIKEY: '.$this->API_KEY
  840. ),
  841. ));
  842. $response = curl_exec($curl);
  843. curl_close($curl);
  844. $result = json_decode($response);
  845. return $result;
  846. }
  847. public function createOrderDetails($data) {
  848. $this->execute("INSERT INTO `azonics_orders` SET
  849. order_uuid = '".$data['order_uuid']."',
  850. order_hotel = '".$data['order_hotel']."',
  851. order_sales = '".$data['order_sales']."',
  852. order_cart = '".serialize($data['order_cart'])."',
  853. order_customer_fname = '".$data['order_customer_fname']."',
  854. order_customer_lname = '".$data['order_customer_lname']."',
  855. order_customer_email = '".$data['order_customer_email']."',
  856. order_customer_city = '".$data['order_customer_city']."',
  857. order_customer_country = '".$data['order_customer_country']."',
  858. order_customer_zip = '".$data['order_customer_zip']."',
  859. order_customer_street = '".$data['order_customer_street']."',
  860. order_customer_house = '".$data['order_customer_house']."',
  861. order_customer_phone = '".$data['order_customer_phone']."',
  862. order_customer_hotel = '".$data['order_customer_hotel']."',
  863. order_customer_ip = '".$data['order_customer_ip']."',
  864. order_customer_browser = '".$data['order_customer_browser']."',
  865. order_terms_accepted = 1,
  866. order_status = 1;");
  867. return $this->getLastInsertID();
  868. }
  869. public function updateOrderDetails($data) {
  870. $this->execute("UPDATE azonics_orders SET
  871. order_transaction_id = '".$data['order_transaction_id']."',
  872. order_auth_code = '".$data['order_auth_code']."',
  873. order_error_code = '".$data['order_error_code']."',
  874. order_error_message = '".$data['order_error_message']."' WHERE order_id = '".$data['order_id']."';");
  875. return $data['order_id'];
  876. }
  877. public function getReports() {
  878. $hotels = $this->getAllPartner();
  879. $reports = [];
  880. $userData = unserialize($_SESSION['admin_user']->admin_dashboard);
  881. $ids = [];
  882. foreach ($userData as $hotelID) {
  883. foreach ($hotels as $hotel) {
  884. if ($hotel['key'] == $hotelID) {
  885. $ids[] = $hotel['id'];
  886. $reports[] = [
  887. 'id' => $hotel['id'],
  888. 'hotel' => $hotel['value'],
  889. 'actual_month' => '',
  890. 'last_month' => ''
  891. ];
  892. }
  893. }
  894. }
  895. $actualMonth = $this->getMonthRevenue(implode(',',$ids), 1);
  896. $lastMonth = $this->getMonthRevenue(implode(',',$ids), 0);
  897. foreach ($reports as $key => $report) {
  898. foreach ($actualMonth as $id => $item) {
  899. if ($id == $report['id']) {
  900. $reports[$key]['actual_month'] = $item;
  901. }
  902. }
  903. foreach ($lastMonth as $id => $item) {
  904. if ($id == $report['id']) {
  905. $reports[$key]['last_month'] = $item;
  906. }
  907. }
  908. }
  909. return $reports;
  910. }
  911. public function getQRCodes($orderID) {
  912. $curl = curl_init();
  913. curl_setopt_array($curl, array(
  914. CURLOPT_URL => $this->API.'/affiliateapi/getSaledItemsQR?sendid='.$orderID,
  915. CURLOPT_RETURNTRANSFER => true,
  916. CURLOPT_ENCODING => '',
  917. CURLOPT_MAXREDIRS => 10,
  918. CURLOPT_TIMEOUT => 0,
  919. CURLOPT_FOLLOWLOCATION => true,
  920. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  921. CURLOPT_CUSTOMREQUEST => 'GET',
  922. CURLOPT_HTTPHEADER => array(
  923. 'DOLAPIKEY: '.$this->API_KEY
  924. ),
  925. ));
  926. $response = curl_exec($curl);
  927. curl_close($curl);
  928. $groups = [];
  929. $response = json_decode($response, true);
  930. foreach ($response as $key => $item) {
  931. $group = [];
  932. $group['id'] = $key;
  933. $group['label'] = $item;
  934. $groups[] = $group;
  935. }
  936. //$data = json_encode($groups, true);
  937. return $groups;
  938. }
  939. }