akznuts / A9 ht dml

// ==UserScript==
// @name         A9 ht dml
// @namespace    http://tampermonkey.net/
// @version      0.2.4
// @author       akznuts
// @license      MIT
// @match        http://a9cp.a97766.com/report/reportCompound
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @require      https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.js
// @grant        GM_setClipboard
// ==/UserScript==

(function () {
  'use strict';
  $.ajaxSetup({
    dataType: 'json',
    async: false,
    xhrFields: {
      withCredentials: true // 这里设置了withCredentials
    },
    contentType: "application/json"
  })

  // Your code here...
  setTimeout(function () {
    //sortBtn();
    //dmlBtn();
  }, 3000);
  $(document).keydown(function (e) {
    if (e.which == 113) {
      $('.panel-heading').after($('<div id="dml_body" style="padding:20px 20px 0;"><div id="dml_head"><div data-v-40958d58="" class="el-form-item el-form-item--small"><label for="userName" class="el-form-item__label">账号</label><div class="el-form-item__content" id="username_div"><div data-v-40958d58="" class="width-search100 el-input el-input--min"><input type="text" autocomplete="off" placeholder="请输入账号" class="el-input__inner" id="username_inp"></div></div></div></div><div id="dml_body2"></div></div>'));
      $('.panel-body').hide();
      var checkdml_btn = $('<button class="el-button el-button--primary el-button--mini" style="margin-left:5px;">查询打码量</button>');
      var checkqpai_btn = $('<button class="el-button el-button--primary el-button--mini" style="margin-left:5px;">查询昨日棋牌</button>');
      var checkip_btn = $('<button class="el-button el-button--primary el-button--mini" style="margin-left:5px;">查IP</button>');
      $('#dml_body').append('<table id="dmltable" class="el-table lottery-table table300 compound-table"></table>');
      $('#dml_body2').append($('<p>盈利:<a id="profit"></a> <span style="margin-left:15px;">VIP:<span id="grade"></span></span></p>'));
      $('#dml_body2').append($('<p>今日盈利:<span id="profit_today"></span> <span style="margin-left:15px;">总充值:<span id="total_recharge"></span></span></p>'));
      $('#dml_body2').append($('<p id="qpai"></p>'));
      $('#username_div').append(checkdml_btn);
      $('#username_div').append(checkqpai_btn);
      $('#username_div').append(checkip_btn);
      checkdml_btn.click(function () {
        cleanDiv();
        checkDML();
      });
      checkqpai_btn.click(function () {
        cleanDiv();
        check_qpai();
      })
      checkip_btn.click(function () {
        cleanDiv();
        check_ip();
      });
      $('#profit').click(function () {
        GM_setClipboard($('#profit').text());
      })
    }
  })

})();

function dmlBtn() {
  var dt_btn = $('<button class="el-button el-button--primary el-button--mini">打码量</button>');
  $('.el-form-item.post-btn.el-form-item--small .el-form-item__content').append(dt_btn);
  dt_btn.click(function () {
    $('tr.td-background').remove();
    //$('table.lottery-table').DataTable().clear().destroy();
    //console.log($('table.lottery-table')[0].rows);
    checkDML();
  })
}

