1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 12:23:06 +08:00

Merge branch 'koogua/v1.4.5' into demo

This commit is contained in:
koogua 2021-10-04 18:56:19 +08:00
commit bfd8b7b306
11 changed files with 184 additions and 3 deletions

View File

@ -6,6 +6,7 @@
- 调整订单发货为每一分钟执行一次
- 增强课时安全性,无权限时不返回播放地址或内容
- 抽离出文章关闭,仅我可见操作
- 增加退出群组和解除好友接口
- 增加删除文章和提问接口
- 增加首页推荐教师接口
- 增加微信公众号支付处理

View File

@ -0,0 +1,30 @@
<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Http\Api\Controllers;
use App\Services\Logic\Im\FriendQuit as FriendQuitService;
/**
* @RoutePrefix("/api/im/friend")
*/
class ImFriendController extends Controller
{
/**
* @Post("/{id:[0-9]+}/quit", name="api.im_friend.quit")
*/
public function quitAction($id)
{
$service = new FriendQuitService();
$service->handle($id);
return $this->jsonSuccess();
}
}

View File

@ -9,6 +9,7 @@ namespace App\Http\Api\Controllers;
use App\Services\Logic\Im\GroupInfo as GroupInfoService;
use App\Services\Logic\Im\GroupList as GroupListService;
use App\Services\Logic\Im\GroupQuit as GroupQuitService;
use App\Services\Logic\Im\GroupUserList as GroupUserListService;
/**
@ -53,4 +54,16 @@ class ImGroupController extends Controller
return $this->jsonPaginate($pager);
}
/**
* @Post("/{id:[0-9]+}/quit", name="api.im_group.quit")
*/
public function quitAction($id)
{
$service = new GroupQuitService();
$service->handle($id);
return $this->jsonSuccess();
}
}

View File

@ -0,0 +1,45 @@
<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Services\Logic\Im;
use App\Models\ImUser as ImUserModel;
use App\Services\Logic\ImUserTrait;
use App\Services\Logic\Service as LogicService;
use App\Validators\ImFriendUser as ImFriendUserValidator;
class FriendQuit extends LogicService
{
use ImUserTrait;
public function handle($id)
{
$loginUser = $this->getLoginUser();
$user = $this->checkImUser($loginUser->id);
$validator = new ImFriendUserValidator();
$friend = $validator->checkFriend($id);
$friendUser = $validator->checkFriendUser($user->id, $friend->id);
$friendUser->delete();
$this->decrUserFriendCount($user);
}
protected function decrUserFriendCount(ImUserModel $user)
{
if ($user->friend_count > 0) {
$user->friend_count -= 1;
$user->update();
}
}
}

View File

@ -18,7 +18,7 @@ class GroupInfo extends LogicService
public function handle($id)
{
$group = $this->checkGroup($id);
$group = $this->checkImGroup($id);
$userRepo = new UserRepo();

View File

@ -0,0 +1,60 @@
<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Services\Logic\Im;
use App\Models\ImGroup as ImGroupModel;
use App\Models\ImUser as ImUserModel;
use App\Services\Logic\ImGroupTrait;
use App\Services\Logic\ImUserTrait;
use App\Services\Logic\Service as LogicService;
use App\Validators\ImGroupUser as ImGroupUserValidator;
class GroupQuit extends LogicService
{
use ImGroupTrait;
use ImUserTrait;
public function handle($id)
{
$loginUser = $this->getLoginUser();
$group = $this->checkImGroup($id);
$user = $this->checkImUser($loginUser->id);
$validator = new ImGroupUserValidator();
$groupUser = $validator->checkGroupUser($group->id, $user->id);
$validator->checkIfAllowQuit($group->id, $user->id);
$groupUser->delete();
$this->decrGroupUserCount($group);
$this->decrUserGroupCount($user);
}
protected function decrUserGroupCount(ImUserModel $user)
{
if ($user->group_count > 0) {
$user->group_count -= 1;
$user->update();
}
}
protected function decrGroupUserCount(ImGroupModel $group)
{
if ($group->user_count > 0) {
$group->user_count -= 1;
$group->update();
}
}
}

View File

@ -20,7 +20,7 @@ class GroupUserList extends LogicService
public function handle($id)
{
$group = $this->checkGroup($id);
$group = $this->checkImGroup($id);
$pagerQuery = new PagerQuery();

View File

@ -12,7 +12,7 @@ use App\Validators\ImGroup as ImGroupValidator;
trait ImGroupTrait
{
public function checkGroup($id)
public function checkImGroup($id)
{
$validator = new ImGroupValidator();

View File

@ -0,0 +1,22 @@
<?php
/**
* @copyright Copyright (c) 2021 深圳市酷瓜软件有限公司
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.koogua.com
*/
namespace App\Services\Logic;
use App\Validators\ImUser as ImUserValidator;
trait ImUserTrait
{
public function checkImUser($id)
{
$validator = new ImUserValidator();
return $validator->checkUser($id);
}
}

View File

@ -114,4 +114,13 @@ class ImGroupUser extends Validator
}
}
public function checkIfAllowQuit($groupId, $userId)
{
$group = $this->checkGroup($groupId);
if ($group->owner_id == $userId) {
throw new BadRequestException('im_group_user.owner_quit_not_allowed');
}
}
}

View File

@ -464,6 +464,7 @@ $error['im_group_user.not_found'] = '群组关系不存在';
$error['im_group_user.remark_too_long'] = '验证信息太长超过30字符';
$error['im_group_user.has_joined'] = '已经加入过群组';
$error['im_group_user.join_not_allowed'] = '当前不允许加入群组';
$error['im_group_user.owner_quit_not_allowed'] = '当前不允许群主退群';
$error['im_group_user.delete_owner_not_allowed'] = '当前不允许删除群主';
$error['im_friend_user.not_found'] = '好友关系不存在';