TagArticle.php 956 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\model;
  4. use think\facade\Config;
  5. use think\facade\Db;
  6. use app\model\Base;
  7. use app\model\Article;
  8. class TagArticle extends Base
  9. {
  10. protected $pk = 'atid';
  11. protected $schema = [
  12. 'atid' => "int",
  13. "infoid" => "int",
  14. "cid" => "int",
  15. "tagid" => "int",
  16. ];
  17. protected $autoWriteTimestamp = false;
  18. public function article()
  19. {
  20. return $this->belongsTo('Article', 'infoid')->bind(['id','title','titlepic','summary','hits','create_time','username']);
  21. }
  22. public function category()
  23. {
  24. return $this->belongsTo('Category', 'cid')->bind(['category_url'=>'url','category_name'=>'name']);
  25. }
  26. public static function queryList($tagid)
  27. {
  28. $limit = (int) Config::get('app.page_size', 20);
  29. return self::with(['article','category'])->where('tagid', $tagid)->order('infoid DESC')->limit($limit)->paginate();
  30. }
  31. }