|
@@ -23,15 +23,10 @@ class member_favoritesControl extends mbMemberControl
|
|
|
/**
|
|
|
* 收藏列表
|
|
|
*/
|
|
|
- public function favorites_listOp()
|
|
|
+ public function listOp()
|
|
|
{
|
|
|
- $token = trim($_GET['key']);
|
|
|
- if (false == $this->checkToken($token)) {
|
|
|
- return joutput_error($this->err_code);
|
|
|
- }
|
|
|
-
|
|
|
$model_favorites = Model('favorites');
|
|
|
- $favorites_list = $model_favorites->getGoodsFavoritesList(array('member_id' => $this->member_info['member_id']), '*', $this->page_size);
|
|
|
+ $favorites_list = $model_favorites->getGoodsFavoritesList(array('member_id' => $_SESSION['member_id']), '*', $this->page_size);
|
|
|
$page_count = $model_favorites->gettotalpage();
|
|
|
$favorites_id = '';
|
|
|
foreach ($favorites_list as $value) {
|
|
@@ -53,72 +48,65 @@ class member_favoritesControl extends mbMemberControl
|
|
|
/**
|
|
|
* 添加收藏
|
|
|
*/
|
|
|
- public function favorites_addOp()
|
|
|
+ public function addOp()
|
|
|
{
|
|
|
- $token = trim($_GET['key']);
|
|
|
- if (false == $this->checkToken($token)) {
|
|
|
- return joutput_error($this->err_code);
|
|
|
- }
|
|
|
+ static $stTypes = array('goods','brands');
|
|
|
|
|
|
- $goods_id = intval($_POST['goods_id']);
|
|
|
- if ($goods_id <= 0) {
|
|
|
- output_error('参数错误');
|
|
|
- }
|
|
|
+ $fav_type = $_POST['fav_type'];
|
|
|
+ $fav_id = intval($_POST['data_id']);
|
|
|
|
|
|
- $favorites_model = Model('favorites');
|
|
|
- //判断是否已经收藏
|
|
|
- $favorites_info = $favorites_model->getOneFavorites(array('fav_id' => $goods_id, 'fav_type' => 'goods', 'member_id' => $this->member_info['member_id']));
|
|
|
- if (!empty($favorites_info)) {
|
|
|
- output_error('您已经收藏了该商品');
|
|
|
+ if ($fav_id <= 0 || empty($fav_type) || !in_array($fav_type,$stTypes)) {
|
|
|
+ return self::outerr(errcode::ErrParamter,"参数错误");
|
|
|
}
|
|
|
|
|
|
- //判断商品是否为当前会员所有
|
|
|
- $goods_model = Model('goods');
|
|
|
- $goods_info = $goods_model->getGoodsInfoByID($goods_id);
|
|
|
- $seller_info = Model('seller')->getSellerInfo(array('member_id' => $this->member_info['member_id']));
|
|
|
- if ($goods_info['store_id'] == $seller_info['store_id']) {
|
|
|
- output_error('您不能收藏自己发布的商品');
|
|
|
+ $mod_fav = Model('favorites');
|
|
|
+ $favorites_info = $mod_fav->getOneFavorites(array('fav_id' => $fav_id, 'fav_type' => $fav_type, 'member_id' => $_SESSION['member_id']));
|
|
|
+ if (!empty($favorites_info)) {
|
|
|
+ return self::outsuccess(null);
|
|
|
}
|
|
|
-
|
|
|
- //添加收藏
|
|
|
- $insert_arr = array();
|
|
|
- $insert_arr['member_id'] = $this->member_info['member_id'];
|
|
|
- $insert_arr['fav_id'] = $goods_id;
|
|
|
- $insert_arr['fav_type'] = 'goods';
|
|
|
- $insert_arr['fav_time'] = time();
|
|
|
- $result = $favorites_model->addFavorites($insert_arr);
|
|
|
-
|
|
|
- if ($result) {
|
|
|
- //增加收藏数量
|
|
|
- $goods_model->editGoodsById(array('goods_collect' => array('exp', 'goods_collect + 1')), $goods_id);
|
|
|
- output_data('1');
|
|
|
- } else {
|
|
|
- output_error('收藏失败');
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $insert_arr = array();
|
|
|
+ $insert_arr['member_id'] = $_SESSION['member_id'];
|
|
|
+ $insert_arr['fav_id'] = $fav_id;
|
|
|
+ $insert_arr['fav_type'] = $fav_type;
|
|
|
+ $insert_arr['fav_time'] = time();
|
|
|
+ $result = $mod_fav->addFavorites($insert_arr);
|
|
|
+
|
|
|
+ if ($result)
|
|
|
+ {
|
|
|
+ if($fav_type == 'goods') {
|
|
|
+ $mod_goods = Model('goods');
|
|
|
+ $mod_goods->editGoodsById(array('goods_collect' => array('exp', 'goods_collect + 1')), array($fav_id));
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return self::outsuccess(null);
|
|
|
+ } else {
|
|
|
+ return self::outerr(errcode::ErrParamter,"参数错误");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除收藏
|
|
|
*/
|
|
|
- public function favorites_delOp()
|
|
|
+ public function delOp()
|
|
|
{
|
|
|
- $token = trim($_GET['key']);
|
|
|
- if (false == $this->checkToken($token)) {
|
|
|
- return joutput_error($this->err_code);
|
|
|
- }
|
|
|
-
|
|
|
$fav_id = intval($_POST['fav_id']);
|
|
|
if ($fav_id <= 0) {
|
|
|
- output_error('参数错误');
|
|
|
+ return self::outerr(errcode::ErrParamter,"参数错误");
|
|
|
}
|
|
|
|
|
|
$model_favorites = Model('favorites');
|
|
|
-
|
|
|
- $condition = array();
|
|
|
- $condition['fav_id'] = $fav_id;
|
|
|
- $condition['member_id'] = $this->member_info['member_id'];
|
|
|
- $model_favorites->delFavorites($condition);
|
|
|
- output_data('1');
|
|
|
+ $ret = $model_favorites->delFavorites(array('autofv_id' => $fav_id,'member_id' => $_SESSION['member_id']));
|
|
|
+ if($ret == false) {
|
|
|
+ return self::outerr(errcode::ErrParamter,"该收藏不存在或者已经被删除.");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return self::outsuccess(null);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
}
|