272eca04ce
购买/支付(Phase B): - 新 SegSwitch 段控 widget(镜像 .segswitch 原子) - 购买页重构:顶部支付渠道 switch(默认 USDT→加密货币 / 人民币→支付宝),套餐价随渠道分币种显示,删底部弹窗选方式;点购买直达支付页 - 支付页加订单信息卡(套餐/渠道/金额按币种) - models:PayChannel + PayCatalogItem.priceUsdtMicro/priceLabel(ch)/perMonthLabel(ch) 订单(P0,全新): - payment_api.listOrders() + orders_provider(列表 + 详情 family) - OrdersScreen 列表→详情(状态 pill / 可复制订单号 / 继续支付·重新购买) - 导航:NavView.orders + desktop_shell 分支 + account 入口 配套: - l10n +19 getter(支付渠道 4 + 订单 15)×6 语言,l10n 闸绿 - 图标单源迁移 lucide_icons_flutter + pangolin_icons.dart(codegen) - 联系渠道订正(Telegram/邮件 support@yanmeiai.com/官网) + 前端去广告&时长 - 测试:购买 switch 分币种 + 订单列表/空态/详情 + 假 API listOrders;golden 重录 - flutter analyze 0 error,flutter test 226 全绿 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013nMthbVEmQquxBRKb9Fj8u
154 lines
5.6 KiB
Dart
154 lines
5.6 KiB
Dart
// payment.dart — pay v2 支付领域模型(server 代理端点的响应形状)。
|
|
// 金额只读展示:price_minor 为 CNY 分;crypto 精确金额在 session.payload 里。
|
|
|
|
/// 支付渠道:结算币种即支付方式(一步定)。usdt→加密货币 / cny→支付宝。
|
|
/// 各币种一口价(不做实时汇率换算);实际扣款以 pay 侧为准。
|
|
enum PayChannel { usdt, cny }
|
|
|
|
extension PayChannelX on PayChannel {
|
|
String get currency => this == PayChannel.usdt ? 'USDT' : 'CNY';
|
|
String get method => this == PayChannel.usdt ? 'crypto' : 'alipay';
|
|
}
|
|
|
|
class PayCatalogItem {
|
|
const PayCatalogItem({
|
|
required this.sku,
|
|
required this.plan,
|
|
required this.days,
|
|
required this.priceMinor,
|
|
required this.currency,
|
|
this.priceUsdtMicro = 0,
|
|
});
|
|
|
|
final String sku;
|
|
final String plan;
|
|
final int days;
|
|
final int priceMinor; // CNY 分(展示)
|
|
final String currency; // CNY
|
|
final int priceUsdtMicro; // USDT 微元(展示;各币种一口价)
|
|
|
|
factory PayCatalogItem.fromJson(Map<String, dynamic> j) => PayCatalogItem(
|
|
sku: j['sku'] as String,
|
|
plan: j['plan'] as String? ?? 'pro',
|
|
days: (j['days'] as num?)?.toInt() ?? 0,
|
|
priceMinor: (j['price_minor'] as num?)?.toInt() ?? 0,
|
|
currency: j['currency'] as String? ?? 'CNY',
|
|
priceUsdtMicro: (j['price_usdt_micro'] as num?)?.toInt() ?? 0,
|
|
);
|
|
|
|
/// 约当月数(31→1 / 92→3 / 366→12),用于每月折算展示。
|
|
int get months {
|
|
final m = (days / 30.4).round();
|
|
return m < 1 ? 1 : m;
|
|
}
|
|
|
|
/// 按渠道币种给总价文案(USDT $ / CNY ¥)。
|
|
String priceLabel(PayChannel ch) => ch == PayChannel.usdt
|
|
? '\$${(priceUsdtMicro / 1000000).toStringAsFixed(2)}'
|
|
: '¥${(priceMinor / 100).toStringAsFixed(2)}';
|
|
|
|
/// 按渠道币种给每月折算文案(不含 /月 后缀,后缀由 l10n 提供)。
|
|
String perMonthLabel(PayChannel ch) => ch == PayChannel.usdt
|
|
? '\$${(priceUsdtMicro / 1000000 / months).toStringAsFixed(2)}'
|
|
: '¥${(priceMinor / 100 / months).toStringAsFixed(2)}';
|
|
}
|
|
|
|
/// PayOrderSummary — 订单列表项(server orderView 台账视图)。
|
|
/// 金额为结算币种 minor:CNY 分 / USDT 微元。
|
|
class PayOrderSummary {
|
|
const PayOrderSummary({
|
|
required this.orderNo,
|
|
required this.sku,
|
|
required this.plan,
|
|
required this.days,
|
|
required this.method,
|
|
required this.status,
|
|
required this.amountMinor,
|
|
required this.currency,
|
|
required this.createdAt,
|
|
this.paidAt,
|
|
});
|
|
|
|
final String orderNo;
|
|
final String sku;
|
|
final String plan;
|
|
final int days;
|
|
final String method; // crypto | alipay | nezha …
|
|
final String status; // created | paid | canceled(本地台账)
|
|
final int amountMinor;
|
|
final String currency; // CNY | USDT
|
|
final DateTime? createdAt;
|
|
final DateTime? paidAt;
|
|
|
|
factory PayOrderSummary.fromJson(Map<String, dynamic> j) => PayOrderSummary(
|
|
orderNo: j['order_no'] as String? ?? '',
|
|
sku: j['sku'] as String? ?? '',
|
|
plan: j['plan'] as String? ?? 'pro',
|
|
days: (j['days'] as num?)?.toInt() ?? 0,
|
|
method: j['method'] as String? ?? '',
|
|
status: j['status'] as String? ?? '',
|
|
amountMinor: (j['amount_minor'] as num?)?.toInt() ?? 0,
|
|
currency: j['currency'] as String? ?? 'CNY',
|
|
createdAt: j['created_at'] == null ? null : DateTime.tryParse(j['created_at'] as String),
|
|
paidAt: j['paid_at'] == null ? null : DateTime.tryParse(j['paid_at'] as String),
|
|
);
|
|
|
|
/// 结算币种金额文案(USDT 6 位、CNY 2 位)。
|
|
String amountLabel() => currency == 'USDT'
|
|
? '\$${(amountMinor / 1000000).toStringAsFixed(2)}'
|
|
: '¥${(amountMinor / 100).toStringAsFixed(2)}';
|
|
}
|
|
|
|
class PaySession {
|
|
const PaySession({required this.renderType, required this.payload, this.expiresAt});
|
|
|
|
final String renderType; // crypto_address | redirect | qr
|
|
final Map<String, dynamic> payload;
|
|
final DateTime? expiresAt;
|
|
|
|
factory PaySession.fromJson(Map<String, dynamic> j) => PaySession(
|
|
renderType: j['render_type'] as String? ?? '',
|
|
payload: (j['payload'] as Map<String, dynamic>?) ?? const {},
|
|
expiresAt: j['expires_at'] == null ? null : DateTime.tryParse(j['expires_at'] as String),
|
|
);
|
|
}
|
|
|
|
class PayOrder {
|
|
const PayOrder({required this.orderNo, required this.session});
|
|
|
|
final String orderNo;
|
|
final PaySession session;
|
|
|
|
factory PayOrder.fromJson(Map<String, dynamic> j) => PayOrder(
|
|
orderNo: j['order_no'] as String,
|
|
session: PaySession.fromJson((j['session'] as Map<String, dynamic>?) ?? const {}),
|
|
);
|
|
}
|
|
|
|
/// PayOrderStatus — 查单/详情响应。轮询只用 activated;订单详情页额外用
|
|
/// 台账富字段(server GetOrder 现回带 orderView 全字段)。
|
|
class PayOrderStatus {
|
|
const PayOrderStatus({
|
|
required this.orderNo,
|
|
required this.payStatus,
|
|
required this.activated,
|
|
this.expiresAt,
|
|
this.summary,
|
|
});
|
|
|
|
final String orderNo;
|
|
final String payStatus;
|
|
final bool activated; // server 台账已消费 = 权益已开通(轮询成功判据)
|
|
final DateTime? expiresAt;
|
|
final PayOrderSummary? summary; // 台账富字段(sku/plan/method/金额/时间…);详情页用
|
|
|
|
factory PayOrderStatus.fromJson(Map<String, dynamic> j) => PayOrderStatus(
|
|
orderNo: j['order_no'] as String? ?? '',
|
|
payStatus: j['pay_status'] as String? ?? '',
|
|
activated: j['activated'] as bool? ?? false,
|
|
expiresAt: j['expires_at'] == null ? null : DateTime.tryParse(j['expires_at'] as String),
|
|
// 详情端点回带台账字段(列表端点同形);sku 存在才解析。
|
|
summary: j['sku'] == null ? null : PayOrderSummary.fromJson(j),
|
|
);
|
|
}
|