params['pid'] ?? 1]; $where[] = ['status','=',1]; return $where; } /** * @notes 广告列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author ljj * @date 2022/3/25 9:54 上午 */ public function lists(): array { $where = self::where(); $lists = Ad::field('id,name,pid,image,link_type,link_address') ->where($where) ->order(['sort'=>'desc','id'=>'desc']) ->select() ->toArray(); foreach ($lists as &$list) { if ($list['link_type'] == AdEnum::LINK_SHOP) { $shop_page = array_column(MenuEnum::SHOP_PAGE,NULL,'index'); $list['link_address'] = $shop_page[$list['link_address']]['path']; } } return $lists; } /** * @notes 广告数量 * @return int * @author ljj * @date 2022/3/25 9:55 上午 */ public function count(): int { $where = self::where(); return Ad::where($where)->count(); } }