__('Type 1'),'2' => __('Type 2'),'3' => __('Type 3'),'4' => __('Type 4')]; } public function getStatusList() { return ['normal' => __('Status normal'),'hidden' => __('Status hidden')]; } public function getTypeTextAttr($value, $data) { $value = $value ? $value : $data['type']; $list = $this->getTypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function getStatusTextAttr($value, $data) { $value = $value ? $value : $data['status']; $list = $this->getStatusList(); return isset($list[$value]) ? $list[$value] : ''; } /** * 返回详情 * @param $id * @return array */ public function getInfo($id) { $result = []; $redis = Redis::instance(); $key = SpecialPageConstants::REDIS_KEY. $id; //书单信息缓存 if ($redis->exists($key)) { $result = json_decode($redis->get($key), true); } else { $page = $this->where('id', 'EQ', $id)->find(); if (!empty($page)) { $result = $page->toArray(); //拉取资源 $blocks = collection(model("SpecialBlock")->where('page_id', 'EQ', $id)->order("weigh desc")->select())->toArray(); $result['items'] = $blocks; if (!empty($result['items'])) { foreach ($result['items'] as &$item) { $bookIds = explode(",", str_replace([" ", " ", "\s", "\r", "\n"], [",", ",", ",", ",", ","], trim($item['book_id']))); $bookIds = array_values(array_filter($bookIds)); if ($bookIds) { $books = []; foreach ($bookIds as $bookId) { $bookInfo = BookService::instance()->getBookModel()->BookInfo($bookId); if(!empty($bookInfo)){ $books[$bookId]['word_count'] = formatNumber($bookInfo['word_count']); $books[$bookId]['read_num'] = formatNumber($bookInfo['read_num']); } } $item['books'] = $books; } if ($item['activity_id']) { $res = ActivityService::instance()->getActivityModel()->alias('a')->join(['resource' => 'r'], 'r.activity_id = a.id') ->field(['r.id', 'a.id' => 'aid']) ->where('a.id', 'eq', $item['activity_id']) ->find(); if ($res) { $item['activity_rid'] = $res['id']; } } } } $redis->set($key, json_encode($result, 256)); } } return $result; } /** * 清除缓存 * @param $id * @return bool */ public function rmCache($id) { if (!empty($id)) { $redis = Redis::instance(); $key = 'SPP:'. $id; //专题页缓存 if ($redis->exists($key)) { $redis->del($key); } } return true; } }