AppController.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * AppController.php UTF-8
  4. * 游戏入口
  5. *
  6. * @date : 2017/11/15 17:21
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : wuyonghong <wyh@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace box\api\controller;
  13. use box\common\controller\V2ApiBaseController;
  14. use huo\controller\integral\MemIa;
  15. use huo\controller\member\MemCache;
  16. use huo\model\game\GamecategoryModel;
  17. use huo\model\member\MemGameModel;
  18. use huolib\constant\CacheConst;
  19. use huolib\constant\CategoryConst;
  20. use huolib\constant\IaConst;
  21. use huolib\constant\MemConst;
  22. use huolib\status\CommonStatus;
  23. use huolib\tool\RateLimit;
  24. use huomp\controller\member\MemberOut;
  25. use think\Cache;
  26. class AppController extends V2ApiBaseController {
  27. public function _initialize() {
  28. parent::_initialize();
  29. $this->checkLogin();
  30. $_rs = (new RateLimit())->rateLimit($this->mem_id);
  31. if (false == $_rs) {
  32. $_code = CommonStatus::TOO_MANY_REQUESTS;
  33. $this->error(CommonStatus::getMsg($_code));
  34. }
  35. }
  36. /**
  37. * 打开游戏开始计算时长
  38. * http://doc.1tsdk.com/159?page_id=4820
  39. * 【域名】/game/start
  40. */
  41. public function gameOpen() {
  42. $_game_rq = $this->setGameData();
  43. $_app_id = $_game_rq->getHAppId();
  44. $_game_id = $this->request->param('game_id/d', 0);
  45. /* 判断是否为红包任务列表游戏 */
  46. $_rs = (new GamecategoryModel())->isGameExist(CategoryConst::CATE_CATE_RP, $_game_id);
  47. if ($_rs == false) {
  48. $_cache_key = CacheConst::CACHE_MEM_OPEN_GAME_PREFIX.md5(json_encode(array($this->mem_id, $_game_id)));
  49. $_rdata = ['status' => MemConst::OPEN_GAME_STATUS_2];
  50. Cache::set($_cache_key, $_rdata);
  51. $this->success(lang('SUCCESS'), $_rdata);
  52. }
  53. $_rs = (new MemberOut())->doOpenGame($this->mem_id, $_app_id, $_game_id);
  54. if (false === $_rs) {
  55. $this->error(lang('ERROR'));
  56. }
  57. $_rdata = ['status' => $_rs];
  58. $this->success(lang('SUCCESS'), $_rdata);
  59. }
  60. /**
  61. * 打开游戏--领取奖励
  62. * http://doc.huosdk.com/159?page_id=4507
  63. * 【域名】/game/open
  64. */
  65. public function startup() {
  66. $_game_rq = $this->setGameData();
  67. $_game_id = $this->request->param('game_id/d', 0);
  68. $_app_id = $_game_rq->getHAppId();
  69. $_mem_data = MemCache::ins()->getInfoById($this->mem_id);
  70. /* 试玩任务处理 */
  71. (new MemberOut())->setRpGamePlayCnt($this->mem_id, $_game_id);
  72. (new MemGameModel())->login($_mem_data, $this->mem_id, $_game_id);
  73. $_ext = [
  74. 'app_id' => $_app_id,
  75. 'game_id' => $_game_id,
  76. ];
  77. /* 打开小游戏获取收益 */
  78. (new MemIa($this->mem_id))->doItgAct(IaConst::IA_OPEN_GAME, $_ext);
  79. $_cache_key = CacheConst::CACHE_MEM_OPEN_GAME_PREFIX.md5(json_encode(array($this->mem_id, $_game_id)));
  80. $_status = Cache::get($_cache_key);
  81. $_status = json_decode($_status, true);
  82. $this->success(lang('SUCCESS'), $_status);
  83. }
  84. }