Pcadmin.php 1.7 KB

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