function checkDML() {
  var cookie = document.cookie;
  var username = $('#username_inp').val();
  if (username) {
    addDMLtable();
    $.ajax({
      url: 'http://a9cp.a97766.com/v1/transaction/summaryPaymentRecordList',
      dataType: 'json',
      method: 'GET',
      async: true,
      data: {
        userName: username,
        startTime: moment().subtract(50, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss"),
        endTime: moment().add(1, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss"),
        pageNum: 1,
        pageSize: 5,
        state: 1,
        isTest: -1
      },
      xhrFields: {
        withCredentials: true // 这里设置了withCredentials
      },
      contentType: "application/json",
      success: function (successdata, txtStatus, jqXHR) {
        //console.log(successdata);
        var cnt = 1;
        var dml_plus = '101,102,103,104,105,106,107,108,109,401,403,202,206,207';
        var dml_touzu = '302,404';
        var cz = '101,102,103,104,105,107,106,108,109';
        cleanDiv();
        if (successdata.code > 0) {
          $.each(successdata.data.rows, function (idx, data) {
            cnt += 1;
            var startdate = data.gmtCreated;
            var charge_amt = data.amount;
            addDMLrow(data.recordCode, charge_amt);
            $.ajax({
              url: 'http://a9cp.a97766.com/v1/balance/getTransactionRecordsCms',
              dataType: 'json',
              async: true,
              method: 'GET',
              data: {
                userName: username,
                startDate: startdate,
                endDate: moment().add(1, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss"),
                pageNum: 1,
                pageSize: 2000,
                dictionIds: dml_plus,
                isTest: '',
                recordCode: ''
              },
              xhrFields: {
                withCredentials: true // 这里设置了withCredentials
              },
              contentType: "application/json",
              success: function (sdata, textStatus, jqXHR) {
                //console.log(sdata);
                var total = 0;
                if (sdata.code == 1) {
                  $.each(sdata.data.rows, function (idx, row_data) {
                    total += row_data.amount;
                  })
                  $('#dml_' + data.recordCode).html(parseFloat(total).toFixed(2));
                  checkDMLStatus(data.recordCode);
                }
              }
            })
            $.ajax({
              url: 'http://a9cp.a97766.com/v1/balance/getTransactionRecordsCms',
              dataType: 'json',
              async: true,
              method: 'GET',
              data: {
                userName: username,
                async: true,
                startDate: startdate,
                endDate: moment().add(1, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss"),
                pageNum: 1,
                pageSize: 2000,
                dictionIds: dml_touzu,
                isTest: '',
                recordCode: ''
              },
              xhrFields: {
                withCredentials: true // 这里设置了withCredentials
              },
              contentType: "application/json",
              success: function (sdata, textStatus, jqXHR) {
                //console.log(sdata);
                var total = 0;
                if (sdata.code == 1) {
                  $.each(sdata.data.rows, function (idx, row_data) {
                    total += row_data.amount;
                    console.log('tz:', total);
                  })
                  $('#tz_' + data.recordCode).html(parseFloat(total).toFixed(2));
                  checkDMLStatus(data.recordCode);
                }
              }
            })
            $.ajax({
              url: 'http://a9cp.a97766.com/v1/balance/getTransactionRecordsCms',
              async: true,
              method: 'GET',
              data: {
                userName: username,
                startDate: startdate,
                endDate: moment().add(1, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss"),
                pageNum: 1,
                pageSize: 99999,
                dictionIds: cz,
                isTest: '',
                recordCode: ''
              },
              success: function (sdata, textStatus, jqXHR) {
                //console.log(sdata);
                //                       var total = 0;
                if (sdata.code == 1) {
                  //                           $.each(sdata.data.rows, function (idx, row_data) {
                  //                               total += row_data.amount;
                  //                           });
                  var afterbal = sdata.data.rows[sdata.data.total - 1];
                  $('#aftercz_' + data.recordCode).html(parseFloat(afterbal.afterBalance).toFixed(2));
                  //checkDMLStatus(data.recordCode);
                }
              }
            })

            if (cnt > 3) {
              return false;
            }

          })
        }
        else {
          alert(successdata.msg);
        }
        $.ajax({
          url: 'http://a9cp.a97766.com/v1/report/userReport/userHistory',
          async: true,
          method: 'GET',
          data: {
            userNames: username
          },
          success: function (sdata, textStatus, jqXHR) {
            if (sdata.code == 1) {
              var userdata = sdata.data[0];
              if (userdata.profit > 0) {
                $('#profit').css('color', 'hsla(354,60%,75%,1)');
              }
              else {
                $('#profit').css('color', 'hsla(120,33%,75%,1)');
              }
              $('#profit').text(parseFloat(userdata.profit).toFixed(2));
              $('#grade').text(userdata.grade);
              $('#total_recharge').text(parseFloat(userdata.inAmount).toFixed(2));
            }
          }
        });

        $.ajax({
          url: 'http://a9cp.a97766.com/v1/report/userReport',
          async: true,
          method: 'GET',
          data: {
            userName: username,
            startTime: moment().format("YYYY-MM-DD"),
            endTime: moment().format("YYYY-MM-DD"),
            pageNum: 1,
            pageSize: 20
          },
          success: function (sdata, textStatus, jqXHR) {
            if (sdata.code == 1) {
              var userdata = sdata.data.result[0];
              if (userdata.profit > 0) {
                $('#profit_today').css('color', 'hsla(354,60%,75%,1)');
              }
              else {
                $('#profit_today').css('color', 'hsla(120,33%,75%,1)');
              }
              $('#profit_today').text(parseFloat(userdata.profit).toFixed(2));
            }
          }
        })
      }
    })
  }
}

function addDMLtable() {
  //$('#dml_body').html('');
  $('#dmltable').html('');
  $('#dmltable').append($('<thead class="el-table__header"><tr><th class="cell"><span class="cell">充值量</span></th><th class="cell"><span class="cell">充值后余额</span></th><th class="cell"><span class="cell">所需打码量</span></th><th class="cell"><span class="cell">已达打码量</span></th><th class="cell"><span class="cell">状态</span></th></tr></thead>'));
  $('#dmltable').append($('<tbody id="dmltable_body"></tbody>'))
}

function addDMLrow(id, charge_amt) {
  $('#dmltable_body').append($('<tr><td class="cell">' + charge_amt + '</td><td id="aftercz_' + id + '" class="cell"></td><td id="dml_' + id + '" class="cell"></td><td id="tz_' + id + '" class="cell"></td><td id="status_' + id + '" class="cell"></td></tr>'));
}

function checkDMLStatus(id) {
  $('#status_' + id).html('');
  var dml = parseFloat($('#dml_' + id).text());
  var tz = parseFloat($('#tz_' + id).text());
  if (isNaN(dml) || isNaN(tz)) {
    $('#status_' + id).append($('<span style="color:red;">不够!</span>'));
  }
  else if (dml <= tz) {
    $('#status_' + id).append($('<span style="color:green;">足够</span>'));
  }
  else {
    var tmp = dml - tz;
    var dml_ele = $('<a></a>');
    dml_ele.css('color', 'red');
    dml_ele.text('不够!还需 ' + parseFloat(tmp).toFixed(2));
    $('#status_' + id).append(dml_ele);
    dml_ele.click(function () {
      GM_setClipboard('您好,您还需 ' + parseFloat(tmp).toFixed(2) + ' 的流水哦,谢谢');
    });
  }
}

function cleanDiv() {
  $('#profit_today').text('-');
  $('#profit').text('-');
  $('#grade').text('-');
  $('#total_recharge').text('-');
  $('#qpai').html('');
}

function check_qpai() {
  var username = $('#username_inp').val();
  $.ajax({
    url: 'http://a9cp.a97766.com/v1/report/userReport/userHistory',
    method: 'GET',
    data: {
      userNames: username
    },
    success: function (sdata, textStatus, jqXHR) {
      if (sdata.code == 1) {
        console.log(sdata);
        var userdata = sdata.data[0];
        $.ajax({
          url: 'http://a9cp.a97766.com/v1/report/userReport/profitDetail',
          method: 'GET',
          data: {
            startTime: moment().add(-1, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss"),
            endTime: moment().add(-1, 'days').endOf('day').format("YYYY-MM-DD HH:mm:ss"),
            userId: userdata.userId,
          },
          success: function (sdata, textStatus, jqXHR) {
            if (sdata.code == 1) {
              var betdata_arr = sdata.data;
              var qpai_no = ['2001', '2002', '2003', '2004', '2005', '2006'];
              var qpai_bet_total = 0;
              var qpai_profit_total = 0;
              $.each(betdata_arr, function (idx, betdata) {
                if (qpai_no.indexOf(betdata.id) >= 0) {
                  qpai_bet_total += betdata.betAmount;
                  qpai_profit_total += betdata.profit;
                }
              })
              qpai_bet_total = parseFloat(qpai_bet_total).toFixed(2);
              qpai_profit_total = parseFloat(qpai_profit_total).toFixed(2);
              $('#dmltable').html('');
              $('#dmltable').append($('<p></p>').text('棋牌总投注:' + parseFloat(qpai_bet_total).toFixed(2)));
              $('#dmltable').append($('<p></p>').text('棋牌总盈利:' + parseFloat(qpai_profit_total).toFixed(2)));
              $('#dmltable').append($('<p>棋牌得意送: <span id="qpdy"></span></p>'));
              $('#dmltable').append($('<p>棋牌亏损送: <span id="qpks"></span></p>'));
              var dy_bonus = 0;
              var ks_bonus = 0;
              $.each(qpai_dy.bonus, function (idx, bdata) {
                if (bdata.max) {
                  if (qpai_bet_total >= bdata.min && qpai_bet_total < bdata.max) {
                    dy_bonus = bdata.amt;
                  }
                }
                else {
                  if (qpai_bet_total >= bdata.min) {
                    dy_bonus = bdata.amt;
                  }
                }

              });
              if (qpai_profit_total < -100) {
                var tmp_amt = Math.abs(qpai_profit_total);
                $.each(qpai_ks.bonus, function (idx, b2data) {
                  if (b2data.max) {
                    if (tmp_amt >= b2data.min && tmp_amt < b2data.max) {
                      ks_bonus = tmp_amt * b2data.amt;
                    }
                  }
                  else {
                    if (tmp_amt >= b2data.min) {
                      ks_bonus = tmp_amt * b2data.amt;
                    }
                  }
                })
              }
              $('#qpdy').text(dy_bonus);
              $('#qpks').text(parseFloat(ks_bonus).toFixed(2));
            }
          }
        });
      }
    }
  });
}

function check_ip() {
  var username = $('#username_inp').val().toLowerCase();
  $('#dmltable').html('');
  $.ajax({
    url: 'http://a9cp.a97766.com/v1/users/loginLog',
    method: 'GET',
    data: {
      userName: username,
      pageNum: 1,
      pageSize: 30,
      startTime: moment().add(-80, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss"),
      endTime: moment().add(1, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss")
    },
    success: function (sdata, textStatus, jqXHR) {
      var ip_arr = sdata.data.result;
      var checkip_arr = [];
      var sameuserIP = [];
      var sameipuserinfo = [];
      $.each(ip_arr, function (idx, ipdata) {
        if (checkip_arr.indexOf(ipdata.loginIp) < 0) {
          checkip_arr.push(ipdata.loginIp);
        }
      })
      $.each(checkip_arr, function (idx, ipx) {
        console.log(ipx);
        $.ajax({
          url: 'http://a9cp.a97766.com/v1/users/loginLog',
          method: 'GET',
          data: {
            ip: ipx,
            pageNum: 1,
            pageSize: 30,
            startTime: moment().add(-80, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss"),
            endTime: moment().add(1, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss")
          },
          success: function (ssdata, textStatus, jqXHR) {
            if (ssdata.code == 1) {
              $.each(ssdata.data.result, function (idx, userip) {
                if (userip.userName != username) {
                  if (sameuserIP.indexOf(userip.userName) < 0) {
                    sameuserIP.push(userip.userName);
                    sameipuserinfo.push(userip);
                  }
                }
              })
            }
          }
        });
      });
      if (sameipuserinfo.length > 0) {
        writeTT('IP多账号', '-', 'red');
      }
      else {
        writeTT('没IP多账号', '-', 'green');
      }
      $.each(sameipuserinfo, function (idx, user) {
        var agents = [user.userName];
        $.ajax({
          url: 'http://a9cp.a97766.com/v1/users/getUserInfo',
          method: 'GET',
          data: {
            userId: user.userId
          },
          success: function (sssdata, textStatus, jqXHR) {
            if (sssdata.code == 1) {
              console.log('agent', sssdata.data.agentInfoList)
              $.each(sssdata.data.agentInfoList.reverse(), function (idx, agentInfo) {
                if (agentInfo.userName != 'a9cptotal') {
                  agents.push(agentInfo.userName);
                }
              })
            }
          }
        })
        writeTT(agents.join(' < '));
      })
      console.log(sameuserIP);
    }
  });
}
var qpai_dy = {
  name: '棋牌得意金',
  bonus: [{
      min: 1000,
      max: 10000,
      amt: 8
    },
    {
      min: 10000,
      max: 30000,
      amt: 28
    },
    {
      min: 30000,
      max: 50000,
      amt: 38
    },
    {
      min: 50000,
      max: 100000,
      amt: 58
    },
    {
      min: 100000,
      max: 500000,
      amt: 88
    },
    {
      min: 500000,
      max: 1000000,
      amt: 588
    },
    {
      min: 1000000,
      max: 5000000,
      amt: 1888
    },
    {
      min: 5000000,
      amt: 5888
    },
  ],
};

var qpai_ks = {
  name: '棋牌亏损金',
  bonus: [{
      min: 100,
      max: 1000,
      amt: 0.01
    },
    {
      min: 1000,
      max: 10000,
      amt: 0.02
    },
    {
      min: 10000,
      max: 50000,
      amt: 0.03
    },
    {
      min: 50000,
      max: 100000,
      amt: 0.05
    },
    {
      min: 100000,
      amt: 0.07
    }
  ],
};

function writeTT(text, amt, txt_clr, amt_clr) {
  var txt = text;
  var p = $('<p></p>');
  p.text(txt);
  if (!isNaN(amt)) {
    var span = $('<span>').text(parseFloat(amt).toFixed(2))
    p.append(':');
    p.append(span);
  }
  if (txt_clr) {
    p.css('color', txt_clr);
  }
  if (amt_clr) {
    span.css('color', amt_clr);
  }

  $('#dmltable').append(p);
}