<?php
// 确保这些常量已经定义
defined('DB_SERVER') ? null : define('DB_SERVER', 'localhost');
defined('DB_USER') ? null : define('DB_USER', 'root');
defined('DB_PASS') ? null : define('DB_PASS', 'wch123.com');
defined('DB_NAME') ? null : define('DB_NAME', 'sdk');

// 连接数据库
$connection = new mysqli(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

// 检查连接
if ($connection->connect_error) {
    die("连接失败: " . $connection->connect_error);
}

// 查询数据库
// $query = "SELECT ANY_VALUE(order_id) as order_id ,ANY_VALUE(uid) as uid , ANY_VALUE(id) as id FROM game_order where status = 2 group by uid order by id ";
$query = "SELECT  order_id FROM game_order where status = 2 group by uid order by id ";
$result = $connection->query($query);

if ($result) {
    while ($row = $result->fetch_assoc()) {

        $sql = "UPDATE game_order SET is_first = 1 WHERE `order_id` = '{$row['order_id']}' ";

        if (mysqli_query($connection, $sql)) {
            echo "记录更新成功";
        } else {
            echo "更新记录时出错: " . mysqli_error($connection);
        }
    }
} else {
    die("查询失败: " . $connection->error);
}

// 关闭数据库连接
$connection->close();
