GameNotify.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * api游戏公告控制器
  4. */
  5. namespace app\api\controller\v1;
  6. use app\api\controller\Api;
  7. use app\common\model\GameNotify as GameNotifyModel;
  8. class GameNotify extends Api
  9. {
  10. protected $notifyModel;
  11. protected $noNeedLogin = ['index', 'ad'];
  12. public function _initialize()
  13. {
  14. parent::_initialize();
  15. $this->notifyModel = new GameNotifyModel();
  16. }
  17. /**
  18. * 游戏公告
  19. */
  20. public function index($notify_type=1)
  21. {
  22. $game_id = $this->input('gameid'); //游戏ID
  23. $channel_id = $this->input('channel_id'); //渠道ID
  24. if ( empty($game_id) ) {
  25. $this->jsonResult('', 0, '游戏ID不能为空');
  26. }
  27. elseif ( empty($channel_id) ) {
  28. $this->jsonResult('', 0, '渠道ID不能为空');
  29. }
  30. $notifyInfo = $this->notifyModel
  31. ->field('title,content,img_url,create_time,begin_time')
  32. ->where(['status'=>1,'notify_type'=>$notify_type,'game_id'=>['in',[$game_id, 0]],'begin_time'=>array('elt',NOW_TIMESTAMP)])
  33. ->where('(end_time>0 AND end_time>'.NOW_TIMESTAMP.') or (end_time=0)')
  34. ->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.',%'])
  35. ->order('create_time desc')
  36. ->find();
  37. if (! empty($notifyInfo)) {
  38. // 加meta标签,使ios中的wkwebview字体正常
  39. $notifyInfo['content'] = '<head><meta name="viewport" content="width=device-width"></head>' . $notifyInfo['content'];
  40. $notifyInfo['img_url'] = STATIC_DOMAIN.$notifyInfo['img_url'];
  41. if($notifyInfo['begin_time']){
  42. $notifyInfo['create_time'] = $notifyInfo['begin_time'];
  43. }
  44. }
  45. $this->jsonResult($notifyInfo, 1, '成功');
  46. exit;
  47. }
  48. /**
  49. * 游戏广告
  50. *
  51. */
  52. public function ad()
  53. {
  54. $this->index(2);
  55. }
  56. }