Authored by Rock Zhang

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

... ... @@ -4,7 +4,7 @@
* 所有Controller控制器的基类
*
* @name AbstractAction
* @package
* @package library
* @copyright yoho.inc
* @version 1.0 (2015-9-15 11:55:25)
* @author fei.hong <fei.hong@yoho.cn>
... ... @@ -25,6 +25,12 @@ class AbstractAction extends Controller_Abstract
* @var object
*/
protected $_request;
/**
* 用户相关信息
*/
protected $_uid;
protected $_uname;
/**
* 初始化
... ... @@ -35,13 +41,13 @@ class AbstractAction extends Controller_Abstract
// 设置环境变量
switch (APPLICATION_ENV) {
case 'production':
case 'production': // 生产
$this->_view->assign('rlsEnv', true);
break;
case 'testing':
case 'testing': // 测试
$this->_view->assign('testEnv', true);
break;
case 'develop':
case 'develop': // 开发
default:
$this->_view->assign('devEnv', true);
break;
... ... @@ -144,7 +150,7 @@ class AbstractAction extends Controller_Abstract
* @param integer $path cookie可用的路径
* @param string $domain cookie可用域名
*/
protected function setCookie($name, $value, $expire = 0, $path = '/',$domain = 'yohobuy.com')
protected function setCookie($name, $value, $expire = 0, $path = '/', $domain = '.yohobuy.com')
{
setcookie($name, $value, $expire, $path, $domain);
}
... ... @@ -158,7 +164,7 @@ class AbstractAction extends Controller_Abstract
*/
protected function getCookie($name, $default = '')
{
return $this->request->getCookie($name, $default);
return $this->_request->getCookie($name, $default);
}
/**
... ... @@ -198,7 +204,17 @@ class AbstractAction extends Controller_Abstract
*/
protected function getUid()
{
return 0;
if (!$this->_uid) {
$cookie = $this->getCookie('_UID');
if (!empty($cookie)) {
$cookieList = explode('::', $cookie);
if (isset($cookieList[1]) && is_numeric($cookieList)) {
$this->_uid = $cookieList[1];
$this->_uname = $cookieList[0];
}
}
}
return $this->_uid;
}
/**
... ... @@ -215,6 +231,26 @@ class AbstractAction extends Controller_Abstract
}
return $udid;
}
/**
* 获取当前登录的用户名字
*
* @return int
* @todo
*/
protected function getUname()
{
if (!$this->_uname) {
$cookie = $this->getCookie('_UID');
if (!empty($cookie)) {
$cookieList = explode('::', $cookie);
if (isset($cookieList[0])) {
$this->_uname = $cookieList[0];
}
}
}
return $this->_uname;
}
/*
* 设置网站SEO的标题
... ... @@ -284,17 +320,18 @@ class AbstractAction extends Controller_Abstract
$footer = array();
// 已登录 @todo
if (false) {
$name = $this->getUname();
if (!empty($name)) {
$footer['user'] = array();
$footer['user']['name'] = 'goodboy'; // 昵称
$footer['user']['name'] = $name; // 昵称
$footer['user']['url'] = ''; // 个人中心链接
$footer['user']['signoutUrl'] = ''; // 登出链接
$footer['user']['signoutUrl'] = '/passport/login/out'; // 登出链接
}
// 未登录
else {
$footer = array();
$footer['loginUrl'] = '/signin.html'; // 登录链接
$footer['signupUrl'] = '/login.html'; // 注册链接
$footer['signupUrl'] = '/reg.html'; // 注册链接
}
$this->_view->assign('pageFooter', $footer);
... ... @@ -313,25 +350,25 @@ class AbstractAction extends Controller_Abstract
'textCn' => '男生',
'textEn' => 'BOYS',
'styleClass' => 'boys',
'url' => '/boys.html',
'url' => '/boys',
),
1 => array(
'textCn' => '女生',
'textEn' => 'GIRLS',
'styleClass' => 'girls',
'url' => '/girls.html',
'url' => '/girls',
),
2 => array(
'textCn' => '潮童',
'textEn' => 'KIDS',
'styleClass' => 'kids',
'url' => '/kids.html',
'url' => '/kids',
),
3 => array(
'textCn' => '创意生活',
'textEn' => 'LIFE STYLE',
'styleClass' => 'life',
'url' => '/life.html',
'url' => '/life',
),
4 => array(
'textCn' => '逛',
... ...
... ... @@ -9,15 +9,20 @@
* @version 1.0 (2015-9-30 16:42:51)
* @author fei.hong <fei.hong@yoho.cn>
*/
namespace Api;
use Plugin\Cache;
namespace Api;
class Yohobuy
{
const API_URL = 'http://api2.open.yohobuy.com/';
const SERVICE_URL = 'http://service.api.yohobuy.com/';
// /* 正式环境 */
// const API_URL = 'http://api2.open.yohobuy.com/';
// const SERVICE_URL = 'http://service.api.yohobuy.com/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
/* 测试环境 */
const API_URL = 'http://test2.open.yohobuy.com/';
const SERVICE_URL = 'http://test.service.api.yohobuy.com/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';
/**
... ... @@ -101,18 +106,6 @@ class Yohobuy
*/
public static function get($url, $data = array(), $returnJson = false, $timeout = 5)
{
// // 代表是否开启缓存
// $useCache = $cache && isset($data['client_secret']);
//
// /* 先尝试获取一级缓存(master), 有数据则直接返回 */
// if ($useCache) {
// $key = md5($url . $data['client_secret']);
// $result = Cache::get($key, 'master');
// if (!empty($result)) {
// return $result;
// }
// }
// 销毁私钥参数
if (isset($data['private_key'])) {
unset($data['private_key']);
... ... @@ -131,18 +124,6 @@ class Yohobuy
}
curl_close($ch);
$data = array();
// /* 设置一级二级缓存 或 获取二级缓存(slave) */
// if ($useCache) {
// // 如果接口异常没数据返回,则获取二级缓存
// if (empty($result)) {
// $result = Cache::get($key, 'slave');
// }
// // 如果接口正常有数据返回,则设置数据缓存
// else {
// Cache::set($key, $result);
// }
// }
return $result;
}
... ... @@ -165,8 +146,7 @@ class Yohobuy
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if (!empty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
}
else {
} else {
curl_setopt($ch, CURLOPT_HEADER, 0);
}
... ... @@ -242,8 +222,7 @@ class Yohobuy
do {
do {
$status = curl_multi_exec($mh, $running);
}
while ($status == CURLM_CALL_MULTI_PERFORM);
} while ($status == CURLM_CALL_MULTI_PERFORM);
if ($status != CURLM_OK) {
break;
... ... @@ -252,8 +231,7 @@ class Yohobuy
if ($running > 0) {
curl_multi_select($mh, 0.5);
}
}
while ($running);
} while ($running);
// 获取API接口响应的结果
foreach ($urlList as $name => $api) {
... ... @@ -293,16 +271,16 @@ class Yohobuy
$client->SetOpt(YAR_OPT_PACKAGER, 'php');
$client->SetOpt(YAR_OPT_TIMEOUT, $timeout);
$client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, $timeout);
try {
$result = call_user_func_array(array($client, $method), $parameters);
} catch (\Exception $e) {
$result = array();
}
return $result;
}
/**
* 并行(异步)调用远程服务
*
... ... @@ -322,6 +300,7 @@ class Yohobuy
YAR_OPT_CONNECT_TIMEOUT => $timeout
));
}
public static function yarConcurrentLoop($callback = null)
{
\Yar_Concurrent_Client::loop($callback);
... ...
<?php
namespace Configs;
/**
* 缓存配置文件
*/
class CacheConfig
{
const KEY_ACTION_INDEX_INDEX = 'key_action_index_index';
}
... ...
<?php
namespace LibModels\Wap\Category;
use Api\Yohobuy;
... ... @@ -15,22 +16,22 @@ use Api\Sign;
*/
class BrandData
{
/**
* 获取品牌数据
/**
* 获取品牌数据
*
* @param integer $channel 是否,默认1表示是,传值为空是app中用于品牌搜索的数据
* @param integer $channel 是否,默认1表示是,传值为空是app中用于品牌搜索的数据
*
* @return array 品牌数据
*/
* @return array 品牌数据
*/
public static function getBrandsData($channel = 1)
{
// 构建必传参数
$param = Yohobuy::param();
// 构建必传参数
$param = Yohobuy::param();
$param['method'] = 'app.brand.brandlist';
$param['yh_channel'] = $channel;
$param['yh_channel'] = $channel;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
... ... @@ -41,13 +42,12 @@ class BrandData
*/
public static function getBrandTopData()
{
// 构建必传参数
$param = Yohobuy::param();
$param['content_code'] = 'ce6ac059493ec26241a8cbe0bfa1b17a';
// 构建必传参数
$param = Yohobuy::param();
$param['content_code'] = 'ce6ac059493ec26241a8cbe0bfa1b17a';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL.'operations/api/v5/resource/get', $param);
return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/resource/get', $param);
}
/**
... ... @@ -60,11 +60,10 @@ class BrandData
{
// 构建必传参数
$param = Yohobuy::param();
$param['brand_id'] = '$brandId';
$param['brand_id'] = $brandId;
$param['method'] = 'app.brand.getBrandIntro';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
... ... @@ -77,11 +76,10 @@ class BrandData
{
// 构建必传参数
$param = Yohobuy::param();
$param['brand_id'] = '$brandId';
$param['brand_id'] = $brandId;
$param['method'] = 'app.brand.banner';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
... ... @@ -113,7 +111,9 @@ class BrandData
'p_d' => $p_d
);
// 拉取筛选参数
$queriedParams = array_filter($selectItems, function($v) {return $v !== null;});
$queriedParams = array_filter($selectItems, function($v) {
return $v !== null;
});
// 构建必传参数
$param = Yohobuy::param();
... ... @@ -123,7 +123,8 @@ class BrandData
$param['limit'] = $limit;
$param['yh_channel'] = $channel;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -22,7 +22,6 @@ class FloorProcess
}
foreach ($data['list'] as $v){
$fun = $v['template_name'];
$data = self::$fun($v['data'],$type);
if(empty($data)){
continue;
... ... @@ -259,9 +258,10 @@ class FloorProcess
if(empty($data)){
return array();
}
$data['name'] = $data['title'];
$data['img'] = Images::getImageUrl($data['src'], 640, 198, 2);
$data['img'] = Helpers::getImageUrl($data['src'], 640, 198, 2);
return array('plusStar'=>$data['data']);
return array('plusStar'=>$data);
}
}
... ...
... ... @@ -16,16 +16,14 @@ class BoysController extends AbstractAction
$this->setTitle('男生首页');
// 显示侧边栏
$this->setNavSide();
// 显示顶部下载
$this->setHeaderDownload();
// 设置顶部信息(搜索)
$this->setHomeChannelHeader();
$data = array('boysHomePage' => true);
$uid = $this->getUid();
// 频道数据
$channelData = IndexData::getUserChannelData(0, '1,3', '201504091403001');
$channelData = IndexData::getUserChannelData($uid, '1,3', '201504091403001');
if (isset($channelData['code']) && $channelData['code'] == 200) {
$data['content'] = FloorProcess::getContent($channelData['data']);
}
... ...
... ... @@ -16,16 +16,14 @@ class GirlsController extends AbstractAction
$this->setTitle('女生首页');
// 显示侧边栏
$this->setNavSide();
// 显示顶部下载
$this->setHeaderDownload();
// 设置顶部信息(搜索)
$this->setHomeChannelHeader();
$data = array('grilsHomePage' => true);
$uid = $this->getUid();
// 频道数据
$channelData = IndexData::getUserChannelData(0, '2,3', '201504091403002');
$channelData = IndexData::getUserChannelData($uid, '2,3', '201504091403002');
if (isset($channelData['code']) && $channelData['code'] == 200) {
$data['content'] = FloorProcess::getContent($channelData['data'], 2);
}
... ...
... ... @@ -15,8 +15,6 @@ class IndexController extends AbstractAction
*/
public function indexAction()
{
$data = array();
// 背景图获取
$banner = IndexData::getBannerStart();
if ($banner) {
... ...
... ... @@ -16,16 +16,14 @@ class KidsController extends AbstractAction
$this->setTitle('潮童首页');
// 显示侧边栏
$this->setNavSide();
// 显示顶部下载
$this->setHeaderDownload();
// 设置顶部信息(搜索)
$this->setHomeChannelHeader();
$data = array('kidsHomePage' => true);
$uid = $this->getUid();
// 频道数据
$channelData = IndexData::getUserChannelData(0, '', 'e9875682c1599a886bfbdb965b740022');
$channelData = IndexData::getUserChannelData($uid, '', 'e9875682c1599a886bfbdb965b740022');
if (isset($channelData['code']) && $channelData['code'] == 200) {
$data['content'] = FloorProcess::getContent($channelData['data'], 3);
}
... ...
... ... @@ -16,16 +16,14 @@ class LifestyleController extends AbstractAction
$this->setTitle('创意生活首页');
// 显示侧边栏
$this->setNavSide();
// 显示顶部下载
$this->setHeaderDownload();
// 设置顶部信息(搜索)
$this->setHomeChannelHeader();
$data = array('lifestyleHomePage' => true);
$uid = $this->getUid();
// 频道数据
$channelData = IndexData::getUserChannelData(0, '', '9aa25f5133f011ec96c2045eb15ae425');
$channelData = IndexData::getUserChannelData($uid, '', '9aa25f5133f011ec96c2045eb15ae425');
if (isset($channelData['code']) && $channelData['code'] == 200) {
$data['content'] = FloorProcess::getContent($channelData['data'], 4);
}
... ...
... ... @@ -59,6 +59,18 @@ class LoginController extends AbstractAction
// 渲染模板
$this->_view->display('interational', $data);
}
/**
* 退出
*
* @todo
*/
public function outAction()
{
$this->setCookie('_UID', '');
headers_sent() || header('Location: /');
}
/**
* 登录操作
... ... @@ -95,9 +107,23 @@ class LoginController extends AbstractAction
/* 调用登录接口进行登录 */
$data = LoginData::signin($area, $profile, $password);
if ($data['code'] == 200) {
$data['data'] = '/'; // @todo
if ($data['code'] != 200 || !isset($data['data']['uid'])) {
break;
}
// /* 获取用户的信息 */
// $profile = LoginData::profile($data['data']['uid']);
// $name = 'YOHO!';
// if (!empty($profile['data']['nickname'])) {
// $name = $profile['data']['nickname'];
// } elseif (!empty($profile['data']['username'])) {
// $name = $profile['data']['username'];
// } elseif (!empty($profile['data']['email'])) {
// $name = $profile['data']['email'];
// } elseif (!empty($profile['data']['mobile'])) {
// $name = $profile['data']['mobile'];
// }
$data['data'] = '/'; // @todo
}
while (false);
... ...
... ... @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Api,LibModels,Plugin"
application.namespaces = "Action,Api,Configs,LibModels,Plugin"
;;使用composer
composer.autoload = 0
... ...
... ... @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Api,LibModels,Plugin"
application.namespaces = "Action,Api,Configs,LibModels,Plugin"
;;使用composer
composer.autoload = 0
... ...
... ... @@ -19,7 +19,7 @@ application.dispatcher.defaultController = "index"
application.dispatcher.defaultAction = "index"
;;初始化命名空间
application.namespaces = "Action,Api,LibModels,Plugin"
application.namespaces = "Action,Api,Configs,LibModels,Plugin"
;;使用composer
composer.autoload = 0
... ...
User-agent: *
Disallow: /
\ No newline at end of file
... ...