248 lines
6.9 KiB
PHP
Raw Normal View History

2025-03-24 09:40:45 +08:00
<?php
2025-04-03 17:58:16 +08:00
namespace app\admin\model\school\activity;
2025-03-24 09:40:45 +08:00
use think\Model;
use traits\model\SoftDelete;
2025-04-03 17:58:16 +08:00
class Activity extends Model
2025-03-24 09:40:45 +08:00
{
use SoftDelete;
// 表名
2025-04-03 17:58:16 +08:00
protected $name = 'school_activity';
2025-03-24 09:40:45 +08:00
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'integer';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
2025-04-03 17:58:16 +08:00
'start_time_text',
'end_time_text',
'sign_start_time_text',
'sign_end_time_text',
2025-03-24 09:40:45 +08:00
'status_text',
2025-04-03 17:58:16 +08:00
'cancel_type_text',
2025-03-24 09:40:45 +08:00
'recommend_text',
'hot_text',
'new_text',
2025-04-03 17:58:16 +08:00
'add_type_text',
'feel_text',
'auth_status_text',
'auth_time_text',
'canceltime_text'
2025-03-24 09:40:45 +08:00
];
public function getCateList(){
return \app\admin\model\school\activity\Cate::column("name", 'id');
}
2025-03-24 09:40:45 +08:00
protected static function init()
{
self::afterInsert(function ($row) {
if (!$row['weigh']) {
$pk = $row->getPk();
2025-04-03 17:58:16 +08:00
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
2025-03-24 09:40:45 +08:00
}
});
}
2025-04-03 17:58:16 +08:00
public function getStatusList()
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return ['1' => __('Status 1'), '2' => __('Status 2'), '3' => __('Status 3'), '4' => __('Status 4'), '5' => __('Status 5'), '-1' => __('Status -1')];
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getCancelTypeList()
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return ['1' => __('Cancel_type 1'), '2' => __('Cancel_type 2')];
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getRecommendList()
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return ['0' => __('Recommend 0'), '1' => __('Recommend 1')];
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getHotList()
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return ['0' => __('Hot 0'), '1' => __('Hot 1')];
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getNewList()
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return ['0' => __('New 0'), '1' => __('New 1')];
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getAddTypeList()
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return ['1' => __('Add_type 1'), '2' => __('Add_type 2')];
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getFeelList()
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return ['0' => __('Feel 0'), '1' => __('Feel 1')];
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getAuthStatusList()
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return ['0' => __('Auth_status 0'), '1' => __('Auth_status 1'), '2' => __('Auth_status 2')];
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getStartTimeTextAttr($value, $data)
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
$value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getEndTimeTextAttr($value, $data)
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
$value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getSignStartTimeTextAttr($value, $data)
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
$value = $value ? $value : (isset($data['sign_start_time']) ? $data['sign_start_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
public function getSignEndTimeTextAttr($value, $data)
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
$value = $value ? $value : (isset($data['sign_end_time']) ? $data['sign_end_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
2025-03-24 09:40:45 +08:00
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
2025-04-03 17:58:16 +08:00
public function getCancelTypeTextAttr($value, $data)
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
$value = $value ? $value : (isset($data['cancel_type']) ? $data['cancel_type'] : '');
$list = $this->getCancelTypeList();
2025-03-24 09:40:45 +08:00
return isset($list[$value]) ? $list[$value] : '';
}
public function getRecommendTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['recommend']) ? $data['recommend'] : '');
$list = $this->getRecommendList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getHotTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['hot']) ? $data['hot'] : '');
$list = $this->getHotList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getNewTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['new']) ? $data['new'] : '');
$list = $this->getNewList();
return isset($list[$value]) ? $list[$value] : '';
}
2025-04-03 17:58:16 +08:00
public function getAddTypeTextAttr($value, $data)
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
$value = $value ? $value : (isset($data['add_type']) ? $data['add_type'] : '');
$list = $this->getAddTypeList();
2025-03-24 09:40:45 +08:00
return isset($list[$value]) ? $list[$value] : '';
}
2025-04-03 17:58:16 +08:00
public function getFeelTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['feel']) ? $data['feel'] : '');
$list = $this->getFeelList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getAuthStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['auth_status']) ? $data['auth_status'] : '');
$list = $this->getAuthStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getAuthTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['auth_time']) ? $data['auth_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getCanceltimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['canceltime']) ? $data['canceltime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setStartTimeAttr($value)
2025-03-24 09:40:45 +08:00
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
2025-04-03 17:58:16 +08:00
protected function setEndTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setSignStartTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
2025-03-24 09:40:45 +08:00
2025-04-03 17:58:16 +08:00
protected function setSignEndTimeAttr($value)
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
2025-03-24 09:40:45 +08:00
}
2025-04-03 17:58:16 +08:00
protected function setAuthTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
2025-03-24 09:40:45 +08:00
2025-04-03 17:58:16 +08:00
protected function setCanceltimeAttr($value)
2025-03-24 09:40:45 +08:00
{
2025-04-03 17:58:16 +08:00
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
2025-03-24 09:40:45 +08:00
}
public function user()
{
return $this->belongsTo('app\common\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
2025-03-24 09:40:45 +08:00
}
public function admin()
{
return $this->belongsTo('app\admin\model\Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}