返回

javascript-错误:路径“TimePeriod”处值“undefined58”(类型字符串)的转换为数字失败

发布时间:2022-08-07 07:51:30 275
# 前端

尝试使用user、original和percent三个参数向用户添加税款。下面定义了模式以及函数的调用

const usertaxschema = require('./schemas/usertaxschema')
const maintaxschema = require('./schemas/maintaxschema')
  const taxedamount = ((percent/100)*original).toFixed(0)
  const data = await usertaxschema.findOne({User:User})
  if(!data) {
    const newSchema = new usertaxschema({
      User:User,
      TaxesPaidInTotal:0,
      TakesPaidThisPeriod:0,
      })
      await newSchema.save().catch((err) => console.log(err))
      return 0
  }
  const chubster = await maintaxschema.findOne({Taxes:'Main'})
  chubster.TotalTaxesPaid +=taxedamount
chubster.taxesavailable += taxedamount
data.TotalTaxesPaid +=taxedamount
data.TimePeriod += taxedamount
await chubster.save()
await data.save()
return taxedamount
}

UserTaxSchema

const mongoose = require('mongoose')
const usertaxschema = mongoose.Schema({
    User:String,
    TaxesPaidInTotal:Number,
    TimePeriod:Number,
    })
module.exports = mongoose.model('usertaxes', usertaxschema, 'usertaxes')

MainTaxSchema

const mongoose = require('mongoose')
const maintaxschema = mongoose.Schema({
    Taxes:String, //Main etc
    TotalTaxesAllTime:Number,
    TaxesCollectedThisPeriod:Number,
    TaxesInBalance:Number,
})
module.exports = mongoose.model('maintaxes', maintaxschema, 'maintaxes')

调用函数示例

 const fatso = await Client.economy.taxUser(interaction.user.id, 500, 11.5)
    console.log(fatso)
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像