123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <?php
- /**
- * Game.php UTF-8
- * 游戏处理
- *
- * @date : 2017/11/16 17:31
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : wuyonghong <wyh@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace huo\controller\game;
- use huo\controller\common\Base;
- use huo\controller\gift\Gift;
- use huo\controller\request\Channel;
- use huo\controller\request\Game as GameRq;
- use huo\logic\game\GameLogic;
- use huo\logic\posts\PostsLogic;
- use huo\model\game\GameversionModel;
- use huolib\constant\GameConst;
- use huolib\status\GameStatus;
- use huomp\controller\game\GameMini;
- class Game extends Base {
- protected $game_logic;
- public function __construct(GameLogic $game_logic = null) {
- if (null === $game_logic) {
- $this->game_logic = new GameLogic();
- } else {
- $this->game_logic = $game_logic;
- }
- }
- /**
- * 获取游戏 app_key
- *
- * @param int $app_id
- *
- * @return bool
- */
- public function getAppkey($app_id = 0) {
- $_game_data = GameCache::ins()->getInfoByAppId($app_id);
- if (empty($_game_data)) {
- return false;
- }
- $_app_key = get_val($_game_data, 'app_key', '');
- return $_app_key;
- }
- /**
- * 获取游戏 切换状态
- *
- * @param int $app_id
- *
- * @return bool
- */
- public function getPaySwitchStatus($app_id = 0) {
- $_game_data = GameCache::ins()->getInfoByAppId($app_id);
- if (empty($_game_data)) {
- return false;
- }
- $_pay_switch = get_val($_game_data, 'pay_switch', 2);
- return $_pay_switch;
- }
- /**
- * 获取游戏 切换状态
- *
- * @param int $app_id
- *
- * @return bool
- */
- public function getPayShowStatus($app_id = 0) {
- $_game_data = GameCache::ins()->getInfoByAppId($app_id);
- if (empty($_game_data)) {
- return false;
- }
- $_pay_switch = get_val($_game_data, 'pay_show', 2);
- return $_pay_switch;
- }
- /**
- * 获取游戏回调地址
- *
- * @param int $app_id
- *
- * @return bool
- */
- public function getCpPaybackUrl($app_id = 0) {
- $_game_data = GameCache::ins()->getInfoByAppId($app_id);
- if (empty($_game_data)) {
- return false;
- }
- $_cp_payback_url = get_val($_game_data, 'cp_payback_url', '');
- return $_cp_payback_url;
- }
- /**
- * 获取游戏地址
- *
- * @param int $app_id
- *
- * @return int|string
- */
- public function getPlayUrl($app_id = 0) {
- if (empty($app_id)) {
- return GameStatus::GAME_ID_EMPTY;
- }
- $_game_info = GameCache::ins()->getInfoByAppId($app_id);
- if (!isset($_game_info['gv'])) {
- return GameStatus::GAME_NOT_EXISTS;
- }
- $_play_url = !empty($_game_info['gv']['0']['package_url']) ? $_game_info['gv']['0']['package_url'] : '';
- if (empty($_play_url)) {
- return GameStatus::GAME_URL_EMPTY;
- }
- return $_play_url;
- }
- /**
- * 获取游戏详情
- *
- * @param int $app_id
- * @param int $mem_id
- *
- * @param int $from 来源
- *
- * @return array
- */
- public function getDetail($app_id, $mem_id = 0, $from = GameConst::GAME_H5) {
- if (empty($app_id)) {
- $this->huoError(GameStatus::INVALID_PARAMS);
- }
- $_map['app_id'] = $app_id;
- $_data = $this->game_logic->getDetail($_map, $field = '');
- if (is_numeric($_data)) {
- $_code = $_data;
- return $this->huoError($_code, GameStatus::getMsg($_code));
- }
- $_list[$_data['game_id']] = $_data;
- unset($_data);
- $_data = (new GameList())->getGameExtInfo($_list);
- $_game_data = $_data[$app_id];
- /* 获取游戏礼包 */
- $_map['app_id'] = $_game_data['game_id'];
- $_gift_list = (new Gift())->getGiftListDetail($mem_id, $_map, '', true);
- if (!empty($_gift_list)) {
- $_game_data['gift'] = $_gift_list['list'];
- }
- if (GameConst::GAME_H5 != $from && GameConst::GAME_MP_BOX != $from) {
- /* 获取最新资讯 */
- $_game_data['news'] = (new PostsLogic())->getTitleByAppId($app_id);
- /* 获取开服信息 */
- $_game_data['serlist'] = (new GameLogic())->getGameServerList($app_id, GameConst::GAME_SERVER_TODAY);
- } elseif (GameConst::GAME_MP_BOX == $from) {
- /* 获取最新资讯 */
- $_game_data['mini_app_id'] = (new GameMini())->getMiniIdByAppId($app_id);
- }
- $_code = GameStatus::NO_ERROR;
- return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_game_data);
- }
- /**
- * 游戏下载接口与下载次数
- *
- * @param $app_id
- *
- * @return array
- */
- public function getDownUrl($app_id, $agent_id = 0) {
- $_down_cnt = $this->game_logic->getDownCnt($app_id);
- $_down_url = $this->game_logic->getDownUrl($app_id);
- $_data['down_cnt'] = $_down_cnt;
- $_data['down_url'] = $_down_url;
- $_code = GameStatus::NO_ERROR;
- return $this->huoSuccess($_code, GameStatus::getMsg($_code), $_data);
- }
- /**
- * 获取更新信息
- *
- * @param GameRq $game_rq
- * @param Channel $channel
- *
- * @return mixed
- */
- public function getUpInfo(GameRq $game_rq, Channel $channel) {
- // TODO: wuyonghong 2018/1/19 获取更新
- $_rs['up_status'] = 0;
- $_rs['url'] = '';
- $_rs['content'] = '';
- return $_rs;
- }
- /**
- * 获取H5游戏Cp游戏地址
- *
- * @param int $app_id
- *
- * @return string
- */
- public function getH5GameCpUrl($app_id) {
- return (new GameversionModel())->getPackageUrlByAppId($app_id);
- }
- }
|