| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- declare(strict_types=1);
- namespace Modules\Api\Services;
- use App\Model\Mongo\UserRelationModel;
- use App\Model\Mongo\VideoLikeModel;
- class UserRelationService
- {
- /**
- * 获取关注/被关注总数
- * @param $type
- * @param $userId
- * @return integer
- */
- public function getTotal($type, $userId)
- {
- if ($type == 'flow') {
- $data = [
- 'from_user_id' => $userId
- ];
- } else {
- $data = [
- 'to_user_id' => $userId
- ];
- }
- return make(UserRelationModel::class)->db()->countDocuments($data);
- }
- /**
- * 检查是否关注
- * @param $userId
- * @param $toUserId
- * @return integer
- */
- public function check($userId, $toUserId)
- {
- $key = md5('favorite_' . $userId . '_' . $toUserId);
- $result = make(UserRelationModel::class)->db()
- ->countDocuments(['_id' => $key]);
- if ($result) {
- return 1;
- }
- return 0;
- }
- /**
- * 获取点赞数
- * @param $userId
- * @param $toUserId
- * @return integer
- */
- public function getLike($userId)
- {
- return make(VideoLikeModel::class)->db()->countDocuments(['uid' => $userId]);
- }
- }
|