Usertrain.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Usertrain extends Model
  5. {
  6. // 表名
  7. protected $table = 'user_train';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'sign_time_text',
  17. 'status_text'
  18. ];
  19. public function getStatusList()
  20. {
  21. return ['1' => __('Status 1'), '2' => __('Status 2')];
  22. }
  23. public function getSignTimeTextAttr($value, $data)
  24. {
  25. $value = $value ? $value : (isset($data['sign_time']) ? $data['sign_time'] : '');
  26. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  27. }
  28. public function getStatusTextAttr($value, $data)
  29. {
  30. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  31. $list = $this->getStatusList();
  32. return isset($list[$value]) ? $list[$value] : '';
  33. }
  34. protected function setSignTimeAttr($value)
  35. {
  36. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  37. }
  38. public function active()
  39. {
  40. return $this->belongsTo('Trainactive', 'train_id', 'id', [], 'LEFT')->setEagerlyType(0);
  41. }
  42. public function user()
  43. {
  44. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  45. }
  46. }