Authored by hf

do add product detail preference goods

... ... @@ -63,4 +63,19 @@ class DetailData
) );
}
/**
* 为你优选的商品列表
*
* @param int $productSkn 商品SKN号
* @return array
*/
public static function preference($productSkn)
{
$param = Yohobuy::param();
$param['product_skn'] = $productSkn;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param, 3600); // 缓存1小时
}
}
... ...
... ... @@ -395,4 +395,26 @@ class DetailModel
return $result;
}
/**
* 获取为你优选的商品
*
* @param int $productSkn 商品SKN
* @return array
*/
public static function getPreference($productSkn)
{
$result = array();
if (is_numeric($productSkn)) {
$preference = DetailData::preference($productSkn);
if (!empty($preference['data'])) {
foreach ($preference['data'] as $value) {
$result['recommendList'][] = Helpers::formatProduct($value, false, true, true, 299, 388, false, false);
}
}
}
return $result;
}
}
... ...
... ... @@ -47,7 +47,6 @@ class DetailController extends AbstractAction
public function introAction()
{
$productSkn = $this->param('productSkn');
$productSkn = 50027562;
if (!is_numeric($productSkn)) {
$this->error();
}
... ... @@ -164,4 +163,26 @@ class DetailController extends AbstractAction
$this->_view->display('consultform', $data);
}
/**
* 为你优选
*
* @param int productSkn 商品SKN号
* @return json
*/
public function preferenceAction()
{
$result = array();
if ($this->isAjax()) {
$productSkn = $this->get('productSkn');
$result = \Product\DetailModel::getPreference($productSkn);
}
if (empty($result)) {
echo ' ';
} else {
$this->_view->display('preference', $result);
}
}
}
... ...