1], [['limit'], 'default', 'value' => 20], ['type', 'integer'], ['is_chosen','integer'], ]; } public function search() { $topic_list_cache_key = 'default_topic_list_' . $this->store_id .'_'. $this->type . '_' . $this->page . '_' . $this->limit; if ($list = cache()->get($topic_list_cache_key)) { return [ 'code' => 0, 'msg' => 'success', 'data' => ['list' => $list] ]; } if ($this->type === '-1') { $query = Topic::find()->where(['store_id' => $this->store_id, 'is_delete' => 0,'is_chosen' =>1]); } elseif ($this->type) { $query = Topic::find()->where(['store_id' => $this->store_id, 'is_delete' => 0])->andWhere('type=:type', [':type' => $this->type]); } else { $query = Topic::find()->where(['store_id' => $this->store_id, 'is_delete' => 0]); } $query->andWhere([ 'is_show' => 1 ]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'page' => $this->page - 1, 'pageSize' => $this->limit]); $list = $query->orderBy('sort ASC,created_at DESC')->limit($pagination->limit)->offset($pagination->offset) ->select('id,title,sub_title,cover_pic,read_count,virtual_read_count,virtual_favorite_count,created_at as addtime, layout, content')->asArray()->all(); foreach ($list as $i => $item) { $read_count = intval($item['read_count'] + $item['virtual_read_count']); unset($list[$i]['read_count']); unset($list[$i]['virtual_read_count']); if ($read_count < 10000) { $read_count = $read_count . '人浏览'; } if ($read_count >= 10000) { $read_count = intval($read_count / 10000) . '万+人浏览'; } $goods_class = 'class="goods-link"'; $goods_count = mb_substr_count($item['content'], $goods_class); unset($list[$i]['content']); $list[$i]['read_count'] = $read_count; if ($goods_count) { $list[$i]['goods_count'] = $goods_count . '件宝贝'; } } cache()->set($topic_list_cache_key, $list, 60); return [ 'code' => 0, 'msg' => 'success', 'data' => ['list' => $list], // 'sql' => $query->createCommand()->getRawSql() ]; } }