From bbf55f078eec065dd79603dcc4d7293c124610db Mon Sep 17 00:00:00 2001 From: liwei Date: Tue, 17 Oct 2023 14:42:16 +0800 Subject: [PATCH] 1 --- .../Api/V1/Group/GiftController.php | 31 +++++++++++++++++-- app/Service/GiftService.php | 21 +++++++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/app/Controller/Api/V1/Group/GiftController.php b/app/Controller/Api/V1/Group/GiftController.php index ae8bc09..0228c24 100644 --- a/app/Controller/Api/V1/Group/GiftController.php +++ b/app/Controller/Api/V1/Group/GiftController.php @@ -8,6 +8,7 @@ use App\Model\LiveGift; use App\Model\Players; use App\Model\PlayersGift; use App\Model\UsersGift; +use Hyperf\DbConnection\Db; use App\Service\GiftService; use App\Service\Group\GroupMemberService; use App\Service\Group\GroupNoticeService; @@ -38,6 +39,12 @@ class GiftController extends CController // $this->groupMemberService = $groupMemberService; // } + public function uid(): int + { + $guard = $this->guard('jwt'); + + return $guard->check() ? $guard->user()->getId() : 0; + } /** * 获取所有礼物 * @@ -75,11 +82,11 @@ class GiftController extends CController $name = data_get($params, 'username', ''); $activityId = data_get($params, 'activity_id', ''); $idnums = []; - + $user_id = $this->uid(); if (!empty($name)) { $r = Players::leftjoin('players_gift as pg', 'pg.player_id', '=', 'players.sign_id') ->leftjoin('signups as o', 'o.id', '=', 'players.sign_id') - ->select('players.sign_id as player_id', 'players.head_img', 'players.name', 'pg.points', 'o.id_num', 'pg.order') + ->select('players.sign_id as player_id', 'players.head_img', 'players.name', 'pg.points', 'o.id_num','o.mine_id', 'pg.order') ->where('players.name', 'like', "%$name%") ->where('players.activity_id', '=', $activityId) ->offset($page * $pageSize - $pageSize) @@ -96,11 +103,26 @@ class GiftController extends CController $headImg = 'https://cdn.rockysports.cn/%E5%BE%AE%E6%AD%A5%E8%AE%A1%E6%97%B6.png'; } $idnum = data_get($v, 'id_num', ''); + + $is_follow = 0; + // 关注状态 + if ($user_id) { + $mine_id = data_get($v, 'mine_id', 0); + $follow_user = DB::table('user_follow') + ->where('user_id',$user_id) + ->where('to_user_id',$mine_id) + ->first(); + if (!empty($follow_user)) { + $is_follow = 1; + } + } + if (!empty($idnum)) { if (!isset($idnums[$idnum])) { $idnums[$idnum]['points'] = '0'; $idnums[$idnum]['player_id'] = $playerId; $idnums[$idnum]['head_img'] = $headImg; + $idnums[$idnum]['is_follow'] = $is_follow; if (!isset($idnums[$idnum]['order'])) { $idnums[$idnum]['order'] = $order; } @@ -112,9 +134,12 @@ class GiftController extends CController $idnums[$k]['points'] = empty($points)? 0: $points; $idnums[$k]['player_id'] = $playerId; $idnums[$k]['head_img'] = $headImg; + $idnums[$k]['is_follow'] = $is_follow; $idnums[$k]['order'] = $order; $idnums[$k]['name'] = data_get($v, 'name'); } + + } $ages = []; foreach ($idnums as $user) { @@ -144,7 +169,7 @@ class GiftController extends CController $return[] = $j; } } else { - GiftService::PlayerGiftRankV2($activityId); + GiftService::PlayerGiftRankV2($activityId, $user_id); $data = $redis->lRange($redisKey, $start, (int)$end); info('data', [$data]); $return = []; diff --git a/app/Service/GiftService.php b/app/Service/GiftService.php index 1515a64..87e3917 100644 --- a/app/Service/GiftService.php +++ b/app/Service/GiftService.php @@ -7,6 +7,8 @@ use App\Model\Players; use App\Model\PlayersGift; use App\Model\UsersGift; use App\Traits\PagingTrait; +use Hyperf\DbConnection\Db; + /** * 笔记服务层 @@ -64,7 +66,7 @@ class GiftService extends BaseService } - public static function PlayerGiftRankV2($activityId) + public static function PlayerGiftRankV2($activityId,$user_id = 0) { $page = 1; @@ -85,7 +87,7 @@ class GiftService extends BaseService if ($count > 0) { // $model->orderBy('pg.points', 'desc'); - $rows = $model->forPage($page, $pageSize)->get(['players.sign_id as player_id', 'players.head_img', 'players.name', 'pg.points', 'o.id_num'])->toArray(); + $rows = $model->forPage($page, $pageSize)->get(['players.sign_id as player_id', 'players.head_img', 'players.name', 'pg.points', 'o.id_num','o.mine_id'])->toArray(); foreach ($rows as $k => $v) { $name = data_get($v, 'name'); @@ -105,11 +107,25 @@ class GiftService extends BaseService $headImg = 'https://cdn.rockysports.cn/%E5%BE%AE%E6%AD%A5%E8%AE%A1%E6%97%B6.png'; } $idnum = data_get($v, 'id_num', ''); + + $is_follow = 0; + // 关注状态 + if ($user_id) { + $mine_id = data_get($v, 'mine_id', 0); + $follow_user = DB::table('user_follow') + ->where('user_id',$user_id) + ->where('to_user_id',$mine_id) + ->first(); + if (!empty($follow_user)) { + $is_follow = 1; + } + } if (!empty($idnum)) { if (!isset($idnums[$idnum])) { $idnums[$idnum]['points'] = 0; $idnums[$idnum]['player_id'] = $playerId; $idnums[$idnum]['head_img'] = $headImg; + $idnums[$idnum]['is_follow'] = $is_follow; $idnums[$idnum]['name'] = data_get($v, 'name'); } $idnums[$idnum]['points'] += $points; @@ -117,6 +133,7 @@ class GiftService extends BaseService $idnums[$k]['points'] = empty($points)? 0: $points; $idnums[$k]['player_id'] = $playerId; $idnums[$k]['head_img'] = $headImg; + $idnums[$k]['is_follow'] = $is_follow; $idnums[$k]['name'] = data_get($v, 'name'); } } -- Gitee