X7ROOT File Manager
Current Path:
/home/hamdjcne/app.hamdalillahitravel.com/app/Controllers
home
/
hamdjcne
/
app.hamdalillahitravel.com
/
app
/
Controllers
/
ðŸ“
..
📄
.DS_Store
(6 KB)
📄
Accounts.php
(52.25 KB)
📄
Activity.php
(4.49 KB)
📄
Analytics.php
(12.22 KB)
📄
Api.php
(41.41 KB)
📄
Auth.php
(34.64 KB)
📄
BaseController.php
(1.77 KB)
📄
Dashboard.php
(42.95 KB)
📄
Notification.php
(6.22 KB)
📄
Order.php
(118.16 KB)
📄
Service.php
(61.77 KB)
📄
Settings.php
(40.13 KB)
📄
Staff.php
(67.17 KB)
📄
Tour.php
(32.09 KB)
📄
Wallets.php
(43.15 KB)
📄
Webhook.php
(5.14 KB)
Editing: Api.php
<?php namespace App\Controllers; class Api extends BaseController { private $token; private $db; public function __construct() { $this->db = \Config\Database::connect(); header("Access-Control-Allow-Origin: *"); header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE"); header("Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding, Authorization"); header("Content-Type: application/json; charset=UTF-8"); $this->token = 'EAACva1Mk73MBAPCKAh12445IAxF01sWkiFYAwcViL6MXEi'; // check token $token = null; $headers = apache_request_headers(); if(isset($headers['Authorization'])){ $token = $headers['Authorization']; $token = explode(' ', $token)[1]; } if($this->token != $token) { echo json_encode(array('status' => false, 'msg' => 'Invalid Token')); die; } } public function index() { } // register public function register() { $status = false; $data = array(); $msg = ''; // collect call paramters $call = json_decode(file_get_contents("php://input")); $fullname = $call->fullname; $email = $call->email; $password = $call->password; $phone = $call->phone; $country = $call->country; if($fullname && $email && $password && $phone) { // check if email already exists if($this->Crud->check('email', $email, 'user') > 0 || $this->Crud->check('phone', $phone, 'user') > 0) { $msg = 'Email and/or Phone Taken! Please choose another.'; } else { $role_id = $this->Crud->read_field('name', 'Customer', 'access_role', 'id'); $ins['fullname'] = $fullname; $ins['email'] = $email; $ins['password'] = md5($password); $ins['phone'] = $phone; $ins['country_id'] = $this->Crud->read_field('name', $country, 'country', 'id'); $ins['role_id'] = $role_id; $ins['reg_date'] = date(fdate); $user_id = $this->Crud->create('user', $ins); if($user_id > 0) { $status = true; $msg = 'Successful!'; $data['id'] = $user_id; } else { $msg = 'Oops! Try later'; } } } else { // $msg = 'Missing field.'; } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } // login public function login() { $status = false; $data = array(); $msg = ''; // collect call paramters $call = json_decode(file_get_contents("php://input")); $email = $call->email; $password = $call->password; if($email && $password) { $password = md5($call->password); $type = 'email'; $query = $this->Crud->read2('email', $email, 'password', $password, 'user'); if(empty($query)) { $type = 'phone'; $query = $this->Crud->read2('phone', $email, 'password', $password, 'user'); } if(empty($query)) { $msg = 'Invalid Authentication!'; } else { $status = true; $msg = 'Login Successful!'; $id = $this->Crud->read_field($type, $email, 'user', 'id'); $data = $this->user_data($id); } } else { $msg = 'Missing field(s).'; } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } // reset code public function reset_code() { $status = false; $data = array(); $msg = ''; // collect call paramters $call = json_decode(file_get_contents("php://input")); $email = $call->email; if($email) { $user_id = $this->Crud->read_field('email', $email, 'user', 'id'); if(empty($user_id)) { $msg = 'Invalid Email!'; } else { $code = substr(md5(time().rand()), 0, 6); if($this->Crud->updates('id', $user_id, 'user', array('reset_code'=>$code)) > 0) { $status = true; $msg = 'Login Successfully!'; $data['code'] = $code; $fullname = $this->Crud->read_field('id', $user_id, 'user', 'fullname'); // email content $bcc = ''; $subject = 'Reset Code'; $body = ' <b>Dear '.$fullname.'</b>,<br/><br/> You requested to reset your account password. Your secret code is '.$code.'.<br/><br/> <i>If you do not request this action, please ignore. Your account will be protected.</i><br/><br/> Thank you.<br/> '; $this->Crud->send_email($email, $subject, $body, $bcc); } } } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } // reset password public function reset_password() { $status = false; $data = array(); $msg = ''; // collect call paramters $call = json_decode(file_get_contents("php://input")); $email = $call->email; $password = $call->password; if($email && $password) { $user_id = $this->Crud->read_field('email', $email, 'user', 'id'); if(empty($user_id)) { $msg = 'Invalid Email!'; } else { if($this->Crud->updates('id', $user_id, 'user', array('password'=>md5($password))) > 0) { $status = true; $msg = 'Password Reset Successfully!'; } } } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } // profile public function profile($id, $type='get') { $status = false; $data = array(); $msg = ''; /// GET if($type == 'get') { $status = true; $data = $this->user_data($id); $msg = 'Successful'; } /// UPDATE if($type == 'update') { // collect call paramters $call = json_decode(file_get_contents("php://input")); $field = $call->field; $value = $call->value; if($field == 'password') $value = md5($value); $process = true; // check email if($field == 'email') { $old_email = $this->Crud->read_field('id', $id, 'user', 'email'); if($old_email != $value) { if($this->Crud->check('email', $value, 'user') > 0) { $process = false; $msg = 'Email already exists!'; } } } // process update if($process == true) { $this->Crud->updates('id', $id, 'user', array($field=>$value)); $status = true; $msg = 'Successful!'; $data = $this->user_data($id); } } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } public function payments($type='get', $id=0) { $status = false; $msg = ''; $cod = 'info'; $data = array(); $admin = $this->Crud->read_field('fullname', 'TiDREM ADMIN', 'user', 'id'); $phone = $this->Crud->read_field('id', $id, 'user', 'phone'); $email = $this->Crud->read_field('id', $id, 'user', 'email'); if($type == 'sms'){ $call = json_decode(file_get_contents("php://input")); // $api_key = $call->api_key; $to = $call->to; $from = $call->from; $sms = $call->sms; $type = $call->type; $channel = $call->channel; // $phone = '07031549500'; // $api_key = $this->Crud->read_field('name', 'termil_api', 'setting', 'value'); // pick from DB if($to) { $phone = '234'.substr($to,1); $datass['to'] = $phone; $datass['from'] = $from; $datass['sms'] = $sms; $datass['api_key'] = $api_key; $datass['type'] = $type; $datass['channel'] = $channel; $msg = $this->Crud->termii('post', 'sms/send', $datass); } } // get if($type == 'get') { $call = json_decode(file_get_contents("php://input")); $user_id = $call->user_id; if(!empty($user_id)) { $query = $this->Crud->read_single('user_id', $user_id, 'wallet'); if(!empty($query)) { $status = true; $msg = 'Successful'; foreach($query as $q) { $item = array(); if($q->type == 'credit') { $earnings += (float)$q->amount; } else { $withdrawns += (float)$q->amount; } $item['id'] = $q->id; $item['type'] = $q->type; $item['remark'] = $q->remark; $item['amount'] = number_format((float)$q->amount, 2); $item['date'] = date('M d, Y h:s A', strtotime($q->reg_date)); $data[] = $item; } $balance = $earnings - $withdrawns; $earnings = number_format($earnings, 2); $withdrawns = number_format($withdrawns, 2); $balance = number_format($balance, 2); } } } // deposit if($type == 'deposit') { $call = json_decode(file_get_contents("php://input")); $payment_method = $call->payment_method; $ref = $call->ref; $remark = $call->remark; $amount = $call->amount; if(!empty($id) && !empty($amount)) { if($payment_method == 'bank'){ $user_country = $this->Crud->read_field('id', $id,'user', 'country_id'); $user_territory = $this->Crud->read_field('id', $id,'user', 'territory'); $user_lga = $this->Crud->read_field('id', $id,'user', 'lga_id'); //Save in Transaction Table if($id > 0){ $ins['user_id'] = $id; $ins['amount'] = $amount; $ins['territory'] = $user_territory; $ins['remark'] = $remark; $ins['lga_id'] = $user_lga; $ins['ref'] = $ref; $ins['payment_type'] = 'wallet'; $ins['payment_method'] = $payment_method; $ins['status'] = 'completed'; $ins['reg_date'] = date(fdate); $ins_id = $this->Crud->create('transaction', $ins); //Credit wallet of user $user_ins['user_id'] = $id; $user_ins['type'] = 'credit'; $user_ins['amount'] = $amount; $user_ins['item'] = 'wallet_fund'; $user_ins['lga_id'] = $user_lga; $user_ins['territory'] = $user_territory; $user_ins['item_id'] = $ins_id; $user_ins['remark'] = 'Wallet Credited using Bank Transfer'; $user_ins['reg_date'] = date(fdate); $user_ids = $this->Crud->create('wallet', $user_ins); $codesa = $this->Crud->read_field('id', $id, 'user', 'fullname'); $action = $codesa.' Account Deposited with N'.number_format($amount,2).' using Bank Transfer'; $this->Crud->activity('transaction', $id, $action); $content = 'Wallet Credited with N'.number_format($amount); $this->notify($admin, $id, $content, $type, $ins_id); if($ins_id > 0){ $status = true; $code = 'success'; $msg = 'Transaction Successful'; } else{ $msg = 'Please Try Again'; } } } } } if($type == 'transaction'){ $call = json_decode(file_get_contents("php://input")); $payment_method = $call->payment_method; $ref = rand(); $remark = $call->remark; $session_id = $call->session_id; $amount = $call->amount; $trans_date = $call->trans_date; // echo $amount.' '; $msg = ' '; if(!empty($id) && !empty($amount)){ if($this->Crud->check('id', $id, 'user') > 0){ if($this->Crud->check('session_id', $session_id, 'history') == 0){ $t_data['user_id'] = $id; $t_data['territory'] = $this->Crud->read_field('id', $id, 'user', 'territory'); $t_data['lga_id'] = $this->Crud->read_field('id', $id, 'user', 'lga_id'); $t_data['payment_method'] = $payment_method; $t_data['remark'] = $remark; $t_data['ref'] = $ref; $t_data['session_id'] = $session_id; $t_data['amount'] = $amount; $t_data['reg_date'] = $trans_date; $msg .= $this->Crud->create('history', $t_data); } } } } if($type == 'pay_tax'){ $call = json_decode(file_get_contents("php://input")); $payment_method = $call->payment_method; $ref = $call->ref; $remark = $call->remark; $total_amount = $call->amount; $msg = ' '; if(!empty($id) && !empty($total_amount)){ if(empty($this->Crud->read_field('id', $id, 'user', 'duration'))){ $trade = $this->Crud->read_field('id', $id, 'user', 'trade'); $duration = 'daily'; $datas['duration'] = $duration; if(!empty($trade))$datas['trade'] = $trade; $add = $this->Crud->updates('id', $id, 'user', $datas); if($add > 0){ $id = $id; $tax_data['user_id'] = $id; $tax_data['territory'] = $this->Crud->read_field('id', $id, 'user', 'territory'); $tax_data['lga_id'] = $this->Crud->read_field('id', $id, 'user', 'lga_id'); $trade = $this->Crud->read_field('id', $id, 'user', 'trade'); $trade_type = $this->Crud->read_field('id', $trade, 'trade', 'medium'); $duration = $this->Crud->read_field('id', $id, 'user', 'duration'); $tax_data['amount'] = $this->Crud->trade_duration($trade_type, $duration); $tax_data['balance'] = $this->Crud->trade_duration($trade_type, $duration); $tax_data['reg_date'] = date(fdate); $tax_data['payment_method'] = 'bank'; $tax_data['remark'] = 'Tax Payment'; $tax_data['payment_type'] = 'tax'; $days = "day"; $durs = '365'; if($duration == 'weekly')$days = "week";$durs = '52'; if($duration == 'monthly')$days = "month";$durs = '12'; // if($role == 'personal' || $role == 'business'){ for ($i = 0; $i < $durs; $i++) { $tax_data['payment_date'] = date('Y-m-d', strtotime(date(fdate).'+'.$i.' '.$days)); $ins = $this->Crud->create('transaction', $tax_data); } // } ///// store activities $code = $this->Crud->read_field('id', $id, 'user', 'fullname'); $action = $code.' created Payment Profile and Updated Profile '; $this->Crud->activity('profile', $id, $action); echo $this->Crud->msg('success', translate_phrase('Profile Settings Updated')); // echo '<script>window.location.replace("'.site_url('dashboard').'");</script>'; } } if($this->Crud->check('id', $id, 'user') > 0){ $phone = $this->Crud->read_field('id', $id, 'user', 'phone'); $email = $this->Crud->read_field('id', $id, 'user', 'email'); $fullname = $this->Crud->read_field('id', $id, 'user', 'fullname'); $tax = $this->Crud->reads3('user_id', $id, 'payment_type', 'tax', 'status', 'pending', 'transaction'); if(!empty($tax)){ $total_bal = $call->amount; //Pay Pending Payment First foreach($tax as $t){ $tax_id = $t->id; $pays_date = $t->payment_date; $bal = $t->balance; $ref = rand(); if($total_bal > 0 ){ if($total_amount >= $bal){ $total_amount -= (float)$bal; $bala = $bal; $bals= ''; $t_data['balance'] = 0; $t_data['status'] = 'paid'; $t_data['paid_date'] = date(fdate); } else { $bala = $total_amount; $bal = $bal - $total_amount; $t_data['balance'] = $bal; $bals = 'Balance of N'.number_format($bal,2); $t_data['status'] = 'pending'; $t_data['paid_date'] = date(fdate); } $t_data['payment_method'] = $payment_method; $upda = $this->Crud->updates('id', $tax_id, 'transaction', $t_data); //Create payment in payment table $pay_data['amount'] = $bala; $pay_data['reference'] = $ref; $pay_data['transaction_id'] = $tax_id; $pay_data['reg_date'] = date(fdate); $this->Crud->create('payment', $pay_data); $first_msg = ''; //Send Notification to the Tax Payer if($upda > 0){ $first_msg .= 'Dear '.ucwords($fullname).', your tax payment of N'.number_format($bala,2).' to the Delta State Government for '.$pays_date.' was successful. Your Payment Reference is {'.$ref.'}. '.$bals; $api_key = $this->Crud->read_field('name', 'termil_api', 'setting', 'value'); // pick from DB if($phone) { $phone = '234'.substr($phone,1); $datass['to'] = $phone; $datass['from'] = 'N-Alert'; $datass['sms'] = $first_msg; $datass['api_key'] = $api_key; $datass['type'] = 'plain'; $datass['channel'] = 'dnd'; $this->Crud->termii('post', 'sms/send', $datass); } // send email if($email) { $data['email_address'] = $email; $this->Crud->send_email($email, 'Tax Payments', $first_msg); } $this->notify('0', $id, $first_msg, 'payment', $upda); } } $total_bal -= (float)$t->balance; } } } } } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'code'=>$cod, 'data'=>$data)); die; } // wallet public function wallet($type='get', $id=0) { $status = false; $msg = ''; $earnings = 0; $withdrawns = 0; $balance = 0; $bal = 0; $data = array(); // get if($type == 'get') { $call = json_decode(file_get_contents("php://input")); $user_id = $call->user_id; if(!empty($user_id)) { $query = $this->Crud->read_single('user_id', $user_id, 'wallet'); if(!empty($query)) { $status = true; $msg = 'Successful'; foreach($query as $q) { $item = array(); if($q->type == 'credit') { $earnings += (float)$q->amount; } else { $withdrawns += (float)$q->amount; } $item['id'] = $q->id; $item['type'] = $q->type; $item['remark'] = $q->remark; $item['amount'] = number_format((float)$q->amount, 2); $item['date'] = date('M d, Y h:s A', strtotime($q->reg_date)); $data[] = $item; } $balance = $earnings - $withdrawns; $earnings = number_format($earnings, 2); $withdrawns = number_format($withdrawns, 2); $balance = number_format($balance, 2); } } } // withdraw if($type == 'withdraw') { $call = json_decode(file_get_contents("php://input")); $user_id = $call->user_id; $threshold = 100; if(!empty($user_id)) { $query = $this->Crud->read_single('user_id', $user_id, 'wallet'); if(!empty($query)) { $status = true; foreach($query as $q) { if($q->type == 'credit') { $earnings += (float)$q->amount; } else { $withdrawns += (float)$q->amount; } } $balance = $earnings - $withdrawns; } if($balance <= 0) { $status = true; $msg = 'You have no Balance to Withdraw'; } else { if($balance < $threshold) { $status = true; $msg = 'Minimum Payout of NGN '.$threshold.' required!'; } else { // check rave balance $rave_balance = 0; $grb = $this->Crud->rave_balance(); $grb = json_decode($grb); if($grb->status == 'success') { $rave_balance = $grb->data->available_balance; } // check if there is enough money in rave wallet if($rave_balance <= $balance) { $status = true; $msg = 'Withdraw Failed! - Please try later or contact support'; } else { // get user account $fullname = $this->Crud->read_field('id', $user_id, 'user', 'fullname'); $email = $this->Crud->read_field('id', $user_id, 'user', 'email'); $bank_code = $this->Crud->read_field('user_id', $user_id, 'account', 'code'); $account = $this->Crud->read_field('user_id', $user_id, 'account', 'account'); $ref = 'WMW-'.time(); $narration = 'Withdrawn by '.$fullname.' ('.$email.')'; if(!empty($bank_code) && !empty($account)) { $r_data['account_bank'] = $bank_code; $r_data['account_number'] = $account; $r_data['amount'] = $balance; $r_data['narration'] = $narration; $r_data['currency'] = 'NGN'; $r_data['reference'] = $ref; $r_data['callback_url'] = ''; $r_data['debit_currency'] = 'NGN'; $w_resp = $this->Crud->rave_withdraw($r_data); $wr = json_decode($w_resp); if($wr->status == 'success') { $status = true; $msg = $wr->message; // register wallet $v_ins['user_id'] = $user_id; $v_ins['type'] = 'debit'; $v_ins['amount'] = $balance; $v_ins['item'] = 'withdraw'; $v_ins['item_id'] = $user_id; $v_ins['remark'] = 'Wallet Withdraw'; $v_ins['reg_date'] = date(fdate); $this->Crud->create('wallet', $v_ins); } else { $status = true; $msg = 'Withdraw Failed! - Please try later or contact support'; } } else { $status = true; $msg = 'No Account Found! - Please add account.'; } } } } } } if($type == 'transaction'){ $call = json_decode(file_get_contents("php://input")); $payment_method = $call->payment_method; $ref = rand(); $remark = $call->remark; $session_id = $call->session_id; $amount = $call->amount; $trans_date = $call->trans_date; // echo $amount.' '; $msg = ' '; if(!empty($id) && !empty($amount)){ if($this->Crud->check('id', $id, 'user') > 0){ if($this->Crud->check('session_id', $session_id, 'history') == 0){ $t_data['user_id'] = $id; $t_data['territory'] = $this->Crud->read_field('id', $id, 'user', 'territory'); $t_data['lga_id'] = $this->Crud->read_field('id', $id, 'user', 'lga_id'); $t_data['payment_method'] = $payment_method; $t_data['remark'] = $remark; $t_data['ref'] = $ref; $t_data['session_id'] = $session_id; $t_data['amount'] = $amount; $t_data['reg_date'] = $trans_date; $msg .= $this->Crud->create('history', $t_data); } } } } if($type == 'fund'){ $call = json_decode(file_get_contents("php://input")); $payment_method = $call->payment_method; $ref = $call->ref; $remark = $call->remark; $total_amount = $call->amount; $msg = ' '; if(!empty($id) && !empty($total_amount)) { $v_ins['user_id'] = $id; $v_ins['type'] = 'credit'; $v_ins['amount'] = $total_amount; $v_ins['item'] = 'fund'; $v_ins['remark'] = 'Wallet Funding'; $v_ins['reg_date'] = date(fdate); $w_id = $this->Crud->create('wallet', $v_ins); if($w_id > 0) { $status = true; $msg = 'Wallet Funded'; $data['id'] = $w_id; $fullname = $this->Crud->read_field('id', $id, 'user', 'fullname'); $email = $this->Crud->read_field('id', $id, 'user', 'email'); $country_id = $this->Crud->read_field('id', $id, 'user', 'country_id'); $curr = $this->Crud->read_field('id', $country_id, 'country', 'currency'); // add notification $u_content = 'You funded your wallet with '.$curr.number_format($total_amount); $this->notify(0, $id, $u_content, 'wallet', $w_id); if($email) { $u_body = 'Dear '.$fullname.',<br/><br/>Your wallet is funded with '.$curr.number_format($total_amount).'.<br/><br/>Thank you.'; $this->send_email($email, 'Wallet Funding', $u_body); } } else { $msg = 'Failed! - Please Contact Support.'; } } } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'earnings'=>$earnings, 'withdrawns'=>$withdrawns, 'balance'=>$balance, 'data'=>$data)); die; } // pump public function pump($type='get') { $status = false; $msg = ''; $data = array(); // get if($type == 'get') { $call = json_decode(file_get_contents("php://input")); $user_id = $call->user_id; if(!empty($user_id)) { $query = $this->Crud->read_single('user_id', $user_id, 'pump'); if(!empty($query)) { $status = true; $msg = 'Successful'; foreach($query as $q) { $item = array(); $product = $this->Crud->read_field('id', $q->product, 'category', 'name'); $item['id'] = $q->id; $item['name'] = ucwords($q->name); $item['product'] = $product; $item['price'] = $q->price; $data[] = $item; } } } } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } // order public function order($method='get') { $status = false; $msg = ''; $data = array(); // POST if($method == 'post') { $call = json_decode(file_get_contents("php://input")); $user_id = $call->user_id; $category = $call->category; $amount = (float)$call->amount; $category_id = $this->Crud->read_field('name', $category, 'category', 'id'); // get balance $balance = $this->get_balance($user_id); // compute total // $comm = 50; // $vat = ($amount + $comm) * 0.075; $comm = 0; $vat = 0; $total = $amount + $comm + $vat; // check wallet balance if($balance < $amount) { $msg = 'Please add Fund to Wallet'; } else { $ref = 'FM-'.substr(rand(),0,3).substr(rand(),0,4).substr(rand(),0,3); // add order $ordData['user_id'] = $user_id; $ordData['category_id'] = $category_id; $ordData['ref'] = $ref; $ordData['amount'] = $this->Crud->to_number($amount); $ordData['comm'] = $comm; $ordData['vat'] = $vat; $ordData['total'] = $total; $ordData['status'] = 'Pending'; $ordData['reg_date'] = date(fdate); $order_id = $this->Crud->create('order', $ordData); if($order_id > 0) { $status = true; $msg = 'Order Initialized Successfully'; $data = $this->orderDetails($order_id); } else { $msg = 'Please try later'; } } } // SUBMIT if($method == 'submit') { $call = json_decode(file_get_contents("php://input")); $user_id = $call->user_id; $order_id = $call->order_id; $orderTotal = (float)$this->Crud->read_field('id', $order_id, 'order', 'total'); $balance = $this->get_balance($user_id); if($balance < $orderTotal) { $msg = 'Please add Fund to Wallet'; } else { $status = true; $msg = 'Order Placed Successfully'; $rands = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $code = substr(str_shuffle($rands), 0, 8); // update order $this->Crud->updates('id', $order_id, 'order', array('code'=>$code, 'status'=>'Purchased')); $cat_id = $this->Crud->read_field('id', $order_id, 'order', 'category_id'); $cat = $this->Crud->read_field('id', $cat_id, 'category', 'name'); // register wallet $v_ins['user_id'] = $user_id; $v_ins['type'] = 'debit'; $v_ins['amount'] = $orderTotal; $v_ins['item'] = 'order'; $v_ins['item_id'] = $order_id; $v_ins['remark'] = 'Purchased of '.$cat; $v_ins['reg_date'] = date(fdate); $this->Crud->create('wallet', $v_ins); $fullname = $this->Crud->read_field('id', $user_id, 'user', 'fullname'); $email = $this->Crud->read_field('id', $user_id, 'user', 'email'); $country_id = $this->Crud->read_field('id', $user_id, 'user', 'country_id'); $curr = $this->Crud->read_field('id', $country_id, 'country', 'currency'); $amt = (float)$this->Crud->read_field('id', $order_id, 'order', 'amount'); // add notification $u_content = 'You purchase a new token for the value of '.$curr.number_format($amt); $this->notify(0, $user_id, $u_content, 'order', $order_id); if($email) { $u_body = 'Dear '.$fullname.',<br/><br/>You purchase a new token for the value of '.$curr.number_format($amt).'.<br/><br/>Thank you.'; $this->send_email($email, 'New Order', $u_body); } } } // VERIFY if($method == 'verify') { $call = json_decode(file_get_contents("php://input")); $user_id = $call->user_id; $code = $call->code; $pump = $call->pump; $submit = $call->submit; $partner_id = $user_id; $order_id = $this->Crud->read_field('code', $code, 'order', 'id'); if(empty($order_id)) { $msg = 'Invalid Transaction Code'; } else { // check if order is already verified $used = $this->Crud->read_field('id', $order_id, 'order', 'used'); if($used > 0) { $msg = 'Transaction Code Already Used'; } else { $amount = (float)$this->Crud->read_field('id', $order_id, 'order', 'amount'); $total = (float)$this->Crud->read_field('id', $order_id, 'order', 'total'); $perLitre = (float)$this->Crud->read_field('id', $pump, 'pump', 'price'); $litres = $amount / $perLitre; if(!empty($submit)) { $country_id = $this->Crud->read_field('id', $partner_id, 'user', 'country_id'); $state_id = $this->Crud->read_field('id', $partner_id, 'user', 'state_id'); $lga_id = $this->Crud->read_field('id', $partner_id, 'user', 'lga_id'); $ins_data['partner_id'] = $partner_id; $ins_data['country_id'] = $country_id; $ins_data['state_id'] = $state_id; $ins_data['city_id'] = $lga_id; $ins_data['partner_id'] = $partner_id; $ins_data['litre'] = $litres; $ins_data['status'] = 'Used'; $ins_data['used'] = 1; $ins_data['pump'] = $pump; $ins_data['used_date'] = date(fdate); $ins_id = $this->Crud->updates('id', $order_id, 'order', $ins_data); if($ins_id > 0) { $status = true; $msg = 'Transaction Code Approved'; $u_id = $this->Crud->read_field('id', $order_id, 'order', 'user_id');; $fullname = $this->Crud->read_field('id', $u_id, 'user', 'fullname'); $partner = $this->Crud->read_field('id', $partner_id, 'user', 'fullname'); $email = $this->Crud->read_field('id', $u_id, 'user', 'email'); $ct_id = $this->Crud->read_field('id', $u_id, 'user', 'country_id'); $curr = $this->Crud->read_field('id', $ct_id, 'country', 'currency'); $amt = (float)$this->Crud->read_field('id', $order_id, 'order', 'amount'); // add notification $u_content = 'Your token ('.$code.') was used at '.$partner; $this->notify(0, $u_id, $u_content, 'token', $ins_id); if($email) { $u_body = 'Dear '.$fullname.',<br/><br/>Your token ('.$code.') was used at '.$partner.'.<br/><br/>Thank you.'; $this->send_email($email, 'Token Used', $u_body); } } else { $msg = 'Please try later'; } } else { $status = true; $msg = 'Verified'; $data['amount'] = number_format($amount, 2); $data['total'] = number_format($total, 2); $data['litres'] = number_format($litres, 2); } } } } // get if($method == 'get') { $user_id = $this->request->getGet('user_id'); $used = $this->request->getGet('used'); if(!empty($this->request->getGet('search'))) { $search = $this->request->getGet('search'); } else { $search = ''; } // $query = $this->Crud->read2('user_id', $user_id, 'used', $used, 'order'); $query = $this->db->table('order')->like('code', $search)->where('user_id', $user_id)->where('used', $used)->get()->getResult(); if(!empty($query)) { $status = true; $msg = 'Successful'; foreach($query as $q) { $data[] = $this->orderDetails($q->id); } } } // count if($method == 'count') { $user_id = $this->request->getGet('user_id'); $count = $this->db->table('order')->where('user_id', $user_id)->countAllResults(); $status = true; $msg = 'Successful'; $data = $count; } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } // notification public function notification($id='') { $status = false; $msg = ''; $data = array(); // collect call paramters $type = $this->request->getGet('type'); $user_id = $this->request->getGet('user_id'); // $limit = $this->request->getGet('limit'); // $offset = $this->request->getGet('offset'); if(empty($limit)) {$limit = 50;} if(empty($offset)) {$offset = 0;} // count total unread notification if($type == 'count') { $status = true; $msg = 'Successful'; $data['count'] = $this->db->table('notify')->where('to_id', $user_id)->where('new', 1)->countAllResults(); } // read all notification if($type == 'all') { $query = $this->Crud->read_single('to_id', $user_id, 'notify', $limit, $offset); if(!empty($query)) { $status = true; $msg = 'Successful'; foreach($query as $q) { $item = array(); $isNew = true; if($q->new == 0) { $isNew = false; } $item['id'] = $q->id; $item['content'] = $q->content; $item['item'] = $q->item; $item['item_id'] = $q->item_id; $item['new'] = $isNew; $item['date'] = $this->timeago(strtotime($q->reg_date)); $data[] = $item; } } } // push notification if($type == 'push') { $query = $this->Crud->read2('to_id', $user_id, 'new', 1, 'notify', 'id', 'DESC', $limit, $offset); if(!empty($query)) { $status = true; $msg = 'Successful'; foreach($query as $q) { $item = array(); $item['id'] = $q->id; $item['content'] = $q->content; $item['item'] = $q->item; $item['item_id'] = $q->item_id; $item['orderId'] = $q->orderId; $item['date'] = $this->timeago(strtotime($q->reg_date)); $data[] = $item; } } } // update notification if($type == 'update') { if($id && $user_id) { $status = true; $msg = 'Successful'; $this->Crud->updates('id', $id, 'notify', array('new'=>0)); } } // delete notification if($type == 'delete') { if($id && $user_id) { $status = true; $msg = 'Successful'; $this->Crud->deletes('id', $id, 'notify'); } } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } // station public function station($id='') { $status = false; $msg = ''; $data = array(); // collect call paramters $type = $this->request->getGet('type'); $user_id = $this->request->getGet('user_id'); $user_address = $this->request->getGet('user_address'); $lga = $this->request->getGet('lga'); // $limit = $this->request->getGet('limit'); // $offset = $this->request->getGet('offset'); if(empty($limit)) {$limit = 10;} if(empty($offset)) {$offset = 0;} // read all notification if($type == 'all') { $field = 'state'; // $lga_id = $this->Crud->read_field('name', trim($lga), $field, 'id'); $lga_id = $this->Crud->read_field('id', $user_id, 'user', 'state_id'); $query = $this->Crud->read2($field.'_id', $lga_id, 'is_partner', 1, 'user', 'id', 'DESC', $limit, $offset); if(!empty($query)) { $status = true; $msg = 'Successful'; foreach($query as $q) { $item = array(); $distance = $this->Crud->getDistance($user_address, $q->address, 'K'); $item['id'] = $q->id; $item['fullname'] = $q->fullname; $item['image'] = site_url($this->Crud->image($q->logo, 'big')); $item['address'] = $q->address; $item['distance'] = $distance; $petrol = 0; $diesel = 0; $gas = 0; $kerosene = 0; $pumps = $this->Crud->read_single('user_id', $q->id, 'pump'); if(!empty($pumps)) { foreach($pumps as $p) { $amount = $p->price; if($p->product == 1) { $petrol = $amount; } if($p->product == 2) { $diesel = $amount; } if($p->product == 3) { $gas = $amount; } if($p->product == 4) { $kerosene = $amount; } } } $item['petrol'] = number_format($petrol, 2); $item['diesel'] = number_format($diesel, 2); $item['gas'] = number_format($gas, 2); $item['kerosene'] = number_format($kerosene, 2); $data[] = $item; } } } echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } // get settings public function setting() { $status = false; $data = array(); $msg = ''; $sandbox = true; $getsandbox = $this->Crud->read_field('name', 'sandbox', 'setting', 'value'); if($getsandbox == 'no') { $sandbox = false; } if($sandbox == true) { $pkey = $this->Crud->read_field('name', 'test_pkey', 'setting', 'value'); $ekey = $this->Crud->read_field('name', 'test_ekey', 'setting', 'value'); } else { $pkey = $this->Crud->read_field('name', 'live_pkey', 'setting', 'value'); $ekey = $this->Crud->read_field('name', 'live_ekey', 'setting', 'value'); } // responses $status = true; $msg = 'Successful'; $data['sandbox'] = $sandbox; $data['public_key'] = $pkey; $data['encryption_key'] = $ekey; echo json_encode(array('status'=>$status, 'msg'=>$msg, 'data'=>$data)); die; } //// others ////// public function user_data($id) { $query = $this->Crud->read_single('id', $id, 'user'); if(!empty($query)) { foreach($query as $q) { $data['id'] = $q->id; $data['fullname'] = $q->fullname; $data['email'] = $q->email; $data['phone'] = $q->phone; $data['country'] = $this->Crud->read_field('id', $q->country_id, 'country', 'name'); $data['curr'] = $this->Crud->read_field('id', $q->country_id, 'country', 'currency'); $data['curr_symbol'] = $this->Crud->read_field('id', $q->country_id, 'country', 'currency_symbol'); $data['img'] = site_url($this->Crud->image($q->img_id, 'big')); $data['role_id'] = $q->role_id; $data['role'] = $this->Crud->read_field('id', $q->role_id, 'access_role', 'name'); $data['reg_date'] = date('M d, Y h:i A', strtotime($q->reg_date)); return $data; } } else { return false; } } private function get_balance($id) { $balance = 0; $earnings = 0; $withdrawns = 0; $wallets = $this->Crud->read_single('user_id', $id, 'wallet'); if(!empty($wallets)) { foreach($wallets as $w) { if($w->type == 'credit') { $earnings += (float)$w->amount; } else { $withdrawns += (float)$w->amount; } } $balance = $earnings - $withdrawns; } return $balance; } private function orderDetails($id) { $data = array(); $query = $this->Crud->read_single('id', $id, 'order'); if(!empty($query)) { foreach($query as $q) { $data['id'] = $q->id; $data['ref'] = $q->ref; $data['code'] = $q->code; $data['category'] = $this->Crud->read_field('id', $q->category_id, 'category', 'name'); $data['amount'] = number_format((float)$q->amount, 2); $data['comm'] = number_format((float)$q->comm, 2); $data['vat'] = number_format((float)$q->vat, 2); $data['total'] = number_format((float)$q->total, 2); $data['status'] = $q->status; $data['litre'] = $q->litre; $data['partner'] = $this->Crud->read_field('id', $q->partner_id, 'user', 'fullname'); $data['partner_address'] = $this->Crud->read_field('id', $q->partner_id, 'user', 'address'); $data['city'] = $this->Crud->read_field('id', $q->city_id, 'city', 'name'); $data['state'] = $this->Crud->read_field('id', $q->state_id, 'state', 'name'); $data['country'] = $this->Crud->read_field('id', $q->country_id, 'country', 'name'); $data['used_date'] = date('M d, Y h:iA', strtotime($q->used_date)); $data['date'] = date('M d, Y h:iA', strtotime($q->reg_date)); } } return $data; } private function notify($from, $to, $content, $item, $item_id) { $ins['from_id'] = $from; $ins['to_id'] = $to; $ins['content'] = $content; $ins['item'] = $item; $ins['item_id'] = $item_id; $ins['new'] = 1; $ins['reg_date'] = date(fdate); $this->Crud->create('notify', $ins); } private function send_email($to, $subject, $body) { $from = push_email; $name = app_name; $subhead = 'Notification'; $this->Crud->send_email($to, $from, $subject, $body, $name, $subhead); } private function timeago($ptime) { $estimate_time = time() - $ptime; if( $estimate_time < 1 ) { return 'less than 1 second ago'; } $condition = array( 12 * 30 * 24 * 60 * 60 => 'year', 30 * 24 * 60 * 60 => 'month', 24 * 60 * 60 => 'day', 60 * 60 => 'hour', 60 => 'minute', 1 => 'second' ); foreach($condition as $secs => $str) { $d = $estimate_time / $secs; if($d >= 1) { $r = round( $d ); return 'about ' . $r . ' ' . $str . ( $r > 1 ? 's' : '' ) . ' ago'; } } } private function getIPAddress() { //whether ip is from the share internet if(!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } //whether ip is from the proxy else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } //whether ip is from the remote address else { $ip = $_SERVER['REMOTE_ADDR']; } return $ip; } }
Upload File
Create Folder