userId]; return $where; } /** * @notes 文章/帮助列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author Tab * @date 2021/7/14 9:48 */ public function lists(): array { $lists = GoodsVisit::field('id,goods_id,ip,visit,create_time') ->where($this->searchWhere) ->append(['goods']) ->order([ 'create_time' => 'desc' ]) ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); // 按日期分组 $groupedData = []; foreach ($lists as $item) { $date = date('Y-m-d', strtotime($item['create_time'])); if (!isset($groupedData[$date])) { $groupedData[$date] = [ 'date' => $date, 'date_text' => date('Y年m月d日', strtotime($item['create_time'])), 'goods_list' => [] ]; } $groupedData[$date]['goods_list'][] = $item; } // 转换为数组格式并按日期倒序排列 return array_values($groupedData); } /** * @notes 文章/帮助总记录数 * @return int * @author Tab * @date 2021/7/14 9:48 */ public function count(): int { return GoodsVisit::where($this->searchWhere)->count(); } }