12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- declare(strict_types=1);
- namespace App\Job;
- use App\Master\Enum\RedisKeyEnum;
- use App\Master\Framework\Extend\BaseJob;
- use App\Master\Framework\Library\Tencent\TencentIm;
- use App\Model\Arts\LiveRoomLogLikeModel;
- use App\Model\Arts\LiveRoomLogModel;
- use App\Model\Arts\LiveRoomModel;
- use App\Utils\LogUtil;
- use App\Utils\RedisUtil;
- class LiveRoomSendJob extends BaseJob
- {
- //日志板块
- protected string $LOG_MODULE = 'LiveRoomSendJob';
- /**
- * 任务执行失败后的重试次数,即最大执行次数为 $maxAttempts+1 次
- */
- protected int $maxAttempts = 2;
- public function __construct($params)
- {
- parent::__construct($params);
- }
- /**
- * 执行
- * @param $params
- * @return bool
- */
- protected function do($params): bool
- {
- $im = new TencentIm();
- $model = new LiveRoomModel();
- $room = $model->getDetail(params: ['room_no' => $params['room_no']],with: ['log']);
- if (!$room) {
- return $this->error('直播间异常');
- }
- // 更新发言权
- $counter[] = [
- 'key' => 'talk_status',
- 'value' => (string)$room['talk_status']
- ];
- // 更新直播间右上角头像
- $model = new LiveRoomLogLikeModel();
- $list = $model->getTopList($room['room_no'], $room['user_id'], 4);
- $avatar = array_column($list, 'avatar');
- $counter[] = [
- 'key' => 'top_avatar',
- 'value' => !empty($avatar) ? implode(',', $avatar) : ''
- ];
- // 更新直播间点赞量
- $counter[] = [
- 'key' => 'like',
- 'value' => (string)($room['log']['like'] ?? 0)
- ];
- // 更新直播间ccu数
- $im->get_online_member_num($room['room_no']);
- $online_member = $im->getData()['OnlineMemberNum'] ?? 0;
- $online_member = $online_member > 0 ? $online_member - 1 : 0;
- LiveRoomLogModel::query()->where('room_no', $room['room_no'])->where('session', $room['session'])->update(['ccu' => $online_member]);
- $counter[] = [
- 'key' => 'online_member_num',
- 'value' => (string)$online_member
- ];
- $now = md5(json_encode($counter));
- $old = RedisUtil::getInstance(RedisKeyEnum::ROOM_SEND_DATA, $params['room_no'])->get();
- if ($now != $old){
- // 统一更新群属性
- $im->modify_group_attr($room['room_no'], $counter);
- }
- RedisUtil::getInstance(RedisKeyEnum::ROOM_SEND_DATA, $params['room_no'])->setex($now,10);
- return $this->success('执行成功', $im->getData());
- }
- }
|