CircleArticleRepository.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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\InterestCircleArticle;
  10. use Illuminate\Database\QueryException;
  11. use Dingo\Api\Http\Response;
  12. use Illuminate\Support\Carbon;
  13. use Illuminate\Support\Facades\DB;
  14. use Illuminate\Support\Facades\Log;
  15. use Illuminate\Support\Facades\Redis;
  16. class CircleArticleRepository
  17. {
  18. public function __construct(InterestCircleArticle $interestCircleArticle)
  19. {
  20. $this->interestCircleArticle = $interestCircleArticle;
  21. }
  22. /**
  23. * 内容列表
  24. */
  25. public function lists($request)
  26. {
  27. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  28. $where = [];
  29. if (isset($request['uid'])) {
  30. $where[] = ['uid', $request['uid']];
  31. }
  32. $articleModel = $this->interestCircleArticle;
  33. return $articleModel
  34. ->join('post', 'post.id', '=', 'post_id')
  35. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  36. ->with('data')
  37. ->select('post.*')
  38. ->where($where)
  39. ->where(function ($query) use ($request) {
  40. if (isset($request['content'])) {
  41. $query->where('title', 'like', "%{$request['content']}%")
  42. ->orWhere('content', 'like', "%{$request['content']}%");
  43. }
  44. })
  45. ->where(function ($query) use ($request) {
  46. if (isset($request['created_at'])) {
  47. $time = explode('_', $request['created_at']);
  48. $query->whereBetween('post.created_at', $time);
  49. }
  50. })
  51. ->orderBy('is_recommend', 'desc')
  52. ->paginate($perPage);
  53. }
  54. }