141 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			141 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace app\admin\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 = 'integer';
 | 
						|
 | 
						|
    // 定义时间戳字段名
 | 
						|
    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'),'-1' => __('Status -1'), '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 classesorder()
 | 
						|
    {
 | 
						|
        return $this->belongsTo('app\admin\model\school\classes\Order', 'classes_order_id', 'id', [], 'LEFT')->setEagerlyType(0);
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    public function spec()
 | 
						|
    {
 | 
						|
        return $this->belongsTo('app\admin\model\school\classes\lib\Spec', 'classes_lib_spec_id', 'id', [], 'LEFT')->setEagerlyType(0);
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    public function user()
 | 
						|
    {
 | 
						|
        return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    public function detail()
 | 
						|
    {
 | 
						|
        return $this->belongsTo('app\admin\model\school\classes\order\Detail', 'classes_order_detail_id', 'id', [], 'LEFT')->setEagerlyType(0);
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
    public function lib()
 | 
						|
    {
 | 
						|
        return $this->belongsTo('app\admin\model\school\classes\Lib', 'classes_lib_id', 'id', [], 'LEFT')->setEagerlyType(0);
 | 
						|
    }
 | 
						|
}
 |