74 lines
1.4 KiB
PHP
Raw Normal View History

2025-05-20 16:33:23 +08:00
<?php
namespace app\admin\model\home;
use think\Model;
use traits\model\SoftDelete;
class Images extends Model
{
use SoftDelete;
// 表名
protected $name = 'home_images';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = false;
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'type_text',
'showtype_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 getShowtypeList()
{
return ['image' => __('Showtype image'), 'video' => __('Showtype video')];
}
public function getTypeTextAttr($value, $data)
{
$value = $value ?: ($data['type'] ?? '');
$list = $this->getTypeList();
return $list[$value] ?? '';
}
public function getShowtypeTextAttr($value, $data)
{
$value = $value ?: ($data['showtype'] ?? '');
$list = $this->getShowtypeList();
return $list[$value] ?? '';
}
}