Dynamic.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 = 'integer';
  10. // 定义时间戳字段名
  11. protected $createTime = 'createtime';
  12. protected $updateTime = 'updatetime';
  13. protected $deleteTime = false;
  14. // 追加属性
  15. protected $append = [
  16. 'type_text',
  17. 'status_text'
  18. ];
  19. public function getTypeList()
  20. {
  21. return ['image' => __('Image'), 'video' => __('Video')];
  22. }
  23. public function getStatusList()
  24. {
  25. return ['checking' => __('Checking'), 'normal' => __('Normal'), 'reject' => __('Reject')];
  26. }
  27. public function getTypeTextAttr($value, $data)
  28. {
  29. $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
  30. $list = $this->getTypeList();
  31. return isset($list[$value]) ? $list[$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 massager()
  40. {
  41. return $this->belongsTo('app\admin\model\Massager', 'massager_id', 'id', [], 'LEFT')
  42. ->setEagerlyType(0);
  43. }
  44. public function topic()
  45. {
  46. return $this->belongsTo('Topic', 'topic_id', 'id', [], 'LEFT')->setEagerlyType(0);
  47. }
  48. public function comments()
  49. {
  50. return $this->hasMany(Comment::class, 'dynamic_id', "id")->where("ma_dynamic_comment.status", \E_BASE_STATUS::Normal);
  51. }
  52. public function likes()
  53. {
  54. return $this->hasMany(Like::class, 'dynamic_id', "id");
  55. }
  56. }