| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>API 服务充值 — BrainHack</title>
- <script src="https://cdn.jsdelivr.net/npm/qrcode@1.5.4/build/qrcode.min.js"></script>
- <script>
- // Fallback: if QRCode lib not loaded, provide a shim using img
- if (typeof QRCode === 'undefined') {
- console.warn('QRCode lib not loaded, will use img fallback');
- window.QRCode = null;
- }
- </script>
- <style>
- /* ═══════════════════════════════════════════════════
- BrainHack Dark Neumorphic Payment Page
- Color Palette: #0A0A0A bg, #00D4FF neon, #00B6C0 tech
- ═══════════════════════════════════════════════════ */
- :root {
- --bg: #0A0A0A;
- --surface: #141414;
- --surface-alt: #1A1A1A;
- --neon: #00D4FF;
- --neon-dim: #00B6C0;
- --neon-glow: rgba(0, 212, 255, 0.15);
- --neon-glow-s: rgba(0, 212, 255, 0.25);
- --text: #E0E0E0;
- --text-dim: #888;
- --text-bright: #FFFFFF;
- --success: #00FF88;
- --success-dim: #059660;
- --danger: #FF4D6A;
- --shadow-dark: rgba(0, 0, 0, 0.7);
- --shadow-light: rgba(255, 255, 255, 0.04);
- --radius: 12px;
- }
- * { margin: 0; padding: 0; box-sizing: border-box; }
- body {
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
- background: var(--bg);
- color: var(--text);
- min-height: 100vh;
- display: flex;
- flex-direction: column;
- align-items: center;
- overflow-x: hidden;
- }
- /* ─── Background Grid Effect ─── */
- body::before {
- content: '';
- position: fixed;
- top: 0; left: 0; right: 0; bottom: 0;
- background-image:
- radial-gradient(ellipse 600px 400px at 50% 0%, rgba(0,212,255,0.06) 0%, transparent 70%),
- linear-gradient(rgba(0,212,255,0.03) 1px, transparent 1px),
- linear-gradient(90deg, rgba(0,212,255,0.03) 1px, transparent 1px);
- background-size: 100% 100%, 40px 40px, 40px 40px;
- pointer-events: none;
- z-index: 0;
- }
- /* ─── Neumorphic Mixins (Dark Mode) ─── */
- .neu-raised {
- background: var(--surface);
- background-image: linear-gradient(145deg, rgba(255,255,255,0.03), rgba(0,0,0,0.2));
- border-radius: var(--radius);
- box-shadow:
- 4px 4px 8px var(--shadow-dark),
- -4px -4px 8px var(--shadow-light);
- transition: box-shadow 0.25s ease, background 0.25s ease, transform 0.15s ease;
- }
- .neu-raised:hover {
- box-shadow:
- 2px 2px 5px var(--shadow-dark),
- -2px -2px 5px var(--shadow-light);
- }
- .neu-pressed {
- box-shadow:
- inset 3px 3px 6px var(--shadow-dark),
- inset -3px -3px 6px var(--shadow-light);
- background-image: linear-gradient(145deg, rgba(0,0,0,0.25), rgba(255,255,255,0.02));
- }
- .neu-groove {
- background: rgba(10,10,10,0.6);
- box-shadow:
- inset 2px 2px 4px rgba(0,0,0,0.5),
- inset -2px -2px 4px rgba(255,255,255,0.03);
- border-radius: var(--radius);
- }
- /* ─── Header ─── */
- .page-header {
- position: relative;
- z-index: 1;
- width: 100%;
- padding: 20px 32px;
- display: flex;
- align-items: center;
- gap: 12px;
- border-bottom: 1px solid rgba(0,212,255,0.1);
- }
- .page-header .logo {
- font-size: 20px;
- font-weight: 700;
- letter-spacing: 2px;
- color: var(--text-bright);
- }
- .page-header .logo span { color: var(--neon); }
- .page-header .subtitle {
- font-size: 14px;
- color: var(--text-dim);
- margin-left: 8px;
- }
- /* ─── Main Container ─── */
- .main-container {
- position: relative;
- z-index: 1;
- width: 100%;
- max-width: 720px;
- padding: 32px 24px;
- flex: 1;
- }
- /* ─── API Info Card ─── */
- .api-info-card {
- padding: 28px;
- margin-bottom: 24px;
- }
- .api-info-card .api-title {
- font-size: 22px;
- font-weight: 700;
- color: var(--text-bright);
- margin-bottom: 8px;
- }
- .api-info-card .api-title .badge {
- display: inline-block;
- font-size: 11px;
- font-weight: 500;
- padding: 2px 8px;
- border: 1px solid var(--neon);
- color: var(--neon);
- border-radius: 4px;
- margin-left: 10px;
- vertical-align: middle;
- }
- .api-info-card .api-desc {
- font-size: 14px;
- color: var(--text-dim);
- line-height: 1.6;
- }
- .api-info-card .api-stats {
- display: flex;
- gap: 24px;
- margin-top: 16px;
- padding-top: 16px;
- border-top: 1px solid rgba(255,255,255,0.06);
- }
- .api-info-card .stat-item {
- display: flex;
- flex-direction: column;
- }
- .api-info-card .stat-label {
- font-size: 12px;
- color: var(--text-dim);
- }
- .api-info-card .stat-value {
- font-size: 18px;
- font-weight: 600;
- color: var(--neon);
- }
- /* ─── Tier Selection ─── */
- .section-title {
- font-size: 14px;
- color: var(--text-dim);
- margin-bottom: 12px;
- letter-spacing: 1px;
- }
- .tier-grid {
- display: grid;
- grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
- gap: 14px;
- margin-bottom: 28px;
- }
- .tier-card {
- padding: 18px;
- cursor: pointer;
- border: 1px solid transparent;
- position: relative;
- overflow: hidden;
- }
- .tier-card::after {
- content: '';
- position: absolute;
- top: 0; left: 0; right: 0;
- height: 2px;
- background: transparent;
- transition: background 0.3s ease;
- }
- .tier-card:hover {
- transform: translateY(-1px);
- }
- .tier-card.active {
- border-color: var(--neon);
- box-shadow:
- 4px 4px 8px var(--shadow-dark),
- -4px -4px 8px var(--shadow-light),
- 0 0 15px var(--neon-glow);
- }
- .tier-card.active::after {
- background: linear-gradient(90deg, var(--neon), var(--neon-dim));
- }
- .tier-price {
- font-size: 28px;
- font-weight: 700;
- color: var(--neon);
- }
- .tier-price .symbol { font-size: 16px; }
- .tier-count {
- font-size: 14px;
- color: var(--text);
- margin-top: 4px;
- }
- .tier-unit-price {
- display: inline-block;
- font-size: 11px;
- color: var(--text-dim);
- background: rgba(255,255,255,0.05);
- padding: 2px 6px;
- border-radius: 4px;
- margin-top: 8px;
- }
- /* ─── Summary ─── */
- .summary-bar {
- padding: 20px 24px;
- margin-bottom: 24px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- }
- .summary-bar .label {
- font-size: 14px;
- color: var(--text-dim);
- }
- .summary-bar .total {
- font-size: 28px;
- font-weight: 700;
- color: var(--neon);
- }
- .summary-bar .validity {
- font-size: 12px;
- color: var(--text-dim);
- margin-top: 2px;
- }
- /* ─── Pay Button (Neumorphic) ─── */
- .pay-btn {
- display: block;
- width: 100%;
- padding: 16px;
- border: none;
- cursor: pointer;
- font-size: 16px;
- font-weight: 600;
- letter-spacing: 2px;
- color: var(--text-bright);
- background: var(--surface);
- background-image: linear-gradient(145deg, rgba(0,212,255,0.15), rgba(0,0,0,0.3));
- border-radius: var(--radius);
- box-shadow:
- 5px 5px 10px var(--shadow-dark),
- -5px -5px 10px var(--shadow-light),
- 0 0 20px var(--neon-glow);
- transition: all 0.25s ease;
- position: relative;
- overflow: hidden;
- }
- .pay-btn::before {
- content: '';
- position: absolute;
- top: 0; left: 0; right: 0;
- height: 1px;
- background: linear-gradient(90deg, transparent, var(--neon), transparent);
- }
- .pay-btn:hover {
- box-shadow:
- 3px 3px 6px var(--shadow-dark),
- -3px -3px 6px var(--shadow-light),
- 0 0 30px var(--neon-glow-s);
- transform: translateY(-1px);
- }
- .pay-btn:active {
- box-shadow:
- inset 3px 3px 6px var(--shadow-dark),
- inset -3px -3px 6px var(--shadow-light);
- background-image: linear-gradient(145deg, rgba(0,0,0,0.3), rgba(0,212,255,0.1));
- transform: translateY(0);
- }
- .pay-btn:disabled {
- opacity: 0.5;
- cursor: not-allowed;
- box-shadow:
- 2px 2px 4px var(--shadow-dark),
- -2px -2px 4px var(--shadow-light);
- }
- .pay-btn .btn-icon { margin-right: 8px; }
- /* ─── QR Modal ─── */
- .modal-overlay {
- display: none;
- position: fixed;
- top: 0; left: 0; right: 0; bottom: 0;
- background: rgba(0,0,0,0.85);
- z-index: 100;
- align-items: center;
- justify-content: center;
- }
- .modal-overlay.show { display: flex; }
- .modal-box {
- width: 380px;
- max-width: 90vw;
- padding: 32px;
- text-align: center;
- position: relative;
- border: 1px solid rgba(0,212,255,0.15);
- }
- .modal-box .modal-close {
- position: absolute;
- top: 12px;
- right: 16px;
- background: none;
- border: none;
- color: var(--text-dim);
- font-size: 20px;
- cursor: pointer;
- transition: color 0.2s;
- }
- .modal-box .modal-close:hover { color: var(--text-bright); }
- .modal-box .modal-title {
- font-size: 18px;
- font-weight: 600;
- color: var(--text-bright);
- margin-bottom: 6px;
- }
- .modal-box .modal-amount {
- font-size: 32px;
- font-weight: 700;
- color: var(--neon);
- margin: 8px 0;
- }
- .modal-box .modal-amount .symbol { font-size: 18px; }
- .qr-wrapper {
- display: inline-block;
- padding: 16px;
- background: #fff;
- border-radius: 8px;
- margin: 16px 0;
- box-shadow: 0 0 20px var(--neon-glow);
- }
- .qr-wrapper canvas { display: block; }
- .modal-box .scan-hint {
- font-size: 13px;
- color: var(--text-dim);
- margin-top: 8px;
- }
- .modal-box .scan-hint svg {
- vertical-align: middle;
- margin-right: 4px;
- }
- .polling-status {
- font-size: 12px;
- color: var(--text-dim);
- margin-top: 12px;
- display: flex;
- align-items: center;
- justify-content: center;
- gap: 6px;
- }
- .polling-dot {
- display: inline-block;
- width: 6px; height: 6px;
- background: var(--neon);
- border-radius: 50%;
- animation: pulse 1.5s infinite;
- }
- @keyframes pulse {
- 0%, 100% { opacity: 0.3; }
- 50% { opacity: 1; }
- }
- /* ─── Success Screen ─── */
- .success-screen {
- display: none;
- text-align: center;
- padding: 48px 24px;
- }
- .success-screen.show { display: block; }
- .success-icon {
- width: 80px; height: 80px;
- margin: 0 auto 20px;
- border-radius: 50%;
- background: var(--surface);
- box-shadow:
- 5px 5px 10px var(--shadow-dark),
- -5px -5px 10px var(--shadow-light),
- 0 0 20px rgba(0,255,136,0.15);
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .success-icon svg {
- width: 40px; height: 40px;
- stroke: var(--success);
- }
- .success-screen .success-title {
- font-size: 24px;
- font-weight: 700;
- color: var(--text-bright);
- margin-bottom: 8px;
- }
- .success-screen .success-detail {
- font-size: 14px;
- color: var(--text-dim);
- line-height: 1.8;
- margin-bottom: 28px;
- }
- .success-screen .back-btn {
- display: inline-block;
- padding: 12px 40px;
- border: none;
- cursor: pointer;
- font-size: 14px;
- font-weight: 600;
- color: var(--text-bright);
- background: var(--surface);
- background-image: linear-gradient(145deg, rgba(0,255,136,0.12), rgba(0,0,0,0.3));
- border-radius: var(--radius);
- box-shadow:
- 4px 4px 8px var(--shadow-dark),
- -4px -4px 8px var(--shadow-light),
- 0 0 15px rgba(0,255,136,0.1);
- transition: all 0.25s ease;
- }
- .success-screen .back-btn:hover {
- transform: translateY(-1px);
- box-shadow:
- 3px 3px 6px var(--shadow-dark),
- -3px -3px 6px var(--shadow-light),
- 0 0 25px rgba(0,255,136,0.15);
- }
- .success-screen .back-btn:active {
- box-shadow:
- inset 3px 3px 6px var(--shadow-dark),
- inset -3px -3px 6px var(--shadow-light);
- transform: translateY(0);
- }
- /* ─── Loading Skeleton ─── */
- .skeleton {
- background: linear-gradient(90deg, var(--surface) 25%, var(--surface-alt) 50%, var(--surface) 75%);
- background-size: 200% 100%;
- animation: shimmer 1.5s infinite;
- border-radius: 6px;
- }
- @keyframes shimmer {
- 0% { background-position: 200% 0; }
- 100% { background-position: -200% 0; }
- }
- /* ─── Error State ─── */
- .error-bar {
- display: none;
- padding: 12px 16px;
- background: rgba(255,77,106,0.1);
- border: 1px solid rgba(255,77,106,0.3);
- border-radius: 8px;
- color: var(--danger);
- font-size: 13px;
- margin-bottom: 16px;
- }
- .error-bar.show { display: block; }
- /* ─── Order History ─── */
- .order-history {
- margin-top: 36px;
- padding-top: 28px;
- border-top: 1px solid rgba(0,212,255,0.08);
- }
- .order-history .section-header {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-bottom: 16px;
- }
- .order-history .section-header .section-title {
- margin-bottom: 0;
- }
- .order-history .refresh-btn {
- background: none;
- border: 1px solid rgba(0,212,255,0.2);
- color: var(--neon-dim);
- font-size: 12px;
- padding: 4px 12px;
- border-radius: 6px;
- cursor: pointer;
- transition: all 0.2s;
- }
- .order-history .refresh-btn:hover {
- border-color: var(--neon);
- color: var(--neon);
- background: var(--neon-glow);
- }
- .order-history .refresh-btn:disabled {
- opacity: 0.4;
- cursor: not-allowed;
- }
- .order-table {
- width: 100%;
- border-collapse: separate;
- border-spacing: 0;
- font-size: 13px;
- }
- .order-table thead th {
- text-align: left;
- padding: 10px 12px;
- color: var(--text-dim);
- font-weight: 500;
- font-size: 12px;
- letter-spacing: 0.5px;
- border-bottom: 1px solid rgba(255,255,255,0.06);
- white-space: nowrap;
- }
- .order-table tbody tr {
- transition: background 0.15s;
- }
- .order-table tbody tr:hover {
- background: rgba(0,212,255,0.03);
- }
- .order-table tbody td {
- padding: 12px 12px;
- border-bottom: 1px solid rgba(255,255,255,0.03);
- color: var(--text);
- vertical-align: middle;
- }
- .order-table tbody tr:last-child td {
- border-bottom: none;
- }
- .order-table .col-time {
- color: var(--text-dim);
- font-size: 12px;
- white-space: nowrap;
- }
- .order-table .col-amount {
- font-weight: 600;
- color: var(--neon);
- white-space: nowrap;
- }
- .order-table .col-count {
- white-space: nowrap;
- }
- .order-status {
- display: inline-block;
- font-size: 11px;
- font-weight: 500;
- padding: 2px 8px;
- border-radius: 4px;
- white-space: nowrap;
- }
- .order-status.status-paid {
- color: var(--success);
- background: rgba(0,255,136,0.08);
- border: 1px solid rgba(0,255,136,0.2);
- }
- .order-status.status-pending {
- color: #FFB800;
- background: rgba(255,184,0,0.08);
- border: 1px solid rgba(255,184,0,0.2);
- }
- .order-status.status-failed {
- color: var(--danger);
- background: rgba(255,77,106,0.08);
- border: 1px solid rgba(255,77,106,0.2);
- }
- .order-status.status-recharged {
- color: var(--neon);
- background: var(--neon-glow);
- border: 1px solid rgba(0,212,255,0.2);
- }
- .order-empty {
- text-align: center;
- padding: 32px 16px;
- color: var(--text-dim);
- font-size: 13px;
- }
- .order-empty svg {
- display: block;
- margin: 0 auto 12px;
- opacity: 0.3;
- }
- .order-loading {
- text-align: center;
- padding: 24px;
- color: var(--text-dim);
- font-size: 13px;
- }
- .order-loading .polling-dot {
- margin-right: 6px;
- }
- .order-error {
- text-align: center;
- padding: 16px;
- color: var(--text-dim);
- font-size: 12px;
- }
- .order-more-btn {
- display: block;
- width: 100%;
- padding: 10px;
- margin-top: 8px;
- background: none;
- border: 1px solid rgba(255,255,255,0.06);
- border-radius: 8px;
- color: var(--text-dim);
- font-size: 12px;
- cursor: pointer;
- transition: all 0.2s;
- }
- .order-more-btn:hover {
- border-color: rgba(0,212,255,0.2);
- color: var(--neon-dim);
- background: rgba(0,212,255,0.03);
- }
- /* ─── Responsive ─── */
- @media (max-width: 480px) {
- .main-container { padding: 20px 16px; }
- .api-info-card { padding: 20px; }
- .tier-grid { grid-template-columns: 1fr; }
- .modal-box { padding: 24px 20px; }
- .order-table { font-size: 12px; }
- .order-table thead th,
- .order-table tbody td { padding: 8px 6px; }
- }
- </style>
- </head>
- <body>
- <!-- Header -->
- <div class="page-header">
- <div class="logo">BRAIN<span>HACK</span></div>
- <div class="subtitle">API 服务充值</div>
- </div>
- <!-- Main -->
- <div class="main-container" id="mainContent">
- <!-- API Info Card -->
- <div class="api-info-card neu-raised" id="apiInfoCard">
- <div class="api-title" id="apiTitle">
- <span class="skeleton" style="display:inline-block;width:200px;height:24px;"> </span>
- </div>
- <div class="api-desc" id="apiDesc">
- <span class="skeleton" style="display:inline-block;width:100%;height:16px;margin-top:8px;"> </span>
- </div>
- <div class="api-stats" id="apiStats" style="display:none;">
- <div class="stat-item">
- <span class="stat-label">当前余额</span>
- <span class="stat-value" id="statCount">—</span>
- </div>
- <div class="stat-item">
- <span class="stat-label">服务状态</span>
- <span class="stat-value" id="statStatus">—</span>
- </div>
- </div>
- </div>
- <!-- Error -->
- <div class="error-bar" id="errorBar"></div>
- <!-- Tier Selection -->
- <div class="section-title">选择套餐</div>
- <div class="tier-grid" id="tierGrid">
- <div class="tier-card neu-raised skeleton" style="height:100px;"></div>
- <div class="tier-card neu-raised skeleton" style="height:100px;"></div>
- <div class="tier-card neu-raised skeleton" style="height:100px;"></div>
- </div>
- <!-- Summary -->
- <div class="summary-bar neu-groove" id="summaryBar" style="display:none;">
- <div>
- <div class="label">套餐配额</div>
- <div id="summaryCount" style="font-size:16px;font-weight:600;color:var(--text-bright);margin-top:2px;">—</div>
- <div class="validity">有效期 730 天(自购买之日起)</div>
- </div>
- <div style="text-align:right;">
- <div class="label">应付金额</div>
- <div class="total"><span class="symbol">¥</span><span id="summaryPrice">0</span></div>
- </div>
- </div>
- <!-- Pay Button -->
- <button class="pay-btn" id="payBtn" disabled>
- <span class="btn-icon">💳</span> 微信支付
- </button>
- <!-- Order History -->
- <div class="order-history" id="orderHistory" style="display:none;">
- <div class="section-header">
- <div class="section-title">历史订单</div>
- <button class="refresh-btn" id="refreshOrdersBtn" onclick="loadOrderHistory()">刷新</button>
- </div>
- <div class="neu-groove" style="padding:2px 16px;overflow-x:auto;">
- <div id="orderListBody">
- <div class="order-loading"><span class="polling-dot"></span> 加载中...</div>
- </div>
- </div>
- </div>
- <!-- Success Screen -->
- <div class="success-screen" id="successScreen">
- <div class="success-icon">
- <svg viewBox="0 0 24 24" fill="none" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round">
- <polyline points="20 6 9 17 4 12"></polyline>
- </svg>
- </div>
- <div class="success-title">充值成功</div>
- <div class="success-detail" id="successDetail"></div>
- <button class="back-btn" onclick="handleDone()">完成</button>
- </div>
- </div>
- <!-- QR Modal -->
- <div class="modal-overlay" id="qrModal">
- <div class="modal-box neu-raised">
- <button class="modal-close" onclick="cancelPayment()">×</button>
- <div class="modal-title">微信扫码支付</div>
- <div class="modal-amount"><span class="symbol">¥</span><span id="modalPrice">0</span></div>
- <div class="qr-wrapper" id="qrWrapper">
- <canvas id="qrCanvas"></canvas>
- </div>
- <div class="scan-hint">
- <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"></path><circle cx="12" cy="13" r="4"></circle></svg>
- 打开微信扫一扫
- </div>
- <div class="polling-status" id="pollingStatus">
- <span class="polling-dot"></span> 等待支付中...
- </div>
- </div>
- </div>
- <script>
- // ═══════════════════════════════════════════════════
- // APIG Payment Logic
- // ═══════════════════════════════════════════════════
- const API_BASE = 'https://server.fmode.cn';
- const PARSE_BASE = API_BASE + '/parse/functions';
- const PAY_COMPANY = '1AiWpTEDH9';
- const APP_ID = 'ncloudmaster';
- // 充值云函数ID — 微信支付回调自动执行 apigRechargeOnPay
- // 部署云函数后将 objectId 填入此处,或通过 URL 参数 fun_id 传入
- const DEFAULT_FUN_ID = 'HOkkX72PMF';
- // URL params
- const params = new URLSearchParams(window.location.search);
- let authId = params.get('authid') || '';
- const userId = params.get('user') || params.get('userid') || '';
- const apigId = params.get('apigid') || '';
- const funId = params.get('fun_id') || DEFAULT_FUN_ID;
- let apig = null;
- let selectedIndex = 0;
- let order = null;
- let tradeNo = '';
- let nonceStr = '';
- let pollTimer = null;
- // ─── Init ───
- document.addEventListener('DOMContentLoaded', () => {
- if (!authId && !(userId && apigId)) {
- showError('缺少参数。请传入 authid,或同时传入 user 和 apigid。');
- return;
- }
- // Show loading state
- const titleEl = document.getElementById('apiTitle');
- if (titleEl) titleEl.textContent = '加载中...';
- loadApig();
- });
- // ─── Load APIG Info ───
- async function loadApig() {
- try {
- // 如果没有 authId 但有 user+apigid,先查询/创建 APIGAuth
- if (!authId && userId && apigId) {
- console.log('[INIT] 无 authId,通过 user+apigid 查询 APIGAuth...');
- authId = await resolveAuthId(userId, apigId);
- if (!authId) {
- showError('无法获取或创建计费账套,请联系管理员。');
- return;
- }
- console.log('[INIT] 获取到 authId:', authId);
- }
- // 1. Try getApig REST endpoint (works when authId is an APIGAuth objectId)
- const resp = await postJSON(API_BASE + '/api/apig/getApig', { authid: authId });
- if (resp.code === 200 && resp.data) {
- apig = resp.data;
- applyTestTier();
- renderApigInfo();
- renderTiers();
- loadOrderHistory();
- return;
- }
- // 2. Fallback: use cloud function to query APIG by objectId
- console.log('getApig returned no data, trying cloud function...');
- const cfFuncName = params.get('cfName') || 'getApigInfo';
- const cfResp = await parseCloudCall(cfFuncName, {
- apigId: authId
- }).catch(e => { console.warn('cloud function error:', e); return null; });
- console.log('Cloud function response:', cfResp);
- if (cfResp && cfResp.result) {
- const cfData = cfResp.result.data || cfResp.result;
- if (cfData && cfData.objectId) {
- apig = cfData;
- applyTestTier();
- renderApigInfo();
- renderTiers();
- loadOrderHistory();
- return;
- }
- }
- showError('无法加载接口信息。请确认参数正确。');
- } catch (e) {
- showError('网络错误: ' + e.message);
- }
- }
- // ─── 通过 user+apigid 查询或创建 APIGAuth ───
- async function resolveAuthId(user, apig) {
- // 1. 查询是否已有 APIGAuth(user 对应 company,api 对应 APIG)
- try {
- const query = {
- _method: 'GET',
- where: JSON.stringify({
- api: { __type: 'Pointer', className: 'APIG', objectId: apig },
- company: { __type: 'Pointer', className: 'Company', objectId: user }
- }),
- limit: 1
- };
- const resp = await fetch(API_BASE + '/parse/classes/APIGAuth?' + new URLSearchParams(query), {
- headers: { 'X-Parse-Application-Id': APP_ID }
- });
- const data = await resp.json();
- if (data.results && data.results.length > 0) {
- console.log('[resolveAuthId] 找到已有 APIGAuth:', data.results[0].objectId);
- return data.results[0].objectId;
- }
- } catch (e) {
- console.warn('[resolveAuthId] 查询失败:', e.message);
- }
- // 2. 不存在则创建新的 APIGAuth
- try {
- console.log('[resolveAuthId] 未找到 APIGAuth,创建新记录...');
- const createResp = await fetch(API_BASE + '/parse/classes/APIGAuth', {
- method: 'POST',
- headers: {
- 'X-Parse-Application-Id': APP_ID,
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify({
- api: { __type: 'Pointer', className: 'APIG', objectId: apig },
- company: { __type: 'Pointer', className: 'Company', objectId: user },
- count: 0,
- used: 0
- })
- });
- const created = await createResp.json();
- if (created.objectId) {
- console.log('[resolveAuthId] 创建成功:', created.objectId);
- return created.objectId;
- }
- console.error('[resolveAuthId] 创建失败:', JSON.stringify(created));
- } catch (e) {
- console.error('[resolveAuthId] 创建异常:', e.message);
- }
- return null;
- }
- function applyTestTier() {
- if (params.get('test') === '1' && apig.priceStep) {
- apig.priceStep.unshift({ count: 1, price: 0.01 });
- }
- }
- function renderApigInfo() {
- const titleEl = document.getElementById('apiTitle');
- titleEl.innerHTML = apig.title + '<span class="badge">HTTPS</span>';
- const descEl = document.getElementById('apiDesc');
- descEl.textContent = apig.content || '专业API数据服务';
- const statsEl = document.getElementById('apiStats');
- statsEl.style.display = 'flex';
- document.getElementById('statCount').textContent =
- (apig.count != null ? apig.count + ' 次' : '—');
- document.getElementById('statStatus').textContent = '正常';
- document.getElementById('statStatus').style.color = 'var(--success)';
- }
- function renderTiers() {
- const grid = document.getElementById('tierGrid');
- if (!apig.priceStep || apig.priceStep.length === 0) {
- grid.innerHTML = '<div style="color:var(--text-dim);">暂无可用套餐</div>';
- return;
- }
- grid.innerHTML = '';
- apig.priceStep.forEach((tier, i) => {
- const card = document.createElement('div');
- card.className = 'tier-card neu-raised' + (i === 0 ? ' active' : '');
- const unitLabel = (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ') ? 'token' : '次';
- const unitPrice = (tier.price / tier.count).toFixed(3);
- card.innerHTML = `
- <div class="tier-price"><span class="symbol">¥</span>${tier.price}</div>
- <div class="tier-count">含 ${tier.count} ${unitLabel}</div>
- <div class="tier-unit-price">≈ ${unitPrice} 元/${unitLabel}</div>
- `;
- card.addEventListener('click', () => selectTier(i));
- grid.appendChild(card);
- });
- selectTier(0);
- document.getElementById('payBtn').disabled = false;
- document.getElementById('payBtn').addEventListener('click', startPayment);
- }
- function selectTier(idx) {
- selectedIndex = idx;
- document.querySelectorAll('.tier-card').forEach((el, i) => {
- el.classList.toggle('active', i === idx);
- if (i === idx) {
- el.classList.remove('neu-raised');
- el.classList.add('neu-pressed');
- } else {
- el.classList.remove('neu-pressed');
- el.classList.add('neu-raised');
- }
- });
- const tier = apig.priceStep[idx];
- const unitLabel = (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ') ? 'token' : '次';
- document.getElementById('summaryBar').style.display = 'flex';
- document.getElementById('summaryCount').textContent = tier.count + ' ' + unitLabel;
- document.getElementById('summaryPrice').textContent = tier.price;
- }
- // ─── Payment Flow ───
- async function startPayment() {
- const btn = document.getElementById('payBtn');
- btn.disabled = true;
- btn.textContent = '正在生成支付码...';
- hideError();
- try {
- // 1. Generate trade number
- const now = new Date();
- tradeNo = 'C' + (userId || 'U') +
- now.getFullYear() +
- String(now.getMonth() + 1).padStart(2, '0') +
- String(now.getDate()).padStart(2, '0') +
- String(now.getHours()).padStart(2, '0') +
- String(now.getMinutes()).padStart(2, '0') +
- String(now.getSeconds()).padStart(2, '0') +
- now.getMilliseconds();
- const tier = apig.priceStep[selectedIndex];
- // 2. Create order FIRST (so backend callback can find it)
- console.log('[PAY] Creating order...', { tradeNo, tier: tier.price, funId });
- await createOrder(tier);
- console.log('[PAY] Order created, order=', order);
- // 3. Call pay_code2 to get QR URL (with fun_id for auto-recharge)
- const payParams = {
- _ApplicationId: APP_ID,
- company: PAY_COMPANY,
- out_trade_no: tradeNo,
- total_fee: +tier.price,
- body: apig.title + ' 接口充值'
- };
- // 传入 fun_id: 微信支付成功后回调自动执行充值云函数
- if (funId) {
- payParams.fun_id = funId;
- }
- console.log('[PAY] Calling pay_code2 with params:', JSON.stringify(payParams));
- let payResp = null;
- try {
- const payController = new AbortController();
- const payTimeout = setTimeout(() => payController.abort(), 15000);
- const rawResp = await fetch(PARSE_BASE + '/pay_code2', {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(payParams),
- signal: payController.signal
- });
- clearTimeout(payTimeout);
- payResp = await rawResp.json();
- console.log('[PAY] pay_code2 response:', JSON.stringify(payResp));
- } catch (fetchErr) {
- console.error('[PAY] pay_code2 fetch error:', fetchErr.message);
- // 如果带 fun_id 请求失败,尝试不带 fun_id 重试
- if (payParams.fun_id) {
- console.log('[PAY] Retrying pay_code2 WITHOUT fun_id...');
- delete payParams.fun_id;
- payResp = await postJSON(PARSE_BASE + '/pay_code2', payParams);
- console.log('[PAY] pay_code2 retry response:', JSON.stringify(payResp));
- } else {
- throw fetchErr;
- }
- }
- if (!payResp || !payResp.result || !payResp.result.code_url) {
- throw new Error('获取支付码失败: ' + JSON.stringify(payResp));
- }
- const codeUrl = payResp.result.code_url[0];
- nonceStr = payResp.result.nonce_str;
- console.log('[PAY] QR code URL:', codeUrl);
- // 4. Show QR modal
- document.getElementById('modalPrice').textContent = tier.price;
- document.getElementById('qrModal').classList.add('show');
- document.getElementById('pollingStatus').innerHTML =
- '<span class="polling-dot"></span> 等待支付中...';
- // Generate QR code
- await renderQR(codeUrl);
- // 5. Start polling
- startPolling();
- } catch (e) {
- showError('支付发起失败: ' + e.message);
- } finally {
- btn.disabled = false;
- btn.innerHTML = '<span class="btn-icon">💳</span> 微信支付';
- }
- }
- async function createOrder(tier) {
- try {
- const body = {
- type: 'wxpay',
- authid: authId,
- params: {
- out_trade_no: tradeNo,
- total_fee: +tier.price,
- body: apig.title + ' 接口充值'
- },
- apigid: apig.objectId,
- oldCount: apig.count || 0,
- count: tier.count
- };
- // Server requires fcompany or user; fallback to authId if userId is empty
- body.user = userId || authId;
- body.fcompany = userId || authId;
- const resp = await postJSON(API_BASE + '/api/apig/created-apigorder', body);
- if (resp.code === 200 && resp.data) {
- order = resp.data;
- console.log('Order created:', order);
- }
- } catch (e) {
- console.warn('Order creation error (non-blocking):', e.message);
- }
- }
- function startPolling() {
- if (pollTimer) clearInterval(pollTimer);
- pollTimer = setInterval(async () => {
- try {
- const resp = await postJSON(PARSE_BASE + '/order_status2', {
- _ApplicationId: APP_ID,
- out_trade_no: tradeNo,
- nonce_str: nonceStr,
- company: PAY_COMPANY
- });
- if (resp.result && resp.result.status && resp.result.status[0] === 'SUCCESS') {
- clearInterval(pollTimer);
- pollTimer = null;
- document.getElementById('pollingStatus').innerHTML =
- '<span style="color:var(--success);">✓ 支付成功,正在充值...</span>';
- await doRecharge();
- }
- } catch (e) {
- console.warn('Poll error:', e.message);
- }
- }, 3000);
- }
- async function doRecharge() {
- showSuccess();
- const oldCount = apig.count || 0;
- const tier = apig.priceStep[selectedIndex];
- console.log('═══ [RECHARGE] 开始 ═══ oldCount:', oldCount, 'addCount:', tier.count, 'fun_id:', funId);
- // 步骤1: 等待后端微信回调自动执行云函数(fun_id 机制)
- // 轮询 8 次(间隔 3 秒,共 24 秒)— 微信回调通常 5~15 秒到达
- for (let i = 1; i <= 8; i++) {
- console.log('[RECHARGE] 步骤1: 等待后端回调... 第' + i + '/8次 (3秒后)');
- await new Promise(r => setTimeout(r, 3000));
- await refreshBalance();
- if (apig.count > oldCount) {
- console.log('[RECHARGE] ✅ 后端回调充值成功! 余额:', oldCount, '→', apig.count);
- console.log('═══ [RECHARGE] 结束 ═══ 最终余额:', apig.count);
- loadOrderHistory();
- return;
- }
- }
- // 步骤2: 后端回调未生效,调用 saveRecharge 保底
- console.log('[RECHARGE] 步骤2: 后端回调未生效,调用 saveRecharge 保底...');
- try {
- const rechargeBody = {
- user: userId || authId,
- authComp: userId || authId,
- authid: authId,
- apigid: apig.objectId,
- oldCount: oldCount,
- count: tier.count,
- orderid: order ? order.objectId : ''
- };
- console.log('[RECHARGE] saveRecharge 参数:', JSON.stringify(rechargeBody));
- const rechargeResp = await postJSON(API_BASE + '/api/apig/saveRecharge', rechargeBody);
- console.log('[RECHARGE] saveRecharge 响应:', JSON.stringify(rechargeResp));
- } catch (e) {
- console.warn('[RECHARGE] saveRecharge 失败:', e.message);
- }
- // 步骤3: 再轮询 3 次确认余额(saveRecharge 或延迟回调)
- for (let i = 1; i <= 3; i++) {
- await new Promise(r => setTimeout(r, 2000));
- await refreshBalance();
- if (apig.count > oldCount) {
- console.log('[RECHARGE] ✅ saveRecharge 充值成功! 余额:', oldCount, '→', apig.count);
- break;
- }
- console.log('[RECHARGE] 步骤3: 第' + i + '次余额未变 (' + apig.count + ')');
- }
- if (apig.count <= oldCount) {
- console.warn('[RECHARGE] ⚠️ 充值可能延迟,请稍后刷新页面查看');
- }
- console.log('═══ [RECHARGE] 结束 ═══ 最终余额:', apig.count);
- loadOrderHistory();
- }
- async function refreshBalance() {
- try {
- const resp = await postJSON(API_BASE + '/api/apig/getApig', { authid: authId });
- if (resp.code === 200 && resp.data && resp.data.count != null) {
- apig.count = resp.data.count;
- const detail = document.getElementById('successDetail');
- if (detail) {
- const tier = apig.priceStep[selectedIndex];
- const unitLabel = (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ') ? 'token' : '次';
- detail.innerHTML =
- '已充值 <strong style="color:var(--neon);">' + apig.title + '</strong> 接口<br>' +
- '获得 <strong style="color:var(--success);">' + tier.count + ' ' + unitLabel + '</strong>,有效期 730 天<br>' +
- '<span style="color:var(--text-dim);margin-top:8px;display:inline-block;">当前余额: <strong style="color:var(--neon);">' + apig.count + ' ' + unitLabel + '</strong></span>';
- }
- console.log('Balance refreshed:', apig.count);
- }
- } catch(e) {
- console.warn('Balance refresh failed:', e.message);
- }
- }
- function showSuccess() {
- document.getElementById('qrModal').classList.remove('show');
- document.getElementById('mainContent').querySelector('.api-info-card').style.display = 'none';
- document.querySelector('.section-title').style.display = 'none';
- document.getElementById('tierGrid').style.display = 'none';
- document.getElementById('summaryBar').style.display = 'none';
- document.getElementById('payBtn').style.display = 'none';
- const tier = apig.priceStep[selectedIndex];
- const unitLabel = (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ') ? 'token' : '次';
- document.getElementById('successDetail').innerHTML =
- '已充值 <strong style="color:var(--neon);">' + apig.title + '</strong> 接口<br>' +
- '获得 <strong style="color:var(--success);">' + tier.count + ' ' + unitLabel + '</strong>,有效期 730 天';
- document.getElementById('successScreen').classList.add('show');
- }
- async function renderQR(url) {
- const wrapper = document.getElementById('qrWrapper');
- const canvas = document.getElementById('qrCanvas');
- // Clear previous QR (img fallback)
- wrapper.querySelectorAll('img').forEach(i => i.remove());
- canvas.style.display = '';
- canvas.width = 200;
- canvas.height = 200;
- // Try canvas-based QRCode lib first
- if (typeof QRCode !== 'undefined' && QRCode && QRCode.toCanvas) {
- try {
- await QRCode.toCanvas(canvas, url, {
- width: 200,
- margin: 0,
- color: { dark: '#000000', light: '#ffffff' }
- });
- console.log('QR rendered via canvas');
- return;
- } catch (e) {
- console.warn('QRCode.toCanvas failed:', e);
- }
- }
- // Fallback: use img with QR server API
- console.log('Using img fallback for QR');
- canvas.style.display = 'none';
- const img = document.createElement('img');
- img.src = 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=' + encodeURIComponent(url);
- img.width = 200;
- img.height = 200;
- img.alt = 'Payment QR Code';
- img.style.display = 'block';
- wrapper.appendChild(img);
- }
- function handleDone() {
- // Notify parent window (OpenClaw integration)
- try {
- const msg = { type: 'apig-payment-done', authid: authId, user: userId };
- if (window.opener) window.opener.postMessage(msg, '*');
- if (window.parent !== window) window.parent.postMessage(msg, '*');
- } catch(e) { console.warn('postMessage failed:', e); }
- // Try to close window (works if opened via window.open)
- try { window.close(); } catch(e) {}
- setTimeout(() => {
- // If still here, window.close didn't work — reload page
- window.location.reload();
- }, 500);
- }
- function cancelPayment() {
- if (pollTimer) { clearInterval(pollTimer); pollTimer = null; }
- document.getElementById('qrModal').classList.remove('show');
- }
- // ─── Order History ───
- let orderSkip = 0;
- const ORDER_PAGE_SIZE = 10;
- async function loadOrderHistory(append) {
- const container = document.getElementById('orderListBody');
- const section = document.getElementById('orderHistory');
- const refreshBtn = document.getElementById('refreshOrdersBtn');
- section.style.display = '';
- if (refreshBtn) refreshBtn.disabled = true;
- if (!append) {
- orderSkip = 0;
- container.innerHTML = '<div class="order-loading"><span class="polling-dot"></span> 加载中...</div>';
- }
- try {
- // Query APIGOrder class via Parse REST API
- // Orders link to user via fromCompany/fromUser Pointer whose objectId = userId or authId
- const userVal = userId || authId;
- const where = JSON.stringify({
- '$or': [
- { fromCompany: { __type: 'Pointer', className: 'Company', objectId: userVal } },
- { fromUser: { __type: 'Pointer', className: '_User', objectId: userVal } }
- ]
- });
- const qs = new URLSearchParams({
- where: where,
- order: '-createdAt',
- limit: String(ORDER_PAGE_SIZE),
- skip: String(orderSkip)
- });
- const resp = await fetch(API_BASE + '/parse/classes/APIGOrder?' + qs.toString(), {
- headers: {
- 'X-Parse-Application-Id': APP_ID
- }
- });
- if (!resp.ok) throw new Error('HTTP ' + resp.status);
- const data = await resp.json();
- const orders = data.results || [];
- console.log('Order history loaded:', orders.length, 'skip:', orderSkip);
- if (!append) {
- if (orders.length === 0) {
- container.innerHTML =
- '<div class="order-empty">' +
- '<svg width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5"><path d="M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2"/><rect x="9" y="3" width="6" height="4" rx="1"/></svg>' +
- '暂无订单记录</div>';
- if (refreshBtn) refreshBtn.disabled = false;
- return;
- }
- container.innerHTML = '';
- // Build table
- const table = document.createElement('table');
- table.className = 'order-table';
- table.innerHTML =
- '<thead><tr>' +
- '<th>时间</th>' +
- '<th>套餐</th>' +
- '<th>金额</th>' +
- '<th>状态</th>' +
- '</tr></thead>';
- const tbody = document.createElement('tbody');
- tbody.id = 'orderTbody';
- table.appendChild(tbody);
- container.appendChild(table);
- }
- const tbody = document.getElementById('orderTbody');
- orders.forEach(o => {
- const tr = document.createElement('tr');
- tr.innerHTML = formatOrderRow(o);
- tbody.appendChild(tr);
- });
- // Remove old "load more" button
- const oldMore = container.querySelector('.order-more-btn');
- if (oldMore) oldMore.remove();
- // Show "load more" if there might be more records
- if (orders.length >= ORDER_PAGE_SIZE) {
- orderSkip += ORDER_PAGE_SIZE;
- const moreBtn = document.createElement('button');
- moreBtn.className = 'order-more-btn';
- moreBtn.textContent = '加载更多...';
- moreBtn.onclick = () => loadOrderHistory(true);
- container.appendChild(moreBtn);
- }
- } catch (e) {
- console.warn('Order history error:', e);
- if (!append) {
- container.innerHTML =
- '<div class="order-error">订单加载失败: ' + e.message + '</div>';
- }
- }
- if (refreshBtn) refreshBtn.disabled = false;
- }
- function formatOrderRow(o) {
- // Time
- const dt = o.createdAt ? new Date(o.createdAt) : null;
- const timeStr = dt
- ? dt.getFullYear() + '-' +
- String(dt.getMonth() + 1).padStart(2, '0') + '-' +
- String(dt.getDate()).padStart(2, '0') + ' ' +
- String(dt.getHours()).padStart(2, '0') + ':' +
- String(dt.getMinutes()).padStart(2, '0')
- : '—';
- // Count — from detail.addCount or count field
- const count = (o.detail && o.detail.addCount) || o.count || '—';
- const unitLabel = (apig && (apig.objectId === 'MYM5zJBKgw' || apig.objectId === 'FQtTgjcqIZ')) ? 'token' : '次';
- const countStr = count !== '—' ? count + ' ' + unitLabel : '—';
- // Amount — from price field
- const fee = o.price != null ? o.price : null;
- const amountStr = fee != null ? '¥' + fee : '—';
- // Status
- const status = resolveOrderStatus(o);
- return '<td class="col-time">' + timeStr + '</td>' +
- '<td class="col-count">' + countStr + '</td>' +
- '<td class="col-amount">' + amountStr + '</td>' +
- '<td>' + status + '</td>';
- }
- function resolveOrderStatus(o) {
- // isPay is the primary payment status flag in APIGOrder
- if (o.isPay === true) {
- // Check if recharge was applied (detail.oldCount exists and addCount exists)
- if (o.detail && o.detail.addCount && o.detail.oldCount != null) {
- return '<span class="order-status status-recharged">已充值</span>';
- }
- return '<span class="order-status status-paid">已支付</span>';
- }
- if (o.isPay === false) {
- // Unpaid — check if expired (>30 min old)
- const age = Date.now() - new Date(o.createdAt).getTime();
- if (age > 30 * 60 * 1000) {
- return '<span class="order-status status-failed">已过期</span>';
- }
- return '<span class="order-status status-pending">待支付</span>';
- }
- return '<span class="order-status status-pending">未知</span>';
- }
- // ─── Helpers ───
- function showError(msg) {
- const el = document.getElementById('errorBar');
- if (!el) { console.error('errorBar not found:', msg); return; }
- el.textContent = msg;
- el.classList.add('show');
- }
- function hideError() {
- const el = document.getElementById('errorBar');
- if (el) el.classList.remove('show');
- }
- async function postJSON(url, data) {
- const resp = await fetch(url, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body: JSON.stringify(data)
- });
- return resp.json();
- }
- async function parseCloudCall(funcId, params) {
- const url = PARSE_BASE + '/' + funcId;
- const body = Object.assign({ _ApplicationId: APP_ID }, params);
- const resp = await fetch(url, {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- 'X-Parse-Application-Id': APP_ID
- },
- body: JSON.stringify(body)
- });
- if (!resp.ok) {
- console.warn('Cloud function ' + funcId + ' returned ' + resp.status);
- return null;
- }
- return resp.json();
- }
- </script>
- </body>
- </html>
|