123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/5
- * Time: 16:03
- */
- namespace App\Repositories\Circle;
- use App\Models\InterestCircleArticle;
- use Illuminate\Database\QueryException;
- use Dingo\Api\Http\Response;
- use Illuminate\Support\Carbon;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class CircleArticleRepository
- {
- public function __construct(InterestCircleArticle $interestCircleArticle)
- {
- $this->interestCircleArticle = $interestCircleArticle;
- }
- /**
- * 内容列表
- */
- public function lists($request)
- {
- $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
- $where = [];
- if (isset($request['uid'])) {
- $where[] = ['uid', $request['uid']];
- }
- $articleModel = $this->interestCircleArticle;
- return $articleModel
- ->join('post', 'post.id', '=', 'post_id')
- ->join('post_data', 'post_data.post_id', '=', 'post.id')
- ->with('data')
- ->select('post.*')
- ->where($where)
- ->where(function ($query) use ($request) {
- if (isset($request['content'])) {
- $query->where('title', 'like', "%{$request['content']}%")
- ->orWhere('content', 'like', "%{$request['content']}%");
- }
- })
- ->where(function ($query) use ($request) {
- if (isset($request['created_at'])) {
- $time = explode('_', $request['created_at']);
- $query->whereBetween('post.created_at', $time);
- }
- })
- ->orderBy('is_recommend', 'desc')
- ->paginate($perPage);
- }
- }
|