DataXw.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\data\model;
  3. use think\admin\Model;
  4. use think\db\Query;
  5. use think\helper\Str;
  6. /**
  7. * @method static|Query show()
  8. */
  9. class DataXw extends Model
  10. {
  11. protected $type=[
  12. 'has_video'=>'bool',
  13. ];
  14. public static function onBeforeWrite(self $model)
  15. {
  16. $model['has_video']=Str::contains($model['content'],'</video>');
  17. }
  18. public function comments()
  19. {
  20. return $this->hasMany(DataXwComment::class,'xw_id');
  21. }
  22. public function likes()
  23. {
  24. return $this->hasMany(DataXwLike::class,'xw_id');
  25. }
  26. public function category()
  27. {
  28. return $this->belongsTo(DataXwCategory::class,'category_id');
  29. }
  30. public function scopeShow(Query $query){
  31. $query->where('status',1);
  32. }
  33. public function getUserAttr(){
  34. static $config;
  35. is_null($config) && $config=sysconf('config_xw.')?:[];
  36. return [
  37. 'avatar'=>$config['user_avatar']??request()->domain().('/static/images/16.jpg'),
  38. 'username'=>$config['username']??'官方账号',
  39. ];
  40. }
  41. }