<?php
/**
 * Created by PhpStorm.
 * User: 中闽 < 1464674022@qq.com >
 * Date: 2020/2/4
 * Time: 12:47
 */

namespace app\common\model;

use think\Model;

class User extends Model
{
    protected $autoWriteTimestamp = false;

    const TYPE_ACCOUNT = 0;
    const TYPE_WECHAT = 1;
    const TYPE_QQ = 2;
    const TYPE_PHONE = 3;
    const TYPE_EMAIL = 4;

    const USER_TYPES = [
        self::TYPE_ACCOUNT => '账号密码',
        self::TYPE_WECHAT => '微信',
        self::TYPE_QQ => 'QQ',
        self::TYPE_PHONE => '手机号',
        self::TYPE_EMAIL => '邮箱',
    ];

    const CATE_USER = 0;
    const CATE_AGENT = 1;
    const CATE_MANAGE = 2;

    const USER_CATES = [
        self::CATE_USER => '用户',
        self::CATE_MANAGE => '管理',
    ];

    const STATUS_WAIT = 0;
    const STATUS_PASS = 1;
    const STATUS_UNPASS = -1;

    const STATUS = [
        self::STATUS_WAIT => '待激活',
        self::STATUS_PASS => '已激活',
        self::STATUS_UNPASS => '已被封'
    ];


    const SEX_UNKNOW = 0;
    const SEX_MAN = 1;
    const SEX_WOMAN = 2;

    const SEXS = [
        self::SEX_UNKNOW => '未知',
        self::SEX_MAN => '男',
        self::SEX_WOMAN => '女'
    ];

    //sex_text
    public function getSexTextAttr($value, $data)
    {
        return self::SEXS[$data['sex']]??'';
    }


    //nickname
    public function getNicknameAttr($value, $data)
    {
        return htmlspecialchars($value);
    }


    //status_text
    public function getStatusTextAttr($value, $data)
    {
        return self::STATUS[$data['status']]??'';
    }


    //register_time
    public function getRegisterTimeAttr($value, $data)
    {
        return $value ? date('Y-m-d H:i:s', $value) : '';
    }

    //login_time
    public function getLoginTimeAttr($value, $data)
    {
        return $value ? date('Y-m-d H:i:s', $value) : '';
    }

    //user_type_text 账号类型
    public function getUserTypeTextAttr($value, $data)
    {
        return self::USER_TYPES[$data['user_type']]??"";
    }

    //user_cate_text 用户角色
    public function getUserCateTextAttr($value, $data)
    {
        return self::USER_CATES[$data['user_cate']]??"";
    }
}
