api_model.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <?php
  2. class api_model extends Model {
  3. const API = $config['api_url'];
  4. const API_KEY = $config['api_key'];
  5. public function getGroupsList() {
  6. $curl = curl_init();
  7. curl_setopt_array($curl, array(
  8. CURLOPT_URL => self::API.'/affiliateapi/groups',
  9. CURLOPT_RETURNTRANSFER => true,
  10. CURLOPT_ENCODING => '',
  11. CURLOPT_MAXREDIRS => 10,
  12. CURLOPT_TIMEOUT => 0,
  13. CURLOPT_FOLLOWLOCATION => true,
  14. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  15. CURLOPT_CUSTOMREQUEST => 'GET',
  16. CURLOPT_HTTPHEADER => array(
  17. 'DOLAPIKEY: '.self::API_KEY
  18. ),
  19. ));
  20. $response = curl_exec($curl);
  21. curl_close($curl);
  22. $groups = [];
  23. $response = json_decode($response, true);
  24. foreach ($response as $key => $item) {
  25. $group = [];
  26. $group['id'] = $key;
  27. $group['label'] = $item;
  28. $groups[] = $group;
  29. }
  30. //$data = json_encode($groups, true);
  31. return $groups;
  32. }
  33. public function getProductsList($groupID) {
  34. $curl = curl_init();
  35. curl_setopt_array($curl, array(
  36. CURLOPT_URL => self::API.'/affiliateapi/products?group_id='.$groupID,
  37. CURLOPT_RETURNTRANSFER => true,
  38. CURLOPT_ENCODING => '',
  39. CURLOPT_MAXREDIRS => 10,
  40. CURLOPT_TIMEOUT => 0,
  41. CURLOPT_FOLLOWLOCATION => true,
  42. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  43. CURLOPT_CUSTOMREQUEST => 'GET',
  44. CURLOPT_HTTPHEADER => array(
  45. 'DOLAPIKEY: '.self::API_KEY
  46. ),
  47. ));
  48. $response = curl_exec($curl);
  49. curl_close($curl);
  50. $products = [];
  51. $response = json_decode($response, true);
  52. foreach ($response as $group) {
  53. foreach ($group as $key => $categories) {
  54. foreach ($categories as $item) {
  55. $product = [];
  56. $product['id'] = $item['id'];
  57. $product['name'] = $item['label'];
  58. $product['price'] = $item['price'];
  59. $products[$key]['products'][] = $product;
  60. }
  61. $products[$key]['label'] = $products[$key]['products'][0]['name'];
  62. $products[$key]['key'] = $key;
  63. }
  64. }
  65. //$data = json_encode($products, true);
  66. return $products;
  67. }
  68. public function getEventsList($groupID) {
  69. $curl = curl_init();
  70. curl_setopt_array($curl, array(
  71. CURLOPT_URL => self::API.'/affiliateapi/events?group_id='.$groupID.'&groupByDate=1',
  72. CURLOPT_RETURNTRANSFER => true,
  73. CURLOPT_ENCODING => '',
  74. CURLOPT_MAXREDIRS => 10,
  75. CURLOPT_TIMEOUT => 0,
  76. CURLOPT_FOLLOWLOCATION => true,
  77. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  78. CURLOPT_CUSTOMREQUEST => 'GET',
  79. CURLOPT_HTTPHEADER => array(
  80. 'DOLAPIKEY: '.self::API_KEY
  81. ),
  82. ));
  83. $response = curl_exec($curl);
  84. curl_close($curl);
  85. $events = [];
  86. $response = json_decode($response, true);
  87. foreach ($response as $key => $item) {
  88. $event = [];
  89. $event['key'] = $key;
  90. foreach ($item as $subkey => $subitem) {
  91. $sub = [];
  92. $date = explode(' ', $subkey);
  93. $sub['id'] = $subitem['id'];
  94. $sub['label'] = $subitem['label'];
  95. $sub['description'] = $subitem['description'];
  96. $sub['date'] = $date[0];
  97. $sub['time'] = substr($date[1],0,-3);
  98. $sub['max_num'] = $subitem['max_num'];
  99. $sub['participants'] = $subitem['participants'];
  100. $sub['available'] = $subitem['max_num'] - $subitem['participants'];
  101. $event['dates'][] = $sub;
  102. }
  103. $event['label'] = $event['dates'][0]['label'];
  104. $event['description'] = $event['dates'][0]['description'];
  105. $event['date'] = $event['dates'][0]['date'];
  106. $event['time'] = $event['dates'][0]['time'];
  107. $event['available'] = $event['dates'][0]['available'];
  108. $events[] = $event;
  109. }
  110. //$data = json_encode($events, true);
  111. return $events;
  112. }
  113. public function getMenusList($eventID) {
  114. $curl = curl_init();
  115. curl_setopt_array($curl, array(
  116. CURLOPT_URL => self::API.'/affiliateapi/menus?eventDetailId='.$eventID,
  117. CURLOPT_RETURNTRANSFER => true,
  118. CURLOPT_ENCODING => '',
  119. CURLOPT_MAXREDIRS => 10,
  120. CURLOPT_TIMEOUT => 0,
  121. CURLOPT_FOLLOWLOCATION => true,
  122. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  123. CURLOPT_CUSTOMREQUEST => 'GET',
  124. CURLOPT_HTTPHEADER => array(
  125. 'DOLAPIKEY: '.self::API_KEY
  126. ),
  127. ));
  128. $response = curl_exec($curl);
  129. curl_close($curl);
  130. $response = json_decode($response, true);
  131. foreach ($response as $key => $item) {
  132. $menu = [];
  133. $menu['id'] = $item['fk_product'];
  134. $menu['label'] = $item['label'];
  135. $menu['description'] = $item['description'];
  136. $menu['price'] = $item['price'];
  137. $menus[] = $menu;
  138. }
  139. //$data = json_encode($events, true);
  140. return $menus;
  141. }
  142. public function getEvents($packageid, $participants) {
  143. $curl = curl_init();
  144. curl_setopt_array($curl, array(
  145. CURLOPT_URL => self::API.'/affiliateapi/events?id='.$packageid.'&participants='.$participants,
  146. CURLOPT_RETURNTRANSFER => true,
  147. CURLOPT_ENCODING => '',
  148. CURLOPT_MAXREDIRS => 10,
  149. CURLOPT_TIMEOUT => 0,
  150. CURLOPT_FOLLOWLOCATION => true,
  151. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  152. CURLOPT_CUSTOMREQUEST => 'GET',
  153. CURLOPT_HTTPHEADER => array(
  154. 'DOLAPIKEY: '.self::API_KEY
  155. ),
  156. ));
  157. $response = curl_exec($curl);
  158. curl_close($curl);
  159. $events = [];
  160. $response = json_decode($response, true);
  161. foreach ($response as $item) {
  162. $event = [];
  163. $date_temp = explode(' ', $item['start_date']);
  164. $date_exp = explode('-',$date_temp[0]);
  165. $honap = $date_exp[1] < 10 ? str_replace('0','',$date_exp[1]) : $date_exp[1];
  166. $nap = $date_exp[2] < 10 ? str_replace('0','',$date_exp[2]) : $date_exp[2];
  167. $datum = $date_exp[0] .'-'. $honap .'-'. $nap;
  168. $timePart = substr($date_temp[1], 0, -3);
  169. $event['id'] = $item['id'];
  170. $event['date'] = $datum;
  171. $event['datum'] = $date_temp[0];
  172. $event['time'] = $timePart;
  173. $event['products'] = $item['products'];
  174. $events[] = $event;
  175. }
  176. $data = json_encode($events, true);
  177. return $data;
  178. }
  179. public function getProductImage() {
  180. $id = $this->escapeString($_REQUEST['id']);
  181. $row = $this->query("select * from azonics_products where slide_title='".$id."' AND slide_status='1';");
  182. return $row[0];
  183. }
  184. public function getServices() {
  185. $rows = $this->query("select * from azonics_services where box_status='1';");
  186. $result = [];
  187. foreach ($rows as $row) {
  188. $result[] = $row;
  189. }
  190. return $result;
  191. }
  192. public function getGroupNameByID($groupID) {
  193. $rows = $this->query("select * from azonics_services where box_status='1' AND parent_service='".$groupID."';");
  194. return $rows[0]->box_subtitle;
  195. }
  196. public function getProdutNameByID($productID) {
  197. $rows = $this->query("select * from azonics_services where box_status='1' AND parent_service='".$groupID."';");
  198. return $rows[0]->box_subtitle;
  199. }
  200. public function initializeTransaction() {
  201. $curl = curl_init();
  202. curl_setopt_array($curl, array(
  203. CURLOPT_URL => self::API.'/affiliateapi/init',
  204. CURLOPT_RETURNTRANSFER => true,
  205. CURLOPT_ENCODING => '',
  206. CURLOPT_MAXREDIRS => 10,
  207. CURLOPT_TIMEOUT => 0,
  208. CURLOPT_FOLLOWLOCATION => true,
  209. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  210. CURLOPT_CUSTOMREQUEST => 'GET',
  211. CURLOPT_HTTPHEADER => array(
  212. 'DOLAPIKEY: '.self::API_KEY
  213. ),
  214. ));
  215. $response = curl_exec($curl);
  216. $response = str_replace('"','',$response);
  217. curl_close($curl);
  218. return $response;
  219. }
  220. public function startReservation() {
  221. $curl = curl_init();
  222. $post_data = array(
  223. 'uuid' => $_REQUEST['uuid'],
  224. 'event_id' => $_REQUEST['event_id'],
  225. 'qty' => $_REQUEST['qty']
  226. );
  227. curl_setopt_array($curl, array(
  228. CURLOPT_URL => self::API.'/affiliateapi/reserve',
  229. CURLOPT_RETURNTRANSFER => true,
  230. CURLOPT_ENCODING => '',
  231. CURLOPT_MAXREDIRS => 10,
  232. CURLOPT_TIMEOUT => 0,
  233. CURLOPT_FOLLOWLOCATION => true,
  234. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  235. CURLOPT_CUSTOMREQUEST => 'POST',
  236. CURLOPT_POSTFIELDS => http_build_query($post_data),
  237. CURLOPT_HTTPHEADER => array(
  238. 'DOLAPIKEY: '.self::API_KEY
  239. ),
  240. ));
  241. $response = curl_exec($curl);
  242. curl_close($curl);
  243. return $response;
  244. }
  245. public function order() {
  246. $data = json_decode($_REQUEST['data']);
  247. $curl = curl_init();
  248. $post_data = $data;
  249. $post_data->uuid = str_replace('"','',$post_data->uuid);
  250. curl_setopt_array($curl, array(
  251. CURLOPT_URL => self::API.'/affiliateapi/order',
  252. CURLOPT_RETURNTRANSFER => true,
  253. CURLOPT_ENCODING => '',
  254. CURLOPT_MAXREDIRS => 10,
  255. CURLOPT_TIMEOUT => 0,
  256. CURLOPT_FOLLOWLOCATION => true,
  257. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  258. CURLOPT_CUSTOMREQUEST => 'POST',
  259. CURLOPT_POSTFIELDS => json_encode($post_data),
  260. CURLOPT_HTTPHEADER => array(
  261. 'Content-Type: application/json',
  262. 'DOLAPIKEY: '.self::API_KEY
  263. ),
  264. ));
  265. //print_r(json_encode($post_data));
  266. //die();
  267. $response = curl_exec($curl);
  268. curl_close($curl);
  269. return $response;
  270. }
  271. public function paymentstatus() {
  272. $curl = curl_init();
  273. curl_setopt_array($curl, array(
  274. CURLOPT_URL => self::API.'/affiliateapi/paymentstatus?uuid='.$_REQUEST['uuid'],
  275. CURLOPT_RETURNTRANSFER => true,
  276. CURLOPT_ENCODING => '',
  277. CURLOPT_MAXREDIRS => 10,
  278. CURLOPT_TIMEOUT => 0,
  279. CURLOPT_FOLLOWLOCATION => true,
  280. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  281. CURLOPT_CUSTOMREQUEST => 'GET',
  282. CURLOPT_HTTPHEADER => array(
  283. 'DOLAPIKEY: '.self::API_KEY
  284. ),
  285. ));
  286. $response = curl_exec($curl);
  287. curl_close($curl);
  288. return $response;
  289. }
  290. public function getProviderDetails() {
  291. $curl = curl_init();
  292. curl_setopt_array($curl, array(
  293. CURLOPT_URL => self::API.'/affiliateapi/getCustomerData',
  294. CURLOPT_RETURNTRANSFER => true,
  295. CURLOPT_ENCODING => '',
  296. CURLOPT_MAXREDIRS => 10,
  297. CURLOPT_TIMEOUT => 0,
  298. CURLOPT_FOLLOWLOCATION => true,
  299. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  300. CURLOPT_CUSTOMREQUEST => 'GET',
  301. CURLOPT_HTTPHEADER => array(
  302. 'DOLAPIKEY: '.self::API_KEY
  303. ),
  304. ));
  305. $response = curl_exec($curl);
  306. curl_close($curl);
  307. return $response;
  308. }
  309. public function getLabels($lang = 'hu') {
  310. $rows = $this->query("select
  311. setting_name,
  312. setting_value_text,
  313. setting_value_text_en,
  314. setting_status from azonics_settings where setting_status='1';");
  315. foreach ($rows as $row) {
  316. if ($lang == 'en') {
  317. $row->setting_value_text = $row->setting_value_text_en;
  318. }
  319. $results[] = $row;
  320. }
  321. return $results;
  322. }
  323. public function getGroups($lang = 'hu') {
  324. $rows = $this->query("SELECT * FROM `azonics_services` WHERE box_status=1;");
  325. foreach ($rows as $row) {
  326. if ($lang == 'en') {
  327. $row->box_subtitle = $row->box_subtitle_en;
  328. $row->box_title = $row->box_button_text_en;
  329. }
  330. $results[] = $row;
  331. }
  332. return $results;
  333. }
  334. public function getGroupID($groupKey) {
  335. $row = $this->query("SELECT * FROM `azonics_services` WHERE box_status=1 AND box_title_en='".$groupKey."';");
  336. return $row[0]->parent_service;
  337. }
  338. public function getEventsData($groupID, $lang = 'hu') {
  339. $parentID = $this->getGroupID($groupID);
  340. $rows = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1 AND parent_service=".$parentID.";");
  341. //print_r($rows);
  342. //die();
  343. foreach ($rows as $row) {
  344. $images = $this->query("SELECT * FROM `azonics_events_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  345. $row->images = $images;
  346. $row->dates = $this->getEventsList($groupID);
  347. if ($lang == 'en') {
  348. $row->box_title = $row->box_title_en;
  349. $row->box_subtitle = $row->box_subtitle_en;
  350. }
  351. $results[] = $row;
  352. }
  353. return $results;
  354. }
  355. public function getEventMenus($eventID, $lang = 'hu') {
  356. $rows = $this->query("SELECT * FROM `azonics_packages` WHERE box_status=1 AND parent_event=".$eventID." ORDER BY box_order ASC;");
  357. $menus = $this->getMenusList($eventID);
  358. foreach ($rows as $row) {
  359. $images = $this->query("SELECT * FROM `azonics_package_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  360. $row->images = $images;
  361. foreach ($menus as $menu) {
  362. if ($menu['id'] == $row->parent_menu) {
  363. $row->parent_price = $menu['price'];
  364. }
  365. }
  366. if ($lang == 'en') {
  367. $row->box_title = $row->box_title_en;
  368. $row->box_subtitle = $row->box_subtitle_en;
  369. }
  370. if (count($images) > 0) {
  371. $results[] = $row;
  372. }
  373. }
  374. return $results;
  375. }
  376. public function getEventName($groupID, $eventID) {
  377. $row = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1 AND parent_service=".$groupID." AND parent_event=".$eventID.";");
  378. return $row[0]->box_title;
  379. }
  380. public function getEventsRawList() {
  381. $rows = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1;");
  382. return $rows;
  383. }
  384. public function getProductsData($groupID, $lang = 'hu') {
  385. $items = $this->getProductsList($groupID);
  386. $rows = $this->query("SELECT * FROM `azonics_prods` WHERE box_status=1 AND parent_service=".$groupID.";");
  387. foreach ($rows as $row) {
  388. $images = $this->query("SELECT * FROM `azonics_prods_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  389. $row->images = $images;
  390. $row->items = $items[$row->parent_prods]['products'];
  391. if ($lang == 'en') {
  392. $row->box_title = $row->box_title_en;
  393. $row->box_subtitle = $row->box_subtitle_en;
  394. }
  395. $results[] = $row;
  396. }
  397. return $results;
  398. }
  399. public function getContent($slug, $lang = 'hu') {
  400. $row = $this->query("SELECT * FROM `azonics_blog` WHERE page_status=1 AND page_slug='".$slug."';");
  401. if ($lang == 'en') {
  402. $row[0]->page_title = $row[0]->page_title_en;
  403. $row[0]->page_content = $row[0]->page_content_en;
  404. }
  405. return $row[0];
  406. }
  407. public function getUID() {
  408. $curl = curl_init();
  409. curl_setopt_array($curl, array(
  410. CURLOPT_URL => self::API.'/affiliateapi/init',
  411. CURLOPT_RETURNTRANSFER => true,
  412. CURLOPT_ENCODING => '',
  413. CURLOPT_MAXREDIRS => 10,
  414. CURLOPT_TIMEOUT => 0,
  415. CURLOPT_FOLLOWLOCATION => true,
  416. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  417. CURLOPT_CUSTOMREQUEST => 'GET',
  418. CURLOPT_HTTPHEADER => array(
  419. 'DOLAPIKEY: '.self::API_KEY
  420. ),
  421. ));
  422. $response = curl_exec($curl);
  423. curl_close($curl);
  424. return $response;
  425. }
  426. public function reserveEvent($uuid, $eventID, $qty) {
  427. $curl = curl_init();
  428. $post_data = array('uuid' => $uuid, 'event_id' => $eventID, 'qty' => $qty);
  429. curl_setopt_array($curl, array(
  430. CURLOPT_URL => self::API.'/affiliateapi/reserve',
  431. CURLOPT_RETURNTRANSFER => true,
  432. CURLOPT_ENCODING => '',
  433. CURLOPT_MAXREDIRS => 10,
  434. CURLOPT_TIMEOUT => 0,
  435. CURLOPT_FOLLOWLOCATION => true,
  436. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  437. CURLOPT_CUSTOMREQUEST => 'POST',
  438. CURLOPT_POSTFIELDS => json_encode($post_data),
  439. CURLOPT_HTTPHEADER => array(
  440. 'Content-Type:application/json',
  441. 'DOLAPIKEY: '.self::API_KEY
  442. ),
  443. ));
  444. $response = curl_exec($curl);
  445. curl_close($curl);
  446. return json_decode($response);
  447. }
  448. public function getHotels($onlyHotels = false) {
  449. $curl = curl_init();
  450. $url = self::API.'/affiliateapi/getAllHotels?givePartnerData=1';
  451. if ($onlyHotels) {
  452. //$url .= '?givePartnerData=1';
  453. }
  454. curl_setopt_array($curl, array(
  455. CURLOPT_URL => $url,
  456. CURLOPT_RETURNTRANSFER => true,
  457. CURLOPT_ENCODING => '',
  458. CURLOPT_MAXREDIRS => 10,
  459. CURLOPT_TIMEOUT => 0,
  460. CURLOPT_FOLLOWLOCATION => true,
  461. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  462. CURLOPT_CUSTOMREQUEST => 'GET',
  463. CURLOPT_HTTPHEADER => array(
  464. 'DOLAPIKEY: '.self::API_KEY
  465. ),
  466. ));
  467. $response = curl_exec($curl);
  468. curl_close($curl);
  469. $groups = [];
  470. $response = json_decode($response, true);
  471. foreach ($response as $key => $value) {
  472. if ($value['contracted_partner'] == '1') {
  473. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label']);
  474. }
  475. }
  476. return $options;
  477. }
  478. public function checkout($data) {
  479. $curl = curl_init();
  480. curl_setopt_array($curl, array(
  481. CURLOPT_URL => self::API.'/affiliateapi/order',
  482. CURLOPT_RETURNTRANSFER => true,
  483. CURLOPT_ENCODING => '',
  484. CURLOPT_MAXREDIRS => 10,
  485. CURLOPT_TIMEOUT => 0,
  486. CURLOPT_FOLLOWLOCATION => true,
  487. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  488. CURLOPT_CUSTOMREQUEST => 'POST',
  489. CURLOPT_POSTFIELDS => json_encode($data),
  490. CURLOPT_HTTPHEADER => array(
  491. 'Content-Type:application/json',
  492. 'DOLAPIKEY: '.self::API_KEY
  493. ),
  494. ));
  495. $response = curl_exec($curl);
  496. curl_close($curl);
  497. return json_decode($response);
  498. }
  499. public function getCountries() {
  500. $curl = curl_init();
  501. curl_setopt_array($curl, array(
  502. CURLOPT_URL => self::API.'/setup/dictionary/countries?sortfield=code&sortorder=ASC&limit=3000',
  503. CURLOPT_RETURNTRANSFER => true,
  504. CURLOPT_ENCODING => '',
  505. CURLOPT_MAXREDIRS => 10,
  506. CURLOPT_TIMEOUT => 0,
  507. CURLOPT_FOLLOWLOCATION => true,
  508. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  509. CURLOPT_CUSTOMREQUEST => 'GET',
  510. CURLOPT_HTTPHEADER => array(
  511. 'DOLAPIKEY: '.self::API_KEY
  512. ),
  513. ));
  514. $response = curl_exec($curl);
  515. curl_close($curl);
  516. $options = [];
  517. $response = json_decode($response, true);
  518. foreach ($response as $value) {
  519. $options[] = array('key' => $value['id'].'_'.$value['code'], 'value' => $value['label']);
  520. }
  521. return $options;
  522. }
  523. public function getPaymentStatus($uuid) {
  524. $curl = curl_init();
  525. curl_setopt_array($curl, array(
  526. CURLOPT_URL => self::API.'/affiliateapi/paymentstatus?uuid='.$uuid,
  527. CURLOPT_RETURNTRANSFER => true,
  528. CURLOPT_ENCODING => '',
  529. CURLOPT_MAXREDIRS => 10,
  530. CURLOPT_TIMEOUT => 0,
  531. CURLOPT_FOLLOWLOCATION => true,
  532. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  533. CURLOPT_CUSTOMREQUEST => 'GET',
  534. CURLOPT_HTTPHEADER => array(
  535. 'DOLAPIKEY: '.self::API_KEY
  536. ),
  537. ));
  538. $response = curl_exec($curl);
  539. curl_close($curl);
  540. $response = json_decode($response, true);
  541. return $response;
  542. }
  543. public function authenticateUser($username, $password) {
  544. $row = $this->query("SELECT * FROM `azonics_admin_users` WHERE admin_pass='".$password."' AND (admin_email='".$username."' OR admin_name='".$username."') AND admin_status='1';");
  545. if (count($row) == 0) {
  546. return ['success' => false];
  547. }
  548. else {
  549. return [
  550. 'success' => true,
  551. 'name' => $row[0]->admin_name,
  552. 'hotel' => $row[0]->admin_dashboard
  553. ];
  554. }
  555. }
  556. public function getMonthRevenue($hotelID, $actualMonth = 0) {
  557. $curl = curl_init();
  558. $postfix = '';
  559. if ($actualMonth == 1) {
  560. $postfix = '&actualMonth='.$actualMonth;
  561. }
  562. curl_setopt_array($curl, array(
  563. CURLOPT_URL => self::API.'/affiliateapi/getAmount?hotel_id='.$hotelID.$postfix,
  564. CURLOPT_RETURNTRANSFER => true,
  565. CURLOPT_ENCODING => '',
  566. CURLOPT_MAXREDIRS => 10,
  567. CURLOPT_TIMEOUT => 0,
  568. CURLOPT_FOLLOWLOCATION => true,
  569. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  570. CURLOPT_CUSTOMREQUEST => 'GET',
  571. CURLOPT_HTTPHEADER => array(
  572. 'DOLAPIKEY: '.self::API_KEY
  573. ),
  574. ));
  575. $response = curl_exec($curl);
  576. curl_close($curl);
  577. $response = str_replace('"','',$response);
  578. $result = intval($response);
  579. return $result;
  580. }
  581. public function getReports() {
  582. $hotels = $this->getHotels(true);
  583. $reports = [];
  584. $userData = unserialize($_SESSION['admin_user']->admin_dashboard);
  585. foreach ($userData as $hotelID) {
  586. $hotel = array_filter($hotels, function($h) use ($hotelID) {
  587. return $h['key'] == $hotelID;
  588. });
  589. if (!empty($hotel)) {
  590. $hotel = array_values($hotel)[0];
  591. }
  592. $report = [];
  593. $report['hotel'] = $hotel['value'];
  594. $report['actual_month'] = $this->getMonthRevenue($hotelID, 1);
  595. $report['last_month'] = $this->getMonthRevenue($hotelID, 0);
  596. $reports[] = $report;
  597. }
  598. return $reports;
  599. }
  600. }