GameServerLogic.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. /**
  3. * GameServerLogic.php UTF-8
  4. *
  5. *
  6. * @date : 2018/5/29 17:09
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : luowei <lw@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\logic\game;
  13. use huo\model\common\CommonModel;
  14. use huo\model\game\GameserverModel;
  15. use huolib\constant\GameConst;
  16. use huolib\tool\Time;
  17. class GameServerLogic extends CommonModel {
  18. /**
  19. * @param array $param
  20. *
  21. * @return array
  22. */
  23. protected function getWhere($param = []) {
  24. $_map = [];
  25. if (!empty($param['app_id'])) {
  26. if (is_array($param['app_id'])) {
  27. $_map['app_id'] = ['in', $param['app_id']];
  28. } else {
  29. $_map['app_id'] = $param['app_id'];
  30. }
  31. }
  32. if (!empty($param['server_type'])) {
  33. switch ($param['server_type']) {
  34. case GameConst::GAME_SERVER_TODAY:
  35. $_map['start_time'] = ['between', Time::today()];
  36. break;
  37. case GameConst::GAME_SERVER_WILL:
  38. $_map['start_time'] = ['>', time()];
  39. break;
  40. case GameConst::GAME_SERVER_OPENED:
  41. default:
  42. $_map['start_time'] = ['<', time()];
  43. break;
  44. }
  45. }
  46. if (!empty($param['is_delete'])) {
  47. $_map['is_delete'] = $param['is_delete'];
  48. }
  49. return $_map;
  50. }
  51. public function getField() {
  52. return [];
  53. }
  54. /**
  55. * 获取开服列表
  56. *
  57. * @param $where
  58. * @param string $page
  59. * @param string $order
  60. *
  61. * @return array
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\ModelNotFoundException
  64. * @throws \think\exception\DbException
  65. */
  66. public function getServerList($where, $page = '1,10', $order = '-create_time') {
  67. $_where = $this->getWhere($where);
  68. $_field = [
  69. 'id' => 'ser_id',
  70. 'ser_name' => 'ser_name',
  71. 'ser_desc' => 'ser_desc',
  72. 'status' => 'ser_status',
  73. 'start_time' => 'start_time',
  74. ];
  75. return $this->getList($_field, $_where, $page, $order);
  76. }
  77. /**
  78. * 获取列表
  79. *
  80. * @param array $_field
  81. * @param array $where
  82. * @param string $page
  83. * @param string $order
  84. *
  85. * @return array
  86. * @throws \think\db\exception\DataNotFoundException
  87. * @throws \think\db\exception\ModelNotFoundException
  88. * @throws \think\exception\DbException
  89. */
  90. public function getList($_field = [], $where = [], $page = '1,10', $order = '-start_time') {
  91. $_where = $where;
  92. $_model = new GameserverModel();
  93. $_count = $_model->where($_where)->count();
  94. if (empty($_count)) {
  95. return [
  96. 'count' => 0,
  97. 'list' => []
  98. ];
  99. }
  100. $_order = $_model->orderFilter($order);
  101. $_datas = $_model->field($_field)->where($_where)->order($_order)->page($page)->select();
  102. if (is_object($_datas)) {
  103. $_datas = $_datas->toArray();
  104. }
  105. if (empty($_datas)) {
  106. return [
  107. 'count' => $_count,
  108. 'list' => []
  109. ];
  110. }
  111. return [
  112. 'count' => $_count,
  113. 'list' => $_datas
  114. ];
  115. }
  116. }