Opt.php 1.78 KB
<?php

use Action\AbstractAction;
use LibModels\Wap\Product\BrandData;
use Plugin\Helpers;

/**
 * 商品操作相关的控制器
 * 
 * @name OptController
 * @package product
 * @copyright yoho.inc
 * @version 1.0 (2015-10-27 19:13:28)
 * @author fei.hong <fei.hong@yoho.cn>
 */
class OptController extends AbstractAction
{

    /**
     * 品牌[店铺]收藏/取消收藏
     * 
     * @param int id 品牌ID
     * @param string opt 操作标识("ok":表示收藏,"cancel":表示取消收藏)
     * @return json
     */
    public function favoriteBrandAction()
    {
        $result = array('code' => 401, 'message' => '未登录', 'data' => false);

        do {
            /* 判断是否是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }

            /* 判断品牌ID是否有效 */
            $id = $this->post('id');
            if (!is_numeric($id)) {
                break;
            }

            /* 判断用户是否登录 */
            $uid = $this->getUdid();
            if (!$uid) {
                break;
            }

            /* 取消收藏 */
            $opt = $this->post('opt', 'ok');
            if ($opt !== 'ok') {
                $result = BrandData::favoriteCancel($id, $uid);
                break;
            }

            /* 收藏 */
            $result = BrandData::favorite($id, $uid);
            if (!isset($result['code'])) {
                break;
            }

            /* 未登录的情况,加跳转链接 */
            if ($result['code'] == 412 || $result['code'] == 400) {
                $referer = $this->server('HTTP_REFERER', SITE_MAIN);
                $result['data'] = Helpers::url('/signin.html', array('refer' => $referer));
            }
        } while (false);

        $this->echoJson($result);
    }

}