DiverseYouthNightSchool/application/manystore/model/school/classes/hourorder/Order.php

141 lines
3.9 KiB
PHP

<?php
namespace app\manystore\model\school\classes\hourorder;
use think\Model;
use traits\model\SoftDelete;
class Order extends Model
{
use SoftDelete;
// 表名
protected $name = 'school_classes_hour_order';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = 'deletetime';
// 追加属性
protected $append = [
'start_time_text',
'end_time_text',
'status_text',
'reservation_time_text',
'finish_time_text',
'cancel_time_text'
];
public function getStatusList()
{
return ['-3' => __('Status -3'), '0' => __('Status 0'), '3' => __('Status 3')];
}
public function getStartTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getEndTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['end_time']) ? $data['end_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 getReservationTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['reservation_time']) ? $data['reservation_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getFinishTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['finish_time']) ? $data['finish_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getCancelTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['cancel_time']) ? $data['cancel_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setStartTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setEndTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setReservationTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setFinishTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setCancelTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
public function schoolclassesorder()
{
return $this->belongsTo('app\manystore\model\SchoolClassesOrder', 'classes_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function schoolclasseslibspec()
{
return $this->belongsTo('app\manystore\model\SchoolClassesLibSpec', 'classes_lib_spec_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function user()
{
return $this->belongsTo('app\manystore\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function schoolclassesorderdetail()
{
return $this->belongsTo('app\manystore\model\SchoolClassesOrderDetail', 'classes_order_detail_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function schoolclasseslib()
{
return $this->belongsTo('app\manystore\model\SchoolClassesLib', 'classes_lib_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}