feat: fetch subscription prices from server settings
- Add GET /api/v1/subscription/plans public endpoint (no auth needed) that reads prices from system_settings table - Subscribe-plans page now loads prices from server on show - Falls back to hardcoded defaults if API fails - Add api.getPlans() to miniprogram API module
这个提交包含在:
@@ -4,10 +4,7 @@ var config = require('../../config/env')
|
||||
Page({
|
||||
data: {
|
||||
statusBarHeight: 44,
|
||||
plans: [
|
||||
{ key: 'monthly', name: '月卡', price: 99, priceLabel: '¥99', desc: '约3.3元/天' },
|
||||
{ key: 'yearly', name: '年卡', price: 899, priceLabel: '¥899', desc: '省¥289', tag: '推荐' }
|
||||
],
|
||||
plans: [],
|
||||
selected: 'yearly',
|
||||
purchasing: false,
|
||||
subscription: null,
|
||||
@@ -28,9 +25,42 @@ Page({
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
this.loadPlans()
|
||||
this.loadSubscription()
|
||||
},
|
||||
|
||||
loadPlans: function () {
|
||||
var self = this
|
||||
api.getPlans().then(function (data) {
|
||||
var plans = (data.plans || []).filter(function (p) { return p.key !== 'trial' }).map(function (p) {
|
||||
var daily = p.days > 0 ? (p.price / p.days).toFixed(1) : 0
|
||||
return {
|
||||
key: p.key,
|
||||
name: p.name,
|
||||
price: p.price,
|
||||
priceLabel: '¥' + p.price,
|
||||
desc: p.key === 'yearly' ? '省¥' + ((p.price / 12 * 12) > 0 ? Math.round(self._monthlyPrice(data.plans) * 12 - p.price) : '') : '约' + daily + '元/天',
|
||||
tag: p.key === 'yearly' ? '推荐' : ''
|
||||
}
|
||||
})
|
||||
if (plans.length > 0) self.setData({ plans: plans })
|
||||
}).catch(function () {
|
||||
self.setData({
|
||||
plans: [
|
||||
{ key: 'monthly', name: '月卡', price: 99, priceLabel: '¥99', desc: '约3.3元/天' },
|
||||
{ key: 'yearly', name: '年卡', price: 899, priceLabel: '¥899', desc: '省¥289', tag: '推荐' }
|
||||
]
|
||||
})
|
||||
})
|
||||
},
|
||||
|
||||
_monthlyPrice: function (plans) {
|
||||
for (var i = 0; i < plans.length; i++) {
|
||||
if (plans[i].key === 'monthly') return plans[i].price
|
||||
}
|
||||
return 99
|
||||
},
|
||||
|
||||
loadSubscription: function () {
|
||||
var self = this
|
||||
api.getSubscription().then(function (sub) {
|
||||
|
||||
在新工单中引用
屏蔽一个用户