diff --git a/app/Caches/ImActiveGroupList.php b/app/Caches/ImActiveGroupList.php new file mode 100644 index 00000000..2dd6eb60 --- /dev/null +++ b/app/Caches/ImActiveGroupList.php @@ -0,0 +1,83 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'im_active_group_list'; + } + + public function getContent($id = null) + { + $groups = $this->findGroups(); + + if (!$groups) return []; + + $result = []; + + foreach ($groups as $group) { + $result[] = [ + 'id' => $group->id, + 'type' => $group->type, + 'name' => $group->name, + 'avatar' => $group->avatar, + 'about' => $group->about, + 'user_count' => $group->user_count, + 'msg_count' => $group->msg_count, + ]; + } + + return $result; + } + + /** + * @param int $days + * @param int $limit + * @return ResultsetInterface|Resultset|UserModel[] + */ + protected function findGroups($days = 7, $limit = 12) + { + $result = []; + + $startTime = strtotime("-{$days} days"); + $endTime = time(); + + $rows = ImMessageModel::query() + ->columns(['receiver_id', 'total_count' => 'count(receiver_id)']) + ->groupBy('receiver_id') + ->orderBy('total_count DESC') + ->where('receiver_type = :type:', ['type' => ImMessageModel::TYPE_GROUP]) + ->betweenWhere('create_time', $startTime, $endTime) + ->limit($limit) + ->execute(); + + if ($rows->count() > 0) { + + $ids = kg_array_column($rows->toArray(), 'receiver_id'); + + $groupRepo = new ImGroupRepo(); + + $result = $groupRepo->findByIds($ids); + } + + return $result; + } + +} diff --git a/app/Caches/ImActiveUserList.php b/app/Caches/ImActiveUserList.php new file mode 100644 index 00000000..b0958fd7 --- /dev/null +++ b/app/Caches/ImActiveUserList.php @@ -0,0 +1,80 @@ +lifetime; + } + + public function getKey($id = null) + { + return 'im_active_user_list'; + } + + public function getContent($id = null) + { + $users = $this->findUsers($id); + + if (!$users) return []; + + $result = []; + + foreach ($users as $user) { + $result[] = [ + 'id' => $user->id, + 'name' => $user->name, + 'avatar' => $user->avatar, + 'title' => $user->title, + 'about' => $user->about, + 'vip' => $user->vip, + ]; + } + + return $result; + } + + /** + * @param int $days + * @param int $limit + * @return ResultsetInterface|Resultset|UserModel[] + */ + protected function findUsers($days = 7, $limit = 12) + { + $result = []; + + $startTime = strtotime("-{$days} days"); + $endTime = time(); + + $rows = ImMessageModel::query() + ->columns(['sender_id', 'total_count' => 'count(sender_id)']) + ->groupBy('sender_id') + ->orderBy('total_count DESC') + ->betweenWhere('create_time', $startTime, $endTime) + ->limit($limit) + ->execute(); + + if ($rows->count() > 0) { + + $ids = kg_array_column($rows->toArray(), 'sender_id'); + + $userRepo = new UserRepo(); + + $result = $userRepo->findByIds($ids); + } + + return $result; + } + +} diff --git a/app/Caches/ImNewGroupList.php b/app/Caches/ImNewGroupList.php index ff819b97..7ab6d929 100644 --- a/app/Caches/ImNewGroupList.php +++ b/app/Caches/ImNewGroupList.php @@ -25,7 +25,7 @@ class ImNewGroupList extends Cache { $limit = 12; - $groups = $this->findHotGroups($limit); + $groups = $this->findGroups($limit); if ($groups->count() == 0) { return []; @@ -49,6 +49,8 @@ class ImNewGroupList extends Cache 'name' => $group->name, 'avatar' => $group->avatar, 'about' => $group->about, + 'user_count' => $group->user_count, + 'msg_count' => $group->msg_count, ]; } @@ -59,11 +61,11 @@ class ImNewGroupList extends Cache * @param int $limit * @return ResultsetInterface|Resultset|ImGroupModel[] */ - public function findHotGroups($limit = 12) + public function findGroups($limit = 12) { return ImGroupModel::query() - ->where('deleted = 0') - ->orderBy('user_count DESC') + ->where('published = 1') + ->orderBy('id DESC') ->limit($limit) ->execute(); } diff --git a/app/Caches/ImNewUserList.php b/app/Caches/ImNewUserList.php index 46b4124d..894a84f1 100644 --- a/app/Caches/ImNewUserList.php +++ b/app/Caches/ImNewUserList.php @@ -25,7 +25,7 @@ class ImNewUserList extends Cache { $limit = 12; - $users = $this->findHotUsers($limit); + $users = $this->findUsers($limit); if ($users->count() == 0) { return []; @@ -47,6 +47,7 @@ class ImNewUserList extends Cache 'id' => $user->id, 'name' => $user->name, 'avatar' => $user->avatar, + 'title' => $user->title, 'about' => $user->about, 'vip' => $user->vip, ]; @@ -59,7 +60,7 @@ class ImNewUserList extends Cache * @param int $limit * @return ResultsetInterface|Resultset|UserModel[] */ - public function findHotUsers($limit = 12) + public function findUsers($limit = 12) { return UserModel::query() ->where('deleted = 0') diff --git a/app/Caches/IndexCarouselList.php b/app/Caches/IndexCarouselList.php index 0a216296..94ccde8c 100644 --- a/app/Caches/IndexCarouselList.php +++ b/app/Caches/IndexCarouselList.php @@ -18,7 +18,7 @@ class IndexCarouselList extends Cache public function getKey($id = null) { - return 'index:carousel_list'; + return 'index_carousel_list'; } public function getContent($id = null) diff --git a/app/Caches/IndexFreeCourseList.php b/app/Caches/IndexFreeCourseList.php index 5a8f380d..b6c69d67 100644 --- a/app/Caches/IndexFreeCourseList.php +++ b/app/Caches/IndexFreeCourseList.php @@ -23,7 +23,7 @@ class IndexFreeCourseList extends Cache public function getKey($id = null) { - return 'index:free_course_list'; + return 'index_free_course_list'; } public function getContent($id = null) diff --git a/app/Caches/IndexLiveList.php b/app/Caches/IndexLiveList.php index 01719a4d..238c0d05 100644 --- a/app/Caches/IndexLiveList.php +++ b/app/Caches/IndexLiveList.php @@ -22,7 +22,7 @@ class IndexLiveList extends Cache public function getKey($id = null) { - return 'index:live_list'; + return 'index_live_list'; } public function getContent($id = null) diff --git a/app/Caches/IndexNewCourseList.php b/app/Caches/IndexNewCourseList.php index 008c8651..7cb627cf 100644 --- a/app/Caches/IndexNewCourseList.php +++ b/app/Caches/IndexNewCourseList.php @@ -23,7 +23,7 @@ class IndexNewCourseList extends Cache public function getKey($id = null) { - return 'index:new_course_list'; + return 'index_new_course_list'; } public function getContent($id = null) diff --git a/app/Caches/IndexVipCourseList.php b/app/Caches/IndexVipCourseList.php index 20aeb6ee..ab869db0 100644 --- a/app/Caches/IndexVipCourseList.php +++ b/app/Caches/IndexVipCourseList.php @@ -23,7 +23,7 @@ class IndexVipCourseList extends Cache public function getKey($id = null) { - return 'index:vip_course_list'; + return 'index_vip_course_list'; } public function getContent($id = null) diff --git a/app/Caches/MaxCategoryId.php b/app/Caches/MaxCategoryId.php index 2a635c52..dfc4fa4f 100644 --- a/app/Caches/MaxCategoryId.php +++ b/app/Caches/MaxCategoryId.php @@ -16,7 +16,7 @@ class MaxCategoryId extends Cache public function getKey($id = null) { - return 'max_id:category'; + return 'max_category_id'; } public function getContent($id = null) diff --git a/app/Caches/MaxChapterId.php b/app/Caches/MaxChapterId.php index 8b80793f..e751dfe8 100644 --- a/app/Caches/MaxChapterId.php +++ b/app/Caches/MaxChapterId.php @@ -16,7 +16,7 @@ class MaxChapterId extends Cache public function getKey($id = null) { - return 'max_id:chapter'; + return 'max_chapter_id'; } public function getContent($id = null) diff --git a/app/Caches/MaxCourseId.php b/app/Caches/MaxCourseId.php index bfc0233d..6f8b350c 100644 --- a/app/Caches/MaxCourseId.php +++ b/app/Caches/MaxCourseId.php @@ -16,7 +16,7 @@ class MaxCourseId extends Cache public function getKey($id = null) { - return 'max_id:course'; + return 'max_course_id'; } public function getContent($id = null) diff --git a/app/Caches/MaxHelpId.php b/app/Caches/MaxHelpId.php index af56d21c..ae43642d 100644 --- a/app/Caches/MaxHelpId.php +++ b/app/Caches/MaxHelpId.php @@ -16,7 +16,7 @@ class MaxHelpId extends Cache public function getKey($id = null) { - return 'max_id:help'; + return 'max_help_id'; } public function getContent($id = null) diff --git a/app/Caches/MaxImGroupId.php b/app/Caches/MaxImGroupId.php index ca2ab945..346206b4 100644 --- a/app/Caches/MaxImGroupId.php +++ b/app/Caches/MaxImGroupId.php @@ -16,7 +16,7 @@ class MaxImGroupId extends Cache public function getKey($id = null) { - return 'max_id:im_group'; + return 'max_im_group_id'; } public function getContent($id = null) diff --git a/app/Caches/MaxPackageId.php b/app/Caches/MaxPackageId.php index 845cbfd4..b5252a4c 100644 --- a/app/Caches/MaxPackageId.php +++ b/app/Caches/MaxPackageId.php @@ -16,7 +16,7 @@ class MaxPackageId extends Cache public function getKey($id = null) { - return 'max_id:package'; + return 'max_package_id'; } public function getContent($id = null) diff --git a/app/Caches/MaxPageId.php b/app/Caches/MaxPageId.php index d3f1a466..cfed90f3 100644 --- a/app/Caches/MaxPageId.php +++ b/app/Caches/MaxPageId.php @@ -16,7 +16,7 @@ class MaxPageId extends Cache public function getKey($id = null) { - return 'max_id:page'; + return 'max_page_id'; } public function getContent($id = null) diff --git a/app/Caches/MaxTopicId.php b/app/Caches/MaxTopicId.php index 6a67fefa..3c739d7a 100644 --- a/app/Caches/MaxTopicId.php +++ b/app/Caches/MaxTopicId.php @@ -16,7 +16,7 @@ class MaxTopicId extends Cache public function getKey($id = null) { - return 'max_id:topic'; + return 'max_topic_id'; } public function getContent($id = null) diff --git a/app/Caches/MaxUserId.php b/app/Caches/MaxUserId.php index 4a48e522..7109382b 100644 --- a/app/Caches/MaxUserId.php +++ b/app/Caches/MaxUserId.php @@ -16,7 +16,7 @@ class MaxUserId extends Cache public function getKey($id = null) { - return 'max_id:user'; + return 'max_user_id'; } public function getContent($id = null) diff --git a/app/Http/Admin/Views/order/show.volt b/app/Http/Admin/Views/order/show.volt index d54cb9cc..12f567ce 100644 --- a/app/Http/Admin/Views/order/show.volt +++ b/app/Http/Admin/Views/order/show.volt @@ -9,7 +9,7 @@
-
+
diff --git a/app/Http/Admin/Views/refund/show.volt b/app/Http/Admin/Views/refund/show.volt index f2869429..36ab2bac 100644 --- a/app/Http/Admin/Views/refund/show.volt +++ b/app/Http/Admin/Views/refund/show.volt @@ -66,7 +66,7 @@
{% else %} -
+
{% endif %} diff --git a/app/Http/Admin/Views/setting/live_push_test.volt b/app/Http/Admin/Views/setting/live_push_test.volt index 8fc16aea..45430f41 100644 --- a/app/Http/Admin/Views/setting/live_push_test.volt +++ b/app/Http/Admin/Views/setting/live_push_test.volt @@ -7,7 +7,7 @@ 手机推流
-
+
二维码图片
diff --git a/app/Http/Admin/Views/setting/site.volt b/app/Http/Admin/Views/setting/site.volt index 6d062530..e027b8fd 100644 --- a/app/Http/Admin/Views/setting/site.volt +++ b/app/Http/Admin/Views/setting/site.volt @@ -84,7 +84,7 @@
- +
diff --git a/app/Http/Admin/Views/trade/show.volt b/app/Http/Admin/Views/trade/show.volt index b9499cc5..06aa8fc4 100644 --- a/app/Http/Admin/Views/trade/show.volt +++ b/app/Http/Admin/Views/trade/show.volt @@ -11,7 +11,7 @@ {% set trade_refund_url = url({'for':'admin.trade.refund','id':trade.id}) %} -
+
{% if trade.status == 'finished' %} {% endif %} diff --git a/app/Http/Web/Controllers/ImController.php b/app/Http/Web/Controllers/ImController.php index bee55ab0..5ae21432 100644 --- a/app/Http/Web/Controllers/ImController.php +++ b/app/Http/Web/Controllers/ImController.php @@ -36,8 +36,6 @@ class ImController extends Controller */ public function csAction() { - $this->seo->prependTitle('在线客服'); - $service = new ImService(); $csUser = $service->getCsUser(); @@ -45,20 +43,6 @@ class ImController extends Controller $this->view->setVar('cs_user', $csUser); } - /** - * @Get("/robot", name="web.im.robot") - */ - public function robotAction() - { - $this->seo->prependTitle('智能聊天'); - - $service = new ImService(); - - $csUser = $service->getRobotUser(); - - $this->view->setVar('cs_user', $csUser); - } - /** * @Get("/init", name="web.im.init") */ @@ -117,7 +101,9 @@ class ImController extends Controller { $service = new ImService(); - $service->pullUnreadFriendMessages(); + $id = $this->request->getQuery('id'); + + $service->pullUnreadFriendMessages($id); return $this->jsonSuccess(); } @@ -199,9 +185,12 @@ class ImController extends Controller */ public function sendChatMessageAction() { + $from = $this->request->getPost('from'); + $to = $this->request->getPost('to'); + $service = new ImService(); - $service->sendChatMessage(); + $service->sendChatMessage($from, $to); return $this->jsonSuccess(); } @@ -211,9 +200,12 @@ class ImController extends Controller */ public function sendCsMessageAction() { + $from = $this->request->getPost('from'); + $to = $this->request->getPost('to'); + $service = new ImService(); - $service->sendCsMessage(); + $service->sendCsMessage($from, $to); return $this->jsonSuccess(); } diff --git a/app/Http/Web/Services/Im.php b/app/Http/Web/Services/Im.php index a905ec94..6dc3940d 100644 --- a/app/Http/Web/Services/Im.php +++ b/app/Http/Web/Services/Im.php @@ -17,21 +17,11 @@ class Im extends Service use ImGroupTrait; use ImMessageTrait; use ImNoticeTrait; - - public function getRobotUser() - { - $imUser = new ImUserModel(); - - $imUser->id = -10000; - $imUser->name = '聊天机器人'; - $imUser->avatar = kg_ci_avatar_img_url(null); - - return $imUser; - } + use ImStatTrait; public function getCsUser() { - $userIds = []; + $csUserIds = []; $onlineUserIds = []; $cache = new SettingCache(); @@ -41,21 +31,21 @@ class Im extends Service Gateway::$registerAddress = $this->getRegisterAddress(); if (!empty($imInfo['cs_user1_id'])) { - $userIds[] = $imInfo['cs_user1_id']; + $csUserIds[] = $imInfo['cs_user1_id']; if (Gateway::isUidOnline($imInfo['cs_user1_id'])) { $onlineUserIds[] = $imInfo['cs_user1_id']; } } if (!empty($imInfo['cs_user2_id'])) { - $userIds[] = $imInfo['cs_user2_id']; + $csUserIds[] = $imInfo['cs_user2_id']; if (Gateway::isUidOnline($imInfo['cs_user2_id'])) { $onlineUserIds[] = $imInfo['cs_user2_id']; } } if (!empty($imInfo['cs_user3_id'])) { - $userIds[] = $imInfo['cs_user3_id']; + $csUserIds[] = $imInfo['cs_user3_id']; if (Gateway::isUidOnline($imInfo['cs_user3_id'])) { $onlineUserIds[] = $imInfo['cs_user3_id']; } @@ -65,8 +55,8 @@ class Im extends Service $key = array_rand($onlineUserIds); $userId = $onlineUserIds[$key]; } else { - $key = array_rand($userIds); - $userId = $userIds[$key]; + $key = array_rand($csUserIds); + $userId = $csUserIds[$key]; } return $this->getImUser($userId); diff --git a/app/Http/Web/Services/ImFriendTrait.php b/app/Http/Web/Services/ImFriendTrait.php index a210b721..a187771b 100644 --- a/app/Http/Web/Services/ImFriendTrait.php +++ b/app/Http/Web/Services/ImFriendTrait.php @@ -4,12 +4,12 @@ namespace App\Http\Web\Services; use App\Models\ImFriendGroup as ImFriendGroupModel; use App\Models\ImFriendUser as ImFriendUserModel; -use App\Models\ImSystemMessage as ImSystemMessageModel; +use App\Models\ImNotice as ImNoticeModel; use App\Models\ImUser as ImUserModel; use App\Repos\ImFriendUser as ImFriendUserRepo; use App\Repos\ImUser as ImUserRepo; use App\Validators\ImFriendUser as ImFriendUserValidator; -use App\Validators\ImMessage as ImMessageValidator; +use App\Validators\ImNotice as ImNoticeValidator; use GatewayClient\Gateway; Trait ImFriendTrait @@ -29,7 +29,7 @@ Trait ImFriendTrait $group = $validator->checkGroup($post['group_id']); $remark = $validator->checkRemark($post['remark']); - $validator->checkIfSelf($user->id, $friend->id); + $validator->checkIfSelfApply($user->id, $friend->id); $validator->checkIfJoined($user->id, $friend->id); $this->handleApplyFriendNotice($user, $friend, $group, $remark); @@ -41,22 +41,22 @@ Trait ImFriendTrait $user = $this->getImUser($loginUser->id); - $messageId = $this->request->getPost('message_id'); + $noticeId = $this->request->getPost('notice_id'); $groupId = $this->request->getPost('group_id'); $validator = new ImFriendUserValidator(); $validator->checkGroup($groupId); - $validator = new ImMessageValidator(); + $validator = new ImNoticeValidator(); - $message = $validator->checkMessage($messageId, 'system'); + $notice = $validator->checkNotice($noticeId); - if ($message->item_type != ImSystemMessageModel::TYPE_FRIEND_REQUEST) { + if ($notice->item_type != ImNoticeModel::TYPE_FRIEND_REQUEST) { return; } - $sender = $this->getImUser($message->sender_id); + $sender = $this->getImUser($notice->sender_id); $friendUserRepo = new ImFriendUserRepo(); @@ -77,7 +77,7 @@ Trait ImFriendTrait $friendUser = $friendUserRepo->findFriendUser($sender->id, $user->id); - $groupId = $message->item_info['group']['id'] ?: 0; + $groupId = $notice->item_info['group']['id'] ?: 0; if (!$friendUser) { @@ -92,13 +92,13 @@ Trait ImFriendTrait $this->incrUserFriendCount($sender); } - $itemInfo = $message->item_info; + $itemInfo = $notice->item_info; - $itemInfo['status'] = ImSystemMessageModel::REQUEST_ACCEPTED; + $itemInfo['status'] = ImNoticeModel::REQUEST_ACCEPTED; - $message->update(['item_info' => $itemInfo]); + $notice->update(['item_info' => $itemInfo]); - $this->handleAcceptFriendNotice($user, $sender, $message); + $this->handleAcceptFriendNotice($user, $sender, $notice); } public function refuseFriend() @@ -107,23 +107,23 @@ Trait ImFriendTrait $user = $this->getImUser($loginUser->id); - $messageId = $this->request->getPost('message_id'); + $noticeId = $this->request->getPost('notice_id'); - $validator = new ImMessageValidator(); + $validator = new ImNoticeValidator(); - $message = $validator->checkMessage($messageId, 'system'); + $notice = $validator->checkNotice($noticeId); - if ($message->item_type != ImSystemMessageModel::TYPE_FRIEND_REQUEST) { + if ($notice->item_type != ImNoticeModel::TYPE_FRIEND_REQUEST) { return; } - $itemInfo = $message->item_info; + $itemInfo = $notice->item_info; - $itemInfo['status'] = ImSystemMessageModel::REQUEST_REFUSED; + $itemInfo['status'] = ImNoticeModel::REQUEST_REFUSED; - $message->update(['item_info' => $itemInfo]); + $notice->update(['item_info' => $itemInfo]); - $sender = $this->getImUser($message->sender_id); + $sender = $this->getImUser($notice->sender_id); $this->handleRefuseFriendNotice($user, $sender); } @@ -145,24 +145,24 @@ Trait ImFriendTrait { $userRepo = new ImUserRepo(); - $itemType = ImSystemMessageModel::TYPE_FRIEND_REQUEST; + $itemType = ImNoticeModel::TYPE_FRIEND_REQUEST; - $message = $userRepo->findSystemMessage($receiver->id, $itemType); + $notice = $userRepo->findNotice($receiver->id, $itemType); - if ($message) { - $expired = time() - $message->create_time > 7 * 86400; - $pending = $message->item_info['status'] == ImSystemMessageModel::REQUEST_PENDING; + if ($notice) { + $expired = time() - $notice->create_time > 7 * 86400; + $pending = $notice->item_info['status'] == ImNoticeModel::REQUEST_PENDING; if (!$expired && $pending) { return; } } - $sysMsgModel = new ImSystemMessageModel(); + $noticeModel = new ImNoticeModel(); - $sysMsgModel->sender_id = $sender->id; - $sysMsgModel->receiver_id = $receiver->id; - $sysMsgModel->item_type = ImSystemMessageModel::TYPE_FRIEND_REQUEST; - $sysMsgModel->item_info = [ + $noticeModel->sender_id = $sender->id; + $noticeModel->receiver_id = $receiver->id; + $noticeModel->item_type = ImNoticeModel::TYPE_FRIEND_REQUEST; + $noticeModel->item_info = [ 'sender' => [ 'id' => $sender->id, 'name' => $sender->name, @@ -173,29 +173,31 @@ Trait ImFriendTrait 'name' => $group->name, ], 'remark' => $remark, - 'status' => ImSystemMessageModel::REQUEST_PENDING, + 'status' => ImNoticeModel::REQUEST_PENDING, ]; - $sysMsgModel->create(); + $noticeModel->create(); Gateway::$registerAddress = $this->getRegisterAddress(); $online = Gateway::isUidOnline($receiver->id); if ($online) { + $content = kg_json_encode(['type' => 'refresh_msg_box']); + Gateway::sendToUid($receiver->id, $content); } } - protected function handleAcceptFriendNotice(ImUserModel $sender, ImUserModel $receiver, ImSystemMessageModel $applyMessage) + protected function handleAcceptFriendNotice(ImUserModel $sender, ImUserModel $receiver, ImNoticeModel $applyNotice) { - $sysMsgModel = new ImSystemMessageModel(); + $noticeModel = new ImNoticeModel(); - $sysMsgModel->sender_id = $sender->id; - $sysMsgModel->receiver_id = $receiver->id; - $sysMsgModel->item_type = ImSystemMessageModel::TYPE_FRIEND_ACCEPTED; - $sysMsgModel->item_info = [ + $noticeModel->sender_id = $sender->id; + $noticeModel->receiver_id = $receiver->id; + $noticeModel->item_type = ImNoticeModel::TYPE_FRIEND_ACCEPTED; + $noticeModel->item_info = [ 'sender' => [ 'id' => $sender->id, 'name' => $sender->name, @@ -203,7 +205,7 @@ Trait ImFriendTrait ] ]; - $sysMsgModel->create(); + $noticeModel->create(); Gateway::$registerAddress = $this->getRegisterAddress(); @@ -214,12 +216,12 @@ Trait ImFriendTrait /** * 上层操作更新了item_info,类型发生了变化,故重新获取 */ - $applyMessage->afterFetch(); + $applyNotice->afterFetch(); /** * @var array $itemInfo */ - $itemInfo = $applyMessage->item_info; + $itemInfo = $applyNotice->item_info; $content = kg_json_encode([ 'type' => 'friend_accepted', @@ -240,12 +242,12 @@ Trait ImFriendTrait protected function handleRefuseFriendNotice(ImUserModel $sender, ImUserModel $receiver) { - $sysMsgModel = new ImSystemMessageModel(); + $noticeModel = new ImNoticeModel(); - $sysMsgModel->sender_id = $sender->id; - $sysMsgModel->receiver_id = $receiver->id; - $sysMsgModel->item_type = ImSystemMessageModel::TYPE_FRIEND_REFUSED; - $sysMsgModel->item_info = [ + $noticeModel->sender_id = $sender->id; + $noticeModel->receiver_id = $receiver->id; + $noticeModel->item_type = ImNoticeModel::TYPE_FRIEND_REFUSED; + $noticeModel->item_info = [ 'sender' => [ 'id' => $sender->id, 'name' => $sender->name, @@ -253,14 +255,16 @@ Trait ImFriendTrait ] ]; - $sysMsgModel->create(); + $noticeModel->create(); Gateway::$registerAddress = $this->getRegisterAddress(); $online = Gateway::isUidOnline($receiver->id); if ($online) { + $content = kg_json_encode(['type' => 'refresh_msg_box']); + Gateway::sendToUid($receiver->id, $content); } } @@ -268,6 +272,7 @@ Trait ImFriendTrait protected function incrUserFriendCount(ImUserModel $user) { $user->friend_count += 1; + $user->update(); } @@ -279,10 +284,4 @@ Trait ImFriendTrait } } - protected function incrFriendUserMsgCount(ImFriendUserModel $friendUser) - { - $friendUser->msg_count += 1; - $friendUser->update(); - } - } diff --git a/app/Http/Web/Services/ImGroupTrait.php b/app/Http/Web/Services/ImGroupTrait.php index 2ace2d61..6ca5221e 100644 --- a/app/Http/Web/Services/ImGroupTrait.php +++ b/app/Http/Web/Services/ImGroupTrait.php @@ -4,14 +4,14 @@ namespace App\Http\Web\Services; use App\Models\ImGroup as ImGroupModel; use App\Models\ImGroupUser as ImGroupUserModel; -use App\Models\ImSystemMessage as ImSystemMessageModel; +use App\Models\ImNotice as ImNoticeModel; use App\Models\ImUser as ImUserModel; use App\Repos\ImGroup as ImGroupRepo; use App\Repos\ImGroupUser as ImGroupUserRepo; use App\Repos\ImUser as ImUserRepo; use App\Validators\ImGroup as ImGroupValidator; use App\Validators\ImGroupUser as ImGroupUserValidator; -use App\Validators\ImMessage as ImMessageValidator; +use App\Validators\ImNotice as ImNoticeValidator; use GatewayClient\Gateway; Trait ImGroupTrait @@ -41,17 +41,17 @@ Trait ImGroupTrait $user = $this->getImUser($loginUser->id); - $messageId = $this->request->getPost('message_id'); + $noticeId = $this->request->getPost('notice_id'); - $validator = new ImMessageValidator(); + $validator = new ImNoticeValidator(); - $message = $validator->checkMessage($messageId, 'system'); + $notice = $validator->checkNotice($noticeId, 'system'); - if ($message->item_type != ImSystemMessageModel::TYPE_GROUP_REQUEST) { + if ($notice->item_type != ImNoticeModel::TYPE_GROUP_REQUEST) { return; } - $groupId = $message->item_info['group']['id'] ?: 0; + $groupId = $notice->item_info['group']['id'] ?: 0; $validator = new ImGroupValidator(); @@ -59,7 +59,7 @@ Trait ImGroupTrait $validator->checkOwner($user->id, $group->user_id); - $applicant = $this->getImUser($message->sender_id); + $applicant = $this->getImUser($notice->sender_id); $groupUserRepo = new ImGroupUserRepo(); @@ -79,11 +79,11 @@ Trait ImGroupTrait $this->incrUserGroupCount($applicant); } - $itemInfo = $message->item_info; + $itemInfo = $notice->item_info; - $itemInfo['status'] = ImSystemMessageModel::REQUEST_ACCEPTED; + $itemInfo['status'] = ImNoticeModel::REQUEST_ACCEPTED; - $message->update(['item_info' => $itemInfo]); + $notice->update(['item_info' => $itemInfo]); $this->handleAcceptGroupNotice($user, $applicant, $group); @@ -96,17 +96,17 @@ Trait ImGroupTrait $user = $this->getImUser($loginUser->id); - $messageId = $this->request->getPost('message_id'); + $noticeId = $this->request->getPost('notice_id'); - $validator = new ImMessageValidator(); + $validator = new ImNoticeValidator(); - $message = $validator->checkMessage($messageId, 'system'); + $notice = $validator->checkNotice($noticeId); - if ($message->item_type != ImSystemMessageModel::TYPE_GROUP_REQUEST) { + if ($notice->item_type != ImNoticeModel::TYPE_GROUP_REQUEST) { return; } - $groupId = $message->item_info['group']['id'] ?: 0; + $groupId = $notice->item_info['group']['id'] ?: 0; $validator = new ImGroupValidator(); @@ -114,13 +114,13 @@ Trait ImGroupTrait $validator->checkOwner($user->id, $group->user_id); - $itemInfo = $message->item_info; + $itemInfo = $notice->item_info; - $itemInfo['status'] = ImSystemMessageModel::REQUEST_REFUSED; + $itemInfo['status'] = ImNoticeModel::REQUEST_REFUSED; - $message->update(['item_info' => $itemInfo]); + $notice->update(['item_info' => $itemInfo]); - $sender = $this->getImUser($message->sender_id); + $sender = $this->getImUser($notice->sender_id); $this->handleRefuseGroupNotice($user, $sender); } @@ -150,24 +150,24 @@ Trait ImGroupTrait $receiver = $userRepo->findById($group->owner_id); - $itemType = ImSystemMessageModel::TYPE_GROUP_REQUEST; + $itemType = ImNoticeModel::TYPE_GROUP_REQUEST; - $message = $userRepo->findSystemMessage($receiver->id, $itemType); + $notice = $userRepo->findNotice($receiver->id, $itemType); - if ($message) { - $expired = time() - $message->create_time > 7 * 86400; - $pending = $message->item_info['status'] == ImSystemMessageModel::REQUEST_PENDING; + if ($notice) { + $expired = time() - $notice->create_time > 7 * 86400; + $pending = $notice->item_info['status'] == ImNoticeModel::REQUEST_PENDING; if (!$expired && $pending) { return; } } - $sysMsgModel = new ImSystemMessageModel(); + $noticeModel = new ImNoticeModel(); - $sysMsgModel->sender_id = $sender->id; - $sysMsgModel->receiver_id = $receiver->id; - $sysMsgModel->item_type = ImSystemMessageModel::TYPE_GROUP_REQUEST; - $sysMsgModel->item_info = [ + $noticeModel->sender_id = $sender->id; + $noticeModel->receiver_id = $receiver->id; + $noticeModel->item_type = ImNoticeModel::TYPE_GROUP_REQUEST; + $noticeModel->item_info = [ 'sender' => [ 'id' => $sender->id, 'name' => $sender->name, @@ -178,29 +178,31 @@ Trait ImGroupTrait 'name' => $group->name, ], 'remark' => $remark, - 'status' => ImSystemMessageModel::REQUEST_PENDING, + 'status' => ImNoticeModel::REQUEST_PENDING, ]; - $sysMsgModel->create(); + $noticeModel->create(); Gateway::$registerAddress = $this->getRegisterAddress(); $online = Gateway::isUidOnline($receiver->id); if ($online) { + $content = kg_json_encode(['type' => 'refresh_msg_box']); + Gateway::sendToUid($receiver->id, $content); } } protected function handleAcceptGroupNotice(ImUserModel $sender, ImUserModel $receiver, ImGroupModel $group) { - $sysMsgModel = new ImSystemMessageModel(); + $noticeModel = new ImNoticeModel(); - $sysMsgModel->sender_id = $sender->id; - $sysMsgModel->receiver_id = $receiver->id; - $sysMsgModel->item_type = ImSystemMessageModel::TYPE_GROUP_ACCEPTED; - $sysMsgModel->item_info = [ + $noticeModel->sender_id = $sender->id; + $noticeModel->receiver_id = $receiver->id; + $noticeModel->item_type = ImNoticeModel::TYPE_GROUP_ACCEPTED; + $noticeModel->item_info = [ 'sender' => [ 'id' => $sender->id, 'name' => $sender->name, @@ -208,7 +210,7 @@ Trait ImGroupTrait ] ]; - $sysMsgModel->create(); + $noticeModel->create(); Gateway::$registerAddress = $this->getRegisterAddress(); @@ -231,12 +233,12 @@ Trait ImGroupTrait protected function handleRefuseGroupNotice(ImUserModel $sender, ImUserModel $receiver) { - $sysMsgModel = new ImSystemMessageModel(); + $noticeModel = new ImNoticeModel(); - $sysMsgModel->sender_id = $sender->id; - $sysMsgModel->receiver_id = $receiver->id; - $sysMsgModel->item_type = ImSystemMessageModel::TYPE_GROUP_REFUSED; - $sysMsgModel->item_info = [ + $noticeModel->sender_id = $sender->id; + $noticeModel->receiver_id = $receiver->id; + $noticeModel->item_type = ImNoticeModel::TYPE_GROUP_REFUSED; + $noticeModel->item_info = [ 'sender' => [ 'id' => $sender->id, 'name' => $sender->name, @@ -244,12 +246,14 @@ Trait ImGroupTrait ] ]; - $sysMsgModel->create(); + $noticeModel->create(); Gateway::$registerAddress = $this->getRegisterAddress(); if (Gateway::isUidOnline($receiver->id)) { + $content = kg_json_encode(['type' => 'refresh_msg_box']); + Gateway::sendToUid($receiver->id, $content); } } @@ -289,6 +293,7 @@ Trait ImGroupTrait protected function incrUserGroupCount(ImUserModel $user) { $user->group_count += 1; + $user->update(); } @@ -303,6 +308,7 @@ Trait ImGroupTrait protected function incrGroupUserCount(ImGroupModel $group) { $group->user_count += 1; + $group->update(); } @@ -314,10 +320,4 @@ Trait ImGroupTrait } } - protected function incrGroupMessageCount(ImGroupModel $group) - { - $group->msg_count += 1; - $group->update(); - } - } diff --git a/app/Http/Web/Services/ImMessageTrait.php b/app/Http/Web/Services/ImMessageTrait.php index 0ba858c5..8a91e42d 100644 --- a/app/Http/Web/Services/ImMessageTrait.php +++ b/app/Http/Web/Services/ImMessageTrait.php @@ -4,6 +4,8 @@ namespace App\Http\Web\Services; use App\Builders\ImMessageList as ImMessageListBuilder; use App\Library\Paginator\Query as PagerQuery; +use App\Models\ImFriendUser as ImFriendUserModel; +use App\Models\ImGroup as ImGroupModel; use App\Models\ImMessage as ImMessageModel; use App\Repos\ImFriendUser as ImFriendUserRepo; use App\Repos\ImMessage as ImMessageRepo; @@ -22,12 +24,10 @@ use GatewayClient\Gateway; Trait ImMessageTrait { - public function pullUnreadFriendMessages() + public function pullUnreadFriendMessages($id) { $user = $this->getLoginUser(); - $id = $this->request->getQuery('id'); - $validator = new ImUserValidator(); $friend = $validator->checkUser($id); @@ -113,15 +113,12 @@ Trait ImMessageTrait } } - public function sendChatMessage() + public function sendChatMessage($from, $to) { - $user = $this->getLoginUser(); - - $from = $this->request->getPost('from'); - $to = $this->request->getPost('to'); - $validator = new ImMessageValidator(); + $validator->checkIfSelfChat($from['id'], $to['id']); + $from['content'] = $validator->checkContent($from['content']); $message = [ @@ -146,11 +143,11 @@ Trait ImMessageTrait Gateway::$registerAddress = $this->getRegisterAddress(); - if ($to['type'] == ImMessageModel::TYPE_FRIEND) { + if ($to['type'] == 'friend') { $validator = new ImFriendUserValidator(); - $relation = $validator->checkFriendUser($to['id'], $user->id); + $relation = $validator->checkFriendUser($to['id'], $from['id']); $online = Gateway::isUidOnline($to['id']); @@ -159,7 +156,7 @@ Trait ImMessageTrait $messageModel->create([ 'sender_id' => $from['id'], 'receiver_id' => $to['id'], - 'receiver_type' => $to['type'], + 'receiver_type' => ImMessageModel::TYPE_FRIEND, 'content' => $from['content'], 'viewed' => $online ? 1 : 0, ]); @@ -170,7 +167,9 @@ Trait ImMessageTrait $this->incrFriendUserMsgCount($relation); } - } elseif ($to['type'] == ImMessageModel::TYPE_GROUP) { + } elseif ($to['type'] == 'group') { + + $user = $this->getLoginUser(); $validator = new ImGroupValidator(); @@ -185,11 +184,11 @@ Trait ImMessageTrait $messageModel->create([ 'sender_id' => $from['id'], 'receiver_id' => $to['id'], - 'receiver_type' => $to['type'], + 'receiver_type' => ImMessageModel::TYPE_GROUP, 'content' => $from['content'], ]); - $this->incrGroupMessageCount($group); + $this->incrGroupMsgCount($group); $excludeClientId = null; @@ -200,26 +199,59 @@ Trait ImMessageTrait $excludeClientId = Gateway::getClientIdByUid($user->id); } - $groupName = $this->getGroupName($to['id']); + $groupName = $this->getGroupName($group->id); Gateway::sendToGroup($groupName, $content, $excludeClientId); } } - public function sendCsMessage() + protected function sendCsMessage($from, $to) { - $from = $this->request->getPost('from'); - $to = $this->request->getPost('to'); - $validator = new ImMessageValidator(); - $from['content'] = $validator->checkContent($from['content']); + $validator->checkIfSelfChat($from['id'], $to['id']); - if ($to['id'] > 0) { - $this->sendCsUserMessage($from, $to); - } else { - $this->sendCsRobotMessage($from, $to); + $sender = $this->getImUser($from['id']); + $receiver = $this->getImUser($to['id']); + + $friendUserRepo = new ImFriendUserRepo(); + + $friendUser = $friendUserRepo->findFriendUser($sender->id, $receiver->id); + + if (!$friendUser) { + + $friendUserModel = new ImFriendUserModel(); + + $friendUserModel->create([ + 'user_id' => $sender->id, + 'friend_id' => $receiver->id, + ]); + + $this->incrUserFriendCount($sender); } + + $friendUser = $friendUserRepo->findFriendUser($receiver->id, $sender->id); + + if (!$friendUser) { + + $friendUserModel = new ImFriendUserModel(); + + $friendUserModel->create([ + 'user_id' => $receiver->id, + 'friend_id' => $sender->id, + ]); + + $this->incrUserFriendCount($receiver); + } + + /** + * 统一普通聊天和自定义聊天的用户名字段 + */ + $to['username'] = $to['name']; + + unset($to['name']); + + $this->sendChatMessage($from, $to); } protected function handleChatMessagePager($pager) @@ -251,81 +283,18 @@ Trait ImMessageTrait return $pager; } - /** - * 向客服发送消息,建立临时好友关系 - * - * @param array $from - * @param array $to - */ - protected function sendCsUserMessage($from, $to) + protected function incrFriendUserMsgCount(ImFriendUserModel $friendUser) { - $message = [ - 'username' => $from['username'], - 'avatar' => $from['avatar'], - 'content' => $from['content'], - 'fromid' => $from['id'], - 'id' => $from['id'], - 'type' => $to['type'], - 'timestamp' => 1000 * time(), - 'mine' => false, - ]; + $friendUser->msg_count += 1; - $content = kg_json_encode([ - 'type' => 'show_cs_msg', - 'message' => $message, - ]); - - Gateway::$registerAddress = $this->getRegisterAddress(); - - $online = Gateway::isUidOnline($to['id']); - - $messageModel = new ImMessageModel(); - - $messageModel->create([ - 'sender_id' => $from['id'], - 'receiver_id' => $to['id'], - 'receiver_type' => $to['type'], - 'content' => $from['content'], - 'viewed' => $online ? 1 : 0, - ]); - - if ($online) { - Gateway::sendToUid($to['id'], $content); - } + $friendUser->update(); } - /** - * 向机器人发送消息,机器人自动应答 - * - * @param array $from - * @param array $to - */ - protected function sendCsRobotMessage($from, $to) + protected function incrGroupMsgCount(ImGroupModel $group) { - /** - * @todo 从腾讯平台获取应答内容 - */ - $content = '不知道你在说什么...'; + $group->msg_count += 1; - $message = [ - 'username' => $to['name'], - 'avatar' => $to['avatar'], - 'content' => $content, - 'fromid' => $to['id'], - 'id' => $to['id'], - 'type' => $to['type'], - 'timestamp' => 1000 * time(), - 'mine' => false, - ]; - - $content = kg_json_encode([ - 'type' => 'show_cs_msg', - 'message' => $message, - ]); - - Gateway::$registerAddress = $this->getRegisterAddress(); - - Gateway::sendToUid($from['id'], $content); + $group->update(); } } \ No newline at end of file diff --git a/app/Http/Web/Services/ImStatTrait.php b/app/Http/Web/Services/ImStatTrait.php new file mode 100644 index 00000000..d0fa379b --- /dev/null +++ b/app/Http/Web/Services/ImStatTrait.php @@ -0,0 +1,28 @@ +getParams(); - - $params['published'] = 1; - - $sort = $pagerQuery->getSort(); - $page = $pagerQuery->getPage(); - $limit = $pagerQuery->getLimit(); - - $groupRepo = new ImGroupRepo(); - - $pager = $groupRepo->paginate($params, $sort, $page, $limit); - - return $this->handleGroups($pager); - } - - public function getActiveUsers() - { - } - - public function getOnlineUsers() - { - } - - protected function handleGroups($pager) - { - if ($pager->total_items == 0) { - return $pager; - } - - $builder = new ImGroupListBuilder(); - - $groups = $pager->items->toArray(); - - $users = $builder->getUsers($groups); - - $baseUrl = kg_ci_base_url(); - - $items = []; - - foreach ($groups as $group) { - - $group['avatar'] = $baseUrl . $group['avatar']; - $group['owner'] = $users[$group['owner_id']] ?? new \stdClass(); - - $items[] = [ - 'id' => $group['id'], - 'type' => $group['type'], - 'name' => $group['name'], - 'avatar' => $group['avatar'], - 'about' => $group['about'], - 'user_count' => $group['user_count'], - 'msg_count' => $group['msg_count'], - 'owner' => $group['owner'], - ]; - } - - $pager->items = $items; - - return $pager; - } - -} diff --git a/app/Http/Web/Views/help/index.volt b/app/Http/Web/Views/help/index.volt index 32bb00a8..3b349e3b 100644 --- a/app/Http/Web/Views/help/index.volt +++ b/app/Http/Web/Views/help/index.volt @@ -19,7 +19,8 @@
@@ -29,15 +30,24 @@
-
-
意见反馈
+
+
客户服务
-
- -
+

没解决你的疑问?试试联系客服吧!

+ {% if im_info.cs.enabled == 1 %} +

+ +

+ {% endif %}
+{% endblock %} + +{% block include_js %} + + {{ js_include('web/js/help.js') }} + {% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/im/cs.volt b/app/Http/Web/Views/im/cs.volt index 3ddcbfe9..f7e3b039 100644 --- a/app/Http/Web/Views/im/cs.volt +++ b/app/Http/Web/Views/im/cs.volt @@ -1,14 +1,7 @@ -{% extends 'templates/main.volt' %} +{% extends 'templates/layer.volt' %} {% block content %} - -
diff --git a/app/Http/Web/Views/im/group/pager.volt b/app/Http/Web/Views/im/group/pager.volt index d08bf272..f90b7510 100644 --- a/app/Http/Web/Views/im/group/pager.volt +++ b/app/Http/Web/Views/im/group/pager.volt @@ -1,36 +1,40 @@ -{% if pager.total_pages > 0 %} -
-
- {% for item in pager.items %} - {% set group_url = url({'for':'web.group.show','id':item.id}) %} - {% set owner_url = url({'for':'web.user.show','id':item.owner.id}) %} - {% set item.about = item.about ? item.about : '这家伙真懒,什么都没留下!' %} -
-
- {% if item.type == 'course' %} - - {% elseif item.type == 'chat' %} - - {% endif %} -
- - {{ item.name }} - -
- -
- 组长:{{ item.owner.name }} -
-
- 成员:{{ item.user_count }} - 讨论:{{ item.msg_count }} -
+{%- macro type_info(value) %} + {% if value == 'course' %} + + {% elseif value == 'chat' %} + + {% elseif value == 'staff' %} + + {% endif %} +{%- endmacro %} + +
+
+ {% for item in pager.items %} + {% set group_url = url({'for':'web.group.show','id':item.id}) %} + {% set owner_url = url({'for':'web.user.show','id':item.owner.id}) %} + {% set item.about = item.about ? item.about : '这家伙真懒,什么都没留下!' %} +
+
+ {{ type_info(item.type) }} +
+ + {{ item.name }} + +
+ +
+ 组长:{{ item.owner.name }} +
+
+ 成员:{{ item.user_count }} + 讨论:{{ item.msg_count }}
- {% endfor %} -
+
+ {% endfor %}
- {{ partial('partials/pager_ajax') }} -{% endif %} \ No newline at end of file +
+{{ partial('partials/pager_ajax') }} \ No newline at end of file diff --git a/app/Http/Web/Views/im/index.volt b/app/Http/Web/Views/im/index.volt index 643773af..185f77ea 100644 --- a/app/Http/Web/Views/im/index.volt +++ b/app/Http/Web/Views/im/index.volt @@ -2,6 +2,23 @@ {% block content %} +
+
+
    +
  • 活跃群组
  • +
  • 活跃用户
  • +
  • 新进群组
  • +
  • 新进用户
  • +
+
+
+
+
+
+
+
+
+ {% endblock %} {% block include_js %} diff --git a/app/Http/Web/Views/im/robot.volt b/app/Http/Web/Views/im/robot.volt deleted file mode 100644 index 5d2b79ba..00000000 --- a/app/Http/Web/Views/im/robot.volt +++ /dev/null @@ -1,25 +0,0 @@ -{% extends 'templates/main.volt' %} - -{% block content %} - - - -
- - - - -
- -{% endblock %} - -{% block include_js %} - - {{ js_include('web/js/im.cs.js') }} - -{% endblock %} \ No newline at end of file diff --git a/app/Http/Web/Views/order/info.volt b/app/Http/Web/Views/order/info.volt index 63c2e2da..e9e2000e 100644 --- a/app/Http/Web/Views/order/info.volt +++ b/app/Http/Web/Views/order/info.volt @@ -20,7 +20,7 @@
-
+
{% if order.status == 'pending' %} 立即支付 {% endif %} diff --git a/app/Http/Web/Views/partials/js_global_vars.volt b/app/Http/Web/Views/partials/js_global_vars.volt index f4a37f0d..d094031d 100644 --- a/app/Http/Web/Views/partials/js_global_vars.volt +++ b/app/Http/Web/Views/partials/js_global_vars.volt @@ -13,9 +13,6 @@ cs: { enabled: '{{ im_info.cs.enabled }}' }, - robot: { - enabled: '{{ im_info.robot.enabled }}' - }, websocket: { url: '{{ im_info.websocket.url }}' } diff --git a/app/Http/Web/Views/refund/confirm.volt b/app/Http/Web/Views/refund/confirm.volt index d31a6459..809d3fec 100644 --- a/app/Http/Web/Views/refund/confirm.volt +++ b/app/Http/Web/Views/refund/confirm.volt @@ -46,13 +46,13 @@

-
+
{% else %} -
没有符合条件的退款项目
+
没有符合条件的退款项目
{% endif %} {% endblock %} diff --git a/app/Http/Web/Views/refund/info.volt b/app/Http/Web/Views/refund/info.volt index 5f8a8d85..5135235c 100644 --- a/app/Http/Web/Views/refund/info.volt +++ b/app/Http/Web/Views/refund/info.volt @@ -20,7 +20,7 @@
-
+
{% if refund.status == 'approved' %} {% endif %} diff --git a/app/Http/Web/Views/teaching/live_push.volt b/app/Http/Web/Views/teaching/live_push.volt index ce8b2350..3aee4112 100644 --- a/app/Http/Web/Views/teaching/live_push.volt +++ b/app/Http/Web/Views/teaching/live_push.volt @@ -7,7 +7,7 @@ 手机推流
-
+
二维码图片
diff --git a/app/Http/Web/Views/templates/layer.volt b/app/Http/Web/Views/templates/layer.volt index fd226500..478951ab 100644 --- a/app/Http/Web/Views/templates/layer.volt +++ b/app/Http/Web/Views/templates/layer.volt @@ -15,6 +15,7 @@ {% block content %}{% endblock %} +{{ partial('partials/js_global_vars') }} {{ js_include('lib/layui/layui.js') }} {{ js_include('web/js/common.js') }} diff --git a/app/Models/ImMessage.php b/app/Models/ImMessage.php index 90ff0309..4f959bc0 100644 --- a/app/Models/ImMessage.php +++ b/app/Models/ImMessage.php @@ -7,8 +7,11 @@ use Phalcon\Mvc\Model\Behavior\SoftDelete; class ImMessage extends Model { - const TYPE_FRIEND = 'friend'; - const TYPE_GROUP = 'group'; + /** + * 接受者类型 + */ + const TYPE_FRIEND = 1; // 好友 + const TYPE_GROUP = 2; // 群组 /** * 主键编号 @@ -101,7 +104,9 @@ class ImMessage extends Model { $this->create_time = time(); - if ($this->chat_type == self::TYPE_FRIEND) { + $this->chat_id = 0; + + if ($this->receiver_type == self::TYPE_FRIEND) { $this->chat_id = self::getChatId($this->sender_id, $this->receiver_id); } } diff --git a/app/Services/Syncer/CourseIndex.php b/app/Services/Syncer/CourseIndex.php index 57b78488..5101ff01 100644 --- a/app/Services/Syncer/CourseIndex.php +++ b/app/Services/Syncer/CourseIndex.php @@ -41,7 +41,7 @@ class CourseIndex extends Service public function getSyncKey() { - return 'sync:course_index'; + return 'sync_course_index'; } } diff --git a/app/Services/Syncer/GroupIndex.php b/app/Services/Syncer/GroupIndex.php index 2dc2c144..4b6e43c8 100644 --- a/app/Services/Syncer/GroupIndex.php +++ b/app/Services/Syncer/GroupIndex.php @@ -41,7 +41,7 @@ class GroupIndex extends Service public function getSyncKey() { - return 'sync:group_index'; + return 'sync_group_index'; } } diff --git a/app/Services/Syncer/Learning.php b/app/Services/Syncer/Learning.php index 69c8e502..4a82164f 100644 --- a/app/Services/Syncer/Learning.php +++ b/app/Services/Syncer/Learning.php @@ -79,7 +79,7 @@ class Learning extends Service public function getSyncKey() { - return 'sync:learning'; + return 'sync_learning'; } } diff --git a/app/Services/Syncer/UserIndex.php b/app/Services/Syncer/UserIndex.php index e76aded9..03a50138 100644 --- a/app/Services/Syncer/UserIndex.php +++ b/app/Services/Syncer/UserIndex.php @@ -41,7 +41,7 @@ class UserIndex extends Service public function getSyncKey() { - return 'sync:user_index'; + return 'sync_user_index'; } } diff --git a/app/Validators/ImFriendUser.php b/app/Validators/ImFriendUser.php index 92c9dc80..c30c2061 100644 --- a/app/Validators/ImFriendUser.php +++ b/app/Validators/ImFriendUser.php @@ -61,7 +61,7 @@ class ImFriendUser extends Validator return $record; } - public function checkIfSelf($userId, $friendId) + public function checkIfSelfApply($userId, $friendId) { if ($userId == $friendId) { throw new BadRequestException('im_friend_user.self_apply'); diff --git a/app/Validators/ImMessage.php b/app/Validators/ImMessage.php index 6da5dc8a..c9838b30 100644 --- a/app/Validators/ImMessage.php +++ b/app/Validators/ImMessage.php @@ -3,29 +3,16 @@ namespace App\Validators; use App\Exceptions\BadRequest as BadRequestException; -use App\Repos\ImFriendMessage as ImFriendMessageRepo; -use App\Repos\ImGroupMessage as ImGroupMessageRepo; -use App\Repos\ImSystemMessage as ImSystemMessageRepo; +use App\Repos\ImMessage as ImMessageRepo; class ImMessage extends Validator { - public function checkMessage($id, $type) + public function checkMessage($id) { - $this->checkType($type); + $repo = new ImMessageRepo(); - $message = null; - - if ($type == 'friend') { - $repo = new ImFriendMessageRepo(); - $message = $repo->findById($id); - } elseif ($type == 'group') { - $repo = new ImGroupMessageRepo(); - $message = $repo->findById($id); - } elseif ($type == 'system') { - $repo = new ImSystemMessageRepo(); - $message = $repo->findById($id); - } + $message = $repo->findById($id); if (!$message) { throw new BadRequestException('im_message.not_found'); @@ -36,7 +23,7 @@ class ImMessage extends Validator public function checkType($type) { - if (!in_array($type, ['friend', 'group', 'system'])) { + if (!in_array($type, ['friend', 'group'])) { throw new BadRequestException('im_message.invalid_type'); } @@ -60,4 +47,11 @@ class ImMessage extends Validator return $value; } + public function checkIfSelfChat($fromId, $toId) + { + if ($fromId == $toId) { + throw new BadRequestException('im_message.self_chat'); + } + } + } diff --git a/app/Validators/ImNotice.php b/app/Validators/ImNotice.php new file mode 100644 index 00000000..7228afa9 --- /dev/null +++ b/app/Validators/ImNotice.php @@ -0,0 +1,41 @@ +findById($id); + + if (!$notice) { + throw new BadRequestException('im_notice.not_found'); + } + + return $notice; + } + + public function checkContent($content) + { + $value = $this->filter->sanitize($content, ['trim', 'string']); + + $length = kg_strlen($value); + + if ($length < 1) { + throw new BadRequestException('im_notice.content_too_short'); + } + + if ($length > 1000) { + throw new BadRequestException('im_notice.content_too_long'); + } + + return $value; + } + +} diff --git a/config/errors.php b/config/errors.php index 522b64ef..41f58b97 100644 --- a/config/errors.php +++ b/config/errors.php @@ -349,5 +349,6 @@ $error['im_message.not_found'] = '消息不存在'; $error['im_message.invalid_type'] = '无效的消息类型'; $error['im_message.content_too_short'] = '消息内容太短(少于1字符)'; $error['im_message.content_too_long'] = '消息内容太长(超过1000字符)'; +$error['im_message.self_chat'] = '不能给自己发送消息'; return $error; diff --git a/public/static/admin/css/common.css b/public/static/admin/css/common.css index e9c99a37..52a6422d 100644 --- a/public/static/admin/css/common.css +++ b/public/static/admin/css/common.css @@ -18,7 +18,7 @@ cursor: pointer; } -.kg-text-center { +.kg-center { text-align: center; } diff --git a/public/static/lib/layui/extends/helper.js b/public/static/lib/layui/extends/helper.js index b010ac53..717685c7 100644 --- a/public/static/lib/layui/extends/helper.js +++ b/public/static/lib/layui/extends/helper.js @@ -23,6 +23,15 @@ layui.define(['jquery', 'layer'], function (exports) { callback(); }; + helper.cs = function () { + layer.open({ + type: 2, + title: '在线客服', + area: ['600px', '560px'], + content: ['/im/cs', 'no'] + }); + }; + helper.getRequestId = function () { var id = Date.now().toString(36); id += Math.random().toString(36).substr(3); diff --git a/public/static/web/css/common.css b/public/static/web/css/common.css index de64322e..5e3ddd03 100644 --- a/public/static/web/css/common.css +++ b/public/static/web/css/common.css @@ -34,7 +34,7 @@ padding: 20px; } -.text-center { +.center { text-align: center; } @@ -193,6 +193,10 @@ body { line-height: 30px; } +.cs-sidebar p { + line-height: 40px; +} + .index-wrap .layui-tab { margin-bottom: 0; } diff --git a/public/static/web/js/fixbar.js b/public/static/web/js/fixbar.js index d2ca44b8..44ee9508 100644 --- a/public/static/web/js/fixbar.js +++ b/public/static/web/js/fixbar.js @@ -1,19 +1,16 @@ -layui.use(['jquery', 'util'], function () { +layui.use(['helper', 'util'], function () { - var $ = layui.jquery; + var helper = layui.helper; var util = layui.util; - var csEnabled = $('input[name="im.cs.enabled"]').val(); - var robotEnabled = $('input[name="im.robot.enabled"]').val(); - util.fixbar({ - bar1: csEnabled === '1' ? '' : false, - bar2: robotEnabled === '1' ? '' : false, + bar1: window.im.cs.enabled === '1', + bar2: true, click: function (type) { if (type === 'bar1') { - window.open('/im/cs', 'cs'); + helper.cs(); } else if (type === 'bar2') { - window.open('/im/robot', 'robot'); + window.open('/help', 'help'); } } }); diff --git a/public/static/web/js/help.js b/public/static/web/js/help.js new file mode 100644 index 00000000..0ccee9c2 --- /dev/null +++ b/public/static/web/js/help.js @@ -0,0 +1,10 @@ +layui.use(['jquery', 'helper'], function () { + + var $ = layui.jquery; + var helper = layui.helper; + + $('.btn-cs').on('click', function () { + helper.cs(); + }); + +}); \ No newline at end of file diff --git a/public/static/web/js/im.cs.js b/public/static/web/js/im.cs.js index b5bb80f4..e2c821ea 100644 --- a/public/static/web/js/im.cs.js +++ b/public/static/web/js/im.cs.js @@ -37,8 +37,8 @@ layui.use(['jquery', 'layim'], function () { socket.send('pong...'); } else if (data.type === 'bind_user') { bindUser(data); - } else if (data.type === 'show_cs_msg') { - showCsMessage(data); + } else if (data.type === 'show_chat_msg') { + showChatMessage(data); } }; @@ -77,7 +77,6 @@ layui.use(['jquery', 'layim'], function () { } function sendCsMessage(res) { - console.log(res); $.ajax({ type: 'POST', url: '/im/msg/cs/send', @@ -85,7 +84,7 @@ layui.use(['jquery', 'layim'], function () { }); } - function showCsMessage(res) { + function showChatMessage(res) { layim.getMessage(res.message); } diff --git a/public/static/web/js/im.msgbox.js b/public/static/web/js/im.msgbox.js index ff7a083c..a1420e77 100644 --- a/public/static/web/js/im.msgbox.js +++ b/public/static/web/js/im.msgbox.js @@ -60,7 +60,7 @@ layui.use(['jquery', 'layer', 'laypage'], function () { type: 'POST', url: '/im/friend/accept', data: { - message_id: li.data('id'), + notice_id: li.data('id'), group_id: group }, success: function () { @@ -85,7 +85,7 @@ layui.use(['jquery', 'layer', 'laypage'], function () { $.ajax({ type: 'POST', url: '/im/friend/refuse', - data: {message_id: li.data('id')}, + data: {notice_id: li.data('id')}, success: function () { layer.close(index); othis.parent().html('已拒绝'); @@ -98,7 +98,7 @@ layui.use(['jquery', 'layer', 'laypage'], function () { $.ajax({ type: 'POST', url: '/im/group/accept', - data: {message_id: li.data('id')}, + data: {notice_id: li.data('id')}, success: function () { othis.parent().html('已同意'); } @@ -110,7 +110,7 @@ layui.use(['jquery', 'layer', 'laypage'], function () { $.ajax({ type: 'POST', url: '/im/group/refuse', - data: {message_id: li.data('id')}, + data: {notice_id: li.data('id')}, success: function () { layer.close(index); othis.parent().html('已拒绝');