Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop
Showing
12 changed files
with
102 additions
and
64 deletions
@@ -142,20 +142,35 @@ class SearchData extends \LibModels\Wap\Product\SearchData | @@ -142,20 +142,35 @@ class SearchData extends \LibModels\Wap\Product\SearchData | ||
142 | */ | 142 | */ |
143 | public static function getSearchDataBySort(array $params, array $sortList) | 143 | public static function getSearchDataBySort(array $params, array $sortList) |
144 | { | 144 | { |
145 | - $data = array(); | ||
146 | - foreach ($sortList as $v) { | ||
147 | - if(empty($v['viewNum'])){ | ||
148 | - continue; | ||
149 | - } | ||
150 | - $searchParams = array_merge($params, $v); | ||
151 | - $list = self::searchElasticByCondition($searchParams, true); | ||
152 | - $productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list']; | ||
153 | - if(count($productList) < $v['viewNum']){ | ||
154 | - continue; | ||
155 | - } | ||
156 | - $data = array_merge($data, $productList); | 145 | +// $data = array(); |
146 | +// foreach ($sortList as $v) { | ||
147 | +// if(empty($v['viewNum'])){ | ||
148 | +// continue; | ||
149 | +// } | ||
150 | +// $searchParams = array_merge($params, $v); | ||
151 | +// $list = self::searchElasticByCondition($searchParams, true); | ||
152 | +// $productList = empty($list['data']['product_list']) ? array() : $list['data']['product_list']; | ||
153 | +// if(count($productList) < $v['viewNum']){ | ||
154 | +// continue; | ||
155 | +// } | ||
156 | +// $data = array_merge($data, $productList); | ||
157 | +// } | ||
158 | +// return $data; | ||
159 | + | ||
160 | + /* 2016/01/26 code review by fei.hong: 优化合并misort参数, 减少调用搜索的次数 */ | ||
161 | + $sortIds = ''; | ||
162 | + $viewNum = 0; | ||
163 | + foreach ($sortList as $value) { | ||
164 | + $viewNum += intval($value['viewNum']); | ||
165 | + $sortIds .= $value['misort'] . ','; | ||
157 | } | 166 | } |
158 | - return $data; | 167 | + $params['viewNum'] = $viewNum; |
168 | + $params['misort'] = rtrim($sortIds, ','); | ||
169 | + $searchd = self::searchElasticByCondition($params); | ||
170 | + if (empty($searchd['data']['product_list'])) { | ||
171 | + return array(); | ||
172 | + } | ||
173 | + return $searchd['data']['product_list']; | ||
159 | } | 174 | } |
160 | 175 | ||
161 | /** | 176 | /** |
@@ -226,6 +226,7 @@ class Helpers | @@ -226,6 +226,7 @@ class Helpers | ||
226 | if ($oneGoods['is_default'] === 'Y') { | 226 | if ($oneGoods['is_default'] === 'Y') { |
227 | $productData['default_images'] = self::procProductImg($oneGoods); | 227 | $productData['default_images'] = self::procProductImg($oneGoods); |
228 | $flag = true; | 228 | $flag = true; |
229 | + break; | ||
229 | } | 230 | } |
230 | } | 231 | } |
231 | // 如果还未赋值,则取第一个skc产品的默认图片 | 232 | // 如果还未赋值,则取第一个skc产品的默认图片 |
@@ -247,7 +248,7 @@ class Helpers | @@ -247,7 +248,7 @@ class Helpers | ||
247 | $result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y'); | 248 | $result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y'); |
248 | $result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_' | 249 | $result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_' |
249 | . $productData['goods_list'][0]['goods_id'] | 250 | . $productData['goods_list'][0]['goods_id'] |
250 | - . '/' . $productData['cn_alphabet'] . '.html', 'item'); | 251 | + . '/' . $productData['cn_alphabet'] . '.html', array(), 'item'); |
251 | // APP访问需要加附加的参数 | 252 | // APP访问需要加附加的参数 |
252 | // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护 | 253 | // 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护 |
253 | if ($isApp) { | 254 | if ($isApp) { |
@@ -12,8 +12,10 @@ | @@ -12,8 +12,10 @@ | ||
12 | </li> | 12 | </li> |
13 | {{#each list}} | 13 | {{#each list}} |
14 | <li {{#if active}}class="active"{{/if}}> | 14 | <li {{#if active}}class="active"{{/if}}> |
15 | - <a href="{{href}}">{{name}}</a> | ||
16 | - <span>{{num}}</span> | 15 | + <a href="{{href}}"> |
16 | + {{name}} | ||
17 | + <span>{{num}}</span> | ||
18 | + </a> | ||
17 | </li> | 19 | </li> |
18 | {{/each}} | 20 | {{/each}} |
19 | </ul> | 21 | </ul> |
@@ -30,8 +32,10 @@ | @@ -30,8 +32,10 @@ | ||
30 | <ul class="sort-child-list new-sale"> | 32 | <ul class="sort-child-list new-sale"> |
31 | {{#each list}} | 33 | {{#each list}} |
32 | <li {{#if active}}active{{/if}}> | 34 | <li {{#if active}}active{{/if}}> |
33 | - <a href="{{href}}">{{name}}</a> | ||
34 | - <span>{{num}}</span> | 35 | + <a href="{{href}}"> |
36 | + {{name}} | ||
37 | + <span>{{num}}</span> | ||
38 | + </a> | ||
35 | </li> | 39 | </li> |
36 | {{/each}} | 40 | {{/each}} |
37 | </ul> | 41 | </ul> |
@@ -51,25 +51,22 @@ class PlusstarModel | @@ -51,25 +51,22 @@ class PlusstarModel | ||
51 | } | 51 | } |
52 | 52 | ||
53 | $result = array(); | 53 | $result = array(); |
54 | + | ||
54 | $brandList = PlusstarData::firstBrandList($gender, $channel); | 55 | $brandList = PlusstarData::firstBrandList($gender, $channel); |
55 | - if (!empty($brandList['recom']['data']['list'][0]['data'])) { | ||
56 | - $result['ps']['star'] = self::formatData($brandList['recom']['data']['list'][0]['data'], $gender, true); | ||
57 | - //$result['ps']['sName'] = isset($brandList['recom']['data']['brand_type_name']) ? $brandList['recom']['data']['brand_type_name'] : ''; | ||
58 | - } | ||
59 | - if (!empty($brandList['all']['data']['list'][0]['data'])) { | ||
60 | - $result['ps']['plus'] = self::formatData($brandList['all']['data']['list'][0]['data'], $gender, true); | ||
61 | - //$result['ps']['pName'] = isset($brandList['all']['data']['brand_type_name']) ? $brandList['all']['data']['brand_type_name'] : ''; | 56 | + // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. |
57 | + if (empty($brandList['recom']['data']['list'][0]['data']) || empty($brandList['all']['data']['list'][0]['data'])) { | ||
58 | + if (USE_CACHE) { | ||
59 | + $result = Cache::get($key, 'slave'); | ||
60 | + } | ||
61 | + return $result; | ||
62 | } | 62 | } |
63 | + | ||
64 | + $result['ps']['star'] = self::formatData($brandList['recom']['data']['list'][0]['data'], $gender, true); | ||
65 | + $result['ps']['plus'] = self::formatData($brandList['all']['data']['list'][0]['data'], $gender, true); | ||
63 | 66 | ||
67 | + // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 | ||
64 | if (USE_CACHE) { | 68 | if (USE_CACHE) { |
65 | - // 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据. | ||
66 | - if (empty($result)) { | ||
67 | - $result = Cache::get($key, 'slave'); | ||
68 | - } | ||
69 | - // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存 | ||
70 | - else { | ||
71 | - Cache::set($key, $result); | ||
72 | - } | 69 | + Cache::set($key, $result); |
73 | } | 70 | } |
74 | 71 | ||
75 | return $result; | 72 | return $result; |
@@ -49,8 +49,8 @@ class CommonController extends WebAction | @@ -49,8 +49,8 @@ class CommonController extends WebAction | ||
49 | HomeModel::COOKIE_NAME_LIFESTYLE | 49 | HomeModel::COOKIE_NAME_LIFESTYLE |
50 | ); | 50 | ); |
51 | $channel = $this->post('type', ''); | 51 | $channel = $this->post('type', ''); |
52 | - $pageIndex = intval($this->post('pageIndex', 0)); | ||
53 | - $pageCount = intval($this->post('pageCount', 8)); | 52 | + $pageIndex = (int) $this->post('pageIndex', 0); |
53 | + $pageCount = (int) $this->post('pageCount', 8); | ||
54 | if (! in_array($channel, $channels)) { | 54 | if (! in_array($channel, $channels)) { |
55 | break; | 55 | break; |
56 | } else { | 56 | } else { |
@@ -247,14 +247,13 @@ class HomeModel | @@ -247,14 +247,13 @@ class HomeModel | ||
247 | */ | 247 | */ |
248 | public static function getNewArrival($channel) | 248 | public static function getNewArrival($channel) |
249 | { | 249 | { |
250 | - $result = array(); | ||
251 | - $key = sprintf(WebCacheConfig::KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA.'_'.$channel); | 250 | + $key = WebCacheConfig::KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA . '_' . $channel; |
252 | //缓存数据 | 251 | //缓存数据 |
253 | $result = Cache::get($key); | 252 | $result = Cache::get($key); |
254 | - if(empty($result)) { | 253 | + if (empty($result)) { |
255 | $params = array( | 254 | $params = array( |
256 | - 'order' => 's_t_desc', | ||
257 | - 'shelve_time' => strtotime("-60 days") . ',' . time() | 255 | + 'order' => 's_t_desc', |
256 | + 'shelve_time' => strtotime("-60 days") . ',' . time() | ||
258 | ); | 257 | ); |
259 | //男首频道最新上架参数是gender=1,3 | 258 | //男首频道最新上架参数是gender=1,3 |
260 | if($channel == self::COOKIE_NAME_BOYS) { | 259 | if($channel == self::COOKIE_NAME_BOYS) { |
@@ -270,9 +269,13 @@ class HomeModel | @@ -270,9 +269,13 @@ class HomeModel | ||
270 | // 获取分类列表获取商品信息 | 269 | // 获取分类列表获取商品信息 |
271 | $goodsList = SearchData::getSearchDataBySort($params, $sortList); | 270 | $goodsList = SearchData::getSearchDataBySort($params, $sortList); |
272 | $pos = 1; | 271 | $pos = 1; |
272 | + $val = array(); | ||
273 | foreach ($goodsList as $goods) { | 273 | foreach ($goodsList as $goods) { |
274 | // 格式化数据 | 274 | // 格式化数据 |
275 | $val = Helpers::formatProduct($goods, true, true, true, 280, 373); | 275 | $val = Helpers::formatProduct($goods, true, true, true, 280, 373); |
276 | + if (!$val) { | ||
277 | + continue; | ||
278 | + } | ||
276 | if ($val['price'] == false) { | 279 | if ($val['price'] == false) { |
277 | $val['price'] = $val['salePrice']; | 280 | $val['price'] = $val['salePrice']; |
278 | } | 281 | } |
@@ -287,13 +290,16 @@ class HomeModel | @@ -287,13 +290,16 @@ class HomeModel | ||
287 | $val['tags']['isReNew'] = false;//$val['tags']['is_advance'];暂时不显示 | 290 | $val['tags']['isReNew'] = false;//$val['tags']['is_advance'];暂时不显示 |
288 | unset($val['tags']['is_advance'], $val['tags']['is_discount'], $val['tags']['is_limited'], $val['tags']['is_new'], | 291 | unset($val['tags']['is_advance'], $val['tags']['is_discount'], $val['tags']['is_limited'], $val['tags']['is_new'], |
289 | $val['tags']['is_yohood'], $val['tags']['midYear'], $val['tags']['yearEnd']); | 292 | $val['tags']['is_yohood'], $val['tags']['midYear'], $val['tags']['yearEnd']); |
290 | - if (! empty($val)) { | ||
291 | - $result[] = $val; | ||
292 | - } | 293 | + $result[] = $val; |
293 | } | 294 | } |
294 | } | 295 | } |
295 | Cache::set($key, $result, 3600); | 296 | Cache::set($key, $result, 3600); |
296 | } | 297 | } |
298 | + // 当一级缓存失效,并且接口异常时, 尝试从二级缓存获取数据 | ||
299 | + if (empty($result)) { | ||
300 | + $result = Cache::get($key, 'slave'); | ||
301 | + } | ||
302 | + | ||
297 | return $result; | 303 | return $result; |
298 | } | 304 | } |
299 | } | 305 | } |
@@ -7,6 +7,7 @@ use LibModels\Web\Home\IndexData; | @@ -7,6 +7,7 @@ use LibModels\Web\Home\IndexData; | ||
7 | use LibModels\Web\Home\UserData; | 7 | use LibModels\Web\Home\UserData; |
8 | use WebPlugin\Images; | 8 | use WebPlugin\Images; |
9 | use WebPlugin\Captcha; | 9 | use WebPlugin\Captcha; |
10 | +use WebPlugin\Cache; | ||
10 | 11 | ||
11 | /** | 12 | /** |
12 | * web登录注册等相关数据构建 | 13 | * web登录注册等相关数据构建 |
@@ -134,4 +135,22 @@ class PassportModel | @@ -134,4 +135,22 @@ class PassportModel | ||
134 | return $ret; | 135 | return $ret; |
135 | } | 136 | } |
136 | 137 | ||
138 | + /* | ||
139 | + * 重写递增计数 cache方法 | ||
140 | + * $key cache-key | ||
141 | + * $offset 递增偏移量 | ||
142 | + * $initValue 初始化值 | ||
143 | + * $expiry 缓存时间 | ||
144 | + */ | ||
145 | + public static function increment($key, $offset = 1, $initValue = 0, $expire = 1800) | ||
146 | + { | ||
147 | + //初始化key | ||
148 | + if (!Cache::get($key)) { | ||
149 | + Cache::set($key, $initValue, $expire); | ||
150 | + } | ||
151 | + //增加偏移量 | ||
152 | + $cacheValue = intval(Cache::get($key))+$offset; | ||
153 | + Cache::set($key, $cacheValue, $expire); | ||
154 | + } | ||
155 | + | ||
137 | } | 156 | } |
@@ -135,12 +135,14 @@ class BrandsModel | @@ -135,12 +135,14 @@ class BrandsModel | ||
135 | 135 | ||
136 | //获取$condition和$option 筛选条件和排序条件 | 136 | //获取$condition和$option 筛选条件和排序条件 |
137 | $searchCondition = SearchModel::searchCondition($customCondition, $customOptions); | 137 | $searchCondition = SearchModel::searchCondition($customCondition, $customOptions); |
138 | - | ||
139 | // 组合搜索商品url | 138 | // 组合搜索商品url |
140 | $urlList['product'] = SearchData::getProductUrl($searchCondition['condition']); | 139 | $urlList['product'] = SearchData::getProductUrl($searchCondition['condition']); |
141 | 140 | ||
142 | // 组合搜索分类url | 141 | // 组合搜索分类url |
143 | - $urlList['sort'] = SearchData::getClassesUrl($searchCondition['sortCondition']); | 142 | + $brandSort = array( |
143 | + 'brand' => $searchCondition['sortCondition']['brand'] | ||
144 | + ); | ||
145 | + $urlList['sort'] = SearchData::getClassesUrl($brandSort); | ||
144 | 146 | ||
145 | //组合搜索品牌url | 147 | //组合搜索品牌url |
146 | $urlList['brand'] = SearchData::getBrandUrl($customOptions); | 148 | $urlList['brand'] = SearchData::getBrandUrl($customOptions); |
@@ -109,27 +109,22 @@ class LoginController extends WebAction | @@ -109,27 +109,22 @@ class LoginController extends WebAction | ||
109 | $ip = Helpers::getClientIp(); | 109 | $ip = Helpers::getClientIp(); |
110 | $ipKey = md5('ip_signin_' . $ip); | 110 | $ipKey = md5('ip_signin_' . $ip); |
111 | $accountKey = md5('account_signin_' . $account); | 111 | $accountKey = md5('account_signin_' . $account); |
112 | - if (!Cache::get($ipKey)) { | ||
113 | - Cache::set($ipKey, 0); | ||
114 | - } | ||
115 | - if (!Cache::get($accountKey)) { | ||
116 | - Cache::set($accountKey, 0); | ||
117 | - } | ||
118 | - Cache::increment($ipKey, 1, 0, 3600); | 112 | + PassportModel::increment($ipKey, 1, 0, 3600); |
119 | $accountTimes = Cache::get($accountKey); | 113 | $accountTimes = Cache::get($accountKey); |
120 | - $ipTimes = Cache::get($ipKey); | ||
121 | if ($accountTimes > 10) { | 114 | if ($accountTimes > 10) { |
122 | $data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => ''); | 115 | $data = array('code' => 400, 'message' => '您的账号已被暂时锁定,请稍后再试', 'data' => ''); |
123 | break; | 116 | break; |
124 | } | 117 | } |
118 | + | ||
119 | + $ipTimes = Cache::get($ipKey); | ||
125 | if ($ipTimes > 100) { | 120 | if ($ipTimes > 100) { |
126 | $data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => ''); | 121 | $data = array('code' => 400, 'message' => '您尝试的次数过多,账号已被暂时锁定,请稍后再试', 'data' => ''); |
127 | break; | 122 | break; |
128 | } | 123 | } |
129 | $data = LoginData::signin($area, $account, $password, $shoppingKey); | 124 | $data = LoginData::signin($area, $account, $password, $shoppingKey); |
130 | if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) { | 125 | if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['uid'])) { |
131 | - Cache::increment($accountKey, 1, 0, 1800); | ||
132 | - $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => ''); | 126 | + PassportModel::increment($accountKey, 1, 0, 1800); |
127 | + $data = array('code' => 400, 'message' => '您输入的密码及账户名不匹配,是否<a href="'.Helpers::url('/passport/back/index').'" target="_blank">忘记密码?</a>', 'data' => ''); | ||
133 | break; | 128 | break; |
134 | } | 129 | } |
135 | 130 |
@@ -48,10 +48,8 @@ class RegisterController extends WebAction | @@ -48,10 +48,8 @@ class RegisterController extends WebAction | ||
48 | $ip = Helpers::getClientIp(); | 48 | $ip = Helpers::getClientIp(); |
49 | $data = array('code' => 400, 'message' => '', 'data' => ''); | 49 | $data = array('code' => 400, 'message' => '', 'data' => ''); |
50 | $ipKey = md5('ip_checkmobile_' . $ip); | 50 | $ipKey = md5('ip_checkmobile_' . $ip); |
51 | - if (!Cache::get($ipKey)) { | ||
52 | - Cache::set($ipKey, 0); | ||
53 | - } | ||
54 | - $ipTimes = Cache::increment($ipKey, 1, 0, 3600); | 51 | + PassportModel::increment($ipKey, 1, 0, 3600); |
52 | + $ipTimes = Cache::get($ipKey); | ||
55 | do{ | 53 | do{ |
56 | /* 判断是不是AJAX请求 */ | 54 | /* 判断是不是AJAX请求 */ |
57 | if (!$this->isAjax()) { | 55 | if (!$this->isAjax()) { |
@@ -132,10 +130,8 @@ class RegisterController extends WebAction | @@ -132,10 +130,8 @@ class RegisterController extends WebAction | ||
132 | } | 130 | } |
133 | //发送代码 | 131 | //发送代码 |
134 | $sendCodeKey = md5('send_code_' . $area . '_' . $mobile); | 132 | $sendCodeKey = md5('send_code_' . $area . '_' . $mobile); |
135 | - if (!Cache::get($sendCodeKey)) { | ||
136 | - Cache::set($sendCodeKey, 0); | ||
137 | - } | ||
138 | - $sendCodeTimes = Cache::increment($sendCodeKey, 1, 0, 3600); | 133 | + PassportModel::increment($sendCodeKey, 1, 0, 3600); |
134 | + $sendCodeTimes = Cache::get($sendCodeKey); | ||
139 | if ($sendCodeTimes > 50) { | 135 | if ($sendCodeTimes > 50) { |
140 | $data['message'] = '发送验证码太多'; | 136 | $data['message'] = '发送验证码太多'; |
141 | break; | 137 | break; |
@@ -25,6 +25,7 @@ class ThirdloginController extends WebAction | @@ -25,6 +25,7 @@ class ThirdloginController extends WebAction | ||
25 | 'openId' => $openId, | 25 | 'openId' => $openId, |
26 | 'sourceType' => $sourceType, | 26 | 'sourceType' => $sourceType, |
27 | 'region' => RegData::getAreasData(), | 27 | 'region' => RegData::getAreasData(), |
28 | + 'serviceUrl' => Helpers::url('/help', array('category_id' => 9)) | ||
28 | ); | 29 | ); |
29 | 30 | ||
30 | $this->_view->display('index', $data); | 31 | $this->_view->display('index', $data); |
@@ -57,6 +58,7 @@ class ThirdloginController extends WebAction | @@ -57,6 +58,7 @@ class ThirdloginController extends WebAction | ||
57 | * 绑定成功 | 58 | * 绑定成功 |
58 | * | 59 | * |
59 | */ | 60 | */ |
61 | + | ||
60 | public function bindSuccessAction() | 62 | public function bindSuccessAction() |
61 | { | 63 | { |
62 | 64 |
-
Please register or login to post a comment