akznuts / 500w ht

// ==UserScript==
// @name         500w ht
// @namespace    http://tampermonkey.net/
// @version      0.5.4
// @description  500w ht shortcut
// @license      MIT
// @author       You
// @match        https://cp500w2.dggamesmanager.net/*
// @grant        GM_getValue
// @grant        GM_listValues
// @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
// @run-at       document-idle
// ==/UserScript==

var dml = 1;
(function () {
  'use strict';
  setTimeout(function () {
    console.log(moment().startOf('day').format("YYYY-MM-DD HH:mm:ss"));
    console.log(moment().endOf('day').format("YYYY-MM-DD HH:mm:ss"));
    var main = $('main.content.app-main');
    var inp = $('<input type="text" id="memberid">');
    var checkBtn = $('<button class="ant-btn btn-search ant-btn-button">CheckDetail</button>');
    var jlguanli = $('<button class="ant-btn btn-search ant-btn-button">CheckDetail</button>');
    var sjtongdao = $('<button class="ant-btn btn-search ant-btn-button">升级通道</button>');
    var dml_opt = $('<select></select>');
    var cjBtn = $('<button class="ant-btn btn-search ant-btn-button">彩金</button>');
    var showEgg = $('<button>Show Egg</button>');
    var clearBtn = $('<button class="ant-btn btn-search ant-btn-button">Clear</button>');
    var tmp_div = $('<div id="tmp_div" ></div>');
    dml_opt.append($('<option value="1">1</option>'));
    dml_opt.append($('<option value="2">2</option>'));
    dml_opt.append($('<option value="5">5</option>'));
    dml_opt.append($('<option value="10">10</option>'));
    main.prepend(tmp_div);
    main.prepend(dml_opt);
    main.prepend(cjBtn);
    main.prepend(showEgg);
    main.prepend(sjtongdao);
    main.prepend(clearBtn);
    main.prepend(jlguanli);
    main.prepend(inp);
    clearBtn.click(function () {
      cleanUpDiv();
    });
    jlguanli.click(function () {
      getMoneyFlow();
    })
    showEgg.click(function () {
      eggeggBonus();
    })
    sjtongdao.click(function(){
        getUserData(inp.val());
    })
      dml_opt.change(function(){
          dml = parseFloat(dml_opt.val());
          console.log(dml);
      });
    cjBtn.click(function(){
        var member_id = inp.val();
      var userdata = JSON.parse(window.localStorage.getItem('userdata'));
      var auth = JSON.parse(window.localStorage.getItem('auth'));
        $.ajax({
            url: 'https://cp500w2.dggamesmanager.net/admin/Lottery/getOrderList',
            dataType: 'json',
            method: 'POST',
            data: JSON.stringify({
                startDate: moment().add(-1, 'days').startOf('day').format("YYYY-MM-DD HH:mm:ss"),
                endDate: moment().add(-1, 'days').endOf('day').format("YYYY-MM-DD HH:mm:ss"),
                username: member_id,
                searchType: 2,
                operatorId: userdata.uid,
                searchStatus: 1,

            }),
            contentType: "application/json",
            headers: {
                'auth-token': auth.token
            },
            success: function (successData, txtStatus, jqXHR) {
                console.log(successData);
                if (successData.errorcode == 200) {
                    btnCreate(successData.data.allBetAmount, dy_btn);
                }
            }
        });
        $.ajax({
            url: 'https://cp500w2.dggamesmanager.net/admin/Game/getOrderList',
            dataType: 'json',
            method: 'POST',
            data: JSON.stringify({
                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"),
                userName: member_id,
                platformId: 3,
                operatorId: userdata.uid,
                gameNames: [],
            }),
            contentType: "application/json",
            headers: {
                'auth-token': auth.token
            },
            success: function (successData, txtStatus, jqXHR) {
                console.log(successData);
                if (successData.errorcode == 200) {
                    btnCreate(successData.data.totalBetAmount, qpdy_btn);
                    if(parseFloat(successData.data.totalGainAmount) > 0){
                        btnCreate(successData.data.totalGainAmount, qpks_btn);
                    }
                }
            }
        });
        $.ajax({
            url: 'https://cp500w2.dggamesmanager.net/admin/Game/getOrderList',
            dataType: 'json',
            method: 'POST',
            data: JSON.stringify({
                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"),
                userName: member_id,
                operatorId: userdata.uid,
                gameNames: [],
            }),
            contentType: "application/json",
            headers: {
                'auth-token': auth.token
            },
            success: function (successData, txtStatus, jqXHR) {
                console.log(successData);
                if (successData.errorcode == 200) {
                    if(parseFloat(successData.data.totalGainAmount) > 0){
                        btnCreate(successData.data.totalGainAmount, dzks_btn);
                    }
                }
            }
        });
    })
    checkBtn.click(function () {
      var member_id = inp.val();
      var getuserdata_url = 'https://cp500w2.dggamesmanager.net/admin/User/getUserExtendInfo';
      var getpaydata1_url = 'https://cp500w2.dggamesmanager.net/admin/UserRechargeRecord/getCompanyList';
      var adddata_url = 'https://cp500w2.dggamesmanager.net/admin/UserRechargeRecord/addSystem';

      var userdata = JSON.parse(window.localStorage.getItem('userdata'));
      var auth = JSON.parse(window.localStorage.getItem('auth'));

      $.ajax({
            url: 'https://cp500w2.dggamesmanager.net/admin/Lottery/getOrderList',
            dataType: 'json',
            method: 'POST',
            data: JSON.stringify({
                startDate: moment().startOf('day').format("YYYY-MM-DD HH:mm:ss"),
                endDate: moment().endOf('day').format("YYYY-MM-DD HH:mm:ss"),
                username: member_id,
                searchType: 2,
                operatorId: userdata.uid,
                searchStatus: 1,

            }),
            contentType: "application/json",
            headers: {
                'auth-token': auth.token
            },
            success: function (successData, txtStatus, jqXHR) {
                console.log('test');
                console.log(successData);
            }
        });

      var postdata = {
        accountValue: member_id,
        startDate: moment().startOf('day').format("YYYY-MM-DD HH:mm:ss"),
        endDate: moment().endOf('day').format("YYYY-MM-DD HH:mm:ss"),
        operatorId: userdata.uid,
        dateType: 1,
        accountType: 1,
      };
      $.ajax({
        url: getpaydata1_url,
        dataType: 'json',
        method: 'POST',
        data: JSON.stringify(postdata),
        contentType: "application/json",
        headers: {
          'auth-token': auth.token
        },
        success: function (successData, txtStatus, jqXHR) {
          console.log(successData);
          if (successData.errorcode == 200) {
            var ret_data = successData.data;
            console.log(ret_data);
            // todo create button for promotions
            var success_record = null;
            var success_record_amt = 0;
            var raise_stop = false;
            $.each(ret_data.list, function (idx, list) {
              //console.log('status', list.status);
              if (list.status == 1) {
                success_record = list;
                success_record_amt += 1;
              }
              else if (list.status == 2) {

              }
              else {
                raise_stop = true;
              }
            });

            if (raise_stop) {}
            else {
              if (success_record_amt > 1) {
                // todo here is to exit
                tmp_div.html('There is ' + success_record_amt + ' success record.');
              }
              else if (success_record_amt == 1) {
                // todo here is to add calculation & btn
                var allbonus_btn = getAllBonusBtn(parseFloat(success_record.amount))
                var sc_1_btn = getfirstandonepercBtn(parseFloat(success_record.amount));
                var merd_btn = getMerdekaBonusBtn(parseFloat(success_record.amount));
                var one_perc_btn = getonepercBtn(parseFloat(success_record.amount));
                tmp_div.html('');
                //tmp_div.prepend(allbonus_btn);
                //tmp_div.prepend(merd_btn);
                tmp_div.prepend(one_perc_btn);
                tmp_div.prepend(sc_1_btn);
              }
              else {
                // todo here is to alert there is no record
                tmp_div.html('There is no record');
              }
            }
            //console.log(ret_data.list[0]);

          }
        }
      });

    });
  }, 1000);
})();

