Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Orders extends CI_Model
- {
- public function __construct()
- {
- $this->load->model('Apa');
- $this->load->model('Cartel');
- }
- public function cinfo($id = null)
- {
- $id = ($id == null ? $this->session->userdata('auth') : $id);
- $orderan = $this->db->get_where('orderan', array(
- 'user_id' => $id
- ))->num_rows();
- $ordersukses = $this->db->get_where('orderan', array(
- 'user_id' => $id,
- 'status' => 'completed'
- ))->num_rows();
- $array = array(
- 'biasa' => $orderan,
- 'sukses' => $ordersukses
- );
- return $array;
- }
- public function _InfoOrder($id, $user)
- {
- foreach ($this->db->query("SELECT * FROM orderan where id = '$id' AND user_id = '$user'")->result() as $order);
- if (!$id) {
- return array(
- 'error' => true,
- 'msg' => "Order ID Not Found"
- );
- } else if (!$order) {
- return array(
- 'error' => true,
- "msg" => "Order ID Not Found"
- );
- } else {
- $service = false;
- foreach ($this->db->query("SELECT * FROM service where id = '" . $order->service_id . "'")->result() as $service);
- return array(
- 'charge' => $order->quantity * $service->price,
- 'start_count' => (int) $order->start,
- 'status' => $order->status,
- 'remains' => (int) $order->remains
- );
- }
- }
- public function UpdateAll()
- {
- 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) {
- $this->benchmark->mark('code_start');
- $status = $this->_CheckOrder($data->id);
- $this->benchmark->mark('code_end');
- echo "Updating Order ID {$data->id} | {$data->order_id_pro} - ".$this->benchmark->elapsed_time('code_start', 'code_end')." sec . response : $status <br/>";
- }
- }
- function time_elapsed_string($datetime, $full = false) {
- $now = new DateTime;
- $ago = new DateTime($datetime);
- $diff = $now->diff($ago);
- $diff->w = floor($diff->d / 7);
- $diff->d -= $diff->w * 7;
- $string = array(
- 'y' => 'year',
- 'm' => 'month',
- 'w' => 'week',
- 'd' => 'day',
- 'h' => 'hour',
- 'i' => 'minute',
- 's' => 'second',
- );
- foreach ($string as $k => &$v) {
- if ($diff->$k) {
- $v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? 's' : '');
- } else {
- unset($string[$k]);
- }
- }
- if (!$full) $string = array_slice($string, 0, 1);
- return $string ? implode(', ', $string) . ' ' : '';
- }
- public function _CheckOrder($id)
- {
- $order = false;
- foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $order);
- if (!$id) {
- return false;
- } else if (!$order) {
- return false;
- } else if ($order->status == "Completed" || $order->status == "Partial" || $order->status == "Canceled") {
- return false;
- } else {
- $service = false;
- foreach ($this->db->query("SELECT * FROM service where id = '$order->service_id' LIMIT 1")->result() as $service);
- if($service == false){
- return "ERROR BRO";
- }
- $aps = $service->api_id;
- if ($aps !== '0') {
- foreach ($this->db->query("SELECT * FROM api where id ='$aps' LIMIT 1")->result() as $api);
- if ($api->type == 'Basic') {
- $this->Apa->set($api->url, $api->api);
- $data = $this->Apa->status($order->order_id_pro);
- if (!$data == null && array_key_exists('status', $data)) {
- $status = $data->status;
- if ($status == 'Pending') {
- $s = "Pending";
- } else if ($status == "In progress") {
- $s = "Processing";
- } else if ($status == "Completed") {
- $s = "Completed";
- } else if ($status == "Partial") {
- $s = "Partial";
- } else if ($status == "Canceled") {
- $s = "Canceled";
- } else {
- $s = $status;
- }
- foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
- if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
- return false;
- }
- if ($s == "Canceled") {
- $refund = $order->quantity * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Cancel Pembelian #{$id}"
- ));
- } else if ($status == "Partial") {
- $refund = $data->remains * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Partial Pembelian #{$id}"
- ));
- }
- $this->db->where('id', $id)->update('orderan', array(
- 'status' => $s,
- 'start' => $data->start_count,
- 'remains' => $data->remains
- ));
- return $status;
- } else {
- return "Something Went Wrong From API";
- }
- } else if ($api->type == 'IrvanKede') {
- $this->Apa->set($api->url, $api->api);
- $data = $this->Apa->status_irvan($order->order_id_pro);
- if ($data != null && array_key_exists('status', $data)) {
- $status = false;
- print_r($data);
- $status = $data->data->status;
- if(!$status){
- return "ERROR FROM API , ANJING NIH IRVAN KEDE ASW";
- }
- if ($status == '1') {
- $s = "Pending";
- } else if ($status == "2") {
- $s = "Processing";
- } else if ($status == "5") {
- $s = "Completed";
- } else if ($status == "3") {
- $s = "Partial";
- } else if ($status == "4") {
- $s = "Canceled";
- } else {
- $s = $status;
- }
- foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
- if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
- return false;
- }
- if ($s == "Canceled") {
- $refund = $order->quantity * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Cancel Pembelian #{$id}"
- ));
- } else if ($s == "Partial") {
- $refund = $data->data->remains * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Partial Pembelian #{$id}"
- ));
- }
- $this->db->where('id', $id)->update('orderan', array(
- 'status' => $s,
- 'start' => $data->data->start_count,
- 'remains' => ($data->data->remains ? $data->data->remains : 0)
- ));
- return $status;
- } else {
- return "Something Went Wrong From API";
- }
- }
- else if ($api->type == 'Regram') {
- $this->Apa->set($api->url, $api->api);
- $data = $this->Apa->status_regram($order->order_id_pro);
- if (array_key_exists('status', $data)) {
- $status = $data->data->status;
- if ($status == 'Pending') {
- $s = "Pending";
- } else if ($status == "Processing") {
- $s = "Processing";
- } else if ($status == "Success") {
- $s = "Completed";
- } else if ($status == "Partial") {
- $s = "Partial";
- } else if ($status == "Error") {
- $s = "Canceled";
- } else {
- $s = $status;
- }
- foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
- if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
- return false;
- }
- if ($s == "Canceled") {
- $refund = $order->quantity * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Cancel Pembelian #{$id}"
- ));
- } else if ($status == "Partial") {
- $refund = $data->data->remains * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Partial Pembelian #{$id}"
- ));
- }
- $this->db->where('id', $id)->update('orderan', array(
- 'status' => $s,
- 'start' => $data->data->start,
- 'remains' => $data->data->remains
- ));
- } else {
- return "LOL";
- }
- }
- else if ($api->type == '2Cartel') {
- $Arrder = array(
- 'KEY' => $order->order_id_pro
- );
- $this->Cartel->set($api->url, $api->api);
- $data = $this->Cartel->get("orders/status", $Arrder);
- if ($data['error'] == false) {
- $orderData = $data['data']['result'][$order->order_id_pro][0];
- $status = $data['data']['result'][$order->order_id_pro][0]['status'];
- if ($status == '0') {
- $s = "Pending";
- } else if ($status == "1") {
- $s = "Pending";
- } else if ($status == "2") {
- $s = "Processing";
- } else if ($status == "3") {
- $s = "Processing";
- } else if ($status == "4") {
- $s = "Completed";
- } else if ($status == "5") {
- $s = "Partial";
- } else if ($status == "6") {
- $s = "Canceled";
- }
- foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
- if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
- return false;
- }
- if ($status == "6") {
- $refund = $order->quantity * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Cancel Pembelian #{$id}"
- ));
- } else if ($status == "5") {
- $refund = $orderData['remains'] * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Partial Pembelian #{$id}"
- ));
- }
- $this->db->where('id', $id)->update('orderan', array(
- 'status' => $s,
- 'start' => $orderData['start'],
- 'remains' => $orderData['remains']
- ));
- return $status;
- }
- } else if ($api->type == 'PostLikes') {
- $this->Apa->set($api->url, $api->api);
- $data = $this->Apa->status_post($order->order_id_pro);
- if ($data != null || array_key_exists('status', $data)) {
- $status = $data->orderStatus;
- if ($status == 'Pending') {
- $s = "Pending";
- } else if ($status == "Processing" || $status == "In Progress") {
- $s = "Processing";
- } else if ($status == "Completed") {
- $s = "Completed";
- } else if ($status == "Partially Completed") {
- $s = "Partial";
- } else if ($status == "Canceled" || $status == "Error") {
- $s = "Canceled";
- } else {
- $s = $status;
- }
- foreach ($this->db->query("SELECT * FROM orderan where id = '$id' LIMIT 1")->result() as $sorder);
- if ($sorder->status == "Completed" || $sorder->status == "Partial" || $sorder->status == "Canceled") {
- return false;
- }
- if ($s == "Canceled") {
- $refund = $order->quantity * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Cancel Pembelian #{$id}"
- ));
- } else if ($s == "Partial") {
- $refund = $data->remaining_amount * $service->price;
- $this->db->query("UPDATE user set balance = balance + $refund WHERE id ='$order->user_id'");
- $U = $this->Users->info($order->user_id);
- $this->db->insert("balance_history", array(
- 'user_id' => $order->user_id,
- 'balance' => $refund,
- 'balance_current' => $U->balance,
- 'type' => 1,
- 'message' => "Pengembalian Partial Pembelian #{$id}"
- ));
- }
- $this->db->where('id', $id)->update('orderan', array(
- 'status' => $s,
- 'start' => $data->startCount,
- 'remains' => $data->remaining_amount
- ));
- return $status;
- } else {
- return "Something Went Wrong From API";
- }
- }
- }
- }
- }
- public function _AddOrder($service, $link, $quantity = 0, $key = null, $usernames = null, $comments = null, $username = null)
- {
- if (!$key) {
- if (!$this->session->userdata('auth')) {
- return true;
- }
- }
- if(!is_int((int) $quantity)){
- return array(
- "error" => true,
- "msg" => "Invalid Data"
- );
- }
- $s = $service;
- $l = $link;
- $q = $quantity;
- $service = array();
- $api = array();
- $User = ($key == null ? $this->Users->info() : $this->Users->info_token($key));
- if (!$User) {
- return true;
- }
- $service = null;
- foreach ($this->db->query("SELECT * FROM service where id = ? AND status = ?", array(
- $s,
- "0"
- ))->result() as $service);
- if (!$service || !$link) {
- return array(
- 'error' => true,
- "msg" => "Empty Data"
- );
- } else if (is_int($s) || !is_string($l)) {
- return array(
- 'error' => true,
- "msg" => "Invalid Data "
- );
- } else if ($service == null) {
- return array(
- 'error' => true,
- "msg" => "Service Not Found"
- );
- } else {
- if ($service->api_id !== '0') {
- $aps = $service->api_id;
- foreach ($this->db->query("SELECT * FROM api where id ='$aps'")->result() as $api);
- if ($api->type == 'Basic') {
- $extends = "";
- if ($service->type == 'Default') {
- if (!$q) {
- return array(
- 'error' => true,
- 'msg' => "Invalid Quantity"
- );
- }
- $Arrder = array(
- 'service' => $service->pro_id,
- 'link' => $l,
- 'quantity' => $q
- );
- } else if ($service->type == "CC") {
- if (!$comments) {
- return array(
- 'error' => true,
- 'msg' => "Invalid Comments"
- );
- }
- $extends = $comments;
- $Arrder = array(
- 'service' => $service->pro_id,
- 'link' => $l,
- 'comments' => $comments
- );
- $q = count(explode("\n", $comments));
- } else if ($service->type == "MCL") {
- if (!$usernames) {
- return array(
- 'error' => true,
- 'msg' => "Invalid Usernames"
- );
- }
- $extends = $usernames;
- $Arrder = array(
- 'service' => $service->pro_id,
- 'link' => $l,
- 'usernames' => $usernames
- );
- $q = count(explode("\n", $usernames));
- } else if ($service->type == "MUF") {
- if (!$username || !$q) {
- return array(
- 'error' => true,
- 'msg' => "Invalid Usernames"
- );
- }
- $extends = $username;
- $Arrder = array(
- 'service' => $service->pro_id,
- 'link' => $l,
- 'username' => $username,
- 'quantity' => $q
- );
- } else {
- return array(
- 'error' => true,
- 'msg' => "Invalid ?"
- );
- }
- if ($User->balance < $service->price * $q) {
- return array(
- 'error' => true,
- "msg" => "Insufficient balance"
- );
- } else if ($q < $service->min - 1) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- } else if ($q > $service->max) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- }
- $this->Apa->set($api->url, $api->api);
- $data = $this->Apa->order($Arrder);
- if ($data == null) {
- return array(
- 'error' => true,
- "msg" => "ERROR !"
- );
- }
- if (array_key_exists('order', $data)) {
- $rand = rand(11111, 99999);
- $order_id = $data->order;
- $this->db->where('id', $User->id)->update('user', array(
- 'balance' => $User->balance - $q * $service->price
- ));
- $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
- $this->db->insert('orderan', array(
- 'user_id' => $User->id,
- 'service_id' => $s,
- 'target' => $l,
- 'quantity' => $q,
- 'extends_form' => $extends,
- 'date' => date('Y-m-d H:i:s'),
- 'data' => "PRO",
- 'status' => "Pending",
- "order_id_pro" => $order_id
- ));
- $ids = $this->db->insert_id();
- $U = $this->Users->info($User->id);
- $this->db->insert("balance_history", array(
- 'user_id' => $U->id,
- 'balance' => $q * $service->price,
- 'balance_current' => $U->balance,
- 'type' => 0,
- 'message' => "Pembelian #{$ids}"
- ));
- return array(
- 'error' => false,
- 'id' => $ids,
- "msg" => "OK",
- "price" => $service->price * $q,
- "service" => $service->name,
- 'quantity' => $q
- );
- } else {
- return array(
- 'error' => true,
- 'msg' =>
- //"Can't Contacting Server"
- $data->error
- );
- }
- } else if ($api->type == 'IrvanKede') {
- if ($service->type == 'Default') {
- if (!$q) {
- return array(
- 'error' => true,
- 'msg' => "Invalid Quantity"
- );
- }
- $Arrder = array(
- 'service' => $service->pro_id,
- 'target' => $l,
- 'quantity' => $q
- );
- } else {
- return array(
- 'error' => true,
- 'msg' => "Invalid ?"
- );
- }
- if ($User->balance < $service->price * $q) {
- return array(
- 'error' => true,
- "msg" => "Insufficient balance"
- );
- } else if ($q < $service->min - 1) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- } else if ($q > $service->max) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- }
- $this->Apa->set($api->url, $api->api);
- $data = $this->Apa->order_irvan($Arrder);
- if ($data->status) {
- $rand = rand(11111, 99999);
- $order_id = $data->data->id;
- $this->db->insert('orderan', array(
- 'user_id' => $User->id,
- 'service_id' => $s,
- 'target' => $l,
- 'quantity' => $q,
- 'extends_form' => '',
- 'date' => date('Y-m-d H:i:s'),
- 'data' => "PRO",
- 'status' => "Pending",
- "order_id_pro" => $order_id
- ));
- $ids = $this->db->insert_id();
- $this->db->where('id', $User->id)->update('user', array(
- 'balance' => $User->balance - $q * $service->price
- ));
- $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
- $U = $this->Users->info($User->id);
- $this->db->insert("balance_history", array(
- 'user_id' => $U->id,
- 'balance' => $q * $service->price,
- 'balance_current' => $U->balance,
- 'type' => 0,
- 'message' => "Pembelian #{$ids}"
- ));
- return array(
- 'error' => false,
- 'id' => $ids,
- "msg" => "OK",
- "price" => $service->price * $q,
- "service" => $service->name,
- 'quantity' => $q
- );
- } else {
- return array(
- 'error' => true,
- 'msg' =>
- // "Silahkan Hubungi Admin"
- $data['data']['msg']
- );
- }
- } else if ($api->type == 'Regram') {
- if ($service->type == 'Default') {
- if (!$q) {
- return array(
- 'error' => true,
- 'msg' => "Invalid Quantity"
- );
- }
- $Arrder = array(
- 'product' => $service->pro_id,
- 'data' => $l,
- 'quantity' => $q
- );
- } else {
- return array(
- 'error' => true,
- 'msg' => "Invalid ?"
- );
- }
- if ($User->balance < $service->price * $q) {
- return array(
- 'error' => true,
- "msg" => "Insufficient balance"
- );
- } else if ($q < $service->min - 1) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- } else if ($q > $service->max) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- }
- $this->Apa->set($api->url, $api->api);
- $data = $this->Apa->order_regram($Arrder);
- if ($data->status) {
- $rand = rand(11111, 99999);
- $order_id = $data->data->code;
- $this->db->insert('orderan', array(
- 'user_id' => $User->id,
- 'service_id' => $s,
- 'target' => $l,
- 'quantity' => $q,
- 'extends_form' => '',
- 'date' => date('Y-m-d H:i:s'),
- 'data' => "PRO",
- 'status' => "Pending",
- "order_id_pro" => $order_id
- ));
- $ids = $this->db->insert_id();
- $this->db->where('id', $User->id)->update('user', array(
- 'balance' => $User->balance - $q * $service->price
- ));
- $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
- $U = $this->Users->info($User->id);
- $this->db->insert("balance_history", array(
- 'user_id' => $U->id,
- 'balance' => $q * $service->price,
- 'balance_current' => $U->balance,
- 'type' => 0,
- 'message' => "Pembelian #{$ids}"
- ));
- return array(
- 'error' => false,
- 'id' => $ids,
- "msg" => "OK",
- "price" => $service->price * $q,
- "service" => $service->name,
- 'quantity' => $q
- );
- } else {
- return array(
- 'error' => true,
- 'msg' =>
- // "Silahkan Hubungi Admin"
- $data->message
- );
- }
- } else if ($api->type == '2Cartel') {
- if ($service->type == 'Default') {
- if (!$q) {
- return array(
- 'error' => true,
- 'msg' => "Invalid Quantity"
- );
- }
- $Arrder = array(
- 'type' => $service->pro_id,
- 'link' => $l,
- 'quantity' => $q
- );
- } else {
- return array(
- 'error' => true,
- 'msg' => "Invalid ?"
- );
- }
- if ($User->balance < $service->price * $q) {
- return array(
- 'error' => true,
- "msg" => "Insufficient balance"
- );
- } else if ($q < $service->min - 1) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- } else if ($q > $service->max) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- }
- $this->Cartel->set($api->url, $api->api);
- $data = $this->Cartel->post("orders/add", $Arrder);
- if ($data['error'] == false) {
- $rand = rand(11111, 99999);
- $order_id = $data['orders']['add'][0]['order_key'];
- $this->db->insert('orderan', array(
- 'user_id' => $User->id,
- 'service_id' => $s,
- 'target' => $l,
- 'quantity' => $q,
- 'extends_form' => '',
- 'date' => date('Y-m-d H:i:s'),
- 'data' => "PRO",
- 'status' => "Pending",
- "order_id_pro" => $order_id
- ));
- $ids = $this->db->insert_id();
- $this->db->where('id', $User->id)->update('user', array(
- 'balance' => $User->balance - $q * $service->price
- ));
- $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
- $U = $this->Users->info($User->id);
- $this->db->insert("balance_history", array(
- 'user_id' => $U->id,
- 'balance' => $q * $service->price,
- 'balance_current' => $U->balance,
- 'type' => 0,
- 'message' => "Pembelian #{$ids}"
- ));
- return array(
- 'error' => false,
- 'id' => $ids,
- "msg" => "OK",
- "price" => $service->price * $q,
- "service" => $service->name,
- 'quantity' => $q
- );
- } else {
- $error = $data['msg'];
- if ($error == "Saldo Tidak Cukup") {
- $error = "Silahkan Kontak Admin";
- }
- return array(
- 'error' => true,
- 'msg' => $error
- );
- }
- } else if ($api->type == 'PostLikes') {
- if ($service->type == 'Default') {
- if (!$q) {
- return array(
- 'error' => true,
- 'msg' => "Invalid Quantity"
- );
- }
- $Arrder = array(
- 'orderType' => $service->pro_id,
- 'orderUrl' => $l,
- 'orderQuantity' => $q
- );
- } else {
- return array(
- 'error' => true,
- 'msg' => "Invalid ?"
- );
- }
- if ($User->balance < $service->price * $q) {
- return array(
- 'error' => true,
- "msg" => "Insufficient balance"
- );
- } else if ($q < $service->min - 1) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- } else if ($q > $service->max) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- }
- $this->Apa->set($api->url, $api->api);
- $data = $this->Apa->order_post($Arrder);
- if (array_key_exists('orderID', $data)) {
- $rand = rand(11111, 99999);
- $order_id = $data->orderID;
- $this->db->insert('orderan', array(
- 'user_id' => $User->id,
- 'service_id' => $s,
- 'target' => $l,
- 'quantity' => $q,
- 'extends_form' => '',
- 'date' => date('Y-m-d H:i:s'),
- 'data' => "PRO",
- 'status' => "Pending",
- "order_id_pro" => $order_id
- ));
- $ids = $this->db->insert_id();
- $this->db->where('id', $User->id)->update('user', array(
- 'balance' => $User->balance - $q * $service->price
- ));
- $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
- $U = $this->Users->info($User->id);
- $this->db->insert("balance_history", array(
- 'user_id' => $U->id,
- 'balance' => $q * $service->price,
- 'balance_current' => $U->balance,
- 'type' => 0,
- 'message' => "Pembelian #{$ids}"
- ));
- return array(
- 'error' => false,
- 'id' => $ids,
- "msg" => "OK",
- "price" => $service->price * $q,
- "service" => $service->name,
- 'quantity' => $q
- );
- } else {
- return array(
- 'error' => true,
- 'msg' =>
- // "Silahkan Hubungi Admin"
- $data->error
- );
- }
- }
- } else {
- if ($User->balance < $service->price * $q) {
- return array(
- 'error' => true,
- "msg" => "Insufficient balance"
- );
- } else if ($q < $service->min - 1) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- } else if ($q > $service->max) {
- return array(
- 'error' => true,
- "msg" => "Invalid Quantity"
- );
- }
- $rand = rand(11111, 99999);
- $this->db->insert('orderan', array(
- 'user_id' => $User->id,
- 'service_id' => $s,
- 'target' => $l,
- 'quantity' => $q,
- 'extends_form' => '',
- 'date' => date('Y-m-d H:i:s'),
- 'data' => "PRO",
- 'status' => "Pending",
- "order_id_pro" => '0'
- ));
- $ids = $this->db->insert_id();
- $this->db->where('id', $User->id)->update('user', array(
- 'balance' => $User->balance - $q * $service->price
- ));
- $this->db->query("UPDATE user set balance_used = balance_used + $q*$service->price WHERE id = '$User->id'");
- $U = $this->Users->info($User->id);
- $this->db->insert("balance_history", array(
- 'user_id' => $U->id,
- 'balance' => $q * $service->price,
- 'balance_current' => $U->balance,
- 'type' => 0,
- 'message' => "Pembelian #{$ids}"
- ));
- return array(
- 'error' => false,
- 'id' => $ids,
- "msg" => "OK",
- "price" => $service->price * $q,
- "service" => $service->name,
- 'quantity' => $q
- );
- }
- }
- }
- public function _GetCountOrder($id = null, $Action = null)
- {
- if ($Action == null) {
- if ($id) {
- return $this->db->get_where('orderan', array(
- 'user_id' => $id
- ))->num_rows();
- }
- return $this->db->get_where('orderan', array())->num_rows();
- } else if ($Action == "Complete") {
- if ($id != null) {
- return $this->db->get_where('orderan', array(
- 'status' => "Completed",
- 'user_id' => $id
- ))->num_rows();
- }
- return $this->db->get_where('orderan', array(
- 'status' => "Completed"
- ))->num_rows();
- } else if ($Action == "Cancel") {
- if ($id != null) {
- return $this->db->get_where('orderan', array(
- 'status' => "Canceled",
- 'user_id' => $id
- ))->num_rows();
- }
- return $this->db->get_where('orderan', array(
- 'status' => "Canceled"
- ))->num_rows();
- } else if ($Action == "Pending") {
- if ($id != null) {
- return $this->db->get_where('orderan', array(
- 'status' => "Pending",
- 'user_id' => $id
- ))->num_rows();
- }
- return $this->db->get_where('orderan', array(
- 'status' => "Pending"
- ))->num_rows();
- } else if ($Action == "Partial") {
- if ($id != null) {
- return $this->db->get_where('orderan', array(
- 'status' => "Partial",
- 'user_id' => $id
- ))->num_rows();
- }
- return $this->db->get_where('orderan', array(
- 'status' => "Partial"
- ))->num_rows();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement