Dynamic.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\admin\model\dynamic;
  3. use think\Model;
  4. class Dynamic extends Model
  5. {
  6. // 表名
  7. protected $name = 'dynamic';
  8. // 自动写入时间戳字段
  9. protected $autoWriteTimestamp = 'int';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'res_type_text',
  17. 'is_online_text',
  18. 'is_recommend_text',
  19. 'status_text'
  20. ];
  21. public function getResTypeList()
  22. {
  23. return ['1' => __('Res_type 1'), '2' => __('Res_type 2'), '3' => __('Res_type 3')];
  24. }
  25. public function getIsOnlineList()
  26. {
  27. return ['-1' => __('Is_online -1'), '1' => __('Is_online 1')];
  28. }
  29. public function getIsRecommendList()
  30. {
  31. return ['0' => __('Is_recommend 0'), '1' => __('Is_recommend 1')];
  32. }
  33. public function getStatusList()
  34. {
  35. return ['-1' => __('Status -1'), '0' => __('Status 0'), '1' => __('Status 1')];
  36. }
  37. public function getResTypeTextAttr($value, $data)
  38. {
  39. $value = $value ? $value : (isset($data['res_type']) ? $data['res_type'] : '');
  40. $list = $this->getResTypeList();
  41. return isset($list[$value]) ? $list[$value] : '';
  42. }
  43. public function getIsOnlineTextAttr($value, $data)
  44. {
  45. $value = $value ? $value : (isset($data['is_online']) ? $data['is_online'] : '');
  46. $list = $this->getIsOnlineList();
  47. return isset($list[$value]) ? $list[$value] : '';
  48. }
  49. public function getIsRecommendTextAttr($value, $data)
  50. {
  51. $value = $value ? $value : (isset($data['is_recommend']) ? $data['is_recommend'] : '');
  52. $list = $this->getIsRecommendList();
  53. return isset($list[$value]) ? $list[$value] : '';
  54. }
  55. public function getStatusTextAttr($value, $data)
  56. {
  57. $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
  58. $list = $this->getStatusList();
  59. return isset($list[$value]) ? $list[$value] : '';
  60. }
  61. public function user()
  62. {
  63. return $this->belongsTo('app\admin\model\User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  64. }
  65. }