isAjax()){ //分页参数 $length = input('rows',10,'intval'); //每页条数 $page = input('page',1,'intval'); //第几页 $start = ($page - 1) * $length; //分页开始位置 //排序 $sortRow = input('sidx','sort','trim'); //排序列 $sort = input('sord','asc','trim'); //排序方式 $order = $sortRow.' '.$sort.' ,id desc'; $map[] = ['del','=',0]; $map[] = ['org_id','=',$this->orgId]; $map= empty($map) ? true: $map; //数据查询 $lists = Db::name('electrical_degree') ->where($map) ->limit($start,$length) ->order('id desc') ->select(); //数据返回 $totalCount = Db::name('electrical_degree')->where($map)->count(); $totalPage = ceil($totalCount/$length); $result['page'] = $page; $result['total'] = $totalPage; $result['records'] = $totalCount; $result['rows'] = $lists; return json($result); }else{ $param = [ 'userId'=>$this->userId, 'orgId'=>$this->orgId, 'create_time'=>date('Y-m-d H:i:s') ]; $token = think_encrypt(json_encode($param)); $screen_url1 = request()->root().'/wap/screen1/#'.'/energy?token='.$token; $this->assign('screen_url1',$screen_url1); $this->assign('meta_title','电度量列表'); return $this->fetch(); } } public function tj1(){ $time = time(); $timeData = []; for ($i = 6; $i >= 0; $i--) { $timeData[] = date('Y-m-d', $time - ($i * 86400)); } $key = []; $value = []; foreach ($timeData as $k => $v) { $key[] = $v; $list = Db::name('electrical_degree') ->where('org_id', $this->orgId) ->where('del', 0) ->where('add_time', '>=',$v.' 00:00:00') ->where('add_time', '<=',$v.' 23:59:59') ->column('num'); $num = 0; if(count($list) >= 2){ $sn = isset($list)&&!empty($list) ? $list[0] :0; $nlist = array_reverse($list); $en = isset($list)&&!empty($list) ? $nlist[0] :0; $num = $en-$sn; } $value[] = $num; } $this->assign('key', $key); $this->assign('value', $value); return $this->fetch(); } public function tj2() { $time = time(); $timeData = []; for ($i = 29; $i >= 0; $i--) { $timeData[] = date('Y-m-d', $time - ($i * 86400)); } $key = []; $value = []; foreach ($timeData as $k => $v) { $key[] = $v; $list = Db::name('electrical_degree') ->where('org_id', $this->orgId) ->where('del', 0) ->where('add_time', '>=',$v.' 00:00:00') ->where('add_time', '<=',$v.' 23:59:59') ->column('num'); $num = 0; if(count($list) >= 2){ $sn = isset($list)&&!empty($list) ? $list[0] :0; $nlist = array_reverse($list); $en = isset($list)&&!empty($list) ? $nlist[0] :0; $num = $en-$sn; } $value[] = $num; } $this->assign('key', $key); $this->assign('value', $value); return $this->fetch(); } }