|
@@ -15,6 +15,7 @@ use App\Models\InterestCircleMessage;
|
|
use App\Models\InterestCircleMessageComment;
|
|
use App\Models\InterestCircleMessageComment;
|
|
use App\Models\InterestCircleMessageImg;
|
|
use App\Models\InterestCircleMessageImg;
|
|
use App\Models\InterestCircleMessageRecord;
|
|
use App\Models\InterestCircleMessageRecord;
|
|
|
|
+use App\Models\InterestCirclePicture;
|
|
use App\Models\InterestCircleUser;
|
|
use App\Models\InterestCircleUser;
|
|
use App\Models\Post;
|
|
use App\Models\Post;
|
|
use App\Service\DetectionService;
|
|
use App\Service\DetectionService;
|
|
@@ -33,6 +34,7 @@ class CircleMessageRepository
|
|
|
|
|
|
public function __construct(InterestCircle $interestCircle,
|
|
public function __construct(InterestCircle $interestCircle,
|
|
InterestCircleMessage $interestCircleMessage,
|
|
InterestCircleMessage $interestCircleMessage,
|
|
|
|
+ InterestCirclePicture $interestCirclePicture,
|
|
InterestCircleMessageImg $interestCircleMessageImg,
|
|
InterestCircleMessageImg $interestCircleMessageImg,
|
|
InterestCircleUser $interestCircleUser,
|
|
InterestCircleUser $interestCircleUser,
|
|
DetectionService $detectionService,
|
|
DetectionService $detectionService,
|
|
@@ -41,6 +43,7 @@ class CircleMessageRepository
|
|
{
|
|
{
|
|
$this->interestCircle = $interestCircle;
|
|
$this->interestCircle = $interestCircle;
|
|
$this->interestCircleMessage = $interestCircleMessage;
|
|
$this->interestCircleMessage = $interestCircleMessage;
|
|
|
|
+ $this->interestCirclePicture = $interestCirclePicture;
|
|
$this->interestCircleMessageImg = $interestCircleMessageImg;
|
|
$this->interestCircleMessageImg = $interestCircleMessageImg;
|
|
$this->interestCircleUser = $interestCircleUser;
|
|
$this->interestCircleUser = $interestCircleUser;
|
|
$this->interestCircleMessageComment = $interestCircleMessageComment;
|
|
$this->interestCircleMessageComment = $interestCircleMessageComment;
|
|
@@ -89,17 +92,22 @@ class CircleMessageRepository
|
|
if (!$userInfo['sns_status']) {
|
|
if (!$userInfo['sns_status']) {
|
|
return jsonError('您已被禁言');
|
|
return jsonError('您已被禁言');
|
|
}
|
|
}
|
|
- $isBlack = $this->interestCircleUser->where('circle_id', $request['circle_id'])
|
|
|
|
|
|
+ $circleUser = $this->interestCircleUser
|
|
|
|
+ ->where('circle_id', $request['circle_id'])
|
|
->where('uid', $userInfo['uid'])
|
|
->where('uid', $userInfo['uid'])
|
|
- ->where('is_black', 1)->exists();
|
|
|
|
- if ($isBlack) {
|
|
|
|
- return jsonError('当前状态无法提问,请联系管理员');
|
|
|
|
|
|
+ ->first();
|
|
|
|
+ if ($circleUser) {
|
|
|
|
+ if ($circleUser->is_black) {
|
|
|
|
+ return jsonError('您在本圈子内的权限受限');
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return jsonError('抱歉,加入圈子才能互动');
|
|
}
|
|
}
|
|
|
|
|
|
$oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString();
|
|
$oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString();
|
|
$oneHourPostCount = $this->interestCircleMessage->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
|
|
$oneHourPostCount = $this->interestCircleMessage->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
|
|
if ($oneHourPostCount > 5) {
|
|
if ($oneHourPostCount > 5) {
|
|
- return jsonError('创作欲望太强啦,休息一下,看看其他用户的提问吧!');
|
|
|
|
|
|
+ return jsonError('创作欲望太强啦,休息一下,看看其他用户的相册吧!');
|
|
}
|
|
}
|
|
|
|
|
|
$detectionText = strip_tags($request['content']);
|
|
$detectionText = strip_tags($request['content']);
|
|
@@ -112,15 +120,15 @@ class CircleMessageRepository
|
|
$imgs = json_decode($request['imgs'], true);
|
|
$imgs = json_decode($request['imgs'], true);
|
|
$imgCount = count($imgs);
|
|
$imgCount = count($imgs);
|
|
if ($imgCount > 3) {
|
|
if ($imgCount > 3) {
|
|
- return jsonError('最多上传3张图片');
|
|
|
|
|
|
+ return jsonError('最多上传3张');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ($imgs) {
|
|
if ($imgs) {
|
|
$allImg = $imgs;
|
|
$allImg = $imgs;
|
|
foreach ($allImg as &$img) {
|
|
foreach ($allImg as &$img) {
|
|
- if(Str::contains($img,'?')){
|
|
|
|
|
|
+ if (Str::contains($img, '?')) {
|
|
$img = $img . '&x-oss-process=image/resize,p_50/quality,Q_50';
|
|
$img = $img . '&x-oss-process=image/resize,p_50/quality,Q_50';
|
|
- }else{
|
|
|
|
|
|
+ } else {
|
|
$img = $img . '?x-oss-process=image/resize,p_50/quality,Q_50';
|
|
$img = $img . '?x-oss-process=image/resize,p_50/quality,Q_50';
|
|
}
|
|
}
|
|
|
|
|
|
@@ -190,11 +198,16 @@ class CircleMessageRepository
|
|
if (!$userInfo['sns_status']) {
|
|
if (!$userInfo['sns_status']) {
|
|
return jsonError('您已被禁言');
|
|
return jsonError('您已被禁言');
|
|
}
|
|
}
|
|
- $isBlack = $this->interestCircleUser->where('circle_id', $request['circle_id'])
|
|
|
|
|
|
+ $circleUser = $this->interestCircleUser
|
|
|
|
+ ->where('circle_id', $request['circle_id'])
|
|
->where('uid', $userInfo['uid'])
|
|
->where('uid', $userInfo['uid'])
|
|
- ->where('is_black', 1)->exists();
|
|
|
|
- if ($isBlack) {
|
|
|
|
- return jsonError('当前状态无法提问,请联系管理员');
|
|
|
|
|
|
+ ->first();
|
|
|
|
+ if ($circleUser) {
|
|
|
|
+ if ($circleUser->is_black) {
|
|
|
|
+ return jsonError('您在本圈子内的权限受限');
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return jsonError('抱歉,加入圈子才能互动');
|
|
}
|
|
}
|
|
$oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString();
|
|
$oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString();
|
|
$oneHourCommentCount = $this->interestCircleMessageComment->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
|
|
$oneHourCommentCount = $this->interestCircleMessageComment->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
|
|
@@ -315,13 +328,28 @@ class CircleMessageRepository
|
|
public function messageAction($request)
|
|
public function messageAction($request)
|
|
{
|
|
{
|
|
$userInfo = $this->getUserInfo();
|
|
$userInfo = $this->getUserInfo();
|
|
- $userInfo['sns_status'] = 1;
|
|
|
|
- $userInfo['uid'] = 268;
|
|
|
|
- $userInfo['username'] = '测试用户';
|
|
|
|
- $userInfo['avatar'] = '';
|
|
|
|
|
|
+// $userInfo['sns_status'] = 1;
|
|
|
|
+// $userInfo['uid'] = 268;
|
|
|
|
+// $userInfo['username'] = '测试用户';
|
|
|
|
+// $userInfo['avatar'] = '';
|
|
if (empty($userInfo)) {
|
|
if (empty($userInfo)) {
|
|
return jsonError('获取用户信息失败');
|
|
return jsonError('获取用户信息失败');
|
|
}
|
|
}
|
|
|
|
+ $messageInfo = $this->interestCircleMessage->find($request['msg_id']);
|
|
|
|
+ if (empty($messageInfo)) {
|
|
|
|
+ return jsonError('该提问不存在');
|
|
|
|
+ }
|
|
|
|
+ $circleUser = $this->interestCircleUser
|
|
|
|
+ ->where('circle_id', $messageInfo->circle_id)
|
|
|
|
+ ->where('uid', $userInfo['uid'])
|
|
|
|
+ ->first();
|
|
|
|
+ if ($circleUser) {
|
|
|
|
+ if ($circleUser->is_black) {
|
|
|
|
+ return jsonError('您在本圈子内的权限受限');
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return jsonError('抱歉,加入圈子才能互动');
|
|
|
|
+ }
|
|
$actionRow = InterestCircleMessageRecord::where([['msg_id', $request['msg_id']], ['uid', $userInfo['uid']]])->first();
|
|
$actionRow = InterestCircleMessageRecord::where([['msg_id', $request['msg_id']], ['uid', $userInfo['uid']]])->first();
|
|
if ($actionRow) {
|
|
if ($actionRow) {
|
|
return jsonSuccess();
|
|
return jsonSuccess();
|
|
@@ -424,4 +452,130 @@ class CircleMessageRepository
|
|
return jsonError('删除提问失败,请重试');
|
|
return jsonError('删除提问失败,请重试');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 创建相册
|
|
|
|
+ */
|
|
|
|
+ public function createPictures($request)
|
|
|
|
+ {
|
|
|
|
+ //验证小号
|
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
|
+// $userInfo['sns_status']=1;
|
|
|
|
+// $userInfo['uid']=268;
|
|
|
|
+ if (empty($userInfo)) {
|
|
|
|
+ return jsonError('获取用户信息失败');
|
|
|
|
+ }
|
|
|
|
+ if (!$userInfo['sns_status']) {
|
|
|
|
+ return jsonError('您已被禁言');
|
|
|
|
+ }
|
|
|
|
+ $circleUser = $this->interestCircleUser
|
|
|
|
+ ->where('circle_id', $request['circle_id'])
|
|
|
|
+ ->where('uid', $userInfo['uid'])
|
|
|
|
+ ->first();
|
|
|
|
+ if ($circleUser) {
|
|
|
|
+ if ($circleUser->is_black) {
|
|
|
|
+ return jsonError('您在本圈子内的权限受限');
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ return jsonError('抱歉,加入圈子才能互动');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString();
|
|
|
|
+ $oneHourPostCount = $this->interestCirclePicture->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
|
|
|
|
+ if ($oneHourPostCount > 5) {
|
|
|
|
+ return jsonError('创作欲望太强啦,休息一下,看看其他用户的提问吧!');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $imgs = json_decode($request['imgs'], true);
|
|
|
|
+ $imgCount = count($imgs);
|
|
|
|
+ if ($imgCount == 0 || $imgCount > 9) {
|
|
|
|
+ return jsonError('所传图集必须1-9个');
|
|
|
|
+ }
|
|
|
|
+ $allImg = $imgs;
|
|
|
|
+ foreach ($allImg as &$img) {
|
|
|
|
+ if (Str::contains($img, '?')) {
|
|
|
|
+ $img = $img . '&x-oss-process=image/resize,p_50/quality,Q_50';
|
|
|
|
+ } else {
|
|
|
|
+ $img = $img . '?x-oss-process=image/resize,p_50/quality,Q_50';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ $detectionImageResult = $this->detectionService->checkImg($allImg);
|
|
|
|
+ if ($detectionImageResult['code'] < 0) {
|
|
|
|
+ Log::debug('图片违规,请修正哦' . json_encode($detectionImageResult));
|
|
|
|
+ return jsonError('图片违规,请修正哦');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $date = date('Y-m-d H:i:s');
|
|
|
|
+ $patchNum = Str::uuid();
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ $imgData = [];
|
|
|
|
+ foreach ($imgs as $img) {
|
|
|
|
+ $imgData[] = [
|
|
|
|
+ 'circle_id' => $request['circle_id'],
|
|
|
|
+ 'uid' => $userInfo['uid'],
|
|
|
|
+ 'image' => $img,
|
|
|
|
+ 'patch_num' => $patchNum,
|
|
|
|
+ 'created_at' => $date,
|
|
|
|
+ 'updated_at' => $date
|
|
|
|
+ ];
|
|
|
|
+ }
|
|
|
|
+ $this->interestCirclePicture->insert($imgData);
|
|
|
|
+
|
|
|
|
+ $this->interestCircle->where('id', $request['circle_id'])->increment('picture_count', $imgCount);
|
|
|
|
+ DB::commit();
|
|
|
|
+ return jsonSuccess();
|
|
|
|
+ } catch (QueryException $exception) {
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ Log::debug('上传相册失败:' . $exception->getMessage());
|
|
|
|
+ return jsonError('上传失败');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 相册列表
|
|
|
|
+ */
|
|
|
|
+ public function pictureLists($request)
|
|
|
|
+ {
|
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
+ $where[] = ['circle_id', $request['circle_id']];
|
|
|
|
+
|
|
|
|
+ return $this->interestCirclePicture
|
|
|
|
+ ->where($where)
|
|
|
|
+ ->groupby('patch_num')
|
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
|
+ ->paginate($perPage);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 删除相册图片
|
|
|
|
+ */
|
|
|
|
+ public function deletePicture($request)
|
|
|
|
+ {
|
|
|
|
+ $circle = $this->interestCirclePicture->where('id', $request['id'])->first();
|
|
|
|
+ if (!$circle) {
|
|
|
|
+ return jsonError('相册不存在');
|
|
|
|
+ }
|
|
|
|
+ $userInfo = $this->getUserInfo();
|
|
|
|
+// $userInfo['sns_status']=1;
|
|
|
|
+// $userInfo['uid']=268;
|
|
|
|
+ if (empty($userInfo)) {
|
|
|
|
+ return jsonError('获取用户信息失败');
|
|
|
|
+ }
|
|
|
|
+ if ($userInfo['uid'] != $circle->uid) {
|
|
|
|
+ return jsonError('只能删除自己的相册');
|
|
|
|
+ }
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
+ try {
|
|
|
|
+ $circle->delete();
|
|
|
|
+ DB::commit();
|
|
|
|
+ return jsonSuccess();
|
|
|
|
+
|
|
|
|
+ } catch (QueryException $exception) {
|
|
|
|
+ DB::rollBack();
|
|
|
|
+ Log::debug('删除相册图片:' . $request['id'] . $exception->getMessage());
|
|
|
|
+ return jsonError('操作失败,请重试');
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|