<?php
require_once '_shared.php';
require_once './db.php';

$conn = db();

/* 1) update deposit status */
$stmt = $conn->prepare("UPDATE deposits SET status=?, updated_at=NOW() WHERE orderno=? LIMIT 1");
$stmt->bind_param('is',$data['status'],$data['orderNo']);
$stmt->execute();

/* 2) credit wallet when success */
if ($data['status'] == 1) {
    $stmt = $conn->prepare("INSERT INTO tbl_wallet (userid,amount)
            VALUES (?,?)  ON DUPLICATE KEY UPDATE amount = amount + VALUES(amount)");
    $stmt->bind_param('id',$data['userId'],$data['amount']);
    $stmt->execute();
}
echo 'ok';
