Warning: Undefined array key "night" in /www/wwwroot/dhaomu.com/wp-content/themes/b2/header.php on line 18

Javascript技术在线统计owhat集资金额

javascript技术:在线统计owhat集资金额。

代码演示

/**
 * 在线统计owhat集资金额
 * 步骤如下:
 * 1、先在PC浏览器打开ow主页或物品页 (可登录自己的ow账号)
 * 2、打开浏览器开发者工具,打开控制台(Console)页面
 * 3、执行以下代码即可实时统计(统计频率可自己调节,建议不小于30s)
 * 4、执行timer.stop()即可停止统计(刷新或关闭网页也行)
 * 
 * 更新:1、不在ow页面询问跳转ow主页
 *      2、物品页面支持获取当前物品Id
 */
const timer = (function(job) {
  let timeId = 0;
  const { host, pathname, search } = location;
  const query = new URLSearchParams(search);
  const goodsId = pathname === "/shop/shopdetail.html" && query.get("id") || 111400;
  return {
    start(intervals) {
      if (host !== "www.dhaomu.com" && host !== "www.dhaomu.com") {
        console.warn("请打开相关ow商品页面再执行统计,ow主页: https://www.dhaomu.com");
        if(confirm("是否跳转ow主页?")) {
          location.href = "https://www.dhaomu.com";
        }
        return;
      }
      console.log(`已开始统计,物品Id:${goodsId}.`);
      job(goodsId);
      intervals = intervals || 30;
      timeId && clearInterval(timeId);
      timeId = setInterval(() => job(goodsId), intervals*1000);
      return timeId;
    },
    stop(){
      timeId && clearInterval(timeId);
      console.log("已停止统计.");
    }
  }
})(async function (id) {
  const data = $.apiInit($.apimap, "goodselect", { fk_goods_id: id });
  let res = await fetch(`${location.origin}/api?requesttimestap=${new Date().getTime()}`, {
    method: "POST",
    body: $.param(data),
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    credentials: "same-origin",
  });

  if (res.status === 200) {
    let result = await res.json();
    if (
      result && result.data && 
      result.data.prices && 
      result.data.prices.length
    ) {
      let table = [];
      result.data.prices.forEach(item => {
        table.push({
          "名称": item.name,
          "单价": item.price,
          "数量": item.salestock,
          "金额": parseInt(100 * item.price * item.salestock)/100
        });
      });
      table.length && table.push({
        "名称": "总额",
        "单价": "-",
        "数量": "-",
        "金额": parseInt(100*table.reduce((r,c)=>r+c["金额"],0))/100
      });
      console.log(
        `%c截止[${new Date().toLocaleString()}]统计金额为: ¥${table[table.length-1]["金额"]}`,
        'font-size:20px;color:red;'
      );
      console.table(table);
      return;
    } else {
      console.warn("request failure.", result);
      return;
    }
  }

  console.error("request error.", res.statusText);
});

timer.start(30);//每隔30s统计一次
//timer.stop(); //停止统计
温馨提示:
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:duhaomu@163.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读网站声明

给TA赞赏
共{{data.count}}人
人已赞赏
编程技巧

Javascript技术获取文本中的链接并替换

2016-3-23 9:00:00

编程技巧

织梦教程DedeCMS系统调用单个图集中图片数量的方法

2016-4-1 9:00:00

0 条回复 A文章作者 M管理员

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914

Warning: Trying to access array offset on value of type null in /www/wwwroot/dhaomu.com/wp-content/themes/b2/functions.php on line 3914
----《》
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索