Authored by 梁志锋

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

... ... @@ -29,11 +29,15 @@ class DetailData
* @param int $uid 用户ID
* @return array
*/
public static function baseInfo($productId, $uid)
public static function baseInfo($productId, $uid, $productSkn = null)
{
$param = Yohobuy::param();
$param['method'] = 'h5.product.data';
$param['productId'] = $productId;
if ($productId !== null) {
$param['productId'] = $productId;
} elseif ($productSkn !== null) {
$param['product_skn'] = $productSkn;
}
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
... ...
... ... @@ -546,8 +546,8 @@ class Helpers
$arr[$key]['appearDate'] = $vo['expect_arrival_time'];
}
// 商品链接
if ($haveLink && isset($vo['product_id'])) {
$arr[$key]['link'] = self::url('/product/pro_' . $vo['product_id'] . '_' . $vo['goods_id'] . '/' . $vo['cn_alphabet'] . '.html');
if ($haveLink && isset($vo['product_skn'])) {
$arr[$key]['link'] = self::url('/product/show_' . $vo['product_skn'] . '.html');
}
// 累计购买数
$count += intval($vo['buy_number']);
... ...
... ... @@ -20,265 +20,270 @@ class DetailModel
/**
* 商品基本信息
*
* @param int $productId 商品ID
* @param int $productId 商品ID SKN 和 ID 只需要传一个
* @param int $goodsId 某个颜色的商品
* @param int $uid 当前登录用户ID, 未登录为0
* @param int $productSkn SKN 和 ID 只需要传一个
* @return array
*/
public static function getBaseInfo($productId, $goodsId, $uid, $vipLevel)
public static function getBaseInfo($productId, $goodsId, $uid, $vipLevel, $productSkn = null)
{
$result = array();
$baseInfo = array();
// 通过ID获取
if (is_numeric($productId) && is_numeric($goodsId)) {
// 调用服务
$baseInfo = DetailData::baseInfo($productId, $uid);
}
// 通过SKN获取
elseif (is_numeric($productSkn)) {
$baseInfo = DetailData::baseInfo(null, $uid, $productSkn);
}
// 商品名称
if (empty($baseInfo['productName'])) {
return $result;
}
$result['goodsName'] = $baseInfo['productName'];
// 商品名称
if (empty($baseInfo['productName'])) {
return $result;
}
$result['goodsName'] = $baseInfo['productName'];
// 商品促销短语
if (!empty($baseInfo['salesPhrase'])) {
$result['goodsSubtitle'] = $baseInfo['salesPhrase'];
}
// 商品促销短语
if (!empty($baseInfo['salesPhrase'])) {
$result['goodsSubtitle'] = $baseInfo['salesPhrase'];
}
// 商品标签
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': // 新品NEW
$result['tags']['is_new'] = true;
break;
case 'is_discount': // SALE
$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;
}
// 商品标签
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': // 新品NEW
$result['tags']['is_new'] = true;
break;
case 'is_discount': // SALE
$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;
}
}
}
// 商品价格
if (isset($baseInfo['productPriceBo'])) {
$result['goodsPrice'] = array();
$result['goodsPrice']['currentPrice'] = $baseInfo['productPriceBo']['formatSalesPrice'];
if ($baseInfo['productPriceBo']['formatMarketPrice'] !== $baseInfo['productPriceBo']['formatSalesPrice']) {
$result['goodsPrice']['previousPrice'] = $baseInfo['productPriceBo']['formatMarketPrice'];
}
// 商品价格
if (isset($baseInfo['productPriceBo'])) {
$result['goodsPrice'] = array();
$result['goodsPrice']['currentPrice'] = $baseInfo['productPriceBo']['formatSalesPrice'];
if ($baseInfo['productPriceBo']['formatMarketPrice'] !== $baseInfo['productPriceBo']['formatSalesPrice']) {
$result['goodsPrice']['previousPrice'] = $baseInfo['productPriceBo']['formatMarketPrice'];
}
// VIP商品价格
if (isset($baseInfo['productPriceBo']['vipPrices'])) {
$build = array();
foreach ($baseInfo['productPriceBo']['vipPrices'] as $value) {
$build['level'] = $value['vipLevel'];
$build['text'] = $value['vipPrice'];
$build['currentLevel'] = ($value['vipLevel'] == $vipLevel) ? true : false;
$result['vipLevel']['list'][] = $build;
}
}
// VIP商品价格
if (isset($baseInfo['productPriceBo']['vipPrices'])) {
$build = array();
foreach ($baseInfo['productPriceBo']['vipPrices'] as $value) {
$build['level'] = $value['vipLevel'];
$build['text'] = $value['vipPrice'];
$build['currentLevel'] = ($value['vipLevel'] == $vipLevel) ? true : false;
$result['vipLevel']['list'][] = $build;
}
}
// 上市期
if (isset($baseInfo['expectArrivalTime']) && !empty($baseInfo['expectArrivalTime'])) {
$result['periodOfMarket'] = $baseInfo['expectArrivalTime'] . '月';
}
// 上市期
if (isset($baseInfo['expectArrivalTime']) && !empty($baseInfo['expectArrivalTime'])) {
$result['periodOfMarket'] = $baseInfo['expectArrivalTime'] . '月';
}
// 促销信息
if (isset($baseInfo['promotionBoList'])) {
$build = array();
foreach ($baseInfo['promotionBoList'] as $value) {
$build['text'] = '【' . $value['promotionType'] . '】' . $value['promotionTitle'];
$result['goodsDiscount']['list'][] = $build;
}
// 促销信息
if (isset($baseInfo['promotionBoList'])) {
$build = array();
foreach ($baseInfo['promotionBoList'] as $value) {
$build['text'] = '【' . $value['promotionType'] . '】' . $value['promotionTitle'];
$result['goodsDiscount']['list'][] = $build;
}
}
$result['feedbacks'] = array();
// 商品咨询
$result['feedbacks']['consultsNum'] = 0;
if (!empty($baseInfo['consultBoWrapper'])) {
$result['feedbacks']['consultsNum'] = $baseInfo['consultBoWrapper']['consultTotal'];
$result['feedbacks']['consults'] = array();
$build = array();
foreach ($baseInfo['consultBoWrapper']['consultBoList'] as $value) {
$build['question'] = $value['ask'];
$build['time'] = $value['askTime'];
$build['answer'] = $value['answer'];
$result['feedbacks']['consults'][] = $build;
}
$result['feedbacks']['consultsUrl'] = Helpers::url('/product/detail/consults', array('product_id' => $productId, 'total' => $result['feedbacks']['consultsNum']));
}
// 暂无咨询
else {
$result['feedbacks']['consultsUrl'] = Helpers::url('/product/detail/consultform', array('product_id' => $productId));
$result['feedbacks'] = array();
// 商品咨询
$result['feedbacks']['consultsNum'] = 0;
if (!empty($baseInfo['consultBoWrapper'])) {
$result['feedbacks']['consultsNum'] = $baseInfo['consultBoWrapper']['consultTotal'];
$result['feedbacks']['consults'] = array();
$build = array();
foreach ($baseInfo['consultBoWrapper']['consultBoList'] as $value) {
$build['question'] = $value['ask'];
$build['time'] = $value['askTime'];
$build['answer'] = $value['answer'];
$result['feedbacks']['consults'][] = $build;
}
$result['feedbacks']['consultsUrl'] = Helpers::url('/product/detail/consults', array('product_id' => $productId, 'total' => $result['feedbacks']['consultsNum']));
}
// 暂无咨询
else {
$result['feedbacks']['consultsUrl'] = Helpers::url('/product/detail/consultform', array('product_id' => $productId));
}
// 商品评价
$result['feedbacks']['commentsNum'] = 0;
if (!empty($baseInfo['commentBoWrapper'])) {
$result['feedbacks']['commentsNum'] = $baseInfo['commentBoWrapper']['commentTotal'];
$result['feedbacks']['comments'] = array();
$build = array();
foreach ($baseInfo['commentBoWrapper']['commentBoList'] as $value) {
$build['userName'] = $value['nickName'];
$build['desc'] = $value['colorName'] . '/' . $value['sizeName'];
$build['content'] = isset($value['content']) ? $value['content'] : '';
$build['time'] = $value['createTime'];
$result['feedbacks']['comments'][] = $build;
}
$result['feedbacks']['commentsUrl'] = Helpers::url('/product/detail/comments', array('product_id' => $productId, 'total' => $result['feedbacks']['commentsNum']));
// 商品评价
$result['feedbacks']['commentsNum'] = 0;
if (!empty($baseInfo['commentBoWrapper'])) {
$result['feedbacks']['commentsNum'] = $baseInfo['commentBoWrapper']['commentTotal'];
$result['feedbacks']['comments'] = array();
$build = array();
foreach ($baseInfo['commentBoWrapper']['commentBoList'] as $value) {
$build['userName'] = $value['nickName'];
$build['desc'] = $value['colorName'] . '/' . $value['sizeName'];
$build['content'] = isset($value['content']) ? $value['content'] : '';
$build['time'] = $value['createTime'];
$result['feedbacks']['comments'][] = $build;
}
$result['feedbacks']['commentsUrl'] = Helpers::url('/product/detail/comments', array('product_id' => $productId, 'total' => $result['feedbacks']['commentsNum']));
}
// 品牌信息
if (!empty($baseInfo['brand'])) {
$result['enterStore'] = array(
'img' => Helpers::getImageUrl($baseInfo['brand']['brandIco'], 47, 47),
'storeName' => $baseInfo['brand']['brandName'],
'url' => Helpers::url('', array(), $baseInfo['brand']['brandDomain'])
);
// 为你优选的链接
$result['preferenceUrl'] = Helpers::url('/product/detail/preference', array('productSkn' => $baseInfo['erpProductId'], 'brandId' => $baseInfo['brand']['id']), '');
}
// 品牌信息
if (!empty($baseInfo['brand'])) {
$result['enterStore'] = array(
'img' => Helpers::getImageUrl($baseInfo['brand']['brandIco'], 47, 47),
'storeName' => $baseInfo['brand']['brandName'],
'url' => Helpers::url('', array(), $baseInfo['brand']['brandDomain'])
);
// 为你优选的链接
$result['preferenceUrl'] = Helpers::url('/product/detail/preference', array('productSkn' => $baseInfo['erpProductId'], 'brandId' => $baseInfo['brand']['id']), '');
}
// 商品信息
if (!empty($baseInfo['goodsList'])) {
$colorGroup = array();
$sizeGroup = array();
$goodsGroup = array();
$sizeList = array();
$thumbImageList = array();
$colorStorageGroup = array(); // 颜色分组的库存总数集合, 多个之间用/分隔
$sizeStorageStr = ''; // 尺码库存总数集合, 多个之间用/分隔
// 商品信息
if (!empty($baseInfo['goodsList'])) {
$colorGroup = array();
$sizeGroup = array();
$goodsGroup = array();
$sizeList = array();
$thumbImageList = array();
$colorStorageGroup = array(); // 颜色分组的库存总数集合, 多个之间用/分隔
$sizeStorageStr = ''; // 尺码库存总数集合, 多个之间用/分隔
$colorStorageNum = 0;
$totalStorageNum = 0; // 总库存数
foreach ($baseInfo['goodsList'] as $value) {
$colorStorageNum = 0;
$totalStorageNum = 0; // 总库存数
foreach ($baseInfo['goodsList'] as $value) {
$colorStorageNum = 0;
$sizeStorageStr = '';
// 商品分组
if (isset($value['goodsImagesList'])) {
foreach ($value['goodsImagesList'] as $goods) {
$goodsGroup[] = array(
'goodsId' => $goods['goodsId'],
'img' => $goods['imageUrl'],
);
}
}
// 商品的尺码列表
if (isset($value['goodsSizeBoList'])) {
foreach ($value['goodsSizeBoList'] as $size) {
$sizeList[$value['colorId']][] = array(
'id' => $size['id'],
'skuId' => $size['goodsSizeSkuId'],
'goodsId' => $size['goodsId'],
'colorId' => $value['colorId'],
'name' => $size['sizeName'],
'sizeNum' => $size['goodsSizeStorageNum'],
);
$colorStorageNum += intval($size['goodsSizeStorageNum']);
$sizeStorageStr .= $size['goodsSizeStorageNum'] . '/';
$colorStorageGroup[$size['sizeName']][$value['colorName']] = $size['goodsSizeStorageNum'];
}
// 颜色分组
$colorGroup[] = array(
'id' => $value['colorId'],
'skcId' => $value['productSkc'],
'name' => $value['colorName'],
'goodsName' => $value['goodsName'],
'colorNum' => $colorStorageNum,
'sizeNumStr' => rtrim($sizeStorageStr, '/'),
$sizeStorageStr = '';
// 商品分组
if (isset($value['goodsImagesList'])) {
foreach ($value['goodsImagesList'] as $goods) {
$goodsGroup[] = array(
'goodsId' => $goods['goodsId'],
'img' => $goods['imageUrl'],
);
}
}
// 缩略图
$thumbImageList[] = array('img' => Helpers::getImageUrl($value['colorImage'], 60, 60));
// 添加尺码对应的各个颜色的库存量
foreach ($sizeList as $colorId => $sizeArr) {
foreach ($sizeArr as $key => $value) {
$sizeList[$colorId][$key]['colorNumStr'] = implode('/', array_values($colorStorageGroup[$value['name']]));
}
// 商品的尺码列表
if (isset($value['goodsSizeBoList'])) {
foreach ($value['goodsSizeBoList'] as $size) {
$sizeList[$value['colorId']][] = array(
'id' => $size['id'],
'skuId' => $size['goodsSizeSkuId'],
'goodsId' => $size['goodsId'],
'colorId' => $value['colorId'],
'name' => $size['sizeName'],
'sizeNum' => $size['goodsSizeStorageNum'],
);
$colorStorageNum += intval($size['goodsSizeStorageNum']);
$sizeStorageStr .= $size['goodsSizeStorageNum'] . '/';
$colorStorageGroup[$size['sizeName']][$value['colorId']] = $size['goodsSizeStorageNum'];
}
// 商品库存总数
$totalStorageNum += $colorStorageNum;
// 颜色分组
$colorGroup[] = array(
'id' => $value['colorId'],
'skcId' => $value['productSkc'],
'name' => $value['colorName'],
'goodsName' => $value['goodsName'],
'colorNum' => $colorStorageNum,
'sizeNumStr' => rtrim($sizeStorageStr, '/'),
);
}
// 格式化尺码对应的各个颜色分组
foreach ($colorGroup as $value) {
$sizeGroup[]['size'] = $sizeList[ $value['id'] ];
}
// 缩略图
$thumbImageList[] = array('img' => Helpers::getImageUrl($value['colorImage'], 60, 60));
// 商品图: 多个
if (isset($goodsGroup[1])) {
foreach ($goodsGroup as $value) {
$result['bannerTop']['list'][] = array(
'img' => Helpers::getImageUrl($value['img'], 450, 600)
);
// 添加尺码对应的各个颜色的库存量
foreach ($sizeList as $colorId => $sizeArr) {
foreach ($sizeArr as $key => $value) {
$sizeList[$colorId][$key]['colorNumStr'] = implode('/', array_values($colorStorageGroup[$value['name']]));
}
}
// 商品图: 单个
elseif (isset($goodsGroup[0])) {
$result['bannerTop'] = array(
'img' => Helpers::getImageUrl($goodsGroup[0]['img'], 450, 600)
);
}
// 商品库存总数
$totalStorageNum += $colorStorageNum;
}
// 悬浮的购物车信息
$result['cartInfo'] = array(
'cartUrl' => Helpers::url('/cart/index/index', null), // 购物车链接
'numInCart' => 0,
'goodsInstore' => $baseInfo['storage'], // 库存量
);
$soldOut = ($baseInfo['storage'] == 0) || ($baseInfo['status'] == 0);
$notForSale = $baseInfo['attribute'] == 2;
// 显示加入购物车链接
if (!$soldOut && !$notForSale) {
$result['cartInfo']['addToCartUrl'] = Helpers::url('/product/buy_' . $productId . '_' . $goodsId . '.html');
$result['cartInfo']['productId'] = $productId;
$result['cartInfo']['thumbs'] = $thumbImageList;
$result['cartInfo']['name'] = isset($result['goodsName']) ? $result['goodsName'] : '';
$result['cartInfo']['price'] = isset($result['goodsPrice']['previousPrice']) ? $result['goodsPrice']['previousPrice'] : '';
$result['cartInfo']['salePrice'] = isset($result['goodsPrice']['currentPrice']) ? $result['goodsPrice']['currentPrice'] : '';
$result['cartInfo']['totalNum'] = $totalStorageNum;
$result['cartInfo']['colors'] = $colorGroup;
$result['cartInfo']['sizes'] = $sizeGroup;
// 格式化尺码对应的各个颜色分组
foreach ($colorGroup as $value) {
$sizeGroup[]['size'] = $sizeList[ $value['id'] ];
}
// 非卖品
elseif ($notForSale) {
$result['cartInfo']['notForSale'] = true;
// 商品图: 多个
if (isset($goodsGroup[1])) {
foreach ($goodsGroup as $value) {
$result['bannerTop']['list'][] = array(
'img' => Helpers::getImageUrl($value['img'], 450, 600)
);
}
}
// 已售磬
elseif ($soldOut) {
$result['cartInfo']['soldOut'] = true;
// 商品图: 单个
elseif (isset($goodsGroup[0])) {
$result['bannerTop'] = array(
'img' => Helpers::getImageUrl($goodsGroup[0]['img'], 450, 600)
);
}
}
// 是否收藏
$result['isCollect'] = false;
if (isset($baseInfo['isCollect']) && $baseInfo['isCollect'] === 'Y') {
$result['isCollect'] = true;
}
// 悬浮的购物车信息
$result['cartInfo'] = array(
'cartUrl' => Helpers::url('/cart/index/index', null), // 购物车链接
'numInCart' => 0,
'goodsInstore' => $baseInfo['storage'], // 库存量
);
$soldOut = ($baseInfo['storage'] == 0) || ($baseInfo['status'] == 0);
$notForSale = $baseInfo['attribute'] == 2;
// 显示加入购物车链接
if (!$soldOut && !$notForSale) {
$result['cartInfo']['addToCartUrl'] = Helpers::url('/product/buy_' . $productId . '_' . $goodsId . '.html');
$result['cartInfo']['productId'] = $productId;
$result['cartInfo']['thumbs'] = $thumbImageList;
$result['cartInfo']['name'] = isset($result['goodsName']) ? $result['goodsName'] : '';
$result['cartInfo']['price'] = isset($result['goodsPrice']['previousPrice']) ? $result['goodsPrice']['previousPrice'] : '';
$result['cartInfo']['salePrice'] = isset($result['goodsPrice']['currentPrice']) ? $result['goodsPrice']['currentPrice'] : '';
$result['cartInfo']['totalNum'] = $totalStorageNum;
$result['cartInfo']['colors'] = $colorGroup;
$result['cartInfo']['sizes'] = $sizeGroup;
}
// 非卖品
elseif ($notForSale) {
$result['cartInfo']['notForSale'] = true;
}
// 已售磬
elseif ($soldOut) {
$result['cartInfo']['soldOut'] = true;
}
// 底部简介的URL链接
$result['introUrl'] = Helpers::url('/product/intro_' . $baseInfo['erpProductId'] . '/' . $baseInfo['cnAlphabet'] . '.html', null, '');
$result['id'] = $productId;
// 是否收藏
$result['isCollect'] = false;
if (isset($baseInfo['isCollect']) && $baseInfo['isCollect'] === 'Y') {
$result['isCollect'] = true;
}
// 底部简介的URL链接
$result['introUrl'] = Helpers::url('/product/intro_' . $baseInfo['erpProductId'] . '/' . $baseInfo['cnAlphabet'] . '.html', null, '');
$result['id'] = $productId;
return $result;
}
... ...
... ... @@ -47,6 +47,39 @@ class DetailController extends AbstractAction
// 渲染模板
$this->_view->display('index', $data);
}
/**
* 商品详情 (SKN)
*
* @param int productSkn
*/
public function showAction()
{
$productSkn = $this->param('productSkn');
if (!is_numeric($productSkn)) {
$this->error();
}
$uid = $this->getUid();
$vipLevel = 0;
if (isset($this->_vip)) {
$vipLevel = Helpers::getVipLevel($this->_vip);
}
$data = \Product\DetailModel::getBaseInfo(null, null, $uid, $vipLevel, $productSkn);
if (array() === $data) {
$this->error();
}
$data['goodsDetailPage'] = true;
$data['pageFooter'] = true;
if (isset($data['goodsName'])) {
$this->setTitle($data['goodsName']);
}
$this->setNavHeader('商品详情');
// 渲染模板
$this->_view->display('index', $data);
}
/**
* 尺码描述信息
... ...
... ... @@ -147,6 +147,13 @@ routes.productintro.route.controller = Detail
routes.productintro.route.action = Intro
routes.productintro.map.1 = productSkn
routes.productskn.type = "regex"
routes.productskn.match = "#/product/show_([0-9]+).html#"
routes.productskn.route.module = Product
routes.productskn.route.controller = Detail
routes.productskn.route.action = Show
routes.productskn.map.1 = productSkn
; 订单相关
routes.cart.type = "rewrite"
routes.cart.match = "/home/order/detail$"
... ...
... ... @@ -20,3 +20,10 @@ routes.productintro.route.module = Product
routes.productintro.route.controller = Detail
routes.productintro.route.action = Intro
routes.productintro.map.1 = productSkn
routes.productskn.type = "regex"
routes.productskn.match = "#/product/show_([0-9]+).html#"
routes.productskn.route.module = Product
routes.productskn.route.controller = Detail
routes.productskn.route.action = Show
routes.productskn.map.1 = productSkn
... ...