redeem.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. <?php
  2. /****************************
  3. * File : redeem.php
  4. * Author : Cygnusa
  5. * @2018
  6. ****************************/
  7. //SECURITY
  8. if (!defined('APPLICATION_PATH')) {
  9. exit('No direct script access allowed');
  10. }
  11. //FUNCTION LISTS
  12. class redeem
  13. {
  14. private $woohoo_url = WOOHOO_API_URL;
  15. public function __construct($parent)
  16. {
  17. //GET PAGE MESSAGE
  18. $this->page_data = globalfunc::getMessage($parent, $parent->lang, 'redeem');
  19. if (count($parent->params) == 0) {
  20. $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
  21. } else {
  22. $qry_params = explode("?", $parent->params[0]);
  23. $parameter_val = strtolower($qry_params[0]);
  24. switch ($parameter_val) {
  25. case "wallet":
  26. case "category":
  27. case "product":
  28. case "order":
  29. case "orderstatus":
  30. $this->$parameter_val($parent);
  31. break;
  32. default:
  33. $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
  34. break;
  35. }
  36. }
  37. $parent->response(array('response' => 'failed', 'message' => 'PAGE NOT FOUND'), 404);
  38. }
  39. /* /////////////////////////////// ADD TO WALLET //////////////////////////////////////////////// */
  40. private function wallet($parent)
  41. {
  42. globalfunc::checkMethodType($parent, array('GET'));
  43. globalfunc::checkParamCount($parent, 1);
  44. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  45. // REDEEM VALIDATION
  46. if (!projectfunc::checkValidReedem($parent)) {
  47. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error1"]), 406);
  48. }
  49. //CHECK POINTS
  50. $query_points = $parent->selectQuery(TABLE_USER_EPOINTS, "*", " smpin='" . $parent->current_smpin . "'", "1");
  51. if (!$query_points['nr'] > 0) {
  52. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error5"]), 406);
  53. }
  54. $points = $query_points['result'][0]->points;
  55. //MUST COMPLETE ON CERTIFICATION
  56. $query_learn = $parent->selectQuery(TABLE_USER_LEARNING, "smpin,lvl_id", "smpin='" . $parent->current_smpin . "' AND status=3 ORDER by lvl_id DESC", "1");
  57. if (!$query_learn['nr'] > 0) {
  58. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error12"]), 406);
  59. }
  60. //GET USER CURRENT LEVEL
  61. //$query_learn=$parent->selectQuery(TABLE_USER_LEARNING,"*","smpin='".$parent->current_smpin."' AND (status=3 OR (lvl_id IN (3,4) AND status NOT IN(4,6) ) ORDER by lvl_id DESC","1");
  62. if ($query_learn['nr'] > 0) {
  63. $query_multply = $parent->selectQuery(TABLE_TRAINING_LEVEL, "*", "lvl_id='" . $query_learn['result'][0]->lvl_id . "' ", "1");
  64. }
  65. // else
  66. // {
  67. // $query_multply=$parent->selectQuery(TABLE_TRAINING_LEVEL,"*","lvl_id='1' ","1");
  68. // }
  69. $balance_point = 0;
  70. //NEW LEVEL BASED COND
  71. switch ($query_learn['result'][0]->lvl_id) {
  72. case '1':
  73. $newpoints = round($points * .5);
  74. $balance_point = $points - $newpoints;
  75. $points = $newpoints;
  76. break;
  77. case '2':
  78. $newpoints = round($points * .75);
  79. $balance_point = $points - $newpoints;
  80. $points = $newpoints;
  81. break;
  82. case '3':
  83. //no condition
  84. $balance_point = 0;
  85. break;
  86. case '4':
  87. //no condition
  88. $balance_point = 0;
  89. break;
  90. case '5':
  91. //no condition
  92. $balance_point = 0;
  93. break;
  94. case '6':
  95. //no condition
  96. $balance_point = 0;
  97. break;
  98. }
  99. $redeem_amount = $query_multply['result'][0]->lvl_points * $points;
  100. //ADD WALLET AMOUNTS
  101. // $obj=new stdClass();
  102. // $obj->type="redeem";
  103. // $obj->type_id=TIMETOKEN.$parent->current_user_id;
  104. // $obj->description="REDEEM POINTS";
  105. // $obj->amount=$redeem_amount;
  106. // $obj->lvl_points=$query_multply['result'][0]->lvl_points;
  107. // projectfunc::userAddWallet($parent,$obj,$parent->current_user_id);
  108. $parent->executeQuery("INSERT INTO " . TABLE_USER_EPOINTS_HISTORY . "( `smpin`, `type`, `type_id`, `description`, `points`, `transaction_type`, `created_on`, `modified_on`) VALUES ('" . $parent->current_smpin . "','redeem','" . TIMETOKEN . $parent->current_user_id . "','REDEEM POINTS','" . $points . "' ,'D','" . NOW . "','" . NOW . "')");
  109. //UPDATE POINT IN USER
  110. $parent->executeQuery("UPDATE " . TABLE_USER_EPOINTS . " SET points=" . $balance_point . " WHERE smpin='" . $parent->current_smpin . "' ");
  111. //GET USER DETAILS
  112. $query_rewardpointarr = $parent->selectQuery(TABLE_USER_EPOINTS, "*", "smpin='" . $parent->current_smpin . "' ", "1");
  113. $earning = ($query_rewardpointarr['nr'] > 0) ? (string) $query_rewardpointarr['result'][0]->points : '0';
  114. $is_redeem_point = (projectfunc::checkValidReedem($parent)) ? "1" : "0";
  115. $wallet_amount = projectfunc::userWalletamount($parent, $parent->current_smpin);
  116. //SEND NOTIFICATION
  117. $nobj = new stdClass();
  118. $nobj->notificationtitle = 'Redemptions of redeem points';
  119. $nobj->notificationtext = 'Redemptions of redeem points will update to wallet on admin approval.';
  120. $nobj->notificationtype = '6';
  121. $nobj->notificationdata = new stdClass();
  122. // projectfunc::sendUserNotification($parent, $nobj);
  123. //ADDED TO APPROVAL
  124. $parent->executeQuery("INSERT INTO " . TABLE_USER_WALLET_APPROVE . "( `smpin`, `points`, `amount`, `lvl_id`, `is_approved`, `approved_id`, `created_on`, `modified_on`) VALUES ('" . $parent->current_smpin . "','" . $points . "','" . $redeem_amount . "','" . $query_multply['result'][0]->lvl_id . "','0' ,'0','" . NOW . "','" . NOW . "')");
  125. //GET UNAPPROVE AMOUNT
  126. $unapproved_amount = projectfunc::userUnapprovedamount($parent, $parent->current_smpin);
  127. $data_arr = array('earning' => $earning, 'is_redeem_point' => $is_redeem_point, 'wallet_amount' => $wallet_amount, 'unapproved_amount' => $unapproved_amount);
  128. $userdata = projectfunc::getuserdata($parent, $parent->current_user_id);
  129. //MAIL ADMIN
  130. $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
  131. <tr>
  132. <td><table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
  133. <tr>
  134. <td bgcolor="#4d90fe" height="36" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#070000; text-align:left; font-weight:bold; padding-left:14px; color:#fff">HYPER-M</td>
  135. </tr>
  136. <tr>
  137. <td bgcolor="#333333" style="line-height:3px;">&nbsp;</td>
  138. </tr>
  139. <tr><td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  140. line-height: 1.5;"><div style="font-family:Arial, Helvetica, sans-serif; color:#333; font-size:12px; padding:5px;" ><p style="font-family:Arial, Helvetica, sans-serif; color:#333; font-size:12px; padding:5px;">Redeem point approval request</p><table width="100%" style="border-collapse: collapse;">
  141. <tr><th style=" border: 1px solid black;">Name</th><th style=" border: 1px solid black;">SMPIN</th><th style=" border: 1px solid black;">Dealer</th><th style=" border: 1px solid black;">Points</th><th style=" border: 1px solid black;">Amount</th></tr>
  142. <tr><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px; ">' . $userdata->fname . ' ' . $userdata->lname . '</td><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px; ">' . $userdata->smpin . '</td><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px;">' . $userdata->dealer->dealer_name . '-' . $userdata->dealer->dealer_code . '</td><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px; ">' . $points . '</td><td style=" border: 1px solid black;font-family:Arial, Helvetica, sans-serif;font-size:12px; ">' . $redeem_amount . '</td></tr>
  143. </div></table>
  144. <br><br>
  145. <tr>
  146. <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:30px; text-align:center;"><div class="footer-con">
  147. <p>Thanks &amp; Regards, <strong style="color:#070000;">HYPER-M Support Team</strong></p>
  148. </div></td>
  149. </tr>
  150. <tr>
  151. <td bgcolor="#4d90fe" style="line-height:1px;">&nbsp;</td>
  152. </tr>
  153. </table></td>
  154. </tr>
  155. </table>';
  156. $obj = array();
  157. $obj['from'] = SUPPORT_EMAIL;
  158. $obj['to'] = SUPPORT_EMAIL;
  159. $obj['subject'] = "Redeem point approval request";
  160. $obj['message'] = $message;
  161. // globalfunc::sendMai($parent, $obj);
  162. //LOG
  163. $logstr = 'ADD WALLET AMOUNT';
  164. globalfunc::insertUserLog($parent, $logstr);
  165. $parent->response(array('response' => 'success', 'message' => "SUCCESS", 'data' => $data_arr), 200);
  166. }
  167. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  168. /* /////////////////////////////// WOOHOO //////////////////////////////////////////////// */
  169. private function woohooCurl($parent, $url, $post = null, $type)
  170. {
  171. // try {
  172. // $url = $this->woohoo_url . $url;
  173. // //GET SETTING
  174. // $data['setting'] = 'REDEEM';
  175. // $redeem_set = globalfunc::getSiteSetting($parent, $data);
  176. // $insert_db = 0;
  177. // switch ($type) {
  178. // case 'status':
  179. // case 'order':
  180. // break;
  181. // case 'category':
  182. // $query_data = $parent->selectQuery(TABLE_WOOHOO_CATEGORY, "*", "modified_on>'" . date('Y-m', strtotime(NOW)) . "-01 00:00:00'", "1");
  183. // if ($query_data['nr']) {
  184. // if (strpos($query_data['result'][0]->category_data, 'API Partners') !== false) {
  185. // $query_data['result'][0]->category_data = @str_replace('API Partners', 'BRANDS', $query_data['result'][0]->category_data);
  186. // }
  187. // $return_data = json_decode(trim($query_data['result'][0]->category_data));
  188. // return $return_data;
  189. // } else {
  190. // $insert_db = 1;
  191. // }
  192. // break;
  193. // case 'category_product':
  194. // $cat_arr = @explode('category/', $url);
  195. // $ncat_arr = @explode('/products?', $cat_arr[1]);
  196. // $cat_id = $ncat_arr[0];
  197. // $query_data = $parent->selectQuery(TABLE_WOOHOO_CATEGORY_DETAILS, "*", "cat_id='" . $cat_id . "' AND modified_on>'" . date('Y-m', strtotime(NOW)) . "-01 00:00:00'", "1");
  198. // if ($query_data['nr']) {
  199. // if (strpos($query_data['result'][0]->category_data, 'API Partners') !== false) {
  200. // $query_data['result'][0]->category_data = @str_replace('API Partners', 'BRANDS', $query_data['result'][0]->category_data);
  201. // }
  202. // if (strpos($query_data['result'][0]->category_data, '/thumbnail') !== false) {
  203. // $query_data['result'][0]->category_data = @str_replace('/thumbnail', '/mobile', $query_data['result'][0]->category_data);
  204. // }
  205. // if (strtolower($parent->device_type) == 'web' && strpos($query_data['result'][0]->category_data, '/image') !== false) {
  206. // $query_data['result'][0]->category_data = @str_replace('/image', '/mobile', $query_data['result'][0]->category_data);
  207. // }
  208. // $return_data = json_decode(trim($query_data['result'][0]->category_data));
  209. // return $return_data;
  210. // } else {
  211. // $insert_db = 1;
  212. // }
  213. // break;
  214. // case 'product':
  215. // $product_arr = @explode('products/', $url);
  216. // $product_id = $product_arr[1];
  217. // $query_data = $parent->selectQuery(TABLE_WOOHOO_PRODUCT, "*", "product_id='" . $product_id . "' AND modified_on>'" . date('Y-m', strtotime(NOW)) . "-01 00:00:00'", "1");
  218. // if ($query_data['nr']) {
  219. // if (strpos($query_data['result'][0]->product_data, '/thumbnail') !== false) {
  220. // $query_data['result'][0]->product_data = @str_replace('/thumbnail', '/mobile', $query_data['result'][0]->product_data);
  221. // }
  222. // if (strtolower($parent->device_type) == 'web' && strpos($query_data['result'][0]->product_data, '/image') !== false) {
  223. // $query_data['result'][0]->product_data = @str_replace('/image', '/mobile', $query_data['result'][0]->product_data);
  224. // }
  225. // $return_data = json_decode(trim($query_data['result'][0]->product_data));
  226. // return $return_data;
  227. // } else {
  228. // $insert_db = 1;
  229. // }
  230. // break;
  231. // }
  232. // $requestHttpMethod = ($post) ? 'POST' : 'GET';
  233. // $requestBody = ($post) ? json_encode($post) : '';
  234. // // if ($post) {
  235. // // $requestBody = '{"address":{"firstname":"Jhon","lastname":"Deo","email":"jhon.deo@gmail.com","telephone":"+919004052509","line1":"C G MOTORS","line2":"Mumbai (Vashi)","city":"Mumbai (Vashi)","region":"Karnataka","country":"IN","postcode":"560076","billToThis":true},"billing":{"firstname":"Jhon ","lastname":"Deo","email":"jhon.deo@gmail.com","telephone":"+919004052509","line1":"C G MOTORS","line2":"Mumbai (Vashi)","city":"Mumbai (Vashi)","region":"Karnataka","country":"IN","postcode":"560076"},"payments":[{"code":"svc","amount":1000}],"refno":"00100000000abf","products":[{"sku":"CNPIN","price":1000,"qty":1,"currency":356,"giftMessage":"HYPER-M","theme":""}],"syncOnly":true,"couponCode":"","deliveryMode":"API"}';
  236. // // //$post = json_decode($post, false);
  237. // // }
  238. // $signature = hash_hmac('sha512', getConcatenateBaseString($url, $requestHttpMethod, $requestBody), WOOHOO_CONSUMERSECRET);
  239. // $datetime = new DateTime(NOW);
  240. // $datestamp = $datetime->format('c');
  241. // $authorization = "Authorization: Bearer " . $redeem_set->WOOHOO_OAUTH2_TOKEN;
  242. // $header = array("Cache-Control: no-cache", "Content-Type: application/json", $authorization, 'dateAtClient: ' . $datestamp, 'signature: ' . $signature);
  243. // //POST DATA
  244. // if ($post) {
  245. // $options = array(CURLOPT_POST => 1, CURLOPT_POSTFIELDS => $requestBody, CURLOPT_HEADER => false, CURLOPT_HTTPHEADER => $header, CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 10, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => false);
  246. // $request = $requestBody;
  247. // } else {
  248. // $options = array(CURLOPT_HTTPHEADER => $header,
  249. // CURLOPT_HEADER => false,
  250. // CURLOPT_URL => $url,
  251. // CURLOPT_CONNECTTIMEOUT => 10,
  252. // CURLOPT_TIMEOUT => 10,
  253. // CURLOPT_RETURNTRANSFER => true,
  254. // CURLOPT_SSL_VERIFYPEER => false);
  255. // $request = "";
  256. // }
  257. // //WOOHOO LOG
  258. // $parent->executeQuery("INSERT INTO " . TABLE_WOOHOO_LOG . "(`userid`, `url`, `request`,`created_on`) VALUES ( '" . $parent->current_user_id . "','" . $url . "','" . escape_str($request) . "','" . NOW . "')");
  259. // $logid = $parent->lastInsertId();
  260. // $ch = curl_init();
  261. // curl_setopt_array($ch, $options);
  262. // $response = curl_exec($ch);
  263. // $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  264. // curl_close($ch);
  265. // if ($response != '' && strpos($response, '/thumbnail') !== false) {
  266. // $response = @str_replace('/thumbnail', '/mobile', $response);
  267. // }
  268. // if ($response != '' && strtolower($parent->device_type) == 'web' && strpos($response, '/image') !== false) {
  269. // $response = @str_replace('/image', '/mobile', $response);
  270. // }
  271. // //CLIENT REQUEST
  272. // if (strpos($response, 'API Partners') !== false) {
  273. // $response = @str_replace('API Partners', 'BRANDS', $response);
  274. // }
  275. // $return_data = json_decode(trim($response));
  276. // //LOG RESPONSE
  277. // $parent->executeQuery("UPDATE " . TABLE_WOOHOO_LOG . " SET response='" . escape_str(trim($response)) . "' WHERE id='" . $logid . "'");
  278. // switch ($type) {
  279. // case 'status':
  280. // case 'order':
  281. // break;
  282. // case 'category':
  283. // if ($insert_db == '1') {
  284. // if (isset($return_data->id) && isset($return_data->name) && $return_data->id > 0) {
  285. // //DELETE OLD RECORD
  286. // $parent->executeQuery("TRUNCATE " . TABLE_WOOHOO_CATEGORY . " ");
  287. // //INSERT
  288. // $parent->executeQuery("INSERT INTO " . TABLE_WOOHOO_CATEGORY . " ( `category_data`, `created_on`, `modified_on`) VALUES ('" . escape_str(json_encode($return_data)) . "','" . NOW . "','" . NOW . "') ");}
  289. // }
  290. // break;
  291. // case 'category_product':
  292. // if ($insert_db == '1') {
  293. // if (isset($return_data->id) && isset($return_data->name) && $return_data->id > 0) {
  294. // //DELETE OLD RECORD
  295. // $parent->executeQuery("DELETE FROM " . TABLE_WOOHOO_CATEGORY_DETAILS . " WHERE cat_id='" . $cat_id . "'");
  296. // $parent->executeQuery("INSERT INTO " . TABLE_WOOHOO_CATEGORY_DETAILS . " (`cat_id`, `category_data`, `created_on`, `modified_on`) VALUES ('" . $cat_id . "','" . escape_str(json_encode($return_data)) . "','" . NOW . "','" . NOW . "') ");
  297. // }
  298. // }
  299. // break;
  300. // case 'product':
  301. // if ($insert_db == '1') {
  302. // if (isset($return_data->id) && isset($return_data->sku)) {
  303. // //DELETE OLD RECORD
  304. // $parent->executeQuery("DELETE FROM " . TABLE_WOOHOO_PRODUCT . " WHERE product_id='" . $product_id . "'");
  305. // $parent->executeQuery("INSERT INTO " . TABLE_WOOHOO_PRODUCT . " (`product_id`, `product_data`, `created_on`, `modified_on`) VALUES ('" . $product_id . "','" . escape_str(json_encode($return_data)) . "','" . NOW . "','" . NOW . "') ");
  306. // }
  307. // }
  308. // break;
  309. // }
  310. // return $return_data;
  311. // } catch (Exception $e) {
  312. // $parent->response(array('response' => 'failed', 'message' => $e->getMessage()), 500);
  313. // exit;
  314. // }
  315. }
  316. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  317. /* /////////////////////////////// CATEGORY //////////////////////////////////////////////// */
  318. private function category($parent)
  319. {
  320. globalfunc::checkMethodType($parent, array('GET'));
  321. //globalfunc::checkParamCount($parent,1);
  322. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  323. projectfunc::generateWoohoo($parent);
  324. if (!projectfunc::userWalletamount($parent, $parent->current_smpin)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error7"]), 406);}
  325. //GET CATEGORY
  326. if (count($parent->params) == 1) {
  327. $url = "catalog/categories";
  328. $return_data = $this->woohooCurl($parent, $url, null, 'category');
  329. $category = new stdClass();
  330. $category->root_category = (object) array('category_id' => $return_data->id, 'category_name' => $return_data->name, 'category_image' => '');
  331. //LOG
  332. $logstr = 'WOOHOO CATEGORY';
  333. globalfunc::insertUserLog($parent, $logstr);
  334. $parent->response(array('response' => 'success', 'message' => "SUCCESS", 'data' => $category), 200);
  335. } else if (count($parent->params) == 2) {
  336. //GET CATEGORY DETAILS
  337. $categoryid = $parent->params[1];
  338. if (!is_numeric($categoryid)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error2"]), 406);}
  339. $url = "catalog/categories/" . $categoryid . '/products?offset=0&limit=1000';
  340. $return_data = $this->woohooCurl($parent, $url, null, 'category_product');
  341. // echo '<pre>';
  342. // print_r($return_data);
  343. // echo '</pre>';
  344. $category = new stdClass();
  345. $product = new stdClass();
  346. foreach ($return_data->products as $k => $v) {
  347. $return_data->products[$k]->id = $v->sku;
  348. $return_data->products[$k]->price_type = 'Range';
  349. $return_data->products[$k]->min_custom_price = $v->minPrice;
  350. $return_data->products[$k]->max_custom_price = $v->maxPrice;
  351. //BASE
  352. $return_data->products[$k]->images->base = ($return_data->products[$k]->images->base != '') ? $return_data->products[$k]->images->base : NOIMAGE_URL;
  353. $return_data->products[$k]->images->base_image = $return_data->products[$k]->images->base;
  354. //SMALL
  355. $return_data->products[$k]->images->small = ($return_data->products[$k]->images->small != '') ? $return_data->products[$k]->images->small : NOIMAGE_URL;
  356. $return_data->products[$k]->images->small_image = $return_data->products[$k]->images->small;
  357. }
  358. $product->product = $return_data->products;
  359. $category = (object) array('id' => $return_data->id, 'name' => $return_data->name, 'description' => $return_data->description, 'count' => $return_data->productsCount, '_embedded' => $product);
  360. //LOG
  361. $logstr = 'WOOHOO CATEGORY PRODUCTS';
  362. globalfunc::insertUserLog($parent, $logstr);
  363. if (isset($return_data->id) && $return_data->id > 0) {
  364. $parent->response(array('response' => 'success', 'message' => "SUCCESS", 'data' => $category), 200);
  365. } else {
  366. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error3"]), 406);
  367. }
  368. }
  369. }
  370. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  371. /* /////////////////////////////// PRODUCT //////////////////////////////////////////////// */
  372. private function product($parent)
  373. {
  374. globalfunc::checkMethodType($parent, array('GET'));
  375. globalfunc::checkParamCount($parent, 2);
  376. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  377. projectfunc::generateWoohoo($parent);
  378. if (!projectfunc::userWalletamount($parent, $parent->current_smpin)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error7"]), 406);}
  379. //GET PRODUCT DETAILS
  380. $productid = $parent->params[1];
  381. //if (!is_numeric($productid)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error4"]), 406);}
  382. $url = "catalog/products/" . $productid;
  383. $return_data = $this->woohooCurl($parent, $url, null, 'product');
  384. //print_r($return_data);
  385. $product = new stdClass();
  386. $return_data->id = $return_data->sku;
  387. $return_data->price_type = ucfirst(strtolower($return_data->price->type));
  388. $return_data->min_custom_price = $return_data->price->min;
  389. $return_data->max_custom_price = $return_data->price->max;
  390. $return_data->images = ($return_data->images->base) ? $return_data->images->base : NOIMAGE_URL;
  391. $return_data->tnc_mobile = $return_data->tnc->link;
  392. $return_data->tnc_web = $return_data->tnc->link;
  393. $return_data->custom_denominations = @implode(',', $return_data->price->denominations);
  394. //LOG
  395. $logstr = 'WOOHOO PRODUCT DETAILS';
  396. globalfunc::insertUserLog($parent, $logstr);
  397. if (isset($return_data->id) && $return_data->id != '') {
  398. $parent->response(array('response' => 'success', 'message' => "SUCCESS", 'data' => $return_data), 200);
  399. } else {
  400. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error4"]), 406);
  401. }
  402. }
  403. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  404. /* /////////////////////////////// ORDER //////////////////////////////////////////////// */
  405. private function order($parent)
  406. {
  407. globalfunc::checkMethodType($parent, array('POST'));
  408. globalfunc::checkParamCount($parent, 1);
  409. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  410. projectfunc::generateWoohoo($parent);
  411. if (!projectfunc::userWalletamount($parent, $parent->current_smpin)) {$parent->response(array('response' => 'failed', 'message' => $this->page_data["error7"]), 406);}
  412. //GET PRODUCT DETAILS
  413. $REQUEST_KEYS = array('product_id' => 'string', 'product_price' => 'number');
  414. globalfunc::mandatoryKey($parent, $REQUEST_KEYS);
  415. $product_id = escape_str($parent->_request["product_id"]);
  416. $product_price = escape_str($parent->_request["product_price"]);
  417. $url = "catalog/products/" . $product_id;
  418. $return_data = $this->woohooCurl($parent, $url, null, 'product');
  419. //print_r($return_data);
  420. $return_data->price_type = ucfirst(strtolower($return_data->price->type));
  421. $return_data->custom_denominations = $return_data->price->denominations;
  422. $return_data->images = ($return_data->images->base) ? $return_data->images->base : NOIMAGE_URL;
  423. //LOG
  424. $logstr = 'WOOHOO ORDER';
  425. globalfunc::insertUserLog($parent, $logstr);
  426. $current_amount = projectfunc::userWalletamount($parent, $parent->current_smpin);
  427. //print_r($return_data);
  428. if (isset($return_data->id) && isset($return_data->sku)) {
  429. if (!($current_amount >= $product_price)) {
  430. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error7"]), 406);
  431. }
  432. switch (strtolower($return_data->price_type)) {
  433. case "range":
  434. if (!($return_data->price->min <= $product_price && $return_data->price->max >= $product_price)) {
  435. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error9"]), 406);
  436. }
  437. break;
  438. case "slab":
  439. if (isset($return_data->custom_denominations) && is_array($return_data->custom_denominations)) {
  440. $slab_arr = $return_data->custom_denominations;
  441. //$slab_arr = @explode(',', $return_data->custom_denominations);
  442. if (!in_array($product_price, $slab_arr)) {
  443. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error9"]), 406);
  444. }
  445. } else {
  446. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error10"]), 406);
  447. }
  448. break;
  449. default:$parent->response(array('response' => 'failed', 'message' => $this->page_data["error8"]), 406);
  450. break;
  451. }
  452. //BILLING DETAILS
  453. $billing_obj = new stdClass();
  454. $shipping_obj = new stdClass();
  455. $billing_obj->firstname = $parent->current_user_data->fname;
  456. $billing_obj->lastname = $parent->current_user_data->lname;
  457. $billing_obj->email = $parent->current_user_data->emailid;
  458. $billing_obj->telephone = '+91' . $parent->current_user_data->mobileno;
  459. $user_data = projectfunc::getuserdata($parent, $parent->current_user_id);
  460. $billing_obj->line1 = $user_data->dealer->dealer_name;
  461. $billing_obj->line2 = $user_data->dealer->city;
  462. $billing_obj->city = $user_data->dealer->city;
  463. $billing_obj->region = $user_data->dealer->state;
  464. $billing_obj->country = "IN";
  465. $billing_obj->postcode = "560076";
  466. //$billing_obj->company = '';
  467. //SHIPPING DETAILS
  468. $shipping_obj->firstname = $parent->current_user_data->fname;
  469. $shipping_obj->lastname = $parent->current_user_data->lname;
  470. $shipping_obj->email = $parent->current_user_data->emailid;
  471. $shipping_obj->telephone = '+91' . $parent->current_user_data->mobileno;
  472. $shipping_obj->line1 = $user_data->dealer->dealer_name;
  473. $shipping_obj->line2 = $user_data->dealer->city;
  474. $shipping_obj->city = $user_data->dealer->city;
  475. $shipping_obj->region = $user_data->dealer->state;
  476. $shipping_obj->country = "IN";
  477. $shipping_obj->postcode = "560076";
  478. $shipping_obj->billToThis = true;
  479. //$shipping_obj->company = '';
  480. $post_obj = new stdClass();
  481. $post_obj->address = $shipping_obj;
  482. $post_obj->billing = $billing_obj;
  483. $post_obj->payments = array(array('code' => 'svc', 'amount' => (int) $product_price));
  484. $product_qty = 1;
  485. //INSERT INTO ORDER
  486. $parent->executeQuery("INSERT INTO " . TABLE_ORDER . "( `userid`,`smpin`, `product_id`, `product_name`, `product_desc`,images, `qty`, `product_amount`, `is_success`, `is_refund`, `created_on`, `modfified_on`) VALUES ( '" . $parent->current_user_id . "','" . $parent->current_smpin . "','" . $product_id . "','" . escape_str($return_data->name) . "','" . escape_str($return_data->name) . "','" . escape_str($return_data->images) . "','" . $product_qty . "','" . $product_price . "' ,'0','0','" . NOW . "','" . NOW . "')");
  487. $orderid = $parent->lastInsertId();
  488. //UDPATE ORDER ID
  489. $order_id = "SUZ" . date('ymd', strtotime(CUR_DATE)) . $orderid;
  490. $parent->executeQuery("UPDATE " . TABLE_ORDER . " SET order_id='" . $order_id . "' WHERE id='" . $orderid . "'");
  491. //WALLET UPDATE
  492. $new_balance = $current_amount - $product_price;
  493. $parent->executeQuery("UPDATE " . TABLE_USER_WALLET . " SET amount='" . $new_balance . "' WHERE smpin='" . $parent->current_smpin . "' ");
  494. $parent->executeQuery("INSERT INTO " . TABLE_USER_WALLET_HISTORY . "( `smpin`, `type`, `type_id`, `description`, `amount`, `transaction_type`, `created_on`, `modified_on`) VALUES ('" . $parent->current_smpin . "','ORDER','" . $orderid . "','ORDER','" . $product_price . "' ,'D','" . NOW . "','" . NOW . "')");
  495. $post_obj->refno = $order_id;
  496. //$post_obj->successUrl = "https://baseurl/ordercomplete/success";
  497. //$post_obj->failureUrl = "https://baseurl/ordercomplete/failure";
  498. $post_obj->products = array(array('sku' => $product_id, 'price' => (int) $product_price, 'qty' => $product_qty, 'currency' => 356, 'giftMessage' => '', "theme" => '')); //, "theme" => "bwi"
  499. $post_obj->syncOnly = true;
  500. $post_obj->deliveryMode = 'API';
  501. $url = "orders";
  502. //print_r($post_obj);
  503. $order_data = $this->woohooCurl($parent, $url, (array) $post_obj, 'order');
  504. if (isset($order_data->orderId) && $order_data->orderId != '') {
  505. $card_data = '';
  506. if (isset($order_data->cards) && count($order_data->cards) > 0) {
  507. //$key_name = key((array) $order_data->carddetails);
  508. //$card_obj = new stdClass();
  509. //$card_obj = $order_data->carddetails->$key_name[0];
  510. //$card_obj->name = $key_name;
  511. $card_data = escape_str(json_encode($order_data->cards[0]));
  512. }
  513. $parent->executeQuery("UPDATE " . TABLE_ORDER . " SET is_success='1',woohoo_order_id='" . escape_str($order_data->order_id) . "',woohoo_order_status='" . escape_str($order_data->status) . "',card_data='" . $card_data . "' WHERE id='" . $orderid . "'");
  514. //SEND NOTIFICATION
  515. $nobj = new stdClass();
  516. $nobj->notificationtitle = 'Order Placed successfully';
  517. $nobj->notificationtext = 'Order Placed successfully.';
  518. $nobj->notificationtype = '7';
  519. $nobj->notificationdata = new stdClass();
  520. // projectfunc::sendUserNotification($parent, $nobj);
  521. if ($order_data->payments[0]->balance < 25000) {
  522. $message = '<table width="100%" bgcolor="#dfdfdf" border="0" cellspacing="10" cellpadding="0" style="padding-top:10px;">
  523. <tbody><tr>
  524. <td><table width="700" border="0" align="center" cellpadding="0" cellspacing="0" style="background:#ffffff; margin-top:0px;">
  525. <tbody><tr>
  526. <td bgcolor="#2d2d2d" height="36" style="font-size:12px; font-family:Arial, Helvetica, sans-serif; color:#e4e4e4; text-align:left; font-weight:bold; padding-left:14px; border-bottom:2px solid black">HYPER-M - WOOHOO API LOW BALANCE</td>
  527. </tr>
  528. <tr><td><table width="85%" align="center">
  529. <tbody> <tr><td height="30" style="font-size:11px; font-family:Arial, Helvetica, sans-serif; color:#3f3f3f; text-align:left;padding-left: 10px;
  530. line-height: 1.5;"><div style="font-family:arial; color:#333; font-size:12px; padding:5px;" >Woohoo api balance is below 25000. <br>Balance Available : ' . $order_data->payments[0]->balance . '</div></td>
  531. </tr>
  532. </tbody></table>
  533. </td>
  534. </tr>
  535. <tr>
  536. <td style="padding-top:0px; padding-bottom:10px;"></td>
  537. </tr>
  538. <tr>
  539. <td style="font-family:Arial, Helvetica, sans-serif; font-size:12px; color:#3f3f3f; background:#fafafa; line-height:30px; text-align:center;border-bottom:2px solid black"><div class="footer-con">
  540. <p>Thanks &amp; Regards, <strong style="color:black;"> Support Team</strong></p>
  541. </div></td>
  542. </tr>
  543. </tbody></table></td>
  544. </tr>
  545. </tbody></table>';
  546. $obj = array();
  547. $obj['from'] = SUPPORT_EMAIL;
  548. //$obj['replayto']=SUPPORT_EMAIL;
  549. $obj['to'] = SUPPORT_EMAIL;
  550. $obj['subject'] = "Woohoo balance is less.";
  551. $obj['message'] = $message;
  552. // globalfunc::sendMai($parent, $obj);
  553. }
  554. $parent->response(array('response' => 'success', 'type' => '1', 'message' => "SUCCESS"), 200);
  555. } else {
  556. //REFUND WALLET
  557. /*
  558. * REFUND FROM CRON REFUND service only
  559. *
  560. $obj=new stdClass();
  561. $obj->type="REFUND";
  562. $obj->type_id=$orderid;
  563. $obj->description="REFUND ORDER";
  564. $obj->amount=$product_price;
  565. projectfunc::userAddWallet($parent,$obj,$parent->current_user_id);
  566. $parent->executeQuery("UPDATE ".TABLE_ORDER." SET is_refund='1' WHERE id='".$orderid."'");
  567. *
  568. */
  569. $parent->response(array('response' => 'success', 'type' => '2', 'message' => "SUCCESS"), 200);
  570. //$parent->response(array('response'=>'failed','message'=>$this->page_data["error10"]),406);
  571. }
  572. } else {
  573. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error4"]), 406);
  574. }
  575. }
  576. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  577. /* /////////////////////////////// ORDER //////////////////////////////////////////////// */
  578. private function orderstatus($parent)
  579. {
  580. globalfunc::checkMethodType($parent, array('GET'));
  581. globalfunc::checkParamCount($parent, 2);
  582. globalfunc::checkAuthrozation($parent, array('type' => 'user'));
  583. projectfunc::generateWoohoo($parent);
  584. $order_id = escape_str($parent->params[1]);
  585. $query_order_arr = $parent->selectQuery(TABLE_ORDER, "*", "is_success=1 AND smpin='" . $parent->current_smpin . "' AND id='" . $order_id . "' ", "1");
  586. if (!$query_order_arr['nr'] > 0) {
  587. $parent->response(array('response' => 'failed', 'message' => $this->page_data['error11']), 406);
  588. }
  589. $order_ref = $query_order_arr['result'][0]->order_id;
  590. $url = "order/" . $order_ref . "/status";
  591. $return_data = $this->woohooCurl($parent, $url, null, 'status');
  592. if ($return_data->status == 'COMPLETE') {
  593. $parent->executeQuery("UPDATE " . TABLE_ORDER . " SET woohoo_order_id='" . $return_data->orderId . "',woohoo_order_status='" . $return_data->status . "' ,modfified_on='" . NOW . "' WHERE id='" . $order_id . "'");
  594. $query_arr = $parent->selectQuery(TABLE_ORDER, "*", " smpin='" . $parent->current_smpin . "' AND is_success='1' AND smpin='" . $parent->current_smpin . "' AND id='" . $order_id . "' ", "1");
  595. $parent->response(array('response' => 'success', 'data' => $query_arr['result'][0], 'message' => "SUCCESS"), 200);
  596. } else {
  597. $parent->response(array('response' => 'failed', 'message' => $this->page_data["error10"]), 406);
  598. }
  599. }
  600. /* //////////////////////////////////////////////////////////////////////////////////////////// */
  601. }