123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- /**
- * GameServerLogic.php UTF-8
- *
- *
- * @date : 2018/5/29 17:09
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : luowei <lw@huosdk.com>
- * @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
- ];
- }
- }
|