<?php use Action\AbstractAction; use LibModels\Wap\Guang\OptData; use LibModels\Wap\Product\BrandData; use Plugin\Helpers; /** * 逛操作 */ class OptController extends AbstractAction { /** * 资讯文章点赞 (H5里显示点赞) * * @param int $id 唯一的资讯ID * @param string $opt 操作(ok:表示确定,cancel:表示取消) * @return json */ public function praiseArticleAction() { $result = array(); do { /* 判断是不是AJAX请求 */ if (!$this->isAjax()) { break; } /* 判断参数是否有效 */ $id = $this->post('id'); if (!is_numeric($id)) { break; } /* 执行点赞或取消操作 */ $opt = $this->post('opt', 'ok'); $udid = $this->getUdid(); $result = OptData::praiseArticle($udid, $id, $opt); } while (false); $this->echoJson($result); } /** * 资讯文章收藏 (APP里显示收藏) * * @param int $id 唯一的资讯ID * @param string $opt 操作(ok:表示确定,cancel:表示取消) * @return json */ public function collectArticleAction() { $result = array('code' => 400, 'message' => '您未登录,无法收藏或者取消收藏。请先登录!', 'data' => ''); do { /* 判断是不是AJAX请求 */ if (!$this->isAjax()) { break; } /* 判断参数是否有效 */ $id = $this->post('id'); if (!is_numeric($id)) { break; } /* 判断用户是否登录 */ $uid = $this->getSession('uid'); if (empty($uid) || !is_numeric($uid)) { break; } /* 执行点赞或取消操作 */ $opt = $this->post('opt', 'ok'); $data = OptData::collectArticle($uid, $id, $opt); if (!$data) { $result = array('code' => 400, 'message' => '操作失败', 'data' => ''); break; } $result = array('code' => 200, 'message' => '成功', 'data' => ''); } while (false); $this->echoJson($result); } /** * 品牌收藏 * * @param int $id 品牌的ID * @param string $opt 操作(ok:表示确定,cancel:表示取消) * @return json */ public function favoriteBrandAction() { $refer = Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', '/'))); $result = array('code' => 400, 'message' => '未登录', 'data' => $refer); do { /* 判断是不是AJAX请求 */ if (!$this->isAjax()) { break; } /* 判断参数是否有效 */ $id = $this->post('id'); if (!is_numeric($id)) { break; } /* 检查用户是否登录 */ $uid = $this->getUid(); if (!$uid) { $uid = $this->getSession('uid'); } if (empty($uid) || !is_numeric($uid)) { break; } /* 取消收藏 */ $opt = $this->post('opt', 'ok'); if ($opt !== 'ok') { $result = BrandData::favoriteCancel($id, $uid); break; } /* 收藏 */ $result = BrandData::favorite($id, $uid); } while (false); $this->echoJson($result); } }