['form_id'], ]; } /** * @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 = ActivityZone::where($this->searchWhere); if (!empty($this->params['store_name'])) { $productIds = StoreProduct::where('store_name', 'like', "%{$this->params['store_name']}%")->column('id'); $query->whereIn('product_id', $productIds); } $list = $query->with('product') ->field(['id', 'form_id', 'product_id']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select() ->toArray(); $unitIds = array_unique(array_column($list, 'unit')); $unit = StoreProductUnit::whereIn('id', $unitIds)->field('id,name')->withTrashed()->select()->toArray(); $unit = reset_index($unit, 'id'); foreach ($list as &$item) { $item['unit_name'] = $unit[$item['unit']]['name'] ?? ''; } return $list; } /** * @notes 获取数量 * @return int * @author admin * @date 2024/12/20 10:52 */ public function count(): int { $query = ActivityZone::where($this->searchWhere); if (!empty($this->params['store_name'])) { $productIds = StoreProduct::where('store_name', 'like', "%{$this->params['store_name']}%")->column('id'); $query->whereIn('product_id', $productIds); } return $query->count(); } }