123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 健康检测数据
- */
- class Jiankangdata extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- public function submit(){
- $map = [
- 'user_id' => $this->auth->id,
- 'createdate' => date('Y-m-d'),
- ];
- $check = Db::name('jiankangdata')->where($map)->find();
- $data = [
- 'user_id' => $this->auth->id,
- 'xueya_low' => $this->request->post('xueya_low'),
- 'xueya_high' => $this->request->post('xueya_high'),
- 'xuetang' => $this->request->post('xuetang'),
- 'createtime' => time(),
- 'updatetime' => time(),
- 'createdate' => date('Y-m-d'),
- ];
- if($check){
- Db::name('jiankangdata')->where($map)->update($data);
- }else{
- Db::name('jiankangdata')->insert($data);
- }
- $this->success('提交成功');
- }
- public function data(){
- $type = $this->request->post('type','week','trim');
- if($type == 'week'){
- $start_date = date('Y-m-d', strtotime('monday this week'));
- $ended_date = date('Y-m-d', strtotime('sunday this week'));
- $days = 7;
- for($i=0;$i<$days;$i++){
- $date_array[] = date('m.d', 86400*$i + strtotime('monday this week'));
- }
- }
- if($type == 'month'){
- $start_date = date('Y-m-01');
- $ended_date = date('Y-m-t');
- $days = date('t');
- for($i=0;$i<$days;$i++){
- $date_array[] = date('m.d', 86400*$i + strtotime(date('Y-m-01')));
- }
- }
- // dump($start_date);
- // dump($ended_date);
- // dump($date_array);
- $list = Db::name('jiankangdata')->where('user_id',$this->auth->id)->whereBetween('createdate',[$start_date,$ended_date])->order('id','asc')->select();
- $xueya_low = [];
- $xueya_high = [];
- $xuetang = [];
- foreach($date_array as $date){
- $xueya_low[$date] = 0;
- $xueya_high[$date] = 0;
- $xuetang[$date] = 0;
- foreach($list as $k=>$v){
- if(date('m.d',strtotime($v['createdate'])) == $date){
- $xueya_low[$date] = $v['xueya_low'];
- $xueya_high[$date] = $v['xueya_high'];
- $xuetang[$date] = $v['xuetang'];
- }
- }
- }
- // dump($xueya_low);
- // dump($xueya_high);
- // dump($xuetang);
- $rs = [
- 'start_date' => date('Y.m.d',strtotime($start_date)),
- 'end_date' => date('Y.m.d',strtotime($ended_date)),
- 'date_array' => $date_array,
- 'xueya_low' => array_values($xueya_low),
- 'xueya_high' => array_values($xueya_high),
- 'xuetang' => array_values($xuetang),
- ];
- $this->success(1,$rs);
- }
- }
|