Xueya.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\admin\controller;
  3. use app\watch\controller\Api;
  4. use think\App;
  5. use think\facade\Db;
  6. class Xueya extends Auth
  7. {
  8. public function __construct(App $app) {
  9. parent::__construct($app);
  10. $this->api = new Api($this->app);
  11. }
  12. public function index(){
  13. $id = request()->get('id');
  14. if(empty($id)){
  15. $d = $this->api->community(1,10);
  16. if(!isset($d['objs'][0])) $this->error('没有添加设备');
  17. $id = isset($d['objs'][0]['_id'])?$d['objs'][0]['_id']:'';
  18. }
  19. if(request()->isAjax()){
  20. //分页参数
  21. $length = input('rows',10,'intval'); //每页条数
  22. $page = input('page',1,'intval'); //第几页
  23. $date = input('riqi','');
  24. $imei = input('imei','');
  25. $p = ['rows_per_page'=>$length,'page'=>$page];
  26. if($date){
  27. $p['time_begin'] = date('Ymd',strtotime($date));
  28. }
  29. if(!empty($imei)){
  30. $id = $imei;
  31. }
  32. $list = $this->api->deviceBloodPressureData($id,$p);
  33. if(!$list['success']){
  34. $this->error($list['error_desc']);
  35. }
  36. $data = [];
  37. foreach ($list['objs'] as $k=>$v){
  38. $a = [
  39. 'id'=>$k+1,
  40. 'dbp'=>$v['dbp'],
  41. 'sbp'=>$v['sbp'],
  42. 'created_at'=>nDate($v['created_at']['$date']),
  43. ];
  44. $data[$k] = $a;
  45. }
  46. $result['page'] = $page;
  47. $result['total'] = $list['page']['page_count'];
  48. $result['records'] = $list['page']['total'];
  49. $result['rows'] = $data;
  50. return json($result);
  51. }else{
  52. $this->assign('id',$id);
  53. return $this->fetch();
  54. }
  55. }
  56. }