Jiankangdata.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 健康检测数据
  7. */
  8. class Jiankangdata extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. public function submit(){
  13. $map = [
  14. 'user_id' => $this->auth->id,
  15. 'createdate' => date('Y-m-d'),
  16. ];
  17. $check = Db::name('jiankangdata')->where($map)->find();
  18. $data = [
  19. 'user_id' => $this->auth->id,
  20. 'xueya_low' => $this->request->post('xueya_low'),
  21. 'xueya_high' => $this->request->post('xueya_high'),
  22. 'xuetang' => $this->request->post('xuetang'),
  23. 'createtime' => time(),
  24. 'updatetime' => time(),
  25. 'createdate' => date('Y-m-d'),
  26. ];
  27. if($check){
  28. Db::name('jiankangdata')->where($map)->update($data);
  29. }else{
  30. Db::name('jiankangdata')->insert($data);
  31. }
  32. $this->success('提交成功');
  33. }
  34. public function data(){
  35. $type = $this->request->post('type','week','trim');
  36. if($type == 'week'){
  37. $where = ['createtime' => ['>=', date('Y-m-d', strtotime('-7 day'))]];
  38. }
  39. if($type == 'month'){
  40. $where = ['createtime' => ['>=', date('Y-m-d', strtotime('-30 day'))]];
  41. }
  42. $list = Db::name('jiankangdata')->where('user_id',$this->auth->id)->order('id','asc')->select();
  43. $this->success(1,$list);
  44. }
  45. }