5], [['page'], 'default', 'value' => 1] ]; } public function search() { if (!$this->validate()) { return $this->errorResponse; } $query = OrderMessage::find()->alias('om')->where([ 'om.store_id' => $this->store_id, 'om.is_delete' => 0, 'om.order_type' => [0, 1, 2, 3, 4, 6, 7], ]); if ($this->is_read) { $query->andWhere(['or',['om.is_read' => 0],['om.is_sound'=>0]]); } $query->andWhere(['>=','om.created_at', strtotime('2022-09-23')]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->orderBy(['om.created_at' => SORT_DESC]) ->limit($pagination->limit) ->offset($pagination->offset) ->asArray() ->all(); $urlManager = \Yii::$app->urlManager; // 此处考虑在 cache 或 setting 内做缓存,存储 order_message 表的更新时间,以及查询结果 // 插入 order_message 时,在 beforeInsert 内清空缓存 // -- wi1dcard foreach ($list as &$value) { $time = time() - $value['created_at']; if ($time < 60) { $value['time'] = $time . '秒前'; } elseif ($time < 3600) { $value['time'] = ceil($time / 60) . '分钟前'; } elseif ($time < 86400) { $value['time'] = ceil($time / 3600) . '小时前'; } else { $value['time'] = ceil($time / 86400) . '天前'; } $value['created_at'] = date("Y-m-d H:i:s", $value['created_at']); } return [ 'list' => $list, 'count' => $count, 'pagination' => $pagination ]; } }