php框架laraavel——日期取值范围与本地缓存
一、日期插件:
$startYesterday = Carbon::yesterday()->startOfDay()->toDateTimeString(); $endYesterday = Carbon::yesterday()->endOfDay()->toDateTimeString(); $startDay = Carbon::now()->startOfDay()->toDateTimeString(); $endDay = Carbon::now()->endOfDay()->toDateTimeString(); $startDay = Carbon::now()->startOfDay()->toDateTimeString(); $endDay = Carbon::now()->endOfDay()->toDateTimeString(); $startWeek = Carbon::now()->startOfWeek()->toDateTimeString(); $endWeek = Carbon::now()->endOfWeek()->toDateTimeString();
二、本地缓存:
$key = “uuid-1"; if(Cache::has($key)){ return Cache::get($key); }else{ $info = []; $info['data'] = $this->getCanvasInstanceStatusMatch($user); Cache::put($key,$info,30); return $info; }
三、分页方法:
//1.自定义分页: search static::whereBetween('create_time', [$startDay, $endDay]) ->where('run_status', $status) ->search(["offset" => $pageNum * $pageSize,"limit" => $pageSize]) ->orderBy("create_time",'desc') ->get(); //2.sql分页方法:返回第一页,每页5条 paginate($perPage = null, $columns = ['*'], $pageName = '', $page = null) selete * from student limit 0,5 ; ->select(DB::raw(selete * from student limit 0,5) //3.实例:返回某些字段+过滤状态+时间排序+分页拉取
$offset = $pageNum * $pageSize;// 0*5;1*10
$arr = static::select("src_canvas_config_id", "create_time", "end_time", "instance_time", "run_status") ->where('run_status', $status)
->orderBy('instance_time', 'desc')
->offset($offset)
->limit($pageSize)
->get();
-end-