api_model.php 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  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 getTransactionStatusFromSimplePay($uuid) {
  811. $curl = curl_init();
  812. curl_setopt_array($curl, array(
  813. CURLOPT_URL => $this->API.'/affiliateapi/getTransactionStatusFromSimplePay?uuid='.$uuid,
  814. CURLOPT_RETURNTRANSFER => true,
  815. CURLOPT_ENCODING => '',
  816. CURLOPT_MAXREDIRS => 10,
  817. CURLOPT_TIMEOUT => 0,
  818. CURLOPT_FOLLOWLOCATION => true,
  819. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  820. CURLOPT_CUSTOMREQUEST => 'GET',
  821. CURLOPT_HTTPHEADER => array(
  822. 'DOLAPIKEY: '.$this->API_KEY
  823. ),
  824. ));
  825. $response = curl_exec($curl);
  826. curl_close($curl);
  827. $response = json_decode($response, true);
  828. return $response;
  829. }
  830. public function validateUUID($uuid) {
  831. $curl = curl_init();
  832. curl_setopt_array($curl, array(
  833. CURLOPT_URL => $this->API.'/affiliateapi/CheckUUIDValidation?uuid='.$uuid,
  834. CURLOPT_RETURNTRANSFER => true,
  835. CURLOPT_ENCODING => '',
  836. CURLOPT_MAXREDIRS => 10,
  837. CURLOPT_TIMEOUT => 0,
  838. CURLOPT_FOLLOWLOCATION => true,
  839. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  840. CURLOPT_CUSTOMREQUEST => 'GET',
  841. CURLOPT_HTTPHEADER => array(
  842. 'DOLAPIKEY: '.$this->API_KEY
  843. ),
  844. ));
  845. $response = curl_exec($curl);
  846. print_r($response);
  847. die();
  848. curl_close($curl);
  849. $response = json_decode($response, true);
  850. return $response;
  851. }
  852. public function authenticateUser($username, $password) {
  853. $row = $this->query("SELECT * FROM `azonics_admin_users` WHERE admin_pass='".$password."' AND (admin_email='".$username."' OR admin_name='".$username."') AND admin_status='1';");
  854. if (count($row) == 0) {
  855. return ['success' => false];
  856. }
  857. else {
  858. return [
  859. 'success' => true,
  860. 'name' => $row[0]->admin_name,
  861. 'hotel' => $row[0]->admin_dashboard
  862. ];
  863. }
  864. }
  865. public function getMonthRevenue($hotelIDs, $actualMonth = 0) {
  866. $curl = curl_init();
  867. $postfix = '';
  868. if ($actualMonth == 1) {
  869. $postfix = '&actualMonth='.$actualMonth;
  870. }
  871. curl_setopt_array($curl, array(
  872. CURLOPT_URL => $this->API.'/affiliateapi/getAmount?hotelids='.$hotelIDs.$postfix,
  873. CURLOPT_RETURNTRANSFER => true,
  874. CURLOPT_ENCODING => '',
  875. CURLOPT_MAXREDIRS => 10,
  876. CURLOPT_TIMEOUT => 0,
  877. CURLOPT_FOLLOWLOCATION => true,
  878. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  879. CURLOPT_CUSTOMREQUEST => 'GET',
  880. CURLOPT_HTTPHEADER => array(
  881. 'DOLAPIKEY: '.$this->API_KEY
  882. ),
  883. ));
  884. $response = curl_exec($curl);
  885. curl_close($curl);
  886. $result = json_decode($response);
  887. return $result;
  888. }
  889. public function createOrderDetails($data) {
  890. $this->execute("INSERT INTO `azonics_orders` SET
  891. order_uuid = '".$data['order_uuid']."',
  892. order_hotel = '".$data['order_hotel']."',
  893. order_sales = '".$data['order_sales']."',
  894. order_cart = '".serialize($data['order_cart'])."',
  895. order_customer_fname = '".$data['order_customer_fname']."',
  896. order_customer_lname = '".$data['order_customer_lname']."',
  897. order_customer_email = '".$data['order_customer_email']."',
  898. order_customer_city = '".$data['order_customer_city']."',
  899. order_customer_country = '".$data['order_customer_country']."',
  900. order_customer_zip = '".$data['order_customer_zip']."',
  901. order_customer_street = '".$data['order_customer_street']."',
  902. order_customer_house = '".$data['order_customer_house']."',
  903. order_customer_phone = '".$data['order_customer_phone']."',
  904. order_customer_hotel = '".$data['order_customer_hotel']."',
  905. order_customer_ip = '".$data['order_customer_ip']."',
  906. order_customer_browser = '".$data['order_customer_browser']."',
  907. order_terms_accepted = 1,
  908. order_status = 1;");
  909. return $this->getLastInsertID();
  910. }
  911. public function updateOrderDetails($data) {
  912. $this->execute("UPDATE azonics_orders SET
  913. order_transaction_id = '".$data['order_transaction_id']."',
  914. order_auth_code = '".$data['order_auth_code']."',
  915. order_error_code = '".$data['order_error_code']."',
  916. order_error_message = '".$data['order_error_message']."' WHERE order_id = '".$data['order_id']."';");
  917. return $data['order_id'];
  918. }
  919. public function getReports() {
  920. $hotels = $this->getAllPartner();
  921. $reports = [];
  922. $userData = unserialize($_SESSION['admin_user']->admin_dashboard);
  923. $ids = [];
  924. foreach ($userData as $hotelID) {
  925. foreach ($hotels as $hotel) {
  926. if ($hotel['key'] == $hotelID) {
  927. $ids[] = $hotel['id'];
  928. $reports[] = [
  929. 'id' => $hotel['id'],
  930. 'hotel' => $hotel['value'],
  931. 'actual_month' => '',
  932. 'last_month' => ''
  933. ];
  934. }
  935. }
  936. }
  937. $actualMonth = $this->getMonthRevenue(implode(',',$ids), 1);
  938. $lastMonth = $this->getMonthRevenue(implode(',',$ids), 0);
  939. foreach ($reports as $key => $report) {
  940. foreach ($actualMonth as $id => $item) {
  941. if ($id == $report['id']) {
  942. $reports[$key]['actual_month'] = $item;
  943. }
  944. }
  945. foreach ($lastMonth as $id => $item) {
  946. if ($id == $report['id']) {
  947. $reports[$key]['last_month'] = $item;
  948. }
  949. }
  950. }
  951. return $reports;
  952. }
  953. public function getQRCodes($orderID) {
  954. $curl = curl_init();
  955. curl_setopt_array($curl, array(
  956. CURLOPT_URL => $this->API.'/affiliateapi/getSaledItemsQR?sendid='.$orderID,
  957. CURLOPT_RETURNTRANSFER => true,
  958. CURLOPT_ENCODING => '',
  959. CURLOPT_MAXREDIRS => 10,
  960. CURLOPT_TIMEOUT => 0,
  961. CURLOPT_FOLLOWLOCATION => true,
  962. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  963. CURLOPT_CUSTOMREQUEST => 'GET',
  964. CURLOPT_HTTPHEADER => array(
  965. 'DOLAPIKEY: '.$this->API_KEY
  966. ),
  967. ));
  968. $response = curl_exec($curl);
  969. curl_close($curl);
  970. $groups = [];
  971. $response = json_decode($response, true);
  972. foreach ($response as $key => $item) {
  973. $group = [];
  974. $group['id'] = $key;
  975. $group['label'] = $item;
  976. $groups[] = $group;
  977. }
  978. //$data = json_encode($groups, true);
  979. return $groups;
  980. }
  981. }