diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 14e8824..f124cfb 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,14 +1,13 @@ - + - + - - + @@ -571,7 +571,6 @@ - @@ -596,7 +595,8 @@ - @@ -607,82 +607,86 @@ - + + + + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + - + - + diff --git a/controllers/Kassa/index.js b/controllers/Kassa/index.js index 30d2e3f..9a3659f 100644 --- a/controllers/Kassa/index.js +++ b/controllers/Kassa/index.js @@ -31,7 +31,6 @@ const Kassa = { } }) } catch (e) { - console.log('err', e) return utils.response.error(res, 'Ты не Яндекс.Касса') } diff --git a/controllers/user/Auth/SignUp.js b/controllers/user/Auth/SignUp.js index 3fb1077..90078bc 100644 --- a/controllers/user/Auth/SignUp.js +++ b/controllers/user/Auth/SignUp.js @@ -20,6 +20,8 @@ async function isHashAndPaymentDone(hash) { return { success: true, status: 'succeeded', user_id: info.user_id } else if (info.p_status.indexOf('promo_code') !== -1) return { success: true, status: info.p_status, user_id: info.user_id } + else if (info.p_status.indexOf('trial') !== -1) + return { success: true, status: info.p_status, user_id: info.user_id } let kassaPayment = await kassa.getPaymentStatus(info.p_key) if (info.p_status !== kassaPayment.status) @@ -67,37 +69,48 @@ const SignUp = { let dbpayment = null, kassaPayment = null - if (!code) { - kassaPayment = await kassa.createPayment({ - value: plan.cost, - description: `Оплата пакета "${plan.name} в приложении Культ Тела"`, - return_url: 'first-login/' + hash, - metadata: { - type: 'PLAN_BUY', - hash: hash - } - }) - if (!kassaPayment) - return utils.response.error(res, 'Ошибка при создании платежа') + if (typeof plan.trial !== 'number') { + if (!code) { + kassaPayment = await kassa.createPayment({ + value: plan.cost, + description: `Оплата пакета "${plan.name} в приложении Культ Тела"`, + return_url: 'first-login/' + hash, + metadata: { + type: 'PLAN_BUY', + hash: hash + } + }) + + if (!kassaPayment) + return utils.response.error(res, 'Ошибка при создании платежа') - dbpayment = await User.Payment.create( - user_id, - kassaPayment.id, - 'PLAN_BUY', - parseInt(plan.cost) - ) - } else if (code) { - const codeStatus = await User.Promo.getStatus(code, true) - if (codeStatus && codeStatus.plan_id === plan_id) { dbpayment = await User.Payment.create( user_id, - null, + kassaPayment.id, 'PLAN_BUY', - 0, - 'promo_code ' + codeStatus.key + parseInt(plan.cost) ) + } else if (code) { + const codeStatus = await User.Promo.getStatus(code, true) + if (codeStatus && codeStatus.plan_id === plan_id) { + dbpayment = await User.Payment.create( + user_id, + null, + 'PLAN_BUY', + 0, + 'promo_code ' + codeStatus.key + ) + } } + } else { + dbpayment = await User.Payment.create( + user_id, + null, + 'PLAN_BUY', + 0, + 'trial ' + plan.trial + ) } if (!dbpayment) { @@ -192,7 +205,8 @@ const SignUp = { if ( isOk.success === true && (isOk.status === 'succeeded' || - isOk.status.indexOf('promo_code') !== -1) + isOk.status.indexOf('promo_code') !== -1 || + isOk.status.indexOf('trial') !== -1) ) { let subscription_duration if (isOk.status.indexOf('promo_code') !== -1) { @@ -200,6 +214,8 @@ const SignUp = { isOk.status.replace('promo_code ', '') ) subscription_duration = promoCode.subscription_duration || 31 + } else if (isOk.status.indexOf('trial') !== -1) { + subscription_duration = parseInt(isOk.status.replace('trial ', '')) } else subscription_duration = 31 const passwordHashed = await bcrypt.hash(password, SALT_ROUNDS) diff --git a/controllers/user/User/Subscription.js b/controllers/user/User/Subscription.js index d924e5c..8a27715 100644 --- a/controllers/user/User/Subscription.js +++ b/controllers/user/User/Subscription.js @@ -5,7 +5,10 @@ const { copyDATA } = require('../../../data/') const Subscription = { async extend(req, res) { const { plan_id } = req.body - const plans = copyDATA('plans') + const plans = copyDATA('plans').map(e => { + if (e.trial) delete e.trial + return e + }) const plan = plans.filter(e => parseInt(e.id) === plan_id)[0] const metadata = { type: 'PLAN_EXTEND', diff --git a/data/json/plans.json b/data/json/plans.json index 6108d2f..27d6178 100644 --- a/data/json/plans.json +++ b/data/json/plans.json @@ -4,14 +4,16 @@ "name": "Пехота", "description": "Видео упражнений и секретные советы по питанию!", "cost": 800, - "color": "#b4bac2" + "color": "#b4bac2", + "disabled": true }, { "id": 1, "name": "Артиллерия", "description": "Видео всех упражнений для безопасного похудения и оздоровления, программа тренировок в зависимости от индивидуальных параметров, меню и секретные советы по питанию!", "cost": 1200, - "color": "#9635db" + "color": "#9635db", + "trial": 7 }, { "id": 2, diff --git a/utils/user/Plan.js b/utils/user/Plan.js index be92b3f..9cc80db 100644 --- a/utils/user/Plan.js +++ b/utils/user/Plan.js @@ -16,7 +16,10 @@ const Plan = { const { rows } = await db.query(query, values) let data = rows[0] if (data && typeof data.plan_id === 'number') { - const plans = copyDATA('plans') + const plans = copyDATA('plans').map(e => { + if (e.trial) delete e.trial + return e + }) if (data.payment_status === 'promo_code') { return plans .map(e => {