CleanUser.php 1.4 KB
<?php

namespace app\admin\model\hotel;

use think\Model;


class CleanUser extends Model
{

    

    

    // 表名
    protected $name = 'clean_user';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'sex_data_text',
        'birthday_time_text'
    ];
    

    
    public function getSexDataList()
    {
        return ['1' => __('Sex_data 1'), '2' => __('Sex_data 2')];
    }


    public function getSexDataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['sex_data']) ? $data['sex_data'] : '');
        $list = $this->getSexDataList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBirthdayTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['birthday_time']) ? $data['birthday_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setBirthdayTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }

    public function shop()
    {
        return $this->belongsTo('\app\admin\model\hotel\Hotel', 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}