Authored by hf

do add .

... ... @@ -22,15 +22,16 @@ class BrandData
*
* @param int $id 品牌ID
* @param int $uid 用户ID
* @param bool $isBrand 是品牌还是商品
* @return array
*/
public static function favorite($id, $uid)
public static function favorite($id, $uid, $isBrand = true)
{
$param = Yohobuy::param();
$param['method'] = 'app.favorite.add';
$param['id'] = $id;
$param['uid'] = $uid;
$param['type'] = 'brand';
$param['type'] = $isBrand ? 'brand' : 'product';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
... ... @@ -41,15 +42,16 @@ class BrandData
*
* @param int $id 品牌ID
* @param int $uid 用户ID
* @param bool $isBrand 是品牌还是商品
* @return array
*/
public static function favoriteCancel($id, $uid)
public static function favoriteCancel($id, $uid, $isBrand = true)
{
$param = Yohobuy::param();
$param['method'] = 'app.favorite.cancel';
$param['fav_id'] = $id;
$param['uid'] = $uid;
$param['type'] = 'brand';
$param['type'] = $isBrand ? 'brand' : 'product';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
... ...
... ... @@ -33,11 +33,40 @@ class DetailModel
// 调用服务
$baseInfo = DetailData::baseInfo($productId, $uid);
// 判断商品是否在架
if (empty($baseInfo['status'])) {
return $result;
}
// 商品名称
if (isset($baseInfo['productName'])) {
$result['goodsName'] = $baseInfo['productName'];
} else {
return $result;
}
// 商品标签
if (!empty($baseInfo['productTagBoList'])) {
foreach ($baseInfo['productTagBoList'] as $value) {
switch ($value['tagLabel']) {
case 'is_soon_sold_out': // 即将售磬
$result['tags']['is_soon_sold_out'] = true;
break;
case 'is_new': // 新品
$result['tags']['is_new'] = true;
break;
case 'is_discount': // 在售
$result['tags']['is_discount'] = true;
break;
case 'is_limited': // 限量
$result['tags']['is_limited'] = true;
break;
case 'is_yohood': // YOHOOD
$result['tags']['is_yohood'] = true;
break;
case 'is_advance': // 再到着
$result['tags']['is_advance'] = true;
break;
}
}
}
// 商品价格
... ... @@ -176,6 +205,7 @@ class DetailModel
// 底部简介的URL链接
$result['introUrl'] = Helpers::url('/product/intro_' . $baseInfo['erpProductId'] . '/' . $baseInfo['cnAlphabet'] . '.html');
$result['id'] = $productId;
}
return $result;
... ...
... ... @@ -60,7 +60,55 @@ class OptController extends AbstractAction
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
break;
}
} while (false);
$this->echoJson($result);
}
/**
* 商品收藏/取消收藏
*
* @param int id 商品ID
* @param string opt 操作标识("ok":表示收藏,"cancel":表示取消收藏)
* @return json
*/
public function favoriteProductAction()
{
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
do {
/* 判断是否是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断品牌ID是否有效 */
$id = $this->post('id');
if (!is_numeric($id)) {
break;
}
/* 判断用户是否登录 */
$uid = $this->getUid();
if (!$uid) {
$referer = $this->server('HTTP_REFERER', SITE_MAIN);
$result = array('code' => 400, 'message' => '未登录', 'data' => Helpers::url('/signin.html', array('refer' => $referer)));
break;
}
/* 取消收藏 */
$opt = $this->post('opt', 'ok');
if ($opt !== 'ok') {
$result = BrandData::favoriteCancel($id, $uid, false);
break;
}
/* 收藏 */
$result = BrandData::favorite($id, $uid, false);
if (!isset($result['code'])) {
$result = array('code' => 401, 'message' => '参数不正确', 'data' => false);
break;
}
} while (false);
$this->echoJson($result);
... ...
<?php
use Yaf\Application;
define('SITE_MAIN', 'http://m.yohobuy.com'); // 网站主域名
define('OLD_MAIN', 'http://m.yohobuy.com'); // 网站旧域名
define('COOKIE_DOMAIN', '.m.yohobuy.com'); // COOKIE作用域
define('SUB_DOMAIN', '.m.yohobuy.com'); // 子域名后缀
define('USE_CACHE', false); // 缓存的开关
define('APPLICATION_PATH', dirname(__DIR__)); // 应用目录
define('ROOT_PATH', dirname(dirname(APPLICATION_PATH))); // 根目录
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'preview');
$application = new Application(APPLICATION_PATH . '/configs/application.preview.ini');
$application->bootstrap()->run();
\ No newline at end of file
... ...