1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace app\admin\model;
- use think\Model;
- class Videoplayuserplay extends Model
- {
-
-
- // 表名
- protected $name = 'video_play_userplay';
-
- // 自动写入时间戳字段
- protected $autoWriteTimestamp = 'int';
- // 定义时间戳字段名
- protected $createTime = 'createtime';
- protected $updateTime = 'updatetime';
- protected $deleteTime = false;
- // 追加属性
- protected $append = [
- 'start_time_text',
- 'end_time_text',
- 'istry_text'
- ];
-
-
- public function getIstryList()
- {
- return ['0' => __('Istry 0'), '1' => __('Istry 1')];
- }
- 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 getIstryTextAttr($value, $data)
- {
- $value = $value ? $value : (isset($data['istry']) ? $data['istry'] : '');
- $list = $this->getIstryList();
- return isset($list[$value]) ? $list[$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);
- }
- public function user()
- {
- return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- public function video()
- {
- return $this->belongsTo('Video', 'video_id', 'id', [], 'LEFT')->setEagerlyType(0);
- }
- }
|