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

function Mirai_api_points_pay($db, $user) {
    if (!$user->hasLogin()) {
        return ['code' => 401, 'msg' => '请先登录', 'need_login' => true];
    }
    $uid = (int)$user->uid;
    $cid = (int)($_POST['cid'] ?? 0);
    if ($cid <= 0) {
        return ['code' => 1, 'msg' => '文章ID无效'];
    }

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

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