Passport.php
4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
namespace Passport;
use WebPlugin\Helpers;
use LibModels\Web\Home\IndexData;
use LibModels\Web\Home\UserData;
use WebPlugin\Images;
use WebPlugin\Captcha;
use WebPlugin\Cache;
/**
* web登录注册等相关数据构建
*
* @name PassportModel
* @package models
* @copyright yoho.inc
* @version 1.0 (2015-12-29 14:38:00)
* @author xiaowei <xiaowei.gong@yoho.cn>
*/
class PassportModel
{
const REGISTER_LEFT_BANNER_CODE = 'c479ec90120cae7f96e52922b4917064'; //注册左边的banner
const BACK_LFFT_BANNER_CODE = '3bbaf502c447a2ddad60879042e286d8'; //找回密码左边的banner
const SIGNIN_LEFT_BANNER_CODE = 'db350894e01e90eac55cd3a13ad77331'; //登录页左边的banner
const AUTOUSERINFO_LEFT_BANNER_CODE = 'c62d5da06d843b6ed78d8d27e87fa143'; //完善信息页左边的banner
const BACK_FIND_SECRET_KEY = '_+@#$%^';
//默认简单头部(不带登录信息 请登录/注册)
public static function getSimpleHeader()
{
//拼接简单头部
$radomNum = time();
$tool = array(
'favoriteHref' => Helpers::url('/home/favorite?t=' . $radomNum), //我的收藏链接
'couponHref' => Helpers::url('/home/coupons?t=' . $radomNum), //我的优惠券链接
'orderHref' => Helpers::url('/home/orders?t=' . $radomNum), //订单中心连接
'userCenter' => Helpers::url('/home?t=' . $radomNum),
'helpHref' => Helpers::url('/help'),
);
$tool+=array(
'loginHref' => Helpers::url('/signin.html'), //登录链接,已登录不传
'registerHref' => Helpers::url('/reg.html'), //注册链接,已登录不传
);
$simpleHeader = array(
'logo' => array(
'img' => 'http://static.yohobuy.com/newheader/img/logo_e.png',
'url' => SITE_MAIN
),
'tool' => $tool,
'simpleHeader' => true,
);
return $simpleHeader;
}
/**
* 获取左侧banner
*
* @param string $code
* @return array
*/
public static function getLeftBanner($code)
{
$ret = array('img' => '', 'url' => '');
$resource = IndexData::getResourceData($code);
if (isset($resource['data'][0])) {
if ($resource['data'][0]['template_name'] == 'single_image') {
$val = current($resource['data'][0]['data']);
}
else if ($resource['data'][0]['template_name'] == 'single_name_image') {
$val = $resource['data'][0]['data'];
}
$ret['img'] = Images::getImageUrl($val['src'], 252, 190);
$ret['url'] = $val['url'];
}
else {
$ret['img'] = 'http://img12.static.yhbimg.com/yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190';
$ret['url'] = '';
}
return $ret;
}
/**
* 校验验证码
*
* @param string $verifyCode
* @return boolean
*/
public static function verifyCode($verifyCode)
{
$verifyCode = strtolower($verifyCode);
$ret = true;
//检测验证码不正确
if ($verifyCode != strtolower(Captcha::getFromSession('passport_istration'))) {
$ret = false;
}
return $ret;
}
/**
* 根据手机号获取用户信息
*
* @param string $area
* @param string $mobile
* @return array
*/
public static function getUserInfoByMobile($area, $mobile)
{
$ret = array();
$data = UserData::getUserInfoByMobile($area, $mobile);
if ($data['code'] == 200) {
if (!empty($data['data'])) {
$ret = current($data['data']);
}
}
return $ret;
}
/**
* 根据邮箱获取用户信息
*
* @param string $email
* @return array
*/
public static function getUserInfoByEmail($email)
{
$ret = array();
$data = UserData::getUserInfoByEmail($email);
if ($data['code'] == 200) {
if (!empty($data['data'])) {
$ret = current($data['data']);
}
}
return $ret;
}
/*
* 重写递增计数 cache方法
* $key cache-key,递增存放变量
* $offset 递增偏移量
* $initValue 初始化值
* $expiry 缓存时间
*/
public static function increment($key, $offset = 1, $initValue = 0, $expire = 1800)
{
//初始化计时
if (!Cache::get($key)) {
Cache::set($key, $initValue, $expire);
}
//递增,过期则重新计算
$cacheValue = intval(Cache::get($key)) + $offset;
Cache::set($key, $cacheValue, $expire);
}
}