Opt.php
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
<?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);
}
}