feat:兼容开发

main
gzydong 2022-01-22 21:02:53 +08:00
parent 428a44a614
commit 79c90a385f
18 changed files with 171 additions and 77 deletions

View File

@ -8,7 +8,6 @@ use App\Controller\Api\V1\CController;
use App\Helper\DateHelper; use App\Helper\DateHelper;
use App\Model\Article\ArticleAnnex; use App\Model\Article\ArticleAnnex;
use App\Service\ArticleService; use App\Service\ArticleService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -27,11 +26,17 @@ use Psr\Http\Message\ResponseInterface;
class AnnexController extends CController class AnnexController extends CController
{ {
/** /**
* @Inject
* @var ArticleService * @var ArticleService
*/ */
private $articleService; private $articleService;
public function __construct(ArticleService $service)
{
parent::__construct();
$this->articleService = $service;
}
/** /**
* 上传附件 * 上传附件
* *

View File

@ -6,7 +6,6 @@ namespace App\Controller\Api\V1\Article;
use App\Controller\Api\V1\CController; use App\Controller\Api\V1\CController;
use App\Helper\StringHelper; use App\Helper\StringHelper;
use App\Service\ArticleService; use App\Service\ArticleService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -16,6 +15,7 @@ use Psr\Http\Message\ResponseInterface;
/** /**
* Class ArticleController * Class ArticleController
*
* @Controller(prefix="/api/v1/note/article") * @Controller(prefix="/api/v1/note/article")
* @Middleware(JWTAuthMiddleware::class) * @Middleware(JWTAuthMiddleware::class)
* *
@ -25,11 +25,18 @@ class ArticleController extends CController
{ {
/** /**
* @Inject
* @var ArticleService * @var ArticleService
*/ */
private $articleService; private $articleService;
public function __construct(ArticleService $service)
{
parent::__construct();
$this->articleService = $service;
}
/** /**
* 获取笔记列表 * 获取笔记列表
* *

View File

@ -7,7 +7,6 @@ use App\Cache\Repository\LockRedis;
use App\Controller\Api\V1\CController; use App\Controller\Api\V1\CController;
use App\Repository\Article\ArticleClassRepository; use App\Repository\Article\ArticleClassRepository;
use App\Service\ArticleService; use App\Service\ArticleService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -25,11 +24,17 @@ use Psr\Http\Message\ResponseInterface;
class ClassController extends CController class ClassController extends CController
{ {
/** /**
* @Inject
* @var ArticleService * @var ArticleService
*/ */
private $articleService; private $articleService;
public function __construct(ArticleService $service)
{
parent::__construct();
$this->articleService = $service;
}
/** /**
* 获取笔记分类列表 * 获取笔记分类列表
* *
@ -37,13 +42,6 @@ class ClassController extends CController
*/ */
public function list(): ResponseInterface public function list(): ResponseInterface
{ {
// $rows = $this->articleService->getUserClass($this->uid());
//
// foreach ($rows as &$row) {
// $row['count'] = is_null($row['count']) ? 0 : $row['count'];
// }
$rows = di()->get(ArticleClassRepository::class)->getUserClass($this->uid()); $rows = di()->get(ArticleClassRepository::class)->getUserClass($this->uid());
return $this->response->success(['rows' => $rows]); return $this->response->success(['rows' => $rows]);

View File

@ -5,7 +5,6 @@ namespace App\Controller\Api\V1\Article;
use App\Controller\Api\V1\CController; use App\Controller\Api\V1\CController;
use App\Service\ArticleService; use App\Service\ArticleService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -23,11 +22,17 @@ use Psr\Http\Message\ResponseInterface;
class TagController extends CController class TagController extends CController
{ {
/** /**
* @Inject
* @var ArticleService * @var ArticleService
*/ */
private $articleService; private $articleService;
public function __construct(ArticleService $service)
{
parent::__construct();
$this->articleService = $service;
}
/** /**
* 获取标签列表 * 获取标签列表
* *

View File

@ -5,7 +5,6 @@ namespace App\Controller\Api\V1;
use App\Constant\SmsConstant; use App\Constant\SmsConstant;
use App\Event\LoginEvent; use App\Event\LoginEvent;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Service\UserService; use App\Service\UserService;
@ -19,17 +18,23 @@ use Psr\Http\Message\ResponseInterface;
class AuthController extends CController class AuthController extends CController
{ {
/** /**
* @Inject
* @var UserService * @var UserService
*/ */
private $userService; private $userService;
/** /**
* @Inject
* @var SmsCodeService * @var SmsCodeService
*/ */
private $sms; private $sms;
public function __construct(SmsCodeService $smsCodeService, UserService $userService)
{
parent::__construct();
$this->userService = $userService;
$this->sms = $smsCodeService;
}
/** /**
* 授权登录接口 * 授权登录接口
* *

View File

@ -5,12 +5,10 @@ namespace App\Controller\Api\V1;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use App\Support\SendEmailCode; use App\Support\SendEmailCode;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Service\SmsCodeService; use App\Service\SmsCodeService;
use App\Constant\SmsConstant; use App\Constant\SmsConstant;
use App\Service\UserService;
/** /**
* class CommonController * class CommonController
@ -20,11 +18,17 @@ use App\Service\UserService;
class CommonController extends CController class CommonController extends CController
{ {
/** /**
* @Inject
* @var SmsCodeService * @var SmsCodeService
*/ */
private $sms; private $sms;
public function __construct(SmsCodeService $service)
{
parent::__construct();
$this->sms = $service;
}
/** /**
* 发送短信验证码 * 发送短信验证码
* *

View File

@ -9,7 +9,6 @@ use App\Controller\Api\V1\CController;
use App\Middleware\JWTAuthMiddleware; use App\Middleware\JWTAuthMiddleware;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use App\Service\Contact\ContactApplyService; use App\Service\Contact\ContactApplyService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
@ -17,6 +16,7 @@ use Psr\Http\Message\ResponseInterface;
/** /**
* Class ContactsApplyController * Class ContactsApplyController
*
* @Controller(prefix="/api/v1/contact/apply") * @Controller(prefix="/api/v1/contact/apply")
* @Middleware(JWTAuthMiddleware::class) * @Middleware(JWTAuthMiddleware::class)
* *
@ -25,11 +25,17 @@ use Psr\Http\Message\ResponseInterface;
class ContactApplyController extends CController class ContactApplyController extends CController
{ {
/** /**
* @Inject
* @var ContactApplyService * @var ContactApplyService
*/ */
private $service; private $service;
public function __construct(ContactApplyService $service)
{
parent::__construct();
$this->service = $service;
}
/** /**
* 添加联系人申请接口 * 添加联系人申请接口
* *

View File

@ -13,7 +13,6 @@ use App\Service\Contact\ContactsService;
use App\Service\SocketClientService; use App\Service\SocketClientService;
use App\Service\TalkSessionService; use App\Service\TalkSessionService;
use App\Service\UserService; use App\Service\UserService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
@ -21,6 +20,7 @@ use Psr\Http\Message\ResponseInterface;
/** /**
* Class ContactsController * Class ContactsController
*
* @Controller(prefix="/api/v1/contact") * @Controller(prefix="/api/v1/contact")
* @Middleware(JWTAuthMiddleware::class) * @Middleware(JWTAuthMiddleware::class)
* *
@ -29,13 +29,11 @@ use Psr\Http\Message\ResponseInterface;
class ContactController extends CController class ContactController extends CController
{ {
/** /**
* @Inject
* @var ContactsService * @var ContactsService
*/ */
private $service; private $service;
/** /**
* @Inject
* @var UserService * @var UserService
*/ */
private $userService; private $userService;
@ -45,6 +43,15 @@ class ContactController extends CController
*/ */
private $userRepository; private $userRepository;
public function __construct(ContactsService $service, UserService $userService, UserRepository $userRepository)
{
parent::__construct();
$this->service = $service;
$this->userService = $userService;
$this->userRepository = $userRepository;
}
/** /**
* 获取用户联系人列表 * 获取用户联系人列表
* *
@ -52,12 +59,7 @@ class ContactController extends CController
*/ */
public function getContacts(UserService $service): ResponseInterface public function getContacts(UserService $service): ResponseInterface
{ {
$rows = di()->get(ContactRepository::class)->friends($this->uid()); $rows = di()->get(ContactRepository::class)->friends($this->uid());
// $rows = $service->getUserFriends($this->uid());
if ($rows) { if ($rows) {
$runArr = ServerRunID::getInstance()->getServerRunIdAll(); $runArr = ServerRunID::getInstance()->getServerRunIdAll();
foreach ($rows as $k => $row) { foreach ($rows as $k => $row) {

View File

@ -3,7 +3,6 @@ declare(strict_types=1);
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -24,11 +23,17 @@ use Psr\Http\Message\ResponseInterface;
class EmoticonController extends CController class EmoticonController extends CController
{ {
/** /**
* @Inject
* @var EmoticonService * @var EmoticonService
*/ */
private $emoticonService; private $emoticonService;
public function __construct(EmoticonService $service)
{
parent::__construct();
$this->emoticonService = $service;
}
/** /**
* 获取用户表情包列表 * 获取用户表情包列表
* *

View File

@ -10,7 +10,6 @@ use App\Model\Group\GroupNotice;
use App\Service\Group\GroupMemberService; use App\Service\Group\GroupMemberService;
use App\Service\Group\GroupService; use App\Service\Group\GroupService;
use App\Service\TalkSessionService; use App\Service\TalkSessionService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -28,19 +27,26 @@ use Psr\Http\Message\ResponseInterface;
class GroupController extends CController class GroupController extends CController
{ {
/** /**
* @Inject
* @var GroupService * @var GroupService
*/ */
private $groupService; private $groupService;
/** /**
* @inject
* @var GroupMemberService * @var GroupMemberService
*/ */
private $groupMemberService; private $groupMemberService;
public function __construct(GroupService $groupService, GroupMemberService $groupMemberService)
{
parent::__construct();
$this->groupService = $groupService;
$this->groupMemberService = $groupMemberService;
}
/** /**
* 获取群组列表 * 获取群组列表
*
* @RequestMapping(path="list", methods="get") * @RequestMapping(path="list", methods="get")
*/ */
public function list(): ResponseInterface public function list(): ResponseInterface
@ -52,6 +58,7 @@ class GroupController extends CController
/** /**
* 创建群组 * 创建群组
*
* @RequestMapping(path="create", methods="post") * @RequestMapping(path="create", methods="post")
*/ */
public function create(): ResponseInterface public function create(): ResponseInterface
@ -76,6 +83,7 @@ class GroupController extends CController
/** /**
* 解散群组接口 * 解散群组接口
*
* @RequestMapping(path="dismiss", methods="post") * @RequestMapping(path="dismiss", methods="post")
*/ */
public function dismiss(): ResponseInterface public function dismiss(): ResponseInterface
@ -96,6 +104,7 @@ class GroupController extends CController
/** /**
* 邀请好友加入群组接口 * 邀请好友加入群组接口
*
* @RequestMapping(path="invite", methods="post") * @RequestMapping(path="invite", methods="post")
*/ */
public function invite(): ResponseInterface public function invite(): ResponseInterface
@ -117,6 +126,7 @@ class GroupController extends CController
/** /**
* 退出群组接口 * 退出群组接口
*
* @RequestMapping(path="secede", methods="post") * @RequestMapping(path="secede", methods="post")
*/ */
public function secede(): ResponseInterface public function secede(): ResponseInterface
@ -136,6 +146,7 @@ class GroupController extends CController
/** /**
* 获取群信息接口 * 获取群信息接口
*
* @RequestMapping(path="detail", methods="get") * @RequestMapping(path="detail", methods="get")
*/ */
public function detail(TalkSessionService $service): ResponseInterface public function detail(TalkSessionService $service): ResponseInterface
@ -174,6 +185,7 @@ class GroupController extends CController
/** /**
* 编辑群组信息 * 编辑群组信息
*
* @RequestMapping(path="setting", methods="post") * @RequestMapping(path="setting", methods="post")
*/ */
public function Setting(): ResponseInterface public function Setting(): ResponseInterface

View File

@ -8,7 +8,6 @@ use App\Model\Group\GroupMember;
use App\Repository\Contact\ContactRepository; use App\Repository\Contact\ContactRepository;
use App\Service\Group\GroupMemberService; use App\Service\Group\GroupMemberService;
use App\Service\Group\GroupService; use App\Service\Group\GroupService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -26,19 +25,26 @@ use Psr\Http\Message\ResponseInterface;
class MemberController extends CController class MemberController extends CController
{ {
/** /**
* @Inject
* @var GroupService * @var GroupService
*/ */
private $groupService; private $groupService;
/** /**
* @inject
* @var GroupMemberService * @var GroupMemberService
*/ */
private $groupMemberService; private $groupMemberService;
public function __construct(GroupService $groupService, GroupMemberService $groupMemberService)
{
parent::__construct();
$this->groupService = $groupService;
$this->groupMemberService = $groupMemberService;
}
/** /**
* 获取群组成员列表 * 获取群组成员列表
*
* @RequestMapping(path="list", methods="get") * @RequestMapping(path="list", methods="get")
*/ */
public function list(): ResponseInterface public function list(): ResponseInterface
@ -102,6 +108,7 @@ class MemberController extends CController
public function removeMembers(): ResponseInterface public function removeMembers(): ResponseInterface
{ {
$params = $this->request->inputs(['group_id', 'members_ids']); $params = $this->request->inputs(['group_id', 'members_ids']);
$this->validate($params, [ $this->validate($params, [
'group_id' => 'required|integer', 'group_id' => 'required|integer',
'members_ids' => 'required|ids' 'members_ids' => 'required|ids'
@ -124,11 +131,13 @@ class MemberController extends CController
/** /**
* 设置群名片 * 设置群名片
*
* @RequestMapping(path="remark", methods="post") * @RequestMapping(path="remark", methods="post")
*/ */
public function remark(): ResponseInterface public function remark(): ResponseInterface
{ {
$params = $this->request->inputs(['group_id', 'visit_card']); $params = $this->request->inputs(['group_id', 'visit_card']);
$this->validate($params, [ $this->validate($params, [
'group_id' => 'required|integer', 'group_id' => 'required|integer',
'visit_card' => 'required|max:20' 'visit_card' => 'required|max:20'

View File

@ -6,8 +6,6 @@ namespace App\Controller\Api\V1\Group;
use App\Controller\Api\V1\CController; use App\Controller\Api\V1\CController;
use App\Service\Group\GroupMemberService; use App\Service\Group\GroupMemberService;
use App\Service\Group\GroupNoticeService; use App\Service\Group\GroupNoticeService;
use App\Service\Group\GroupService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -24,21 +22,21 @@ use Psr\Http\Message\ResponseInterface;
*/ */
class NoticeController extends CController class NoticeController extends CController
{ {
/** /**
* @Inject
* @var GroupService
*/
private $groupService;
/**
* @inject
* @var GroupMemberService * @var GroupMemberService
*/ */
private $groupMemberService; private $groupMemberService;
public function __construct(GroupMemberService $groupMemberService)
{
parent::__construct();
$this->groupMemberService = $groupMemberService;
}
/** /**
* 获取群组公告列表 * 获取群组公告列表
*
* @RequestMapping(path="list", methods="get") * @RequestMapping(path="list", methods="get")
*/ */
public function list(GroupNoticeService $service): ResponseInterface public function list(GroupNoticeService $service): ResponseInterface

View File

@ -16,7 +16,6 @@ use App\Service\TalkMessageService;
use App\Support\UserRelation; use App\Support\UserRelation;
use App\Service\EmoticonService; use App\Service\EmoticonService;
use App\Service\TalkService; use App\Service\TalkService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -26,6 +25,7 @@ use Psr\Http\Message\ResponseInterface;
/** /**
* Class TalkController * Class TalkController
*
* @Controller(prefix="/api/v1/talk/message") * @Controller(prefix="/api/v1/talk/message")
* @Middleware(JWTAuthMiddleware::class) * @Middleware(JWTAuthMiddleware::class)
* *
@ -34,17 +34,23 @@ use Psr\Http\Message\ResponseInterface;
class MessageController extends CController class MessageController extends CController
{ {
/** /**
* @Inject
* @var TalkService * @var TalkService
*/ */
public $talkService; public $talkService;
/** /**
* @Inject
* @var TalkMessageService * @var TalkMessageService
*/ */
public $talkMessageService; public $talkMessageService;
public function __construct(TalkService $talkService, TalkMessageService $talkMessageService)
{
parent::__construct();
$this->talkService = $talkService;
$this->talkMessageService = $talkMessageService;
}
/** /**
* 发送文本消息 * 发送文本消息
* *

View File

@ -10,9 +10,7 @@ use App\Controller\Api\V1\CController;
use App\Model\Talk\TalkRecords; use App\Model\Talk\TalkRecords;
use App\Model\Talk\TalkRecordsFile; use App\Model\Talk\TalkRecordsFile;
use App\Service\Group\GroupMemberService; use App\Service\Group\GroupMemberService;
use App\Service\TalkSessionService;
use App\Service\TalkService; use App\Service\TalkService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -31,16 +29,17 @@ use Psr\Http\Message\ResponseInterface;
class RecordsController extends CController class RecordsController extends CController
{ {
/** /**
* @Inject
* @var TalkService * @var TalkService
*/ */
public $talkService; private $talkService;
/**
* @Inject public function __construct(TalkService $talkService)
* @var TalkSessionService {
*/ parent::__construct();
public $talkListService;
$this->talkService = $talkService;
}
/** /**
* 获取对话面板中的聊天记录 * 获取对话面板中的聊天记录

View File

@ -15,7 +15,6 @@ use App\Service\TalkSessionService;
use App\Service\TalkService; use App\Service\TalkService;
use App\Service\UserFriendService; use App\Service\UserFriendService;
use App\Support\UserRelation; use App\Support\UserRelation;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -24,6 +23,7 @@ use Psr\Http\Message\ResponseInterface;
/** /**
* Class TalkController * Class TalkController
*
* @Controller(prefix="/api/v1/talk") * @Controller(prefix="/api/v1/talk")
* @Middleware(JWTAuthMiddleware::class) * @Middleware(JWTAuthMiddleware::class)
* *
@ -32,19 +32,26 @@ use Psr\Http\Message\ResponseInterface;
class TalkController extends CController class TalkController extends CController
{ {
/** /**
* @Inject
* @var TalkService * @var TalkService
*/ */
public $talkService; public $talkService;
/** /**
* @Inject
* @var TalkSessionService * @var TalkSessionService
*/ */
public $talkListService; public $talkSessionService;
public function __construct(TalkService $talkService, TalkSessionService $talkSessionService)
{
parent::__construct();
$this->talkService = $talkService;
$this->talkSessionService = $talkSessionService;
}
/** /**
* 获取用户对话列表 * 获取用户对话列表
*
* @RequestMapping(path="list", methods="get") * @RequestMapping(path="list", methods="get")
* *
* @return ResponseInterface * @return ResponseInterface
@ -56,11 +63,11 @@ class TalkController extends CController
// 读取用户的未读消息列表 // 读取用户的未读消息列表
if ($list = UnreadTalkCache::getInstance()->reads($user_id)) { if ($list = UnreadTalkCache::getInstance()->reads($user_id)) {
foreach ($list as $friend_id => $num) { foreach ($list as $friend_id => $num) {
$this->talkListService->create($user_id, $friend_id, TalkModeConstant::PRIVATE_CHAT); $this->talkSessionService->create($user_id, $friend_id, TalkModeConstant::PRIVATE_CHAT);
} }
} }
return $this->response->success($this->talkListService->getTalkList($user_id)); return $this->response->success($this->talkSessionService->getTalkList($user_id));
} }
/** /**
@ -71,6 +78,7 @@ class TalkController extends CController
public function create(UserFriendService $service): ResponseInterface public function create(UserFriendService $service): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id']); $params = $this->request->inputs(['talk_type', 'receiver_id']);
$this->validate($params, [ $this->validate($params, [
'talk_type' => 'required|in:1,2', 'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1' 'receiver_id' => 'required|integer|min:1'
@ -90,7 +98,7 @@ class TalkController extends CController
return $this->response->fail('暂不属于好友关系或群聊成员,无法进行聊天!'); return $this->response->fail('暂不属于好友关系或群聊成员,无法进行聊天!');
} }
$result = $this->talkListService->create($user_id, $params['receiver_id'], $params['talk_type']); $result = $this->talkSessionService->create($user_id, $params['receiver_id'], $params['talk_type']);
if (!$result) { if (!$result) {
LockRedis::getInstance()->delete($lock); LockRedis::getInstance()->delete($lock);
return $this->response->fail('创建失败!'); return $this->response->fail('创建失败!');
@ -135,7 +143,7 @@ class TalkController extends CController
'list_id' => 'required|integer|min:0' 'list_id' => 'required|integer|min:0'
]); ]);
return $this->talkListService->delete($this->uid(), $params['list_id']) return $this->talkSessionService->delete($this->uid(), $params['list_id'])
? $this->response->success([], '对话列表删除成功...') ? $this->response->success([], '对话列表删除成功...')
: $this->response->fail('对话列表删除失败!'); : $this->response->fail('对话列表删除失败!');
} }
@ -148,12 +156,13 @@ class TalkController extends CController
public function topping(): ResponseInterface public function topping(): ResponseInterface
{ {
$params = $this->request->inputs(['list_id', 'type']); $params = $this->request->inputs(['list_id', 'type']);
$this->validate($params, [ $this->validate($params, [
'list_id' => 'required|integer|min:0', 'list_id' => 'required|integer|min:0',
'type' => 'required|in:1,2', 'type' => 'required|in:1,2',
]); ]);
return $this->talkListService->top($this->uid(), $params['list_id'], $params['type'] == 1) return $this->talkSessionService->top($this->uid(), $params['list_id'], $params['type'] == 1)
? $this->response->success([], '对话列表置顶(或取消置顶)成功...') ? $this->response->success([], '对话列表置顶(或取消置顶)成功...')
: $this->response->fail('对话列表置顶(或取消置顶)失败!'); : $this->response->fail('对话列表置顶(或取消置顶)失败!');
} }
@ -166,13 +175,14 @@ class TalkController extends CController
public function disturb(): ResponseInterface public function disturb(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id', 'is_disturb']); $params = $this->request->inputs(['talk_type', 'receiver_id', 'is_disturb']);
$this->validate($params, [ $this->validate($params, [
'talk_type' => 'required|in:1,2', 'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1', 'receiver_id' => 'required|integer|min:1',
'is_disturb' => 'required|in:0,1', 'is_disturb' => 'required|in:0,1',
]); ]);
return $this->talkListService->disturb($this->uid(), $params['receiver_id'], $params['talk_type'], $params['is_disturb']) return $this->talkSessionService->disturb($this->uid(), $params['receiver_id'], $params['talk_type'], $params['is_disturb'])
? $this->response->success([], '免打扰设置成功...') ? $this->response->success([], '免打扰设置成功...')
: $this->response->fail('免打扰设置失败!'); : $this->response->fail('免打扰设置失败!');
} }
@ -184,6 +194,7 @@ class TalkController extends CController
public function updateUnreadNum(): ResponseInterface public function updateUnreadNum(): ResponseInterface
{ {
$params = $this->request->inputs(['talk_type', 'receiver_id']); $params = $this->request->inputs(['talk_type', 'receiver_id']);
$this->validate($params, [ $this->validate($params, [
'talk_type' => 'required|in:1,2', 'talk_type' => 'required|in:1,2',
'receiver_id' => 'required|integer|min:1', 'receiver_id' => 'required|integer|min:1',

View File

@ -3,7 +3,6 @@ declare(strict_types=1);
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -22,11 +21,17 @@ use Psr\Http\Message\ResponseInterface;
class UploadController extends CController class UploadController extends CController
{ {
/** /**
* @inject
* @var SplitUploadService * @var SplitUploadService
*/ */
private $splitUploadService; private $splitUploadService;
public function __construct(SplitUploadService $service)
{
parent::__construct();
$this->splitUploadService = $service;
}
/** /**
* 图片文件流上传接口 * 图片文件流上传接口
* *

View File

@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Controller\Api\V1; namespace App\Controller\Api\V1;
use App\Constant\SmsConstant; use App\Constant\SmsConstant;
use Hyperf\Di\Annotation\Inject; use App\Repository\UserRepository;
use Hyperf\HttpServer\Annotation\Controller; use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping; use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Middleware; use Hyperf\HttpServer\Annotation\Middleware;
@ -26,11 +26,23 @@ use Psr\Http\Message\ResponseInterface;
class UsersController extends CController class UsersController extends CController
{ {
/** /**
* @Inject
* @var UserService * @var UserService
*/ */
private $userService; private $userService;
/**
* @var UserRepository
*/
private $userRepository;
public function __construct(UserService $userService, UserRepository $userRepository)
{
parent::__construct();
$this->userService = $userService;
$this->userRepository = $userRepository;
}
/** /**
* 获取我的信息 * 获取我的信息
* @RequestMapping(path="detail", methods="get") * @RequestMapping(path="detail", methods="get")
@ -97,7 +109,7 @@ class UsersController extends CController
'avatar' => 'present|url' 'avatar' => 'present|url'
]); ]);
User::where('id', $this->uid())->update($params); $this->userRepository->update(["id" => $this->uid()], $params);
return $this->response->success([], '个人信息修改成功...'); return $this->response->success([], '个人信息修改成功...');
} }

View File

@ -1,9 +1,11 @@
<?php <?php
declare(strict_types=1);
namespace App\Service; namespace App\Service;
use App\Helper\HashHelper; use App\Helper\HashHelper;
use App\Model\Contact\ContactApply; use App\Model\Contact\ContactApply;
use App\Model\User;
use App\Repository\Article\ArticleClassRepository; use App\Repository\Article\ArticleClassRepository;
use App\Repository\UserRepository; use App\Repository\UserRepository;
use Hyperf\DbConnection\Db; use Hyperf\DbConnection\Db;
@ -31,6 +33,8 @@ class UserService extends BaseService
* *
* @param string $mobile 手机号 * @param string $mobile 手机号
* @param string $password 登录密码 * @param string $password 登录密码
*
* @return \App\Model\User|false
*/ */
public function login(string $mobile, string $password) public function login(string $mobile, string $password)
{ {
@ -43,6 +47,7 @@ class UserService extends BaseService
return false; return false;
} }
/** @var \App\Model\User $user */
return $user; return $user;
} }