 <?php
    //获取会员组名称
    function  GetMemberGroupName($groupid)
    {
        $retname = "";
        if (!empty($groupid)) {
            $strsql = "select * from `#yunyecms_membergroup` where `id`= {$groupid}";
            $curmembergroup = getone($strsql);
            if (empty($curmembergroup)) {
                $retname = false;
            } else {
                $retname = $curmembergroup["groupname"];
            }
        }
        return $retname;
    }


    function  GetGroupStyle($groupid)
    {
        $groupname = GetMemberGroupName($groupid);
        $retname = "";
        if (stripos($groupname, '普通') !== false) {
            $retname = "<span class='badge bg-success'>普通会员</span>";
        } elseif (stripos($groupname, 'VIP') !== false) {
            $retname = "<span class='badge bg-danger'>VIP会员</span>";
        } elseif (stripos($groupname, '游客') !== false) {
            $retname = "<span class='badge bg-info'>游客</span>";
        } else {
            $retname = "<span class='badge bg-info'>游客</span>";
        }
        return $retname;
    }


    function apigetmember($userid, $token)
    {
        if (empty($userid) || !is_numeric($userid) || empty($token)) {
            return false;
        } else {
            if ($userid && is_numeric($userid)) {
                $strsql = "select id, username, groupid,  tid, name, money, score, openid,unionid, nickname, avatarurl,  country, province, city, area, access_token, expires_in, sex, mobile, phone, address, weixin, status,  pic  from `#yunyecms_member` where `id`= '{$userid}' and  `rnd`='$token'";
                $cuser = getone($strsql);
                if (!empty($cuser)) {
                    if ($cuser["pic"]) $cuser["pic"] = DOMAIN . "/" . $cuser["pic"];
                    $cuser["final_pic"] = api_final_pic($cuser["pic"], $cuser["avatarurl"]);
                    $cuser["final_name"] = api_final_name($cuser["name"], $cuser["nickname"]);
                    $income_list = getone("select  sum(money) as income  from `#yunyecms_rebate_records` where status=1  and userid='{$userid}' ");
                    if (!empty($income_list['income'])) {
                        $cuser["income"] = $income_list['income'];
                    } else {
                        $cuser["income"] = 0;
                    }
                    api_check_userinfo($cuser);
                    return $cuser;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    }

    function api_check_userinfo($cuser)
    {
        if ($cuser['userid'] == $cuser['tid']) {
            output_json(array("code" => 196, "msg" => "用户的推荐人不能是自己"));
        }
    }



    function api_final_pic($pic, $avatarurl)
    {
        $ret = "";
        if (empty($pic) && empty($avatarurl)) {
            $ret = "";
        }
        if (!empty($pic) && !empty($avatarurl)) {
            $ret = $pic;
        } elseif (!empty($pic)) {
            $ret = $pic;
        } elseif (!empty($avatarurl)) {
            $ret = $avatarurl;
        }
        return  $ret;
    }


    function api_final_name($name, $nickname)
    {
        $ret = "";
        if (empty($name) && empty($nickname)) {
            $ret = "";
        }
        if (!empty($name) && !empty($nickname)) {
            $ret = $name;
        } elseif (!empty($name)) {
            $ret = $name;
        } elseif (!empty($nickname)) {
            $ret = $nickname;
        }
        return  $ret;
    }


    function getmember($userid)
    {
        if (empty($userid) || !is_numeric($userid)) {
            return false;
        } else {
            if ($userid && is_numeric($userid)) {
                $strsql = "select id, username, groupid,  tid, name, money, score, openid, nickname, avatarurl, unionid, country, province, city, area, access_token, expires_in, sex, mobile, phone, address, status,  pic  from `#yunyecms_member` where `id`= '{$userid}' ";
                $cuser = getone($strsql);
                if (!empty($cuser)) {
                    if ($cuser["pic"]) $cuser["pic"] = DOMAIN . "/" . $cuser["pic"];
                    $cuser["final_pic"] = api_final_pic($cuser["pic"], $cuser["avatarurl"]);
                    $cuser["final_name"] = api_final_name($cuser["name"], $cuser["nickname"]);
                    $income_list = getone("select  sum(money) as income  from `#yunyecms_rebate_records` where status=1  and userid='{$userid}' ");
                    if (!empty($income_list['income'])) {
                        $cuser["income"] = $income_list['income'];
                    } else {
                        $cuser["income"] = 0;
                    }
                    api_check_userinfo($cuser);
                    return $cuser;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    }


    //获取验证码类型
    function get_smstype($smstype = 1)
    {
        $ret = "";
        if (empty($smstype) || !is_numeric($smstype)) {
            return false;
        } else {
            $smstype = intval($smstype);
            switch ($smstype) {
                case 1:
                    $ret = "regcode";
                    break;
                case 2:
                    $ret = "logincode";
                    break;
                case 3:
                    $ret = "findpwdcode";
                    break;
                case 4:
                    $ret = "editpwdcode";
                    break;
                case 5:
                    $ret = "infoeditcode";
                    break;
                default:
                    $ret = "regcode";
            }
        }
        return  $ret;
    }

    //获取验证码类型
    function getEmailMsg($msgtype = 1, $code)
    {
        $ret = "";
        if (empty($msgtype) || !is_numeric($msgtype)) {
            return false;
        } else {
            $msgtype = intval($msgtype);
            switch ($msgtype) {
                case 1:
                    $ret = "验证码{$code}，您正在注册成为新用户，感谢您的支持！";
                    break;
                case 2:
                    $ret = "验证码{$code}，您正在登录，若非本人操作，请勿泄露！";
                    break;
                case 3:
                    $ret = "验证码{$code}，您正在进行密码找回操作，如非本人操作，请忽略本短信！";
                    break;
                case 4:
                    $ret = "验证码{$code}，您正在尝试修改登录密码，请妥善保管账户信息。";
                    break;
                case 5:
                    $ret = "验证码{$code}，您正在进行身份验证，打死不要告诉别人哦！";
                    break;
                default:
                    $ret = "验证码{$code}，您正在注册成为新用户，感谢您的支持！";
            }
        }
        return  $ret;
    }

    //获取验证码类型
    function get_sms_tplcode($smstype = 1)
    {
        global $cfg;
        $ret = "";
        if (empty($smstype) || !is_numeric($smstype)) {
            return false;
        } else {
            $smstype = intval($smstype);
            switch ($smstype) {
                case 1:
                    $ret = $cfg['sms']['tpl_reg'];
                    break;
                case 2:
                    $ret = $cfg['sms']['tpl_quicklogin'];
                    break;
                case 3:
                    $ret = $cfg['sms']['tpl_findpwd'];
                    break;
                case 4:
                    $ret = $cfg['sms']['tpl_editpwd'];
                    break;
                case 5:
                    $ret = $cfg['sms']['tpl_infoedit'];
                    break;
                default:
                    $ret = $cfg['sms']['tpl_reg'];
            }
        }
        return  $ret;
    }





    ?>
 
