123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace box\api\controller;
- use box\common\controller\V2ApiBaseController;
- use huo\controller\agent\AgentGame;
- use huo\controller\game\GameCache;
- use huo\model\agent\AgentGameModel;
- use huo\model\user\UserModel;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use huolib\status\CommonStatus;
- use huolib\status\GameStatus;
- use huolib\status\MemberStatus;
- use huomp\logic\game\AgentGameListLogic;
- use huomp\logic\game\MemGameLogic;
- class MemGameController extends V2ApiBaseController {
- public function _initialize() {
- parent::_initialize();
- }
-
- public function index() {
- $_to_mem_id = get_val($this->rq_data, 'to_mem_id', null);
- $_page = get_val($this->rq_data, 'page', 1);
- $_offset = get_val($this->rq_data, 'offset', 10);
- if (!empty($_to_mem_id)) {
-
- $_agent_info = (new UserModel())->getInfoByMemId($_to_mem_id);
- } else {
-
- $_agent_info = (new UserModel())->getInfoByMemId($this->mem_id);
- }
- if (empty($_agent_info)) {
- $_code = MemberStatus::YOU_ARE_NOT_AGENT;
- $this->error(MemberStatus::getMsg($_code), [], $_code);
- }
- $_param = ['agent_id' => $_agent_info['id'], 'classify' => GameConst::GAME_MP];
- $_page = $_page.','.$_offset;
- $_order = '-gameext.down_cnt';
- $_rdata = (new AgentGameListLogic())->getAgentGames($this->mem_id, $_param, $_page, $_order);
- $_code = CommonStatus::NO_ERROR;
- $this->success(CommonStatus::getMsg($_code), $_rdata, $_code);
- }
-
- public function add() {
- $this->checkLogin();
- $_game_id = get_val($this->rq_data, 'game_id');
- if (empty($_game_id)) {
- $_code = GameStatus::GAME_ID_EMPTY;
- $this->error(GameStatus::getMsg($_code), [], $_code);
- }
- $_app_info = (new GameCache())->getInfoByAppId($_game_id);
- if (empty($_app_info)) {
- $_code = GameStatus::GAME_NOT_EXISTS;
- $this->error(GameStatus::getMsg($_code), [], $_code);
- }
- if ($_app_info['is_delete'] != CommonConst::CONST_NOT_DELETE) {
- $_code = GameStatus::GAME_NOT_EXISTS;
- $this->error(GameStatus::getMsg($_code), [], $_code);
- }
- if ($_app_info['status'] != GameConst::GAME_STATUS_ON) {
- $_code = GameStatus::GAME_ONLINE_NO;
- $this->error(GameStatus::getMsg($_code), [], $_code);
- }
- $_agent_info = (new UserModel())->getInfoByMemId($this->mem_id);
- if (empty($_agent_info)) {
- $_code = MemberStatus::YOU_ARE_NOT_AGENT;
- $this->error(MemberStatus::getMsg($_code), [], $_code);
- }
- $_rs = (new AgentGame())->addGame($_agent_info['id'], $_game_id);
- if (!$_rs) {
- $_code = CommonStatus::INNER_ERROR;
- $this->error(CommonStatus::getMsg($_code), [], $_code);
- }
- $_code = CommonStatus::NO_ERROR;
- $this->success(CommonStatus::getMsg($_code), [], $_code);
- }
-
- public function cancel() {
- $this->checkLogin();
- $_game_id = get_val($this->rq_data, 'game_id');
- if (empty($_game_id)) {
- $_code = GameStatus::GAME_ID_EMPTY;
- $this->error(GameStatus::getMsg($_code), [], $_code);
- }
- $_app_info = (new GameCache())->getInfoByAppId($_game_id);
- if (empty($_app_info)) {
- $_code = GameStatus::GAME_NOT_EXISTS;
- $this->error(GameStatus::getMsg($_code), [], $_code);
- }
- $_agent_info = (new UserModel())->getInfoByMemId($this->mem_id);
- if (empty($_agent_info)) {
- $_code = MemberStatus::YOU_ARE_NOT_AGENT;
- $this->error(MemberStatus::getMsg($_code), [], $_code);
- }
- $_ag_model = new AgentGameModel();
- $_ag_info = $_ag_model->getInfoByAgentIdAppId($_agent_info['id'], $_game_id);
- if (empty($_ag_info)) {
- $_code = GameStatus::NOT_YET_ADDED_GAME;
- $this->error(GameStatus::getMsg($_code), [], $_code);
- }
- if ($_ag_info['is_delete'] == CommonConst::CONST_DELETED) {
-
- $_code = CommonStatus::NO_ERROR;
- $this->success(CommonStatus::getMsg($_code), [], $_code);
- } else {
- $_ag_info['is_delete'] = CommonConst::CONST_DELETED;
- $_ag_info['delete_time'] = time();
- $_rs = $_ag_model->updateData($_ag_info, $_ag_info['id']);
- if (!$_rs) {
- $_code = CommonStatus::INNER_ERROR;
- $this->error(CommonStatus::getMsg($_code), [], $_code);
- }
- $_code = CommonStatus::NO_ERROR;
- $this->success(CommonStatus::getMsg($_code), [], $_code);
- }
- }
-
- public function playList() {
- $this->checkLogin();
- $_page = get_val($this->rq_data, 'page', 1);
- $_offset = get_val($this->rq_data, 'offset', 10);
-
- $_agent_info = (new UserModel())->getInfoByMemId($this->mem_id);
- if (empty($_agent_info)) {
- $_code = MemberStatus::YOU_ARE_NOT_AGENT;
- $this->error(MemberStatus::getMsg($_code), [], $_code);
- }
- $_param = [];
- $_page = $_page.','.$_offset;
- $_mg_logic = new MemGameLogic();
- $_rdata = $_mg_logic->getApiMemGame($this->mem_id, $_param, $_page);
- $_code = CommonStatus::NO_ERROR;
- $this->success(CommonStatus::getMsg($_code), $_rdata, $_code);
- }
- }
|