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'); @@ -9,7 +9,9 @@ var $ = require('yoho.jquery');
9 var handlebars = require('yoho.handlebars'); 9 var handlebars = require('yoho.handlebars');
10 var json2 = require('json2'); 10 var json2 = require('json2');
11 var noticeSuccess = false; 11 var noticeSuccess = false;
12 - 12 +var apiDomain = 'http://api.open.yohobuy.com';
  13 +var vipInfoCombine = null;
  14 +var loginInfoCombine = null;
13 /** 15 /**
14 * 判断为1的helper 16 * 判断为1的helper
15 * @param {[type]} v1 [description] 17 * @param {[type]} v1 [description]
@@ -24,6 +26,37 @@ handlebars.registerHelper('equalone', function(v1, options) { @@ -24,6 +26,37 @@ handlebars.registerHelper('equalone', function(v1, options) {
24 return options.inverse(this); 26 return options.inverse(this);
25 } 27 }
26 }); 28 });
  29 +/**
  30 + * 判断等级为3的helper
  31 + * @param {[type]} v1 [description]
  32 + * @param {[type]} options) { if (v1 [description]
  33 + * @return {[type]} [description]
  34 + */
  35 +
  36 +handlebars.registerHelper('equallevelthree', function(v1, options) {
  37 +
  38 + if (v1 === '3') {
  39 + return options.fn(this);
  40 + } else {
  41 + return options.inverse(this);
  42 + }
  43 +});
  44 +
  45 +/**
  46 + * 判断为0的helper
  47 + * @param {[type]} v1 [description]
  48 + * @param {[type]} options) { if (v1 [description]
  49 + * @return {[type]} [description]
  50 + */
  51 +
  52 +handlebars.registerHelper('equalzero', function(v1, options) {
  53 +
  54 + if (v1 === '0') {
  55 + return options.fn(this);
  56 + } else {
  57 + return options.inverse(this);
  58 + }
  59 +});
