fix: mock purchase now actually activates subscription
POST /api/v1/subscription/purchase only creates an order without activating. Add POST /api/v1/subscription/mock-purchase that does purchase + verify in one step (non-production only). Miniprogram subscribe page now calls mock-purchase so subscriptions take effect.
这个提交包含在:
@@ -147,7 +147,7 @@ Page({
|
||||
doPurchase: function (plan) {
|
||||
var self = this
|
||||
self.setData({ purchasing: true })
|
||||
api.purchase(plan.key).then(function (order) {
|
||||
api.mockPurchase(plan.key).then(function (order) {
|
||||
self.setData({ purchasing: false })
|
||||
wx.showToast({ title: '支付成功', icon: 'success' })
|
||||
setTimeout(function () {
|
||||
|
||||
@@ -21,6 +21,7 @@ module.exports = {
|
||||
getSubscription: function () { return http.get('/api/v1/subscription') },
|
||||
activateTrial: function () { return http.post('/api/v1/subscription/trial') },
|
||||
purchase: function (plan) { return http.post('/api/v1/subscription/purchase', { plan: plan }) },
|
||||
mockPurchase: function (plan) { return http.post('/api/v1/subscription/mock-purchase', { plan: plan }) },
|
||||
|
||||
// Treatment
|
||||
getRecords: function (params) { return http.get('/api/v1/treatment/history', params) },
|
||||
|
||||
@@ -46,6 +46,19 @@ router.post('/subscription/purchase', requireUser, wrap(async (req, res) => {
|
||||
res.json(ok({ order_id: orderId, payment_params: {}, plan, amount: PLANS[plan].amount }))
|
||||
}))
|
||||
|
||||
router.post('/subscription/mock-purchase', requireUser, wrap(async (req, res) => {
|
||||
const config = require('../config')
|
||||
if (config.nodeEnv === 'production') return res.json(fail(2001, 'not available in production'))
|
||||
const plan = req.body.plan || req.body.plan_type
|
||||
if (!PLANS[plan] || plan === 'trial') return res.json(fail(2001, 'invalid plan'))
|
||||
const p = PLANS[plan]
|
||||
const orderId = 'MOCK' + Date.now()
|
||||
await subscriptionDao.purchase(req.user.user_id, plan, p.amount, orderId, p.days)
|
||||
const logDao = require('../dao/log.dao')
|
||||
await logDao.write({ user_id: req.user.user_id, action: 'subscription_mock_purchase', detail: '模拟购买: ' + plan, ip: req.ip })
|
||||
res.json(ok({ status: 'active', plan, remaining_days: p.days }))
|
||||
}))
|
||||
|
||||
router.post('/subscription/trial', requireUser, wrap(async (req, res) => {
|
||||
const usedTrial = await subscriptionDao.findTrial(req.user.user_id)
|
||||
if (usedTrial) return res.json(fail(2001, '已使用过试用'))
|
||||
|
||||
在新工单中引用
屏蔽一个用户