Authored by Rock Zhang

添加限购商品分享详情页的逻辑

添加用户未登录时浏览限购商品页跳转登录的逻辑

Code Review By Rock Zhang
... ... @@ -225,14 +225,16 @@ class DetailData
/**
* 获取限购商品详情
*
* @param int $uid 用户UID
* @param string $productCode 限购商品商品码
* @return mixed
*/
public static function limitProductData($productCode)
public static function limitProductData($uid, $productCode)
{
$param = Yohobuy::param();
$param['method'] = 'app.consult.useful';
$param['limit_product_code'] = $productCode;
$param['method'] = 'app.limitProduct.limitProductDetail';
$param['uid'] = $uid;
$param['limitProductCode'] = $productCode;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
... ...
... ... @@ -7,14 +7,12 @@
<p>我在Yoho!Buy有货发现了一个限定发售商品</p>
</div>
<div class="banner">
<a href="{{bannerSrc}}">
<img src="{{banner}}" alt="">
</a>
<img src="{{banner}}" alt="">
</div>
<div class="detail clearfix">
<p class="name">{{name}}</p>
<div class="sale-info">
<span class="price">{{price}}</span>
<span class="price">{{price}}</span>
<span class="date">
<span class="iconfont">&#xe603;</span>
<span class="text">{{releaseDate}}</span>
... ...
... ... @@ -44,6 +44,15 @@ class DetailModel
if (empty($baseInfo['productName'])) {
return $result;
}
// 是否为限购商品
$isLimited = ($baseInfo['isLimitBuy'] === 'Y');
// 如果未登录并且为限购商品,就跳转到登录页
if (empty($uid) && $isLimited) {
$result['needLogin'] = true;
return $result;
}
$result['goodsName'] = $baseInfo['productName'];
// 商品促销短语
... ... @@ -290,11 +299,6 @@ class DetailModel
$soldOut = ($baseInfo['storage'] == 0) || ($baseInfo['status'] == 0 || $totalStorageNum === 0);
$notForSale = $baseInfo['attribute'] == 2;
// 是否为限购商品
$isLimited = ($baseInfo['isLimitBuy'] === 'Y');
// 显示加入购物车链接
if (!$soldOut && !$notForSale && !$isLimited) {
ksort($colorGroup, SORT_NUMERIC);
... ... @@ -744,20 +748,21 @@ class DetailModel
/**
* 获取限购商品详情
*
* @param int $uid 用户UID
* @param string $productCode
* @return array
*/
public static function getLimitProductData($productCode)
public static function getLimitProductData($uid, $productCode)
{
$result = array();
do {
if (empty($productCode)) {
if (empty($uid) || empty($productCode)) {
break;
}
$product = DetailData::limitProductData($productCode);
$product = array(
$productData = DetailData::limitProductData($uid, $productCode);
/*$product = array(
"activityId" => null,
"attachment" => array(
array(
... ... @@ -789,26 +794,26 @@ class DetailModel
"saleTime" => 1454342400,
"showFlag" => 1,
"status" => 1
);
);*/
if (empty($product)) {
if (empty($productData)) {
break;
}
$product = $productData['data'];
$result['price'] = $product['price'];
$result['name'] = $product['productName'];
// 发售日期
$format = 'Y年m月';
if ($product['dayFlag']) { // 具体到日
$format .= 'd日';
}
$result['releaseDate'] = date($format, $product['saleTime']) . '发售';
$result['releaseDate'] = $product['saleTime'] . '发售';
// baner
$result['banner'] = $product['defaultUrl'];
$result['description'] = $product['description'];
// 附件
foreach ($product['attachment'] as $item) {
$result['attach'][] = self::procLimitProductAttach($item);
if (isset($product['attachment'])) {
foreach ($product['attachment'] as $item) {
$result['attach'][] = self::procLimitProductAttach($item);
}
}
} while (false);
... ...
... ... @@ -38,6 +38,12 @@ class DetailController extends AbstractAction
if (array() === $data) {
$this->error();
}
// 如果为限购商品且没有登录就跳转到登陆页
if (isset($data['needLogin'])) {
$this->go(Helpers::url('/signin.html', array('refer' => Helpers::url($this->server('REQUEST_URI')))));
}
$data['goodsDetailPage'] = true;
$data['pageFooter'] = true;
... ... @@ -328,8 +334,9 @@ class DetailController extends AbstractAction
)
);*/
$productCode = $this->get('code', '34343');
$data = DetailModel::getLimitProductData($productCode);
$productCode = $this->get('code', '2016030711270231');
$uid = $this->getUid();
$data = DetailModel::getLimitProductData($uid, $productCode);
// APP下载链接地址
$data['appSrc'] = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho';
... ...