Wentihuizong.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. class Wentihuizong extends Model
  5. {
  6. // 表名
  7. protected $table = 'wentihuizong';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = false;
  10. // 定义时间戳字段名
  11. protected $createTime = false;
  12. protected $updateTime = false;
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'findtime_text',
  17. 'finishtime_text',
  18. 'result_text'
  19. ];
  20. public function getResultList()
  21. {
  22. return ['1' => __('Result 1'), '2' => __('Result 2')];
  23. }
  24. public function getFindtimeTextAttr($value, $data)
  25. {
  26. $value = $value ? $value : (isset($data['findtime']) ? $data['findtime'] : '');
  27. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  28. }
  29. public function getFinishtimeTextAttr($value, $data)
  30. {
  31. $value = $value ? $value : (isset($data['finishtime']) ? $data['finishtime'] : '');
  32. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  33. }
  34. public function getResultTextAttr($value, $data)
  35. {
  36. $value = $value ? $value : (isset($data['result']) ? $data['result'] : '');
  37. $list = $this->getResultList();
  38. return isset($list[$value]) ? $list[$value] : '';
  39. }
  40. protected function setFindtimeAttr($value)
  41. {
  42. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  43. }
  44. protected function setFinishtimeAttr($value)
  45. {
  46. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  47. }
  48. public function company()
  49. {
  50. return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
  51. }
  52. public function usercompany()
  53. {
  54. return $this->belongsTo('Usercompany', 'uc_id', 'id', [], 'LEFT')->setEagerlyType(0);
  55. }
  56. }