NewsCategory.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace app\admin\model;
  3. use support\Db;
  4. use support\Model;
  5. /**
  6. * 文章分类
  7. * Class Users
  8. * @package app\admin\model
  9. */
  10. class NewsCategory extends Model
  11. {
  12. /**
  13. * The table associated with the model.
  14. *
  15. * @var string
  16. */
  17. protected $table = 'news_category';
  18. public $timestamps = false;
  19. /**
  20. * Notes:获取运费列表
  21. * @param string $keywords
  22. * @param int $page
  23. * @param int $limit
  24. * @return array
  25. * User: QJF
  26. * Date: 2022/9/28
  27. */
  28. public static function getCategory(int $page, int $limit,$keywords)
  29. {
  30. $list = static::select('*')
  31. ->when($keywords != '', function ($query) use ($keywords){
  32. $query->where('category_name', 'like', '%' . $keywords . '%');
  33. })
  34. ->orderBy('category_create_time','DESC')
  35. ->forPage($page, $limit)
  36. ->get();
  37. $count = static::when($keywords != '', function ($query) use ($keywords){
  38. $query->where('category_name', 'like', '%' . $keywords . '%');
  39. })->count();
  40. return [$list, $count];
  41. }
  42. public function getNewsCreateTimeAttribute($value)
  43. {
  44. return date('Y-m-d H:i:s', $value);
  45. }
  46. }