27 require('../plugin/yohocookie'); 60 require('../plugin/yohocookie');
28 require('../plugin/yohocart'); 61 require('../plugin/yohocart');
29 /** 62 /**
@@ -817,6 +850,7 @@ function actionExeTemplate() { @@ -817,6 +850,7 @@ function actionExeTemplate() {
817 var resulthtml = $('#goodcartempwarpper').html().replace(/\\/g, ''); 850 var resulthtml = $('#goodcartempwarpper').html().replace(/\\/g, '');
818 851
819 $('#goodcartempwarpper').html(resulthtml); 852 $('#goodcartempwarpper').html(resulthtml);
  853 + vipInfoCombine = handlebars.compile($('#tmpl-my-login-new').html())
820 } 854 }
821 /** 855 /**
822 * 执行搜索 856 * 执行搜索
@@ -828,6 +862,138 @@ function actionSearch() { @@ -828,6 +862,138 @@ function actionSearch() {
828 $('#query_key').search(searchDomain); 862 $('#query_key').search(searchDomain);
829 } 863 }
830 /** 864 /**
  865 + * 获取登录状态
  866 + * @return {[type]} [description]
  867 + */
  868 +function actionLoginState(_data) {
  869 + var timestamp = new Date().getTime();
  870 + 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>]'
  871 + var loginHtml = '<span>Hi~<a href="http://www.yohobuy.com/home?t=' + timestamp + '">{{user_name}}</a></span>&nbsp;'+
  872 + '{{#equalone is_login}}'+
  873 + '[<a href="{{logout}}" class="list-a login-out">退出</a>]'+
  874 + '{{else}}'+
  875 + '[<a href="http://www.yohobuy.com/signin.html" class="list-a login-out">请登录</a>]&nbsp;'+
  876 + '[<a href="http://www.yohobuy.com/reg.html" onclick="" class="list-a login-out">免费注册</a>]'+
  877 + '{{/equalone}}';
  878 + var boxObj = $('#loginBox');
  879 + var info = $.cookie('_UID');
  880 + loginInfoCombine = handlebars.compile(loginHtml);
  881 +
  882 + if (typeof info == 'undefined' || info == null) {
  883 + boxObj.html(noLoginHtml);
  884 + return false;
  885 + }
  886 + var user = info.split('::');
  887 + if (typeof user == 'undefined' || user.length < 4) {
  888 + boxObj.html(noLoginHtml);
  889 + return false;
  890 + }
  891 + var userName = user[0] || ' ';
  892 + var name = '';
  893 + var _length = 0;
  894 + for (var t = 0; t < userName.length; t++) {
  895 + var char = userName.substr(t, 1);
  896 + if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
  897 + _length += 2;
  898 + } else {
  899 + _length += 1;
  900 + }
  901 + }
  902 + if (_length <= 10) {
  903 + name = userName;
  904 + } else {
  905 + _num = 0;
  906 + for (var t = 0; t < userName.length; t++) {
  907 + if (_num < 10) {
  908 + var char = userName.substr(t, 1);
  909 + if (char != '*') {
  910 + if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
  911 + _num += 2;
  912 + } else {
  913 + _num += 1;
  914 + }
  915 + }
  916 + name += char;
  917 + }
  918 + }
  919 + if (name.length < userName.length) {
  920 + name += '...';
  921 + }
  922 + }
  923 + var _logout = '';
  924 + if (/http:\/\//.test(user[3])) {
  925 + _logout = user[3].replace('www.yohobuy.com', 'www.yohobuy.com');
  926 + } else {
  927 + _logout = 'http://www.yohobuy.com/logout_' + user[3] + '.html';
  928 + }
  929 + var data = {
  930 + "user_name": name,
  931 + "logout": _logout,
  932 + "random": Math.random()
  933 + };
  934 + var is_login = '1';
  935 + if (_data.result === -1) {
  936 + is_login = '-1';
  937 + }
  938 + data['is_login'] = is_login;
  939 + boxObj.html(loginInfoCombine(data));
  940 +}
  941 +/**
  942 + * 获得vip用户信息
  943 + * @return {[type]} [description]
  944 + */
  945 +function actionVipInfo(_data) {
  946 + if (_data.result == 1) {
  947 + var vipInfo = _data.data;
  948 +
  949 + if (typeof vipInfo == undefined || vipInfo.length < 1) {
  950 + return false;
  951 + }
  952 + $('#myYohoBox').mouseenter(function() {
  953 + $(this).addClass('acttags');
  954 + $('#myYohoBox .myyoho-info').show().html(vipInfoCombine(vipInfo));
  955 + var headUrl = $('.myyoho-photo img').attr('data-url');
  956 + if ($._checkUrlState == 1) {
  957 + $('.myyoho-photo').show().find('img').attr('src', headUrl);
  958 + return;
  959 + }
  960 + if (headUrl == '' || $._checkUrl != '') {
  961 + return;
  962 + }
  963 + $.ajax({
  964 + url: headUrl,
  965 + type: 'GET',
  966 + complete: function(response) {
  967 + if (response.status == 200 || response.status == 0) {
  968 + $('.myyoho-photo').show().find('img').attr('src', headUrl);
  969 + $._checkUrlState = 1;
  970 + }
  971 + $._checkUrl = headUrl;
  972 + }
  973 + });
  974 +
  975 + ;
  976 + });
  977 + $('#myYohoBox').mouseleave(function() {
  978 + $(this).removeClass('acttags');
  979 + $('#myYohoBox .myyoho-info').hide()
  980 + });
  981 + } else {}
  982 +}
  983 +/**
  984 + * 获取登录信息
  985 + * @return {[type]} [description]
  986 + */
  987 +function actionLoginInfo() {
  988 + var param = {
  989 + method: 'open.passport.get'
  990 + };
  991 + $.getData(apiDomain, param, function(_data) {
  992 + actionLoginState(_data); // 更改登录状态
  993 + actionVipInfo(_data);//获得vip;
  994 + });
  995 +}
  996 +/**
831 * 初始化函数 997 * 初始化函数
832 * @return {[type]} [description] 998 * @return {[type]} [description]
833 */ 999 */
@@ -849,6 +1015,7 @@ function init() { @@ -849,6 +1015,7 @@ function init() {
849 actionClickMiniCartBox(); //点击购物车跳转 1015 actionClickMiniCartBox(); //点击购物车跳转
850 actionListenDelCarGoods(); //监听购物车删除 1016 actionListenDelCarGoods(); //监听购物车删除
851 actionListenCartMore(); // 1017 actionListenCartMore(); //
  1018 + actionLoginInfo();//获取登录信息
852 } 1019 }
853 1020
854 init(); 1021 init();
@@ -19,7 +19,7 @@ class SearchModel @@ -19,7 +19,7 @@ class SearchModel
19 /** 19 /**
20 * 根据条件获取搜索数据 20 * 根据条件获取搜索数据
21 * 21 *
22 - * @param $condition 搜索数据的条件 22 + * @param $condition 搜索数据的条件
23 * @param $options Array([imgSize] 23 * @param $options Array([imgSize]
24 * => Array([0] => 235[1] => 314)[minImgSize] => Array([0] => 60[1] => 80)[gender] => 1[needPd] => Y[rowNum] => 5[viewNum] => 60) 24 * => Array([0] => 235[1] => 314)[minImgSize] => Array([0] => 60[1] => 80)[gender] => 1[needPd] => Y[rowNum] => 5[viewNum] => 60)
25 * @author sefon 2015-12-17 16:12:18 25 * @author sefon 2015-12-17 16:12:18
@@ -28,7 +28,6 @@ class SearchModel @@ -28,7 +28,6 @@ class SearchModel
28 public static function getSearchData($condition, $options) 28 public static function getSearchData($condition, $options)
29 { 29 {
30 $data = array(); 30 $data = array();
31 -  
32 // 调用接口查询商品数据 31 // 调用接口查询商品数据
33 $result = SearchData::searchElasticByCondition($condition); 32 $result = SearchData::searchElasticByCondition($condition);
34 if (isset($result['code']) && $result['code'] === 200) { 33 if (isset($result['code']) && $result['code'] === 200) {
@@ -5,13 +5,13 @@ class ListController extends WebAction @@ -5,13 +5,13 @@ class ListController extends WebAction
5 { 5 {
6 public function indexAction() 6 public function indexAction()
7 { 7 {
8 - 8 +
9 } 9 }
10 10
11 public function newAction(){ 11 public function newAction(){
12 12
13 } 13 }
14 - 14 +
15 /** 15 /**
16 * list列表sale 16 * list列表sale
17 */ 17 */
@@ -48,11 +48,11 @@ class ListController extends WebAction @@ -48,11 +48,11 @@ class ListController extends WebAction
48 $condition['gender'] = $gender; 48 $condition['gender'] = $gender;
49 //每页显示商品数 49 //每页显示商品数
50 if(!isset($condition['viewNum']) || empty($condition['viewNum'])){ 50 if(!isset($condition['viewNum']) || empty($condition['viewNum'])){
51 - $condition['viewNum'] =60; 51 + $condition['viewNum'] =59;
52 } 52 }
53 $view_num_arr = array(60, 100, 200); 53 $view_num_arr = array(60, 100, 200);
54 if (!in_array($condition['viewNum'], $view_num_arr)) { 54 if (!in_array($condition['viewNum'], $view_num_arr)) {
55 - $condition['viewNum'] = 60; 55 + $condition['viewNum'] = 59;
56 } 56 }
57 //每行显示的商品数量 57 //每行显示的商品数量
58 if(!isset($condition['rowNum']) || empty($condition['rowNum'])){ 58 if(!isset($condition['rowNum']) || empty($condition['rowNum'])){
@@ -70,14 +70,25 @@ class ListController extends WebAction @@ -70,14 +70,25 @@ class ListController extends WebAction
70 //$query = $this->get('query'); 70 //$query = $this->get('query');
71 //返回搜索条件 71 //返回搜索条件
72 $condition['needFilter'] = 1; 72 $condition['needFilter'] = 1;
  73 + //过滤赠品
  74 + $condition['attribute_not'] = 2;
  75 + /*sale*/
  76 + //默认排序
  77 + if (!isset($condition['order']) || empty($condition['order'])) {
  78 + $condition['order'] = 's_n_desc';
  79 + }
  80 + if (!isset($condition['p_d']) || empty($condition['p_d'])) {
  81 + $condition['p_d'] = '0,0.9';
  82 + }
73 $options = array( 83 $options = array(
74 'imgSize' => $imgSize, 84 'imgSize' => $imgSize,
75 'minImgSize' => $minImgSize, 85 'minImgSize' => $minImgSize,
76 'gender' => $gender, 86 'gender' => $gender,
77 'needPd' => 'Y', 87 'needPd' => 'Y',
78 'rowNum' =>$condition['rowNum'], 88 'rowNum' =>$condition['rowNum'],
79 - 'viewNum' =>$condition['viewNum'], 89 + 'viewNum' =>$condition['viewNum']-1,
80 ); 90 );
  91 +
81 $params = $condition + $_GET; 92 $params = $condition + $_GET;
82 $params = array_filter($params); 93 $params = array_filter($params);
83 $data = SearchModel::getSearchData($params,$options); 94 $data = SearchModel::getSearchData($params,$options);