1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace box\api\controller;
- use box\common\controller\V2ApiBaseController;
- use huo\controller\integral\MemIa;
- use huo\controller\member\MemCache;
- use huo\model\game\GamecategoryModel;
- use huo\model\member\MemGameModel;
- use huolib\constant\CacheConst;
- use huolib\constant\CategoryConst;
- use huolib\constant\IaConst;
- use huolib\constant\MemConst;
- use huolib\status\CommonStatus;
- use huolib\tool\RateLimit;
- use huomp\controller\member\MemberOut;
- use think\Cache;
- class AppController extends V2ApiBaseController {
- public function _initialize() {
- parent::_initialize();
- $this->checkLogin();
- $_rs = (new RateLimit())->rateLimit($this->mem_id);
- if (false == $_rs) {
- $_code = CommonStatus::TOO_MANY_REQUESTS;
- $this->error(CommonStatus::getMsg($_code));
- }
- }
-
- public function gameOpen() {
- $_game_rq = $this->setGameData();
- $_app_id = $_game_rq->getHAppId();
- $_game_id = $this->request->param('game_id/d', 0);
-
- $_rs = (new GamecategoryModel())->isGameExist(CategoryConst::CATE_CATE_RP, $_game_id);
- if ($_rs == false) {
- $_cache_key = CacheConst::CACHE_MEM_OPEN_GAME_PREFIX.md5(json_encode(array($this->mem_id, $_game_id)));
- $_rdata = ['status' => MemConst::OPEN_GAME_STATUS_2];
- Cache::set($_cache_key, $_rdata);
- $this->success(lang('SUCCESS'), $_rdata);
- }
- $_rs = (new MemberOut())->doOpenGame($this->mem_id, $_app_id, $_game_id);
- if (false === $_rs) {
- $this->error(lang('ERROR'));
- }
- $_rdata = ['status' => $_rs];
- $this->success(lang('SUCCESS'), $_rdata);
- }
-
- public function startup() {
- $_game_rq = $this->setGameData();
- $_game_id = $this->request->param('game_id/d', 0);
- $_app_id = $_game_rq->getHAppId();
- $_mem_data = MemCache::ins()->getInfoById($this->mem_id);
-
- (new MemberOut())->setRpGamePlayCnt($this->mem_id, $_game_id);
- (new MemGameModel())->login($_mem_data, $this->mem_id, $_game_id);
- $_ext = [
- 'app_id' => $_app_id,
- 'game_id' => $_game_id,
- ];
-
- (new MemIa($this->mem_id))->doItgAct(IaConst::IA_OPEN_GAME, $_ext);
- $_cache_key = CacheConst::CACHE_MEM_OPEN_GAME_PREFIX.md5(json_encode(array($this->mem_id, $_game_id)));
- $_status = Cache::get($_cache_key);
- $_status = json_decode($_status, true);
- $this->success(lang('SUCCESS'), $_status);
- }
- }
|