1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/5
- * Time: 16:03
- */
- namespace App\Repositories\Circle;
- use App\Models\InterestCircle;
- use App\Models\InterestCircleArticle;
- use App\Models\InterestCircleUser;
- use App\Models\Post;
- 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 CircleMemberRepository
- {
- public function __construct(InterestCircle $interestCircle,InterestCircleUser $interestCircleUser)
- {
- $this->interestCircleUser = $interestCircleUser;
- $this->interestCircle = $interestCircle;
- }
- /**
- * 用户列表
- */
- public function lists($request)
- {
- $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
- $where = [];
- if (isset($request['uid'])) {
- $where[] = ['uid', $request['uid']];
- }
- if (isset($request['user_type'])) {
- $where[] = ['is_black', $request['user_type']];
- }
- if (isset($request['circle_id'])) {
- $where[] = ['circle_id', $request['circle_id']];
- }
- $userModel = $this->interestCircleUser;
- return $userModel
- ->where($where)
- ->orderBy('created_at', 'desc')
- ->paginate($perPage);
- }
- /**
- * 设置该用户为当前圈子黑名单
- */
- public function setUserBlack($request)
- {
- $article = $this->interestCircleUser
- ->where('uid', $request['uid'])
- ->where('circle_id', $request['circle_id'])
- ->first();
- if (!$article) {
- return Response::create([
- 'message' => '当前用户不在该圈子',
- 'status_code' => 500
- ]);
- }
- if ($article->is_black == 1) {
- $article->is_black = 0;
- } else {
- $article->is_black = 1;
- }
- DB::beginTransaction();
- try {
- $article->save();
- DB::commit();
- return Response::create();
- } catch (QueryException $exception) {
- DB::rollBack();
- Log::debug('设置圈子黑名单:' . $request['uid'] . '-' . $request['circle_id'] . $exception->getMessage());
- return Response::create([
- 'message' => '操作失败,请重试',
- 'error' => $exception->getMessage(),
- 'status_code' => 500
- ]);
- }
- }
- }
|