{"id":471,"date":"2025-08-20T09:33:07","date_gmt":"2025-08-20T00:33:07","guid":{"rendered":"https:\/\/xn--gckvb8f657lfda.com\/?page_id=471"},"modified":"2025-08-20T10:11:17","modified_gmt":"2025-08-20T01:11:17","slug":"471-2","status":"publish","type":"page","link":"https:\/\/xn--gckvb8f657lfda.com\/?page_id=471","title":{"rendered":""},"content":{"rendered":"\n<h2>1. <code>functions.php<\/code> \u306b\u8ffd\u52a0<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u30eb\u30fc\u30ec\u30c3\u30c8\u62bd\u9078\u7528 API\nadd_action('rest_api_init', function () {\n    register_rest_route('roulette\/v1', '\/spin', array(\n        'methods' =&gt; 'POST',\n        'callback' =&gt; 'roulette_spin',\n    ));\n});\n\nfunction roulette_spin() {\n    $option_key = 'roulette_prizes';\n\n    \/\/ \u521d\u671f\u8a2d\u5b9a\uff08\u6b8b\u308a\u672c\u6570\uff09\n    $default = array(\n        '&#x1f947; 1\u7b49: 3000\u5186OFF\u30af\u30fc\u30dd\u30f3' =&gt; 3,\n        '&#x1f948; 2\u7b49: 2000\u5186OFF\u30af\u30fc\u30dd\u30f3' =&gt; 5,\n        '&#x1f949; 3\u7b49: 1000\u5186OFF\u30af\u30fc\u30dd\u30f3' =&gt; 10,\n        '&#x2b50; 4\u7b49: 500\u5186OFF\u30af\u30fc\u30dd\u30f3'  =&gt; 20,\n        '&#x1f3ab; 5\u7b49: 100\u5186OFF\u30af\u30fc\u30dd\u30f3'  =&gt; 9999,\n    );\n\n    \/\/ DB\u304b\u3089\u53d6\u5f97\u3001\u672a\u767b\u9332\u306a\u3089\u30c7\u30d5\u30a9\u30eb\u30c8\u3092\u4fdd\u5b58\n    $pool = get_option($option_key, null);\n    if (!$pool) {\n        update_option($option_key, $default);\n        $pool = $default;\n    }\n\n    $total = array_sum($pool);\n    if ($total &lt;= 0) {\n        return array('message' =&gt; '\u62bd\u9078\u7d42\u4e86');\n    }\n\n    $rand = rand(1, $total);\n    $sum = 0;\n    foreach ($pool as $prize =&gt; $count) {\n        $sum += $count;\n        if ($rand &lt;= $sum) {\n            $result = $prize;\n            $pool&#91;$prize] -= 1;\n            update_option($option_key, $pool);\n            return array(\n                'prize' =&gt; $result,\n                'remaining' =&gt; $pool\n            );\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2>2. \u6295\u7a3f\u3084\u56fa\u5b9a\u30da\u30fc\u30b8\u306b\u57cb\u3081\u8fbc\u3080 HTML + JS<\/h2>\n\n\n\n<p>&#8220;`html \u30eb\u30fc\u30ec\u30c3\u30c8\u3092\u56de\u3059 &#x1f3a1;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1. functions.php \u306b\u8ffd\u52a0 2. \u6295\u7a3f\u3084\u56fa\u5b9a\u30da\u30fc\u30b8\u306b\u57cb\u3081\u8fbc\u3080 HTML + JS &#8220;`html \u30eb\u30fc\u30ec\u30c3\u30c8\u3092\u56de\u3059 &#x1f3a1;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"https:\/\/xn--gckvb8f657lfda.com\/index.php?rest_route=\/wp\/v2\/pages\/471"}],"collection":[{"href":"https:\/\/xn--gckvb8f657lfda.com\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/xn--gckvb8f657lfda.com\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/xn--gckvb8f657lfda.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xn--gckvb8f657lfda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=471"}],"version-history":[{"count":1,"href":"https:\/\/xn--gckvb8f657lfda.com\/index.php?rest_route=\/wp\/v2\/pages\/471\/revisions"}],"predecessor-version":[{"id":472,"href":"https:\/\/xn--gckvb8f657lfda.com\/index.php?rest_route=\/wp\/v2\/pages\/471\/revisions\/472"}],"wp:attachment":[{"href":"https:\/\/xn--gckvb8f657lfda.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=471"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}