getPrice

计算价格

当前为 2024-06-30 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/485233/1402977/getPrice.js

  const defaultRate = 7;
  const defaultShippingCost = 70;

  function getPrice(cost, weight) {
    if (cost > 300) {
      alert('价格太高,请自行计算!');
      return 0;
    }
    let proRate = 0;
    if (cost <= 50) {
      proRate = 0.4;
    }
    if (cost <= 100 && cost > 50) {
      proRate = 0.36;
    }
    if (cost <= 200 && cost > 100) {
      proRate = 0.3;
    }
    if (cost <= 300 && cost > 200) {
      proRate = 0.32;
    }
    const rate = defaultRate * 0.944 * 0.99;
    const shippingCost = defaultShippingCost + 10;
    if (weight !== 0) {
      const price = (cost + cost * proRate + weight * shippingCost) / rate;
      return Math.round(price);
    }
    return 0;
  }