Opt.php
3.31 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?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()
{
header('Access-Control-Allow-Origin:' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Credentials:true');
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
do {
/* 判断品牌ID是否有效 */
$id = $this->post('id');
if (!is_numeric($id)) {
break;
}
/* 判断用户是否登录 */
$uid = $this->getUid();
if (!$uid) {
$referer = $this->server('HTTP_REFERER', SITE_MAIN);
$result = array('code' => 400, 'message' => '未登录', 'data' => Helpers::url('/signin.html', array('refer' => $referer)));
break;
}
/* 取消收藏 */
$opt = $this->post('opt', 'ok');
if ($opt !== 'ok') {
$result = BrandData::favoriteCancel($id, $uid);
break;
}
/* 收藏 */
$result = BrandData::favorite($id, $uid);
if (!isset($result['code'])) {
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
break;
}
} while (false);
$this->echoJson($result);
}
/**
* 商品收藏/取消收藏
*
* @param int id 商品ID
* @param string opt 操作标识("ok":表示收藏,"cancel":表示取消收藏)
* @return json
*/
public function favoriteProductAction()
{
header('Access-Control-Allow-Origin:' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Credentials:true');
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
do {
/* 判断品牌ID是否有效 */
$id = $this->post('id');
if (!is_numeric($id)) {
break;
}
/* 判断用户是否登录 */
$uid = $this->getUid();
if (!$uid) {
$referer = $this->server('HTTP_REFERER', SITE_MAIN);
$result = array('code' => 400, 'message' => '未登录', 'data' => Helpers::url('/signin.html', array('refer' => $referer)));
break;
}
/* 取消收藏 */
$opt = $this->post('opt', 'ok');
if ($opt !== 'ok') {
$result = BrandData::favoriteCancel($id, $uid, false);
break;
}
/* 收藏 */
$result = BrandData::favorite($id, $uid, false);
if (!isset($result['code'])) {
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
break;
}
} while (false);
$this->echoJson($result);
}
}