|
@@ -10,6 +10,7 @@
|
|
|
namespace App\Repositories\Circle;
|
|
|
|
|
|
use App\Models\InterestCircleArticle;
|
|
|
+use App\Models\Post;
|
|
|
use Illuminate\Database\QueryException;
|
|
|
use Dingo\Api\Http\Response;
|
|
|
use Illuminate\Support\Carbon;
|
|
@@ -20,9 +21,10 @@ use Illuminate\Support\Facades\Redis;
|
|
|
class CircleArticleRepository
|
|
|
{
|
|
|
|
|
|
- public function __construct(InterestCircleArticle $interestCircleArticle)
|
|
|
+ public function __construct(InterestCircleArticle $interestCircleArticle, Post $post)
|
|
|
{
|
|
|
$this->interestCircleArticle = $interestCircleArticle;
|
|
|
+ $this->post = $post;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -37,13 +39,13 @@ class CircleArticleRepository
|
|
|
$where[] = ['uid', $request['uid']];
|
|
|
}
|
|
|
|
|
|
- $articleModel = $this->interestCircleArticle;
|
|
|
+ $articleModel = $this->post;
|
|
|
|
|
|
return $articleModel
|
|
|
- ->join('post', 'post.id', '=', 'post_id')
|
|
|
->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
+ ->join('interest_circle_articles', 'interest_circle_articles.post_id', '=', 'post.id')
|
|
|
+ ->select('post.*', 'interest_circle_articles.is_recommend', 'interest_circle_articles.circle_id')
|
|
|
->with('data')
|
|
|
- ->select('post.*')
|
|
|
->where($where)
|
|
|
->where(function ($query) use ($request) {
|
|
|
if (isset($request['content'])) {
|
|
@@ -60,4 +62,82 @@ class CircleArticleRepository
|
|
|
->orderBy('is_recommend', 'desc')
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推荐精品文章
|
|
|
+ */
|
|
|
+ public function articleRecommend($request)
|
|
|
+ {
|
|
|
+ $article = $this->interestCircleArticle
|
|
|
+ ->where('post_id', $request['post_id'])
|
|
|
+ ->where('circle_id', $request['circle_id'])
|
|
|
+ ->first();
|
|
|
+ if (!$article) {
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取精品文章信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($article->is_recommend == 1) {
|
|
|
+ $article->is_recommend = 0;
|
|
|
+ } else {
|
|
|
+ $article->is_recommend = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $article->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ } catch (QueryException $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('推荐精品文章:' . $request['post_id'] . '-' . $request['circle_id'] . $exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 精品文章从当前圈子移出
|
|
|
+ */
|
|
|
+ public function articleRemove($request)
|
|
|
+ {
|
|
|
+ $article = $this->interestCircleArticle
|
|
|
+ ->where('post_id', $request['post_id'])
|
|
|
+ ->where('circle_id', $request['circle_id'])
|
|
|
+ ->first();
|
|
|
+ if (!$article) {
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取精品文章信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try {
|
|
|
+ $article->delete();
|
|
|
+ $isRef = $this->interestCircleArticle->where('post_id', $request['post_id'])->exists();
|
|
|
+ if (!$isRef) {
|
|
|
+ //todo 移出后需要检测该帖子在其他圈子有没有设为精品,如没有,则删除该帖子的精品标识
|
|
|
+ //$this->post->where('id',$request['post_id'])->update();
|
|
|
+ }
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ } catch (QueryException $exception) {
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('移出精品文章:' . $request['post_id'] . '-' . $request['circle_id'] . $exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|