Jiance.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use traits\model\SoftDelete;
  5. class Jiance extends Model
  6. {
  7. use SoftDelete;
  8. // 表名
  9. protected $table = 'jiance';
  10. // 自动写入时间戳字段
  11. protected $autoWriteTimestamp = false;
  12. // 定义时间戳字段名
  13. protected $createTime = false;
  14. protected $updateTime = false;
  15. protected $deleteTime = 'deletetime';
  16. // 追加属性
  17. protected $append = [
  18. 'status_text',
  19. 'tongjitime_text'
  20. ];
  21. public function getStatusList()
  22. {
  23. return ['0' => __('Status 0'), '1' => __('Status 1')];
  24. }
  25. public function getStatusTextAttr($value, $data)
  26. {
  27. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  28. $list = $this->getStatusList();
  29. return isset($list[$value]) ? $list[$value] : '';
  30. }
  31. public function getTongjitimeTextAttr($value, $data)
  32. {
  33. $value = $value ? $value : (isset($data['tongjitime']) ? $data['tongjitime'] : '');
  34. return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
  35. }
  36. protected function setTongjitimeAttr($value)
  37. {
  38. return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
  39. }
  40. public function company()
  41. {
  42. return $this->belongsTo('Company', 'company_id', 'id', [], 'LEFT')->setEagerlyType(0);
  43. }
  44. public function usercompany()
  45. {
  46. return $this->belongsTo('Usercompany', 'uc_id', 'id', [], 'LEFT')->setEagerlyType(0);
  47. }
  48. public function worker()
  49. {
  50. return $this->belongsTo('Worker', 'worker_id', 'id', [], 'LEFT')->setEagerlyType(0);
  51. }
  52. }