Authored by yangyang

收藏商品

<?php
namespace LibModels\Web\Product;
use Api\Yohobuy;
/**
* FavoriteData
* 收藏相关接口
* @author Administrator
*/
class FavoriteData {
const URL_PRODUCT_FAVORITE = 'shops/service/v1/favorite/';
/**
* 根据uid和商品的skn查询是否被用户收藏
* @param $uid
* @param $productSkn
* @return boolean 收藏 true 未收藏 false
*/
public static function getUidProductFav($uid, $productSkn)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_PRODUCT_FAVORITE, 'getUidProductFav', array($uid, $productSkn));
}
/**
* 根据uid和商品的skn收藏商品
* @param $uid
* @param $productSkn
* @return bool
*/
public static function addUidProductFav($uid, $productSkn)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_PRODUCT_FAVORITE, 'addUidProductFav', array($uid, $productSkn));
}
/**
* 根据uid和商品的skn取消收藏商品
* @param $uid
* @param $productSkn
* @return bool
*/
public static function delUidProductFav($uid, $productSkn)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_PRODUCT_FAVORITE, 'delUidProductFav', array($uid, $productSkn));
}
}
... ...
... ... @@ -71,7 +71,7 @@ class Bootstrap extends Bootstrap_Abstract
$controller = 'Index';
$action = 'Index';
// 二级域名
if (2 === $level) {
if (3 === $level) {
$url = strtolower($dispatcher->getRequest()->getRequestUri());
if(empty($url) || $url == '/index' || $url == '/') {
$urlAction = '/index';
... ...
... ... @@ -204,6 +204,7 @@ class SearchModel
//组织数据结构
$data = HelperSearch::getProductPic($data['data']['product_list'], $options);
}
$data['isFavorite'] = $options['isFavorite'];
echo json_encode($data);
}
... ...
<?php
use Action\WebAction;
use Product\SearchModel;
use LibModels\Web\Product\FavoriteData;
class ListController extends WebAction
{
public function indexAction()
... ... @@ -12,6 +14,7 @@ class ListController extends WebAction
'positionId' => $positionId,
'reviewNum' => 6
);
$indexData = Product\IndexModel::getIndexData($condition, $options);
$data = array(
... ... @@ -31,8 +34,6 @@ class ListController extends WebAction
'order' => 's_t_desc'
);
$options = array(
'specialsale_id' => 'Y',
'needDay' => 'Y',
'reviewNum' => 6
);
... ... @@ -69,7 +70,12 @@ class ListController extends WebAction
*/
public function getProductPicAction()
{
if (!$this->isAjax()) {
return;
}
$product_skn = $this->post('skn');
$uid = $this->getUid();
if (!$product_skn) {
return ;
}
... ... @@ -90,6 +96,46 @@ class ListController extends WebAction
'imgSize' => $imgSize,
'minImgSize' => $minImgSize,
);
$isFavorite = false;
if ($uid) {
$favorite = FavoriteData::getUidProductFav($uid, $product_skn);
if (isset($favorite['code']) && $favorite['code'] == 200) {
$isFavorite = true;
}
}
$options['isFavorite'] = $isFavorite;
SearchModel::getProductPic($product_skn, $options);
}
/**
* 根据product_skn收藏
* @author
* @return json
*/
public static function changeFavoriteAction()
{
if (!$this->isAjax()) {
return;
}
$product_skn = $this->post('skn');
$isFavorite = $this->post('isFavorite');
$uid = $this->getUid();
do {
if (!$product_skn && !$uid) {
break;
}
if ($isFavorite) {
$result = FavoriteData::delUidProductFav($uid, $product_skn);
$this->echoJson($result);
break;
}else{
$result = FavoriteData::addUidProductFav($uid, $product_skn);
$this->echoJson($result);
break;
}
} while(false);
}
}
\ No newline at end of file
... ...