function oneperc(amount) {
  amount = parseFloat(amount);
  return amount * 0.01;
}

function submitBonus(charge_amt, remark, traffic_damaliang, member_id, callback) {
  var userdata = JSON.parse(window.localStorage.getItem('userdata'));
  var auth = JSON.parse(window.localStorage.getItem('auth'));
  if (!member_id) {
    member_id = $('#memberid').val();
  }
  $.ajax({
    url: 'https://cp500w2.dggamesmanager.net/admin/User/getUserExtendInfo',
    dataType: 'json',
    method: 'POST',
    data: JSON.stringify({
      operatorId: userdata.uid,
      username: member_id
    }),
    contentType: "application/json",
    headers: {
      'auth-token': auth.token
    },
    success: function (successdata, txtStatus, jqXHR) {
      if (successdata.errorcode == 200) {
        var member_data = successdata.data[0];
        var pdata = {
          "accountBalance": member_data.accountBalance,
          "amount": "",
          "operationType": 2,
          "realname": member_data.realname,
          "reason": "",
          "discountRemark": "",
          "rechargeDiscount": charge_amt,
          "remark": remark,
          "trafficAmount": traffic_damaliang,
          "ulId": member_data.ulId,
          "ulName": member_data.ulName,
          "username": member_data.username,
          "operatorId": userdata.uid
        };
        $.ajax({
          url: 'https://cp500w2.dggamesmanager.net/admin/UserRechargeRecord/addSystem',
          dataType: 'json',
          method: 'POST',
          data: JSON.stringify(pdata),
            async: false,
          contentType: "application/json",
          headers: {
            'auth-token': auth.token
          },
          success: function (sdata, txtsts, jqxhr) {
            console.log(sdata);
            if (callback) {
              callback(sdata);
            }
          },
        })
      }
      else {
        alert('Failed');
      }
    }
  })
}

