<?php

namespace app\mobile\controller;

use app\admin\logic\CommonLogic;
use app\BaseController;
use app\mobile\logic\AccountLogic;
use think\exception\ValidateException;
use think\facade\Config;
use think\facade\Validate;

//账户
class Account extends BaseController
{

    //登录
    public function login()
    {
        $param = $this->request->only(['username', 'password'], 'post');

        $val = Validate::rule(Config::get('validate_rules.login'));

        if (!$val->check($param)) throw new ValidateException($val->getError());

        return AccountLogic::login($param);
    }

    //登出
    public function logout()
    {
        return AccountLogic::logout();
    }

    //详情
    public function info()
    {
        return AccountLogic::info();
    }

    //更改密码
    public function updatePassword(){
        $param = $this->request->only(['old_password', 'new_password'], 'post');

        $val = Validate::rule(Config::get('validate_rules.changePassword'));

        if (!$val->check($param)) throw new ValidateException($val->getError());

        return AccountLogic::updatePassword($param);
    }

    //省市区编码
    public function area()
    {
        $parent_code = $this->request->post('parent_code', '');
        return CommonLogic::getAddr($parent_code);
    }

    //视频列表
    public function getVideoList()
    {
        $param = $this->request->only(['page' => 1, 'size' => 10], 'post');
        return AccountLogic::getVideoList($param);
    }

    //手机主题
    public function theme()
    {
        return AccountLogic::theme();
    }

}