Blame view

yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Opt.php 3.6 KB
hf authored
1 2 3 4
<?php

use Action\AbstractAction;
use LibModels\Wap\Guang\OptData;
hf authored
5
use LibModels\Wap\Product\BrandData;
6
use Plugin\Helpers;
hf authored
7 8 9 10 11 12

/**
 * 逛操作
 */
class OptController extends AbstractAction
{
13 14 15

    /**
     * 资讯文章点赞 (H5里显示点赞)
hf authored
16 17 18 19 20 21 22 23
     * 
     * @param int $id 唯一的资讯ID
     * @param string $opt 操作(ok:表示确定,cancel:表示取消)
     * @return json
     */
    public function praiseArticleAction()
    {
        $result = array();
24
hf authored
25 26 27 28 29
        do {
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
30
hf authored
31
            /* 判断参数是否有效 */
hf authored
32
            $id = $this->post('id');
hf authored
33 34 35
            if (!is_numeric($id)) {
                break;
            }
36
hf authored
37
            /* 执行点赞或取消操作 */
hf authored
38
            $opt = $this->post('opt', 'ok');
hf authored
39 40
            $udid = $this->getUdid();
            $result = OptData::praiseArticle($udid, $id, $opt);
41 42 43
            
        } while (false);
hf authored
44 45
        $this->echoJson($result);
    }
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90

    /**
     * 资讯文章收藏 (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);
    }
hf authored
91 92 93 94 95 96 97 98 99
    /**
     * 品牌收藏
     * 
     * @param int $id 品牌的ID
     * @param string $opt 操作(ok:表示确定,cancel:表示取消)
     * @return json
     */
    public function favoriteBrandAction()
    {
100 101 102
        $refer = Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', '/')));
        $result = array('code' => 400, 'message' => '未登录', 'data' => $refer);
hf authored
103 104 105 106 107
        do {
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
108
hf authored
109
            /* 判断参数是否有效 */
hf authored
110
            $id = $this->post('id');
hf authored
111 112 113
            if (!is_numeric($id)) {
                break;
            }
114
hf authored
115
            /* 检查用户是否登录 */
hf authored
116
            $uid = $this->getUid(); 
hf authored
117
            if (!$uid) {
hf authored
118 119 120
                $uid = $this->getSession('uid');
            }
            if (empty($uid) || !is_numeric($uid)) {
hf authored
121 122 123
                break;
            }
hf authored
124
            /* 取消收藏 */
hf authored
125
            $opt = $this->post('opt', 'ok');
hf authored
126 127
            if ($opt !== 'ok') {
                $result = BrandData::favoriteCancel($id, $uid);
hf authored
128 129
                break;
            }
hf authored
130 131 132

            /* 收藏 */
            $result = BrandData::favorite($id, $uid);
133 134 135
            
        } while (false);
hf authored
136 137
        $this->echoJson($result);
    }
138
hf authored
139
}