function cleanUpDiv() {
  $('#tmp_div').html('');
  $('#tmp_div2').remove();
  $('#memberid').val('');
}

function eggeggBonus() {
  var main = $('main.content.app-main');
  var div = $('#tmp_div');
  var div2 = $('<div id="tmp_div2"></div>')
  var txtarea = $('<textarea></textarea>');
  var sendBtn = $('<button>Create Egg egg</button>');
  div.append(txtarea);
  div.append(sendBtn);

  sendBtn.click(function () {
    var egg_arr = txtarea.val();
    var egg_json_arr = JSON.parse(egg_arr);
    var interval_cnt = 1;
    $.each(egg_json_arr, function (idx, egg_data) {
      var created_btn = $('<button>' + egg_data.userid + '(' + egg_data.amount + ')' + '</button>');
      created_btn.click(function () {
        submitBonus(egg_data.amount, '蛋蛋', egg_data.amount, egg_data.userid, function (sdata) {
            if(sdata.errorcode == 200){
                created_btn.remove();
            } else {
                alert(sdata.message);
            }
        });
      });
      div2.append(created_btn);
    });
    txtarea.val('');
  });
  div.append(div2);
}

function getMoneyFlow(member_id) {
  var getuserdata_url = 'https://cp500w2.dggamesmanager.net/admin/User/getUserExtendInfo';
  var getflow_url = 'https://cp500w2.dggamesmanager.net/admin/UserAccountRecord/getAccountList';
  var userdata = JSON.parse(window.localStorage.getItem('userdata'));
  var auth = JSON.parse(window.localStorage.getItem('auth'));
  var tmp_div = $('#tmp_div');
  if (!member_id) {
    member_id = $('#memberid').val();
  }

  $.ajax({
    url: getflow_url,
    dataType: 'json',
    method: 'POST',
    data: JSON.stringify({
      operatorId: userdata.uid,
      username: member_id,
      dateType: 1,
      endDate: moment().endOf('day').format("YYYY-MM-DD HH:mm:ss"),
      num: 30,
      page: 1,
      searchStatus: 1,
      startDate: moment().startOf('day').format("YYYY-MM-DD HH:mm:ss"),
      transactionType: [1, 9, 14],
      status: '',
      actionType: ''
    }),
    contentType: "application/json",
    headers: {
      'auth-token': auth.token
    },
    success: function (sdata, txtsts, jqxhr) {
      console.log(sdata);
      var total = sdata.allAmount;
      console.log(sdata.data.list);
      if (sdata.errorcode == 200) {
        var ret_data = sdata.data;
        //console.log(ret_data);
        // todo create button for promotions
        var success_record = ret_data.list[0];
        var success_record_amt = ret_data.list.length;
        var raise_stop = false;
        /*
                        $.each(ret_data.list,function(idx, list){
            //console.log('status', list.status);
            if(list.status == 1){
                success_record = list;
                success_record_amt += 1;
            } else if (list.status == 2){

            } else { raise_stop = true;}
        });

        */

        if (raise_stop) {}
        else {
          if (success_record_amt == 0) {
            tmp_div.html('There is no record');
          }
          else {
            // var sc_1_btn = getfirstandonepercBtn(parseFloat(success_record.amount));
            // var one_perc_btn = getonepercBtn(parseFloat(success_record.amount));
            // var sc_btn = getfirstBtn(parseFloat(success_record.amount));
            // var ylcj_btn = getylcjBtn(parseFloat(success_record.amount));
            console.log(success_record);
            tmp_div.html('');
            tmp_div.append('<p>There is ' + success_record_amt + ' success record. it takes the newest record to calculate <span style="color:green;font-size:20px;">' + success_record.transactionType + '</span></p>');
            //tmp_div.prepend(allbonus_btn);
            //tmp_div.prepend(merd_btn);
            // tmp_div.append(sc_1_btn);
            // tmp_div.append(sc_btn);
            // tmp_div.append(one_perc_btn);
            // tmp_div.append(ylcj_btn);
            btnArrCreate(parseFloat(success_record.amount), success_record.transactionType);
          }
        }
        //console.log(ret_data.list[0]);

      }
    }
  })
}

