Authored by 郝肖肖

个人中心 店铺收藏取消

... ... @@ -114,19 +114,24 @@ class FavoriteData
}
/**
* 取消商品或品牌收藏
* @param type $uid 用户uid
* @param type $productId 商品id或品牌id
* @param type $bool 商品或品牌
* 取消商品或品牌或店铺收藏
* @param type $uid 用户uid
* @param type $productId 商品id或品牌id或店铺id
* @param type $isBrand 商品或品牌
* @param type $isShop 是否是店铺
* @return type
*/
public static function cancelProductFav($uid, $productId, $isBrand = false)
public static function cancelProductFav($uid, $productId, $isBrand = false, $isShop = false)
{
$param = Yohobuy::param();
$param['method'] = 'web.favorite.cancel';
$param['favIds'] = $productId;
$param['uid'] = $uid;
$param['type'] = $isBrand ? 'brand' : 'product';
if ($isShop) {
$param['type'] = 'shop';
} else {
$param['type'] = $isBrand ? 'brand' : 'product';
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
... ...
... ... @@ -14,7 +14,7 @@
{{^}}
<ul>
{{# brands}}
<li class="fav-brand fav-row" data-id="{{id}}">
<li class="fav-brand fav-row" data-id="{{id}}" data-shopid="{{shop_id}}" data-brandOrShopType="{{brandOrShopType}}">
<div class="checkbox">
<input type="checkbox">
</div>
... ...
... ... @@ -392,7 +392,9 @@ $('#me-checkall').click(function() {
//删除收藏
$('.del-favorite').click(function(e) {
var id = $(this).closest('.fav-row').data('id');
var id = $(this).closest('.fav-row').data('id'),
shopid = $(this).closest('.fav-row').data('shopid'),
brandorshoptype = $(this).closest('.fav-row').data('brandorshoptype');
e.preventDefault();
... ... @@ -401,6 +403,8 @@ $('.del-favorite').click(function(e) {
url: '/home/favorite/cancel',
data: {
id: id,
shopid: shopid,
brandorshoptype: brandorshoptype,
type: favType
}
}).then(function(data) {
... ...
... ... @@ -166,29 +166,36 @@ class FavoriteModel
$result = array('brands' => array('empty' => '您没有收藏品牌'), 'pager' => array());
$brand = FavoriteData::favoriteBrandData($uid, $page, $limit);
do {
if (empty($brand['data']) || empty($brand['data']['page_total'])) {
break;
}
if ($brand['data']['page_total'] < $page) {
$page = $data['data']['page_total'];
$page = $brand['data']['page_total'];
$brand = FavoriteData::favoriteBrandData($uid, $page, $limit);
continue;
}
if (isset($brand['data']['brand_list'])) {
foreach ($brand['data']['brand_list'] as $brandkey => $brandval) {
$brands[$brandkey]['id'] = $brandval['brand_id']; //品牌id
$brands[$brandkey]['img'] = Images::getImageUrl($brandval['brand_ico'], 100, 100); //品牌缩略图
$brands[$brandkey]['url'] = Helpers::url('', '', $brandval['brand_domain']); //品牌链接
$brands[$brandkey]['name'] = $brandval['brand_name']; //品牌名
$brands[$brandkey]['naCount'] = $brandval['new_product_num']; //新品到着数量
$brands[$brandkey]['colCount'] = $brandval['brand_favorite_num']; //收藏人气
$result['brands'] = $brands;
}
$total = isset($brand['data']['total']) ? $brand['data']['total'] : 0; //消息总条数
$pageTotal = isset($brand['data']['page_total']) ? $brand['data']['page_total'] : 0; //总页数
$page = isset($brand['data']['page']) ? $brand['data']['page'] : 0; //当前页
$result['pager'] = self::getPager($page, $total, $pageTotal, $limit, $type);
if (empty($brand['data']['brand_list'])) {
break;
}
$brands = array();
foreach ($brand['data']['brand_list'] as $brandkey => $brandval) {
$brands[$brandkey]['id'] = $brandval['brand_id']; //品牌id
$brands[$brandkey]['brandOrShopType'] = empty($brandval['brandOrShopType']) ? '' : $brandval['brandOrShopType'];
$brands[$brandkey]['shop_id'] = empty($brandval['shop_id']) ? '' : $brandval['shop_id'];
$brands[$brandkey]['img'] = Images::getImageUrl($brandval['brand_ico'], 100, 100); //品牌缩略图
$brands[$brandkey]['url'] = Helpers::url('', '', $brandval['brand_domain']); //品牌链接
$brands[$brandkey]['name'] = $brandval['brand_name']; //品牌名
$brands[$brandkey]['naCount'] = $brandval['new_product_num']; //新品到着数量
$brands[$brandkey]['colCount'] = $brandval['brand_favorite_num']; //收藏人气
}
$result['brands'] = $brands;
$total = isset($brand['data']['total']) ? $brand['data']['total'] : 0; //消息总条数
$pageTotal = isset($brand['data']['page_total']) ? $brand['data']['page_total'] : 0; //总页数
$page = isset($brand['data']['page']) ? $brand['data']['page'] : 0; //当前页
$result['pager'] = self::getPager($page, $total, $pageTotal, $limit, $type);
}
while (false);
return $result;
... ...
... ... @@ -183,10 +183,17 @@ class FavoriteController extends WebAction
$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); //取消品牌收藏
... ...