Userdongtai.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace app\admin\model;
  3. use think\Model;
  4. use think\Db;
  5. class Userdongtai extends Model
  6. {
  7. // 表名
  8. protected $name = 'user_dongtai';
  9. // 自动写入时间戳字段
  10. protected $autoWriteTimestamp = 'int';
  11. // 定义时间戳字段名
  12. protected $createTime = 'createtime';
  13. protected $updateTime = 'updatetime';
  14. protected $deleteTime = false;
  15. // 追加属性
  16. protected $append = [
  17. 'is_hidden_text'
  18. ];
  19. protected static function init()
  20. {
  21. self::afterDelete(function ($row){
  22. //删除点赞,评论
  23. Db::name('user_dongtai_answer')->where('dt_id',$row['id'])->delete();
  24. Db::name('user_dongtai_good')->where('dt_id',$row['id'])->delete();
  25. });
  26. }
  27. public function getIsHiddenList()
  28. {
  29. return ['1' => __('Is_hidden 1'), '0' => __('Is_hidden 0')];
  30. }
  31. public function getIsHiddenTextAttr($value, $data)
  32. {
  33. $value = $value ? $value : (isset($data['is_hidden']) ? $data['is_hidden'] : '');
  34. $list = $this->getIsHiddenList();
  35. return isset($list[$value]) ? $list[$value] : '';
  36. }
  37. public function user()
  38. {
  39. return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
  40. }
  41. }