function getUserData(member_id) {
  var getuserdata_url = 'https://cp500w2.dggamesmanager.net/admin/User/getUserList';
  var edituserlevel_url = 'https://cp500w2.dggamesmanager.net/admin/User/editUserSelfLevel';
  var userdata = JSON.parse(window.localStorage.getItem('userdata'));
  var auth = JSON.parse(window.localStorage.getItem('auth'));
  var tmp_div = $('#tmp_div');
  if (!member_id) {
    member_id = $('#memberid').val();
  }

  $.ajax({
    url: getuserdata_url,
    dataType: 'json',
    method: 'POST',
    data: JSON.stringify({
      operatorId: userdata.uid,
      username: member_id,
      num: 30,
      page: 1,
    }),
    contentType: "application/json",
    headers: {
      'auth-token': auth.token
    },
    success: function (sdata, txtsts, jqxhr) {
      console.log(sdata);
      var total = sdata.allAmount;
//       console.log(sdata.data.list);
      if (sdata.errorcode == 200) {
        var ret_data = sdata.data;
        var success_record = ret_data.list[0];
        var success_record_amt = ret_data.list.length;
        var raise_stop = false;

        if (raise_stop) {}
        else {
          if (success_record_amt == 0) {
            tmp_div.html('There is no record');
          }
          else {
            console.log(success_record);
              $.ajax({
                  url: edituserlevel_url,
                  dataType: 'json',
                  method: 'POST',
                  data: JSON.stringify({
                      operatorId: userdata.uid,
                      uid: [success_record.uid],
                      ulId: 7
                  }),
                  contentType: "application/json",
                  headers: {
                      'auth-token': auth.token
                  },
                  success: function (sdata, txtsts, jqxhr) {
                      console.log(sdata);
                      if(sdata.data){
                          tmp_div.html('');
                          tmp_div.append('<p>成功升级通道</p>');
                      }
                  }})
          }
        }

      }
    }
  })
}



var btn_arr = [{
    name: '首冲+1%',
    bonus: [{
        min: 500,
        max: 3000,
        amt: 18
      },
      {
        min: 3000,
        max: 5000,
        amt: 58
      },
      {
        min: 5000,
        max: 10000,
        amt: 88
      },
      {
        min: 10000,
        max: 20000,
        amt: 158
      },
      {
        min: 20000,
        max: 50000,
        amt: 358
      },
      {
        min: 50000,
        max: 100000,
        amt: 668
      },
      {
        min: 100000,
        max: 200000,
        amt: 1888
      },
      {
        min: 200000,
        max: 500000,
        amt: 5888
      },
      {
        min: 500000,
        amt: 18888
      },
    ],
    oneperc: true,
    type: ['公司入款', '人工入款']
  },
  {
    name: '首冲',
    bonus: [{
        min: 500,
        max: 3000,
        amt: 18
      },
      {
        min: 3000,
        max: 5000,
        amt: 58
      },
      {
        min: 5000,
        max: 10000,
        amt: 88
      },
      {
        min: 10000,
        max: 20000,
        amt: 158
      },
      {
        min: 20000,
        max: 50000,
        amt: 358
      },
      {
        min: 50000,
        max: 100000,
        amt: 668
      },
      {
        min: 100000,
        max: 200000,
        amt: 1888
      },
      {
        min: 200000,
        max: 500000,
        amt: 5888
      },
      {
        min: 500000,
        amt: 18888
      },
    ],
    oneperc: false,
    type: ['公司入款', '在线充值', '人工入款']
  },
  {
    name: '1%',
    bonus: [],
    oneperc: true,
    type: ['公司入款', '人工入款']
  },
  {
    name: '引流彩金',
    bonus: [{
        min: 18,
        max: 100,
        amt: 18
      },
      {
        min: 100,
        max: 500,
        amt: 28
      },
      {
        min: 500,
        max: 1000,
        amt: 58
      },
      {
        min: 1000,
        max: 5000,
        amt: 88
      },
      {
        min: 5000,
        max: 10000,
        amt: 288
      },
      {
        min: 10000,
        max: 50000,
        amt: 588
      },
      {
        min: 50000,
        max: 100000,
        amt: 2888
      },
      {
        min: 100000,
        amt: 5888
      },
    ],
    oneperc: false,
    type: ['公司入款', '在线充值', '人工入款']
  }
]

