* @version : HUOSDK 8.0 */ namespace huo\logic\game; use huo\model\common\CommonModel; use huo\model\game\GameserverModel; use huolib\constant\GameConst; use huolib\tool\Time; class GameServerLogic extends CommonModel { /** * @param array $param * * @return array */ protected function getWhere($param = []) { $_map = []; if (!empty($param['app_id'])) { if (is_array($param['app_id'])) { $_map['app_id'] = ['in', $param['app_id']]; } else { $_map['app_id'] = $param['app_id']; } } if (!empty($param['server_type'])) { switch ($param['server_type']) { case GameConst::GAME_SERVER_TODAY: $_map['start_time'] = ['between', Time::today()]; break; case GameConst::GAME_SERVER_WILL: $_map['start_time'] = ['>', time()]; break; case GameConst::GAME_SERVER_OPENED: default: $_map['start_time'] = ['<', time()]; break; } } if (!empty($param['is_delete'])) { $_map['is_delete'] = $param['is_delete']; } return $_map; } public function getField() { return []; } /** * 获取开服列表 * * @param $where * @param string $page * @param string $order * * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getServerList($where, $page = '1,10', $order = '-create_time') { $_where = $this->getWhere($where); $_field = [ 'id' => 'ser_id', 'ser_name' => 'ser_name', 'ser_desc' => 'ser_desc', 'status' => 'ser_status', 'start_time' => 'start_time', ]; return $this->getList($_field, $_where, $page, $order); } /** * 获取列表 * * @param array $_field * @param array $where * @param string $page * @param string $order * * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getList($_field = [], $where = [], $page = '1,10', $order = '-start_time') { $_where = $where; $_model = new GameserverModel(); $_count = $_model->where($_where)->count(); if (empty($_count)) { return [ 'count' => 0, 'list' => [] ]; } $_order = $_model->orderFilter($order); $_datas = $_model->field($_field)->where($_where)->order($_order)->page($page)->select(); if (is_object($_datas)) { $_datas = $_datas->toArray(); } if (empty($_datas)) { return [ 'count' => $_count, 'list' => [] ]; } return [ 'count' => $_count, 'list' => $_datas ]; } }