insert([ 'menu_id' => $menuId, ]); return $re; } public static function insertCollection($menuId) { $re = DB::table('collection_record')->insert([ 'menu_id' => $menuId, ]); return $re; } public static function selectListRecord($menuIdList) { $menuIdList = implode(',', $menuIdList); $viewNum = DB::select('select count(*) as num,menu_id from view_record where menu_id in (' . $menuIdList . ') group by menu_id'); $collectionNum = DB::select('select count(*) as num,menu_id from collection_record where menu_id in (' . $menuIdList . ') group by menu_id'); $count = count($viewNum); $record = []; for ($i = 0; $i < $count; $i++) { if (isset($viewNum[$i])) { $record['view'][$viewNum[$i]->menu_id] = $viewNum[$i]->num; } if (isset($collectionNum[$i])) { $record['collection'][$collectionNum[$i]->menu_id] = $collectionNum[$i]->num; } } return $record; } public static function selectRecord($menuId) { $viewNum = DB::select('select count(*) as num from view_record where menu_id=' . $menuId); $collectionNum = DB::select('select count(*) as num from collection_record where menu_id=' . $menuId); $record['view'] = $viewNum[0]->num; $record['collection'] = $collectionNum[0]->num; return $record; } }