<commit_before><?php
namespace Home\Controller;

header('Access-Control-Allow-Origin: *');

use Common\Controller\CommonController;
use Common\Jpush;
use Common\Tools;
use Home\Api\ApiAppKnow;

class IndexController extends CommonController {

    //农医问药接口
    public function index(){
        // 返回函数
        $jsoncallback = I('get.jsoncallback');
        $api = new ApiAppKnow();

        $show['status'] = 200;
        //$api->putLog('data',I());
        switch (I('get.action')) {
            // 登陆
            case 'login':
                $password = md5(md5(I('get.password')));
                $x = $api->getUserFromMobile(I('get.mobile'));
                $show['member_info'] = $x;
                if ($x[0]['password'] == $password) {
                    if($x[0]['status'] != 0){
                        $show['member_info'] = $x;
                        $api->getLastLoginTime($x[0]['userid']);

                        $show['info'] = $api->getMemAreaId($x[0]['userid']);

                        //登录积分设置 每天累加一分
                        $last_time = $x[0]['last_login_time'];
                        $timestamp = time() - $last_time;
                        //$api->putLog('sql',$timestamp);
                        if($timestamp > 86400){  //24h 后才可以累加积分
                            $api->addScore($x[0]['userid'],'sa_login');
                        }

                    }else{
                        $show['status'] = 222;
                    }
                } else {
                    $show['status'] = 204;
                }

                break;

            // 获取注册码
            case 'get_register_code':
                if ($api->getUserFromMobile(I('get.mobile'))) {
                    $show['status'] = 202;
                } else {
                    $k = md5(I('get.mobile')) . 'register_code';
                    if (S($k)) {
                        $show['status'] = 209;
                    } else {
                        $x = rand(100000, 999999);
                        S($k, $x, 120);
                        if ($y = $api->sendSms($x, I('get.mobile'))) {

                        } else {
                            $show['status'] = 206;
                        }
                    }
                }
                break;

            // 注册
            case 'register':
                $password = <PASSWORD>(<PASSWORD>(I('get.password')));
                $k = md5(I('get.mobile')) . 'register_code';
                if ($api->getUserFromMobile(I('get.mobile'))) {
                    $show['status'] = 202;
                } else {
                    if (S($k) == I('get.yzm')) {
                        $show['status'] = $api->register(I('get.'));
                        if ($show['status'] = 200) {
                            $show['member_info'] = $api->getUserFromMobile(I('get.mobile'));
                            
                            //默认添加信息到个人资料表
                            $api->setMemberProfile($show['member_info'][0]['userid']);

                            //判断邀请码是否存在
                            $code = $api->checkApplyCode(I('get.apply_code'));
                            if($code == 1){
                                // 双方各加 100积分
                                $api->addApplyCodeScore($show['member_info'][0]['userid'],I('get.apply_code'));

                                // 邀请信息添加到邀请表
                                $api->addApplyCode(I('get.apply_code'),$show['member_info'][0]['userid']);
                            }
                        }
                    }else{
                        $show['status'] = 223;
                    }
                }
                break;

            // 重置密码
            // 获取验证码
            case 'get_code':
                if ($api->getUserFromMobile(I('get.mobile'))) {
                    $k = md5(I('get.mobile')) . 'reset_password_code';
                    if (S($k)) {
                        $show['status'] = 209;
                    } else {
                        $x = rand(100000,999999);
                        S($k, $x, 120);
                        if ($y = $api->sendSms($x, I('get.mobile'))) {

                        } else {
                            $show['status'] = 206;
                        }
                    }
                } else {
                    $show['status'] = 205;
                }
                break;

            // 验证验证码
            case 'validate_code':
                $k = md5(I('get.mobile')) . 'reset_password_code';
                if (S($k) == I('get.code')) {

                } else {
                    $show['status'] = 207;
                }
                break;

            // 重置新密码
            case 'reset_password':
                $password = <PASSWORD>(md5(I('get.password')));
                $mobile = I('get.mobile');
                $sql = "UPDATE ".C('DATABASE_MALL_TABLE_PREFIX')."ucenter_member SET password = '{<PASSWORD>}' WHERE mobile = '{$mobile}'";
                if ($api->execute($sql)) {
                } else {
                    $show['status'] = 208;
                }
                break;

            // 获取地区信息
            case 'get_area_info':
                $show['area_info'] = $api->getAreaInfo(I('get.pid'));
                if (!$show['area_info']) {
                    $show['status'] = 210;
                }
                break;

            // 获取地区父级节点
            case 'get_area_parent_nodes':
                $allArea = $api->getAllArea();
                $x = Tools::get_list_parents($allArea, I('get.areaid'), 'areaid', 'parentid');
                $show['parent_areas'] = $x;
                break;

            // 获取自定义栏目信息
            case 'get_ask_category_info':
                $show['category_info'] = $api->getAskCategoryInfo(I('get.pid'));
                if (!$show['category_info']) {
                    $show['status'] = 210;
                }
                break;

            // 获取个人信息
            case 'get_member_profile':
                $show['member_profile'] = $api->getUserDetail(I('get.userid'),array('member_profile','expert_profile'));
                if (!$show['member_profile']) {
                    $show['status'] = 211;
                }

                $allArea = $api->getAllArea();
                $x = Tools::get_list_parents($allArea, I('get.areaid'), 'areaid', 'parentid');
                $show['parent_areas'] = $x;
                break;

            // 设置个人信息
            case 'set_member_profile':
                $info = I('get.');
                $x = $api->setAppknowMemberProfile($info);
                if (!$x) {
                    $show['status'] = 212;
                }else{
                    $show['member_profile'] = $api->getUserDetail(I('get.userid'),array('member_profile','expert_profile'));

                    //登录积分设置 每天累加一分
                    $is_ok = $show['member_profile'][0]['is_ok'];
                    if($is_ok == 0){
                        $api->addScore(I('get.userid'),'sa_profile');
                        $api->profileIsOk(I('get.userid')); //完善信息状态修改
                    }
                }
                break;

            // 上传会员图片
            case 'upload_avatar_image':
                $_dir = C('UPLOADS').'avatar/';
                $extend_type = Tools::get_extend($_FILES['filename']['name']);
                $upload_dir = APP_ROOT . $_dir;
                $upload_name = "user_" . I('get.userid') . "_" . date("Y_m_d__H_i_s", time());
                $show['status'] = ApiAppKnow::uploadImage($_FILES['filename'], $upload_dir, $upload_name);
                if ($show['status'] == 200) {
                    $info = array('userid' => I('get.userid'), 'avatar' => $_dir . $upload_name . "." . $extend_type);
                    if ($api->setAppknowMemberAvatar($info)) {
                        $show['image_path'] = APP_ROOT . $info['avatar'];
                    } else {<commit_msg>我的邀请码bug修复<commit_after><?php
namespace Home\Controller;

header('Access-Control-Allow-Origin: *');

use Common\Controller\CommonController;
use Common\Jpush;
use Common\Tools;
use Home\Api\ApiAppKnow;

class IndexController extends CommonController {

    //农医问药接口
    public function index(){
        // 返回函数
        $jsoncallback = I('get.jsoncallback');
        $api = new ApiAppKnow();

        $show['status'] = 200;
        //$api->putLog('data',I());
        switch (I('get.action')) {
            // 登陆
            case 'login':
                $password = <PASSWORD>(<PASSWORD>(I('get.password')));
                $x = $api->getUserFromMobile(I('get.mobile'));
                $show['member_info'] = $x;
                if ($x[0]['password'] == $password) {
                    if($x[0]['status'] != 0){
                        $show['member_info'] = $x;
                        $api->getLastLoginTime($x[0]['userid']);

                        $show['info'] = $api->getMemAreaId($x[0]['userid']);

                        //登录积分设置 每天累加一分
                        $last_time = $x[0]['last_login_time'];
                        $timestamp = time() - $last_time;
                        //$api->putLog('sql',$timestamp);
                        if($timestamp > 86400){  //24h 后才可以累加积分
                            $api->addScore($x[0]['userid'],'sa_login');
                        }

                    }else{
                        $show['status'] = 222;
                    }
                } else {
                    $show['status'] = 204;
                }

                break;

            // 获取注册码
            case 'get_register_code':
                if ($api->getUserFromMobile(I('get.mobile'))) {
                    $show['status'] = 202;
                } else {
                    $k = md5(I('get.mobile')) . 'register_code';
                    if (S($k)) {
                        $show['status'] = 209;
                    } else {
                        $x = rand(100000, 999999);
                        S($k, $x, 120);
                        if ($y = $api->sendSms($x, I('get.mobile'))) {

                        } else {
                            $show['status'] = 206;
                        }
                    }
                }
                break;

            // 注册
            case 'register':
                $password = <PASSWORD>(<PASSWORD>(I('get.password')));
                $k = md5(I('get.mobile')) . 'register_code';
                if ($api->getUserFromMobile(I('get.mobile'))) {
                    $show['status'] = 202;
                } else {
                    if (S($k) == I('get.yzm')) {
                        $show['status'] = $api->register(I('get.'));
                        if ($show['status'] = 200) {
                            $show['member_info'] = $api->getUserFromMobile(I('get.mobile'));
                            
                            //默认添加信息到个人资料表
                            $api->setMemberProfile($show['member_info'][0]['userid']);

                            //判断邀请码是否存在
                            $code = $api->checkApplyCode(I('get.apply_code'));
                            if($code == 1){
                                // 双方各加 100积分
                                $api->addApplyCodeScore($show['member_info'][0]['userid'],I('get.apply_code'));

                                // 邀请信息添加到邀请表
                                $api->addApplyCode(I('get.apply_code'),$show['member_info'][0]['userid']);
                            }
                        }
                    }else{
                        $show['status'] = 223;
                    }
                }
                break;

            // 重置密码
            // 获取验证码
            case 'get_code':
                if ($api->getUserFromMobile(I('get.mobile'))) {
                    $k = md5(I('get.mobile')) . 'reset_password_code';
                    if (S($k)) {
                        $show['status'] = 209;
                    } else {
                        $x = rand(100000,999999);
                        S($k, $x, 120);
                        if ($y = $api->sendSms($x, I('get.mobile'))) {

                        } else {
                            $show['status'] = 206;
                        }
                    }
                } else {
                    $show['status'] = 205;
                }
                break;

            // 验证验证码
            case 'validate_code':
                $k = md5(I('get.mobile')) . 'reset_password_code';
                if (S($k) == I('get.code')) {

                } else {
                    $show['status'] = 207;
                }
                break;

            // 重置新密码
            case 'reset_password':
                $password = <PASSWORD>(md5(I('get.password')));
                $mobile = I('get.mobile');
                $sql = "UPDATE ".C('DATABASE_MALL_TABLE_PREFIX')."ucenter_member SET password = '{<PASSWORD>}' WHERE mobile = '{$mobile}'";
                if ($api->execute($sql)) {
                } else {
                    $show['status'] = 208;
                }
                break;

            // 获取地区信息
            case 'get_area_info':
                $show['area_info'] = $api->getAreaInfo(I('get.pid'));
                if (!$show['area_info']) {
                    $show['status'] = 210;
                }
                break;

            // 获取地区父级节点
            case 'get_area_parent_nodes':
                $allArea = $api->getAllArea();
                $x = Tools::get_list_parents($allArea, I('get.areaid'), 'areaid', 'parentid');
                $show['parent_areas'] = $x;
                break;

            // 获取自定义栏目信息
            case 'get_ask_category_info':
                $show['category_info'] = $api->getAskCategoryInfo(I('get.pid'));
                if (!$show['category_info']) {
                    $show['status'] = 210;
                }
                break;

            // 获取个人信息
            case 'get_member_profile':
                $show['member_profile'] = $api->getUserDetail(I('get.userid'),array('member_profile','expert_profile'));
                if (!$show['member_profile']) {
                    $show['status'] = 211;
                }

                $allArea = $api->getAllArea();
                $x = Tools::get_list_parents($allArea, I('get.areaid'), 'areaid', 'parentid');
                $show['parent_areas'] = $x;
                break;

            // 设置个人信息
            case 'set_member_profile':
                $info = I('get.');
                $x = $api->setAppknowMemberProfile($info);
                if (!$x) {
                    $show['status'] = 212;
                }else{
                    $show['member_profile'] = $api->getUserDetail(I('get.userid'),array('member_profile','expert_profile'));

                    //登录积分设置 每天累加一分
                    $is_ok = $show['member_profile'][0]['is_ok'];
                    if($is_ok == 0){
                        $api->addScore(I('get.userid'),'sa_profile');
                        $api->profileIsOk(I('get.userid')); //完善信息状态修改
                    }

                    $api->setApplyCode($show['member_profile'][0]['userid']);  //设置邀请码
                }
                break;

            // 上传会员图片
            case 'upload_avatar_image':
                $_dir = C('UPLOADS').'avatar/';
                $extend_type = Tools::get_extend($_FILES['filename']['name']);
                $upload_dir = APP_ROOT . $_dir;
                $upload_name = "user_" . I('get.userid') . "_" . date("Y_m_d__H_i_s", time());
                $show['status'] = ApiAppKnow::uploadImage($_FILES['filename'], $upload_dir, $upload_name);
                if ($show['status'] == 200) {
                    $info = array('userid' => I('get.userid'), 'avatar' => $_dir . $upload_name . "." . $extend_type);
                    if ($api->setAppknowMemberAvatar($info)) {
                        $show['image_path'] = APP_ROOT . $info['avatar'];
                    } else {
{'fraction_non_alphanumeric': 0.1570258270277031, 'fraction_numerical': 0.014570696016509286, 'mean_word_length': 1.09483887870055, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3950495', 'n_tokens_mistral': 4857, 'n_tokens_neox': 4515, 'n_words': 632}