<?php
/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 2017/4/27
 * Time: 下午6:01
 */

namespace login;

class mobile_log extends ILogin
{
    private $mMobile;
    public function __construct($mobile)
    {
        $this->mMobile = $mobile;
    }

    public function ismember()
    {
        $mod_member = Model('member');
        $minfo = $mod_member->getMemberInfo(['member_mobile' => $this->mMobile],ILogin::fields,true);
        if(empty($minfo)) {
            return false;
        }
        else {
            $this->mMemberId = intval($minfo['member_id']);
            $this->mMemberInfo = $minfo;
            return true;
        }
    }
    public function register($passwd,$user_info,$relay_id = 0)
    {
        $info['member_mobile'] = $this->mMobile;
        $info['member_type'] = ILogin::mobile_login;
        $info['member_passwd'] =  $passwd;
        $info['member_name'] =  $this->mMobile;
        $info['member_mobile_bind'] = 1;
        $info['inviter_id'] = $relay_id;

        if(empty($user_info)) {
            $info['member_sex'] = 0;
            $info['member_nickname'] = substr_replace($this->mMobile, '****', 3, 4);
        } else {
            $info['member_nickname']  = $user_info['nickname'];
            $info['member_wxunionid'] = $user_info['unionid'];
            $info['member_avatar']   = $user_info['headimgurl'];
            $info['member_sex']      = intval($user_info['sex']);
        }

        $mod_member = Model('member');
        $insert_id = $mod_member->addMember($info);
        if($insert_id != false) {
            $this->mMemberId = $insert_id;
        }

        return $insert_id;
    }
}