| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\alliance\models;
- use app\cyy\ApiResponse;
- use app\models\Topic;
- use yii\data\Pagination;
- use app\models\TopicType;
- use app\modules\alliance\models\ApiModel;
- class TopicListForm extends ApiModel
- {
- public $store_id;
- public $page;
- public $limit = 20;
- public $type;
- public $is_chosen;
- public function rules()
- {
- return [
- [['page' ,'limit'], 'integer'],
- [['page'], 'default', 'value' => 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()
- ];
- }
- }
|