diff --git a/CHANGELOG.md b/CHANGELOG.md index 00dd33e0..51ce29a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +### [v1.3.3](https://gitee.com/koogua/course-tencent-cloud/releases/v1.3.3)(2021-04-30) + +### 更新 + +- 前台增加文章发布功能 +- 增加文章,咨询,评价,评论相关事件站内提醒 +- 增加文章,咨询,评价,评论事件埋点 +- 后台首页增加若干统计项目 +- 后台增加文章审核功能 +- 重构积分历史记录 +- 优化在线统计方式 +- 优化前台界面 + ### [v1.3.2](https://gitee.com/koogua/course-tencent-cloud/releases/v1.3.2)(2021-04-20) ### 更新 diff --git a/app/Caches/ArticleRelatedList.php b/app/Caches/ArticleRelatedList.php index de602a27..78c97f4b 100644 --- a/app/Caches/ArticleRelatedList.php +++ b/app/Caches/ArticleRelatedList.php @@ -40,7 +40,7 @@ class ArticleRelatedList extends Cache $where = [ 'tag_id' => $tagIds[$randKey], - 'published' => 1, + 'published' => ArticleModel::PUBLISH_APPROVED, ]; $pager = $articleRepo->paginate($where); diff --git a/app/Http/Admin/Services/AuthNode.php b/app/Http/Admin/Services/AuthNode.php index 6c955e12..1c7871e3 100644 --- a/app/Http/Admin/Services/AuthNode.php +++ b/app/Http/Admin/Services/AuthNode.php @@ -140,36 +140,36 @@ class AuthNode extends Service ], [ 'id' => '1-4', - 'title' => '话题管理', + 'title' => '专题管理', 'type' => 'menu', 'children' => [ [ 'id' => '1-4-1', - 'title' => '话题列表', + 'title' => '专题列表', 'type' => 'menu', 'route' => 'admin.topic.list', ], [ 'id' => '1-4-5', - 'title' => '搜索话题', + 'title' => '搜索专题', 'type' => 'menu', 'route' => 'admin.topic.search', ], [ 'id' => '1-4-2', - 'title' => '添加话题', + 'title' => '添加专题', 'type' => 'menu', 'route' => 'admin.topic.add', ], [ 'id' => '1-4-3', - 'title' => '编辑话题', + 'title' => '编辑专题', 'type' => 'button', 'route' => 'admin.topic.edit', ], [ 'id' => '1-4-4', - 'title' => '删除话题', + 'title' => '删除专题', 'type' => 'button', 'route' => 'admin.topic.delete', ], diff --git a/app/Http/Admin/Views/topic/add.volt b/app/Http/Admin/Views/topic/add.volt index ccda82ce..e470d1cb 100644 --- a/app/Http/Admin/Views/topic/add.volt +++ b/app/Http/Admin/Views/topic/add.volt @@ -4,7 +4,7 @@
- 添加话题 + 添加专题
diff --git a/app/Http/Admin/Views/topic/edit.volt b/app/Http/Admin/Views/topic/edit.volt index 5b09f72f..681d128f 100644 --- a/app/Http/Admin/Views/topic/edit.volt +++ b/app/Http/Admin/Views/topic/edit.volt @@ -4,7 +4,7 @@
- 编辑话题 + 编辑专题
diff --git a/app/Http/Admin/Views/topic/list.volt b/app/Http/Admin/Views/topic/list.volt index fb7f0bc1..522e6975 100644 --- a/app/Http/Admin/Views/topic/list.volt +++ b/app/Http/Admin/Views/topic/list.volt @@ -8,15 +8,15 @@ diff --git a/app/Http/Admin/Views/topic/search.volt b/app/Http/Admin/Views/topic/search.volt index 7a4c97c5..96577795 100644 --- a/app/Http/Admin/Views/topic/search.volt +++ b/app/Http/Admin/Views/topic/search.volt @@ -4,7 +4,7 @@
- 搜索话题 + 搜索专题
diff --git a/app/Http/Api/Controllers/UserConsoleController.php b/app/Http/Api/Controllers/UserConsoleController.php index f4da2585..2d921bc7 100644 --- a/app/Http/Api/Controllers/UserConsoleController.php +++ b/app/Http/Api/Controllers/UserConsoleController.php @@ -11,6 +11,7 @@ use App\Services\Logic\User\Console\GroupList as GroupListService; use App\Services\Logic\User\Console\NotificationList as NotificationListService; use App\Services\Logic\User\Console\NotificationRead as NotificationReadService; use App\Services\Logic\User\Console\NotifyStats as NotifyStatsService; +use App\Services\Logic\User\Console\Online as OnlineService; use App\Services\Logic\User\Console\OrderList as OrderListService; use App\Services\Logic\User\Console\ProfileInfo as ProfileInfoService; use App\Services\Logic\User\Console\ProfileUpdate as ProfileUpdateService; @@ -183,4 +184,16 @@ class UserConsoleController extends Controller return $this->jsonSuccess(); } + /** + * @Post("/online", name="api.uc.online") + */ + public function onlineAction() + { + $service = new OnlineService(); + + $service->handle(); + + return $this->jsonSuccess(); + } + } diff --git a/app/Http/Home/Controllers/UserConsoleController.php b/app/Http/Home/Controllers/UserConsoleController.php index a95aa086..c38d6209 100644 --- a/app/Http/Home/Controllers/UserConsoleController.php +++ b/app/Http/Home/Controllers/UserConsoleController.php @@ -18,6 +18,7 @@ use App\Services\Logic\User\Console\GroupList as GroupListService; use App\Services\Logic\User\Console\NotificationList as NotificationListService; use App\Services\Logic\User\Console\NotificationRead as NotificationReadService; use App\Services\Logic\User\Console\NotifyStats as NotifyStatsService; +use App\Services\Logic\User\Console\Online as OnlineService; use App\Services\Logic\User\Console\OrderList as OrderListService; use App\Services\Logic\User\Console\PointHistory as PointHistoryService; use App\Services\Logic\User\Console\PointRedeemList as PointRedeemListService; @@ -369,4 +370,16 @@ class UserConsoleController extends Controller return $this->jsonSuccess($content); } + /** + * @Post("/online", name="home.uc.online") + */ + public function onlineAction() + { + $service = new OnlineService(); + + $service->handle(); + + return $this->jsonSuccess(); + } + } diff --git a/app/Listeners/Site.php b/app/Listeners/Site.php index c4a870e7..088d7756 100644 --- a/app/Listeners/Site.php +++ b/app/Listeners/Site.php @@ -2,11 +2,7 @@ namespace App\Listeners; -use App\Library\Utils\Lock as LockUtil; -use App\Models\Online as OnlineModel; use App\Models\User as UserModel; -use App\Repos\Online as OnlineRepo; -use App\Services\Logic\Point\History\SiteVisit as SiteVisitPointHistory; use App\Traits\Client as ClientTrait; use Phalcon\Events\Event as PhEvent; @@ -17,102 +13,7 @@ class Site extends Listener public function afterView(PhEvent $event, $source, UserModel $user) { - if ($user->id > 0) { - $this->handleOnline($user); - - $this->handleVisitPoint($user); - - /** - * 更新会重置afterFetch,重新执行 - */ - $user->afterFetch(); - } - } - - protected function handleOnline(UserModel $user) - { - $now = time(); - - if ($now - $user->active_time < 900) { - return; - } - - $itemId = "user_online:{$user->id}"; - - $clientType = $this->getClientType(); - $clientIp = $this->getClientIp(); - - $lockId = LockUtil::addLock($itemId); - - if ($lockId === false) return; - - $user->active_time = $now; - - $user->update(); - - $onlineRepo = new OnlineRepo(); - - $records = $onlineRepo->findByUserDate($user->id, date('Ymd')); - - if ($records->count() > 0) { - $online = null; - foreach ($records as $record) { - $case1 = $record->client_type == $clientType; - $case2 = $record->client_ip == $clientIp; - if ($case1 && $case2) { - $online = $record; - break; - } - } - if ($online) { - $online->active_time = $now; - $online->update(); - } else { - $this->createOnline($user->id, $clientType, $clientIp); - } - } else { - $this->createOnline($user->id, $clientType, $clientIp); - } - - LockUtil::releaseLock($itemId, $lockId); - } - - protected function createOnline($userId, $clientType, $clientIp) - { - $online = new OnlineModel(); - - $online->user_id = $userId; - $online->client_type = $clientType; - $online->client_ip = $clientIp; - $online->active_time = time(); - - $online->create(); - - return $online; - } - - protected function handleVisitPoint(UserModel $user) - { - $todayDate = date('Ymd'); - - $keyName = sprintf('site_visit:%s:%s', $user->id, $todayDate); - - $cache = $this->getCache(); - - $content = $cache->get($keyName); - - if ($content) return; - - $service = new SiteVisitPointHistory(); - - $service->handle($user); - - $tomorrow = strtotime($todayDate) + 86400; - - $lifetime = $tomorrow - time(); - - $cache->save($keyName, 1, $lifetime); } } \ No newline at end of file diff --git a/app/Models/Reason.php b/app/Models/Reason.php index 1be969b6..8ff03c0a 100644 --- a/app/Models/Reason.php +++ b/app/Models/Reason.php @@ -16,9 +16,10 @@ class Reason 106 => '低俗色情', 107 => '广告软文', 108 => '封面反感', - 109 => '抄袭他人作品', - 110 => '涉嫌非法集资', - 111 => '其它问题', + 109 => '归类与主题不符', + 110 => '抄袭他人作品', + 111 => '内容涉嫌违法', + 112 => '其它问题', ]; } diff --git a/app/Services/Logic/Article/ArticleInfo.php b/app/Services/Logic/Article/ArticleInfo.php index 53d336bb..bbf6c933 100644 --- a/app/Services/Logic/Article/ArticleInfo.php +++ b/app/Services/Logic/Article/ArticleInfo.php @@ -60,6 +60,7 @@ class ArticleInfo extends LogicService 'comment_count' => $article->comment_count, 'favorite_count' => $article->favorite_count, 'create_time' => $article->create_time, + 'update_time' => $article->update_time, ]; } diff --git a/app/Services/Logic/Article/ArticleList.php b/app/Services/Logic/Article/ArticleList.php index 907eb892..07ffcd70 100644 --- a/app/Services/Logic/Article/ArticleList.php +++ b/app/Services/Logic/Article/ArticleList.php @@ -21,6 +21,7 @@ class ArticleList extends LogicService $params = $this->checkQueryParams($params); $params['published'] = ArticleModel::PUBLISH_APPROVED; + $params['private'] = 0; $params['deleted'] = 0; $sort = $pagerQuery->getSort(); diff --git a/app/Services/Logic/Article/CommentList.php b/app/Services/Logic/Article/CommentList.php index 2f311af2..194cec1c 100644 --- a/app/Services/Logic/Article/CommentList.php +++ b/app/Services/Logic/Article/CommentList.php @@ -23,9 +23,9 @@ class CommentList extends LogicService $params = $pagerQuery->getParams(); - $params['item_type'] = CommentModel::ITEM_ARTICLE; $params['item_id'] = $article->id; - $params['published'] = 1; + $params['item_type'] = CommentModel::ITEM_ARTICLE; + $params['published'] = CommentModel::PUBLISH_APPROVED; $sort = $pagerQuery->getSort(); $page = $pagerQuery->getPage(); diff --git a/app/Services/Logic/Chapter/CommentList.php b/app/Services/Logic/Chapter/CommentList.php index beca7675..f1ebe80e 100644 --- a/app/Services/Logic/Chapter/CommentList.php +++ b/app/Services/Logic/Chapter/CommentList.php @@ -23,9 +23,9 @@ class CommentList extends LogicService $params = $pagerQuery->getParams(); - $params['item_type'] = CommentModel::ITEM_CHAPTER; $params['item_id'] = $chapter->id; - $params['published'] = 1; + $params['item_type'] = CommentModel::ITEM_CHAPTER; + $params['published'] = CommentModel::PUBLISH_APPROVED; $sort = $pagerQuery->getSort(); $page = $pagerQuery->getPage(); diff --git a/app/Services/Logic/Comment/CommentListTrait.php b/app/Services/Logic/Comment/CommentListTrait.php index bef84037..908b5d4f 100644 --- a/app/Services/Logic/Comment/CommentListTrait.php +++ b/app/Services/Logic/Comment/CommentListTrait.php @@ -37,6 +37,7 @@ trait CommentListTrait 'like_count' => $comment['like_count'], 'reply_count' => $comment['reply_count'], 'create_time' => $comment['create_time'], + 'update_time' => $comment['update_time'], 'to_user' => $toUser, 'owner' => $owner, 'me' => $me, diff --git a/app/Services/Logic/Course/ConsultListTrait.php b/app/Services/Logic/Course/ConsultListTrait.php index 2ea63229..d6d97699 100644 --- a/app/Services/Logic/Course/ConsultListTrait.php +++ b/app/Services/Logic/Course/ConsultListTrait.php @@ -36,6 +36,7 @@ trait ConsultListTrait 'like_count' => $consult['like_count'], 'reply_time' => $consult['reply_time'], 'create_time' => $consult['create_time'], + 'update_time' => $consult['update_time'], 'owner' => $owner, 'me' => $me, ]; diff --git a/app/Services/Logic/Course/ReviewList.php b/app/Services/Logic/Course/ReviewList.php index 5c198a19..d3979015 100644 --- a/app/Services/Logic/Course/ReviewList.php +++ b/app/Services/Logic/Course/ReviewList.php @@ -63,6 +63,7 @@ class ReviewList extends LogicService 'content' => $review['content'], 'like_count' => $review['like_count'], 'create_time' => $review['create_time'], + 'update_time' => $review['update_time'], 'owner' => $owner, 'me' => $me, ]; diff --git a/app/Services/Logic/User/ArticleList.php b/app/Services/Logic/User/ArticleList.php index 0e856e1a..ad596aa8 100644 --- a/app/Services/Logic/User/ArticleList.php +++ b/app/Services/Logic/User/ArticleList.php @@ -3,6 +3,7 @@ namespace App\Services\Logic\User; use App\Library\Paginator\Query as PagerQuery; +use App\Models\Article as ArticleModel; use App\Repos\Article as ArticleRepo; use App\Services\Logic\Article\ArticleList as ArticleListService; use App\Services\Logic\Service as LogicService; @@ -22,7 +23,9 @@ class ArticleList extends LogicService $params = $pagerQuery->getParams(); $params['owner_id'] = $user->id; - $params['published'] = 1; + $params['published'] = ArticleModel::PUBLISH_APPROVED; + $params['private'] = 0; + $params['deleted'] = 0; $sort = $pagerQuery->getSort(); $page = $pagerQuery->getPage(); diff --git a/app/Services/Logic/User/Console/Online.php b/app/Services/Logic/User/Console/Online.php new file mode 100644 index 00000000..285fd700 --- /dev/null +++ b/app/Services/Logic/User/Console/Online.php @@ -0,0 +1,101 @@ +getLoginUser(); + + $this->handleVisitLog($user); + + $this->handleVisitPoint($user); + } + + protected function handleVisitLog(UserModel $user) + { + $now = time(); + + if ($now - $user->active_time < 900) return; + + $user->active_time = $now; + + $user->update(); + + $onlineRepo = new OnlineRepo(); + + $records = $onlineRepo->findByUserDate($user->id, date('Ymd')); + + $clientType = $this->getClientType(); + $clientIp = $this->getClientIp(); + + if ($records->count() > 0) { + $online = null; + foreach ($records as $record) { + $case1 = $record->client_type == $clientType; + $case2 = $record->client_ip == $clientIp; + if ($case1 && $case2) { + $online = $record; + break; + } + } + if ($online) { + $online->active_time = $now; + $online->update(); + } else { + $this->createOnline($user->id, $clientType, $clientIp); + } + } else { + $this->createOnline($user->id, $clientType, $clientIp); + } + } + + protected function createOnline($userId, $clientType, $clientIp) + { + $online = new OnlineModel(); + + $online->user_id = $userId; + $online->client_type = $clientType; + $online->client_ip = $clientIp; + $online->active_time = time(); + + $online->create(); + + return $online; + } + + protected function handleVisitPoint(UserModel $user) + { + $todayDate = date('Ymd'); + + $keyName = sprintf('site_visit:%s:%s', $user->id, $todayDate); + + $cache = $this->getCache(); + + $content = $cache->get($keyName); + + if ($content) return; + + $service = new SiteVisitPointHistory(); + + $service->handle($user); + + $tomorrow = strtotime($todayDate) + 86400; + + $lifetime = $tomorrow - time(); + + $cache->save($keyName, 1, $lifetime); + } + +} diff --git a/app/Services/Logic/User/Console/PointRedeemList.php b/app/Services/Logic/User/Console/PointRedeemList.php index b7f6e6a0..66df0c31 100644 --- a/app/Services/Logic/User/Console/PointRedeemList.php +++ b/app/Services/Logic/User/Console/PointRedeemList.php @@ -3,6 +3,7 @@ namespace App\Services\Logic\User\Console; use App\Library\Paginator\Query as PagerQuery; +use App\Models\PointRedeem as PointRedeemModel; use App\Repos\PointRedeem as PointRedeemRepo; use App\Services\Logic\Service as LogicService; use App\Services\Logic\UserTrait; @@ -42,25 +43,31 @@ class PointRedeemList extends LogicService $items = []; - foreach ($pager->items as $item) { + /** + * @var PointRedeemModel[] $redeems + */ + $redeems = $pager->items; + + foreach ($redeems as $redeem) { $items[] = [ - 'id' => $item->id, - 'status' => $item->status, - 'create_time' => $item->create_time, + 'id' => $redeem->id, + 'status' => $redeem->status, + 'create_time' => $redeem->create_time, + 'update_time' => $redeem->update_time, 'user' => [ - 'id' => $item->user_id, - 'name' => $item->user_name, + 'id' => $redeem->user_id, + 'name' => $redeem->user_name, ], 'gift' => [ - 'id' => $item->gift_id, - 'name' => $item->gift_name, - 'type' => $item->gift_type, - 'point' => $item->gift_point, + 'id' => $redeem->gift_id, + 'name' => $redeem->gift_name, + 'type' => $redeem->gift_type, + 'point' => $redeem->gift_point, ], 'contact' => [ - 'name' => $item->contact_name, - 'phone' => $item->contact_phone, - 'address' => $item->contact_address, + 'name' => $redeem->contact_name, + 'phone' => $redeem->contact_phone, + 'address' => $redeem->contact_address, ], ]; } diff --git a/app/Services/Logic/User/Console/ProfileInfo.php b/app/Services/Logic/User/Console/ProfileInfo.php index d4d81c10..9cb2e2f1 100644 --- a/app/Services/Logic/User/Console/ProfileInfo.php +++ b/app/Services/Logic/User/Console/ProfileInfo.php @@ -31,10 +31,12 @@ class ProfileInfo extends LogicService 'gender' => $user->gender, 'vip' => $user->vip, 'locked' => $user->locked, - 'vip_expiry_time' => $user->vip_expiry_time, - 'lock_expiry_time' => $user->lock_expiry_time, 'edu_role' => $user->edu_role, 'admin_role' => $user->admin_role, + 'vip_expiry_time' => $user->vip_expiry_time, + 'lock_expiry_time' => $user->lock_expiry_time, + 'create_time' => $user->create_time, + 'update_time' => $user->update_time, ]; } diff --git a/app/Services/Logic/User/Console/RefundList.php b/app/Services/Logic/User/Console/RefundList.php index da1b0af1..c693efde 100644 --- a/app/Services/Logic/User/Console/RefundList.php +++ b/app/Services/Logic/User/Console/RefundList.php @@ -69,6 +69,7 @@ class RefundList extends LogicService 'apply_note' => $refund['apply_note'], 'review_note' => $refund['review_note'], 'create_time' => $refund['create_time'], + 'update_time' => $refund['update_time'], ]; } diff --git a/app/Services/Logic/User/UserInfo.php b/app/Services/Logic/User/UserInfo.php index f3d1bcdc..d6a6a36f 100644 --- a/app/Services/Logic/User/UserInfo.php +++ b/app/Services/Logic/User/UserInfo.php @@ -41,6 +41,7 @@ class UserInfo extends LogicService 'group_count' => $imUser->group_count, 'active_time' => $user->active_time, 'create_time' => $user->create_time, + 'update_time' => $user->update_time, ]; } diff --git a/public/static/home/js/common.js b/public/static/home/js/common.js index 5f3aae31..86f89ab6 100644 --- a/public/static/home/js/common.js +++ b/public/static/home/js/common.js @@ -58,6 +58,9 @@ layui.use(['jquery', 'form', 'element', 'layer', 'helper'], function () { } }); }, 30000); + setInterval(function () { + $.post('/uc/online'); + }, 30000); } form.on('submit(go)', function (data) {