CategoryRepository.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019-06-15
  6. * Time: 11:16
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Category;
  10. use App\Models\CategoryTopic;
  11. class CategoryRepository {
  12. public function __construct(Category $category,CategoryTopic $categoryTopic) {
  13. $this->category = $category;
  14. $this->categoryTopic = $categoryTopic;
  15. }
  16. //列表
  17. public function lists($request)
  18. {
  19. $where = [];
  20. if(isset($request['is_suggest'])){
  21. $where[] = ['is_suggest', '=', $request['is_suggest']];
  22. }
  23. return $this->category->where($where)->get();
  24. }
  25. //获取多个话题
  26. public function getTopics($ids){
  27. $ids = explode(',',$ids);
  28. return $this->categoryTopic
  29. ->leftJoin('topic', 'category_topic.topic_id', '=', 'topic.id')
  30. ->where('topic.is_suggest',1)
  31. ->whereIn('category_topic.category_id',$ids)
  32. ->select('topic.id','topic.name','topic.is_suggest')
  33. ->get();
  34. }
  35. }