Robot.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. defined('IN_WEB') or die('Include Error!');
  3. /**
  4. * 机器人相关
  5. */
  6. class Robot
  7. {
  8. private $key = 'RDSRBTL';
  9. protected $smallBlind = array(50, 100, 200, 500, 1000, 2000, 3000, 5000, 10000, 20000);//小盲
  10. protected $tableListArr = array();
  11. public function __construct()
  12. {
  13. $this->tableListArr[50] = array( 1 => 101, 2 => 111, 3 => 121, 4 => 131);
  14. $this->tableListArr[100] = array( 1 => 102, 2 => 112, 3 => 122, 4 => 132);
  15. $this->tableListArr[200] = array( 1 => 103, 2 => 113, 3 => 123, 4 => 133);
  16. $this->tableListArr[500] = array( 1 => 104, 2 => 114, 3 => 124, 4 => 134);
  17. $this->tableListArr[1000] = array( 1 => 105, 2 => 115, 3 => 125, 4 => 135);
  18. $this->tableListArr[2000] = array( 1 => 106, 2 => 116, 3 => 126, 4 => 136);
  19. $this->tableListArr[3000] = array( 1 => 201, 2 => 211, 3 => 221, 4 => 231);
  20. $this->tableListArr[5000] = array( 1 => 202, 2 => 212, 3 => 222, 4 => 232);
  21. $this->tableListArr[10000] = array( 1 => 203, 2 => 213, 3 => 223, 4 => 233);
  22. $this->tableListArr[20000] = array( 1 => 204, 2 => 214, 3 => 224, 4 => 234);
  23. $this->tableListArr[] = array( 1 => 151, 2 => 161, 3 => 171, 4 => 181);//第二组开始
  24. $this->tableListArr[] = array( 1 => 152, 2 => 162, 3 => 172, 4 => 182);
  25. $this->tableListArr[] = array( 1 => 153, 2 => 163, 3 => 173, 4 => 183);
  26. $this->tableListArr[] = array( 1 => 154, 2 => 164, 3 => 174, 4 => 184);
  27. $this->tableListArr[] = array( 1 => 155, 2 => 165, 3 => 175, 4 => 185);
  28. $this->tableListArr[] = array( 1 => 156, 2 => 166, 3 => 176, 4 => 186);
  29. }
  30. /**
  31. * 机器人场次列表
  32. */
  33. public function getlist($param)
  34. {
  35. $data = array();
  36. $smallBlind = oo::functions()->uint($param['smallblind']);
  37. if (!in_array($smallBlind, $this->smallBlind)) {
  38. return json_encode($data);
  39. }
  40. $levelList = array();//level列表
  41. foreach ($this->tableListArr[$smallBlind] as $level) {
  42. array_push($levelList, $level);
  43. }
  44. //玩家信息
  45. $uidList = $uidLevel = array();
  46. $i = 1;
  47. foreach ($levelList as $v) {
  48. $rediskey = $this->key.$v;
  49. $rs = oo::commonOprRedis('robot')->sMembers($rediskey);
  50. if( empty($rs) ){
  51. continue;
  52. }
  53. foreach ($rs as $info) {
  54. $temp = explode('|', $info);
  55. array_push($uidList, $temp[0]);
  56. $uidLevel[$temp[0]] = $v;
  57. }
  58. if( $i%5 == 0 ){
  59. usleep(100);
  60. }
  61. $i++;
  62. }
  63. //获取玩家筹码信息
  64. foreach ($uidList as $uid) {
  65. $property = oo::commonOprModel('member')->getUserAssetsInfo($uid);
  66. if( empty($property) ){
  67. continue;
  68. }
  69. $data[$uid]['money'] = $property['money'];
  70. $data[$uid]['level'] = $uidLevel[$uid];
  71. }
  72. return json_encode($data);
  73. }
  74. /**
  75. * 机器人批量加钱
  76. */
  77. public function actionmultiRobotmoney($param)
  78. {
  79. $smallBlind = oo::functions()->uint($param['smallBlind']);
  80. $addMoney = oo::functions()->uint($param['robotmoney']);
  81. oo::commonOprModel('robot')->autoAddMoney($smallBlind, $addMoney);
  82. return 1;
  83. }
  84. /**
  85. * 机器人输赢统计
  86. * @param $param
  87. * @return string
  88. */
  89. public function loseWin($param)
  90. {
  91. $stime = oo::functions()->uint($param['stime']);
  92. $etime = oo::functions()->uint($param['etime']);
  93. //写入时间是后一天,所以查询时相应加一天
  94. if(empty($stime)){
  95. $stime = strtotime("0:0:0");
  96. $sdate = date('Ymd');
  97. }else{
  98. $sdate = date('Ymd', $stime);
  99. // $stime = strtotime("$date +1 day ");
  100. }
  101. if(empty($etime)){
  102. $etime = strtotime("23:59:59");
  103. $edate = date('Ymd');
  104. }else{
  105. $edate = date('Ymd', $etime);
  106. // $etime = strtotime("$date +1 day ");
  107. }
  108. $bcreportTable = otable::robotLoseWin();
  109. $where = " date >= {$sdate} ";
  110. $where .= " AND date <= {$edate} ";
  111. $sql = "SELECT * FROM (
  112. SELECT gameid, level, sum(effective_bet) as effective_bet, sum(record_num) as record_num,sum(total_num) as total_num, sum(wincoins) as wincoins, base, robot_type, fee
  113. FROM {$bcreportTable}
  114. WHERE {$where} GROUP BY gameid, base ORDER BY gameid, level DESC) AS aa
  115. ORDER BY gameid, base ASC";
  116. $ret = oo::commonOprDb('common')->getAll($sql , 1);
  117. $data['list'] = $ret;
  118. return json_encode($data);
  119. }
  120. /**
  121. * 机器人输赢统计
  122. * @param $param
  123. * @return string
  124. */
  125. public function loseWinTotalByDate($param)
  126. {
  127. $stime = oo::functions()->uint($param['stime']);
  128. $etime = oo::functions()->uint($param['etime']);
  129. //写入时间是后一天,所以查询时相应加一天
  130. if(empty($stime)){
  131. $stime = strtotime("0:0:0");
  132. $sdate = date('Ymd');
  133. }else{
  134. $sdate = date('Ymd', $stime);
  135. // $stime = strtotime("$date +1 day ");
  136. }
  137. if(empty($etime)){
  138. $etime = strtotime("23:59:59");
  139. $edate = date('Ymd');
  140. }else{
  141. $edate = date('Ymd', $etime);
  142. // $etime = strtotime("$date +1 day ");
  143. }
  144. $bcreportTable = otable::robotLoseWin();
  145. $where = " date >= {$sdate} ";
  146. $where .= " AND date <= {$edate} ";
  147. $sql = "SELECT date, sum(wincoins) as wincoins
  148. FROM {$bcreportTable}
  149. WHERE {$where} GROUP BY date";
  150. $ret = oo::commonOprDb('common')->getAll($sql , 1);
  151. $list = [];
  152. foreach ($ret as $val){
  153. $list[$val['date']] = $val['wincoins'] ?? 0;
  154. }
  155. $data['list'] = $list;
  156. return json_encode($data);
  157. }
  158. }