interval.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //检查订单间隔
  2. var mysql = require('mysql');
  3. var mysqlcn = require('../../terry/mysqlcn.js');
  4. var qs = require('querystring');
  5. var http = require('http');
  6. var query = mysqlcn.query;
  7. var USER = "yytx";
  8. var PWD = "lee@YY-Games.520";
  9. var sql_insert = function(orderid, serverid,uid,rmb,moneytype,cfid,platform,channel,overtime,flag,product_id,user_id,purchase_date_ms,talkingdata){
  10. var sql = "INSERT INTO prohibition_info SET orderid=?, serverid=?, channel=?, submittime=?, flag=?, user_id=?, channel_order_id=?, money=?, cfid=?, platform=?,overtime=?,product_id=?,uid=?,moneytype=?,talkingdata=?";
  11. var values = [orderid, serverid, channel,purchase_date_ms,flag,user_id,orderid,rmb,cfid,platform,overtime,product_id,uid,moneytype,talkingdata];
  12. sql = mysql.format(sql, values);
  13. return sql;
  14. }
  15. //查询游戏服务器列表
  16. var sql_select_server = function(id){
  17. var sql = "SELECT * FROM services WHERE id = ?";
  18. var inserts = [id];
  19. sql = mysql.format(sql, inserts);
  20. return sql;
  21. }
  22. //查询玩家是否被封号
  23. var sql_select_uid = function(id){
  24. var sql = "SELECT * FROM prohibition_info WHERE uid = ?";
  25. var inserts = [id];
  26. sql = mysql.format(sql, inserts);
  27. return sql;
  28. }
  29. //封号
  30. function prohibition(uid,serverid){
  31. var sql = sql_select_server(serverid);
  32. query(sql,function(qerr,vals,fields){
  33. if (vals.length>0){
  34. queryRet = vals[0];
  35. //content={"receiver":"00-6326686271099908096","times":10}
  36. var content = {
  37. 'receiver': uid,
  38. 'times': 99999999,
  39. };
  40. content = JSON.stringify(content);
  41. var data2game = {
  42. 'user' : USER,
  43. 'pwd' : PWD,
  44. 'content' : content,
  45. }
  46. data2game = JSON.stringify(data2game);
  47. //console.log("data2game:%s",data2game)
  48. var opt = {
  49. method: "POST",
  50. host: queryRet.ip,
  51. port: queryRet.port,
  52. path: "/forbidden",
  53. headers: {
  54. "Content-Type": 'application/json',
  55. "Content-Length": data2game.length
  56. }
  57. };
  58. var req = http.request(opt, function (res){
  59. if (res.statusCode == 200){
  60. var datas = [];
  61. var size = 0;
  62. res.on('data', function (data){
  63. datas.push(data);
  64. size += data.length;
  65. });
  66. res.on('end', function (){
  67. var buff = Buffer.concat(datas, size);
  68. var result = buff.toString();
  69. var result = JSON.parse(result);
  70. if (parseInt(result.errno)==200){
  71. // 至此,一笔充值圆满的结束了
  72. console.log("[IOS短间隔充值封号] 请求封号成功,result.errno:%s",result.errno);
  73. }
  74. else{
  75. console.log("[IOS短间隔充值封号] 请求封号失败3,result.errno:%s,result.info:%s",result.errno,result.info);
  76. }
  77. });
  78. res.on('error', function (err){
  79. console.log(err);
  80. console.log("[IOS短间隔充值封号] 请求封号失败2");
  81. });
  82. }
  83. }).on('error', function(){
  84. console.log("[IOS短间隔充值封号] 请求封号失败1");
  85. });
  86. req.write(data2game);
  87. req.end();
  88. }else {
  89. console.log("[IOS短间隔充值封号] 查询角色服务器失败");
  90. }
  91. })
  92. }
  93. function get_orderid(overtime,uid,orderid_a){
  94. var sql = mysql.format("SELECT * FROM payinfo where overtime=? AND uid=?", [overtime,uid]);//在mysql库中检查订单号
  95. query(sql,function(qerr,vals,fields){
  96. if (qerr==null){
  97. if (vals[0]==null){
  98. //console.log("[查询订单] 没有找到该订单");
  99. return ;
  100. }
  101. if (vals[0].overtime>0 && orderid_a != vals[0].orderid){
  102. console.log("[查询订单] 得到订单:%s,时间:%s,本次时间:%s",vals[0].orderid,vals[0].overtime,overtime);
  103. var orderid = vals[0].orderid;
  104. var serverid = vals[0].serverid
  105. //记录有短间隔的订单对玩家封号
  106. var sql = sql_insert(vals[0].orderid, vals[0].serverid,vals[0].uid,vals[0].money,vals[0].moneytype,vals[0].cfid,vals[0].platform,vals[0].channel,vals[0].overtime,0,vals[0].product_id,vals[0].user_id,vals[0].submittime,0)
  107. query(sql,function(qerr,vals,fields){
  108. try {
  109. if (qerr) {
  110. if (qerr.errno == 1062) {
  111. // 视为成功,但不再封号。
  112. } else {
  113. console.log("[IOS短间隔充值封号] 订单 %s: 存储失败!\n\t%s",orderid, JSON.stringify(qerr));
  114. }
  115. } else {
  116. //通知游戏服封号
  117. var sql = sql_select_uid(uid);
  118. query(sql,function(qerr,vals,fields){
  119. if (vals.length>=4){
  120. console.log("[IOS短间隔充值封号] 角色将被封号,uid:%s",uid);
  121. prohibition(uid,serverid)
  122. }else {
  123. console.log("[IOS短间隔充值封号] 角色未被封号,uid:%s,overtime:%s",uid,overtime);
  124. }
  125. })
  126. }
  127. } catch(err) {
  128. console.log(err);
  129. }
  130. })
  131. }
  132. }else{
  133. console.log("[IOS短间隔充值封号] 查询订单列表错误,请检查数据表结构和sql语句:\n\t%s", qerr);
  134. return ;
  135. }
  136. })
  137. }
  138. exports.orderid_interval = function(uid,overtime,orderid){
  139. for(var i = 0; i < 4; ++i){
  140. var now_overtime = overtime - i
  141. //console.log("[IOS短间隔充值封号] 角色未被封号,uid:%s,overtime:%s,now_overtime:%s",uid,overtime,now_overtime);
  142. get_orderid(now_overtime,uid,orderid)
  143. // query(sql,function(qerr,vals,fields){
  144. // if (vals.length>0){
  145. // console.log("[IOS短间隔充值封号] 角色已经封号,uid:%s,now_overtime:%s",uid,now_overtime);
  146. // }else {
  147. // console.log("[IOS短间隔充值封号] 角色未被封号,uid:%s,overtime:%s,now_overtime:%s",uid,overtime,now_overtime);
  148. // get_orderid(now_overtime,uid)
  149. // }
  150. // })
  151. }
  152. }