['type'], '%like%' => ['title'], ]; } /** * @notes 获取列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author admin * @date 2024/12/20 10:52 */ public function lists(): array { $query = ActivityZoneForm::where($this->searchWhere); $cateIds = []; $list = $query ->field(['id', 'type', 'cate_ids', 'title', 'remark']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->each(function ($item) use (&$cateIds) { $item['cate_ids'] = explode(',', $item['cate_ids']); foreach ($item['cate_ids'] as $cateId) { if (!empty($cateId) && !in_array($cateId, $cateIds)) { $cateIds[] = $cateId; } } }) ->toArray(); $cateList = StoreCategory::where('id', 'in', $cateIds)->field('id,name')->select()->toArray(); $cateList = reset_index($cateList, 'id'); foreach ($list as &$item) { $item['cate_names'] = []; foreach ($item['cate_ids'] as $cateId) { if (isset($cateList[$cateId])) { $item['cate_names'][] = $cateList[$cateId]['name']; } } $item['cate_names'] = implode(',', $item['cate_names']); } return $list; } /** * @notes 获取数量 * @return int * @author admin * @date 2024/12/20 10:52 */ public function count(): int { $query = ActivityZoneForm::where($this->searchWhere); return $query->count(); } }