123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Support\Facades\DB;
- class Record extends Model
- {
- protected $table = '';
- public $timestamps = false;
- public static function insertViews($menuId)
- {
- $re = DB::table('view_record')->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;
- }
- }
|