CircleArticleRepository.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/5
  6. * Time: 16:03
  7. */
  8. namespace App\Repositories\Circle;
  9. use App\Models\InterestCircle;
  10. use App\Models\InterestCircleArticle;
  11. use App\Models\InterestCircleUser;
  12. use App\Models\Post;
  13. use Illuminate\Database\QueryException;
  14. use Dingo\Api\Http\Response;
  15. use Illuminate\Support\Carbon;
  16. use Illuminate\Support\Facades\DB;
  17. use Illuminate\Support\Facades\Log;
  18. use Illuminate\Support\Facades\Redis;
  19. class CircleArticleRepository
  20. {
  21. public function __construct(InterestCircle $interestCircle,
  22. InterestCircleArticle $interestCircleArticle,
  23. Post $post)
  24. {
  25. $this->interestCircle = $interestCircle;
  26. $this->interestCircleArticle = $interestCircleArticle;
  27. $this->post = $post;
  28. }
  29. /**
  30. * 内容列表
  31. */
  32. public function lists($request)
  33. {
  34. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  35. $where[] = ['interest_circle_articles.circle_id', $request['id']];
  36. $articleModel = $this->post;
  37. return $articleModel
  38. ->join('interest_circle_articles', 'interest_circle_articles.post_id', '=', 'post.id')
  39. ->select('post.*', 'interest_circle_articles.is_recommend', 'interest_circle_articles.circle_id')
  40. ->where($where)
  41. ->orderBy('interest_circle_articles.is_recommend', 'desc')
  42. ->orderBy('post.weight', 'desc')
  43. ->paginate($perPage);
  44. }
  45. }