<?php
/**
 *
 * ============================================================================
 * * 版权所有 蜘蛛出行 * *
 * 网站地址: http://www.zhizhuchuxing.com
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * Author By: 倪宗锋
 * PhpStorm LoginController.php
 * Create By 2017/2/22 15:08 $
 */


namespace fx\controllers\user;

use common\Controller\FxWebController;
use common\models\FxUser;
use fx\service\user\LoginService;
use common\util\Util;
use Yii;

class LoginController extends FxWebController
{
    public $enableCsrfValidation = false;
    /**
     * Des:获取service
     * Name: service
     * @return LoginService
     * @author 倪宗锋
     */
    public function service()
    {
        if ($this->service == '') {
            $this->service = new LoginService();
        }
        return $this->service;
    }

    /**
     * Des:登录处理
     * Name: actionDoLogin
     * @return string
     * @author 倪宗锋
     */

    public function actionIndex()
    {
        $fx_user=new FxUser();
        $phone=$fx_user->checkPhone();
        if($phone){
            return Util::returnJsSu('','需要注册','','FX-100001');
        }else{
            return Util::returnArrSu();
        }
    }
    /**
     * Function Description:发送短信
     * Function Name: actionSendMessage
     *
     *
     * @author 娄梦宁
     */
    public function actionSendMessage(){
        $phone=Yii::$app->request->post('phone');
        $result = $this->service()->sendMessage($phone);
        return json_encode($result);
    }

    /**
     * Function Description:注册验证码校验
     * Function Name: actionCheckCode
     *
     * @return string
     *
     * @author 娄梦宁
     */
    public function actionCheckCode(){
        $phone=Yii::$app->request->post('phone', '');
        $code=Yii::$app->request->post('code', '');
        $result=$this->service()->checkCode($phone,$code);
        return json_encode($result);
    }

    /**
     * Des:校验用户是否登录
     * Name: checkLogin
     * @return string
     * @author 倪宗锋
     */
    public function actionCheckLogin(){
        $return =  Util::returnArrSu();
        ob_clean();
        return json_encode($return);
    }
}