<?php
/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 2017/6/2
 * Time: 下午12:09
 */

namespace login;

//兼容开放平台的微信登录
class open_userinfo_log extends ILogin
{
    private $mUserInfo;

    public function __construct($user_info)
    {
        $this->mUserInfo = $user_info;
    }

    public function ismember()
    {
        $mod_member = Model('member');
        $openid  = $this->mUserInfo['openid'];
        $unionid = $this->mUserInfo['unionid'];
        $cond['member_wxunionid|member_wxopenid'] = array('_multi'=>true,$unionid,$openid);
        $minfo = $mod_member->getMemberInfo($cond,ILogin::fields,true);

        if(empty($minfo)) {
            return false;
        }
        else
        {
            $this->mMemberId = intval($minfo['member_id']);
            $this->mMemberInfo = $minfo;

            if($minfo['member_wxopenid'] == $openid) {
                $this->mMemberInfo['member_wxopenid'] = '';
                $mod_member->editMember(['member_id' => $this->memberid()],['member_wxopenid' => '']);
            }

            return true;
        }
    }

    public function register($passwd,$user_info,$relay_id = 0)
    {

    }
}