Favorite.php
7.46 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
use Action\WebAction;
use WebPlugin\Helpers;
use Home\UserModel;
use Home\FavoriteModel;
use LibModels\Web\Product\FavoriteData;
/**
* 商品收藏
*/
class FavoriteController extends WebAction
{
/**
* 我的收藏
*/
public function indexAction()
{
//判断是否登录
$uid = $this->auditJumpLogin(true, Helpers::url('/home/favorite'));
$udid = $uid . $this->getUdid();
//头部导航
$channel = Helpers::getChannelNameByCookie();
$this->setWebNavHeader($channel);
$page = $this->get('page', 1);
$type = $this->get('type', 'product'); //收藏类别
$sort = $this->get('sort_id', 0); //商品分类
$reduction = $this->get('is_reduction', 'N'); //降价商品
$promotion = $this->get('is_promotion', 'N'); //参加活动的商品
$limit = 10;
$data = array(
'path' => UserModel::getCenterCrumb('我的收藏'),
'userThumb' => UserModel::getUserHeadImg($uid),
'homeNav' => UserModel::getCenterLeftNav('我的收藏', $uid),
'tabs' => FavoriteModel::getFavoriteTabs($type),
);
switch (strval($type)) {
case 'brand':
$data['favBrands'] = FavoriteModel::favoriteBrandList($uid, $page, $limit, $type); //品牌收藏
break;
case 'article':
$data['favArticles'] = FavoriteModel::favoriteArticleList($uid, $udid, $page, $limit, $type); //文章收藏
break;
default:
$data['favProducts'] = FavoriteModel::favoriteProductList($uid, $page, $limit, $type, $sort, 'N', $reduction, $promotion); //商品收藏
break;
}
$this->_view->display('favorite', array('meFavoritePage' => true, 'meFavorite' => $data));
}
/**
* 品牌收藏-新品到着
*/
public function newproductAction()
{
$result = array('code' => 400, 'message' => '', 'data' => '');
do {
//获取相关参数
$uid = $this->getUid(true);
$page = $this->get('page', 1);
$limit = 10;
$id = $this->get('id', '');
if (!$uid || !$id) {
$result = array('code' => 400, 'message' => '缺少参数', 'data' => '');
break;
}
$data = FavoriteModel::newproduct($uid, $page, $limit, $id);
$result = array('code' => 200, 'message' => '', 'data' => $data);
}
while (false);
$this->echoJson($result);
}
/**
* 商品收藏,降价通知
*/
public function reductionAction()
{
//判断是否登录
$uid = $this->auditJumpLogin();
//显示头部导航
$channel = Helpers::getChannelNameByCookie();
$this->setWebNavHeader($channel);
$page = $this->get('page', 1);
$type = $this->get('type', '');
$limit = 10;
$reduction = FavoriteModel::favoriteProductList($uid, $page, $limit, $type, 0, $subscribe = 'Y');
$data = array(
'path' => UserModel::getCenterCrumb('我的收藏'),
'userThumb' => UserModel::getUserHeadImg($uid),
'homeNav' => UserModel::getCenterLeftNav('我的收藏', $uid),
'tabs' => FavoriteModel::getFavoriteTabs('product'),
'reductionUrl' => Helpers::url('/home/favorite'),
'goods' => $reduction['goods'],
);
$this->_view->display('reduction', array('meFavoritePage' => true, 'meFavorite' => $data));
}
/**
* 订阅降价通知
*/
public function noticeAction()
{
$result = array('code' => 400, 'message' => '', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
//获取相关参数
$uid = $this->getUid(true);
$id = $this->get('id', '');
$mobile = $this->get('mobile', '');
$data = FavoriteData::redutionAdd($uid, $mobile, $id);
if (!isset($data['code'])) {
break;
}
//降价通知订阅失败
if ($data['code'] === 500) {
$result = array('code' => 500, 'message' => '', 'data' => '');
switch (strval($data['message'])) {
case 'count must be lt 5':
$result['message'] = '您的订阅数已经到达上限';
break;
case 'mobile must bu not null':
$result['message'] = '请填写手机号';
break;
default:
$result['message'] = '订阅失败';
break;
}
}else{
$result = $data;
}
}
while (false);
$this->echoJson($result);
}
/**
* 取消订阅通知
*/
public function cancelnoticeAction()
{
$result = array('code' => 400, 'message' => '取消失败', 'data' => '');
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
//获取相关参数
$uid = $this->getUid(true);
$id = $this->get('id', '');
if (!$uid || !$id) {
$result = array('code' => 400, 'message' => '取消失败', 'data' => '');
break;
}
$result = FavoriteData::redutionCancel($uid, $id);
if (!isset($result['code'])|| $result['code'] !==200) {
break;
}
}
while (false);
$this->echoJson($result);
}
/**
* 取消收藏
*/
public function cancelAction()
{
$result = array('code' => 400, 'message' => '', 'data' => '');
do {
//判断是否ajax请求
if (!$this->isAjax()) {
break;
}
//获取相关参数
$uid = $this->getUid(true);
$id = $this->get('id', '');
$type = $this->get('type', '');
$shopid = $this->get('shopid', '');
$brandorshoptype = $this->get('brandorshoptype', '');
if (!$uid || !$id) {
$result = array('code' => 400, 'message' => '缺少参数', 'data' => '');
break;
}
if ($brandorshoptype && $shopid && $brandorshoptype === 'shop') {
$result = FavoriteData::cancelProductFav($uid, $shopid, false, true); //取消店铺收藏
break;
}
switch (strval($type)) {
case 'brand':
$result = FavoriteData::cancelProductFav($uid, $id, true); //取消品牌收藏
break;
case 'article':
$result = FavoriteData::changeFavoriteArticle($id, $uid); //取消文章收藏
break;
default:
$result = FavoriteData::cancelProductFav($uid, $id); //取消商品收藏
break;
}
if (!isset($result['code'])) {
break;
}
}
while (false);
$this->echoJson($result);
}
}