fix: 更改短信模板,删除用户模型原型方法
This commit is contained in:
@@ -27,7 +27,7 @@ module.exports = {
|
||||
sendSMS(phone, {
|
||||
msgParam: { code },
|
||||
templateCode: 'SMS_142465215',
|
||||
signName: 'TIC钱包管家'
|
||||
signName: '第五维度'
|
||||
}),
|
||||
this.saveCode({
|
||||
id: phone,
|
||||
|
||||
@@ -19,7 +19,7 @@ const CodeSchema = new mongoose.Schema({
|
||||
expiresAt: {
|
||||
type: Date,
|
||||
default: Date.now,
|
||||
expires: 3600
|
||||
expires: 600
|
||||
}
|
||||
}, {
|
||||
timestamps: {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
const mongoose = require('mongoose');
|
||||
const ASSETTYPES = ['log', 'profit', 'usdtBTC', 'usdtETH', 'usdtTRX'];
|
||||
|
||||
const UserSchema = new mongoose.Schema({
|
||||
phone: {
|
||||
@@ -40,31 +39,4 @@ const UserSchema = new mongoose.Schema({
|
||||
|
||||
const UserModel = mongoose.model('User', UserSchema);
|
||||
|
||||
UserModel.prototype.increase = async function (assetName, amount, option = {}) {
|
||||
if (!assetName || !amount || amount <= 0 || !Number.isFinite(amount) || !ASSETTYPES.includes(assetName)) return null;
|
||||
const asset = 'asset.' + assetName;
|
||||
const res = await UserModel.findByIdAndUpdate(this.id, {
|
||||
$inc: {
|
||||
[asset]: amount
|
||||
}
|
||||
}, { ...option, returnOriginal: false }).exec().catch(err => null);
|
||||
if (!res || !res.asset) throw new Error('用户资产修改[increase]失败!');
|
||||
if (res.asset[assetName] < 0) throw new Error('Insufficient funds');
|
||||
return res;
|
||||
};
|
||||
UserModel.prototype.decrease = async function (assetName, amount, option) {
|
||||
// 传入的amount应该是大于0的正数
|
||||
if (!assetName || !amount || amount <= 0 || !Number.isFinite(amount) || !ASSETTYPES.includes(assetName)) return null;
|
||||
amount = 0 - amount;
|
||||
const asset = 'asset.' + assetName;
|
||||
const res = await UserModel.findByIdAndUpdate(this.id, {
|
||||
$inc: {
|
||||
[asset]: amount
|
||||
}
|
||||
}, { ...option, returnOriginal: false }).exec().catch(err => null);
|
||||
if (!res || !res.asset) throw new Error('用户资产修改[decrease]失败!');
|
||||
if (res.asset[assetName] < 0) throw new Error('Insufficient funds');
|
||||
return res;
|
||||
};
|
||||
|
||||
module.exports = UserModel;
|
||||
Reference in New Issue
Block a user