DiverseYouthNightSchool/application/manystore/model/school/classes/Evaluate.php

119 lines
2.9 KiB
PHP
Raw Normal View History

2024-12-11 19:03:47 +08:00
<?php
namespace app\manystore\model\school\classes;
use app\common\model\dyqc\ManystoreShop;
use app\manystore\model\Manystore;
use think\Model;
class Evaluate extends Model
{
// 表名
protected $name = 'school_classes_evaluate';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'evaluate_time_text',
'status_text',
'top_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getTopList()
{
return ['0' => __('Top 0'), '1' => __('Top 1')];
}
public function getEvaluateTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['evaluate_time']) ? $data['evaluate_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getTopTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['top']) ? $data['top'] : '');
$list = $this->getTopList();
return isset($list[$value]) ? $list[$value] : '';
}
protected function setEvaluateTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
public function user()
{
return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function schoolclasseslib()
{
return $this->belongsTo(ClassesLib::class, 'classes_lib_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function schoolclassesorder()
{
return $this->belongsTo(\app\common\model\school\classes\order\Order::class, 'classes_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function manystore()
{
return $this->belongsTo(Manystore::class, 'manystore_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function manystoreshop()
{
return $this->belongsTo(ManystoreShop::class, 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function schoolteacher()
{
return $this->belongsTo(Teacher::class, 'teacher_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}