api_model.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  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. public function getMenusList($eventID) {
  167. $curl = curl_init();
  168. curl_setopt_array($curl, array(
  169. CURLOPT_URL => $this->API.'/affiliateapi/menus?eventDetailId='.$eventID,
  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. $response = json_decode($response, true);
  184. foreach ($response as $key => $item) {
  185. $menu = [];
  186. $menu['id'] = $item['fk_product'];
  187. $menu['label'] = $item['label'];
  188. $menu['description'] = $item['description'];
  189. $menu['price'] = $item['price'];
  190. $menus[] = $menu;
  191. }
  192. //$data = json_encode($events, true);
  193. return $menus;
  194. }
  195. public function getEvents($packageid, $participants) {
  196. $curl = curl_init();
  197. curl_setopt_array($curl, array(
  198. CURLOPT_URL => $this->API.'/affiliateapi/events?id='.$packageid.'&participants='.$participants,
  199. CURLOPT_RETURNTRANSFER => true,
  200. CURLOPT_ENCODING => '',
  201. CURLOPT_MAXREDIRS => 10,
  202. CURLOPT_TIMEOUT => 0,
  203. CURLOPT_FOLLOWLOCATION => true,
  204. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  205. CURLOPT_CUSTOMREQUEST => 'GET',
  206. CURLOPT_HTTPHEADER => array(
  207. 'DOLAPIKEY: '.$this->API_KEY
  208. ),
  209. ));
  210. $response = curl_exec($curl);
  211. curl_close($curl);
  212. $events = [];
  213. $response = json_decode($response, true);
  214. foreach ($response as $item) {
  215. $event = [];
  216. $date_temp = explode(' ', $item['start_date']);
  217. $date_exp = explode('-',$date_temp[0]);
  218. $honap = $date_exp[1] < 10 ? str_replace('0','',$date_exp[1]) : $date_exp[1];
  219. $nap = $date_exp[2] < 10 ? str_replace('0','',$date_exp[2]) : $date_exp[2];
  220. $datum = $date_exp[0] .'-'. $honap .'-'. $nap;
  221. $timePart = substr($date_temp[1], 0, -3);
  222. $event['id'] = $item['id'];
  223. $event['date'] = $datum;
  224. $event['datum'] = $date_temp[0];
  225. $event['time'] = $timePart;
  226. $event['products'] = $item['products'];
  227. $events[] = $event;
  228. }
  229. $data = json_encode($events, true);
  230. return $data;
  231. }
  232. public function getProductImage() {
  233. $id = $this->escapeString($_REQUEST['id']);
  234. $row = $this->query("select * from azonics_products where slide_title='".$id."' AND slide_status='1';");
  235. return $row[0];
  236. }
  237. public function getServices() {
  238. $rows = $this->query("select * from azonics_services where box_status='1';");
  239. $result = [];
  240. foreach ($rows as $row) {
  241. $result[] = $row;
  242. }
  243. return $result;
  244. }
  245. public function getGroupNameByID($groupID) {
  246. $rows = $this->query("select * from azonics_services where box_status='1' AND parent_service='".$groupID."';");
  247. return $rows[0]->box_subtitle;
  248. }
  249. public function getProdutNameByID($productID) {
  250. $rows = $this->query("select * from azonics_services where box_status='1' AND parent_service='".$groupID."';");
  251. return $rows[0]->box_subtitle;
  252. }
  253. public function initializeTransaction() {
  254. $curl = curl_init();
  255. curl_setopt_array($curl, array(
  256. CURLOPT_URL => $this->API.'/affiliateapi/init',
  257. CURLOPT_RETURNTRANSFER => true,
  258. CURLOPT_ENCODING => '',
  259. CURLOPT_MAXREDIRS => 10,
  260. CURLOPT_TIMEOUT => 0,
  261. CURLOPT_FOLLOWLOCATION => true,
  262. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  263. CURLOPT_CUSTOMREQUEST => 'GET',
  264. CURLOPT_HTTPHEADER => array(
  265. 'DOLAPIKEY: '.$this->API_KEY
  266. ),
  267. ));
  268. $response = curl_exec($curl);
  269. $response = str_replace('"','',$response);
  270. curl_close($curl);
  271. return $response;
  272. }
  273. public function startReservation() {
  274. $curl = curl_init();
  275. $post_data = array(
  276. 'uuid' => $_REQUEST['uuid'],
  277. 'event_id' => $_REQUEST['event_id'],
  278. 'qty' => $_REQUEST['qty']
  279. );
  280. curl_setopt_array($curl, array(
  281. CURLOPT_URL => $this->API.'/affiliateapi/reserve',
  282. CURLOPT_RETURNTRANSFER => true,
  283. CURLOPT_ENCODING => '',
  284. CURLOPT_MAXREDIRS => 10,
  285. CURLOPT_TIMEOUT => 0,
  286. CURLOPT_FOLLOWLOCATION => true,
  287. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  288. CURLOPT_CUSTOMREQUEST => 'POST',
  289. CURLOPT_POSTFIELDS => http_build_query($post_data),
  290. CURLOPT_HTTPHEADER => array(
  291. 'DOLAPIKEY: '.$this->API_KEY
  292. ),
  293. ));
  294. $response = curl_exec($curl);
  295. curl_close($curl);
  296. return $response;
  297. }
  298. public function order() {
  299. $data = json_decode($_REQUEST['data']);
  300. $curl = curl_init();
  301. $post_data = $data;
  302. $post_data->uuid = str_replace('"','',$post_data->uuid);
  303. curl_setopt_array($curl, array(
  304. CURLOPT_URL => $this->API.'/affiliateapi/order',
  305. CURLOPT_RETURNTRANSFER => true,
  306. CURLOPT_ENCODING => '',
  307. CURLOPT_MAXREDIRS => 10,
  308. CURLOPT_TIMEOUT => 0,
  309. CURLOPT_FOLLOWLOCATION => true,
  310. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  311. CURLOPT_CUSTOMREQUEST => 'POST',
  312. CURLOPT_POSTFIELDS => json_encode($post_data),
  313. CURLOPT_HTTPHEADER => array(
  314. 'Content-Type: application/json',
  315. 'DOLAPIKEY: '.$this->API_KEY
  316. ),
  317. ));
  318. //print_r(json_encode($post_data));
  319. //die();
  320. $response = curl_exec($curl);
  321. curl_close($curl);
  322. return $response;
  323. }
  324. public function paymentstatus() {
  325. $curl = curl_init();
  326. curl_setopt_array($curl, array(
  327. CURLOPT_URL => $this->API.'/affiliateapi/paymentstatus?uuid='.$_REQUEST['uuid'],
  328. CURLOPT_RETURNTRANSFER => true,
  329. CURLOPT_ENCODING => '',
  330. CURLOPT_MAXREDIRS => 10,
  331. CURLOPT_TIMEOUT => 0,
  332. CURLOPT_FOLLOWLOCATION => true,
  333. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  334. CURLOPT_CUSTOMREQUEST => 'GET',
  335. CURLOPT_HTTPHEADER => array(
  336. 'DOLAPIKEY: '.$this->API_KEY
  337. ),
  338. ));
  339. $response = curl_exec($curl);
  340. curl_close($curl);
  341. return $response;
  342. }
  343. public function getProviderDetails() {
  344. $curl = curl_init();
  345. curl_setopt_array($curl, array(
  346. CURLOPT_URL => $this->API.'/affiliateapi/getCustomerData',
  347. CURLOPT_RETURNTRANSFER => true,
  348. CURLOPT_ENCODING => '',
  349. CURLOPT_MAXREDIRS => 10,
  350. CURLOPT_TIMEOUT => 0,
  351. CURLOPT_FOLLOWLOCATION => true,
  352. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  353. CURLOPT_CUSTOMREQUEST => 'GET',
  354. CURLOPT_HTTPHEADER => array(
  355. 'DOLAPIKEY: '.$this->API_KEY
  356. ),
  357. ));
  358. $response = curl_exec($curl);
  359. curl_close($curl);
  360. return $response;
  361. }
  362. public function getLabels($lang = 'hu') {
  363. $rows = $this->query("select
  364. setting_name,
  365. setting_value_text,
  366. setting_value_text_en,
  367. setting_status from azonics_settings where setting_status='1';");
  368. foreach ($rows as $row) {
  369. if ($lang == 'en') {
  370. $row->setting_value_text = $row->setting_value_text_en;
  371. }
  372. $results[] = $row;
  373. }
  374. return $results;
  375. }
  376. public function getGroups($lang = 'hu') {
  377. $rows = $this->query("SELECT * FROM `azonics_services` WHERE box_status=1;");
  378. foreach ($rows as $row) {
  379. if ($lang == 'en') {
  380. $row->box_subtitle = $row->box_subtitle_en;
  381. $row->box_title = $row->box_button_text_en;
  382. }
  383. $results[] = $row;
  384. }
  385. return $results;
  386. }
  387. public function getGroupID($groupKey) {
  388. $row = $this->query("SELECT * FROM `azonics_services` WHERE box_status=1 AND box_title_en='".$groupKey."';");
  389. return $row[0]->parent_service;
  390. }
  391. public function getLowestEventprice($eventID) {
  392. $events = $this->getMenusList($eventID);
  393. foreach ($events as $event) {
  394. if (!isset($lowest) || $event['price'] < $lowest) {
  395. $lowest = $event['price'];
  396. }
  397. }
  398. return formatize::currency(round($lowest));
  399. }
  400. public function getEventsData($groupID, $lang = 'hu') {
  401. $parentID = $this->getGroupID($groupID);
  402. $rows = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1 AND parent_service=".$parentID.";");
  403. foreach ($rows as $row) {
  404. $row->parent_price = $this->getLowestEventprice($row->parent_event);
  405. $images = $this->query("SELECT * FROM `azonics_events_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  406. $row->images = $images;
  407. $row->dates = $this->getEventsListByGroup($groupID, $row->parent_event);
  408. if ($lang == 'en') {
  409. $row->box_title = $row->box_title_en;
  410. $row->box_subtitle = $row->box_subtitle_en;
  411. }
  412. if (count($row->dates) < 1) {
  413. continue;
  414. }
  415. $results[] = $row;
  416. }
  417. return $results;
  418. }
  419. public function getEventMenus($eventID, $lang = 'hu') {
  420. $rows = $this->query("SELECT * FROM `azonics_packages` WHERE box_status=1 AND parent_event=".$eventID." ORDER BY box_order ASC;");
  421. $menus = $this->getMenusList($eventID);
  422. foreach ($rows as $row) {
  423. $images = $this->query("SELECT * FROM `azonics_package_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  424. $row->images = $images;
  425. foreach ($menus as $menu) {
  426. if ($menu['id'] == $row->parent_menu) {
  427. $row->parent_price = $menu['price'];
  428. }
  429. }
  430. if ($lang == 'en') {
  431. $row->box_title = $row->box_title_en;
  432. $row->box_subtitle = $row->box_subtitle_en;
  433. }
  434. if (count($images) > 0) {
  435. $results[] = $row;
  436. }
  437. }
  438. return $results;
  439. }
  440. public function getEventName($groupID, $eventID) {
  441. $row = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1 AND parent_service=".$groupID." AND parent_event=".$eventID.";");
  442. return $row[0]->box_title;
  443. }
  444. public function getEventsRawList() {
  445. $rows = $this->query("SELECT * FROM `azonics_events` WHERE box_status=1;");
  446. return $rows;
  447. }
  448. public function getProductsData($groupID, $lang = 'hu') {
  449. $items = $this->getProductsList($groupID);
  450. $rows = $this->query("SELECT * FROM `azonics_prods` WHERE box_status=1 AND parent_service=".$groupID.";");
  451. foreach ($rows as $row) {
  452. $images = $this->query("SELECT * FROM `azonics_prods_blocks` WHERE block_status=1 AND box_id=".$row->box_id.";");
  453. $row->images = $images;
  454. $row->items = $items[$row->parent_prods]['products'];
  455. if ($lang == 'en') {
  456. $row->box_title = $row->box_title_en;
  457. $row->box_subtitle = $row->box_subtitle_en;
  458. }
  459. $results[] = $row;
  460. }
  461. return $results;
  462. }
  463. public function getContent($slug, $lang = 'hu') {
  464. $row = $this->query("SELECT * FROM `azonics_blog` WHERE page_status=1 AND page_slug='".$slug."';");
  465. if ($lang == 'en') {
  466. $row[0]->page_title = $row[0]->page_title_en;
  467. $row[0]->page_content = $row[0]->page_content_en;
  468. }
  469. return $row[0];
  470. }
  471. public function getUID() {
  472. $curl = curl_init();
  473. curl_setopt_array($curl, array(
  474. CURLOPT_URL => $this->API.'/affiliateapi/init',
  475. CURLOPT_RETURNTRANSFER => true,
  476. CURLOPT_ENCODING => '',
  477. CURLOPT_MAXREDIRS => 10,
  478. CURLOPT_TIMEOUT => 0,
  479. CURLOPT_FOLLOWLOCATION => true,
  480. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  481. CURLOPT_CUSTOMREQUEST => 'GET',
  482. CURLOPT_HTTPHEADER => array(
  483. 'DOLAPIKEY: '.$this->API_KEY
  484. ),
  485. ));
  486. $response = curl_exec($curl);
  487. curl_close($curl);
  488. return $response;
  489. }
  490. public function reserveEvent($uuid, $eventID, $qty) {
  491. $curl = curl_init();
  492. $post_data = array('uuid' => $uuid, 'event_id' => $eventID, 'qty' => $qty);
  493. curl_setopt_array($curl, array(
  494. CURLOPT_URL => $this->API.'/affiliateapi/reserve',
  495. CURLOPT_RETURNTRANSFER => true,
  496. CURLOPT_ENCODING => '',
  497. CURLOPT_MAXREDIRS => 10,
  498. CURLOPT_TIMEOUT => 0,
  499. CURLOPT_FOLLOWLOCATION => true,
  500. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  501. CURLOPT_CUSTOMREQUEST => 'POST',
  502. CURLOPT_POSTFIELDS => json_encode($post_data),
  503. CURLOPT_HTTPHEADER => array(
  504. 'Content-Type:application/json',
  505. 'DOLAPIKEY: '.$this->API_KEY
  506. ),
  507. ));
  508. $response = curl_exec($curl);
  509. curl_close($curl);
  510. return json_decode($response);
  511. }
  512. public function getAllHotels() {
  513. $curl = curl_init();
  514. $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
  515. curl_setopt_array($curl, array(
  516. CURLOPT_URL => $url,
  517. CURLOPT_RETURNTRANSFER => true,
  518. CURLOPT_ENCODING => '',
  519. CURLOPT_MAXREDIRS => 10,
  520. CURLOPT_TIMEOUT => 0,
  521. CURLOPT_FOLLOWLOCATION => true,
  522. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  523. CURLOPT_CUSTOMREQUEST => 'GET',
  524. CURLOPT_HTTPHEADER => array(
  525. 'DOLAPIKEY: '.$this->API_KEY
  526. ),
  527. ));
  528. $response = curl_exec($curl);
  529. curl_close($curl);
  530. $groups = [];
  531. $response = json_decode($response, true);
  532. foreach ($response as $key => $value) {
  533. if ($allHotels === false ) {
  534. if ($value['contracted_partner'] == 1) {
  535. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  536. }
  537. }
  538. else if ($allHotels === true) {
  539. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  540. }
  541. }
  542. return $options;
  543. }
  544. public function getAllPartner() {
  545. $curl = curl_init();
  546. $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
  547. curl_setopt_array($curl, array(
  548. CURLOPT_URL => $url,
  549. CURLOPT_RETURNTRANSFER => true,
  550. CURLOPT_ENCODING => '',
  551. CURLOPT_MAXREDIRS => 10,
  552. CURLOPT_TIMEOUT => 0,
  553. CURLOPT_FOLLOWLOCATION => true,
  554. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  555. CURLOPT_CUSTOMREQUEST => 'GET',
  556. CURLOPT_HTTPHEADER => array(
  557. 'DOLAPIKEY: '.$this->API_KEY
  558. ),
  559. ));
  560. $response = curl_exec($curl);
  561. curl_close($curl);
  562. $groups = [];
  563. $response = json_decode($response, true);
  564. foreach ($response as $key => $value) {
  565. $options[] = array('id' => $value['id'], 'key' => $key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  566. }
  567. return $options;
  568. }
  569. public function getAllContractedPartner() {
  570. $curl = curl_init();
  571. $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
  572. curl_setopt_array($curl, array(
  573. CURLOPT_URL => $url,
  574. CURLOPT_RETURNTRANSFER => true,
  575. CURLOPT_ENCODING => '',
  576. CURLOPT_MAXREDIRS => 10,
  577. CURLOPT_TIMEOUT => 0,
  578. CURLOPT_FOLLOWLOCATION => true,
  579. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  580. CURLOPT_CUSTOMREQUEST => 'GET',
  581. CURLOPT_HTTPHEADER => array(
  582. 'DOLAPIKEY: '.$this->API_KEY
  583. ),
  584. ));
  585. $response = curl_exec($curl);
  586. curl_close($curl);
  587. $groups = [];
  588. $response = json_decode($response, true);
  589. foreach ($response as $key => $value) {
  590. if ($value['contracted_partner'] == 1) {
  591. $options[] = array('id' => $value['id'], 'key' => $key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  592. }
  593. }
  594. return $options;
  595. }
  596. public function getHotels($allHotels = false) {
  597. $curl = curl_init();
  598. $url = $this->API.'/affiliateapi/getAllHotels?givePartnerData=1';
  599. curl_setopt_array($curl, array(
  600. CURLOPT_URL => $url,
  601. CURLOPT_RETURNTRANSFER => true,
  602. CURLOPT_ENCODING => '',
  603. CURLOPT_MAXREDIRS => 10,
  604. CURLOPT_TIMEOUT => 0,
  605. CURLOPT_FOLLOWLOCATION => true,
  606. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  607. CURLOPT_CUSTOMREQUEST => 'GET',
  608. CURLOPT_HTTPHEADER => array(
  609. 'DOLAPIKEY: '.$this->API_KEY
  610. ),
  611. ));
  612. $response = curl_exec($curl);
  613. curl_close($curl);
  614. $groups = [];
  615. $response = json_decode($response, true);
  616. foreach ($response as $key => $value) {
  617. if ($allHotels === false ) {
  618. if ($value['contracted_partner'] == 1) {
  619. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  620. }
  621. }
  622. else if ($allHotels === true) {
  623. $options[] = array('key' => 'hotel_'.$key, 'value' => $value['label'], 'partner' => $value['contracted_partner']);
  624. }
  625. }
  626. return $options;
  627. }
  628. public function checkout($data) {
  629. $curl = curl_init();
  630. curl_setopt_array($curl, array(
  631. CURLOPT_URL => $this->API.'/affiliateapi/order',
  632. CURLOPT_RETURNTRANSFER => true,
  633. CURLOPT_ENCODING => '',
  634. CURLOPT_MAXREDIRS => 10,
  635. CURLOPT_TIMEOUT => 0,
  636. CURLOPT_FOLLOWLOCATION => true,
  637. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  638. CURLOPT_CUSTOMREQUEST => 'POST',
  639. CURLOPT_POSTFIELDS => json_encode($data),
  640. CURLOPT_HTTPHEADER => array(
  641. 'Content-Type:application/json',
  642. 'DOLAPIKEY: '.$this->API_KEY
  643. ),
  644. ));
  645. $response = curl_exec($curl);
  646. curl_close($curl);
  647. return json_decode($response);
  648. }
  649. public function getCountries() {
  650. $curl = curl_init();
  651. curl_setopt_array($curl, array(
  652. CURLOPT_URL => $this->API.'/setup/dictionary/countries?sortfield=code&sortorder=ASC&limit=3000',
  653. CURLOPT_RETURNTRANSFER => true,
  654. CURLOPT_ENCODING => '',
  655. CURLOPT_MAXREDIRS => 10,
  656. CURLOPT_TIMEOUT => 0,
  657. CURLOPT_FOLLOWLOCATION => true,
  658. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  659. CURLOPT_CUSTOMREQUEST => 'GET',
  660. CURLOPT_HTTPHEADER => array(
  661. 'DOLAPIKEY: '.$this->API_KEY
  662. ),
  663. ));
  664. $response = curl_exec($curl);
  665. curl_close($curl);
  666. $options = [];
  667. $response = json_decode($response, true);
  668. if (is_array($response)) {
  669. usort($response, function($a, $b) {
  670. $la = isset($a['label']) ? mb_strtolower($a['label'], 'UTF-8') : '';
  671. $lb = isset($b['label']) ? mb_strtolower($b['label'], 'UTF-8') : '';
  672. return $la <=> $lb;
  673. });
  674. }
  675. foreach ($response as $value) {
  676. $options[] = array('key' => $value['id'].'_'.$value['code'], 'value' => $value['label']);
  677. }
  678. return $options;
  679. }
  680. public function getPaymentStatus($uuid) {
  681. $curl = curl_init();
  682. curl_setopt_array($curl, array(
  683. CURLOPT_URL => $this->API.'/affiliateapi/paymentstatus?uuid='.$uuid,
  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. $response = json_decode($response, true);
  698. return $response;
  699. }
  700. public function authenticateUser($username, $password) {
  701. $row = $this->query("SELECT * FROM `azonics_admin_users` WHERE admin_pass='".$password."' AND (admin_email='".$username."' OR admin_name='".$username."') AND admin_status='1';");
  702. if (count($row) == 0) {
  703. return ['success' => false];
  704. }
  705. else {
  706. return [
  707. 'success' => true,
  708. 'name' => $row[0]->admin_name,
  709. 'hotel' => $row[0]->admin_dashboard
  710. ];
  711. }
  712. }
  713. public function getMonthRevenue($hotelIDs, $actualMonth = 0) {
  714. $curl = curl_init();
  715. $postfix = '';
  716. if ($actualMonth == 1) {
  717. $postfix = '&actualMonth='.$actualMonth;
  718. }
  719. curl_setopt_array($curl, array(
  720. CURLOPT_URL => $this->API.'/affiliateapi/getAmount?hotelids='.$hotelIDs.$postfix,
  721. CURLOPT_RETURNTRANSFER => true,
  722. CURLOPT_ENCODING => '',
  723. CURLOPT_MAXREDIRS => 10,
  724. CURLOPT_TIMEOUT => 0,
  725. CURLOPT_FOLLOWLOCATION => true,
  726. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  727. CURLOPT_CUSTOMREQUEST => 'GET',
  728. CURLOPT_HTTPHEADER => array(
  729. 'DOLAPIKEY: '.$this->API_KEY
  730. ),
  731. ));
  732. $response = curl_exec($curl);
  733. curl_close($curl);
  734. $result = json_decode($response);
  735. return $result;
  736. }
  737. public function createOrderDetails($data) {
  738. $this->execute("INSERT INTO `azonics_orders` SET
  739. order_uuid = '".$data['order_uuid']."',
  740. order_hotel = '".$data['order_hotel']."',
  741. order_sales = '".$data['order_sales']."',
  742. order_cart = '".serialize($data['order_cart'])."',
  743. order_customer_fname = '".$data['order_customer_fname']."',
  744. order_customer_lname = '".$data['order_customer_lname']."',
  745. order_customer_email = '".$data['order_customer_email']."',
  746. order_customer_city = '".$data['order_customer_city']."',
  747. order_customer_country = '".$data['order_customer_country']."',
  748. order_customer_zip = '".$data['order_customer_zip']."',
  749. order_customer_street = '".$data['order_customer_street']."',
  750. order_customer_house = '".$data['order_customer_house']."',
  751. order_customer_phone = '".$data['order_customer_phone']."',
  752. order_customer_hotel = '".$data['order_customer_hotel']."',
  753. order_customer_ip = '".$data['order_customer_ip']."',
  754. order_customer_browser = '".$data['order_customer_browser']."',
  755. order_terms_accepted = 1,
  756. order_status = 1;");
  757. return $this->getLastInsertID();
  758. }
  759. public function updateOrderDetails($data) {
  760. $this->execute("UPDATE azonics_orders SET
  761. order_transaction_id = '".$data['order_transaction_id']."',
  762. order_auth_code = '".$data['order_auth_code']."' WHERE order_id = '".$data['order_id']."';");
  763. return $data['order_id'];
  764. }
  765. public function getReports() {
  766. $hotels = $this->getAllPartner();
  767. $reports = [];
  768. $userData = unserialize($_SESSION['admin_user']->admin_dashboard);
  769. $ids = [];
  770. foreach ($userData as $hotelID) {
  771. foreach ($hotels as $hotel) {
  772. if ($hotel['key'] == $hotelID) {
  773. $ids[] = $hotel['id'];
  774. $reports[] = [
  775. 'id' => $hotel['id'],
  776. 'hotel' => $hotel['value'],
  777. 'actual_month' => '',
  778. 'last_month' => ''
  779. ];
  780. }
  781. }
  782. }
  783. $actualMonth = $this->getMonthRevenue(implode(',',$ids), 1);
  784. $lastMonth = $this->getMonthRevenue(implode(',',$ids), 0);
  785. foreach ($reports as $key => $report) {
  786. foreach ($actualMonth as $id => $item) {
  787. if ($id == $report['id']) {
  788. $reports[$key]['actual_month'] = $item;
  789. }
  790. }
  791. foreach ($lastMonth as $id => $item) {
  792. if ($id == $report['id']) {
  793. $reports[$key]['last_month'] = $item;
  794. }
  795. }
  796. }
  797. return $reports;
  798. }
  799. public function getQRCodes($orderID) {
  800. $curl = curl_init();
  801. curl_setopt_array($curl, array(
  802. CURLOPT_URL => $this->API.'/affiliateapi/getSaledItemsQR?sendid='.$orderID,
  803. CURLOPT_RETURNTRANSFER => true,
  804. CURLOPT_ENCODING => '',
  805. CURLOPT_MAXREDIRS => 10,
  806. CURLOPT_TIMEOUT => 0,
  807. CURLOPT_FOLLOWLOCATION => true,
  808. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  809. CURLOPT_CUSTOMREQUEST => 'GET',
  810. CURLOPT_HTTPHEADER => array(
  811. 'DOLAPIKEY: '.$this->API_KEY
  812. ),
  813. ));
  814. $response = curl_exec($curl);
  815. curl_close($curl);
  816. $groups = [];
  817. $response = json_decode($response, true);
  818. foreach ($response as $key => $item) {
  819. $group = [];
  820. $group['id'] = $key;
  821. $group['label'] = $item;
  822. $groups[] = $group;
  823. }
  824. //$data = json_encode($groups, true);
  825. return $groups;
  826. }
  827. }