1692 lines
61 KiB
PHP
Executable File
1692 lines
61 KiB
PHP
Executable File
<?php
|
|
//'tes' => number_format(200 / 100, 2, ",", "."),
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
require APPPATH . '/libraries/REST_Controller.php';
|
|
class Pelanggan extends REST_Controller
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->load->helper("url");
|
|
$this->load->helper('fcm_v1_helper');
|
|
$this->load->database();
|
|
$this->load->model('Pelanggan_model');
|
|
$this->load->model('wallet_model', 'wallet');
|
|
$this->load->model('Driver_model');
|
|
date_default_timezone_set('Asia/Jakarta');
|
|
}
|
|
|
|
/**
|
|
* Structured API request log for order-related endpoints.
|
|
*/
|
|
private function log_order_api_request($endpoint, $rawBody)
|
|
{
|
|
log_message('debug', '[ORDER_API][' . $endpoint . '][REQUEST] ' . $rawBody);
|
|
}
|
|
|
|
/**
|
|
* Structured API response log for order-related endpoints.
|
|
*/
|
|
private function log_order_api_response($endpoint, $responsePayload)
|
|
{
|
|
log_message('debug', '[ORDER_API][' . $endpoint . '][RESPONSE] ' . json_encode($responsePayload));
|
|
}
|
|
|
|
/**
|
|
* Log candidate drivers targeted by customer order flow.
|
|
*/
|
|
private function log_order_driver_targets($endpoint, $idTransaksi, $driverList)
|
|
{
|
|
$ids = array();
|
|
if (is_array($driverList)) {
|
|
foreach ($driverList as $d) {
|
|
if (is_object($d) && isset($d->id)) {
|
|
$ids[] = (string) $d->id;
|
|
} else if (is_array($d) && isset($d['id'])) {
|
|
$ids[] = (string) $d['id'];
|
|
}
|
|
}
|
|
}
|
|
log_message(
|
|
'debug',
|
|
'[ORDER_API][' . $endpoint . '][DRIVER_TARGETS] id_transaksi=' . $idTransaksi .
|
|
' total=' . count($ids) . ' driver_ids=' . implode(',', $ids)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Store raw request/response on transaksi row for dashboard detail (requires DB columns).
|
|
*/
|
|
private function save_order_creation_logs($id_transaksi, $raw_request, $response_payload, $driver_targets)
|
|
{
|
|
$id_transaksi = (int) $id_transaksi;
|
|
if ($id_transaksi <= 0) {
|
|
return;
|
|
}
|
|
$rows = array();
|
|
if (is_array($driver_targets)) {
|
|
foreach ($driver_targets as $d) {
|
|
$rows[] = json_decode(json_encode($d), true);
|
|
}
|
|
}
|
|
$backend_driver = json_encode(array(
|
|
'note' => 'Candidate drivers from get_data_driver_histroy after order create; client apps may use Firebase/FCM for dispatch.',
|
|
'candidate_drivers' => $rows,
|
|
), JSON_UNESCAPED_UNICODE);
|
|
$this->Pelanggan_model->save_transaksi_api_log(
|
|
$id_transaksi,
|
|
$raw_request,
|
|
json_encode($response_payload, JSON_UNESCAPED_UNICODE),
|
|
$backend_driver
|
|
);
|
|
}
|
|
|
|
function index_get()
|
|
{
|
|
$this->response("Api for Ontime!", 200);
|
|
}
|
|
|
|
function privacy_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$app_settings = $this->Pelanggan_model->get_settings();
|
|
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'found',
|
|
'data' => $app_settings
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function forgot_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$decoded_data = json_decode($data);
|
|
|
|
$condition = array(
|
|
'email' => $decoded_data->email,
|
|
'status' => '1'
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
$app_settings = $this->Pelanggan_model->get_settings();
|
|
$token = sha1(rand(0, 999999) . time());
|
|
|
|
|
|
if ($cek_login->num_rows() > 0) {
|
|
$cheker = array('msg' => $cek_login->result());
|
|
foreach ($app_settings as $item) {
|
|
foreach ($cheker['msg'] as $item2 => $val) {
|
|
$dataforgot = array(
|
|
'userid' => $val->id,
|
|
'token' => $token,
|
|
'idKey' => '1'
|
|
);
|
|
}
|
|
|
|
|
|
$forgot = $this->Pelanggan_model->dataforgot($dataforgot);
|
|
|
|
$linkbtn = base_url() . 'resetpass/rest/' . $token . '/1';
|
|
$template = $this->Pelanggan_model->template1($item['email_subject'], $item['email_text1'], $item['email_text2'], $item['app_website'], $item['app_name'], $linkbtn, $item['app_linkgoogle'], $item['app_address']);
|
|
$sendmail = $this->Pelanggan_model->emailsend($item['email_subject'] . " [ticket-" . rand(0, 999999) . "]", $decoded_data->email, $template, $item['smtp_host'], $item['smtp_port'], $item['smtp_username'], $item['smtp_password'], $item['smtp_from'], $item['app_name'], $item['smtp_secure']);
|
|
}
|
|
if ($forgot && $sendmail) {
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'found',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '401',
|
|
'message' => 'email tidak terdaftar',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
} else {
|
|
$message = array(
|
|
'code' => '404',
|
|
'message' => 'email tidak terdaftar',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function login_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$decoded_data = json_decode($data);
|
|
if (!$decoded_data || !isset($decoded_data->password)) {
|
|
$this->response(array('code' => '400', 'message' => 'Invalid request', 'data' => []), 200);
|
|
return;
|
|
}
|
|
if (function_exists('fcm_v1_validate_login_device_token_from_app')) {
|
|
$fcm_err = fcm_v1_validate_login_device_token_from_app($decoded_data);
|
|
if (is_array($fcm_err)) {
|
|
$this->response(
|
|
array('code' => $fcm_err['code'], 'message' => $fcm_err['message'], 'data' => []),
|
|
200
|
|
);
|
|
return;
|
|
}
|
|
}
|
|
// Only save FCM token when valid (relogin overwrites invalid/placeholder tokens).
|
|
$token = function_exists('fcm_v1_device_token_from_request')
|
|
? fcm_v1_device_token_from_request($decoded_data)
|
|
: '';
|
|
$reg_id = array();
|
|
if ($token !== '' && function_exists('fcm_v1_is_valid_device_token') && fcm_v1_is_valid_device_token($token)) {
|
|
$reg_id['token'] = $token;
|
|
}
|
|
|
|
$condition = array(
|
|
'password' => sha1($decoded_data->password)
|
|
);
|
|
$no_telepon_val = isset($decoded_data->no_telepon) ? trim($decoded_data->no_telepon) : '';
|
|
$email_val = isset($decoded_data->email) ? trim($decoded_data->email) : '';
|
|
$login_by_phone = $no_telepon_val !== '';
|
|
if ($login_by_phone) {
|
|
$condition['no_telepon'] = $no_telepon_val;
|
|
} else {
|
|
if ($email_val === '') {
|
|
$this->response(array('code' => '404', 'message' => 'no hp atau password salah!', 'data' => []), 200);
|
|
return;
|
|
}
|
|
$condition['email'] = $email_val;
|
|
}
|
|
|
|
$check_banned = $login_by_phone
|
|
? $this->Pelanggan_model->check_banned($no_telepon_val)
|
|
: $this->Pelanggan_model->check_banned_user($email_val);
|
|
if ($check_banned) {
|
|
$message = array(
|
|
'message' => 'banned',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
$message = array();
|
|
|
|
if ($cek_login->num_rows() > 0) {
|
|
$no_telepon = $cek_login->row()->no_telepon;
|
|
if (!empty($reg_id)) {
|
|
$this->Pelanggan_model->edit_profile($reg_id, $no_telepon);
|
|
}
|
|
$get_pelanggan = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'found',
|
|
'data' => $get_pelanggan->result()
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '404',
|
|
'message' => 'no hp atau password salah!',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
}
|
|
|
|
function register_user_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
|
|
$email = $dec_data->email;
|
|
$phone = $dec_data->no_telepon;
|
|
$check_exist = $this->Pelanggan_model->check_exist($email, $phone);
|
|
$check_exist_phone = $this->Pelanggan_model->check_exist_phone($phone);
|
|
$check_exist_email = $this->Pelanggan_model->check_exist_email($email);
|
|
if ($check_exist) {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'email atau no hp sudah ada',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
} else if ($check_exist_phone) {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'no hp sudah dipakai',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
} else if ($check_exist_email) {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'email sudah dipakai',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
} else {
|
|
if ($dec_data->checked == "true") {
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'next',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$image = $dec_data->fotopelanggan;
|
|
$namafoto = time() . '-' . rand(0, 99999) . ".jpg";
|
|
$path = "images/pelanggan/" . $namafoto;
|
|
file_put_contents($path, base64_decode($image));
|
|
|
|
// New users may register from older apps that do not send an FCM token.
|
|
// Generate a deterministic placeholder based on email so the column is never empty.
|
|
// This placeholder is intentionally SHORT / starting with "R" + digits so
|
|
// fcm_v1_is_valid_device_token() will treat it as invalid for push.
|
|
$incomingToken = function_exists('fcm_v1_device_token_from_request')
|
|
? fcm_v1_device_token_from_request($dec_data)
|
|
: (isset($dec_data->token) ? trim((string) $dec_data->token) : '');
|
|
if ($incomingToken === '') {
|
|
$emailForToken = isset($dec_data->email) ? strtolower(trim((string) $dec_data->email)) : '';
|
|
if ($emailForToken !== '') {
|
|
$incomingToken = 'R' . sprintf('%u', crc32($emailForToken));
|
|
} else {
|
|
$incomingToken = 'R' . sprintf('%u', crc32('guest-' . time()));
|
|
}
|
|
}
|
|
|
|
$data_signup = array(
|
|
'id' => 'P' . time(),
|
|
'fullnama' => $dec_data->fullnama,
|
|
'email' => $dec_data->email,
|
|
'no_telepon' => $dec_data->no_telepon,
|
|
'phone' => $dec_data->phone,
|
|
'password' => sha1($dec_data->password),
|
|
'tgl_lahir' => $dec_data->tgl_lahir,
|
|
'countrycode' => $dec_data->countrycode,
|
|
'fotopelanggan' => $namafoto,
|
|
'token' => $incomingToken,
|
|
);
|
|
$signup = $this->Pelanggan_model->signup($data_signup);
|
|
if ($signup) {
|
|
$condition = array(
|
|
'password' => sha1($dec_data->password),
|
|
'email' => $dec_data->email
|
|
);
|
|
$datauser1 = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'data' => $datauser1->result()
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function kodepromo_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$kodepromo = $this->Pelanggan_model->promo_code_use($dec_data->code, $dec_data->fitur);
|
|
if ($kodepromo) {
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'nominal' => $kodepromo['nominal'],
|
|
'type' => $kodepromo['type']
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed'
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
function listkodepromo_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$kodepromo = $this->Pelanggan_model->promo_code()->result();
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'data' => $kodepromo
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function home_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$slider = $this->Pelanggan_model->sliderhome();
|
|
$fitur = $this->Pelanggan_model->fiturhome();
|
|
$allfitur = $this->Pelanggan_model->fiturhomeall();
|
|
$rating = $this->Pelanggan_model->ratinghome();
|
|
$saldo = $this->Pelanggan_model->saldouser($dec_data->id);
|
|
$app_settings = $this->Pelanggan_model->get_settings();
|
|
$berita = $this->Pelanggan_model->beritahome();
|
|
$kategorymerchant = $this->Pelanggan_model->kategorymerchant()->result();
|
|
$long = $dec_data->longitude;
|
|
$lat = $dec_data->latitude;
|
|
$merchantpromo = $this->Pelanggan_model->merchantpromo($long, $lat)->result();
|
|
$merchantnearby = $this->Pelanggan_model->merchantnearby($long, $lat);
|
|
|
|
|
|
|
|
$condition = array(
|
|
'no_telepon' => $dec_data->no_telepon,
|
|
'status' => '1'
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
foreach ($app_settings as $item) {
|
|
if ($cek_login->num_rows() > 0) {
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'saldo' => $saldo->row('saldo'),
|
|
'currency' => $item['app_currency'],
|
|
'currency_text' => $item['app_currency_text'],
|
|
'app_aboutus' => $item['app_aboutus'],
|
|
'app_contact' => $item['app_contact'],
|
|
'app_website' => $item['app_website'],
|
|
'mobilepulsa_username' => $item['mobilepulsa_username'],
|
|
'mobilepulsa_api_key' => $item['mobilepulsa_api_key'],
|
|
'mp_status' => $item['mp_status'],
|
|
'mp_active' => $item['mp_active'],
|
|
'app_email' => $item['app_email'],
|
|
'api_password' => $item['api_password'],
|
|
'harga_pulsa' => $item['harga_pulsa'],
|
|
'api_token' => $item['api_token'],
|
|
'slider' => $slider,
|
|
'allfitur' => $allfitur,
|
|
'ratinghome' => $rating,
|
|
'beritahome' => $berita,
|
|
'kategorymerchanthome' => $kategorymerchant,
|
|
'merchantnearby' => $merchantnearby,
|
|
'merchantpromo' => $merchantpromo,
|
|
'data' => $cek_login->result(),
|
|
'fitur' => $fitur
|
|
|
|
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function merchantbykategori_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$kategori = $dec_data->kategori;
|
|
$long = $dec_data->longitude;
|
|
$lat = $dec_data->latitude;
|
|
$merchantbykategori = $this->Pelanggan_model->merchantbykategori($kategori, $long, $lat)->result();
|
|
$condition = array(
|
|
'no_telepon' => $dec_data->no_telepon,
|
|
'status' => '1'
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
if ($cek_login->num_rows() > 0) {
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
|
|
'merchantbykategori' => $merchantbykategori
|
|
);
|
|
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
}
|
|
}
|
|
|
|
public function merchantbykategoripromo_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$kategori = $dec_data->kategori;
|
|
$long = $dec_data->longitude;
|
|
$lat = $dec_data->latitude;
|
|
|
|
$merchantbykategori = $this->Pelanggan_model->merchantbykategoripromo($kategori, $long, $lat)->result();
|
|
$condition = array(
|
|
'no_telepon' => $dec_data->no_telepon,
|
|
'status' => '1'
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
if ($cek_login->num_rows() > 0) {
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
|
|
'merchantbykategori' => $merchantbykategori
|
|
);
|
|
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
}
|
|
}
|
|
|
|
public function allmerchant_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
|
|
|
|
$fitur = $dec_data->fitur;
|
|
$kategorymerchant = $this->Pelanggan_model->kategorymerchantbyfitur($fitur)->result();
|
|
$long = $dec_data->longitude;
|
|
$lat = $dec_data->latitude;
|
|
|
|
$allmerchantnearby = $this->Pelanggan_model->allmerchantnearby($long, $lat, $fitur)->result();
|
|
$condition = array(
|
|
'no_telepon' => $dec_data->no_telepon,
|
|
'status' => '1'
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
|
|
if ($cek_login->num_rows() > 0) {
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
|
|
'kategorymerchant' => $kategorymerchant,
|
|
'allmerchantnearby' => $allmerchantnearby
|
|
|
|
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
}
|
|
}
|
|
|
|
public function allmerchantbykategori_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
|
|
|
|
$fitur = $dec_data->fitur;
|
|
|
|
$long = $dec_data->longitude;
|
|
$lat = $dec_data->latitude;
|
|
$kategori = $dec_data->kategori;
|
|
$allmerchantnearbybykategori = $this->Pelanggan_model->allmerchantnearbybykategori($long, $lat, $fitur, $kategori)->result();
|
|
$condition = array(
|
|
'no_telepon' => $dec_data->no_telepon,
|
|
'status' => '1'
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
|
|
if ($cek_login->num_rows() > 0) {
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
|
|
|
|
'allmerchantnearby' => $allmerchantnearbybykategori
|
|
|
|
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
}
|
|
}
|
|
|
|
public function searchmerchant_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$like = $dec_data->like;
|
|
$long = $dec_data->longitude;
|
|
$lat = $dec_data->latitude;
|
|
$fitur = $dec_data->fitur;
|
|
$searchmerchantnearby = $this->Pelanggan_model->searchmerchantnearby($like, $long, $lat, $fitur);
|
|
$condition = array(
|
|
'no_telepon' => $dec_data->no_telepon,
|
|
'status' => '1'
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
|
|
if ($cek_login->num_rows() > 0) {
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
|
|
|
|
'allmerchantnearby' => $searchmerchantnearby
|
|
|
|
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
}
|
|
}
|
|
|
|
public function merchantbyid_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$idmerchant = $dec_data->idmerchant;
|
|
$long = $dec_data->longitude;
|
|
$lat = $dec_data->latitude;
|
|
|
|
$merchantbyid = $this->Pelanggan_model->merchantbyid($idmerchant, $long, $lat)->row();
|
|
$itemstatus = $this->Pelanggan_model->itemstatus($idmerchant)->row();
|
|
if (empty($itemstatus->status_promo)) {
|
|
$itempromo = '0';
|
|
} else {
|
|
$itempromo = $itemstatus->status_promo;
|
|
}
|
|
|
|
|
|
$itembyid = $this->Pelanggan_model->itembyid($idmerchant)->Result();
|
|
$kategoriitem = $this->Pelanggan_model->kategoriitem($idmerchant)->Result();
|
|
|
|
$condition = array(
|
|
'no_telepon' => $dec_data->no_telepon,
|
|
'status' => '1'
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
|
|
if ($cek_login->num_rows() > 0) {
|
|
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'idfitur' => $merchantbyid->id_fitur,
|
|
'idmerchant' => $merchantbyid->id_merchant,
|
|
'namamerchant' => $merchantbyid->nama_merchant,
|
|
'alamatmerchant' => $merchantbyid->alamat_merchant,
|
|
'rate_merchant' => $merchantbyid->rate_merchant,
|
|
'latmerchant' => $merchantbyid->latitude_merchant,
|
|
'longmerchant' => $merchantbyid->longitude_merchant,
|
|
'bukamerchant' => $merchantbyid->jam_buka,
|
|
'tutupmerchant' => $merchantbyid->jam_tutup,
|
|
'descmerchant' => $merchantbyid->deskripsi_merchant,
|
|
'fotomerchant' => $merchantbyid->foto_merchant,
|
|
'telpcmerchant' => $merchantbyid->telepon_merchant,
|
|
'distance' => $merchantbyid->distance,
|
|
'partner' => $merchantbyid->partner,
|
|
'kategori' => $merchantbyid->nama_kategori,
|
|
'promo' => $itempromo,
|
|
'itembyid' => $itembyid,
|
|
'kategoriitem' => $kategoriitem
|
|
|
|
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
}
|
|
}
|
|
|
|
public function itembykategori_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$idmerchant = $dec_data->id;
|
|
|
|
$itemk = $dec_data->kategori;
|
|
$itembykategori = $this->Pelanggan_model->itembykategori($idmerchant, $itemk)->result();
|
|
|
|
$condition = array(
|
|
'no_telepon' => $dec_data->no_telepon,
|
|
'status' => '1'
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
|
|
if ($cek_login->num_rows() > 0) {
|
|
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'itembyid' => $itembykategori
|
|
|
|
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'failed',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function rate_driver_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
|
|
|
|
$data_rate = array();
|
|
|
|
if ($dec_data->catatan == "") {
|
|
$data_rate = array(
|
|
'id_pelanggan' => $dec_data->id_pelanggan,
|
|
'id_driver' => $dec_data->id_driver,
|
|
'rating' => $dec_data->rating,
|
|
'id_transaksi' => $dec_data->id_transaksi
|
|
);
|
|
} else {
|
|
$data_rate = array(
|
|
'id_pelanggan' => $dec_data->id_pelanggan,
|
|
'id_driver' => $dec_data->id_driver,
|
|
'rating' => $dec_data->rating,
|
|
'id_transaksi' => $dec_data->id_transaksi,
|
|
'catatan' => $dec_data->catatan
|
|
);
|
|
}
|
|
|
|
$finish_transaksi = $this->Pelanggan_model->rate_driver($data_rate);
|
|
|
|
if ($finish_transaksi) {
|
|
$message = array(
|
|
'message' => 'success',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'message' => 'fail',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
public function topupmidtrans_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
|
|
$iduser = $dec_data->id;
|
|
$bank = $dec_data->bank;
|
|
$nama = $dec_data->nama;
|
|
$amount = $dec_data->amount;
|
|
$card = $dec_data->card;
|
|
$email = $dec_data->email;
|
|
$phone = $dec_data->no_telepon;
|
|
|
|
|
|
$datatopup = array(
|
|
'id_user' => $iduser,
|
|
'rekening' => $card,
|
|
'bank' => $bank,
|
|
'nama_pemilik' => $nama,
|
|
'type' => 'topup',
|
|
'jumlah' => $amount,
|
|
'status' => 1
|
|
);
|
|
$check_exist = $this->Pelanggan_model->check_exist($email, $phone);
|
|
|
|
if ($check_exist) {
|
|
$this->Pelanggan_model->insertwallet($datatopup);
|
|
$saldolama = $this->Pelanggan_model->saldouser($iduser);
|
|
$saldobaru = $saldolama->row('saldo') + $amount;
|
|
$saldo = array('saldo' => $saldobaru);
|
|
$this->Pelanggan_model->tambahsaldo($iduser, $saldo);
|
|
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'You have insufficient balance',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
|
|
public function withdraw_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
|
|
|
|
$iduser = $dec_data->id;
|
|
$bank = $dec_data->bank;
|
|
$nama = $dec_data->nama;
|
|
$amount = $dec_data->amount;
|
|
$card = $dec_data->card;
|
|
$email = $dec_data->email;
|
|
$phone = $dec_data->no_telepon;
|
|
|
|
$saldolama = $this->Pelanggan_model->saldouser($iduser);
|
|
|
|
$datawithdraw = array(
|
|
'id_user' => $iduser,
|
|
'rekening' => $card,
|
|
'bank' => $bank,
|
|
'nama_pemilik' => $nama,
|
|
'type' => $dec_data->type,
|
|
'jumlah' => $amount,
|
|
'status' => ($dec_data->type == "topup") ? 0 : 1
|
|
);
|
|
$check_exist = $this->Pelanggan_model->check_exist($email, $phone);
|
|
|
|
if ($dec_data->type == "topup") {
|
|
$withdrawdata = $this->Pelanggan_model->insertwallet($datawithdraw);
|
|
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
|
|
if ($saldolama->row('saldo') >= $amount && $check_exist) {
|
|
$withdrawdata = $this->Pelanggan_model->insertwallet($datawithdraw);
|
|
|
|
/**
|
|
* Start Edit
|
|
*
|
|
*
|
|
*/
|
|
$token = $this->wallet->gettoken($iduser);
|
|
$regid = $this->wallet->getregid($iduser);
|
|
$tokenmerchant = $this->wallet->gettokenmerchant($iduser);
|
|
|
|
$topic = null;
|
|
if ($token == NULL and $tokenmerchant == NULL and $regid != NULL && !empty(trim((string) $regid['reg_id']))) {
|
|
$topic = $regid['reg_id'];
|
|
} else if ($regid == NULL and $tokenmerchant == NULL and $token != NULL && !empty(trim((string) $token['token']))) {
|
|
$topic = $token['token'];
|
|
} else if ($regid == NULL and $token == NULL and $tokenmerchant != NULL && !empty(trim((string) $tokenmerchant['token_merchant']))) {
|
|
$topic = $tokenmerchant['token_merchant'];
|
|
}
|
|
|
|
$title = 'Sukses';
|
|
$message = 'Permintaan berhasil dikirim';
|
|
$saldo = $this->wallet->getsaldo($iduser);
|
|
|
|
$this->wallet->ubahsaldo($iduser, $amount, $saldo);
|
|
if ($topic !== null) {
|
|
$this->wallet->send_notif($title, $message, $topic);
|
|
}
|
|
|
|
/* END EDIT */
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'Saldo anda tidak mencukupi',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
}
|
|
|
|
function list_ride_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
log_message('debug', 'list_ride_post REQUEST: ' . $data);
|
|
|
|
$dec_data = json_decode($data);
|
|
if (!$dec_data || !isset($dec_data->latitude, $dec_data->longitude, $dec_data->fitur)) {
|
|
log_message('error', 'list_ride_post: invalid request, missing latitude/longitude/fitur');
|
|
$message = array('data' => [], 'error' => 'Invalid request: latitude, longitude, fitur required');
|
|
$this->response($message, 200);
|
|
return;
|
|
}
|
|
|
|
$radius_km = null;
|
|
if (isset($dec_data->radius_km) && is_numeric($dec_data->radius_km)) {
|
|
$radius_km = max(1, min(100, (float) $dec_data->radius_km));
|
|
}
|
|
$near = $this->Pelanggan_model->get_driver_ride($dec_data->latitude, $dec_data->longitude, $dec_data->fitur, $radius_km);
|
|
$drivers = $near->result();
|
|
$message = array(
|
|
'data' => $drivers
|
|
);
|
|
log_message('debug', 'list_ride_post RESPONSE: fitur=' . $dec_data->fitur . ' lat=' . $dec_data->latitude . ' lng=' . $dec_data->longitude . ' radius_km=' . ($radius_km !== null ? $radius_km : 'default') . ' drivers_found=' . count($drivers));
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function list_bank_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$near = $this->Pelanggan_model->listbank();
|
|
$message = array(
|
|
'data' => $near->result()
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function list_car_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
log_message('debug', 'list_car_post REQUEST: ' . $data);
|
|
|
|
$dec_data = json_decode($data);
|
|
if (!$dec_data || !isset($dec_data->latitude, $dec_data->longitude, $dec_data->fitur)) {
|
|
log_message('error', 'list_car_post: invalid request, missing latitude/longitude/fitur');
|
|
$message = array('data' => [], 'error' => 'Invalid request: latitude, longitude, fitur required');
|
|
$this->response($message, 200);
|
|
return;
|
|
}
|
|
|
|
$radius_km = null;
|
|
if (isset($dec_data->radius_km) && is_numeric($dec_data->radius_km)) {
|
|
$radius_km = max(1, min(100, (float) $dec_data->radius_km));
|
|
}
|
|
$near = $this->Pelanggan_model->get_driver_car($dec_data->latitude, $dec_data->longitude, $dec_data->fitur, $radius_km);
|
|
$drivers = $near->result();
|
|
$message = array(
|
|
'data' => $drivers
|
|
);
|
|
log_message('debug', 'list_car_post RESPONSE: fitur=' . $dec_data->fitur . ' lat=' . $dec_data->latitude . ' lng=' . $dec_data->longitude . ' radius_km=' . ($radius_km !== null ? $radius_km : 'default') . ' drivers_found=' . count($drivers));
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function detail_fitur_get()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$app_settings = $this->Pelanggan_model->get_settings();
|
|
$biaya = $this->Pelanggan_model->get_biaya();
|
|
foreach ($app_settings as $item) {
|
|
$message = array(
|
|
'data' => $biaya,
|
|
'currency' => $item['app_currency'],
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
function request_transaksi_post()
|
|
{
|
|
$endpoint = 'request_transaksi_post';
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
} else {
|
|
$cek = $this->Pelanggan_model->check_banned_user($_SERVER['PHP_AUTH_USER']);
|
|
if ($cek) {
|
|
$message = array(
|
|
'message' => 'fail',
|
|
'data' => 'Status User Banned'
|
|
);
|
|
log_message('debug', '[ORDER_API][' . $endpoint . '] banned user ' . $_SERVER['PHP_AUTH_USER']);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$this->log_order_api_request($endpoint, $data);
|
|
|
|
$data_req = array(
|
|
'id_pelanggan' => $dec_data->id_pelanggan,
|
|
'order_fitur' => $dec_data->order_fitur,
|
|
'start_latitude' => $dec_data->start_latitude,
|
|
'start_longitude' => $dec_data->start_longitude,
|
|
'end_latitude' => $dec_data->end_latitude,
|
|
'end_longitude' => $dec_data->end_longitude,
|
|
'jarak' => $dec_data->jarak,
|
|
'harga' => $dec_data->harga,
|
|
'estimasi_time' => $dec_data->estimasi,
|
|
'waktu_order' => date('Y-m-d H:i:s'),
|
|
'alamat_asal' => $dec_data->alamat_asal,
|
|
'alamat_tujuan' => $dec_data->alamat_tujuan,
|
|
'biaya_akhir' => $dec_data->harga,
|
|
'kredit_promo' => $dec_data->kredit_promo,
|
|
'pakai_wallet' => $dec_data->pakai_wallet
|
|
);
|
|
|
|
$request = $this->Pelanggan_model->insert_transaksi($data_req);
|
|
$idTransaksiNum = 0;
|
|
if ($request['status'] && !empty($request['data'])) {
|
|
foreach ($request['data'] as $row) {
|
|
if (is_object($row) && isset($row->id)) {
|
|
$idTransaksiNum = (int) $row->id;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if ($request['status']) {
|
|
$idTransaksi = $idTransaksiNum > 0 ? $idTransaksiNum : 'unknown';
|
|
$driverTargets = $idTransaksiNum > 0
|
|
? $this->Pelanggan_model->get_data_driver_histroy($idTransaksiNum)->result()
|
|
: array();
|
|
$this->log_order_driver_targets($endpoint, $idTransaksi, $driverTargets);
|
|
if ($idTransaksiNum > 0) {
|
|
log_message('debug', 'request_transaksi_post: success id_transaksi=' . $idTransaksiNum . ' id_pelanggan=' . $dec_data->id_pelanggan . ' fitur=' . $dec_data->order_fitur);
|
|
} else {
|
|
log_message('debug', 'request_transaksi_post: success (no id in data) payload=' . json_encode($request['data']));
|
|
}
|
|
$message = array(
|
|
'message' => 'success',
|
|
'data' => $request['data']
|
|
);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->save_order_creation_logs($idTransaksiNum, $data, $message, $driverTargets);
|
|
$this->response($message, 200);
|
|
} else {
|
|
log_message('error', 'request_transaksi_post: insert_transaksi fail data=' . json_encode($request['data']));
|
|
$message = array(
|
|
'message' => 'fail',
|
|
'data' => $request['data']
|
|
);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
function check_status_transaksi_post()
|
|
{
|
|
$endpoint = 'check_status_transaksi_post';
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$this->log_order_api_request($endpoint, $data);
|
|
|
|
$dataTrans = array(
|
|
'id_transaksi' => $dec_data->id_transaksi
|
|
);
|
|
|
|
$getStatus = $this->Pelanggan_model->check_status($dataTrans);
|
|
$this->log_order_driver_targets(
|
|
$endpoint,
|
|
isset($dec_data->id_transaksi) ? $dec_data->id_transaksi : 'unknown',
|
|
isset($getStatus['list_driver']) ? $getStatus['list_driver'] : array()
|
|
);
|
|
$this->log_order_api_response($endpoint, $getStatus);
|
|
$this->response($getStatus, 200);
|
|
}
|
|
|
|
function user_cancel_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
|
|
$data_req = array(
|
|
'id_transaksi' => $dec_data->id_transaksi
|
|
);
|
|
$cancel_req = $this->Pelanggan_model->user_cancel_request($data_req);
|
|
if ($cancel_req['status']) {
|
|
$this->Driver_model->delete_chat($cancel_req['iddriver'], $cancel_req['idpelanggan']);
|
|
$message = array(
|
|
'message' => 'canceled',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'message' => 'cancel fail',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
function liat_lokasi_driver_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$getLoc = $this->Pelanggan_model->get_driver_location($dec_data->id);
|
|
$message = array(
|
|
'status' => true,
|
|
'data' => $getLoc->result()
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function detail_transaksi_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$gettrans = $this->Pelanggan_model->transaksi($dec_data->id);
|
|
$getdriver = $this->Pelanggan_model->detail_driver($dec_data->id_driver);
|
|
$getitem = $this->Pelanggan_model->detail_item($dec_data->id);
|
|
|
|
$message = array(
|
|
'status' => true,
|
|
'data' => $gettrans->result(),
|
|
'driver' => $getdriver->result(),
|
|
'item' => $getitem->result(),
|
|
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function detail_berita_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$getberita = $this->Pelanggan_model->beritadetail($dec_data->id);
|
|
$message = array(
|
|
'status' => true,
|
|
'data' => $getberita->result()
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function all_berita_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$getberita = $this->Pelanggan_model->allberita();
|
|
$message = array(
|
|
'status' => true,
|
|
'data' => $getberita
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function edit_profile_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$decoded_data = json_decode($data);
|
|
$check_exist_phone = $this->Pelanggan_model->check_exist_phone_edit($decoded_data->id, $decoded_data->no_telepon);
|
|
$check_exist_email = $this->Pelanggan_model->check_exist_email_edit($decoded_data->id, $decoded_data->email);
|
|
if ($check_exist_phone) {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'no hp sudah dipakai',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
} else if ($check_exist_email) {
|
|
$message = array(
|
|
'code' => '201',
|
|
'message' => 'email sudah dipakai',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 201);
|
|
} else {
|
|
|
|
$condition = array(
|
|
'no_telepon' => $decoded_data->no_telepon
|
|
);
|
|
$condition2 = array(
|
|
'no_telepon' => $decoded_data->no_telepon_lama
|
|
);
|
|
|
|
if ($decoded_data->fotopelanggan == null && $decoded_data->fotopelanggan_lama == null) {
|
|
$datauser = array(
|
|
'fullnama' => $decoded_data->fullnama,
|
|
'no_telepon' => $decoded_data->no_telepon,
|
|
'phone' => $decoded_data->phone,
|
|
'email' => $decoded_data->email,
|
|
'countrycode' => $decoded_data->countrycode,
|
|
'tgl_lahir' => $decoded_data->tgl_lahir
|
|
);
|
|
} else {
|
|
$image = $decoded_data->fotopelanggan;
|
|
$namafoto = time() . '-' . rand(0, 99999) . ".jpg";
|
|
$path = "images/pelanggan/" . $namafoto;
|
|
file_put_contents($path, base64_decode($image));
|
|
|
|
$foto = $decoded_data->fotopelanggan_lama;
|
|
$path = "./images/pelanggan/$foto";
|
|
unlink("$path");
|
|
|
|
|
|
$datauser = array(
|
|
'fullnama' => $decoded_data->fullnama,
|
|
'no_telepon' => $decoded_data->no_telepon,
|
|
'phone' => $decoded_data->phone,
|
|
'email' => $decoded_data->email,
|
|
'fotopelanggan' => $namafoto,
|
|
'countrycode' => $decoded_data->countrycode,
|
|
'tgl_lahir' => $decoded_data->tgl_lahir
|
|
);
|
|
}
|
|
|
|
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition2);
|
|
if ($cek_login->num_rows() > 0) {
|
|
$upd_user = $this->Pelanggan_model->edit_profile($datauser, $decoded_data->no_telepon_lama);
|
|
$getdata = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'success',
|
|
'data' => $getdata->result()
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '404',
|
|
'message' => 'error data',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
}
|
|
|
|
function wallet_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$decoded_data = json_decode($data);
|
|
$getWallet = $this->Pelanggan_model->getwallet($decoded_data->id);
|
|
$message = array(
|
|
'status' => true,
|
|
'data' => $getWallet->result()
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function history_progress_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
$data = file_get_contents("php://input");
|
|
$decoded_data = json_decode($data);
|
|
$getWallet = $this->Pelanggan_model->all_transaksi($decoded_data->id);
|
|
$message = array(
|
|
'status' => true,
|
|
'data' => $getWallet->result()
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function request_transaksi_send_post()
|
|
{
|
|
$endpoint = 'request_transaksi_send_post';
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
} else {
|
|
$cek = $this->Pelanggan_model->check_banned_user($_SERVER['PHP_AUTH_USER']);
|
|
if ($cek) {
|
|
$message = array(
|
|
'message' => 'fail',
|
|
'data' => 'Status User Banned'
|
|
);
|
|
log_message('debug', '[ORDER_API][' . $endpoint . '] banned user ' . $_SERVER['PHP_AUTH_USER']);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$this->log_order_api_request($endpoint, $data);
|
|
|
|
$data_req = array(
|
|
'id_pelanggan' => $dec_data->id_pelanggan,
|
|
'order_fitur' => $dec_data->order_fitur,
|
|
'start_latitude' => $dec_data->start_latitude,
|
|
'start_longitude' => $dec_data->start_longitude,
|
|
'end_latitude' => $dec_data->end_latitude,
|
|
'end_longitude' => $dec_data->end_longitude,
|
|
'jarak' => $dec_data->jarak,
|
|
'harga' => $dec_data->harga,
|
|
'estimasi_time' => $dec_data->estimasi,
|
|
'waktu_order' => date('Y-m-d H:i:s'),
|
|
'alamat_asal' => $dec_data->alamat_asal,
|
|
'alamat_tujuan' => $dec_data->alamat_tujuan,
|
|
'biaya_akhir' => $dec_data->harga,
|
|
'kredit_promo' => $dec_data->kredit_promo,
|
|
'pakai_wallet' => $dec_data->pakai_wallet
|
|
);
|
|
|
|
|
|
$dataDetail = array(
|
|
'nama_pengirim' => $dec_data->nama_pengirim,
|
|
'telepon_pengirim' => $dec_data->telepon_pengirim,
|
|
'nama_penerima' => $dec_data->nama_penerima,
|
|
'telepon_penerima' => $dec_data->telepon_penerima,
|
|
'nama_barang' => $dec_data->nama_barang
|
|
);
|
|
|
|
$request = $this->Pelanggan_model->insert_transaksi_send($data_req, $dataDetail);
|
|
if ($request['status']) {
|
|
$resultRows = $request['data']->result();
|
|
$message = array(
|
|
'message' => 'success',
|
|
'data' => $resultRows
|
|
);
|
|
$idTransaksiNum = 0;
|
|
if (!empty($resultRows[0]) && is_object($resultRows[0]) && isset($resultRows[0]->id)) {
|
|
$idTransaksiNum = (int) $resultRows[0]->id;
|
|
}
|
|
$idTransaksi = $idTransaksiNum > 0 ? $idTransaksiNum : 'unknown';
|
|
$driverTargets = $idTransaksiNum > 0
|
|
? $this->Pelanggan_model->get_data_driver_histroy($idTransaksiNum)->result()
|
|
: array();
|
|
$this->log_order_driver_targets($endpoint, $idTransaksi, $driverTargets);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->save_order_creation_logs($idTransaksiNum, $data, $message, $driverTargets);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'message' => 'fail',
|
|
'data' => []
|
|
);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
function changepass_post()
|
|
{
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$decoded_data = json_decode($data);
|
|
$reg_id = array(
|
|
'password' => sha1($decoded_data->new_password)
|
|
);
|
|
|
|
$condition = array(
|
|
'password' => sha1($decoded_data->password),
|
|
'no_telepon' => $decoded_data->no_telepon
|
|
);
|
|
$condition2 = array(
|
|
'password' => sha1($decoded_data->new_password),
|
|
'no_telepon' => $decoded_data->no_telepon
|
|
);
|
|
$cek_login = $this->Pelanggan_model->get_data_pelanggan($condition);
|
|
$message = array();
|
|
|
|
if ($cek_login->num_rows() > 0) {
|
|
$upd_regid = $this->Pelanggan_model->edit_profile($reg_id, $decoded_data->no_telepon);
|
|
$get_pelanggan = $this->Pelanggan_model->get_data_pelanggan($condition2);
|
|
|
|
$message = array(
|
|
'code' => '200',
|
|
'message' => 'found',
|
|
'data' => $get_pelanggan->result()
|
|
);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'code' => '404',
|
|
'message' => 'wrong password',
|
|
'data' => []
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
function alldriver_get($id)
|
|
{
|
|
$near = $this->Pelanggan_model->get_driver_location_admin();
|
|
$message = array(
|
|
'data' => $near->result()
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function alltransactionpickup_get()
|
|
{
|
|
$near = $this->Pelanggan_model->getAlltransaksipickup();
|
|
$message = array(
|
|
'data' => $near->result()
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
function alltransactiondestination_get()
|
|
{
|
|
$near = $this->Pelanggan_model->getAlltransaksidestination();
|
|
$message = array(
|
|
'data' => $near->result()
|
|
);
|
|
$this->response($message, 200);
|
|
}
|
|
|
|
|
|
function inserttransaksimerchant_post()
|
|
{
|
|
$endpoint = 'inserttransaksimerchant_post';
|
|
if (!isset($_SERVER['PHP_AUTH_USER'])) {
|
|
header("WWW-Authenticate: Basic realm=\"Private Area\"");
|
|
header("HTTP/1.0 401 Unauthorized");
|
|
return false;
|
|
} else {
|
|
$cek = $this->Pelanggan_model->check_banned_user($_SERVER['PHP_AUTH_USER']);
|
|
if ($cek) {
|
|
$message = array(
|
|
'message' => 'fail',
|
|
'data' => 'Status User Banned'
|
|
);
|
|
log_message('debug', '[ORDER_API][' . $endpoint . '] banned user ' . $_SERVER['PHP_AUTH_USER']);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
$data = file_get_contents("php://input");
|
|
$dec_data = json_decode($data);
|
|
$this->log_order_api_request($endpoint, $data);
|
|
|
|
$data_transaksi = array(
|
|
'id_pelanggan' => $dec_data->id_pelanggan,
|
|
'order_fitur' => $dec_data->order_fitur,
|
|
'start_latitude' => $dec_data->start_latitude,
|
|
'start_longitude' => $dec_data->start_longitude,
|
|
'end_latitude' => $dec_data->end_latitude,
|
|
'end_longitude' => $dec_data->end_longitude,
|
|
'jarak' => $dec_data->jarak,
|
|
'harga' => $dec_data->harga,
|
|
'waktu_order' => date('Y-m-d H:i:s'),
|
|
'estimasi_time' => $dec_data->estimasi,
|
|
'alamat_asal' => $dec_data->alamat_asal,
|
|
'alamat_tujuan' => $dec_data->alamat_tujuan,
|
|
'kredit_promo' => $dec_data->kredit_promo,
|
|
|
|
'pakai_wallet' => $dec_data->pakai_wallet,
|
|
);
|
|
$total_belanja = [
|
|
'total_belanja' => $dec_data->total_biaya_belanja,
|
|
];
|
|
|
|
|
|
|
|
$dataDetail = [
|
|
'id_merchant' => $dec_data->id_resto,
|
|
'total_biaya' => $dec_data->total_biaya_belanja,
|
|
'struk' => rand(0, 9999),
|
|
|
|
];
|
|
|
|
|
|
|
|
$result = $this->Pelanggan_model->insert_data_transaksi_merchant($data_transaksi, $dataDetail, $total_belanja);
|
|
|
|
if ($result['status'] == true) {
|
|
|
|
|
|
$pesanan = $dec_data->pesanan;
|
|
|
|
foreach ($pesanan as $pes) {
|
|
$item[] = [
|
|
'catatan_item' => $pes->catatan,
|
|
'id_item' => $pes->id_item,
|
|
'id_merchant' => $dec_data->id_resto,
|
|
'id_transaksi' => $result['id_transaksi'],
|
|
'jumlah_item' => $pes->qty,
|
|
'total_harga' => $pes->total_harga,
|
|
];
|
|
}
|
|
|
|
$request = $this->Pelanggan_model->insert_data_item($item);
|
|
|
|
if ($request['status']) {
|
|
$message = array(
|
|
'message' => 'success',
|
|
'data' => $result['data'],
|
|
);
|
|
$tid = isset($result['id_transaksi']) ? (int) $result['id_transaksi'] : 0;
|
|
$driverTargets = $tid > 0
|
|
? $this->Pelanggan_model->get_data_driver_histroy($tid)->result()
|
|
: array();
|
|
$this->log_order_driver_targets($endpoint, $tid ?: 'unknown', $driverTargets);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->save_order_creation_logs($tid, $data, $message, $driverTargets);
|
|
$this->response($message, 200);
|
|
} else {
|
|
$message = array(
|
|
'message' => 'fail',
|
|
'data' => []
|
|
|
|
);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->response($message, 200);
|
|
}
|
|
} else {
|
|
$message = array(
|
|
'message' => 'fail',
|
|
'data' => []
|
|
|
|
);
|
|
$this->log_order_api_response($endpoint, $message);
|
|
$this->response($message, 200);
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
}
|
|
|