fix: 更改短信模板,删除用户模型原型方法
This commit is contained in:
@@ -27,7 +27,7 @@ module.exports = {
|
|||||||
sendSMS(phone, {
|
sendSMS(phone, {
|
||||||
msgParam: { code },
|
msgParam: { code },
|
||||||
templateCode: 'SMS_142465215',
|
templateCode: 'SMS_142465215',
|
||||||
signName: 'TIC钱包管家'
|
signName: '第五维度'
|
||||||
}),
|
}),
|
||||||
this.saveCode({
|
this.saveCode({
|
||||||
id: phone,
|
id: phone,
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ const CodeSchema = new mongoose.Schema({
|
|||||||
expiresAt: {
|
expiresAt: {
|
||||||
type: Date,
|
type: Date,
|
||||||
default: Date.now,
|
default: Date.now,
|
||||||
expires: 3600
|
expires: 600
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
timestamps: {
|
timestamps: {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const mongoose = require('mongoose');
|
const mongoose = require('mongoose');
|
||||||
const ASSETTYPES = ['log', 'profit', 'usdtBTC', 'usdtETH', 'usdtTRX'];
|
|
||||||
|
|
||||||
const UserSchema = new mongoose.Schema({
|
const UserSchema = new mongoose.Schema({
|
||||||
phone: {
|
phone: {
|
||||||
@@ -40,31 +39,4 @@ const UserSchema = new mongoose.Schema({
|
|||||||
|
|
||||||
const UserModel = mongoose.model('User', UserSchema);
|
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;
|
module.exports = UserModel;
|
||||||
Reference in New Issue
Block a user