Authored by whb

添加缓存

@@ -63,59 +63,64 @@ class HomeModel @@ -63,59 +63,64 @@ class HomeModel
63 return array(); 63 return array();
64 } 64 }
65 $menu = array(); 65 $menu = array();
66 - $item = array();  
67 - foreach ($data['data'] as $val) {  
68 - $item = array(  
69 - 'name_cn' => $val['sort_name'], // 父级  
70 - 'name_en' => $val['sort_name_en'],  
71 - 'link' => $val['sort_url'],  
72 - 'icon' => $val['sort_ico'],  
73 - 'classname' => str_replace(' ', '', strtolower($val['sort_name_en'])) == $channel ? $channel : '',  
74 - 'index_main' => 0,  
75 - 'is_hot' => $val['is_hot'] == 'Y' ? true : false,  
76 - 'is_new' => $val['is_new'] == 'Y' ? true : false,  
77 - // 'subnav' => array()  
78 - );  
79 - foreach ($val['sub'] as $sub) { // 二级  
80 - $index_sub = 0;  
81 - $subnav = array(  
82 - 'name' => $sub['sort_name'],  
83 - 'name_en' => $sub['sort_name_en'],  
84 - 'link' => $sub['sort_url'],  
85 - 'is_hot' => $sub['is_hot'] == 'Y' ? true : false,  
86 - 'is_new' => $sub['is_new'] == 'Y' ? true : false,  
87 - // 'thirdnav' => array(),  
88 - 'index_sub' => $index_sub ++  
89 - );  
90 - if (isset($sub['sub'])) {  
91 - foreach ($sub['sub'] as $thirdsub) { // 三级  
92 - $thirdnav = array(  
93 - 'title' => $thirdsub['sort_name'],  
94 - 'name_en' => $thirdsub['sort_name_en'],  
95 - 'link' => $thirdsub['sort_url'],  
96 - // 'branditems' => array()  
97 - );  
98 - if (isset($thirdsub['sub'])) {  
99 - foreach ($thirdsub['sub'] as $fourthnav) { // 四级  
100 - $thirdnav['branditems'][] = array(  
101 - 'brandname' => $fourthnav['sort_name'],  
102 - 'link' => $fourthnav['sort_url'],  
103 - 'hot' => $fourthnav['is_hot'] == 'Y' ? 'hot' : ''  
104 - );  
105 - }  
106 - }  
107 - $subnav['thirdnav'][] = $thirdnav;  
108 - }  
109 - }  
110 -  
111 - $item['subnav'][] = $subnav;  
112 - }  
113 - $menu[] = $item; 66 + $key = sprintf('%s_%s_%s',CacheConfig::KEY_WEB_HOME_NAVBAR_DATA, md5(serialize($data)), $channel);
  67 + $menu = Cache::get($key);
  68 + if(empty($menu)) {
  69 + $item = array();
  70 + foreach ($data['data'] as $val) {
  71 + $item = array(
  72 + 'name_cn' => $val['sort_name'], // 父级
  73 + 'name_en' => $val['sort_name_en'],
  74 + 'link' => $val['sort_url'],
  75 + 'icon' => $val['sort_ico'],
  76 + 'classname' => str_replace(' ', '', strtolower($val['sort_name_en'])) == $channel ? $channel : '',
  77 + 'index_main' => 0,
  78 + 'is_hot' => $val['is_hot'] == 'Y' ? true : false,
  79 + 'is_new' => $val['is_new'] == 'Y' ? true : false,
  80 + // 'subnav' => array()
  81 + );
  82 + foreach ($val['sub'] as $sub) { // 二级
  83 + $index_sub = 0;
  84 + $subnav = array(
  85 + 'name' => $sub['sort_name'],
  86 + 'name_en' => $sub['sort_name_en'],
  87 + 'link' => $sub['sort_url'],
  88 + 'is_hot' => $sub['is_hot'] == 'Y' ? true : false,
  89 + 'is_new' => $sub['is_new'] == 'Y' ? true : false,
  90 + // 'thirdnav' => array(),
  91 + 'index_sub' => $index_sub ++
  92 + );
  93 + if (isset($sub['sub'])) {
  94 + foreach ($sub['sub'] as $thirdsub) { // 三级
  95 + $thirdnav = array(
  96 + 'title' => $thirdsub['sort_name'],
  97 + 'name_en' => $thirdsub['sort_name_en'],
  98 + 'link' => $thirdsub['sort_url'],
  99 + // 'branditems' => array()
  100 + );
  101 + if (isset($thirdsub['sub'])) {
  102 + foreach ($thirdsub['sub'] as $fourthnav) { // 四级
  103 + $thirdnav['branditems'][] = array(
  104 + 'brandname' => $fourthnav['sort_name'],
  105 + 'link' => $fourthnav['sort_url'],
  106 + 'hot' => $fourthnav['is_hot'] == 'Y' ? 'hot' : ''
  107 + );
  108 + }
  109 + }
  110 + $subnav['thirdnav'][] = $thirdnav;
  111 + }
  112 + }
  113 +
  114 + $item['subnav'][] = $subnav;
  115 + }
  116 + $menu[] = $item;
  117 + }
  118 + Cache::set($key, $menu, 3600);
114 } 119 }
115 return $menu; 120 return $menu;
116 } 121 }
117 122
118 - /** 123 + /**
119 * 选择频道 124 * 选择频道
120 * 125 *
121 * @return void 126 * @return void
@@ -165,9 +170,14 @@ class HomeModel @@ -165,9 +170,14 @@ class HomeModel
165 */ 170 */
166 public static function getChannelResource($channel, $content_code) 171 public static function getChannelResource($channel, $content_code)
167 { 172 {
168 - $resource = IndexData::getResourceData($content_code);  
169 - // 格式化数据  
170 - $data = ChannelProcess::getFormat($channel, $resource['data']); 173 + $key = sprintf(CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.$channel);
  174 + $data = Cache::get($key);
  175 + if(empty($data)) {
  176 + $resource = IndexData::getResourceData($content_code);
  177 + // 格式化数据
  178 + $data = ChannelProcess::getFormat($channel, $resource['data']);
  179 + Cache::set($key, $data, 3600);
  180 + }
171 return $data; 181 return $data;
172 } 182 }
173 183
@@ -213,45 +223,51 @@ class HomeModel @@ -213,45 +223,51 @@ class HomeModel
213 public static function getNewArrival($channel) 223 public static function getNewArrival($channel)
214 { 224 {
215 $result = array(); 225 $result = array();
216 - $params = array(  
217 - 'order' => 's_t_desc',  
218 - 'shelve_time' => strtotime("-60 days") . ',' . time()  
219 - );  
220 - //男首频道最新上架参数是gender=1,3  
221 - if($channel == self::COOKIE_NAME_BOYS) {  
222 - $params['gender'] = '1,3';  
223 - }  
224 - //女首频道最新上架参数是gender=2,3  
225 - else if($channel == self::COOKIE_NAME_GIRLS) {  
226 - $params['gender'] = '2,3';  
227 - }  
228 - // 最新上架分类  
229 - if (isset(ChannelConfig::$newArrivalSortList[$channel])) {  
230 - $sortList = ChannelConfig::$newArrivalSortList[$channel];  
231 - // 获取分类列表获取商品信息  
232 - $goodsList = SearchData::getSearchDataBySort($params, $sortList);  
233 - $pos = 1;  
234 - foreach ($goodsList as $goods) {  
235 - // 格式化数据  
236 - $val = Helpers::formatProduct($goods, true, true, true, 280, 373);  
237 - if ($val['price'] == false) {  
238 - $val['price'] = $val['salePrice'];  
239 - }  
240 - $val['url'] = sprintf('%s?channel=%s&from=%s-n_%s', $val['url'], $channel , $channel, $pos++);  
241 - //TODO 字段要调整  
242 - $val['isFew'] = $val['is_soon_sold_out'];  
243 - $val['tags']['isLimit'] = $val['tags']['is_limited'];  
244 - $val['tags']['isSale'] = false;//$val['tags']['is_discount'];暂时不显示  
245 - $val['tags']['isNew'] = false;//$val['tags']['is_new'];暂时不显示  
246 - $val['tags']['isYearMidPromotion'] = $val['tags']['midYear'];  
247 - $val['tags']['isYearEndPromotion'] = $val['tags']['yearEnd'];  
248 - $val['tags']['isReNew'] = false;//$val['tags']['is_advance'];暂时不显示  
249 - unset($val['tags']['is_advance'], $val['tags']['is_discount'], $val['tags']['is_limited'], $val['tags']['is_new'],  
250 - $val['tags']['is_yohood'], $val['tags']['midYear'], $val['tags']['yearEnd']);  
251 - if (! empty($val)) {  
252 - $result[] = $val;  
253 - }  
254 - } 226 + $key = sprintf(CacheConfig::KEY_WEB_HOME_CHANNEL_NEWARRIVAL_DATA.'_'.$channel);
  227 + //缓存数据
  228 + $result = Cache::get($key);
  229 + if(empty($result)) {
  230 + $params = array(
  231 + 'order' => 's_t_desc',
  232 + 'shelve_time' => strtotime("-60 days") . ',' . time()
  233 + );
  234 + //男首频道最新上架参数是gender=1,3
  235 + if($channel == self::COOKIE_NAME_BOYS) {
  236 + $params['gender'] = '1,3';
  237 + }
  238 + //女首频道最新上架参数是gender=2,3
  239 + else if($channel == self::COOKIE_NAME_GIRLS) {
  240 + $params['gender'] = '2,3';
  241 + }
  242 + // 最新上架分类
  243 + if (isset(ChannelConfig::$newArrivalSortList[$channel])) {
  244 + $sortList = ChannelConfig::$newArrivalSortList[$channel];
  245 + // 获取分类列表获取商品信息
  246 + $goodsList = SearchData::getSearchDataBySort($params, $sortList);
  247 + $pos = 1;
  248 + foreach ($goodsList as $goods) {
  249 + // 格式化数据
  250 + $val = Helpers::formatProduct($goods, true, true, true, 280, 373);
  251 + if ($val['price'] == false) {
  252 + $val['price'] = $val['salePrice'];
  253 + }
  254 + $val['url'] = sprintf('%s?channel=%s&from=%s-n_%s', $val['url'], $channel , $channel, $pos++);
  255 + //TODO 字段要调整
  256 + $val['isFew'] = $val['is_soon_sold_out'];
  257 + $val['tags']['isLimit'] = $val['tags']['is_limited'];
  258 + $val['tags']['isSale'] = false;//$val['tags']['is_discount'];暂时不显示
  259 + $val['tags']['isNew'] = false;//$val['tags']['is_new'];暂时不显示
  260 + $val['tags']['isYearMidPromotion'] = $val['tags']['midYear'];
  261 + $val['tags']['isYearEndPromotion'] = $val['tags']['yearEnd'];
  262 + $val['tags']['isReNew'] = false;//$val['tags']['is_advance'];暂时不显示
  263 + unset($val['tags']['is_advance'], $val['tags']['is_discount'], $val['tags']['is_limited'], $val['tags']['is_new'],
  264 + $val['tags']['is_yohood'], $val['tags']['midYear'], $val['tags']['yearEnd']);
  265 + if (! empty($val)) {
  266 + $result[] = $val;
  267 + }
  268 + }
  269 + }
  270 + Cache::set($key, $result, 3600);
255 } 271 }
256 return $result; 272 return $result;
257 } 273 }
1 -<?php  
2 -use Action\WebAction;  
3 -use LibModels\Web\Passport\RegData;  
4 -use Passport\PassportModel;  
5 -use Plugin\Helpers;  
6 -use LibModels\Wap\Passport\BackData;  
7 -use Plugin\AuthCode;  
8 -class BackController extends WebAction {  
9 -  
10 - /**  
11 - * 找回密码  
12 - */  
13 - public function indexAction() {  
14 - $banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);  
15 - $data = array (  
16 - 'simpleHeader' => PassportModel::getSimpleHeader(false),  
17 - 'backPage' => true,  
18 - 'back' => array (  
19 - 'coverHref' => $banner ['url'],  
20 - 'coverImg' => $banner ['img'],  
21 - 'countryCode' => '86',  
22 - 'countryName' => '中国',  
23 - 'captchaUrl' => '/passport/images?t=1449799445',  
24 - 'countryList' => RegData::getAreasData()  
25 - )  
26 - );  
27 - $this->_view->display ( 'index', $data );  
28 - }  
29 -  
30 - /**  
31 - * 校验验证码  
32 - */  
33 - public function authcodeAction() {  
34 - $phoneNum = $this->post ('phoneNum', '');  
35 - $area = intval ($this->post( 'area', '86' ));  
36 - $verifyCode = $this->post ('verifyCode', '');  
37 - $data = array('code' => 400, 'message' =>'验证失败');  
38 - if ((Helpers::verifyEmail($phoneNum) || Helpers::verifyMobile($phoneNum))  
39 - && PassportModel::verifyCode($verifyCode)) {  
40 - $data['code'] = 200;  
41 - $data['message'] = '验证成功';  
42 - }  
43 - echo $this->echoJson($data);  
44 - }  
45 -  
46 - /**  
47 - * 邮箱  
48 - */  
49 - public function emailAction() {  
50 - $phoneNum = $this->post ('phoneNum', '');  
51 - $area = intval ($this->post('area', '86'));  
52 - $verifyCode = $this->post('verifyCode', '');  
53 - if (Helpers::verifyEmail($phoneNum)) { // 验证邮箱  
54 - $email = $phoneNum;  
55 - $data = BackData::sendCodeToEmail($email);  
56 -  
57 - if ($data ['code'] == 200) {  
58 - $this->setSession('email', $email);  
59 - $this->redirect ('sendemail');  
60 - } else {  
61 - $this->redirect ('index');  
62 - }  
63 -  
64 - } else if (Helpers::verifyMobile($phoneNum)) { // 验证手机号  
65 - $mobile = $phoneNum;  
66 - $data = BackData::sendCodeToMobile($mobile, $area);  
67 - if ($data ['code'] == 200) {  
68 - $this->setSession ('mobile', $mobile );  
69 - $this->setSession ('area', $area );  
70 - $this->setSession ('verifyCode', $verifyCode );  
71 - $this->redirect ('verification');  
72 - } else {  
73 - $this->redirect ('index');  
74 - }  
75 - }  
76 - }  
77 -  
78 - /**  
79 - * 发送邮件页面  
80 - */  
81 - public function sendemailAction() {  
82 - $email = $this->getSession ('email');  
83 - if (empty ( $email )) {  
84 - $this->redirect ('index');  
85 - }  
86 - $banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);  
87 - $data = array (  
88 - 'simpleHeader' => PassportModel::getSimpleHeader(false),  
89 - 'sendEmail' => array (  
90 - 'coverHref' => $banner ['url'],  
91 - 'coverImg' => $banner ['img'],  
92 - 'countrys' => array ()  
93 - )  
94 - );  
95 - $this->_view->display('send-email', $data);  
96 - }  
97 -  
98 - /**  
99 - * 重置密码页面  
100 - */  
101 - public function backcodeAction() {  
102 - $code = $this->get('code');  
103 - $info = $this->checkCode($code);  
104 - if (empty ( $info )) {  
105 - $this->redirect ('index');  
106 - }  
107 - $banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);  
108 - $data = array (  
109 - 'simpleHeader' => PassportModel::getSimpleHeader(false),  
110 - 'resetPage' => true,  
111 - 'resetPwd' => array (  
112 - 'coverHref' => $banner ['url'],  
113 - 'coverImg' => $banner ['img'],  
114 - 'countrys' => array(),  
115 - 'code' => $code  
116 - )  
117 - );  
118 - $this->_view->display('reset-pwd', $data);  
119 - }  
120 -  
121 - /**  
122 - * 更新密码接口  
123 - */  
124 - public function updateAction() {  
125 - $code = $this->post('code');  
126 - $password = $this->post('pwd');  
127 - $info = $this->checkCode($code);  
128 - if (Helpers::verifyPassword ($password) && ! empty ($info)) {  
129 - // 修改密码  
130 - if (isset ( $info ['mobile'] )) { // 手机号修改密码  
131 - $mobile = $info ['mobile'];  
132 - $token = $info ['token'];  
133 - $area = $info ['area'];  
134 - $data = BackData::modifyPasswordByMobile($mobile, $token, $password, $area);  
135 - if ($data ['code'] == 200) {  
136 - $this->redirect ( 'resetSuccess' );  
137 - }  
138 - } else if (isset ($info ['uid'])) { // 其他方式修改密码  
139 - $uid = $info ['uid'];  
140 - $this->redirect ( 'resetSuccess' );  
141 - }  
142 - }  
143 - // 跳转错误页面  
144 - // $this->redirect('/error/index');  
145 - }  
146 -  
147 - /**  
148 - * 重置密码成功  
149 - */  
150 - public function resetSuccessAction() {  
151 - $banner = PassportModel::getLeftBanner ( PassportModel::BACK_LFFT_BANNER_CODE );  
152 - $data = array (  
153 - 'simpleHeader' => PassportModel::getSimpleHeader ( false ),  
154 - 'resetSuccess' => array (  
155 - 'coverHref' => $banner ['url'],  
156 - 'coverImg' => $banner ['img'],  
157 - 'countrys' => array ()  
158 - )  
159 - );  
160 - $this->_view->display ( 'reset-success', $data );  
161 - }  
162 -  
163 - /**  
164 - * 手机验证页面  
165 - */  
166 - public function verificationAction() {  
167 - $mobile = $this->getSession ('mobile');  
168 - $area = $this->getSession ('area');  
169 - $verifyCode = $this->getSession ('verifyCode');  
170 - if (empty ($mobile)) {  
171 - $this->redirect ('index');  
172 - }  
173 - $banner = PassportModel::getLeftBanner (PassportModel::BACK_LFFT_BANNER_CODE);  
174 - $data = array (  
175 - 'simpleHeader' => PassportModel::getSimpleHeader ( false ),  
176 - 'vertificationPage' => true,  
177 - 'verification' => array (  
178 - 'coverHref' => $banner ['url'],  
179 - 'coverImg' => $banner ['img'],  
180 - 'mobile' => $mobile,  
181 - 'area' => $area,  
182 - 'verifyCode' => $verifyCode,  
183 - 'countrys' => array ()  
184 - )  
185 - );  
186 - $this->_view->display ('verification', $data);  
187 - }  
188 -  
189 - /**  
190 - * 手机找回密码验证  
191 - */  
192 - public function backmobileAction() {  
193 - $mobile = $this->post ( 'mobile' );  
194 - $area = $this->post ( 'area' );  
195 - $verifyCode = $this->post ( 'verifyCode' );  
196 - $code = $this->post ( 'code' ); // code  
197 - if ($this->getSession ( 'mobile' ) == $mobile && $this->getSession ( 'area' ) == $area) {  
198 - $result = BackData::validateMobileCode ( $mobile, $code, $area );  
199 - if ($result ['code'] == 200) {  
200 - $str = json_encode ( array (  
201 - 'mobile' => $mobile,  
202 - 'area' => $area,  
203 - 'token' => $result ['data'] ['token'],  
204 - 'create_time' => time ()  
205 - ) );  
206 - $code = AuthCode::encode ( $str, PassportModel::BACK_FIND_SECRET_KEY );  
207 - $url = '/passport/back/backcode?code=' . base64_encode ( $code );  
208 - $this->redirect ( SITE_MAIN . $url );  
209 - }  
210 - }  
211 - }  
212 -  
213 - /**  
214 - * 检查code  
215 - *  
216 - * @param string $code  
217 - * @return boolean  
218 - */  
219 - private function checkCode($code) {  
220 - $code = base64_decode ( $code );  
221 - $info = json_decode ( AuthCode::decode ( $code, PassportModel::BACK_FIND_SECRET_KEY ), true );  
222 - if ($info ['create_time'] < 1 || (time () - $info ['create_time']) > 86400) {  
223 - return array ();  
224 - }  
225 - return $info;  
226 - } 1 +<?php
  2 +use Action\WebAction;
  3 +use LibModels\Web\Passport\RegData;
  4 +use Passport\PassportModel;
  5 +use Plugin\Helpers;
  6 +use LibModels\Wap\Passport\BackData;
  7 +use Plugin\AuthCode;
  8 +class BackController extends WebAction {
  9 +
  10 + /**
  11 + * 找回密码
  12 + */
  13 + public function indexAction() {
  14 + $banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);
  15 + $data = array (
  16 + 'simpleHeader' => PassportModel::getSimpleHeader(false),
  17 + 'backPage' => true,
  18 + 'back' => array (
  19 + 'coverHref' => $banner ['url'],
  20 + 'coverImg' => $banner ['img'],
  21 + 'countryCode' => '86',
  22 + 'countryName' => '中国',
  23 + 'captchaUrl' => '/passport/images?t=1449799445',
  24 + 'countryList' => RegData::getAreasData()
  25 + )
  26 + );
  27 + $this->_view->display ( 'index', $data );
  28 + }
  29 +
  30 + /**
  31 + * 校验验证码
  32 + */
  33 + public function authcodeAction() {
  34 + $phoneNum = $this->post ('phoneNum', '');
  35 + $area = intval ($this->post( 'area', '86' ));
  36 + $verifyCode = $this->post ('verifyCode', '');
  37 + $data = array('code' => 400, 'message' =>'验证失败');
  38 + if ((Helpers::verifyEmail($phoneNum) || Helpers::verifyMobile($phoneNum))
  39 + && PassportModel::verifyCode($verifyCode)) {
  40 + $data['code'] = 200;
  41 + $data['message'] = '验证成功';
  42 + }
  43 + echo $this->echoJson($data);
  44 + }
  45 +
  46 + /**
  47 + * 邮箱
  48 + */
  49 + public function emailAction() {
  50 + $phoneNum = $this->post ('phoneNum', '');
  51 + $area = intval ($this->post('area', '86'));
  52 + $verifyCode = $this->post('verifyCode', '');
  53 + if (Helpers::verifyEmail($phoneNum)) { // 验证邮箱
  54 + $email = $phoneNum;
  55 + $data = BackData::sendCodeToEmail($email);
  56 + if ($data ['code'] == 200) {
  57 + $this->setSession('email', $email);
  58 + $this->redirect ('sendemail');
  59 + } else {
  60 + $this->redirect ('index');
  61 + }
  62 +
  63 + } else if (Helpers::verifyMobile($phoneNum)) { // 验证手机号
  64 + $mobile = $phoneNum;
  65 + $data = BackData::sendCodeToMobile($mobile, $area);
  66 +
  67 + if ($data['code'] == 200) {
  68 + $this->setSession ('mobile', $mobile );
  69 + $this->setSession ('area', $area );
  70 + $this->setSession ('verifyCode', $verifyCode );
  71 + $this->redirect ('verification');
  72 + } else {
  73 + $this->redirect ('index');
  74 + }
  75 + }
  76 + }
  77 +
  78 + /**
  79 + * 发送邮件页面
  80 + */
  81 + public function sendemailAction() {
  82 + $email = $this->getSession ('email');
  83 + if (empty ( $email )) {
  84 + $this->redirect ('index');
  85 + }
  86 + $banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);
  87 + $data = array (
  88 + 'simpleHeader' => PassportModel::getSimpleHeader(false),
  89 + 'sendEmail' => array (
  90 + 'coverHref' => $banner ['url'],
  91 + 'coverImg' => $banner ['img'],
  92 + 'countrys' => array ()
  93 + )
  94 + );
  95 + $this->_view->display('send-email', $data);
  96 + }
  97 +
  98 + /**
  99 + * 重置密码页面
  100 + */
  101 + public function backcodeAction() {
  102 + $code = $this->get('code');
  103 + $info = $this->checkCode($code);
  104 + if (empty ( $info )) {
  105 + $this->redirect ('index');
  106 + }
  107 + $banner = PassportModel::getLeftBanner(PassportModel::BACK_LFFT_BANNER_CODE);
  108 + $data = array (
  109 + 'simpleHeader' => PassportModel::getSimpleHeader(false),
  110 + 'resetPage' => true,
  111 + 'resetPwd' => array (
  112 + 'coverHref' => $banner ['url'],
  113 + 'coverImg' => $banner ['img'],
  114 + 'countrys' => array(),
  115 + 'code' => $code
  116 + )
  117 + );
  118 + $this->_view->display('reset-pwd', $data);
  119 + }
  120 +
  121 + /**
  122 + * 更新密码接口
  123 + */
  124 + public function updateAction() {
  125 + $code = $this->post('code');
  126 + $password = $this->post('pwd');
  127 + $info = $this->checkCode($code);
  128 + if (Helpers::verifyPassword ($password) && ! empty ($info)) {
  129 + // 修改密码
  130 + if (isset ( $info ['mobile'] )) { // 手机号修改密码
  131 + $mobile = $info ['mobile'];
  132 + $token = $info ['token'];
  133 + $area = $info ['area'];
  134 + $data = BackData::modifyPasswordByMobile($mobile, $token, $password, $area);
  135 + if ($data ['code'] == 200) {
  136 + $this->redirect ( 'resetSuccess' );
  137 + }
  138 + } else if (isset ($info ['uid'])) { // 其他方式修改密码
  139 + $uid = $info ['uid'];
  140 + $this->redirect ( 'resetSuccess' );
  141 + }
  142 + }
  143 + // 跳转错误页面
  144 + // $this->redirect('/error/index');
  145 + }
  146 +
  147 + /**
  148 + * 重置密码成功
  149 + */
  150 + public function resetSuccessAction() {
  151 + $banner = PassportModel::getLeftBanner ( PassportModel::BACK_LFFT_BANNER_CODE );
  152 + $data = array (
  153 + 'simpleHeader' => PassportModel::getSimpleHeader ( false ),
  154 + 'resetSuccess' => array (
  155 + 'coverHref' => $banner ['url'],
  156 + 'coverImg' => $banner ['img'],
  157 + 'countrys' => array ()
  158 + )
  159 + );
  160 + $this->_view->display ( 'reset-success', $data );
  161 + }
  162 +
  163 + /**
  164 + * 手机验证页面
  165 + */
  166 + public function verificationAction() {
  167 + $mobile = $this->getSession ('mobile');
  168 + $area = $this->getSession ('area');
  169 + $verifyCode = $this->getSession ('verifyCode');
  170 + if (empty ($mobile)) {
  171 + $this->redirect ('index');
  172 + }
  173 + $banner = PassportModel::getLeftBanner (PassportModel::BACK_LFFT_BANNER_CODE);
  174 + $data = array (
  175 + 'simpleHeader' => PassportModel::getSimpleHeader ( false ),
  176 + 'vertificationPage' => true,
  177 + 'verification' => array (
  178 + 'coverHref' => $banner ['url'],
  179 + 'coverImg' => $banner ['img'],
  180 + 'mobile' => $mobile,
  181 + 'area' => $area,
  182 + 'verifyCode' => $verifyCode,
  183 + 'countrys' => array ()
  184 + )
  185 + );
  186 + $this->_view->display ('verification', $data);
  187 + }
  188 +
  189 + /**
  190 + * 手机找回密码验证
  191 + */
  192 + public function backmobileAction() {
  193 + $mobile = $this->post ( 'mobile' );
  194 + $area = $this->post ( 'area' );
  195 + $verifyCode = $this->post ( 'verifyCode' );
  196 + $code = $this->post ( 'code' ); // code
  197 + if ($this->getSession ( 'mobile' ) == $mobile && $this->getSession ( 'area' ) == $area) {
  198 + $result = BackData::validateMobileCode ( $mobile, $code, $area );
  199 + if ($result ['code'] == 200) {
  200 + $str = json_encode ( array (
  201 + 'mobile' => $mobile,
  202 + 'area' => $area,
  203 + 'token' => $result ['data'] ['token'],
  204 + 'create_time' => time ()
  205 + ) );
  206 + $code = AuthCode::encode ( $str, PassportModel::BACK_FIND_SECRET_KEY );
  207 + $url = '/passport/back/backcode?code=' . base64_encode ( $code );
  208 + $this->redirect ( SITE_MAIN . $url );
  209 + }
  210 + }
  211 + //出错直接跳到找回密码页
  212 + $this->redirect ('/passport/back/index');
  213 + }
  214 +
  215 + /**
  216 + * 检查code
  217 + *
  218 + * @param string $code
  219 + * @return boolean
  220 + */
  221 + private function checkCode($code) {
  222 + $code = base64_decode ( $code );
  223 + $info = json_decode ( AuthCode::decode ( $code, PassportModel::BACK_FIND_SECRET_KEY ), true );
  224 + if ($info ['create_time'] < 1 || (time () - $info ['create_time']) > 86400) {
  225 + return array ();
  226 + }
  227 + return $info;
  228 + }
  229 +
227 } 230 }