demo transaksi

This commit is contained in:
2026-04-01 11:55:47 +07:00
parent 619d758027
commit 7417222c79
166 changed files with 3111 additions and 5265 deletions
@@ -15,6 +15,16 @@ class Merchantapi_model extends CI_model
}
}
public function check_banned_by_email($email)
{
$stat = $this->db->query("SELECT id_mitra FROM mitra WHERE status_mitra='3' AND email_mitra='$email'");
if ($stat->num_rows() == 1) {
return true;
} else {
return false;
}
}
public function check_exist($email, $phone)
{
$cek = $this->db->query("SELECT id_mitra FROM mitra where email_mitra = '$email' AND telepon_mitra='$phone'");
@@ -64,11 +64,7 @@ class notification_model extends CI_model
public function send_notif($title, $message, $target)
{
if ($this->is_token_empty($target)) {
log_message('debug', 'send_notif: skip, no token');
return true;
}
if (!$this->is_valid_fcm_token($target)) {
log_message('debug', 'send_notif: skip, invalid/placeholder FCM token');
log_message('debug', 'send_notif: skip, empty target');
return true;
}
if (!function_exists('fcm_v1_validate_token')) {
@@ -87,7 +83,11 @@ class notification_model extends CI_model
'title' => $title,
'body' => $message,
);
return $this->send_generic_to_token($target, $data, $options);
if ($this->is_valid_fcm_token($target)) {
return $this->send_generic_to_token($target, $data, $options);
}
// Values like pelanggan, driver, mitra, ouride are FCM topic names (broadcast).
return $this->send_generic_to_topic(trim((string) $target), $data, $options);
}
public function send_notif_topup($title, $id, $message, $method, $token)
@@ -309,7 +309,7 @@ class Pelanggan_model extends CI_model
FROM config_driver ld, driver d, driver_job dj, kendaraan k, saldo s, fitur f
WHERE ld.id_driver = d.id
AND f.id_fitur = $fitur
AND ld.status = '1'
AND ld.status IN ('1','4')
AND dj.id = d.job
AND d.job = f.driver_job
AND d.status = '1'
@@ -334,9 +334,9 @@ class Pelanggan_model extends CI_model
*/
private function log_driver_diagnostic($type, $lat, $lng, $fitur, $lat_min, $lat_max, $lng_min, $lng_max, $radius_km)
{
$r_online = $this->db->query("SELECT COUNT(*) as c FROM config_driver WHERE status='1'")->row();
$r_online = $this->db->query("SELECT COUNT(*) as c FROM config_driver WHERE status IN ('1','4')")->row();
$cnt_online = $r_online ? (int) $r_online->c : 0;
$r_box = $this->db->query("SELECT COUNT(*) as c FROM config_driver ld JOIN driver d ON ld.id_driver=d.id WHERE ld.status='1' AND d.status='1' AND ld.latitude BETWEEN " . (float)$lat_min . " AND " . (float)$lat_max . " AND ld.longitude BETWEEN " . (float)$lng_min . " AND " . (float)$lng_max)->row();
$r_box = $this->db->query("SELECT COUNT(*) as c FROM config_driver ld JOIN driver d ON ld.id_driver=d.id WHERE ld.status IN ('1','4') AND d.status='1' AND ld.latitude BETWEEN " . (float)$lat_min . " AND " . (float)$lat_max . " AND ld.longitude BETWEEN " . (float)$lng_min . " AND " . (float)$lng_max)->row();
$cnt_in_box = $r_box ? (int) $r_box->c : 0;
$fitur_row = $this->db->query("SELECT driver_job, jarak_minimum, wallet_minimum FROM fitur WHERE id_fitur=" . (int)$fitur)->row();
$driver_job = $fitur_row ? $fitur_row->driver_job : null;
@@ -381,7 +381,7 @@ class Pelanggan_model extends CI_model
FROM config_driver ld, driver d, driver_job dj, kendaraan k, saldo s, fitur f
WHERE ld.id_driver = d.id
AND f.id_fitur = $fitur
AND ld.status = '1'
AND ld.status IN ('1','4')
AND dj.id = d.job
AND d.job = f.driver_job
AND d.status = '1'
@@ -1849,5 +1849,80 @@ class Pelanggan_model extends CI_model
$this->db->update('history_transaksi', $data);
return true;
}
/**
* Customers for admin FCM screen: label with fullnama / phone / email plus id.
*/
public function get_all_for_notification_picker()
{
$this->db->select('id, fullnama, email, no_telepon, token');
$this->db->from('pelanggan');
$this->db->order_by('fullnama', 'ASC');
$this->db->order_by('id', 'ASC');
return $this->db->get()->result();
}
/**
* One row for sending push: registration token and display name.
*/
public function get_notification_row_by_id($id)
{
$this->db->select('id, fullnama, token');
$this->db->from('pelanggan');
$this->db->where('id', (int) $id);
return $this->db->get()->row();
}
/**
* Truncate for MEDIUMTEXT logging (safety cap).
*/
private function truncate_api_log_value($value, $max_bytes = 1048576)
{
$s = is_string($value) ? $value : (string) $value;
if (strlen($s) > $max_bytes) {
return substr($s, 0, $max_bytes) . "\n...[truncated]";
}
return $s;
}
/**
* Persist raw pelanggan order API + backend snapshot for driver candidates (admin detail).
*/
public function save_transaksi_api_log($id_transaksi, $raw_request, $response_json, $backend_to_driver_json)
{
$id_transaksi = (int) $id_transaksi;
if ($id_transaksi <= 0) {
return;
}
$this->db->where('id', $id_transaksi);
$this->db->update('transaksi', array(
'api_log_pelanggan_request' => $this->truncate_api_log_value($raw_request),
'api_log_pelanggan_response' => $this->truncate_api_log_value($response_json),
'api_log_backend_to_driver' => $this->truncate_api_log_value($backend_to_driver_json),
));
}
/**
* Append driver → backend raw body (e.g. accept_post JSON) for this transaction.
*/
public function append_transaksi_driver_request_log($id_transaksi, $raw_inbound)
{
$id_transaksi = (int) $id_transaksi;
if ($id_transaksi <= 0) {
return;
}
$raw_inbound = $this->truncate_api_log_value($raw_inbound, 262144);
$this->db->select('api_log_driver_request');
$this->db->where('id', $id_transaksi);
$row = $this->db->get('transaksi')->row();
$prev = ($row && isset($row->api_log_driver_request) && $row->api_log_driver_request !== null)
? (string) $row->api_log_driver_request : '';
$stamp = date('c');
$line = '[' . $stamp . "] accept/driver inbound:\n" . $raw_inbound;
$merged = $prev === '' ? $line : $prev . "\n\n" . $line;
$merged = $this->truncate_api_log_value($merged, 1048576);
$this->db->where('id', $id_transaksi);
$this->db->update('transaksi', array('api_log_driver_request' => $merged));
}
}