page . '_' . $this->store_id; $cache = cache()->get($cacheKey); if ($cache) { return $cache; } $start = ($this->page - 1) * $this->limit; $wechat = Wechat::getWechat(); $res = $wechat->broadcast->getRooms($start, $this->limit); if ($res['errcode'] === 0) { $res['room_info'] = $this->eachList($res['room_info']); cache()->set(static::LIVE_LIST_KEY, $res, static::CACHE_TIME); } return $res; } /** * 处理数据 * @param array $list * @return array */ protected function eachList(array $list) { foreach ($list as $key => &$value) { /* id958新增需求:增加直播间可见范围 */ $purview = LiveRoomPurview::findOne(['store_id' => $this->store_id, 'room_id' => $value['roomid']]); $user_info = User::findOne(get_user_id()); if($purview->type == 1) {//指定用户 if(!in_array($user_info->id ,explode(',', $purview->user_id))) { unset($list[$key]); continue; } } elseif($purview->type == 2) {//指定会员等级 $level_info = Level::findOne(['level' => $user_info->level, 'store_id' => $this->store_id, 'is_delete' => 0]); if(!in_array($level_info->id ,explode(',', $purview->level_id))) { unset($list[$key]); continue; } } $list = array_values($list); /* end */ if ($value['live_status'] == 103) { $value['time'] = $this->formatDateByInterval($value['start_time'], $value['end_time']); $value['time2'] = $this->formatDate($value['start_time'], $value['end_time']); } else { $value['time'] = $this->formatDate($value['start_time'], $value['end_time']); $value['time2'] = $this->formatDateByInterval($value['start_time'], $value['end_time']); } foreach ($value['goods'] as $k => &$v) { $v['price'] = $v['price'] / 100; } } return $list; } /** * 格式化时间差 * @param $start * @param $end * @return string */ protected function formatDateByInterval($start, $end) { $start = date_create(date('Y-m-d H:i:s', $start)); $end = date_create(date('Y-m-d H:i:s', $end)); $interval = date_diff($start, $end); $res = $interval->format('%h'); if ($res > 0) { return $res . ' 小时'; } $res = $interval->format('%i'); if ($res > 0) { return $res . ' 分钟'; } $res = $interval->format('%s'); return $res . ' 秒'; } /** * 格式化时间 * @param $start * @param $end * @return string */ protected function formatDate($start, $end) { $start = date('y/m/d H:i', $start); $end = date('H:i', $end); return $start . ' - ' . $end; } }