var dy_btn = {
    name: '得意彩金',
    bonus: [{
        min: 1000,
        max: 5000,
        amt: 8
      },
      {
        min: 5000,
        max: 30000,
        amt: 18
      },
      {
        min: 30000,
        max: 100000,
        amt: 88
      },
      {
        min: 100000,
        max: 300000,
        amt: 188
      },
      {
        min: 300000,
        max: 500000,
        amt: 388
      },
      {
        min: 500000,
        max: 1000000,
        amt: 888
      },
      {
        min: 1000000,
        max: 3000000,
        amt: 1888
      },
      {
        min: 3000000,
        max: 5000000,
        amt: 3888
      },
      {
        min: 5000000,
        amt: 8888
      },
    ],
  }

var qpdy_btn = {
    name: '棋牌得意',
    bonus: [{
        min: 1000,
        max: 5000,
        amt: 8
      },
      {
        min: 5000,
        max: 10000,
        amt: 18
      },
      {
        min: 10000,
        max: 50000,
        amt: 38
      },
      {
        min: 50000,
        max: 100000,
        amt: 158
      },
      {
        min: 100000,
        max: 500000,
        amt: 388
      },
      {
        min: 500000,
        max: 1000000,
        amt: 888
      },
      {
        min: 1000000,
        max: 5000000,
        amt: 1888
      },
      {
        min: 5000000,
        amt: 5888
      },
    ],
  }

var qpks_btn = {
    name: '棋牌亏损',
    max: 8888,
    is_perc: true,
    bonus: [
        {
            min: 100,
            max: 1000,
            amt: 0.01
        },
        {
            min: 1000,
            max: 5000,
            amt: 0.02
        },
        {
            min: 5000,
            max: 10000,
            amt: 0.03
        },
        {
            min: 10000,
            max: 111111,
            amt: 0.05
        },
        {
            min: 111111,
            amt: 0.08
        },
    ],
}

var dzks_btn = {
    name: '电子亏损金',
    max: 1388,
    is_perc: true,
    bonus: [
        {
            min: 500,
            max: 3000,
            amt: 0.03
        },
        {
            min: 3000,
            max: 10000,
            amt: 0.02
        },
        {
            min: 10000,
            amt: 0.05
        },
    ],
}

function btnArrCreate(recharge_amt, transacType) {
  var tmp_div = $('#tmp_div');
  $.each(btn_arr, function (idx, btn) {
    var created_btn = $('<button></button>');
    var name = btn.name;
    var onep = 0;
    var bonus = 0;
    if (btn.oneperc) {
      onep = oneperc(recharge_amt);
    }
    $.each(btn.bonus, function (idx, bdata) {
      //console.log(bdata, recharge_amt);
      if (bdata.max) {
        if (recharge_amt >= bdata.min && recharge_amt < bdata.max) {
          bonus = bdata.amt;
          return false;
        }
      }
      else {
        if (recharge_amt >= bdata.min) {
          bonus = bdata.amt;
          return false;
        }
      }

    })
    var charge_amt = (bonus + onep).toFixed(2);
    created_btn.text(name + ' (' + charge_amt + ')');
    created_btn.click(function () {
      submitBonus(charge_amt, name, charge_amt*dml);
      cleanUpDiv();
    })
    if (btn.type.indexOf(transacType) >= 0) {
      tmp_div.append(created_btn);
    }
  })
}


function btnCreate(amt, btn_data) {
  var tmp_div = $('#tmp_div');
    var created_btn = $('<button></button>');
    var charge_amt = 0;
        var name = btn_data.name;

    $.each(btn_data.bonus, function (idx, bdata) {
      //console.log(bdata, recharge_amt);
      if (bdata.max) {
        if (amt >= bdata.min && amt < bdata.max) {
            if(btn_data.is_perc){
                charge_amt = amt * bdata.amt;
            }else{
                charge_amt = bdata.amt;
            }
          return false;
        }
      }
      else {
        if (amt >= bdata.min) {
            if(btn_data.is_perc){
                charge_amt = amt * bdata.amt;
            }else{
                charge_amt = bdata.amt;
            }
          return false;
        }
      }
    })
    if(btn_data.max && charge_amt > btn_data.max){
        charge_amt = btn_data.max;
    }
    charge_amt = charge_amt.toFixed(2);
    created_btn.text(name + ' (' + charge_amt + ')');
    created_btn.click(function () {
      submitBonus(charge_amt, name, charge_amt);
      cleanUpDiv();
    })
    tmp_div.append(created_btn);
}