请选择 进入手机版 | 继续访问电脑版

站内搜索

搜索
热搜: 活动 交友 discuz

iFAction 世界需要你的想象力!

记录你的游戏被别人打开次数

4

主题

4

帖子

46

积分

iF元素粒

Rank: 2

积分
46
发表于 2020-10-15 19:14:49 | 显示全部楼层 |阅读模式
写了个简单的记录打开次数
ifaction发生get请求,无条件记录数据
  1. <div style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34); line-height: 19px; white-space: pre;"><div><span style="color: #66d9ef;font-style: italic;">var</span> web <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"http://127.0.0.1/?id=1"</span></div><div>    IWeb.<span style="color: #a6e22e;">getUrl</span>(web)</div></div>
复制代码

node
  1. <div style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34); line-height: 19px; white-space: pre;"><div style="line-height: 19px;"><span style="color: #66d9ef;font-style: italic;">var</span> getmysql <span style="color: #f92672;">=</span> <span style="color: #66d9ef;">require</span>(<span style="color: #e6db74;">"../get/cateController"</span>)</div></div><div style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34); line-height: 19px; white-space: pre;">router.<span style="color: #a6e22e;">get</span>(<span style="color: #e6db74;">'/'</span>, getmysql.getgame)</div><div style="color: rgb(248, 248, 242); background-color: rgb(39, 40, 34); line-height: 19px; white-space: pre;"><div style="line-height: 19px;"><div><span style="color: #66d9ef;font-style: italic;">var</span> jishiqi <span style="color: #f92672;">=</span> <span style="color: #ae81ff;">0</span></div><div><span style="color: #66d9ef;font-style: italic;">var</span> chaxun <span style="color: #f92672;">=</span> <span style="color: #ae81ff;">0</span></div><div><span style="color: #a6e22e;">newone</span> <span style="color: #f92672;">=</span> () <span style="color: #66d9ef;font-style: italic;">=></span>{</div><div>  <span style="color: #66d9ef;font-style: italic;">var</span> sql <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"SELECT id FROM game"</span></div><div>  <span style="color: #66d9ef;font-style: italic;">var</span> sqlArr <span style="color: #f92672;">=</span> [];</div><div>  <span style="color: #66d9ef;font-style: italic;">var</span> <span style="color: #a6e22e;">callBack</span> <span style="color: #f92672;">=</span> (<span style="color: #fd971f;font-style: italic;">err</span>,<span style="color: #fd971f;font-style: italic;">data</span>)<span style="color: #66d9ef;font-style: italic;">=></span>{</div><div>    <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(data)</div><div>    <span style="color: #66d9ef;font-style: italic;">var</span> sqlcmd <span style="color: #f92672;">=</span> <span style="color: #66d9ef;">JSON</span>.<span style="color: #66d9ef;">stringify</span>(data)</div><div>    <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(sqlcmd)</div><div>    <span style="color: #66d9ef;font-style: italic;">var</span> sqlcmd1 <span style="color: #f92672;">=</span> <span style="color: #66d9ef;">JSON</span>.<span style="color: #66d9ef;">parse</span>(sqlcmd)</div><div>    <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(sqlcmd1[<span style="color: #ae81ff;">0</span>].id)</div><div>    chaxun <span style="color: #f92672;">=</span> sqlcmd1[<span style="color: #ae81ff;">0</span>].id</div><div>  }</div><div>  </div><div>  dbCongif.<span style="color: #a6e22e;">sqlConnect</span>(sql,sqlArr,callBack)</div><div>}</div><div><span style="color: #88846f;">// sql读取数据初始化计数器</span></div><div><span style="color: #a6e22e;">newone</span>()</div><div><span style="color: #a6e22e;">getgame</span> <span style="color: #f92672;">=</span> (<span style="color: #fd971f;font-style: italic;">req</span>,<span style="color: #fd971f;font-style: italic;">res</span>)<span style="color: #66d9ef;font-style: italic;">=></span>{</div><div>  chaxun<span style="color: #f92672;">++</span></div><div>  <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(chaxun)</div><div>  <span style="color: #66d9ef;font-style: italic;">var</span> sql <span style="color: #f92672;">=</span> <span style="color: #e6db74;">"UPDATE `game` SET `id`="</span><span style="color: #f92672;">+</span>chaxun<span style="color: #f92672;">+</span><span style="color: #e6db74;">""</span></div><div>  <span style="color: #66d9ef;font-style: italic;">var</span> sqlArr <span style="color: #f92672;">=</span> [];</div><div>  <span style="color: #66d9ef;font-style: italic;">var</span> <span style="color: #a6e22e;">callBack</span> <span style="color: #f92672;">=</span> (<span style="color: #fd971f;font-style: italic;">err</span>,<span style="color: #fd971f;font-style: italic;">data</span>)<span style="color: #66d9ef;font-style: italic;">=></span>{</div><div>    <span style="color: #f92672;">if</span>(err){</div><div>      <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(<span style="color: #e6db74;">"sql错误无法初始化sql池"</span>)</div><div>    }<span style="color: #f92672;">else</span>(</div><div>      res.<span style="color: #a6e22e;">send</span>({</div><div>        <span style="color: #e6db74;">"cishu"</span>:data</div><div>      })</div><div>    )</div><div>    <span style="color: #66d9ef;font-style: italic;">console</span>.<span style="color: #66d9ef;">log</span>(<span style="color: #e6db74;">"数据传输完成 "</span><span style="color: #f92672;">+</span>jishiqi<span style="color: #f92672;">+</span><span style="color: #e6db74;">" 次"</span>);</div><div>    jishiqi<span style="color: #f92672;">++</span></div><div>}</div><div>dbCongif.<span style="color: #a6e22e;">sqlConnect</span>(sql,sqlArr,callBack)</div>
  2. <div>}</div><div><span style="color: #88846f;">// 相应数据变化</span></div>
  3. <div><span style="color: #66d9ef;font-style: italic;">module</span>.<span style="color: #66d9ef;font-style: italic;">exports</span> <span style="color: #f92672;">=</span> {</div><div>    getgame,</div><div>}</div></div></div>
复制代码

源代码:https://epiphylluminlove.lanzous.com/iPe9Xhg8mwf
实况

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

联系我们
QQ群:977585123
iFAction下载
Windows客户端
反馈
意见建议
iFAction

iFAction

京ICP备15053274号-1

Powered by Discuz! X3.4 © 2001-2013 Comsenz Inc.