DiverseYouthNightSchool/application/admin/model/style/HomeImages.php

60 lines
1.1 KiB
PHP

<?php
namespace app\admin\model\style;
use think\Model;
use traits\model\SoftDelete;
class HomeImages extends Model
{
use SoftDelete;
// 表名
protected $name = 'school_home_images';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'type_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
if (!$row['weigh']) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
}
});
}
public function getTypeList()
{
return ['in' => __('Type in'), 'out' => __('Type out')];
}
public function getTypeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
$list = $this->getTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
}