Authored by yangyang

Merge branch 'feature/web-list' of http://git.dev.yoho.cn/web/yohobuy into feature/web-list

... ... @@ -9,7 +9,9 @@ var $ = require('yoho.jquery');
var handlebars = require('yoho.handlebars');
var json2 = require('json2');
var noticeSuccess = false;
var apiDomain = 'http://api.open.yohobuy.com';
var vipInfoCombine = null;
var loginInfoCombine = null;
/**
* 判断为1的helper
* @param {[type]} v1 [description]
... ... @@ -24,6 +26,37 @@ handlebars.registerHelper('equalone', function(v1, options) {
return options.inverse(this);
}
});
/**
* 判断等级为3的helper
* @param {[type]} v1 [description]
* @param {[type]} options) { if (v1 [description]
* @return {[type]} [description]
*/
handlebars.registerHelper('equallevelthree', function(v1, options) {
if (v1 === '3') {
return options.fn(this);
} else {
return options.inverse(this);
}
});
/**
* 判断为0的helper
* @param {[type]} v1 [description]
* @param {[type]} options) { if (v1 [description]
* @return {[type]} [description]
*/
handlebars.registerHelper('equalzero', function(v1, options) {
if (v1 === '0') {
return options.fn(this);
} else {
return options.inverse(this);
}
});
require('../plugin/yohocookie');
require('../plugin/yohocart');
/**
... ... @@ -817,6 +850,7 @@ function actionExeTemplate() {
var resulthtml = $('#goodcartempwarpper').html().replace(/\\/g, '');
$('#goodcartempwarpper').html(resulthtml);
vipInfoCombine = handlebars.compile($('#tmpl-my-login-new').html())
}
/**
* 执行搜索
... ... @@ -828,6 +862,138 @@ function actionSearch() {
$('#query_key').search(searchDomain);
}
/**
* 获取登录状态
* @return {[type]} [description]
*/
function actionLoginState(_data) {
var timestamp = new Date().getTime();
var noLoginHtml = '<span>Hi~</span>[<a href="http://www.yohobuy.com/signin.html" class="list-a login-out ">请登录</a>]&nbsp;[<a href="http://www.yohobuy.com/reg.html" class="list-a login-out" onclick="">免费注册</a>]'
var loginHtml = '<span>Hi~<a href="http://www.yohobuy.com/home?t=' + timestamp + '">{{user_name}}</a></span>&nbsp;'+
'{{#equalone is_login}}'+
'[<a href="{{logout}}" class="list-a login-out">退出</a>]'+
'{{else}}'+
'[<a href="http://www.yohobuy.com/signin.html" class="list-a login-out">请登录</a>]&nbsp;'+
'[<a href="http://www.yohobuy.com/reg.html" onclick="" class="list-a login-out">免费注册</a>]'+
'{{/equalone}}';
var boxObj = $('#loginBox');
var info = $.cookie('_UID');
loginInfoCombine = handlebars.compile(loginHtml);
if (typeof info == 'undefined' || info == null) {
boxObj.html(noLoginHtml);
return false;
}
var user = info.split('::');
if (typeof user == 'undefined' || user.length < 4) {
boxObj.html(noLoginHtml);
return false;
}
var userName = user[0] || ' ';
var name = '';
var _length = 0;
for (var t = 0; t < userName.length; t++) {
var char = userName.substr(t, 1);
if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
_length += 2;
} else {
_length += 1;
}
}
if (_length <= 10) {
name = userName;
} else {
_num = 0;
for (var t = 0; t < userName.length; t++) {
if (_num < 10) {
var char = userName.substr(t, 1);
if (char != '*') {
if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
_num += 2;
} else {
_num += 1;
}
}
name += char;
}
}
if (name.length < userName.length) {
name += '...';
}
}
var _logout = '';
if (/http:\/\//.test(user[3])) {
_logout = user[3].replace('www.yohobuy.com', 'www.yohobuy.com');
} else {
_logout = 'http://www.yohobuy.com/logout_' + user[3] + '.html';
}
var data = {
"user_name": name,
"logout": _logout,
"random": Math.random()
};
var is_login = '1';
if (_data.result === -1) {
is_login = '-1';
}
data['is_login'] = is_login;
boxObj.html(loginInfoCombine(data));
}
/**
* 获得vip用户信息
* @return {[type]} [description]
*/
function actionVipInfo(_data) {
if (_data.result == 1) {
var vipInfo = _data.data;
if (typeof vipInfo == undefined || vipInfo.length < 1) {
return false;
}
$('#myYohoBox').mouseenter(function() {
$(this).addClass('acttags');
$('#myYohoBox .myyoho-info').show().html(vipInfoCombine(vipInfo));
var headUrl = $('.myyoho-photo img').attr('data-url');
if ($._checkUrlState == 1) {
$('.myyoho-photo').show().find('img').attr('src', headUrl);
return;
}
if (headUrl == '' || $._checkUrl != '') {
return;
}
$.ajax({
url: headUrl,
type: 'GET',
complete: function(response) {
if (response.status == 200 || response.status == 0) {
$('.myyoho-photo').show().find('img').attr('src', headUrl);
$._checkUrlState = 1;
}
$._checkUrl = headUrl;
}
});
;
});
$('#myYohoBox').mouseleave(function() {
$(this).removeClass('acttags');
$('#myYohoBox .myyoho-info').hide()
});
} else {}
}
/**
* 获取登录信息
* @return {[type]} [description]
*/
function actionLoginInfo() {
var param = {
method: 'open.passport.get'
};
$.getData(apiDomain, param, function(_data) {
actionLoginState(_data); // 更改登录状态
actionVipInfo(_data);//获得vip;
});
}
/**
* 初始化函数
* @return {[type]} [description]
*/
... ... @@ -849,6 +1015,7 @@ function init() {
actionClickMiniCartBox(); //点击购物车跳转
actionListenDelCarGoods(); //监听购物车删除
actionListenCartMore(); //
actionLoginInfo();//获取登录信息
}
init();
\ No newline at end of file
... ...
... ... @@ -19,7 +19,7 @@ class SearchModel
/**
* 根据条件获取搜索数据
*
* @param $condition 搜索数据的条件
* @param $condition 搜索数据的条件
* @param $options Array([imgSize]
* => Array([0] => 235[1] => 314)[minImgSize] => Array([0] => 60[1] => 80)[gender] => 1[needPd] => Y[rowNum] => 5[viewNum] => 60)
* @author sefon 2015-12-17 16:12:18
... ... @@ -28,7 +28,6 @@ class SearchModel
public static function getSearchData($condition, $options)
{
$data = array();
// 调用接口查询商品数据
$result = SearchData::searchElasticByCondition($condition);
if (isset($result['code']) && $result['code'] === 200) {
... ...
... ... @@ -5,13 +5,13 @@ class ListController extends WebAction
{
public function indexAction()
{
}
public function newAction(){
}
/**
* list列表sale
*/
... ... @@ -48,11 +48,11 @@ class ListController extends WebAction
$condition['gender'] = $gender;
//每页显示商品数
if(!isset($condition['viewNum']) || empty($condition['viewNum'])){
$condition['viewNum'] =60;
$condition['viewNum'] =59;
}
$view_num_arr = array(60, 100, 200);
if (!in_array($condition['viewNum'], $view_num_arr)) {
$condition['viewNum'] = 60;
$condition['viewNum'] = 59;
}
//每行显示的商品数量
if(!isset($condition['rowNum']) || empty($condition['rowNum'])){
... ... @@ -70,14 +70,25 @@ class ListController extends WebAction
//$query = $this->get('query');
//返回搜索条件
$condition['needFilter'] = 1;
//过滤赠品
$condition['attribute_not'] = 2;
/*sale*/
//默认排序
if (!isset($condition['order']) || empty($condition['order'])) {
$condition['order'] = 's_n_desc';
}
if (!isset($condition['p_d']) || empty($condition['p_d'])) {
$condition['p_d'] = '0,0.9';
}
$options = array(
'imgSize' => $imgSize,
'minImgSize' => $minImgSize,
'gender' => $gender,
'needPd' => 'Y',
'rowNum' =>$condition['rowNum'],
'viewNum' =>$condition['viewNum'],
'viewNum' =>$condition['viewNum']-1,
);
$params = $condition + $_GET;
$params = array_filter($params);
$data = SearchModel::getSearchData($params,$options);
... ...