70 lines
1.7 KiB
PHP
70 lines
1.7 KiB
PHP
<?php
|
|
|
|
class Customer
|
|
{
|
|
private $pdo;
|
|
|
|
public function __construct($pdo)
|
|
{
|
|
$this->pdo = $pdo;
|
|
}
|
|
|
|
/**
|
|
* Ambil customer berdasarkan token
|
|
*/
|
|
public function getByToken($token)
|
|
{
|
|
$sql = "
|
|
SELECT a.id, a.nama, a.alamat, a.nomor_whatsapp, a.status, a.akun, a.email, a.id_data_server, b.payment_gateway
|
|
FROM pelanggan a
|
|
LEFT JOIN data_server b
|
|
ON a.id_data_server=b.id
|
|
WHERE a.token_id = :token
|
|
LIMIT 1
|
|
";
|
|
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute(['token' => $token]);
|
|
|
|
return $stmt->fetch();
|
|
}
|
|
|
|
/**
|
|
* Validasi 4 digit terakhir WA
|
|
*/
|
|
public function verifyLastPhone($customer_id, $input)
|
|
{
|
|
$sql = "SELECT nomor_whatsapp FROM pelanggan WHERE id = :id LIMIT 1";
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute(['id' => $customer_id]);
|
|
|
|
$data = $stmt->fetch();
|
|
if (!$data) return false;
|
|
|
|
// bersihin format WA
|
|
$wa = preg_replace('/[^0-9]/', '', $data['nomor_whatsapp']);
|
|
$last4 = substr($wa, -4);
|
|
|
|
return $last4 === $input;
|
|
}
|
|
|
|
/**
|
|
* Ambil detail customer
|
|
*/
|
|
public function getDetail($customer_id)
|
|
{
|
|
$sql = "
|
|
SELECT a.id, a.nama, a.alamat, a.nomor_whatsapp, a.status, a.akun, a.email, b.payment_gateway
|
|
FROM pelanggan a
|
|
LEFT JOIN data_server b
|
|
ON a.id_data_server=b.id
|
|
WHERE a.id = :id
|
|
LIMIT 1
|
|
";
|
|
|
|
$stmt = $this->pdo->prepare($sql);
|
|
$stmt->execute(['id' => $customer_id]);
|
|
|
|
return $stmt->fetch();
|
|
}
|
|
} |