<?php

namespace app\admin\model;

use think\Model;


class CircleGroup extends Model
{

    

    

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

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

    // 追加属性
    protected $append = [
        'circle_type_list_text',
        'circle_state_text',
        'circle_open_state_text'
    ];
    

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

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

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

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


    public function getCircleTypeListTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['circle_type_list']) ? $data['circle_type_list'] : '');
        $list = $this->getCircleTypeListList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCircleStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['circle_state']) ? $data['circle_state'] : '');
        $list = $this->getCircleStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCircleOpenStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['circle_open_state']) ? $data['circle_open_state'] : '');
        $list = $this->getCircleOpenStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
