ArticleService.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\extra\service\blue;
  3. use app\extra\basic\Service;
  4. use app\model\blue\BlueArticle;
  5. use app\model\blue\BlueCategory;
  6. class ArticleService extends Service
  7. {
  8. /**
  9. * 列表
  10. * @param array $param
  11. */
  12. public function getList(array $param = [])
  13. {
  14. $this->mode = new BlueArticle();
  15. return $this->searchVal($param,$this->searchFilter($param))->with(['categoryJoin' => function($query){
  16. $query->field("id,name");
  17. }])->paginate([
  18. "list_rows" => $param['pageSize'],
  19. "page" => $param['page']
  20. ]);
  21. }
  22. /**
  23. * 列表
  24. * @param array $param
  25. */
  26. public function getSchoolList(array $param = [])
  27. {
  28. $this->mode = new BlueArticle();
  29. return $this->searchVal($param,$this->searchFilter($param))->with(['categoryJoin' => function($query){
  30. $query->field("id,name");
  31. }])->field("id,title,category,view,zan,author,source,comment,cover")->paginate([
  32. "list_rows" => $param['pageSize'],
  33. "page" => $param['page']
  34. ]);
  35. }
  36. /**
  37. *
  38. * @param array $param
  39. * @return array
  40. */
  41. public function searchFilter(array $param = []): array
  42. {
  43. $filter = [];
  44. !empty($param['type']) && $filter[] = ["type", '=', $param['type']];
  45. !empty($param['status']) && $filter[] = ["status", '=', $param['status']];
  46. !empty($param['name']) && $filter[] = ["name", 'like', "%{$param['name']}%"];
  47. return $filter;
  48. }
  49. }