12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace app\data\model;
- use think\admin\Model;
- use think\db\Query;
- use think\helper\Str;
- /**
- * @method static|Query show()
- */
- class DataXw extends Model
- {
- protected $type=[
- 'has_video'=>'bool',
- ];
- public static function onBeforeWrite(self $model)
- {
- $model['has_video']=Str::contains($model['content'],'</video>');
- }
- public function comments()
- {
- return $this->hasMany(DataXwComment::class,'xw_id');
- }
- public function likes()
- {
- return $this->hasMany(DataXwLike::class,'xw_id');
- }
- public function category()
- {
- return $this->belongsTo(DataXwCategory::class,'category_id');
- }
- public function scopeShow(Query $query){
- $query->where('status',1);
- }
- public function getUserAttr(){
- static $config;
- is_null($config) && $config=sysconf('config_xw.')?:[];
- return [
- 'avatar'=>$config['user_avatar']??request()->domain().('/static/images/16.jpg'),
- 'username'=>$config['username']??'官方账号',
- ];
- }
- }
|