Authored by yangyang

换小写

  1 +<?php
  2 +
  3 +use Action\AbstractAction;
  4 +use Guang\StarClassModel;
  5 +use LibModels\Wap\Guang\StarClassData;
  6 +use Plugin\Helpers;
  7 +
  8 +/**
  9 + * 星潮教室
  10 + * Class StarClassController
  11 + */
  12 +class StarClassController extends AbstractAction
  13 +{
  14 + //定义是否APP变量
  15 + protected $_isApp = false;
  16 +
  17 + /**
  18 + * 星潮教室首页
  19 + */
  20 + public function indexAction()
  21 + {
  22 + //设置头部公共导航
  23 + $this->setNavHeader('星潮教室', true, false);
  24 + //获取uid
  25 + $uid = $this->getLoggedUid();
  26 + //调用模型获得星潮教室首页数据
  27 + $data = StarClassModel::getStarClass($uid);
  28 + //渲染模板
  29 + $this->_view->display('index', array(
  30 + 'trendClassHome' => $data,
  31 + 'trendClassHomePage' => true
  32 + )
  33 + );
  34 + }
  35 +
  36 +
  37 + /**
  38 + * 星潮教室-星专题
  39 + */
  40 + public function specialAction()
  41 + {
  42 + //设置头部公共导航
  43 + $this->setNavHeader('星潮教室', true, false);
  44 +
  45 + //调用模型获得星专题数据
  46 + $data = StarClassModel::getspecial();
  47 +
  48 + //渲染模板
  49 + $this->_view->display('subject', array(
  50 + 'trendClassSubject' => $data,
  51 + 'trendClassHomePage' => true
  52 + ));
  53 + }
  54 +
  55 +
  56 + /**
  57 + * 星潮教室-星搭配
  58 + */
  59 + public function collocationAction()
  60 + {
  61 + //设置头部公共导航
  62 + $this->setNavHeader('星潮教室', true, false);
  63 +
  64 + //调用模板获得星搭配数据
  65 + $data = StarClassModel::getCollocation();
  66 +
  67 + //渲染模板
  68 + $this->_view->display('collocation', array(
  69 + 'trendClassCollocation' => $data,
  70 + 'trendClassCollocationPage' => true
  71 + ));
  72 + }
  73 +
  74 +
  75 + /**
  76 + * 星潮教室-星搭配文章 ajax请求
  77 + */
  78 + public function ajaxCollocationAction()
  79 + {
  80 + if (!$this->isAjax()) {
  81 + return;
  82 + }
  83 + //获得必要参数
  84 + $page = $this->get('page',1);
  85 + $uid = $this->getLoggedUid();
  86 + $isApp = $this->_isApp;
  87 +
  88 + //调取模型获得星搭配文章
  89 + $data = StarClassModel::ajaxCollocation($page, $uid, $isApp, $limit = 20);
  90 +
  91 + //返回数据到页面,没有数据返回空格
  92 + if (isset($data) && !empty($data)) {
  93 + $this->_view->display('collocation-list',$data);
  94 + }else{
  95 + echo ' ';
  96 + }
  97 + }
  98 +
  99 +
  100 + /**
  101 + * 星潮教室-签到-Top100排行榜
  102 + */
  103 + public function topAction()
  104 + {
  105 + //设置头部公共导航(此处返回键调转星潮教室首页)
  106 + $url = Helpers::url('/guang/starclass/index');
  107 + $this->setNavHeader('星潮粉丝榜', $url, false);
  108 +
  109 + //根据客户端类型,进行未登录跳转
  110 + $uid = $this->getLoggedUid();
  111 + if (!$uid) {
  112 + $refer = Helpers::url('/guang/starclass/top');
  113 + if (!$this->_isApp) {
  114 + $this->go(Helpers::url('/signin.html', array('refer' => $refer)));
  115 + } else {
  116 + $referEncode = strtr($refer, array('/' => '\\/'));
  117 + $this->go($refer . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $referEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}');
  118 + }
  119 + return;
  120 + }
  121 +
  122 + //调取模型获得Top100数据
  123 + $data = StarClassModel::getTop($uid);
  124 +
  125 + //渲染模板
  126 + $this->_view->display('check-in',array(
  127 + 'trendClassCheckIn'=>$data,
  128 + 'trendClassTopPage' => true
  129 + ));
  130 + }
  131 +
  132 +
  133 + /**
  134 + * 星潮教室-签到
  135 + */
  136 + public function signAction()
  137 + {
  138 + if(!$this->isAjax()){
  139 + return;
  140 + }
  141 +
  142 + //根据客户端类型,进行未登录跳转
  143 + $uid = $this->getLoggedUid();
  144 + if (!$uid) {
  145 + $refer = Helpers::url('/guang/starclass/index');
  146 + if (!$this->_isApp) {
  147 + $this->echoJson(array('code'=>201,'data'=>Helpers::url('/signin.html', array('refer' => $refer))));
  148 + } else {
  149 + $referEncode = strtr($refer, array('/' => '\\/'));
  150 + $this->echoJson(array('code'=>201,'data'=>$refer . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $referEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}'));
  151 + }
  152 + return;
  153 + }
  154 + //调取模型完成签到,并返回数据
  155 + $res = StarClassModel::sign($uid);
  156 +
  157 + //输出签到结果到页面
  158 + $this->echoJson($res);
  159 + }
  160 +
  161 + /**
  162 + * 星鲜事-点赞
  163 + */
  164 + public function setPraiseAction()
  165 + {
  166 + if(!$this->isAjax()){
  167 + return;
  168 + }
  169 + //获得客户端ID(点赞不需要登录)
  170 + $udid = $this->getUdid();
  171 + //获得文章ID
  172 + $articleId = $this->post('articleId');
  173 +
  174 + //调取接口点赞
  175 + $result = StarClassData::setPraise($articleId, $udid);
  176 +
  177 + $this->echoJson($result);
  178 + }
  179 +
  180 + /**
  181 + * 星搭配-文章分享
  182 + */
  183 + public function forwardAction()
  184 + {
  185 + if(!$this->isAjax()){
  186 + return;
  187 + }
  188 + $result = array();
  189 +
  190 + //根据客户端类型,进行未登录跳转
  191 + $uid = $this->getLoggedUid();
  192 + if (!$uid) {
  193 + $refer = Helpers::url('/guang/starclass/collocation');
  194 + if (!$this->_isApp) {
  195 + $this->echoJson(array('code'=>201,'data'=>Helpers::url('/signin.html', array('refer' => $refer))));
  196 + } else {
  197 + $referEncode = strtr($refer, array('/' => '\\/'));
  198 + $this->echoJson(array('code'=>201,'data'=>$refer . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $referEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}'));
  199 + }
  200 + return;
  201 + }else{
  202 + //调取接口分享文章
  203 + $result = StarClassData::forward($uid);
  204 + }
  205 +
  206 + $this->echoJson($result);
  207 + }
  208 +
  209 + /**
  210 + * 星搭配-收藏资讯文章
  211 + */
  212 + public function setFavoriteAction()
  213 + {
  214 + if (!$this->isAjax()) {
  215 + return;
  216 + }
  217 +
  218 + //根据客户端类型,进行未登录跳转
  219 + $uid = $this->getLoggedUid();
  220 + if (!$uid) {
  221 + $refer = Helpers::url('/guang/starclass/collocation');;
  222 + if (!$this->_isApp) {
  223 + $this->echoJson(array('code'=>201,'data'=>Helpers::url('/signin.html', array('refer' => $refer))));
  224 + } else {
  225 + $referEncode = strtr($refer, array('/' => '\\/'));
  226 + $this->echoJson(array('code'=>201,'data'=>$refer . '?openby:yohobuy={"action":"go.weblogin","params":{"jumpurl":{"url":"' . $referEncode . '","param":{"from":"app"}},"requesturl":{"url":"","param":{}},"priority":"N"}}'));
  227 + }
  228 + return;
  229 + }
  230 +
  231 + //获取文章ID,接口Type(fav调取收藏接口,del调取取消收藏接口)
  232 + $articleId = $this->post('articleId');
  233 + $type = $this->post('type');
  234 +
  235 + if (!isset($articleId) || !isset($type)) {
  236 + $this->echoJson(array('code'=>400,'message'=>'参数错误!'));
  237 + }
  238 + $result = array();
  239 + //调取接口进行收藏
  240 + $result = StarClassData::setFavorite($articleId, $uid, $type);
  241 +
  242 + if (!empty($result)) {
  243 + $this->echoJson($result);
  244 + }
  245 +
  246 + }
  247 +
  248 + /**
  249 + * 检测登录状态
  250 + *
  251 + * @return int
  252 + */
  253 + private function getLoggedUid()
  254 + {
  255 + // 判断是否是应用访问, 拼接APP需要的URL参数
  256 + $this->_isApp = (null !== $this->get('app_version') || null !== $this->get('uid'));
  257 + $uid = false;
  258 + if ($this->_isApp) {
  259 + $uid = $this->get('uid');
  260 + } else {
  261 + $uid = $this->getUid();
  262 + }
  263 +
  264 + return $uid;
  265 + }
  266 +
  267 +}