Style.php 1.5 KB
<?php

namespace app\admin\model;

use think\Model;


class Style extends Model
{

    

    

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

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

    // 追加属性
    protected $append = [
        'style_type_text',
        'display_mode_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getStyleTypeList()
    {
        return ['1' => __('Style_type 1'), '2' => __('Style_type 2'), '3' => __('Style_type 3')];
    }

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


    public function getStyleTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['style_type']) ? $data['style_type'] : '');
        $list = $this->getStyleTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDisplayModeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['display_mode']) ? $data['display_mode'] : '');
        $list = $this->getDisplayModeList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}