feat: 增加充值功能
This commit is contained in:
@@ -36,6 +36,6 @@ export const pushBill = async ({
|
||||
$inc: { balance: -price }
|
||||
});
|
||||
} catch (error) {
|
||||
Bill.findByIdAndDelete(billId);
|
||||
billId && Bill.findByIdAndDelete(billId);
|
||||
}
|
||||
};
|
||||
|
||||
23
src/service/models/pay.ts
Normal file
23
src/service/models/pay.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { Schema, model, models } from 'mongoose';
|
||||
|
||||
const PaySchema = new Schema({
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: 'user',
|
||||
required: true
|
||||
},
|
||||
time: {
|
||||
type: Number,
|
||||
default: () => Date.now()
|
||||
},
|
||||
price: {
|
||||
type: Number,
|
||||
required: true
|
||||
},
|
||||
orderId: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
export const Pay = models['pay'] || model('pay', PaySchema);
|
||||
@@ -16,7 +16,7 @@ const UserSchema = new Schema({
|
||||
},
|
||||
balance: {
|
||||
type: Number,
|
||||
default: 0
|
||||
default: 0.5
|
||||
},
|
||||
accounts: [
|
||||
{
|
||||
|
||||
@@ -31,3 +31,4 @@ export * from './models/model';
|
||||
export * from './models/user';
|
||||
export * from './models/training';
|
||||
export * from './models/bill';
|
||||
export * from './models/pay';
|
||||
|
||||
@@ -22,8 +22,12 @@ export const generateToken = (userId: string) => {
|
||||
};
|
||||
|
||||
/* 校验 token */
|
||||
export const authToken = (token: string): Promise<string> => {
|
||||
export const authToken = (token?: string): Promise<string> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!token) {
|
||||
reject('缺少登录凭证');
|
||||
return;
|
||||
}
|
||||
const key = process.env.TOKEN_KEY as string;
|
||||
|
||||
jwt.verify(token, key, function (err, decoded: any) {
|
||||
|
||||
Reference in New Issue
Block a user