ElectricalDegree.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\admin\controller;
  3. use think\App;
  4. use think\Db;
  5. use think\Exception;
  6. class ElectricalDegree extends Auth
  7. {
  8. protected function initialize()
  9. {
  10. parent::initialize(); // TODO: Change the autogenerated stub
  11. }
  12. public function index(){
  13. if(request()->isAjax()){
  14. //分页参数
  15. $length = input('rows',10,'intval'); //每页条数
  16. $page = input('page',1,'intval'); //第几页
  17. $start = ($page - 1) * $length; //分页开始位置
  18. //排序
  19. $sortRow = input('sidx','sort','trim'); //排序列
  20. $sort = input('sord','asc','trim'); //排序方式
  21. $order = $sortRow.' '.$sort.' ,id desc';
  22. $map[] = ['del','=',0];
  23. $map[] = ['org_id','=',$this->orgId];
  24. $map= empty($map) ? true: $map;
  25. //数据查询
  26. $lists = Db::name('electrical_degree')
  27. ->where($map)
  28. ->limit($start,$length)
  29. ->order('id desc')
  30. ->select();
  31. //数据返回
  32. $totalCount = Db::name('electrical_degree')->where($map)->count();
  33. $totalPage = ceil($totalCount/$length);
  34. $result['page'] = $page;
  35. $result['total'] = $totalPage;
  36. $result['records'] = $totalCount;
  37. $result['rows'] = $lists;
  38. return json($result);
  39. }else{
  40. $this->assign('meta_title','电度量列表');
  41. return $this->fetch();
  42. }
  43. }
  44. public function tj1(){
  45. $time = time();
  46. $timeData = [];
  47. for ($i = 6; $i >= 0; $i--) {
  48. $timeData[] = date('Y-m-d', $time - ($i * 86400));
  49. }
  50. $key = [];
  51. $value = [];
  52. foreach ($timeData as $k => $v) {
  53. $key[] = $v;
  54. $list = Db::name('electrical_degree')
  55. ->where('org_id', $this->orgId)
  56. ->where('del', 0)
  57. ->where('add_time', '>=',$v.' 00:00:00')
  58. ->where('add_time', '<=',$v.' 23:59:59')
  59. ->column('num');
  60. $num = 0;
  61. if(count($list) >= 2){
  62. $sn = isset($list)&&!empty($list) ? $list[0] :0;
  63. $nlist = array_reverse($list);
  64. $en = isset($list)&&!empty($list) ? $nlist[0] :0;
  65. $num = $en-$sn;
  66. }
  67. $value[] = $num;
  68. }
  69. $this->assign('key', $key);
  70. $this->assign('value', $value);
  71. return $this->fetch();
  72. }
  73. public function tj2() {
  74. $time = time();
  75. $timeData = [];
  76. for ($i = 29; $i >= 0; $i--) {
  77. $timeData[] = date('Y-m-d', $time - ($i * 86400));
  78. }
  79. $key = [];
  80. $value = [];
  81. foreach ($timeData as $k => $v) {
  82. $key[] = $v;
  83. $list = Db::name('electrical_degree')
  84. ->where('org_id', $this->orgId)
  85. ->where('del', 0)
  86. ->where('add_time', '>=',$v.' 00:00:00')
  87. ->where('add_time', '<=',$v.' 23:59:59')
  88. ->column('num');
  89. $num = 0;
  90. if(count($list) >= 2){
  91. $sn = isset($list)&&!empty($list) ? $list[0] :0;
  92. $nlist = array_reverse($list);
  93. $en = isset($list)&&!empty($list) ? $nlist[0] :0;
  94. $num = $en-$sn;
  95. }
  96. $value[] = $num;
  97. }
  98. $this->assign('key', $key);
  99. $this->assign('value', $value);
  100. return $this->fetch();
  101. }
  102. }