Authored by Rock Zhang

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

Conflicts:
	library/LibModels/Wap/Passport/LoginData.php
	library/Plugin/Helpers.php
... ... @@ -426,7 +426,7 @@
ps: {
id: 1,
banner: '',
log: '',
logo: '',
name: '',
isLike: '',
likeUrl: '',
... ...
... ... @@ -122,5 +122,15 @@ class AbstractAction extends Controller_Abstract
{
return $this->_request->isXmlHttpRequest();
}
/**
* 跳转到错误页面
*/
protected function error()
{
headers_sent() || header('Location: /error.html');
exit;
}
}
... ...
... ... @@ -15,8 +15,8 @@ use Api\Yohobuy;
*/
class DetailData
{
const API_URI_ARTICLE = 'guang/service/v2/article/';
const API_URI_AUTHOR = 'guang/service/v1/author/';
const URI_PACKAGE_ARTICLE = 'guang/service/v2/article/';
const URI_PACKAGE_AUTHOR = 'guang/service/v1/author/';
/**
* 逛资讯详情页数据封装
... ... @@ -31,7 +31,7 @@ class DetailData
$result['getOtherArticle'] = array();
// 获取资讯
$article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getArticle', array($id));
$article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticle', array($id));
if (!isset($article['tag'])) {
return $result;
} else {
... ... @@ -39,7 +39,7 @@ class DetailData
}
// 获取作者信息
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_AUTHOR, 'getAuthor', array($id), function ($retval) use (&$result) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_AUTHOR, 'getAuthor', array($id), function ($retval) use (&$result) {
$result['getAuthor'] = empty($retval) ? array() : $retval;
});
... ...
... ... @@ -4,7 +4,6 @@ namespace LibModels\Wap\Guang;
use Api\Sign;
use Api\Yohobuy;
use Hood\Cache;
/**
* 逛首页列表相关的数据模型
... ...
... ... @@ -4,6 +4,7 @@ namespace LibModels\Wap\Guang;
use Api\Sign;
use Api\Yohobuy;
use Plugin\Helpers;
/**
* 明星品牌和原创品牌相关的数据模型
... ... @@ -17,6 +18,11 @@ use Api\Yohobuy;
class PlusstarData
{
const URI_BRANDLIST = 'guang/api/v1/plustar/getlist';
const URI_BRANDINFO_PLUSSTAR = 'guang/service/v1/plustar/';
const URI_BRANDINFO_FAVORITE = 'shops/service/v1/favorite/';
const URI_BRANDINFO_ARTICLE = 'guang/service/v1/article/';
/**
* 品牌列表
*
... ... @@ -32,7 +38,7 @@ class PlusstarData
// 存放接口列表
$urlList = array();
// 接口调用的URL
$url = Yohobuy::SERVICE_URL . 'guang/api/v1/plustar/getlist';
$url = Yohobuy::SERVICE_URL . self::URI_BRANDLIST;
// 公共的参数
$param = Yohobuy::param();
... ... @@ -80,7 +86,7 @@ class PlusstarData
$result['getArticleByBrand'] = array();
// 品牌详情信息
$brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/plustar/', 'getBrandInfo', array(array('id' => $id)) );
$brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_PLUSSTAR, 'getBrandInfo', array(array('id' => $id)) );
if (!isset($brandInfo['brand_id'])) {
return $result;
} else {
... ... @@ -90,14 +96,14 @@ class PlusstarData
// 是否收藏店铺
$isUidOk = $uid && is_numeric($uid);
if ($isUidOk) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'getUidBrandFav', array($uid, $id), function($retval) use(&$result) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidBrandFav', array($uid, $id), function($retval) use(&$result) {
$result['getUidBrandFav'] = empty($retval['data']) ? false : $retval['data'];
});
}
// 相关资讯列表 (3篇)
$result['getArticleByBrand'] = array();
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'guang/service/v1/article/', 'getArticleByBrand', array($brandInfo['brand_id'], 3, $udid), function($retval) use(&$result) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_ARTICLE, 'getArticleByBrand', array($brandInfo['brand_id'], 3, $udid), function($retval) use(&$result) {
$result['getArticleByBrand'] = empty($retval) ? array() : $retval;
});
... ... @@ -120,24 +126,23 @@ class PlusstarData
break;
}
//$result['getNewProduct'] = $newProduct['data']['product_list'];
$skn = '';
foreach ($newProduct['data']['product_list'] as $value) {
if (empty($value['goods_list'])) {
continue;
}
// 商品信息列表
$result['getNewProduct'][] = Helpers::formatProduct($value);
// 用户是否收藏该商品
$skn = $value['product_skn'];
$result['getUidProductFav'][ $skn ] = false;
if ($isUidOk) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'getUidProductFav', array($uid, $value['product_skn']), function($retval) use(&$result,&$skn) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_FAVORITE, 'getUidProductFav', array($uid, $value['product_skn']), function($retval) use(&$result,&$skn) {
$result['getUidProductFav'][ $skn ] = empty($retval['data']) ? false : $retval['data'];
});
}
// @todo 需要根据页面结构封装返回数据
}
} while (false);
... ... @@ -146,63 +151,8 @@ class PlusstarData
return $result;
// @todo 根据页面展示数据封装
// $url = '';
// if($uid > 0){
// $isLike = Favorite::getUidProductFav($uid, $new_goods_info['product_skn']);
// }
// if($client_type == 'web'){
// $baseUrl = QUtilsConfig::$websiteRoot['yohobuy'];
// }else{
// $baseUrl = QUtilsConfig::$websiteRoot['h5'];
// }
// $goods_url = MakeUrl::h5ProductDetailUrl($baseUrl,$new_goods_info['product_id'],$new_goods_info['goods_list'][0]['goods_id'],$new_goods_info['cn_alphabet']);
// $url = MakeUrl::makeUrl('go.productDetail',$goods_url, array('product_skn'=>$new_goods_info['product_skn']),$client_type);
// if((int)$new_goods_info['market_price'] == (int)$new_goods_info['sales_price'])
// {
// $new_goods_info['market_price'] = '';
// }
// $tags = array(
// 'isNew' => false,
// 'isSale' => false,
// 'isLimit' => false,
// 'isYohood' => false,
// 'midYear' => false,
// 'yearEnd' => false,
// );
// foreach ($new_goods_info['tags'] as $v){
// if($v == 'is_new'){
// $tags['isNew'] = true;
// }elseif($v == 'is_discount'){
// $tags['isSale'] = true;
// }elseif($v == 'is_limited'){
// $tags['isLimit'] = true;
// }elseif($v == 'is_yohood'){
// $tags['isYohood'] = true;
// }elseif($v == 'mid-year'){
// $tags['midYear'] = true;
// }elseif($v == 'year-end'){
// $tags['yearEnd'] = true;
// }
// }
// $newPatterns[$new_goods_info['product_skn']]= array (
// 'id'=>$new_goods_info['product_skn'],
// 'product_id'=>$new_goods_info['product_id'],
// 'product_skn'=>$new_goods_info['product_skn'],
// 'thumb' => $new_goods_info['default_images'],
// 'name' => $new_goods_info['product_name'],
// 'isLike' => $isLike,
// 'price' => $new_goods_info['market_price'],
// 'salePrice' => $new_goods_info['sales_price'],
// 'isSale' => $new_goods_info['is_discount'] == 'Y' ? true : false,
// 'isFew' => $new_goods_info['is_soon_sold_out'] == 'Y' ? true : false,
// 'isNew' => $new_goods_info['is_new'] == 'Y' ? true : false,
// 'url' => $url,
// 'tags' => $tags
// );
}
}
... ...
<?php
namespace LibModels\Wap\Passport;
use Api\Yohobuy;
use Api\Sign;
use Api\Yohobuy;
/**
* 登录的数据模型
*
* @name LoginData
* @package LibModels/Wap/Passport
* @copyright yoho.inc
* @version 1.0 (2015-10-12 14:05:04)
* @author fei.hong <fei.hong@yoho.cn>
*/
class LoginData
{
/**
* 第三方登录接口(包括alipay,qq,sina)
* @param string $nickname 姓名
* @param string $openId 第三方唯一识别码
* @param string $sourceType 登录方式
* @return array 登录返回结果
*/
public static function signinByOpenID($nickname, $openId, $sourceType)
{
// 构建必传参数
$param = Yohobuy::param();
{
/**
* 登录
*
* @param string $profile 邮箱或手机号
* @param string $password 密码
* @return array
*/
public static function signin($profile, $password)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.signin';
$param['profile'] = $profile;
$param['password'] = $password;
return Yohobuy::post(Yohobuy::API_URL, $param);
}
/**
* 用户信息
*
* @param int $uid 用户唯一ID
* @return array
*/
public static function profile($uid)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.profile';
$param['uid'] = $uid;
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 第三方登录接口(包括alipay,qq,sina)
* @param string $nickname 姓名
* @param string $openId 第三方唯一识别码
* @param string $sourceType 登录方式
* @return array 登录返回结果
*/
public static function signinByOpenID($nickname, $openId, $sourceType)
{
// 构建必传参数
$param = Yohobuy::param();
$param['method'] = 'app.passport.signinByOpenID';
$param['openId'] = $openId;
$param['source_type'] = $sourceType;
$param['openId'] = $openId;
$param['source_type'] = $sourceType;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
}
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
namespace LibModels\Wap\Passport;
use Api\Sign;
use Api\Yohobuy;
/**
* 注册的数据模型
*
* @name RegData
* @package LibModels/Wap/Passport
* @copyright yoho.inc
* @version 1.0 (2015-10-12 14:04:55)
* @author fei.hong <fei.hong@yoho.cn>
*/
class RegData
{
/**
* 获取地区数据
*
* @return array 地区数据
*/
public static function getAreasData()
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.getArea';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 发送手机注册验证码
*
* @param string $area 地区号 如"86"
* @param string $mobile 手机号
* @return array
*/
public static function sendCodeToMobile($area, $mobile)
{
$param = Yohobuy::param();
$param['method'] = 'app.register.sendRegCodeToMobile';
$param['area'] = $area;
$param['mobile'] = $mobile;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
}
/**
* 验证手机注册的识别码
*
* @param string $area 地区号 如"86"
* @param string $mobile 手机号
* @param string $code 验证码
* @return array
*/
public static function validMobileCode($area, $mobile, $code)
{
$param = Yohobuy::param();
$param['method'] = 'app.register.validRegCode';
$param['area'] = $area;
$param['mobile'] = $mobile;
$param['code'] = $code;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
}
/**
* 通过手机注册
*
* @param string $area 地区号 如"86"
* @param string $mobile 手机号
* @param string $password 登录密码
* @return array
*/
public static function regMobile($area, $mobile, $password)
{
$param = Yohobuy::param();
$param['method'] = 'app.passport.register';
$param['area'] = $area;
$param['profile'] = $mobile;
$param['password'] = $password;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::post(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -22,15 +22,55 @@ class Helpers
}
/**
* 从数组中中获取指定键值对应的元素
* @param array $array 需要获取的数组
* @param array|string $keys 指定键值,数组或者字符串
* @return array 获取的数据
* 格式化商品信息
*
* @param array $productData 需要格式化的商品数据
* @return array | false
*/
public static function array_get($array, $keys)
public static function formatProduct($productData)
{
return array_intersect_key($array, array_flip((array) $keys));
// 商品信息有问题,则不显示
if (!isset($productData['product_skn'])) {
return false;
}
// 市场价和售价一样,则不显示市场价
if (intval($productData['market_price']) === intval($productData['sales_price'])) {
$productData['market_price'] = '';
}
$result = array();
$result['id'] = $productData['product_skn'];
$result['product_id'] = $productData['product_id'];
$result['thumb'] = $productData['default_images'];
$result['name'] = $productData['product_name'];
$result['price'] = $productData['market_price'];
$result['salePrice'] = $productData['sales_price'];
$result['isFew'] = ($productData['is_soon_sold_out'] === 'Y') ? true : false;
$result['url'] = ''; // @todo
$result['tags'] = array(
'isNew' => false, // 新品
'isSale' => false, // 在售
'isLimit' => false, // 限量
'isNewFestival' => false, // 新品节
'isReNew' => false, // 再到着
'isYohood' => false, // YOHOOD
'midYear' => false, // 年中
'yearEnd' => false, // 年末
);
foreach ($productData['tags'] as $tag) {
if ($tag['is_limited'] === 'Y') {
$result['tags']['isLimit'] = true;
} elseif ($tag['is_yohood'] === 'Y') {
$result['tags']['isYohood'] = true;
} elseif ($tag['is_new'] === 'Y') {
$result['tags']['isNew'] = true;
}
}
return $result;
}
}
\ No newline at end of file
... ...
... ... @@ -32,7 +32,7 @@ class TemplateLayout implements View_Interface
*/
public function assign($name, $value = null)
{
$this->tpl_vars[$name] = $value;
$this->_tpl_vars[$name] = $value;
}
/**
... ... @@ -43,10 +43,10 @@ class TemplateLayout implements View_Interface
*/
public function clear($name = null)
{
if (isset($this->tpl_vars[$name])) {
unset($this->tpl_vars[$name]);
if (isset($this->_tpl_vars[$name])) {
unset($this->_tpl_vars[$name]);
} else {
$this->tpl_vars = array();
$this->_tpl_vars = array();
}
}
... ... @@ -79,8 +79,11 @@ class TemplateLayout implements View_Interface
if (!file_exists($viewName)) {
return '';
}
$tpl_vars = array_merge($this->tpl_vars, $tpl_vars);
// 合并通过assign传递的参数
if (is_array($this->_tpl_vars)) {
$tpl_vars = array_merge($this->_tpl_vars, $tpl_vars);
}
// 取得模板的最后修改时间戳
$lastModifyTime = filemtime($viewName);
// 使用MD5生成唯一的键名
... ... @@ -131,7 +134,7 @@ class TemplateLayout implements View_Interface
{
$result = false;
if (is_dir($path)) {
$this->tpl_dir = $path;
$this->_tpl_dir = $path;
$result = true;
}
return $result;
... ...
{{>layout/header}}
<code>
{{#focus}}
<ul>
{{#each data}}
{{#data}}
<li><img src="{{src}}" alt="{{title}}"></li>
{{/data}}
{{/each}}
</ul>
{{/focus}}
</code>
{{>layout/footer}}
\ No newline at end of file
... ...
... ... @@ -23,7 +23,7 @@
}());
})(document, window);
</script>
<link rel="stylesheet" href="http://static.dev.yohobuy.com/css/index.css">
<link rel="stylesheet" href="http://172.16.6.248:8088/css/index.css">
</head>
<body {{#if isPassportPage}}class=passport-body{{/if}}>
{{> layout/page_header}}
\ No newline at end of file
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Guang\PlusstarData;
use Plugin\Helpers;
/**
* 明星品牌和原创品牌
*/
class PlusstarController extends AbstractAction
{
/**
* 品牌列表页
*
* @param int gender "1,3"表示男, "2,3"表示女
*/
public function listAction()
{
$data = array(
'star' => array(
array(
'imgs' => array(
array(
'url' => 'http://stussy.m.yohobuy.com',
'img' => 'http://ad.yoho.cn/yohobuy/newfestival/img/brandsmap/6KTZ_01.jpg'
),
array(
'url' => 'http://stussy.m.yohobuy.com',
'img' =>'http://ad.yoho.cn/yohobuy/newfestival/img/brandsmap/5HUF_01.jpg'
)
)
),
array(
'url' => 'http://stussy.m.yohobuy.com',
'img' => 'http://ad.yoho.cn/yohobuy/newfestival/img/brandsmap/4STAYREAL_02.jpg',
'deps' => '优秀的自助品牌,高瞻远瞩的建设性意见来测试文字溢出后的处理问题'
)
),
'plus' => array(
)
);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('list', array('test' => 'hello world'));
$test = PlusstarData::brandList("1,3", 1);
var_dump($test);
$data = array('ps' => array('star' => array(), 'plus' => array()));
$brandList = array();
$build = array();
$imgs = array();
$gender = $this->get('gender', '1,3');
// 女
if ($gender === '2,3') {
$brandList = PlusstarData::brandList('2,3', 2);
}
// 男
else {
$brandList = PlusstarData::brandList('1,3', 1);
}
// 明星品牌列表
if (!empty($brandList['star']['data']['list'][0]['data'])) {
foreach ($brandList['star']['data']['list'][0]['data'] as $star) {
$imgs = array();
$build = array();
// 情况1: 多张图
if (isset($star['data'][1])) {
foreach ($star['data'] as $value) {
$build['url'] = $value['url'];
$build['img'] = Helpers::getImageUrl($value['src'], 640, 310);
$imgs[] = $build;
}
$data['ps']['star'][] = array('imgs' => $imgs);
}
// 情况2: 单张图
elseif (isset($star['data'][0])) {
$build['url'] = $star['data'][0]['url'];
$build['img'] = $star['data'][0]['src'];
$data['ps']['star'][] = $build;
}
}
}
// 原创品牌列表
if (!empty($brandList['original']['data']['list'][0]['data'])) {
foreach ($brandList['original']['data']['list'][0]['data'] as $original) {
$imgs = array();
$build = array();
// 情况1: 多张图
if (isset($original['data'][1])) {
foreach ($original['data'] as $value) {
$build['url'] = $value['url'];
$build['img'] = Helpers::getImageUrl($value['src'], 640, 310);
$build['deps'] = $original['brand_title'];
$imgs[] = $build;
}
$data['ps']['plus'][] = array('imgs' => $imgs);
}
// 情况2: 单张图
elseif (isset($original['data'][0])) {
$build['url'] = $original['data'][0]['url'];
$build['img'] = Helpers::getImageUrl($original['data'][0]['src'], 640, 310);
$build['deps'] = $original['brand_title'];
$data['ps']['plus'][] = $build;
}
}
}
$this->_view->display('list', $data);
$brandList = array();
$data = array();
}
/**
* 品牌介绍页
*/
public function detailAction()
{
$test = PlusstarData::brandInfo(67, '1,3', 123456);
var_dump($test);
$data = array();
$id = $this->get('id');
$gender = $this->get('gender', '1,3');
$uid = 0; // @todo
$udid = null; // @todo
do {
/* 判断参数是否有效 */
if (!is_numeric($id) || ($gender !== '1,3' && $gender !== '2,3')) {
break;
}
/* 判断品牌信息是否为空 */
$brandInfo = PlusstarData::brandInfo($id, $gender, $uid, $udid); var_dump($brandInfo); exit;
if (empty($brandInfo['getBrandInfo']['brand_id'])) {
break;
}
$data['id'] = $brandInfo['getBrandInfo']['brand_id'];
$data['banner'] = Helpers::getImageUrl($brandInfo['getBrandInfo']['cover_img'], 640, 309);
$data['logo'] = Helpers::getImageUrl($brandInfo['getBrandInfo']['brand_ico'], 160, 160);
$data['name'] = $brandInfo['getBrandInfo']['name'];
$data['isLike'] = $brandInfo['getUidBrandFav'];
$data['likeUrl'] = "http://guang.m.yohobuy.com/plustar/brandinfo?id=285&amp;openby:yohobuy={&quot;action&quot;:&quot;go.weblogin&quot;,&quot;params&quot;:{&quot;jumpurl&quot;:{&quot;url&quot;:&quot;http:\/\/guang.m.yohobuy.com\/plustar\/brandinfo&quot;,&quot;param&quot;:{&quot;id&quot;:285}},&quot;requesturl&quot;:{&quot;url&quot;:&quot;\/guang\/api\/v1\/favorite\/togglebrand&quot;,&quot;param&quot;:{&quot;brand_id&quot;:&quot;701&quot;}},&quot;priority&quot;:&quot;Y&quot;}}";
$data['intro'] = empty($brandInfo['brand_intro']) ? '' : strip_tags($brandInfo['brand_intro']);
$data['newArrival'] = array();
$data['newArrival']['moreUrl'] = ''; // @todo
$data['newArrival']['naList'] = $brandInfo['getNewProduct'];
$data['infos'] = array();
$brandInfo = array();
} while (false);
if (array() === $data) {
$this->error();
} else {
$this->_view->display('detail', $data);
}
}
}
\ No newline at end of file
}
... ...