<?php
if (!defined('__TYPECHO_ROOT_DIR__')) exit;

function Mirai_api_points_purchase($db, $user) {
    if (!$user->hasLogin()) {
        return ['code' => 401, 'msg' => '请先登录', 'need_login' => true];
    }
    $uid = (int)$user->uid;
    $points = (int)($_POST['points'] ?? 0);

    $result = Mirai_pointsProcessPurchase($uid, $points);
    if (!$result['success']) {
        return ['code' => 1, 'msg' => $result['msg']];
    }

    return ['code' => 0, 'data' => $result];
}
