Advertisement
Guest User

Untitled

a guest
May 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.52 KB | None | 0 0
  1. <?php
  2. class Orders extends CI_Model
  3. {
  4. public function __construct()
  5. {
  6. $this->load->model('Apa');
  7. $this->load->model('Cartel');
  8. }
  9. public function cinfo($id = null)
  10. {
  11. $id = ($id == null ? $this->session->userdata('auth') : $id);
  12. $orderan = $this->db->get_where('orderan', array(
  13. 'user_id' => $id
  14. ))->num_rows();
  15. $ordersukses = $this->db->get_where('orderan', array(
  16. 'user_id' => $id,
  17. 'status' => 'completed'
  18. ))->num_rows();
  19. $array = array(
  20. 'biasa' => $orderan,
  21. 'sukses' => $ordersukses
  22. );
  23. return $array;
  24. }
  25. public function _InfoOrder($id, $user)
  26. {
  27. foreach ($this->db->query("SELECT * FROM orderan where id = '$id' AND user_id = '$user'")->result() as $order);
  28. if (!$id) {
  29. return array(
  30. 'error' => true,
  31. 'msg' => "Order ID Not Found"
  32. );
  33. } else if (!$order) {
  34. return array(
  35. 'error' => true,
  36. "msg" => "Order ID Not Found"
  37. );
  38. } else {
  39. $service = false;
  40. foreach ($this->db->query("SELECT * FROM service where id = '" . $order->service_id . "'")->result() as $service);
  41. return array(
  42. 'charge' => $order->quantity * $service->price,
  43. 'start_count' => (int) $order->start,
  44. 'status' => $order->status,
  45. 'remains' => (int) $order->remains
  46. );
  47. }
  48. }
  49. public function UpdateAll()
  50. {
  51. foreach ($this->db->query("SELECT o.id,o.status,o.order_id_pro FROM orderan as o inner join service as s on o.service_id = s.id WHERE o.status <> 'Completed' AND o.status <> 'Canceled' AND o.status <> 'Partial' AND o.order_id_pro <> '' AND o.order_id_pro <> '0' ORDER BY RAND() LIMIT 50")->result() as $data) {
  52. $this->benchmark->mark('code_start');
  53. $status = $this->_CheckOrder($data->id);
  54. $this->benchmark->mark('code_end');
  55. echo "Updating Order ID {$data->id} | {$data->order_id_pro} - ".$this->benchmark->elapsed_time('code_start', 'code_end')." sec . response : $status <br/>";
  56. }
  57. }
  58. function time_elapsed_string($datetime, $full = false) {
  59. $now = new DateTime;
  60. $ago = new DateTime($datetime);
  61. $diff = $now->diff($ago);
  62.  
  63. $diff->w = floor($diff->d / 7);
  64. $diff->d -= $diff->w * 7;
  65.  
  66. $string = array(
  67. 'y' => 'year',
  68. 'm' => 'month',
  69. 'w' => 'week',
  70. 'd' => 'day',
  71. 'h' => 'hour',
  72. 'i' => 'minute',
  73. 's' => 'second',
  74. );
  75. foreach ($string as $k => &$v) {
  76. if ($diff->$k) {
  77. $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
  78. } else {
  79. unset($string[$k]);
  80. }
  81. }
  82.  
  83. if (!$full) $string = array_slice($string, 0, 1);
  84. return $string ? implode(', ', $string) . ' ' : '';
  85. }
  86. public function _CheckOrder($id)
  87. {
  88. $order = false;
  89. foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $order);
  90. if (!$id) {
  91. return false;
  92. } else if (!$order) {
  93. return false;
  94. } else if ($order->status == "Completed" || $order->status == "Partial" || $order->status == "Canceled") {
  95. return false;
  96. } else {
  97. $service = false;
  98. foreach ($this->db->query("SELECT * FROM service where id = '$order->service_id' LIMIT 1")->result() as $service);
  99. if($service == false){
  100. return "ERROR BRO";
  101. }
  102. $aps = $service->api_id;
  103. if ($aps !== '0') {
  104. foreach ($this->db->query("SELECT * FROM api where id ='$aps' LIMIT 1")->result() as $api);
  105. if ($api->type == 'Basic') {
  106. $this->Apa->set($api->url, $api->api);
  107. $data = $this->Apa->status($order->order_id_pro);
  108. if (!$data == null && array_key_exists('status', $data)) {
  109. $status = $data->status;
  110. if ($status == 'Pending') {
  111. $s = "Pending";
  112. } else if ($status == "In progress") {
  113. $s = "Processing";
  114. } else if ($status == "Completed") {
  115. $s = "Completed";
  116. } else if ($status == "Partial") {
  117. $s = "Partial";
  118. } else if ($status == "Canceled") {
  119. $s = "Canceled";
  120. } else {
  121. $s = $status;
  122. }
  123. foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
  124. if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
  125. return false;
  126. }
  127. if ($s == "Canceled") {
  128. $refund = $order->quantity * $service->price;
  129. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  130. $U = $this->Users->info($order->user_id);
  131. $this->db->insert("balance_history", array(
  132. 'user_id' => $order->user_id,
  133. 'balance' => $refund,
  134. 'balance_current' => $U->balance,
  135. 'type' => 1,
  136. 'message' => "Pengembalian Cancel Pembelian #{$id}"
  137. ));
  138. } else if ($status == "Partial") {
  139. $refund = $data->remains * $service->price;
  140. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  141. $U = $this->Users->info($order->user_id);
  142. $this->db->insert("balance_history", array(
  143. 'user_id' => $order->user_id,
  144. 'balance' => $refund,
  145. 'balance_current' => $U->balance,
  146. 'type' => 1,
  147. 'message' => "Pengembalian Partial Pembelian #{$id}"
  148. ));
  149. }
  150. $this->db->where('id', $id)->update('orderan', array(
  151. 'status' => $s,
  152. 'start' => $data->start_count,
  153. 'remains' => $data->remains
  154. ));
  155. return $status;
  156.  
  157. } else {
  158. return "Something Went Wrong From API";
  159. }
  160. } else if ($api->type == 'IrvanKede') {
  161. $this->Apa->set($api->url, $api->api);
  162. $data = $this->Apa->status_irvan($order->order_id_pro);
  163. if ($data != null && array_key_exists('status', $data)) {
  164. $status = false;
  165. print_r($data);
  166. $status = $data->data->status;
  167. if(!$status){
  168. return "ERROR FROM API , ANJING NIH IRVAN KEDE ASW";
  169. }
  170. if ($status == '1') {
  171. $s = "Pending";
  172. } else if ($status == "2") {
  173. $s = "Processing";
  174. } else if ($status == "5") {
  175. $s = "Completed";
  176. } else if ($status == "3") {
  177. $s = "Partial";
  178. } else if ($status == "4") {
  179. $s = "Canceled";
  180. } else {
  181. $s = $status;
  182. }
  183. foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
  184. if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
  185. return false;
  186. }
  187. if ($s == "Canceled") {
  188. $refund = $order->quantity * $service->price;
  189. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  190. $U = $this->Users->info($order->user_id);
  191. $this->db->insert("balance_history", array(
  192. 'user_id' => $order->user_id,
  193. 'balance' => $refund,
  194. 'balance_current' => $U->balance,
  195. 'type' => 1,
  196. 'message' => "Pengembalian Cancel Pembelian #{$id}"
  197. ));
  198. } else if ($s == "Partial") {
  199. $refund = $data->data->remains * $service->price;
  200. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  201. $U = $this->Users->info($order->user_id);
  202. $this->db->insert("balance_history", array(
  203. 'user_id' => $order->user_id,
  204. 'balance' => $refund,
  205. 'balance_current' => $U->balance,
  206. 'type' => 1,
  207. 'message' => "Pengembalian Partial Pembelian #{$id}"
  208. ));
  209. }
  210. $this->db->where('id', $id)->update('orderan', array(
  211. 'status' => $s,
  212. 'start' => $data->data->start_count,
  213. 'remains' => ($data->data->remains ? $data->data->remains : 0)
  214. ));
  215. return $status;
  216.  
  217. } else {
  218. return "Something Went Wrong From API";
  219. }
  220. }
  221. else if ($api->type == 'Regram') {
  222. $this->Apa->set($api->url, $api->api);
  223. $data = $this->Apa->status_regram($order->order_id_pro);
  224. if (array_key_exists('status', $data)) {
  225. $status = $data->data->status;
  226. if ($status == 'Pending') {
  227. $s = "Pending";
  228. } else if ($status == "Processing") {
  229. $s = "Processing";
  230. } else if ($status == "Success") {
  231. $s = "Completed";
  232. } else if ($status == "Partial") {
  233. $s = "Partial";
  234. } else if ($status == "Error") {
  235. $s = "Canceled";
  236. } else {
  237. $s = $status;
  238. }
  239. foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
  240. if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
  241. return false;
  242. }
  243.  
  244. if ($s == "Canceled") {
  245. $refund = $order->quantity * $service->price;
  246. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  247. $U = $this->Users->info($order->user_id);
  248. $this->db->insert("balance_history", array(
  249. 'user_id' => $order->user_id,
  250. 'balance' => $refund,
  251. 'balance_current' => $U->balance,
  252. 'type' => 1,
  253. 'message' => "Pengembalian Cancel Pembelian #{$id}"
  254. ));
  255. } else if ($status == "Partial") {
  256. $refund = $data->data->remains * $service->price;
  257. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  258. $U = $this->Users->info($order->user_id);
  259. $this->db->insert("balance_history", array(
  260. 'user_id' => $order->user_id,
  261. 'balance' => $refund,
  262. 'balance_current' => $U->balance,
  263. 'type' => 1,
  264. 'message' => "Pengembalian Partial Pembelian #{$id}"
  265. ));
  266. }
  267. $this->db->where('id', $id)->update('orderan', array(
  268. 'status' => $s,
  269. 'start' => $data->data->start,
  270. 'remains' => $data->data->remains
  271. ));
  272.  
  273. } else {
  274. return "LOL";
  275. }
  276.  
  277. }
  278. else if ($api->type == '2Cartel') {
  279. $Arrder = array(
  280. 'KEY' => $order->order_id_pro
  281. );
  282. $this->Cartel->set($api->url, $api->api);
  283. $data = $this->Cartel->get("orders/status", $Arrder);
  284. if ($data['error'] == false) {
  285. $orderData = $data['data']['result'][$order->order_id_pro][0];
  286. $status = $data['data']['result'][$order->order_id_pro][0]['status'];
  287. if ($status == '0') {
  288. $s = "Pending";
  289. } else if ($status == "1") {
  290. $s = "Pending";
  291. } else if ($status == "2") {
  292. $s = "Processing";
  293. } else if ($status == "3") {
  294. $s = "Processing";
  295. } else if ($status == "4") {
  296. $s = "Completed";
  297. } else if ($status == "5") {
  298. $s = "Partial";
  299. } else if ($status == "6") {
  300. $s = "Canceled";
  301. }
  302. foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
  303. if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
  304. return false;
  305. }
  306. if ($status == "6") {
  307. $refund = $order->quantity * $service->price;
  308.  
  309. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  310. $U = $this->Users->info($order->user_id);
  311. $this->db->insert("balance_history", array(
  312. 'user_id' => $order->user_id,
  313. 'balance' => $refund,
  314. 'balance_current' => $U->balance,
  315. 'type' => 1,
  316. 'message' => "Pengembalian Cancel Pembelian #{$id}"
  317. ));
  318. } else if ($status == "5") {
  319. $refund = $orderData['remains'] * $service->price;
  320.  
  321. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  322. $U = $this->Users->info($order->user_id);
  323. $this->db->insert("balance_history", array(
  324. 'user_id' => $order->user_id,
  325. 'balance' => $refund,
  326. 'balance_current' => $U->balance,
  327. 'type' => 1,
  328. 'message' => "Pengembalian Partial Pembelian #{$id}"
  329. ));
  330. }
  331. $this->db->where('id', $id)->update('orderan', array(
  332. 'status' => $s,
  333. 'start' => $orderData['start'],
  334. 'remains' => $orderData['remains']
  335. ));
  336. return $status;
  337. }
  338. } else if ($api->type == 'PostLikes') {
  339. $this->Apa->set($api->url, $api->api);
  340. $data = $this->Apa->status_post($order->order_id_pro);
  341.  
  342. if ($data != null || array_key_exists('status', $data)) {
  343. $status = $data->orderStatus;
  344. if ($status == 'Pending') {
  345. $s = "Pending";
  346. } else if ($status == "Processing" || $status == "In Progress") {
  347. $s = "Processing";
  348. } else if ($status == "Completed") {
  349. $s = "Completed";
  350. } else if ($status == "Partially Completed") {
  351. $s = "Partial";
  352. } else if ($status == "Canceled" || $status == "Error") {
  353. $s = "Canceled";
  354. } else {
  355. $s = $status;
  356. }
  357. foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
  358. if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
  359. return false;
  360. }
  361. if ($s == "Canceled") {
  362. $refund = $order->quantity * $service->price;
  363. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  364. $U = $this->Users->info($order->user_id);
  365. $this->db->insert("balance_history", array(
  366. 'user_id' => $order->user_id,
  367. 'balance' => $refund,
  368. 'balance_current' => $U->balance,
  369. 'type' => 1,
  370. 'message' => "Pengembalian Cancel Pembelian #{$id}"
  371. ));
  372. } else if ($s == "Partial") {
  373. $refund = $data->remaining_amount * $service->price;
  374. $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
  375. $U = $this->Users->info($order->user_id);
  376. $this->db->insert("balance_history", array(
  377. 'user_id' => $order->user_id,
  378. 'balance' => $refund,
  379. 'balance_current' => $U->balance,
  380. 'type' => 1,
  381. 'message' => "Pengembalian Partial Pembelian #{$id}"
  382. ));
  383. }
  384. $this->db->where('id', $id)->update('orderan', array(
  385. 'status' => $s,
  386. 'start' => $data->startCount,
  387. 'remains' => $data->remaining_amount
  388. ));
  389.  
  390. return $status;
  391.  
  392. } else {
  393. return "Something Went Wrong From API";
  394. }
  395.  
  396. }
  397. }
  398. }
  399. }
  400. public function _AddOrder($service, $link, $quantity = 0, $key = null, $usernames = null, $comments = null, $username = null)
  401. {
  402. if (!$key) {
  403. if (!$this->session->userdata('auth')) {
  404. return true;
  405. }
  406. }
  407. if(!is_int((int) $quantity)){
  408. return array(
  409. "error" => true,
  410. "msg" => "Invalid Data"
  411. );
  412. }
  413. $s = $service;
  414. $l = $link;
  415. $q = $quantity;
  416. $service = array();
  417. $api = array();
  418. $User = ($key == null ? $this->Users->info() : $this->Users->info_token($key));
  419. if (!$User) {
  420. return true;
  421. }
  422. $service = null;
  423. foreach ($this->db->query("SELECT * FROM service where id = ? AND status = ?", array(
  424. $s,
  425. "0"
  426. ))->result() as $service);
  427. if (!$service || !$link) {
  428. return array(
  429. 'error' => true,
  430. "msg" => "Empty Data"
  431. );
  432. } else if (is_int($s) || !is_string($l)) {
  433. return array(
  434. 'error' => true,
  435. "msg" => "Invalid Data "
  436. );
  437. } else if ($service == null) {
  438. return array(
  439. 'error' => true,
  440. "msg" => "Service Not Found"
  441. );
  442. } else {
  443. if ($service->api_id !== '0') {
  444. $aps = $service->api_id;
  445. foreach ($this->db->query("SELECT * FROM api where id ='$aps'")->result() as $api);
  446.  
  447. if ($api->type == 'Basic') {
  448. $extends = "";
  449. if ($service->type == 'Default') {
  450. if (!$q) {
  451. return array(
  452. 'error' => true,
  453. 'msg' => "Invalid Quantity"
  454. );
  455. }
  456. $Arrder = array(
  457. 'service' => $service->pro_id,
  458. 'link' => $l,
  459. 'quantity' => $q
  460. );
  461.  
  462. } else if ($service->type == "CC") {
  463. if (!$comments) {
  464. return array(
  465. 'error' => true,
  466. 'msg' => "Invalid Comments"
  467. );
  468. }
  469. $extends = $comments;
  470.  
  471. $Arrder = array(
  472. 'service' => $service->pro_id,
  473. 'link' => $l,
  474. 'comments' => $comments
  475. );
  476. $q = count(explode("\n", $comments));
  477.  
  478. } else if ($service->type == "MCL") {
  479.  
  480. if (!$usernames) {
  481. return array(
  482. 'error' => true,
  483. 'msg' => "Invalid Usernames"
  484. );
  485. }
  486. $extends = $usernames;
  487.  
  488. $Arrder = array(
  489. 'service' => $service->pro_id,
  490. 'link' => $l,
  491. 'usernames' => $usernames
  492. );
  493. $q = count(explode("\n", $usernames));
  494.  
  495. } else if ($service->type == "MUF") {
  496. if (!$username || !$q) {
  497. return array(
  498. 'error' => true,
  499. 'msg' => "Invalid Usernames"
  500. );
  501. }
  502. $extends = $username;
  503.  
  504. $Arrder = array(
  505. 'service' => $service->pro_id,
  506. 'link' => $l,
  507. 'username' => $username,
  508. 'quantity' => $q
  509. );
  510. } else {
  511. return array(
  512. 'error' => true,
  513. 'msg' => "Invalid ?"
  514. );
  515. }
  516. if ($User->balance < $service->price * $q) {
  517. return array(
  518. 'error' => true,
  519. "msg" => "Insufficient balance"
  520. );
  521. } else if ($q < $service->min - 1) {
  522. return array(
  523. 'error' => true,
  524. "msg" => "Invalid Quantity"
  525. );
  526. } else if ($q > $service->max) {
  527. return array(
  528. 'error' => true,
  529. "msg" => "Invalid Quantity"
  530. );
  531. }
  532. $this->Apa->set($api->url, $api->api);
  533. $data = $this->Apa->order($Arrder);
  534. if ($data == null) {
  535. return array(
  536. 'error' => true,
  537. "msg" => "ERROR !"
  538. );
  539. }
  540. if (array_key_exists('order', $data)) {
  541. $rand = rand(11111, 99999);
  542. $order_id = $data->order;
  543.  
  544. $this->db->where('id', $User->id)->update('user', array(
  545. 'balance' => $User->balance - $q * $service->price
  546. ));
  547. $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
  548. $this->db->insert('orderan', array(
  549. 'user_id' => $User->id,
  550. 'service_id' => $s,
  551. 'target' => $l,
  552. 'quantity' => $q,
  553. 'extends_form' => $extends,
  554. 'date' => date('Y-m-d H:i:s'),
  555. 'data' => "PRO",
  556. 'status' => "Pending",
  557. "order_id_pro" => $order_id
  558. ));
  559. $ids = $this->db->insert_id();
  560.  
  561. $U = $this->Users->info($User->id);
  562. $this->db->insert("balance_history", array(
  563. 'user_id' => $U->id,
  564. 'balance' => $q * $service->price,
  565. 'balance_current' => $U->balance,
  566. 'type' => 0,
  567. 'message' => "Pembelian #{$ids}"
  568. ));
  569. return array(
  570. 'error' => false,
  571. 'id' => $ids,
  572. "msg" => "OK",
  573. "price" => $service->price * $q,
  574. "service" => $service->name,
  575. 'quantity' => $q
  576. );
  577. } else {
  578. return array(
  579. 'error' => true,
  580. 'msg' =>
  581. //"Can't Contacting Server"
  582. $data->error
  583. );
  584. }
  585.  
  586. } else if ($api->type == 'IrvanKede') {
  587. if ($service->type == 'Default') {
  588. if (!$q) {
  589. return array(
  590. 'error' => true,
  591. 'msg' => "Invalid Quantity"
  592. );
  593. }
  594. $Arrder = array(
  595. 'service' => $service->pro_id,
  596. 'target' => $l,
  597. 'quantity' => $q
  598. );
  599. } else {
  600. return array(
  601. 'error' => true,
  602. 'msg' => "Invalid ?"
  603. );
  604. }
  605. if ($User->balance < $service->price * $q) {
  606. return array(
  607. 'error' => true,
  608. "msg" => "Insufficient balance"
  609. );
  610. } else if ($q < $service->min - 1) {
  611. return array(
  612. 'error' => true,
  613. "msg" => "Invalid Quantity"
  614. );
  615. } else if ($q > $service->max) {
  616. return array(
  617. 'error' => true,
  618. "msg" => "Invalid Quantity"
  619. );
  620. }
  621. $this->Apa->set($api->url, $api->api);
  622. $data = $this->Apa->order_irvan($Arrder);
  623. if ($data->status) {
  624. $rand = rand(11111, 99999);
  625. $order_id = $data->data->id;
  626.  
  627. $this->db->insert('orderan', array(
  628. 'user_id' => $User->id,
  629. 'service_id' => $s,
  630. 'target' => $l,
  631. 'quantity' => $q,
  632. 'extends_form' => '',
  633. 'date' => date('Y-m-d H:i:s'),
  634. 'data' => "PRO",
  635. 'status' => "Pending",
  636. "order_id_pro" => $order_id
  637. ));
  638. $ids = $this->db->insert_id();
  639.  
  640. $this->db->where('id', $User->id)->update('user', array(
  641. 'balance' => $User->balance - $q * $service->price
  642. ));
  643. $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
  644. $U = $this->Users->info($User->id);
  645. $this->db->insert("balance_history", array(
  646. 'user_id' => $U->id,
  647. 'balance' => $q * $service->price,
  648. 'balance_current' => $U->balance,
  649. 'type' => 0,
  650. 'message' => "Pembelian #{$ids}"
  651. ));
  652. return array(
  653. 'error' => false,
  654. 'id' => $ids,
  655. "msg" => "OK",
  656. "price" => $service->price * $q,
  657. "service" => $service->name,
  658. 'quantity' => $q
  659. );
  660. } else {
  661. return array(
  662. 'error' => true,
  663. 'msg' =>
  664. // "Silahkan Hubungi Admin"
  665. $data['data']['msg']
  666. );
  667. }
  668.  
  669. } else if ($api->type == 'Regram') {
  670. if ($service->type == 'Default') {
  671. if (!$q) {
  672. return array(
  673. 'error' => true,
  674. 'msg' => "Invalid Quantity"
  675. );
  676. }
  677. $Arrder = array(
  678. 'product' => $service->pro_id,
  679. 'data' => $l,
  680. 'quantity' => $q
  681. );
  682. } else {
  683. return array(
  684. 'error' => true,
  685. 'msg' => "Invalid ?"
  686. );
  687. }
  688. if ($User->balance < $service->price * $q) {
  689. return array(
  690. 'error' => true,
  691. "msg" => "Insufficient balance"
  692. );
  693. } else if ($q < $service->min - 1) {
  694. return array(
  695. 'error' => true,
  696. "msg" => "Invalid Quantity"
  697. );
  698. } else if ($q > $service->max) {
  699. return array(
  700. 'error' => true,
  701. "msg" => "Invalid Quantity"
  702. );
  703. }
  704. $this->Apa->set($api->url, $api->api);
  705. $data = $this->Apa->order_regram($Arrder);
  706. if ($data->status) {
  707. $rand = rand(11111, 99999);
  708. $order_id = $data->data->code;
  709.  
  710. $this->db->insert('orderan', array(
  711. 'user_id' => $User->id,
  712. 'service_id' => $s,
  713. 'target' => $l,
  714. 'quantity' => $q,
  715. 'extends_form' => '',
  716. 'date' => date('Y-m-d H:i:s'),
  717. 'data' => "PRO",
  718. 'status' => "Pending",
  719. "order_id_pro" => $order_id
  720. ));
  721. $ids = $this->db->insert_id();
  722.  
  723. $this->db->where('id', $User->id)->update('user', array(
  724. 'balance' => $User->balance - $q * $service->price
  725. ));
  726. $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
  727. $U = $this->Users->info($User->id);
  728. $this->db->insert("balance_history", array(
  729. 'user_id' => $U->id,
  730. 'balance' => $q * $service->price,
  731. 'balance_current' => $U->balance,
  732. 'type' => 0,
  733. 'message' => "Pembelian #{$ids}"
  734. ));
  735. return array(
  736. 'error' => false,
  737. 'id' => $ids,
  738. "msg" => "OK",
  739. "price" => $service->price * $q,
  740. "service" => $service->name,
  741. 'quantity' => $q
  742. );
  743. } else {
  744. return array(
  745. 'error' => true,
  746. 'msg' =>
  747. // "Silahkan Hubungi Admin"
  748. $data->message
  749. );
  750. }
  751.  
  752.  
  753.  
  754. } else if ($api->type == '2Cartel') {
  755. if ($service->type == 'Default') {
  756. if (!$q) {
  757. return array(
  758. 'error' => true,
  759. 'msg' => "Invalid Quantity"
  760. );
  761. }
  762. $Arrder = array(
  763. 'type' => $service->pro_id,
  764. 'link' => $l,
  765. 'quantity' => $q
  766. );
  767. } else {
  768. return array(
  769. 'error' => true,
  770. 'msg' => "Invalid ?"
  771. );
  772. }
  773. if ($User->balance < $service->price * $q) {
  774. return array(
  775. 'error' => true,
  776. "msg" => "Insufficient balance"
  777. );
  778. } else if ($q < $service->min - 1) {
  779. return array(
  780. 'error' => true,
  781. "msg" => "Invalid Quantity"
  782. );
  783. } else if ($q > $service->max) {
  784. return array(
  785. 'error' => true,
  786. "msg" => "Invalid Quantity"
  787. );
  788. }
  789. $this->Cartel->set($api->url, $api->api);
  790. $data = $this->Cartel->post("orders/add", $Arrder);
  791.  
  792. if ($data['error'] == false) {
  793. $rand = rand(11111, 99999);
  794. $order_id = $data['orders']['add'][0]['order_key'];
  795.  
  796. $this->db->insert('orderan', array(
  797. 'user_id' => $User->id,
  798. 'service_id' => $s,
  799. 'target' => $l,
  800. 'quantity' => $q,
  801. 'extends_form' => '',
  802. 'date' => date('Y-m-d H:i:s'),
  803. 'data' => "PRO",
  804. 'status' => "Pending",
  805. "order_id_pro" => $order_id
  806. ));
  807. $ids = $this->db->insert_id();
  808. $this->db->where('id', $User->id)->update('user', array(
  809. 'balance' => $User->balance - $q * $service->price
  810. ));
  811. $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
  812. $U = $this->Users->info($User->id);
  813. $this->db->insert("balance_history", array(
  814. 'user_id' => $U->id,
  815. 'balance' => $q * $service->price,
  816. 'balance_current' => $U->balance,
  817. 'type' => 0,
  818. 'message' => "Pembelian #{$ids}"
  819. ));
  820. return array(
  821. 'error' => false,
  822. 'id' => $ids,
  823. "msg" => "OK",
  824. "price" => $service->price * $q,
  825. "service" => $service->name,
  826. 'quantity' => $q
  827. );
  828. } else {
  829. $error = $data['msg'];
  830. if ($error == "Saldo Tidak Cukup") {
  831. $error = "Silahkan Kontak Admin";
  832. }
  833. return array(
  834. 'error' => true,
  835. 'msg' => $error
  836. );
  837. }
  838.  
  839. } else if ($api->type == 'PostLikes') {
  840. if ($service->type == 'Default') {
  841. if (!$q) {
  842. return array(
  843. 'error' => true,
  844. 'msg' => "Invalid Quantity"
  845. );
  846. }
  847. $Arrder = array(
  848. 'orderType' => $service->pro_id,
  849. 'orderUrl' => $l,
  850. 'orderQuantity' => $q
  851. );
  852. } else {
  853. return array(
  854. 'error' => true,
  855. 'msg' => "Invalid ?"
  856. );
  857. }
  858. if ($User->balance < $service->price * $q) {
  859. return array(
  860. 'error' => true,
  861. "msg" => "Insufficient balance"
  862. );
  863. } else if ($q < $service->min - 1) {
  864. return array(
  865. 'error' => true,
  866. "msg" => "Invalid Quantity"
  867. );
  868. } else if ($q > $service->max) {
  869. return array(
  870. 'error' => true,
  871. "msg" => "Invalid Quantity"
  872. );
  873. }
  874. $this->Apa->set($api->url, $api->api);
  875. $data = $this->Apa->order_post($Arrder);
  876. if (array_key_exists('orderID', $data)) {
  877. $rand = rand(11111, 99999);
  878. $order_id = $data->orderID;
  879.  
  880. $this->db->insert('orderan', array(
  881. 'user_id' => $User->id,
  882. 'service_id' => $s,
  883. 'target' => $l,
  884. 'quantity' => $q,
  885. 'extends_form' => '',
  886. 'date' => date('Y-m-d H:i:s'),
  887. 'data' => "PRO",
  888. 'status' => "Pending",
  889. "order_id_pro" => $order_id
  890. ));
  891. $ids = $this->db->insert_id();
  892.  
  893. $this->db->where('id', $User->id)->update('user', array(
  894. 'balance' => $User->balance - $q * $service->price
  895. ));
  896. $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
  897. $U = $this->Users->info($User->id);
  898. $this->db->insert("balance_history", array(
  899. 'user_id' => $U->id,
  900. 'balance' => $q * $service->price,
  901. 'balance_current' => $U->balance,
  902. 'type' => 0,
  903. 'message' => "Pembelian #{$ids}"
  904. ));
  905. return array(
  906. 'error' => false,
  907. 'id' => $ids,
  908. "msg" => "OK",
  909. "price" => $service->price * $q,
  910. "service" => $service->name,
  911. 'quantity' => $q
  912. );
  913. } else {
  914. return array(
  915. 'error' => true,
  916. 'msg' =>
  917. // "Silahkan Hubungi Admin"
  918. $data->error
  919. );
  920. }
  921. }
  922.  
  923.  
  924. } else {
  925. if ($User->balance < $service->price * $q) {
  926. return array(
  927. 'error' => true,
  928. "msg" => "Insufficient balance"
  929. );
  930. } else if ($q < $service->min - 1) {
  931. return array(
  932. 'error' => true,
  933. "msg" => "Invalid Quantity"
  934. );
  935. } else if ($q > $service->max) {
  936. return array(
  937. 'error' => true,
  938. "msg" => "Invalid Quantity"
  939. );
  940. }
  941. $rand = rand(11111, 99999);
  942. $this->db->insert('orderan', array(
  943. 'user_id' => $User->id,
  944. 'service_id' => $s,
  945. 'target' => $l,
  946. 'quantity' => $q,
  947. 'extends_form' => '',
  948. 'date' => date('Y-m-d H:i:s'),
  949. 'data' => "PRO",
  950. 'status' => "Pending",
  951. "order_id_pro" => '0'
  952. ));
  953. $ids = $this->db->insert_id();
  954. $this->db->where('id', $User->id)->update('user', array(
  955. 'balance' => $User->balance - $q * $service->price
  956. ));
  957. $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
  958. $U = $this->Users->info($User->id);
  959. $this->db->insert("balance_history", array(
  960. 'user_id' => $U->id,
  961. 'balance' => $q * $service->price,
  962. 'balance_current' => $U->balance,
  963. 'type' => 0,
  964. 'message' => "Pembelian #{$ids}"
  965. ));
  966. return array(
  967. 'error' => false,
  968. 'id' => $ids,
  969. "msg" => "OK",
  970. "price" => $service->price * $q,
  971. "service" => $service->name,
  972. 'quantity' => $q
  973. );
  974.  
  975. }
  976. }
  977. }
  978. public function _GetCountOrder($id = null, $Action = null)
  979. {
  980. if ($Action == null) {
  981. if ($id) {
  982. return $this->db->get_where('orderan', array(
  983. 'user_id' => $id
  984. ))->num_rows();
  985. }
  986. return $this->db->get_where('orderan', array())->num_rows();
  987.  
  988. } else if ($Action == "Complete") {
  989. if ($id != null) {
  990. return $this->db->get_where('orderan', array(
  991. 'status' => "Completed",
  992. 'user_id' => $id
  993. ))->num_rows();
  994. }
  995. return $this->db->get_where('orderan', array(
  996. 'status' => "Completed"
  997. ))->num_rows();
  998. } else if ($Action == "Cancel") {
  999. if ($id != null) {
  1000. return $this->db->get_where('orderan', array(
  1001. 'status' => "Canceled",
  1002. 'user_id' => $id
  1003. ))->num_rows();
  1004. }
  1005. return $this->db->get_where('orderan', array(
  1006. 'status' => "Canceled"
  1007. ))->num_rows();
  1008. } else if ($Action == "Pending") {
  1009. if ($id != null) {
  1010. return $this->db->get_where('orderan', array(
  1011. 'status' => "Pending",
  1012. 'user_id' => $id
  1013. ))->num_rows();
  1014. }
  1015. return $this->db->get_where('orderan', array(
  1016. 'status' => "Pending"
  1017. ))->num_rows();
  1018. } else if ($Action == "Partial") {
  1019. if ($id != null) {
  1020. return $this->db->get_where('orderan', array(
  1021. 'status' => "Partial",
  1022. 'user_id' => $id
  1023. ))->num_rows();
  1024. }
  1025. return $this->db->get_where('orderan', array(
  1026. 'status' => "Partial"
  1027. ))->num_rows();
  1028. }
  1029. }
  1030. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement