Authored by whb

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

... ... @@ -142,20 +142,35 @@ class SearchData extends \LibModels\Wap\Product\SearchData
*/
public static function getSearchDataBySort(array $params, array $sortList)
{
$data = array();
foreach ($sortList as $v) {
if(empty($v['viewNum'])){
continue;
}
$searchParams = array_merge($params, $v);
$list = self::searchElasticByCondition($searchParams, true);
$productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list'];
if(count($productList) < $v['viewNum']){
continue;
}
$data = array_merge($data, $productList);
// $data = array();
// foreach ($sortList as $v) {
// if(empty($v['viewNum'])){
// continue;
// }
// $searchParams = array_merge($params, $v);
// $list = self::searchElasticByCondition($searchParams, true);
// $productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list'];
// if(count($productList) < $v['viewNum']){
// continue;
// }
// $data = array_merge($data, $productList);
// }
// return $data;
/* 2016/01/26 code review by fei.hong: 优化合并misort参数, 减少调用搜索的次数 */
$sortIds = '';
$viewNum = 0;
foreach ($sortList as $value) {
$viewNum += intval($value['viewNum']);
$sortIds .= $value['misort'] . ',';
}
return $data;
$params['viewNum'] = $viewNum;
$params['misort'] = rtrim($sortIds, ',');
$searchd = self::searchElasticByCondition($params);
if (empty($searchd['data']['product_list'])) {
return array();
}
return $searchd['data']['product_list'];
}
/**
... ...
... ... @@ -226,6 +226,7 @@ class Helpers
if ($oneGoods['is_default'] === 'Y') {
$productData['default_images'] = self::procProductImg($oneGoods);
$flag = true;
break;
}
}
// 如果还未赋值,则取第一个skc产品的默认图片
... ... @@ -247,7 +248,7 @@ class Helpers
$result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y');
$result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_'
. $productData['goods_list'][0]['goods_id']
. '/' . $productData['cn_alphabet'] . '.html', 'item');
. '/' . $productData['cn_alphabet'] . '.html', array(), 'item');
// APP访问需要加附加的参数
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
if ($isApp) {
... ...
... ... @@ -12,8 +12,10 @@
</li>
{{#each list}}
<li {{#if active}}class="active"{{/if}}>
<a href="{{href}}">{{name}}</a>
<span>{{num}}</span>
<a href="{{href}}">
{{name}}
<span>{{num}}</span>
</a>
</li>
{{/each}}
</ul>
... ... @@ -30,8 +32,10 @@
<ul class="sort-child-list new-sale">
{{#each list}}
<li {{#if active}}active{{/if}}>
<a href="{{href}}">{{name}}</a>
<span>{{num}}</span>
<a href="{{href}}">
{{name}}
<span>{{num}}</span>
</a>
</li>
{{/each}}
</ul>
... ...
... ... @@ -51,7 +51,8 @@
}
/*990px*/
.min-screen .product-list-page, .new-sale-page {
.min-screen .product-list-page,
.min-screen .new-sale-page {
.list-right {
width: 810px;
... ...
... ... @@ -51,25 +51,22 @@ class PlusstarModel
}
$result = array();
$brandList = PlusstarData::firstBrandList($gender, $channel);
if (!empty($brandList['recom']['data']['list'][0]['data'])) {
$result['ps']['star'] = self::formatData($brandList['recom']['data']['list'][0]['data'], $gender, true);
//$result['ps']['sName'] = isset($brandList['recom']['data']['brand_type_name']) ? $brandList['recom']['data']['brand_type_name'] : '';
}
if (!empty($brandList['all']['data']['list'][0]['data'])) {
$result['ps']['plus'] = self::formatData($brandList['all']['data']['list'][0]['data'], $gender, true);
//$result['ps']['pName'] = isset($brandList['all']['data']['brand_type_name']) ? $brandList['all']['data']['brand_type_name'] : '';
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($brandList['recom']['data']['list'][0]['data']) || empty($brandList['all']['data']['list'][0]['data'])) {
if (USE_CACHE) {
$result = Cache::get($key, 'slave');
}
return $result;
}
$result['ps']['star'] = self::formatData($brandList['recom']['data']['list'][0]['data'], $gender, true);
$result['ps']['plus'] = self::formatData($brandList['all']['data']['list'][0]['data'], $gender, true);
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result);
}
Cache::set($key, $result);
}
return $result;
... ...
... ... @@ -49,8 +49,8 @@ class CommonController extends WebAction
HomeModel::COOKIE_NAME_LIFESTYLE
);
$channel = $this->post('type', '');
$pageIndex = intval($this->post('pageIndex', 0));
$pageCount = intval($this->post('pageCount', 8));
$pageIndex = (int) $this->post('pageIndex', 0);
$pageCount = (int) $this->post('pageCount', 8);
if (! in_array($channel, $channels)) {
break;
} else {
... ...
... ... @@ -247,14 +247,13 @@ class HomeModel
*/
public static function getNewArrival($channel)
{
$result = array();
$key = sprintf(WebCacheConfig::KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA.'_'.$channel);
$key = WebCacheConfig::KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA . '_' . $channel;
//缓存数据
$result = Cache::get($key);
if(empty($result)) {
if (empty($result)) {
$params = array(
'order' => 's_t_desc',
'shelve_time' => strtotime("-60 days") . ',' . time()
'order' => 's_t_desc',
'shelve_time' => strtotime("-60 days") . ',' . time()
);
//男首频道最新上架参数是gender=1,3
if($channel == self::COOKIE_NAME_BOYS) {
... ... @@ -270,9 +269,13 @@ class HomeModel
// 获取分类列表获取商品信息
$goodsList = SearchData::getSearchDataBySort($params, $sortList);
$pos = 1;
$val = array();
foreach ($goodsList as $goods) {
// 格式化数据
$val = Helpers::formatProduct($goods, true, true, true, 280, 373);
if (!$val) {
continue;
}
if ($val['price'] == false) {
$val['price'] = $val['salePrice'];
}
... ... @@ -287,13 +290,16 @@ class HomeModel
$val['tags']['isReNew'] = false;//$val['tags']['is_advance'];暂时不显示
unset($val['tags']['is_advance'], $val['tags']['is_discount'], $val['tags']['is_limited'], $val['tags']['is_new'],
$val['tags']['is_yohood'], $val['tags']['midYear'], $val['tags']['yearEnd']);
if (! empty($val)) {
$result[] = $val;
}
$result[] = $val;
}
}
Cache::set($key, $result, 3600);
}
// 当一级缓存失效,并且接口异常时, 尝试从二级缓存获取数据
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
return $result;
}
}
\ No newline at end of file
... ...
... ... @@ -7,6 +7,7 @@ use LibModels\Web\Home\IndexData;
use LibModels\Web\Home\UserData;
use WebPlugin\Images;
use WebPlugin\Captcha;
use WebPlugin\Cache;
/**
* web登录注册等相关数据构建
... ... @@ -134,4 +135,22 @@ class PassportModel
return $ret;
}
/*
* 重写递增计数 cache方法
* $key cache-key
* $offset 递增偏移量
* $initValue 初始化值
* $expiry 缓存时间
*/
public static function increment($key, $offset = 1, $initValue = 0, $expire = 1800)
{
//初始化key
if (!Cache::get($key)) {
Cache::set($key, $initValue, $expire);
}
//增加偏移量
$cacheValue = intval(Cache::get($key))+$offset;
Cache::set($key, $cacheValue, $expire);
}
}
... ...
... ... @@ -135,12 +135,14 @@ class BrandsModel
//获取$condition和$option 筛选条件和排序条件
$searchCondition = SearchModel::searchCondition($customCondition, $customOptions);
// 组合搜索商品url
$urlList['product'] = SearchData::getProductUrl($searchCondition['condition']);
// 组合搜索分类url
$urlList['sort'] = SearchData::getClassesUrl($searchCondition['sortCondition']);
$brandSort = array(
'brand' => $searchCondition['sortCondition']['brand']
);
$urlList['sort'] = SearchData::getClassesUrl($brandSort);
//组合搜索品牌url
$urlList['brand'] = SearchData::getBrandUrl($customOptions);
... ...
... ... @@ -109,27 +109,22 @@ class LoginController extends WebAction
$ip = Helpers::getClientIp();
$ipKey = md5('ip_signin_' . $ip);
$accountKey = md5('account_signin_' . $account);
if (!Cache::get($ipKey)) {
Cache::set($ipKey, 0);
}
if (!Cache::get($accountKey)) {
Cache::set($accountKey, 0);
}
Cache::increment($ipKey, 1, 0, 3600);
PassportModel::increment($ipKey, 1, 0, 3600);
$accountTimes = Cache::get($accountKey);
$ipTimes = Cache::get($ipKey);
if ($accountTimes > 10) {
$data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => '');
break;
}
$ipTimes = Cache::get($ipKey);
if ($ipTimes > 100) {
$data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => '');
break;
}
$data = LoginData::signin($area, $account, $password, $shoppingKey);
if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) {
Cache::increment($accountKey, 1, 0, 1800);
$data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => '');
PassportModel::increment($accountKey, 1, 0, 1800);
$data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => '');
break;
}
... ...
... ... @@ -48,10 +48,8 @@ class RegisterController extends WebAction
$ip = Helpers::getClientIp();
$data = array('code' => 400, 'message' => '', 'data' => '');
$ipKey = md5('ip_checkmobile_' . $ip);
if (!Cache::get($ipKey)) {
Cache::set($ipKey, 0);
}
$ipTimes = Cache::increment($ipKey, 1, 0, 3600);
PassportModel::increment($ipKey, 1, 0, 3600);
$ipTimes = Cache::get($ipKey);
do{
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
... ... @@ -132,10 +130,8 @@ class RegisterController extends WebAction
}
//发送代码
$sendCodeKey = md5('send_code_' . $area . '_' . $mobile);
if (!Cache::get($sendCodeKey)) {
Cache::set($sendCodeKey, 0);
}
$sendCodeTimes = Cache::increment($sendCodeKey, 1, 0, 3600);
PassportModel::increment($sendCodeKey, 1, 0, 3600);
$sendCodeTimes = Cache::get($sendCodeKey);
if ($sendCodeTimes > 50) {
$data['message'] = '发送验证码太多';
break;
... ...
... ... @@ -25,6 +25,7 @@ class ThirdloginController extends WebAction
'openId' => $openId,
'sourceType' => $sourceType,
'region' => RegData::getAreasData(),
'serviceUrl' => Helpers::url('/help', array('category_id' => 9))
);
$this->_view->display('index', $data);
... ... @@ -57,6 +58,7 @@ class ThirdloginController extends WebAction
* 绑定成功
*
*/
public function bindSuccessAction()
{
... ...