| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- /**
- * api游戏公告控制器
- */
- namespace app\api\controller\v1;
- use app\api\controller\Api;
- use app\common\model\GameNotify as GameNotifyModel;
- class GameNotify extends Api
- {
- protected $notifyModel;
- protected $noNeedLogin = ['index', 'ad'];
-
- public function _initialize()
- {
- parent::_initialize();
-
- $this->notifyModel = new GameNotifyModel();
- }
-
- /**
- * 游戏公告
- */
- public function index($notify_type=1)
- {
- $game_id = $this->input('gameid'); //游戏ID
- $channel_id = $this->input('channel_id'); //渠道ID
-
- if ( empty($game_id) ) {
- $this->jsonResult('', 0, '游戏ID不能为空');
- }
- elseif ( empty($channel_id) ) {
- $this->jsonResult('', 0, '渠道ID不能为空');
- }
-
- $notifyInfo = $this->notifyModel
- ->field('title,content,img_url,create_time,begin_time')
- ->where(['status'=>1,'notify_type'=>$notify_type,'game_id'=>['in',[$game_id, 0]],'begin_time'=>array('elt',NOW_TIMESTAMP)])
- ->where('(end_time>0 AND end_time>'.NOW_TIMESTAMP.') or (end_time=0)')
- ->where('(deny_type=0 AND denied_channel not like :channelid1 and denied_channel not like :channelid2) or (deny_type=1 AND (denied_channel like :channelid3 or denied_channel like :channelid4))',['channelid1'=>$channel_id.',%', 'channelid2'=>'%,'.$channel_id.',%','channelid3'=>$channel_id.',%', 'channelid4'=>'%,'.$channel_id.',%'])
- ->order('create_time desc')
- ->find();
- if (! empty($notifyInfo)) {
- // 加meta标签,使ios中的wkwebview字体正常
- $notifyInfo['content'] = '<head><meta name="viewport" content="width=device-width"></head>' . $notifyInfo['content'];
- $notifyInfo['img_url'] = STATIC_DOMAIN.$notifyInfo['img_url'];
- if($notifyInfo['begin_time']){
- $notifyInfo['create_time'] = $notifyInfo['begin_time'];
- }
- }
-
- $this->jsonResult($notifyInfo, 1, '成功');
-
- exit;
- }
- /**
- * 游戏广告
- *
- */
- public function ad()
- {
- $this->index(2);
- }
- }
|