Authored by Rock Zhang

添加限购码商品详情的代码逻辑(模板仍需要调整)

Code Review By Rock Zhang
... ... @@ -133,8 +133,10 @@ class DetailData
/**
* 为你优选的商品列表
*
*
* @param int $productSkn 商品SKN号
* @param int $channel
* @param int $brandId
* @return array
*/
public static function preference($productSkn, $channel, $brandId)
... ... @@ -220,4 +222,20 @@ class DetailData
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 获取限购商品详情
*
* @param string $productCode 限购商品商品码
* @return mixed
*/
public static function limitProductData($productCode)
{
$param = Yohobuy::param();
$param['method'] = 'app.consult.useful';
$param['limit_product_code'] = $productCode;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -895,4 +895,21 @@ class Helpers
}
return $area.'-'.$mobile;
}
/**
* 按照数组中指定字段排序二维数组
*
* @param array &$array 需要排序的数组
* @param string $field 字段名称
* @param boolean $desc 时候降序排列,默认为false
*/
public static function sortArrByField(&$array, $field, $desc = false)
{
$fieldArr = array();
foreach ($array as $k => $v) {
$fieldArr[$k] = isset($v[$field]) ? $v[$field] : '';
}
$sort = $desc == false ? SORT_ASC : SORT_DESC;
array_multisort($fieldArr, $sort, $array);
}
}
... ...
... ... @@ -717,6 +717,8 @@ class DetailModel
* 获取为你优选的商品
*
* @param int $productSkn 商品SKN
* @param int $channel
* @param int $brandId
* @return array
*/
public static function getPreference($productSkn, $channel, $brandId)
... ... @@ -738,6 +740,107 @@ class DetailModel
return $result;
}
/**
* 获取限购商品详情
*
* @param string $productCode
* @return array
*/
public static function getLimitProductData($productCode)
{
$result = array();
do {
if (empty($productCode)) {
break;
}
$product = DetailData::limitProductData($productCode);
$product = array(
"activityId" => null,
"attachment" => array(
array(
"attachName" => "",
"attachType" => 1,
"attachUrl" => "http://img10.static.yhbimg.com/yhb-img01/2016/03/03/17/012ddf849c5bd975452063594f36d21c37.png",
"id" => 445,
"intro" => "",
"isDefault" => 1,
"orderBy" => 0,
"productId" => 197,
"status" => 0
)
),
"batchNo" => "20160303171415",
"createTime" => 1456996513,
"dayFlag" => 1,
"description" => "",
"hotFlag" => 1,
"id" => 197,
"lastUpdateTime" => 1456998239,
"limitProductCode" => "2016030317150854",
"limitProductType" => 1,
"notSaleOrderBy" => 0,
"orderBy" => 72,
"price" => "¥65.00",
"productName" => "damao-已开售-码已发完-已售罄",
"productSkn" => 51147512,
"saleTime" => 1454342400,
"showFlag" => 1,
"status" => 1
);
if (empty($product)) {
break;
}
$result['price'] = $product['price'];
$result['name'] = $product['productName'];
$result['releaseDate'] = date('Y年m月', $product['saleTime']) . '发售';
$result['description'] = $product['description'];
// 附件
foreach ($product['attachment'] as $item) {
$result['attach'][] = self::procLimitProductAttach($item);
}
} while (false);
return $result;
}
/**
* 处理限购商品附件数据
*
* @param array $attachment 附件数据
* @return array
*/
private static function procLimitProductAttach($attachment)
{
$result = array();
switch(intval($attachment['attachType'])) {
case 1: // 大图文字
$result['mainImg'] = $attachment['attachUrl'];
$result['goodDescription'] = $attachment['intro'];
$result['orderBy'] = $attachment['orderBy'];
break;
case 2: // 图片列表
break;
case 3: // 视频
break;
default:
break;
}
if(count($result) > 1) {
Helpers::sortArrByField($result, 'orderBy');
}
return $result;
}
/**
* 处理限购商品的有关按钮状态(或取现购买以及底部商品购买按钮)
*
... ...
... ... @@ -3,6 +3,7 @@
use Action\AbstractAction;
use Plugin\Helpers;
use LibModels\Wap\Product\DetailData;
use Product\DetailModel;
/**
* 商品详情的控制器
... ... @@ -33,7 +34,7 @@ class DetailController extends AbstractAction
$vipLevel = Helpers::getVipLevel($this->_vip);
}
$data = \Product\DetailModel::getBaseInfo($productId, $goodsId, $uid, $vipLevel);
$data = DetailModel::getBaseInfo($productId, $goodsId, $uid, $vipLevel);
if (array() === $data) {
$this->error();
}
... ... @@ -66,7 +67,7 @@ class DetailController extends AbstractAction
$vipLevel = Helpers::getVipLevel($this->_vip);
}
$data = \Product\DetailModel::getBaseInfo(null, null, $uid, $vipLevel, $productSkn);
$data = DetailModel::getBaseInfo(null, null, $uid, $vipLevel, $productSkn);
if (array() === $data) {
$this->error();
}
... ... @@ -94,7 +95,7 @@ class DetailController extends AbstractAction
// 加入uid和udid参数,为了实现记录浏览记录的功能
$uid = $this->getUid();
$udid = $this->getUdid();
$data = \Product\DetailModel::getSizeInfo($productSkn, $uid, $udid);
$data = DetailModel::getSizeInfo($productSkn, $uid, $udid);
if (array() === $data) {
echo ' ';
exit();
... ... @@ -126,7 +127,7 @@ class DetailController extends AbstractAction
'goodsCommentsPage' => true,
'pageFooter' => true,
'comments' => array(
'list' => \Product\DetailModel::getComments($productId),
'list' => DetailModel::getComments($productId),
),
);
... ... @@ -155,14 +156,14 @@ class DetailController extends AbstractAction
$this->setTitle('购买咨询');
$uid = $this->getUid();
$consults = \Product\DetailModel::getConsults($uid, $productId);
$consults = DetailModel::getConsults($uid, $productId);
$data = array(
'goodsConsultsPage' => true,
'pageFooter' => true,
'consults' => array(
'list' => $consults
),
'faq' => \Product\DetailModel::getCommonConsults(),
'faq' => DetailModel::getCommonConsults(),
'showReadMore' => count($consults) > 2,
'link' => Helpers::url('/product/detail/consultform', array('product_id' => $productId)),
);
... ... @@ -184,7 +185,7 @@ class DetailController extends AbstractAction
$total = $this->post('total', 0);
$uid = $this->getUid();
$id = $this->post('id');
$result = \Product\DetailModel::upvoteConsult($uid, $id, $productId, $total);
$result = DetailModel::upvoteConsult($uid, $id, $productId, $total);
}
$this->echoJson($result);
... ... @@ -202,7 +203,7 @@ class DetailController extends AbstractAction
$total = $this->post('total', 0);
$uid = $this->getUid();
$id = $this->post('id');
$result = \Product\DetailModel::usefulConsult($uid, $id, $productId, $total);
$result = DetailModel::usefulConsult($uid, $id, $productId, $total);
}
$this->echoJson($result);
... ... @@ -266,7 +267,7 @@ class DetailController extends AbstractAction
$productSkn = $this->get('productSkn');
$brandId = $this->get('brandId');
$channel = Helpers::getChannelByCookie();
$result = \Product\DetailModel::getPreference($productSkn, $channel, $brandId);
$result = DetailModel::getPreference($productSkn, $channel, $brandId);
}
if (empty($result)) {
... ... @@ -276,4 +277,64 @@ class DetailController extends AbstractAction
}
}
/**
* 限购商品说明页面
*/
public function limitHelpAction()
{
$data = array();
$this->_view->display('limit-help', $data);
}
/**
* 限购商品详情页
*/
public function limitAction()
{
/*$data = array(
'profile' => 'http://cdn.yoho.cn/myohobuy/assets/img/me/index/user-avatar.png?1455719653',
'banner' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240',
'bannerSrc' => './',
'name' => '潮流尖端商品啊啊啊啊',
'price' => '1999',
'releaseDate' => '2016年12月发售',
'appSrc' => './',
'mainImg' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240',
'goodDescription' => '独独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤',
'imgList' => array(
array(
'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240'
),
array(
'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240'
),
array(
'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240'
)
),
'vedio' => array(
'img' => './',
'list' => array(
array(
'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.mp4'
),
array(
'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.webm'
),
array(
'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.ogv'
)
)
)
);*/
$productCode = $this->get('code', '34343');
$data = DetailModel::getLimitProductData($productCode);
// APP下载链接地址
$data['appSrc'] = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.yoho';
$this->_view->display('limit', $data);
}
}
... ...
... ... @@ -228,54 +228,4 @@ class IndexController extends AbstractAction
$this->_view->display('index', $data);
}
public function limitHelpAction()
{
$data = array();
$this->_view->display('limit-help', $data);
}
public function limitAction()
{
$data = array(
'profile' => 'http://cdn.yoho.cn/myohobuy/assets/img/me/index/user-avatar.png?1455719653',
'banner' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240',
'bannerSrc' => './',
'name' => '潮流尖端商品啊啊啊啊',
'price' => '1999',
'releaseDate' => '2016年12月发售',
'appSrc' => './',
'mainImg' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240',
'goodDescription' => '独独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤独家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤家发售快乐的肌肤立刻就是大老骥伏枥开始的肌肤',
'imgList' => array(
array(
'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240'
),
array(
'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240'
),
array(
'img' => 'http://img11.static.yhbimg.com/yhb-img01/2016/02/25/02/016ed5a17fb9d9bc7542174c22dccb4acf.jpg?imageView/2/w/640/h/240'
)
),
'vedio' => array(
'img' => './',
'list' => array(
array(
'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.mp4'
),
array(
'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.webm'
),
array(
'src' => 'http://video.yohoboys.com/xuanchuan/wuyifan_mobile.ogv'
)
)
)
);
$this->_view->display('limit', $data);
}
}
... ...