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

77 lines
1.6 KiB
PHP

<?php
namespace app\common\model\style;
use app\common\model\BaseModel;
use think\Model;
use traits\model\SoftDelete;
class HomeImages extends BaseModel
{
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] : '';
}
public function getImageAttr($value, $data)
{
if (!empty($value)) return cdnurl($value, true);
}
public static function allList($page, $limit,$params=[]){
$sort = "weigh desc,id desc";
// if(!empty($params['status'])){
// $params['status'] = '1';
// }
return (new self)->getBaseList($params, $page, $limit,$sort);
}
}