robot.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. /**
  3. * 机器人相关
  4. */
  5. defined('IN_WEB') or die('Include Error!');
  6. class ModelRobot{
  7. /**
  8. * 获得全部机器人
  9. * @return array
  10. * Created by: Owen
  11. * Created on: 2019/7/24 17:47
  12. * Description:
  13. */
  14. public function getAllRobot(){
  15. $userList = oo::commonOprRedis('common')->get(okeys::GetRobotUserList());
  16. if(!empty($userList)){
  17. $userList = json_decode($userList,true);
  18. if(!empty($userList)&&is_array($userList)){
  19. return $userList;
  20. }
  21. }
  22. $tb = otable::Robot();
  23. $sql = "SELECT * FROM {$tb} WHERE 1";
  24. $ret = oo::commonOprDb('api')->getAll($sql,1);
  25. $robot = [];
  26. foreach ($ret as $row){
  27. $robot[] = $row['uid'];
  28. }
  29. oo::commonOprRedis('common')->set(okeys::GetRobotUserList(),json_encode($robot));
  30. return $robot;
  31. }
  32. /**
  33. * 设置机器人金钱排行
  34. * Created by: Owen
  35. * Created on: 2019/7/24 17:47
  36. * Description:
  37. */
  38. public function rankRobot(){
  39. $robot = self::getAllRobot();
  40. $InUid = implode(',',$robot);
  41. $ghtable = otable::gh_gameserver(1);
  42. $sql = "SELECT * FROM {$ghtable} WHERE mid IN ({$InUid})";
  43. $ret = oo::commonOprDb('ghgames')->getAll($sql,MYSQLI_ASSOC);
  44. foreach ($ret as $row){
  45. oo::commonOprRedis('common')->zAdd(okeys::rankRobot(),$row['money'],$row['mid']);
  46. }
  47. }
  48. }