ElectricalDegree.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. $param = [
  41. 'userId'=>$this->userId,
  42. 'orgId'=>$this->orgId,
  43. 'create_time'=>date('Y-m-d H:i:s')
  44. ];
  45. $token = think_encrypt(json_encode($param));
  46. $screen_url1 = request()->root().'/wap/screen1/#'.'/energy?token='.$token;
  47. $this->assign('screen_url1',$screen_url1);
  48. $this->assign('meta_title','电度量列表');
  49. return $this->fetch();
  50. }
  51. }
  52. public function tj1(){
  53. $time = time();
  54. $timeData = [];
  55. for ($i = 6; $i >= 0; $i--) {
  56. $timeData[] = date('Y-m-d', $time - ($i * 86400));
  57. }
  58. $key = [];
  59. $value = [];
  60. foreach ($timeData as $k => $v) {
  61. $key[] = $v;
  62. $list = Db::name('electrical_degree')
  63. ->where('org_id', $this->orgId)
  64. ->where('del', 0)
  65. ->where('add_time', '>=',$v.' 00:00:00')
  66. ->where('add_time', '<=',$v.' 23:59:59')
  67. ->column('num');
  68. $num = 0;
  69. if(count($list) >= 2){
  70. $sn = isset($list)&&!empty($list) ? $list[0] :0;
  71. $nlist = array_reverse($list);
  72. $en = isset($list)&&!empty($list) ? $nlist[0] :0;
  73. $num = $en-$sn;
  74. }
  75. $value[] = $num;
  76. }
  77. $this->assign('key', $key);
  78. $this->assign('value', $value);
  79. return $this->fetch();
  80. }
  81. public function tj2() {
  82. $time = time();
  83. $timeData = [];
  84. for ($i = 29; $i >= 0; $i--) {
  85. $timeData[] = date('Y-m-d', $time - ($i * 86400));
  86. }
  87. $key = [];
  88. $value = [];
  89. foreach ($timeData as $k => $v) {
  90. $key[] = $v;
  91. $list = Db::name('electrical_degree')
  92. ->where('org_id', $this->orgId)
  93. ->where('del', 0)
  94. ->where('add_time', '>=',$v.' 00:00:00')
  95. ->where('add_time', '<=',$v.' 23:59:59')
  96. ->column('num');
  97. $num = 0;
  98. if(count($list) >= 2){
  99. $sn = isset($list)&&!empty($list) ? $list[0] :0;
  100. $nlist = array_reverse($list);
  101. $en = isset($list)&&!empty($list) ? $nlist[0] :0;
  102. $num = $en-$sn;
  103. }
  104. $value[] = $num;
  105. }
  106. $this->assign('key', $key);
  107. $this->assign('value', $value);
  108. return $this->fetch();
  109. }
  110. }