Passport.php 3.25 KB
<?php

namespace Passport;

use Plugin\Helpers;
use LibModels\Web\Home\IndexData;
use LibModels\Web\Passport\RegData;
use Plugin\Images;
use Plugin\Captcha;

/**
 * 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
    
    //简单头部
    public static function getSimpleHeader($isLogin, $username = '')
    {
        $tool = array(
            'favoriteHref' => Helpers::url('/home/favorite/index'), //我的收藏链接
            'couponHref' => Helpers::url('/home/coupons/index'), //我的优惠券链接
            'orderHref' => Helpers::url('/home/orders/index'), //订单中心连接
            'helpHref' => Helpers::url('/help'),
        );
        if ($isLogin) {
            $tool+=array(
                'user' => $username,
                'userCenter' => Helpers::url('/home/index'), //用户中心链接
                'logoutHref' => Helpers::url('/passport/signout/index'), //退出
            );
        }
        else {
            $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
        );

        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]))
        {
            $val = current($resource['data'][0]['data']);
            $ret['img'] = Images::getImageUrl($val['src'], 252, 190);
            $ret['url'] = $val['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 = RegData::getUserInfoByMobile($area, $mobile);
        if($data['code'] == 200) {
            if(!empty($data['data'])) {
                $ret = current($data['data']);
            }
        }
        return $ret;
    }
    
}