From 81a856850b0f51b46688dc44ba663a158a1d63a8 Mon Sep 17 00:00:00 2001 From: tsf <460834639@qq.com> Date: Sat, 23 Nov 2024 16:46:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E6=96=B0=E7=89=882024-11-23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/admin/controller/Editortext.php | 293 ++++ .../admin/view/appversion/app_edit.html | 204 +++ .../admin/view/editortext/add_content.html | 349 +++++ .../admin/view/editortext/edit_content.html | 397 +++++ application/admin/view/editortext/index.html | 341 ++++ .../admin/view/editortext/model_content.html | 294 ++++ application/admin/view/index/index.html | 13 + application/app/controller/Base.php | 355 +++-- application/app/controller/Calculatebody.php | 44 +- application/app/controller/Card.php | 852 +++++++--- application/app/controller/Cardparts.php | 50 +- application/app/controller/Cardpublic.php | 699 +++++++-- application/app/controller/Device.php | 273 ++-- application/app/controller/Index.php | 1373 +++++++++++------ application/app/controller/Login.php | 458 +++--- application/app/controller/Msginformation.php | 283 ++++ application/app/controller/Myinformation.php | 178 ++- application/app/controller/Pagingcontrast.php | 395 +++-- application/app/controller/Skip.php | 324 ++-- application/app/controller/Sportstesting.php | 1022 ++++-------- application/app/controller/Vitalcapacity.php | 302 ++-- application/app/view/download/demo.html | 5 +- application/app/view/download/demo2.html | 106 +- application/appbackups/controller/Base.php | 328 +++- .../appbackups/controller/Calculatebody.php | 36 +- application/appbackups/controller/Card.php | 439 +++--- .../appbackups/controller/Cardparts.php | 31 - .../appbackups/controller/Cardpublic.php | 778 +++++++++- application/appbackups/controller/Device.php | 274 ++-- application/appbackups/controller/Index.php | 1118 +++++++++----- application/appbackups/controller/Login.php | 458 +++--- .../appbackups/controller/Myinformation.php | 180 ++- .../appbackups/controller/Pagingcontrast.php | 311 ++-- application/appbackups/controller/Skip.php | 324 ++-- .../appbackups/controller/Sportstesting.php | 1022 ++++-------- .../appbackups/controller/Vitalcapacity.php | 224 +-- .../appbackups/view/download/demo.html | 5 +- .../appbackups/view/download/demo2.html | 26 +- application/route.php | 57 +- application/testapp/controller/Base.php | 181 ++- .../testapp/controller/Calculatebody.php | 25 +- application/testapp/controller/Card.php | 524 ++++++- application/testapp/controller/Cardparts.php | 30 +- application/testapp/controller/Cardpublic.php | 352 +++-- application/testapp/controller/Device.php | 47 +- application/testapp/controller/Download.php | 6 +- application/testapp/controller/Index.php | 825 +++++----- application/testapp/controller/Login.php | 104 +- .../testapp/controller/Msginformation.php | 283 ++++ .../testapp/controller/Myinformation.php | 35 +- .../testapp/controller/Pagingcontrast.php | 145 +- application/testapp/controller/Skip.php | 43 +- .../testapp/controller/Sportstesting.php | 114 +- .../testapp/controller/Vitalcapacity.php | 137 +- application/testapp/view/download/demo.html | 5 +- application/testapp/view/download/demo2.html | 26 +- public/Q1medp48CV.txt | 1 + 57 files changed, 11532 insertions(+), 5572 deletions(-) create mode 100644 application/admin/controller/Editortext.php create mode 100644 application/admin/view/appversion/app_edit.html create mode 100644 application/admin/view/editortext/add_content.html create mode 100644 application/admin/view/editortext/edit_content.html create mode 100644 application/admin/view/editortext/index.html create mode 100644 application/admin/view/editortext/model_content.html create mode 100644 application/app/controller/Msginformation.php create mode 100644 application/testapp/controller/Msginformation.php create mode 100644 public/Q1medp48CV.txt diff --git a/application/admin/controller/Editortext.php b/application/admin/controller/Editortext.php new file mode 100644 index 0000000..4f9b230 --- /dev/null +++ b/application/admin/controller/Editortext.php @@ -0,0 +1,293 @@ +=',$data['s_time']]; + // } + // if($data['e_time']){ + // $parameter['create_time'] = ['<=',$data['e_time']]; + // } + } + $num = Db::table('admin_editor_text_content')->where($parameter)->count(); + $result = Db::table('admin_editor_text_content')->where($parameter)->order('is_del,id desc')->page($page,$this->page_num)->select(); + if(!$pd){ + $return_result['num'] = $num; + $return_result['data'] = $result; + return $this->msg(0,'success',$return_result); + } + $this->assign([ + 'result' => $result, + 'num' => $num, + ]); + return $this->fetch(); + } + + public function add_content(){ + return $this->fetch(); + } + public function edit_content(){ + $data = input(); + $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->find(); + // $result['sector'] = explode(',',$result['sector']); + // dump($result); + // die; + // .replace(/'/g, ''').replace(/"/g, '"') + // $result['content'] = htmlspecialchars_decode($result['content']); + // $result['content'] = str_replace("'", "'", $result['content']); + // $result['content'] = str_replace('"', '"', $result['content']); + $this->assign([ + 'result' => $result, + 'content' => $result['content'], + ]); + return $this->fetch(); + } + + public function model_content(){ + $data = input(); + // $data['id'] = '3'; + if(!array_key_exists('id', $data)){ + return $this->msg(10001); + } + $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->setInc('reading'); + $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->find(); + if(array_key_exists('token', $data)){ + $result['token'] = $data['token']; + $is_like = Db::table('admin_editor_text_like_up_log')->where(['aetc_id'=>$data['id'],'token'=>$data['token']])->find(); + if($is_like){ + if($is_like['is_del'] == 0){ + $result['user_like'] = 0; + }else{ + $result['user_like'] = 1; + } + }else{ + $result['user_like'] = 2; + } + }else{ + $result['user_like'] = 3; + $result['token'] = ''; + } + + $this->assign([ + 'result' => $result + ]); + return $this->fetch(); + } + + + ################################################################action################################################################ + ################################################################action################################################################ + ################################################################action################################################################ + + // 添加咨询动作 + public function add_content_action(){ + $file = request()->file('cover_image'); + $data = request()->param(); + if(!array_key_exists('title', $data) || !array_key_exists('sector', $data) || !array_key_exists('type', $data) || !array_key_exists('content', $data)){ + return $this->msg(10001); + } + $name = time().$file->getInfo()['name']; + $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'cover',$name); + if($info){ + $result = Db::table('admin_editor_text_content')->insert([ + 'title'=>$data['title'], + 'cover_image'=>"editor_upload/cover/".$name, + 'content'=>$data['content'], + 'create_time'=>date('Y-m-d H:i:s'), + 'update_time'=>date('Y-m-d H:i:s'), + 'sector'=>$data['sector'], + 'type'=>$data['type'], + ]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + + }else{ + return $this->msg(10002,$file->getError()); + } + } + // 修改咨询动作 + public function edit_content_action(){ + $file = request()->file('cover_image'); + $data = request()->param(); + if(!array_key_exists('title', $data) || !array_key_exists('sector', $data) || !array_key_exists('type', $data) || !array_key_exists('content', $data)){ + return $this->msg(10001); + } + if($file){ + $name = time().$file->getInfo()['name']; + $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'cover',$name); + if($info){ + $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update([ + 'title'=>$data['title'], + 'cover_image'=>"editor_upload/cover/".$name, + 'content'=>$data['content'], + 'update_time'=>date('Y-m-d H:i:s'), + 'sector'=>$data['sector'], + 'type'=>$data['type'] + ]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + + }else{ + return $this->msg(10002,$file->getError()); + } + }else{ + $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update([ + 'title'=>$data['title'], + 'content'=>$data['content'], + 'update_time'=>date('Y-m-d H:i:s'), + 'sector'=>$data['sector'], + 'type'=>$data['type'] + ]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + } + + // 修改排序动作 + public function edit_order_action(){ + $data = input(); + if(!array_key_exists('id', $data) || !array_key_exists('data', $data) || !array_key_exists('str', $data)){ + return $this->msg(10001); + } + $data['str'] = $data['str'] == 'loop'?'loop_img':'top_up'; + $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update([ + $data['str']=>$data['data'], + 'update_time'=>date('Y-m-d H:i:s'), + ]); + if($result){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + + // 上传图片动作 + public function upload_pic_action(){ + // $file1 = request()->file('file'); + $file = request()->file('wangeditor-uploaded-image'); + + if($file){ + $name = $file->getInfo()['name']; + // 使用 pathinfo() 函数获取文件名的扩展名 + $pathinfo = pathinfo($name); + $extension = strtolower($pathinfo['extension']); // 转换为小写以进行不区分大小写的比较 + // 判断扩展名是否不是 .png 或 .gif + if ($extension !== 'png' && $extension !== 'gif') { + // 修改文件名,将扩展名改为 .jpg + $new_filename = time().$pathinfo['filename'] . '.jpg'; + } else { + $new_filename = time().$name; + } + $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'pic',$new_filename); + if($info){ + $return_data = [ + 'errno'=>0, + 'data'=>[ + 'url'=>'http://tc.pcxbc.com/editor_upload/pic/'.$new_filename, + ] + ]; + return json($return_data); + }else{ + // 上传失败获取错误信息 + // echo $file->getError(); + $return_data = [ + 'errno'=>9999, + 'message'=>$file->getError() + ]; + return json($return_data); + } + } + } + // 上传视频动作 + public function upload_video_action(){ + // $file1 = request()->file('file'); + $file = request()->file('wangeditor-uploaded-video'); + // dump($file); + // die; + if($file){ + $name = time().$file->getInfo()['name']; + $info = $file->move(ROOT_PATH . 'public' . DS . 'editor_upload' . DS . 'video',$name); + if($info){ + $return_data = [ + 'errno'=>0, + 'data'=>[ + 'url'=>'http://tc.pcxbc.com/editor_upload/video/'.$name, + ] + ]; + return json($return_data); + }else{ + // 上传失败获取错误信息 + // echo $file->getError(); + $return_data = [ + 'errno'=>9999, + 'message'=>$file->getError() + ]; + return json($return_data); + } + } + } + + // 停用启用动作 + public function stop_action(){ + $data = input(); + if(is_array($data['id'])){ + $data['id'] = implode(',',$data['id']); + $result = Db::table('admin_editor_text_content')->where("id in (".$data['id'].")")->update(['is_del'=>$data['is_del']]); + }else{ + $result = Db::table('admin_editor_text_content')->where(['id'=>$data['id']])->update(['is_del'=>$data['is_del']]); + } + + if($result){ + return $this->msg(0,'success'); + }else{ + return $this->msg(10001,'success'); + } + } + + ################################################################other################################################################ + ################################################################other################################################################ + ################################################################other################################################################ + + public function msg($code,$msg='',$data=[]){ + return json(['code'=>$code,'msg'=>$msg,'data'=>$data]); + } + +} \ No newline at end of file diff --git a/application/admin/view/appversion/app_edit.html b/application/admin/view/appversion/app_edit.html new file mode 100644 index 0000000..17372aa --- /dev/null +++ b/application/admin/view/appversion/app_edit.html @@ -0,0 +1,204 @@ + + + + + + app版本管理 + + + + + + + + + + + + +
+
+
+
+ +
+ + +
+ +
+
+ +
+ + +
+
+
+ +
+ +
+
最多10个字符(由数字跟英文"."组成)
+
+ +
+ +
+
+
+ + + + +
+
+
+
+ + + + + + \ No newline at end of file diff --git a/application/admin/view/editortext/add_content.html b/application/admin/view/editortext/add_content.html new file mode 100644 index 0000000..2331a05 --- /dev/null +++ b/application/admin/view/editortext/add_content.html @@ -0,0 +1,349 @@ + + + + + + 添加咨询 + + + + + + + + + + + + + +
+
+
+
+ +
+ +
+
+
+ +
+ + + +
+
+
+ +
+ +
+
+
+ + + + + + + + + +
+ + +
+ + + +
+
+
+
+ + + + + + + + +
+ + +
+ + + + + +
+
+
+
+ +
+
+
+
+
+
+ + + +
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/application/admin/view/editortext/edit_content.html b/application/admin/view/editortext/edit_content.html new file mode 100644 index 0000000..9013715 --- /dev/null +++ b/application/admin/view/editortext/edit_content.html @@ -0,0 +1,397 @@ + + + + + + 设备管理_add + + + + + + + + + + + + + +
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ + + + + + + + +
+ {if condition="strpos($result.sector, '1') !== false && strpos($result.sector, '2') !== false && strpos($result.sector, '3') !== false"} + + {else /} + + {/if} + +
+ {if condition="strpos($result.sector, '1') !== false"} + + {else /} + + {/if} + {if condition="strpos($result.sector, '2') !== false"} + + {else /} + + {/if} + {if condition="strpos($result.sector, '3') !== false"} + + {else /} + + {/if} +
+
+
+
+ + + + + + + + +
+ {if condition="strpos($result.type, '1') !== false && strpos($result.type, '2') !== false && strpos($result.type, '3') !== false && strpos($result.type, '4') !== false && strpos($result.type, '5') !== false"} + + {else /} + + {/if} + +
+ {if condition="strpos($result.type, '1') !== false"} + + {else /} + + {/if} + + {if condition="strpos($result.type, '2') !== false"} + + {else /} + + {/if} + + {if condition="strpos($result.type, '3') !== false"} + + {else /} + + {/if} + + {if condition="strpos($result.type, '4') !== false"} + + {else /} + + {/if} + + {if condition="strpos($result.type, '5') !== false"} + + {else /} + + {/if} +
+
+
+
+ +
+
+
+
+
+
+ + + +
+
+
+
+ + + + + + + \ No newline at end of file diff --git a/application/admin/view/editortext/index.html b/application/admin/view/editortext/index.html new file mode 100644 index 0000000..36c39be --- /dev/null +++ b/application/admin/view/editortext/index.html @@ -0,0 +1,341 @@ + + + + + 资讯管理 + + + + + + + + + + +
+ + 首页 + 演示 + + 导航元素 + + + +
+
+
+
+
+ +
+ + + +
+
+ + + + + + + + + + + + + + + {volist name="result" id="vo"} + + + + + + + + + + {/volist} + +
ID标题创建时间上次修改时间置顶排序轮播排序操作
{$vo.id}{$vo.title}{$vo.create_time}{$vo.update_time} + + {if condition="$vo.is_del == 1"} + 已停用 + {else /} + 已启用 + {/if} +
+
+
+
+
+
+ +
+
+
+
+ + + \ No newline at end of file diff --git a/application/admin/view/editortext/model_content.html b/application/admin/view/editortext/model_content.html new file mode 100644 index 0000000..d199561 --- /dev/null +++ b/application/admin/view/editortext/model_content.html @@ -0,0 +1,294 @@ + + + + + + + {$result.title} + + + + + + +
+
{$result.content}
+
+
+
+ {$result.i_like} +
+
+
+ {$result.reading} +
+
+
+ + + + + + \ No newline at end of file diff --git a/application/admin/view/index/index.html b/application/admin/view/index/index.html index 97ed76d..2df5eab 100644 --- a/application/admin/view/index/index.html +++ b/application/admin/view/index/index.html @@ -120,6 +120,19 @@ +
  • + + + 资讯管理 + + +
  • diff --git a/application/app/controller/Base.php b/application/app/controller/Base.php index 609d978..3d86444 100644 --- a/application/app/controller/Base.php +++ b/application/app/controller/Base.php @@ -6,12 +6,22 @@ use think\Controller; use think\Db; use think\Cache; use think\Log; +use PHPMailer\PHPMailer\PHPMailer; class Base extends Controller{ - protected $ceshiyong_token = ['caadd1be045a65f30b92aa805f1de54a','e0966788d02cc93290d9d674921d9715']; + protected $base_use_db_name = [ + '1'=>'app_data_log', + '2'=>'app_card_data', + '3'=>'app_user_data', + '4'=>'pc_vitalcapacity_standard', + '5'=>'admin_estimate', + '6'=>'app_account_number' + ]; + + protected $ceshiyong_token = ['57bd45e3a963b372ea2d873e4bd8d1f8','e0966788d02cc93290d9d674921d9715']; protected $base_call_method = ['内部']; - protected $token_time = 2592000;//30天的秒数 + protected $token_time = 30;//30天的秒数 protected $return_data_all = [ // '0' => ['success',[]], '10001'=>'关键参数缺失', @@ -20,11 +30,12 @@ class Base extends Controller{ '10004'=>'未找到有效数据', '10005'=>'参数格式错误', '10006'=>'参数不能为空', - '10007'=>'', + '10007'=>'参数错误', '10008'=>'', '10009'=>'', '10010'=>'自定义信息', '20001'=>'登录失效', + '99999'=>'网络异常,请稍后重试', ]; // 加 bcadd(,,20) // 减 bcsub(,,20) @@ -34,19 +45,25 @@ class Base extends Controller{ ################################################################接口################################################################ ################################################################接口################################################################ - // 操作记录留存 - // $data = ['aud_id'=>'xxxxxxxxxxxxxxx','order_list'=>[1,2,3,4,5]] - public function abnormal_data_log_action($dacall_methoda = 0,$content='未记录的内容',$use_database_name='未记录的数据库名'){ - $result = Db::table('app_data_log')->insert([ - 'create_time'=>date('Y-m-d H:i:s'), - 'call_method'=>$this->base_call_method[$dacall_methoda], - 'content'=>$content, - 'use_database_name'=>$use_database_name, - ]); + // 接口记录 + public function record_api_log($params, $error = null, $response = null){ + $logContent = "接口请求参数:" . json_encode($params, JSON_UNESCAPED_UNICODE) . PHP_EOL; + if ($error) { + $logContent .= "错误信息:" . $error['all_content'] . PHP_EOL; + if(!cache($error['flie']."_".$error['line'])){ + cache($error['flie']."_".$error['line'],"API错误",3600); + $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>$logContent]); + } + } + if ($response) { + $logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL; + } + // 使用ThinkPHP的日志记录方法 + Log::record($logContent, 'api_log'); + } - // 检查变量是否是一个只有数字的一维数组 - public function is_num_array($array = [1,2,3],$type=1) { + public function is_num_array($array = [1,2,3]) { if (!is_array($array)) { return false; // 变量不是数组 } @@ -55,10 +72,8 @@ class Base extends Controller{ return false; // 数组中包含非数字元素 } } - if($type!=1){ - return true; - } - $result = Db::table('app_card_data')->where(['is_del'=>0])->cache(true,3600)->select();//查询结果缓存3600秒 + + $result = Db::table($this->base_use_db_name['2'])->where(['is_del'=>0])->cache(true,600)->select();//查询结果缓存3600秒 if(empty(array_diff($array, array_column($result, 'id')))){ return true;// 数组是一维的且只包含数字,且已经跟数据库比对过,每个数值都是有效 }else{ @@ -66,7 +81,7 @@ class Base extends Controller{ } } public function validate_user_identity($data) { - $validate_user = Db::table('app_user_data')->where(['id'=>$data])->count(); + $validate_user = Db::table($this->base_use_db_name['3'])->where(['id'=>$data])->count(); if($validate_user<=0){ return false; }else{ @@ -121,33 +136,57 @@ class Base extends Controller{ // 判断token是否过期 public function token_time_validate($token){ - // if(in_array($token,$this->ceshiyong_token)){ - // return true; - // } - // $time = cache($token); - // if($time === false){ - // Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token', 'log'); - // return false; - // } - // $diff_time = bcsub(time(),$time,0); - // if($diff_time > $this->token_time){ - // Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因当前时间戳减去记录时间戳后为'.$diff_time.'秒,大于规定秒数'.$this->token_time, 'log'); - // return false; - // } - // cache($token, time()); - // Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的秒数为'.time(), 'log'); - // return true; - - - if(cache($token) === false){ - Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token,或该token已经超过30天', 'log'); + // 591b70e0d80b5fa6d77e6e1384453ab9 + if(is_string($token)){ + $length = strlen($token); + if ($length < 10 ) { + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,字符串长度小于10', 'token_log'); + return false; + } + }else{ + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,不是字符串', 'token_log'); return false; } - $time_now = date('Y-m-d H:i:s'); - cache($token,$time_now,$this->token_time); - Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.$time_now, 'log'); - return true; + $user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->field('id,login_time')->find(); + if(!$user_login){ + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,未找到用户token', 'token_log'); + return false; + } + + // 创建 DateTime 对象来表示指定的日期和时间 + $specifiedDateTime = new \DateTime($user_login['login_time']); + + // 获取当前时间的 DateTime 对象 + $currentDateTime = new \DateTime(); + + // 计算两个日期之间的差异(以秒为单位) + $interval = $currentDateTime->diff($specifiedDateTime); + + // 将差异转换为天数(注意:这里的天数可能不是整数,因为差异可能包括小时、分钟等) + $daysDifference = $interval->days; + + // 如果需要更精确的计算(包括小时、分钟等转换成的天数),可以使用以下方式: + // $totalSecondsDifference = $interval->format('%a') * 86400 + $interval->format('%h') * 3600 + $interval->format('%i') * 60 + $interval->format('%s'); + // $daysDifference = floor($totalSecondsDifference / 86400); // 将总秒数转换为天数并取整 + + // 判断差异是否超过指定的天数 + if ($daysDifference > $this->token_time) { + // echo "超过 {$specifiedDays} 天"; + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token,或该token已经超过30天', 'token_log'); + return false; + } else { + // echo "未超过 {$specifiedDays} 天"; + $user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->update(['login_time'=>date('Y-m-d H:i:s')]); + if($user_login){ + Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.date('Y-m-d H:i:s'), 'token_log'); + return true; + }else{ + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,数据库更新时间未成功', 'token_log'); + return true; + } + + } } // 计算天数 @@ -190,7 +229,10 @@ class Base extends Controller{ // 第一种:用户详情(所有数据都有) // 第二种:手动记录(只有最新体重) // 第三种:修改原始体重(只有原始体重) - // dump($data); + // $result_data['target_weight'] 目标体重 + // $result_data['initial_weight'] 最初体重 + // $result_data['weight'] 最近一次测量重量 + // $result_data['initial_date'] 初始体重日期 if(count($data) > 0){ $result_data['target_weight'] = $data['target_weight']; $result_data['initial_weight'] = $data['initial_weight']; @@ -202,7 +244,6 @@ class Base extends Controller{ $result_data['cumulative_weight'] = 0; $result_data['cumulative_day'] = 0; } - // dump($result_data); return $result_data; } @@ -240,10 +281,43 @@ class Base extends Controller{ ['min_val'=>'10','max_val'=>'59','text'=>'不及格','color'=>'#FF5656'], ['min_val'=>'0','max_val'=>'9','text'=>'无效','color'=>'#FF5656'], ]; - $grade = Db::table('app_user_data')->where(['id'=>$id])->field('id,grade,gender')->find(); - if(!$grade || $grade['grade'] == 'nothing'){ + $grade = Db::table($this->base_use_db_name['3'])->where(['id'=>$id])->field('id,grade,gender,birthday')->find(); + if(!$grade){ return []; } + if($grade['grade'] == 'nothing'){ + // 计算年龄判断是属于哪个年级 + $user_age = $this->calculate_age($grade['birthday']); + if($user_age <= 7){ + $grade['grade'] = 'grade_s_1'; + }else if($user_age == 8){ + $grade['grade'] = 'grade_s_2'; + }else if($user_age == 9){ + $grade['grade'] = 'grade_s_3'; + }else if($user_age == 10){ + $grade['grade'] = 'grade_s_4'; + }else if($user_age == 11){ + $grade['grade'] = 'grade_s_5'; + }else if($user_age == 12){ + $grade['grade'] = 'grade_s_6'; + }else if($user_age == 13){ + $grade['grade'] = 'grade_m_1'; + }else if($user_age == 14){ + $grade['grade'] = 'grade_m_2'; + }else if($user_age == 15){ + $grade['grade'] = 'grade_m_3'; + }else if($user_age == 16){ + $grade['grade'] = 'grade_h_1'; + }else if($user_age == 17){ + $grade['grade'] = 'grade_h_2'; + }else if($user_age == 18){ + $grade['grade'] = 'grade_h_3'; + }else if($user_age == 19 || $user_age == 20){ + $grade['grade'] = 'grade_u_12'; + }else if($user_age >= 21){ + $grade['grade'] = 'grade_u_34'; + } + } $sql_min = "WITH RankedGrades AS ( SELECT id, @@ -251,7 +325,7 @@ class Base extends Controller{ ".$grade['grade'].", ROW_NUMBER() OVER(PARTITION BY level ORDER BY ".$grade['grade']." ASC, id ASC) AS rn FROM - pc_vitalcapacity_standard + ".$this->base_use_db_name['4']." WHERE sex = ".$grade['gender']." ) @@ -263,10 +337,7 @@ class Base extends Controller{ RankedGrades WHERE rn = 1"; - // dump($sql_min); $result_min = Db::query($sql_min); - // dump($result_min); - // die; foreach ($result_min as $key => $value) { foreach ($standard_data as $sdk => $sdv) { if($value['level'] == $sdv['text']){ @@ -280,8 +351,6 @@ class Base extends Controller{ $standard_data[0]['max_val'] = '5140'; return $standard_data; } - - // 时间日期转换 public function addCurrentTimeToDateString($dateStr) { // 将日期字符串转换为DateTime对象 @@ -301,7 +370,7 @@ class Base extends Controller{ } // 处理分秒变秒 - function convertMinutesSecondsToStringSeconds($timeString) { + public function convertMinutesSecondsToStringSeconds($timeString) { // 分割字符串获取分钟和秒 list($minutes, $seconds) = explode(':', $timeString); // 将分钟和秒转换为秒 @@ -309,6 +378,35 @@ class Base extends Controller{ return $totalSeconds; } + // 转换数字"90.00", "88.11", "66.50", ".00"为正常数字 + public function convertStringToNumber($str) { + // 去除字符串两端的空格(如果有的话) + $str = trim($str); + + // 检查字符串是否为空或只包含小数点 + if ($str === '' || $str === '.') { + return 0; + } + + // 尝试将字符串转换为浮点数 + $number = (float)$str; + + // 格式化浮点数,去掉末尾多余的零 + $formattedNumber = rtrim(rtrim(sprintf('%.2f', $number), '0'), '.'); + + // 如果结果为空字符串(比如,原字符串是“.00”),则返回0 + if ($formattedNumber === '') { + return '0'; + } + // 返回结果,转换为整数如果小数点后没有数字 + if (strpos($formattedNumber, '.') === false) { + $formattedNumber = (int)$formattedNumber; + return "$formattedNumber"; + } + + return $formattedNumber; + } + // 时间加一或者减一 public function adjustDateTime($datetimeStr, $type) { // 将时间字符串转换为时间戳 @@ -350,6 +448,7 @@ class Base extends Controller{ } + // 发送一个PSOT请求 public function postRequest($url, $data = [], $headers = []) { $ch = curl_init(); // 初始化cURL会话 @@ -367,6 +466,7 @@ class Base extends Controller{ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // POST数据 // 设置请求头 if (!empty($headers)) { + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); }else{ // 如果需要发送JSON数据,可以使用以下设置: @@ -416,44 +516,127 @@ class Base extends Controller{ } + /* 接口说明(发邮件) + * $address(收件人的邮箱地址) 数组 格式: ['460834639@qq.com','460834639@qq.com'.......] + * $content(邮件的主题数据信息) 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123'] + * $annex(附件路径信息) 字符串 + */ + public function send_email_api_error($address,$content,$annex=''){ + // $ad = '460834639@qq.com'; + $ad1 = '295155911@qq.com'; + $mail = new PHPMailer(); //实例化 + $mail->IsSMTP(); // 启用SMTP + $mail->Host = "smtp.126.com"; //SMTP服务器 163邮箱例子 + $mail->Port = 465; //邮件发送端口 + $mail->SMTPAuth = true; //启用SMTP认证 + $mail->SMTPSecure = 'ssl'; + $mail->CharSet = "UTF-8"; //字符集 + $mail->Encoding = "base64"; //编码方式 + $mail->Username = "tsf3920322@126.com"; //你的邮箱 + $mail->Password = "HLWXNRPUCTHJFIIX"; //你的密码(邮箱后台的授权密码) + $mail->From = "tsf3920322@126.com"; //发件人地址(也就是你的邮箱) + + // $mail->Subject = "微盟测试邮件"; //邮件标题 + $mail->Subject = $content['title']; //邮件标题 + + // $mail->FromName = "微盟体测中心"; //发件人姓名 + $mail->FromName = $content['from_user_name']; //发件人姓名 + + + for ($i=0; $i < count($address); $i++) { + $mail->AddAddress($address[$i], ""); //添加收件人(地址,昵称) + } + + if($annex != ''){ + // $url = ROOT_PATH. 'public' . DS . 'tsf' . DS .'demoooo.jpg'; + $mail->AddAttachment($annex,''); // 添加附件,并指定名称 + } + + $mail->IsHTML(true); //支持html格式内容 + + $neirong = $content['content']; + + $mail->Body = $neirong; //邮件主体内容 + //发送 + if (!$mail->Send()) { + + return ['code' => 10003,'msg'=>$mail->ErrorInfo]; + // return $mail->ErrorInfo; + } else { + return ['code' => 0]; + // return 'success'; + } + } + + + + // 验证是否字符串 + public function verify_data_is_ok($data = 2,$type){ + if($type == 'str'){ + if (is_string($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]); + return false; + } + }else if($type == 'num'){ + if (is_numeric($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]); + return false; + } + }else if($type == 'intnum'){ + $pattern = '/^\d+$/'; + if (preg_match($pattern, $data)) { + return true; // 匹配成功,返回 true + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]); + return false; // 匹配失败,返回 false + } + }else if($type == 'datetime'){ + $formats = ['Y-m-d','Y-m-d H:i:s']; + foreach ($formats as $format) { + $dateTime = \DateTime::createFromFormat($format, $data); + // 检查时间字符串是否成功解析,并且解析后的日期时间与原始字符串表示的时间一致 + if ($dateTime && $dateTime->format($format) === $data) { + return true; + } + } + // 如果所有格式都解析失败,则返回 false + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]); + return false; + }else if($type == 'other'){ + + } + + } + public function ceshiyong($aa = 4,$gd = 0.2){ - $token = 'caadd1be045a65f30b92aa805f1de54a'; - // $jieguo = $this->token_time_validate($token); - // // // Log::record('用户尝试更新token时间,token:' . $token, 'log'); - // // // phpinfo(); - // // dump($jieguo); - // // // return $jieguo; - // // die; - // // cache($token, time()); - // $time = cache($token); - dump($token); - // dump($time); - die; + $token = 'cd3f27cf4c4002170ea7bceeb723ac91'; - - - - // $aa = 3; - // dump($aa/20); - $a = $aa; - for ($i=0; $i < 100; $i++) { - dump($a.'======='.$a/$aa*100); - $a = $a - $gd; - if($a < 0){ - break; + $data = Db::table('pc_bmistand2')->select(); + for ($i=0; $i < count($data); $i++) { + foreach ($data[$i] as $key => $value) { + $data[$i][$key] = str_replace(' ', '',$data[$i][$key]); + } + Db::table('pc_bmistand2')->where(['id'=>$data[$i]['id']])->update([ + 'month'=>$data[$i]['month'], + 'sex'=>$data[$i]['sex'], + // 'f3sd'=>$data[$i]['f3sd'], + // 'f2sd'=>$data[$i]['f2sd'], + 'f1sd'=>$data[$i]['f1sd'], + 'median'=>$data[$i]['median'], + 'z1sd'=>$data[$i]['z1sd'], + 'z2sd'=>$data[$i]['z2sd'], + // 'z3sd'=>$data[$i]['z3sd'], + ]); } - // $aa = 15; - // $a = 1; - // for ($i=0; $i < 100; $i++) { - // dump($aa.'======='.$aa/17.5*100); - // $aa = $aa - $a; - // if($aa < 1){ - // break; - // } - // } + die; + // $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>'123']); } diff --git a/application/app/controller/Calculatebody.php b/application/app/controller/Calculatebody.php index 14433fb..66714a0 100644 --- a/application/app/controller/Calculatebody.php +++ b/application/app/controller/Calculatebody.php @@ -61,14 +61,15 @@ class Calculatebody extends Base{ $temporary_parameter = [ 'weight'=>$data['weight'], 'height'=>$data['height'], - 'age'=>$data['age'], - 'adc'=>$data['adc'], + 'age'=>round($data['age']),//四舍五入取整 + 'adc'=>round($data['adc']),//四舍五入取整 'gender'=>$data['gender'], ]; - // dump($temporary_parameter); - $request_result = $this->postRequest($url,$temporary_parameter); - // dump($request_result); + if($request_result['code'] != 0){ + return false; + } + $result['weight'] = $request_result['data']['weight']; $result['height'] = $request_result['data']['height']; $result['bmi'] = $request_result['data']['bmi']; @@ -89,8 +90,6 @@ class Calculatebody extends Base{ $result['bodyage'] = $request_result['data']['bodyage']; $result['lbm'] = $request_result['data']['lbm']; $result['body'] = $request_result['data']['body']; - // dump($result); - // die; // 使用接口调用之前的进行计算end $return_data['体重'] = $data['weight']; @@ -344,8 +343,6 @@ class Calculatebody extends Base{ $return_data['身体年龄'] = $result['bodyage']; - // dump($return_data); - // die; // $result_end['fat_r'] = $result['fat_r']; // $result_end['muscle'] = $result['muscle']; // $result_end['water'] = $result['water']; @@ -365,11 +362,7 @@ class Calculatebody extends Base{ // $result_end['lbm'] = $result['lbm']; // $result_end['weight'] = $result['weight']; // $result_end['height'] = $result['height']; - // dump($return_data); - // dump('========================================='); return $return_data; - // dump($result_end); - // die; } // 加 bcadd(,,20) @@ -387,10 +380,7 @@ class Calculatebody extends Base{ if (($weight <= 0) || ($weight > 220) || ($height <= 0) || ($height > 270) || ($age <= 0) || ($age > 120) || ($impedance <= 0) || ($impedance > 1000) || !in_array($gender, [1, 2])) { if ($weight != 0 && $height != 0) { // 计算BMI - // dump(bcmul($mheight, $mheight,20)); - // $bmi = bcmul(bcdiv($weight, bcmul($mheight, $mheight,20), 20), '10.0', 20); // 先算除法再算乘法 $bmi = bcdiv($weight, bcmul($mheight, $mheight,20), 2); - // $bmi = bcdiv($bmi, '10.0', 2); // 最后除以10,保留2位小数 $result_data['bmi'] = $bmi; $result_data['bone'] = 0; $result_data['muscle'] = 0; @@ -411,10 +401,6 @@ class Calculatebody extends Base{ return $result_data; } } - - // $num = bcmul(bcdiv($weight, bcmul($mheight, $mheight,20), 20), '10.0', 20); - // $num = bcdiv($num, '10.0', 2); // 确保最后结果也保留20位小数 - $num = intval(bcmul(bcdiv($weight,bcmul($mheight,$mheight,20),20),'10',20))/10; $num2 = 0.0; $num3 = 0.0; @@ -426,16 +412,9 @@ class Calculatebody extends Base{ $num9 = 0.0; $num10 = 0.0; $num11 = 0.0; - + // 根据男女计算脂肪率、脂肪量、肌肉率、肌肉量等等.... $standard_weight = 0.0; $standard_level = 0.0; - - - // dump($gender); - // 加 bcadd(,,20) - // 减 bcsub(,,20) - // 乘 bcmul(,,20) - // 除 bcdiv(,,20) if ($gender == 1){ // $num2 = 0.015 * $weight + (2.0 - 0.00055 * $impedance) * $height / 100 - 1.15; $num2 = bcsub(bcadd(bcmul('0.015',$weight,20),bcdiv(bcmul(bcsub('2.0',bcmul('0.00055',$impedance,20),20),$height,20),'100.0',20),20),'1.15',2); @@ -503,13 +482,11 @@ class Calculatebody extends Base{ $num3 = '75.0'; } // $result_data['muscle'] = ($num3 < 15.0) ? 15.0 : $num3; - // dump($num3); if(bccomp($num3, '15.0', 20) === -1){ $result_data['muscle'] = '15.00'; }else{ $result_data['muscle'] = $num3; } - // dump($num4); // $num4 = (($num4 > 70.0) ? 70.0 : $num4); if(bccomp($num4, '70.0', 20) === 1){ $num4 = '70.0'; @@ -530,7 +507,6 @@ class Calculatebody extends Base{ $result_data['fat_r'] = '5.00'; }else{ // $result_data['fat_r'] = $num5; - // dump($num5); $result_data['fat_r'] = substr($num5, 0, strpos($num5, ".") + 3); } // $result_data['sfr'] = $num6 <= 0 ? "0" : $num6; @@ -572,11 +548,9 @@ class Calculatebody extends Base{ $standard_level = bcdiv(bcsub($weight,$standard_weight,20),$standard_weight,2); // 加 bcadd(,,20) // 减 bcsub(,,20) - // dump($num11); if ($age < 18){ $num11 = $age; }else{ - // dump($num11); // $num11 = (($num11 > ($age + 10)) ? (($age + 10)) : $num11); if(bccomp($num11, $age + 10, 20) === 1){ $num11 = $age + 10; @@ -586,7 +560,6 @@ class Calculatebody extends Base{ $num11 = $age - 10; } } - // dump($age); $result_data['bodyage'] = $num11; $result_data['weight'] = $weight; @@ -595,13 +568,10 @@ class Calculatebody extends Base{ $result_data['adc'] = $impedance; $result_data['gender'] = $gender; $result_data['standard_level'] = $standard_level; - // dump($result_data); - // die; return $result_data; } // 计算脂肪率 function calculate_fat_r(){ - dump(123); } // 计算脂肪量 function calculate_zhifangliang(){ diff --git a/application/app/controller/Card.php b/application/app/controller/Card.php index c838a9d..52a43ec 100644 --- a/application/app/controller/Card.php +++ b/application/app/controller/Card.php @@ -2,19 +2,25 @@ namespace app\app\controller; -use think\Controller; use think\Db; -use app\bj\controller\Common; -use think\Log; -use \think\Validate; use app\app\controller\Calculatebody; use app\app\controller\Cardparts; -use app\app\controller\Skip; class Card extends Base{ protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6']; - + protected $card_use_db_name = [ + '1'=>'app_card_body_data', + '2'=>'app_user_data', + '3'=>'pc_bmistand', + '4'=>'pc_heightstand', + '5'=>'pc_weightstand', + '6'=>'pc_childrenprescription', + '7'=>'pc_childprescriptionbyage', + '8'=>'pc_heightstand', + '9'=>'pc_weightstand', + '10'=>'pc_bmistand', + ]; protected $age_limit = 16; protected $unit_symbol = ['score'=>'分','height'=>'CM','weight'=>'公斤','bmi'=>'','fat_r'=>'%','fat_w'=>'kg','muscle'=>'%','muscleval'=>'kg','water'=>'kg','bone'=>'kg','protein'=>'%','proteinval'=>'kg','kcal'=>'kcal','visceral'=>'','sfr'=>'%',]; protected $unit_name = ['score'=>'身体得分','height'=>'身高','weight'=>'体重','bmi'=>'BMI','fat_r'=>'脂肪率','fat_w'=>'脂肪量','muscle'=>'肌肉率','muscleval'=>'肌肉量','water'=>'水分','bone'=>'骨重','protein'=>'蛋白率','proteinval'=>'蛋白量','kcal'=>'基础代谢','visceral'=>'内脏指数','sfr'=>'皮下脂肪','body_level'=>'肥胖等级','body_type'=>'身体类型']; @@ -49,7 +55,7 @@ class Card extends Base{ 'proteinval'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], 'bone'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], 'protein'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], - 'kcal'=>['偏低'=>'#FF5656','优'=>'#5ad06d'], + 'kcal'=>['偏低'=>'#FF5656','优'=>'#3A68D4'], 'visceral'=>['标准'=>'#55CF6C','警惕'=>'#FEAC00','危险'=>'#FB5A52'], 'sfr'=>['不足'=>'#FCDB68','标准'=>'#59D16F','偏高'=>'#FEAB03'], ]; @@ -71,9 +77,10 @@ class Card extends Base{ 'weight'=>['value'=>3,'list'=>['低'=>1,'偏低'=>1,'标准'=>2,'偏高'=>3,'高'=>3]], 'bmi'=>['value'=>2,'list'=>['消瘦'=>1,'正常'=>2,'偏重'=>3,'肥胖'=>4]], ]; - - - + protected $unit_data = [ + 'height'=>['cm','inch','ft-in'], + 'weight'=>['kg','斤','st:lb','lb'], + ]; ################################################################接口################################################################ ################################################################接口################################################################ ################################################################接口################################################################ @@ -81,139 +88,372 @@ class Card extends Base{ // 详细卡片信息 // $data = ['id'=>'2'] - public function card_data_detailed($data=['aud_id'=>'87','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function card_data_detailed($data=['aud_id'=>'37']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->get_user_body_data($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->get_user_body_data($data); } // 曲线页面-曲线接口 - public function card_curve_chart($data = ['aud_id'=>'83','s_time'=>'2024-04-01','e_time'=>'2024-07-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function card_curve_chart($data = ['aud_id'=>'11','s_time'=>'2024-04-01','e_time'=>'2024-10-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + $return_data = $this->curve_chart_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // $data['s_time'] = $data['s_time'].' 00:00:00'; - // $data['e_time'] = $data['e_time'].' 23:59:59'; - return $this->curve_chart_action($data); + } // 手动记录 // $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1'] - public function card_manual_recording($data = ['aud_id'=>'83','time'=>'2024-07-24','height'=>'145.7','weight'=>'41.3','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - }else{ - $data['time'] = date('Y-m-d H:i:s'); + // public function card_manual_recording($data = ['aud_id'=>'37','time'=>'2024-10-12','height'=>'144.7,cm','weight'=>'36.8,kg','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + public function card_manual_recording($data = ['aud_id'=>'37','time'=>'2024-10-12','height'=>'144.7','weight'=>'36.8','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + }else{ + $data['time'] = date('Y-m-d H:i:s'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['height'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['weight'],'num')){ + return $this->msg(10005); + } + // $data['height'] = explode(',',$data['height']); + // if(count($data['height']) < 2){ + // return $this->msg(10005); + // } + // if(!$this->verify_data_is_ok($data['height'][0],'num')){ + // return $this->msg(10005); + // } + // if(!in_array($data['height'][1],$this->unit_data['height'])){ + // return $this->msg(10005); + // } + // $data['weight'] = explode(',',$data['weight']); + // if(count($data['height']) < 2){ + // return $this->msg(10005); + // } + // if(!$this->verify_data_is_ok($data['weight'][0],'num')){ + // return $this->msg(10005); + // } + // if(!in_array($data['weight'][1],$this->unit_data['weight'])){ + // return $this->msg(10005); + // } + $data['acd_id'] = '2'; + $return_data = $this->set_user_body_data($data,'by_hand_means'); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - // dump($data); - // die; - if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $data['acd_id'] = '2'; - return $this->set_user_body_data($data); + } // 设备记录 // $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1'] - public function card_manual_recording_device($data = ['aud_id'=>'58','height'=>'175','weight'=>'68','adc'=>'550','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - }else{ + // public function card_manual_recording_device($data = ['aud_id'=>'37','height'=>'169.60,inch','weight'=>'52.45,lb','adc'=>'520.3','token'=>'591b70e0d80b5fa6d77e6e1384453ab9']){ + public function card_manual_recording_device($data = ['aud_id'=>'37','height'=>'169.60','weight'=>'52.45','adc'=>'520.3','token'=>'591b70e0d80b5fa6d77e6e1384453ab9']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + }else{ + $data['time'] = date('Y-m-d H:i:s'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['height'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['weight'],'num')){ + return $this->msg(10005); + } + // $data['height'] = explode(',',$data['height']); + // if(count($data['height']) < 2){ + // return $this->msg(10005); + // } + // if(!$this->verify_data_is_ok($data['height'][0],'num')){ + // return $this->msg(10005); + // } + // if(!in_array($data['height'][1],$this->unit_data['height'])){ + // return $this->msg(10005); + // } + // $data['weight'] = explode(',',$data['weight']); + // if(count($data['height']) < 2){ + // return $this->msg(10005); + // } + // if(!$this->verify_data_is_ok($data['weight'][0],'num')){ + // return $this->msg(10005); + // } + // if(!in_array($data['weight'][1],$this->unit_data['weight'])){ + // return $this->msg(10005); + // } + if(!$this->verify_data_is_ok($data['adc'],'num')){ + return $this->msg(10005); + } $data['time'] = date('Y-m-d H:i:s'); + $data['acd_id'] = '2'; + $return_data = $this->set_user_body_data($data,'by_device'); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - // dump($data); - // die; - if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($data['adc'] == 0){ - $data['adc'] = 550; - } - $data['time'] = date('Y-m-d H:i:s'); - // if($this->token_time_validate($data['token']) === false){ - // return $this->msg(20001); - // } - // unset($data['token']); - $data['acd_id'] = '2'; - return $this->set_user_body_data($data); + } // 修改初始体重/目标体重 - public function card_modify_weight($data = ['aud_id'=>'25','weight'=>'25','type'=>1,'time'=>'','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function card_modify_weight($data = ['aud_id'=>'11','weight'=>'50','type'=>2,'time'=>'2024-10-01','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!is_array($data)){ + return $this->msg(10005); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('weight', $data) || !array_key_exists('type', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['weight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + if($data['type'] != 1){ + if(!$this->verify_data_is_ok($data['time'],'datetime')){ + return $this->msg(10005); + } + } + + $return_data = $this->modify_weight_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!is_array($data)){ - return $this->msg(10005); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('weight', $data) || !array_key_exists('type', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->modify_weight_action($data); } - // // 删除历史数据 - // public function card_del_record_data($data = ['id'=>'16','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - // if(count(input('post.')) > 0){ - // $data = input('post.'); - // } - // if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ - // return $this->msg(10001); - // } - // if($this->token_time_validate($data['token']) === false){ - // return $this->msg(20001); - // } - // unset($data['token']); - // $user_data = Db::table('app_card_body_data')->where(['id'=>$data['id']])->update(['is_del'=>1]); - // if($user_data){ - // return $this->msg([]); - // }else{ - // return $this->msg(10002); - // } - // } - // // 数据对比 - // public function card_data_contrast($data = ['before_id'=>'24','after_id'=>'25','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - // if(count(input('post.')) > 0){ - // $data = input('post.'); - // } - // if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('token', $data)){ - // return $this->msg(10001); - // } - // if($this->token_time_validate($data['token']) === false){ - // return $this->msg(20001); - // } - // unset($data['token']); - // // $data = explode(',',$data['id_arr']); - // // dump($data); - // // die; - // return $this->body_data_contrast($data); - // } + // 身高预测 + public function card_height_prediction($data = ['dadHeight'=>'199','momHeight'=>'160','birthday'=>'2014-07-24','sex'=>'1',]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!is_array($data)){ + return $this->msg(10005); + } + if(!array_key_exists('dadHeight', $data) || !array_key_exists('momHeight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){ + return $this->msg(10001); + } + unset($data['token']); + if(!$this->verify_data_is_ok($data['birthday'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['dadHeight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['momHeight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['sex'],'intnum')){ + return $this->msg(10005); + } + + // 直接开始业务,请求外部接口start + $url = 'https://ybapi.pcxbc.com/api/child/predictheight'; + $temporary_parameter = [ + 'dadHeight'=>$data['dadHeight'], + 'momHeight'=>$data['momHeight'], + 'birthday'=>$data['birthday'], + 'sex'=>$data['sex'], + ]; + $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com')); + // 直接开始业务,请求外部接口end + $this->record_api_log($data, null, $request_result); + return json($request_result); + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } + + // BMI测评 + public function card_bmi_evaluation($cbe_data = ['height'=>'177','weight'=>'177','birthday'=>'2024-10-03','sex'=>'1'],$type = false){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0 && $type == false){ + $cbe_data = input('post.'); + } + if(!is_array($cbe_data)){ + return $this->msg(10005); + } + if(!array_key_exists('height', $cbe_data) || !array_key_exists('weight', $cbe_data) || !array_key_exists('birthday', $cbe_data) || !array_key_exists('sex', $cbe_data)){ + return $this->msg(10001); + } + unset($cbe_data['token']); + if(!$this->verify_data_is_ok($cbe_data['birthday'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($cbe_data['height'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($cbe_data['weight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($cbe_data['sex'],'intnum')){ + return $this->msg(10005); + } + + // 直接开始业务,请求外部接口start + $url = 'http://ybdevice.pcxbc.com/api/result/calcbmi'; + $temporary_parameter = [ + 'height'=>$cbe_data['height'], + 'weight'=>$cbe_data['weight'], + 'birthday'=>$cbe_data['birthday'], + 'sex'=>$cbe_data['sex'], + ]; + $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com')); + // 直接开始业务,请求外部接口end + + // 处理进度点 + $request_result =$this->bmi_evaluation_action($request_result); + $this->record_api_log($cbe_data, null, $request_result); + return $request_result; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($cbe_data, $logContent, null); + return $this->msg(99999); + } + } ################################################################业务接口################################################################ ################################################################业务接口################################################################ @@ -221,19 +461,12 @@ class Card extends Base{ ################################################card_data_detailed // 用户身体数据卡片获取 public function get_user_body_data($data){ - // $result = Db::table('app_card_body_data') - // ->alias('acbd') - // ->join('app_user_data aud','acbd.aud_id = aud.id','LEFT') - // ->where(['acbd.aud_id'=>$data['aud_id']]) - // ->order('acbd.record_time desc') - // ->field('acbd.*,aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date') - // ->find(); - // dump($data); $result = Db::query(" select Top 1 acbd.id, acbd.acd_id, + acbd.record_type, acbd.create_time, acbd.last_update_time, acbd.score, @@ -255,34 +488,88 @@ class Card extends Base{ acbd.age, acbd.is_del, acbd.height, + acbd.height_val, acbd.weight, + acbd.weight_val, acbd.bmi, acbd.body_age, aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date - from app_card_body_data as acbd - left join app_user_data as aud on acbd.aud_id=aud.id - where acbd.aud_id='".$data['aud_id']."' + from ".$this->card_use_db_name['1']." as acbd + left join ".$this->card_use_db_name['2']." as aud on acbd.aud_id=aud.id + where acbd.is_del=0 and acbd.aud_id='".$data['aud_id']."' order by acbd.record_time desc "); - // dump($result); - // die; - if(!$result){ - return $this->msg(10004); + + if(count($result) <= 0){ + $result_return = [ + "score_name"=>"", + "score_value"=>"", + "score_unit"=>"", + "body_type_name"=>"", + "body_type_value"=>"", + "body_type_unit"=>"", + "record_time"=>"", + 'top_list'=>[ + [ + "name"=>"体重", + "value"=>"0", + "unit"=>"公斤", + "standard"=>"", + "color"=>"", + "list"=>[], + "key_name"=>"weight", + "desc"=>"反映和衡量一个人健康状况的重要标志之一", + "offset"=>"0" + ], + [ + "name"=>"身高", + "value"=>"0", + "unit"=>"CM", + "standard"=>"", + "color"=>"", + "list"=>[], + "key_name"=>"height", + "desc"=>"人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大", + "offset"=>"0" + ], + [ + "name"=>"BMI", + "value"=>"0", + "unit"=>"公斤", + "standard"=>"", + "color"=>"", + "list"=>[], + "key_name"=>"bmi", + "desc"=>"BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。", + "offset"=>"0" + ], + ], + 'bottom_list' => [], + 'cplist'=>[ + 'nutritionlist'=>[], + 'sportlist'=>[], + 'sleeplist'=>[], + 'moodlist'=>[], + ], + 'literature'=>[], + 'target_current'=>[ + 'target_weight'=>'0', + 'initial_weight'=>'0', + 'cumulative_weight'=>'0', + 'cumulative_day'=>'0' + ], + ]; + return $this->msg($result_return); }else{ - // $curve_bottom = $this->card_curve_target_action($result); + $result_end = $this->processing_return_data_new($result[0]); - // dump($result_end); - // die; $cardparts = new Cardparts; - // dump($result_end); $result_end['gender'] = $result[0]['gender']; $result_end['record_time'] = $result[0]['record_time']; $result_end['score'] = $result_end['score']; $result_end['body_type'] = $result_end['body_type']; $result_end = $cardparts->conversion_interval($result_end); - // dump($result); - // dump($result_end); - // die; + $result_end['cplist'] = $this->grow_up_recommendation([ 'birthday'=>$result[0]['birthday'], 'body'=>[ @@ -291,50 +578,79 @@ class Card extends Base{ 'bmi'=>$result[0]['bmi'] ], ]); - if(count($result_end['cplist']['nutritionlist']) <= 0){ - // $result_end['cplist'] = []; - $result_end['literature'] = []; + // 只有含有阻抗的记录才有数据参考 + if($result[0]['record_type'] == 'by_device_adc'){ + if(count($result_end['cplist']['nutritionlist']) <= 0){ + $result_end['literature'] = []; + }else{ + $result_end['literature'] = [ + '《中华人民共和国卫生行业标准WS 423-2013》', + '《中华人民共和国卫生行业标准WS/T 612-2018》', + '《中华人民共和国卫生行业标准WS/T1586-2018》', + '《WHO 5~19岁身高/体重判定标准》', + ]; + } }else{ - $result_end['literature'] = [ - '《中华人民共和国卫生行业标准WS 423-2013》', - '《中华人民共和国卫生行业标准WS/T 612-2018》', - '《中华人民共和国卫生行业标准WS/T1586-2018》', - '《WHO 5~19岁身高/体重判定标准》', - ]; + $result_end['literature'] = []; } + + // 加入曲线板块底部的减肥计划数据start + $result_end['target_current'] = $this->base_target_initial_cumulative_weight([ + 'weight'=>$result[0]['weight']>0?$result[0]['weight']:0, + 'target_weight'=>$result[0]['target_weight']>0?$result[0]['target_weight']:0, + 'initial_weight'=>$result[0]['initial_weight']>0?$result[0]['initial_weight']:0, + 'initial_date'=>$result[0]['initial_date']!=null?$result[0]['initial_date']:0, + ]); + + if(count($result_end['top_list'][2]['list']) <= 0){ + // 这是16岁以上人群 + $data = [ + 'height'=>$result[0]['height_val'], + 'weight'=>$result[0]['weight_val'], + 'birthday'=>$result[0]['birthday'], + 'sex'=>$result[0]['gender'] + ]; + + $temporary_arr_bmi_list = $this->card_bmi_evaluation($data,true); + $temporary_arr_bmi_list = $temporary_arr_bmi_list->getData(); + + if($temporary_arr_bmi_list['code'] == 0){ + $result_end['top_list'][2]['standard'] = $temporary_arr_bmi_list['data']['bmilevel']; + $result_end['top_list'][2]['color'] = $temporary_arr_bmi_list['data']['bmilevelcolor']; + $result_end['top_list'][2]['list'] = $temporary_arr_bmi_list['data']['bmilevellist']; + $result_end['top_list'][2]['offset'] = $temporary_arr_bmi_list['data']['offset']; + } + } + + // 加入曲线板块底部的减肥计划数据end return $this->msg($result_end); } } // 返回数据处理 public function processing_return_data_new($data){ - // dump($data); $result_end_data = []; $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']); $gender_val = $data['gender']; - // dump($data); - // dump($this->result_end_data_mould); - // die; foreach ($data as $key => $value) { if($key != 'aud_id' && $key != 'id' && $key != 'create_time' && $key != 'last_update_time' && $key != 'acd_id' && $key != 'ROW_NUMBER' && $key != 'record_time' && $key != 'gender' && $key != 'birthday'){ - // dump($key); // 设置单个数据格式 $result_end_data[$key] = $this->result_end_data_mould; + // 该项名 if(array_key_exists($key, $this->unit_name)){ $result_end_data[$key]['name'] = $this->unit_name[$key]; } + // 该项单位 if(array_key_exists($key, $this->unit_symbol)){ $result_end_data[$key]['unit'] = $this->unit_symbol[$key]; } + $result_end_data[$key]['value'] = explode(',',$value)[0]; + if(strpos($value, ',')){ $result_end_data[$key]['standard'] = explode(',',$value)[1]; } - // dump($result_end_data[$key]); if(array_key_exists($key, $this->standard_color)){ - // dump($key); - // dump($result_end_data[$key]); - // dump($this->standard_color[$key]); - if($result_end_data[$key]['standard'] != '异常'){ + if($result_end_data[$key]['standard'] != '异常' && $result_end_data[$key]['standard'] != ''){ $result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']]; } } @@ -343,9 +659,7 @@ class Card extends Base{ if(array_key_exists($key, $this->bhw_list)){ $result_end_data[$key]['list'] = $this->bhw_list[$key]; if($key == 'bmi'){ - // dump($month_num); - $bhw_date = Db::table('pc_bmistand')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); - // dump($bhw_date); + $bhw_date = Db::table($this->card_use_db_name['3'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f1sd']; $result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f1sd']; @@ -355,7 +669,7 @@ class Card extends Base{ $result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z2sd']; } }else if($key == 'height'){ - $bhw_date = Db::table('pc_heightstand')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + $bhw_date = Db::table($this->card_use_db_name['4'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd']; $result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd']; @@ -368,9 +682,7 @@ class Card extends Base{ $result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd']; } }else if($key == 'weight'){ - $bhw_date = Db::table('pc_weightstand')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); - // dump($value); - // dump($bhw_date);/ + $bhw_date = Db::table($this->card_use_db_name['5'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd']; $result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd']; @@ -387,10 +699,6 @@ class Card extends Base{ } } } - // $result_end_data['age'] = $data['age']; - // dump($data['age']); - // dump($result_end_data); - // die; return $result_end_data; } @@ -426,15 +734,14 @@ class Card extends Base{ $min_value = min($temporary_arr); $min_key = array_search($min_value,$temporary_arr); $type_num = $this->card_body_level[$min_key]['value']; - $temporary_arr2 = Db::table('pc_childrenprescription')->where(['Type'=>$type_num,'Level'=>$min_value,'IsDeleted'=>0])->field('Nutrition,Sport')->find(); - // dump($temporary_arr2); + $temporary_arr2 = Db::table($this->card_use_db_name['6'])->where(['Type'=>$type_num,'Level'=>$min_value,'IsDeleted'=>0])->field('Nutrition,Sport')->find(); array_push($result['nutritionlist'],$temporary_arr2['Nutrition']); array_push($result['sportlist'],$temporary_arr2['Sport']); // $result['nutritionlist'] = $temporary_arr2['Nutrition']; // $result['sportlist'] = $temporary_arr2['Sport']; $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']); - $temporary_arr2 = Db::table('pc_childprescriptionbyage')->where(['IsDeleted'=>0])->field('MinAge,MaxAge,Type,Content')->select(); + $temporary_arr2 = Db::table($this->card_use_db_name['7'])->where(['IsDeleted'=>0])->field('MinAge,MaxAge,Type,Content')->select(); $default_sleep = ''; $default_emotion = ''; foreach ($temporary_arr2 as $key => $value) { @@ -469,35 +776,17 @@ class Card extends Base{ // 曲线图动作函数 public function curve_chart_action($data){ $card_body_curve_arr = implode(',',$this->card_body_curve_arr); - // $user_data_list = Db::query(" - // select - // record_time, - // $card_body_curve_arr - // from app_card_body_data - // where aud_id='".$data['aud_id']."' - // and record_time between '".$data['s_time']."' - // and '".$data['e_time']."' - // order by record_time desc - // "); - // dump($card_body_curve_arr); - // dump($this->card_body_curve_arr); - // dump($data); - // $data['s_time'] = $this->adjustDateTime($data['s_time'],'subtract'); - // $data['e_time'] = $this->adjustDateTime($data['e_time'],'add'); - // dump($data); - // die; $data['s_time'] = $data['s_time'].' 00:00:00'; $data['e_time'] = $data['e_time'].' 23:59:59'; - $user_data_list = Db::table('app_card_body_data') + $user_data_list = Db::table($this->card_use_db_name['1']) ->where('aud_id', $data['aud_id']) ->whereTime('record_time', 'between', [$data['s_time'], $data['e_time']]) ->field("record_time,REPLACE(CONVERT(varchar(10), record_time, 23), '-', '-') AS b_time,$card_body_curve_arr") // ->field("record_time,REPLACE(CONVERT(varchar(10), record_time, 23), '-', '/') AS b_time,$card_body_curve_arr") ->order('record_time desc') ->select(); - // dump($user_data_list); // 下面业务逻辑是取每天的,最近后一次记录成绩 $data_arr = []; @@ -516,9 +805,6 @@ class Card extends Base{ array_push($record_arr2,$user_data_list[$key]); } } - // dump($record_arr1); - // dump($record_arr2); - // die; foreach ($this->card_body_curve_arr as $key => $value) { $temporary_arr = []; $temporary_arr['title'] = $this->card_body_curve_arr2[$key]; @@ -533,21 +819,36 @@ class Card extends Base{ array_push($data_arr,$temporary_arr); } } - // dump($data_arr); return $this->msg($data_arr); } ################################################card_manual_recording // 用户身体数据卡片记录 - public function set_user_body_data($data){ - + public function set_user_body_data($data,$type){ + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + // // 这里开始转换不同单位的身高体重为cm跟kg(start) + // if($data['height'][1] == 'kg'){ + // $data['height'] = $data['height'][0]; + // }else if($data['height'][1] == '斤'){ + // // 斤数除以2就是公斤 + // $data['height'] = bcdiv($data['height'][0],2,2); + // }else if($data['height'][1] == 'st:lb'){ + // $data['height'] = $data['height'][0]; + // }else if($data['height'][1] == 'lb'){ + // $data['height'] = $data['height'][0]; + // } + // // 这里开始转换不同单位的身高体重为cm跟kg(end) + // $adc_type = $type; $data['type'] = 1; - $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('birthday,gender,target_weight,initial_weight,initial_date')->find(); + $user_data = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->field('birthday,gender,target_weight,initial_weight,initial_date')->find(); if(!$user_data){ return $this->msg(10003); } if($user_data['initial_date'] == null){ - Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]); + Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]); $target_current = $this->base_target_initial_cumulative_weight([ 'weight'=>$data['weight'], 'target_weight'=>$user_data['target_weight'], @@ -567,12 +868,21 @@ class Card extends Base{ $result_data['age'] = $this->calculate_age($user_data['birthday']); $result_data['gender'] = $user_data['gender']; if(array_key_exists('adc', $data)){ - $result_data['adc'] = $data['adc']; + if($data['adc'] > 0){ + $result_data['adc'] = $data['adc']; + $type = "by_device_adc"; + }else{ + $result_data['adc'] = 550; + $type = "by_device"; + } } $calculate_body_formula = new Calculatebody(); + // 计算身体数据 $get_body_value = $calculate_body_formula->calculate_body_data_result($result_data); - + if($get_body_value === false){ + return $this->msg(10005); + } $get_body_value['gender'] = $user_data['gender']; $get_body_value['birthday'] = $user_data['birthday']; // 添加身高体重bmi的标尺标准 @@ -604,43 +914,49 @@ class Card extends Base{ 'sfr'=>implode(',',$get_body_value['皮下脂肪']), 'body_level'=>$get_body_value['肥胖等级'], 'body_type'=>$get_body_value['身体类型'], - 'body_age'=>$get_body_value['身体年龄'] + 'body_age'=>$get_body_value['身体年龄'], + 'record_type' => $type ]; if(strlen($set_data['record_time']) <= 12){ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式 $set_data['record_time'] = $this->addCurrentTimeToDateString($set_data['record_time']); } - - $set_user_data = Db::table('app_card_body_data')->insert($set_data); - if($set_user_data){ - // 返回简要数据 - if($data['type'] == 1){ - return $this->msg([ - 'acd_id'=>2, - 'height'=>$get_body_value['身高'].',CM', - 'weight'=>$get_body_value['体重'].',公斤', - 'bmi'=>$get_body_value['BMI'], - 'target_current'=>$target_current, - ]); - } + // 启动事务 + Db::startTrans(); + try{ + $set_user_data = Db::table($this->card_use_db_name['1'])->insert($set_data); + $update_user_data = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update(['height'=>$get_body_value['身高'],'weight'=>$get_body_value['体重']]); - }else{ + // 提交事务 + Db::commit(); + return $this->msg([ + 'acd_id'=>2, + 'height'=>$get_body_value['身高'].',CM', + 'weight'=>$get_body_value['体重'].',公斤', + 'bmi'=>$get_body_value['BMI'], + // 'user_set_height'=>$get_body_value['身高'], + // 'user_set_weight'=>$get_body_value['体重'], + 'target_current'=>$target_current, + ]); + } catch (\Exception $e) { + // 回滚事务 + Db::rollback(); return $this->msg(10002); } + } // 添加身高体重bmi的标准 public function hwb_standard($data){ - $linshi_data = []; $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']); - // dump($month_num); $gender_val = $data['gender']; if($data['age'] < $this->age_limit){ foreach ($data as $key => $value) { if($key =='身高'){ $linshi_data['身高'] = $this->bhw_list['height']; - $bhw_date = Db::table('pc_heightstand2')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + $bhw_date = Db::table($this->card_use_db_name['8'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + if($bhw_date){ $linshi_data['身高'][0]['max_val'] = $bhw_date[0]['f2sd']; $linshi_data['身高'][1]['min_val'] = $bhw_date[0]['f2sd']; @@ -652,9 +968,10 @@ class Card extends Base{ $linshi_data['身高'][4]['min_val'] = $bhw_date[0]['z2sd']; $linshi_data['身高'][4]['max_val'] = $bhw_date[0]['z3sd']; } + }else if($key =='体重'){ $linshi_data['体重'] = $this->bhw_list['weight']; - $bhw_date = Db::table('pc_weightstand2')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + $bhw_date = Db::table($this->card_use_db_name['9'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $linshi_data['体重'][0]['max_val'] = $bhw_date[0]['f2sd']; $linshi_data['体重'][1]['min_val'] = $bhw_date[0]['f2sd']; @@ -668,8 +985,7 @@ class Card extends Base{ } }else if($key =='BMI'){ $linshi_data['BMI'] = $this->bhw_list['bmi']; - $bhw_date = Db::table('pc_bmistand2')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); - // dump($bhw_date); + $bhw_date = Db::table($this->card_use_db_name['10'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $linshi_data['BMI'][0]['max_val'] = $bhw_date[0]['f1sd']; $linshi_data['BMI'][1]['min_val'] = $bhw_date[0]['f1sd']; @@ -680,10 +996,7 @@ class Card extends Base{ } } } - // dump($linshi_data); - // die; foreach ($linshi_data as $key => $value) { - // dump($value); foreach ($value as $k => $v) { if($data[$key] >= $v['min_val'] && $data[$key] < $v['max_val']){ // 如果落在区间内 @@ -704,10 +1017,7 @@ class Card extends Base{ $data['体重2'] = $data['体重'].',无,无'; $data['BMI2'] = $data['BMI'].',无,无'; } - // dump($data); - // die; return $data; - // dump($data); } @@ -715,18 +1025,16 @@ class Card extends Base{ public function modify_weight_action($data){ // $data['aud_id'] = 26; // $data['weight'] = 60; - // dump($data); - // die; $result = Db::query(" select TOP 1 - acbd.weight, + acbd.weight_val as weight, aud.target_weight, aud.initial_weight, aud.initial_date - from app_card_body_data as acbd - left join app_user_data as aud on acbd.aud_id = aud.id + from ".$this->card_use_db_name['1']." as acbd + left join ".$this->card_use_db_name['2']." as aud on acbd.aud_id = aud.id where acbd.aud_id = ".$data['aud_id']." order by acbd.record_time desc "); @@ -739,10 +1047,7 @@ class Card extends Base{ }else{ return $this->msg(10005); } - $result_update = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update($bhw_date); - // dump($result_update); - // dump($result[0]['weight']); - // dump($result); + $result_update = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update($bhw_date); if($result_update){ $target_current = $this->base_target_initial_cumulative_weight([ @@ -751,8 +1056,7 @@ class Card extends Base{ 'initial_weight'=>$data['type'] == 1?$result[0]['initial_weight']:$data['weight'], 'initial_date'=>$data['type'] == 1?$result[0]['initial_date']:$data['time'], ]); - // die; - // dump($target_current); + return $this->msg($target_current); }else{ return $this->msg(10002); @@ -760,7 +1064,69 @@ class Card extends Base{ } - ################################################card_record_detailed_information + ################################################card_bmi_evaluation + public function bmi_evaluation_action($data){ + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + if(!array_key_exists('code',$data) || !array_key_exists('data',$data)){ + return $this->msg(99999,'网络异常,请稍后重试1'); + } + if($data['code'] != 0){ + return $this->msg(99999,'网络异常,请稍后重试2'); + } + if(!is_array($data['data'])){ + return $this->msg(99999,'网络异常,请稍后重试3'); + } + if(!array_key_exists('bmi',$data['data']) || !array_key_exists('bmilevel',$data['data']) || !array_key_exists('bmilevelcolor',$data['data']) || !array_key_exists('bmilevellist',$data['data'])){ + return $this->msg(99999,'网络异常,请稍后重试4'); + } + if(!is_array($data['data']['bmilevellist'])){ + return $this->msg(99999,'网络异常,请稍后重试5'); + } + $num = 0; + $subsection_val = 0; + $temporary_subsection_val = null; + foreach ($data['data']['bmilevellist'] as $key => $value) { + if(!array_key_exists('maxvalue',$value) || !array_key_exists('minvalue',$value)){ + return $this->msg(99999,'网络异常,请稍后重试6'); + } + // 判断是否可以进行比较,规则是否正确 + if(is_numeric($value['maxvalue']) && is_numeric($value['minvalue'])){ + if($data['data']['bmi'] >= $value['minvalue'] && $data['data']['bmi'] < $value['maxvalue']){ + // 在落点内 + $subsection_val = bcsub($value['maxvalue'],$value['minvalue'],1);//获取最大最小值差 + $temporary_subsection_val = bcsub($data['data']['bmi'],$value['minvalue'],1);//获取当前值与最小值差 + $temporary_subsection_val = bcdiv($temporary_subsection_val,$subsection_val,1);//获取当前值与最小值差与最大最小值差之比 + $subsection_val = bcdiv(100,count($data['data']['bmilevellist']),1);//每段应该的百分比 + $temporary_subsection_val = bcmul($subsection_val,$temporary_subsection_val,1);//获取当前值与最小值差与最大最小值差之比与总段数之比 + $temporary_subsection_val = bcadd($temporary_subsection_val,bcmul($subsection_val,$num,1),1); + }else{ + $num = $num + 1; + } + } + } + + if($temporary_subsection_val === null){ + if($data['data']['bmi'] >= $data['data']['bmilevellist'][count($data['data']['bmilevellist'])-1]['maxvalue']){ + $temporary_subsection_val = 100; + }else{ + return $this->msg(99999,'网络异常,请稍后重试7'); + } + } + $data['data']['offset'] = $temporary_subsection_val; + $data = $data['data']; + // 处理key名称一致start + foreach ($data['bmilevellist'] as $key => $value) { + $data['bmilevellist'][$key]['max_val'] = $value['maxvalue']; + $data['bmilevellist'][$key]['min_val'] = $value['minvalue']; + unset($data['bmilevellist'][$key]['minvalue']); + unset($data['bmilevellist'][$key]['maxvalue']); + } + // 处理key名称一致end + return $this->msg($data); + } ################################################################其他接口################################################################ diff --git a/application/app/controller/Cardparts.php b/application/app/controller/Cardparts.php index 048c153..f93fedc 100644 --- a/application/app/controller/Cardparts.php +++ b/application/app/controller/Cardparts.php @@ -2,13 +2,6 @@ namespace app\app\controller; -use think\Controller; -use think\Db; -use app\bj\controller\Common; -use think\Log; -use \think\Validate; -use app\app\controller\Calculatebody; -use app\app\controller\Skip; class Cardparts extends Base{ @@ -181,31 +174,27 @@ class Cardparts extends Base{ // 除 bcdiv(,,20) // 计算部分内容的横线标准以及说明文字 public function conversion_interval($data){ - // dump($data); - // die; // $data['gender'] = $data['gender']==2?'woman':'man'; $gender = $data['gender']==2?'woman':'man'; $age = $data['age']['value']; $weight = 0; $temporary_arr = [ - 'score_name' =>$data['score']['name'], - 'score_value' =>$data['score']['value'], - 'score_unit' =>$data['score']['unit'], - 'body_type_name' =>$data['body_type']['name'], - 'body_type_value' =>$data['body_type']['value'], - 'body_type_unit' =>$data['body_type']['unit'], + 'score_name' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['name']:'', + 'score_value' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['value']:'', + 'score_unit' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['unit']:'', + 'body_type_name' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['name']:'', + 'body_type_value' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['value']:'', + 'body_type_unit' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['unit']:'', // 'record_time' =>str_replace('-', '/', $data['record_time']), 'record_time' =>$data['record_time'], 'top_list'=>[], 'bottom_list'=>[], ]; + // die; $date_temporary = new \DateTime($temporary_arr['record_time']); // 使用 format 方法来指定新的日期和时间格式 $temporary_arr['record_time'] = $date_temporary->format('Y年m月d日 H:i:s'); - // dump($data); - // dump($temporary_arr); - // die; // 处理格式(顶部) foreach ($this->parameter_aggregate_top as $key => $value) { $data[$key]['key_name'] = $key; @@ -222,19 +211,20 @@ class Cardparts extends Base{ $data[$key]['desc'] = $value; array_push($temporary_arr['bottom_list'],$data[$key]); } - - // dump($temporary_arr); - // die; // 处理顶部list foreach ($temporary_arr['top_list'] as $key => $value) { if(count($temporary_arr['top_list'][$key]['list']) > 0){ $temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['top_list'][$key]['list'],$temporary_arr['top_list'][$key]['value'],$temporary_arr['top_list'][$key]['standard']); } } - + + // 如果是没有阻抗的测试,那么就不要底部的其他数据了 + if($data['record_type']['value'] != 'by_device_adc'){ + $temporary_arr['bottom_list'] = []; + return $temporary_arr; + } // 处理底部list foreach ($temporary_arr['bottom_list'] as $key => $value) { - // dump($value['key_name']); // 脂肪率& if($value['key_name'] == 'fat_r'){ if($age < 30){ @@ -264,18 +254,15 @@ class Cardparts extends Base{ } // 肌肉率 else if($value['key_name'] == 'muscle'){ - // dump('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); $temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender]; // 处理异常 if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){ $temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]); } $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); - // dump($temporary_arr['bottom_list'][$key]); } // 肌肉量 else if($value['key_name'] == 'muscleval'){ - // dump('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); $temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender]; $temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']); // 处理异常 @@ -283,7 +270,6 @@ class Cardparts extends Base{ $temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]); } $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); - // dump($temporary_arr['bottom_list'][$key]); } // 水分 else if($value['key_name'] == 'water'){ @@ -323,7 +309,6 @@ class Cardparts extends Base{ $temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60']; } } - // dump($temporary_arr['bottom_list'][$key]); // 处理异常 if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){ $temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]); @@ -367,11 +352,6 @@ class Cardparts extends Base{ $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); } } - // dump($data['gender']); - // dump($data['age']['value']); - // // dump($temporary_arr['top_list']); - // dump($temporary_arr['bottom_list']); - // die; return $temporary_arr; } @@ -459,10 +439,6 @@ class Cardparts extends Base{ $temporary_arr = $data; } return $temporary_arr; - - // dump($data); - // dump($w); - // dump($k); } diff --git a/application/app/controller/Cardpublic.php b/application/app/controller/Cardpublic.php index f2b0753..c011b96 100644 --- a/application/app/controller/Cardpublic.php +++ b/application/app/controller/Cardpublic.php @@ -2,18 +2,20 @@ namespace app\app\controller; -use think\Controller; use think\Db; -use app\bj\controller\Common; -use think\Log; -use \think\Validate; -use app\app\controller\Calculatebody; -use app\app\controller\Cardparts; -use app\app\controller\Skip; use Exception; class Cardpublic extends Base{ + protected $cardpublic_use_db_name = [ + '1'=>'app_user_data', + '2'=>'app_card_data_sub_item', + '3'=>'app_card_data_sub_item_data', + '4'=>'admin_estimate', + '5'=>'app_card_data' + ]; + + protected $curve_color = ['#f7b03e','#fb7b92','#ff9f40','#3fcba7',]; protected $level_data = [ ['min_val'=>'0','max_val'=>'59','text'=>'不及格','color'=>'#FB5755'], ['min_val'=>'60','max_val'=>'79','text'=>'及格','color'=>'#FCAE00'], @@ -21,78 +23,432 @@ class Cardpublic extends Base{ ['min_val'=>'90','max_val'=>'150','text'=>'优秀','color'=>'#6691EF'], ]; - // 示意接口 - public function card_curve_chart($data = ['aud_id'=>'83','s_time'=>'2024-04-01','e_time'=>'2024-07-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - } + // 获取卡片数据 - public function get_card_content($data = ['aud_id'=>'83','acd_id'=>'10','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // dump(111); - // die; - return $this->get_card_content_action($data); + public function get_card_content($data = ['aud_id'=>'11','acd_id'=>'13','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + // try { + // // 你的业务逻辑 + // $return_data = + // // 成功 + // $this->record_api_log($data, null, $return_data); + // return $return_data; + // } catch (\Exception $e) { + // // 捕获异常 + // $logContent["flie"] = $e->getFile(); + // $logContent["line"] = $e->getLine(); + // $logContent['all_content'] = "异常信息:\n"; + // $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + // $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + // $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + // $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + // $this->record_api_log($data, $logContent, null); + // return $this->msg(99999); + // } + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->get_card_content_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } + // {"acd_id":"11","name":"200米","record_time":"2024-09-27","data":"02:00","aud_id":"1","token":"57bd45e3a963b372ea2d873e4bd8d1f8","aan_id":"1"} // 存储信息 - public function data_save($data = ['aud_id'=>'83','acd_id'=>'10','name'=>'50米','data'=>'10.3','record_time'=>'2024-09-06','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('data', $data) || !array_key_exists('record_time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - - return $this->data_save_action($data); + public function data_save($data = ['aud_id'=>'11','acd_id'=>'16','name'=>'排球','data'=>'33','record_time'=>'2024-10-18']){ + // {"acd_id":"10","name":"1000米","record_time":"2024-10-18","data":"05:00","aud_id":"24","token":"6441bf7dabea7b3360a30240d3b19fc5","aan_id":"4"} + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('data', $data) || !array_key_exists('record_time', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['name'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['record_time'],'datetime')){ + return $this->msg(10005); + } + $return_data = $this->data_save_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取标签项目信息 - public function get_label_list($data = ['aud_id'=>'83','acd_id'=>'10','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - return $this->get_label_list_action($data); + public function get_label_list($data = ['aud_id'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->get_label_list_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } - - + // 卡片运动曲线 + public function card_motion_curve($data = ['aud_id'=>'1','acd_id'=>'10','s_time'=>'2024-04-01','e_time'=>'2024-11-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->card_motion_curve_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + + // 数据对比-获取数据 + public function data_contrast_obtain_data($data = ['aud_id'=>'1','acd_id'=>'10','name'=>'1000米','s_time'=>'2024-04-01','e_time'=>'2024-10-03']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['name'],'str')){ + return $this->msg(10005); + } + $return_data = $this->data_contrast_obtain_data_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + // 数据对比-对比数据(暂时荒废) + public function data_contrast_contrast_data($data = ['before_id'=>'1','after_id'=>'3']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data)){ + return $this->msg(10001); + } + $return_data = $this->data_contrast_contrast_data_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + // 历史记录 + public function obtain_history_record($data = ['aud_id'=>'1','acd_id'=>'10','name'=>'1000米','page'=>'1']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['name'],'str')){ + return $this->msg(10005); + } + $return_data = $this->obtain_history_record_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + // 历史记录 + public function history_record_del($data = ['id'=>'10']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->history_record_del_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + // 获取手动记录内容 + public function obtain_manual_record_content($data = ['aud_id'=>11]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + if(!$user_data){ + return $this->msg(10004); + } + $card_data_c = Db::table($this->cardpublic_use_db_name['2']) + ->where(['is_del'=>0]) + ->field('id,name,type,unit,unit2,suit_gender,acd_id') + ->select(); + $card_data_c2 = []; + foreach ($card_data_c as $key => $value) { + $temporary_arr = []; + $temporary_arr['id'] = $value['acd_id']; + $temporary_arr['height'] = false; + $temporary_arr['weight'] = false; + $temporary_arr['number'] = false; + $temporary_arr['time'] = false; + $temporary_arr['list'] = []; + $card_data_c2[$value['acd_id']] = $temporary_arr; + } + foreach ($card_data_c as $key => $value) { + if(in_array($user_data['gender'], explode(",", $value['suit_gender']))){ + $temporary_arr = []; + $temporary_arr['id'] = $value['id']; + $temporary_arr['name'] = $value['name']; + $temporary_arr['number'] = $value['unit2'] == '时长'?false:true; + $temporary_arr['type'] = $value['type']; + $temporary_arr['time'] = $value['unit2'] == '时长'?true:false; + $temporary_arr['describe'] = $value['unit2']; + $temporary_arr['unit'] = $value['unit'] == "分/秒"?'': $value['unit']; + array_push($card_data_c2[$value['acd_id']]['list'],$temporary_arr); + }else{ + continue; + } + + } + $card_data = [ + ['id'=>'2','height'=>true,'weight'=>true,'number'=>false,'time'=>false,'list'=>[]], + ['id'=>'6','height'=>false,'weight'=>false,'number'=>true,'time'=>true,'list'=>[]], + ]; + foreach ($card_data_c2 as $key => $value) { + array_push($card_data,$value); + } + // 成功 + $this->record_api_log($data, null, $card_data); + return $this->msg($card_data); + // return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } ################################################################action################################################################ ################################################################action################################################################ ##################################################get_card_content################################################## public function get_card_content_action($data){ + // 查找用户是存在 - $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find(); if(!$user_data){ return $this->msg(10004); } + // 卡片是否存在,以及是否含有子项 - $card_data_sub_item = Db::table('app_card_data_sub_item')->where("acd_id = ".$data['acd_id']." and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit')->select(); + $card_data_sub_item = Db::table($this->cardpublic_use_db_name['2'])->where("acd_id = ".$data['acd_id']." and is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit')->select(); + if(!$card_data_sub_item){ return $this->msg(10004); } @@ -124,14 +480,15 @@ class Cardpublic extends Base{ 'color' => '', 'offset' => '', 'unit_data' => '', + 'record_time' => '', ]; // 添加标签 array_push($return_data['label_list'],$value['name']); // 添加线性轴描述 $return_data['line_list'] = $this->level_data; // 查询最后一次成绩 - $data_this_time = Db::table('app_card_data_sub_item_data')->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id']])->order('id desc')->field('id,detailed_msg,achievement')->find(); - // dump($data_this_time); + $data_this_time = Db::table($this->cardpublic_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id'],'is_del'=>0])->order('record_time desc')->field('id,detailed_msg,achievement,record_time')->find(); + if($data_this_time){ $data_this_time['detailed_msg'] = json_decode($data_this_time['detailed_msg'],true); // 设置基础数据 @@ -142,8 +499,9 @@ class Cardpublic extends Base{ $temporary_arr_c['color'] = $data_this_time['detailed_msg']['color']; $temporary_arr_c['offset'] = $data_this_time['detailed_msg']['offset']; $temporary_arr_c['unit_data'] = $data_this_time['detailed_msg']['unit_data']; + $temporary_arr_c['record_time'] = $data_this_time['record_time']; // 获取到该项所有数据 - $all_time_title = Db::table('app_card_data_sub_item_data')->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id']])->order('id desc')->field('id,achievement,LEFT(record_time,10) AS r_t')->select(); + $all_time_title = Db::table($this->cardpublic_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id'],'is_del'=>0])->order('id desc')->field('id,achievement,LEFT(record_time,10) AS r_t')->select(); // 处理今日,以及总计数据 if($data_this_time['detailed_msg']['unit_data'] == '分/秒'){ // 如果是分秒形式的数据 @@ -153,7 +511,6 @@ class Cardpublic extends Base{ // 处理本次数据最终格式 list($minutes, $seconds) = explode(':', $data_this_time['achievement']); $temporary_arr_c['this_time_value'] = $minutes . '分' . sprintf('%02d', $seconds) . '秒'; - // 计算今日总计&所有平均 $temporary_arr_c['all_times'] = count($all_time_title); foreach ($all_time_title as $k1 => $v1) { @@ -186,6 +543,11 @@ class Cardpublic extends Base{ $temporary_arr_c['today_times'] = $temporary_arr_c['today_times'].'次'; $temporary_arr_c['all_times'] = $temporary_arr_c['all_times'].'次'; + }else{ + $project_describe = Db::table($this->cardpublic_use_db_name['2'])->where(['id'=>$value['id'],'is_del'=>0])->field('id,project_describe')->find(); + if($project_describe){ + $temporary_arr_c['describe'] = $project_describe['project_describe']; + } } array_push($return_data['label_data'],$temporary_arr_c); } @@ -195,14 +557,14 @@ class Cardpublic extends Base{ public function data_save_action($data){ // 查找用户是存在 - $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); if(!$user_data){ return $this->msg(10004); } // 查找项目是否存在,以及获取项目信息 - $card_data_sub_item_data = Db::table('app_card_data_sub_item')->where("name = '".$data['name']."' and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit,acd_id')->find(); + $card_data_sub_item_data = Db::table($this->cardpublic_use_db_name['2'])->where("name = '".$data['name']."' and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit,acd_id')->find(); if(!$card_data_sub_item_data){ - return $this->msg(10004); + return $this->msg(10004,'1'); } // 如果项目数据类型为分秒格式 if($card_data_sub_item_data['type'] == 1){ @@ -217,12 +579,11 @@ class Cardpublic extends Base{ } }else if($card_data_sub_item_data['type'] == 2){ // 判断一个字符串是否为两位以内小数 - // dump($this->isTwoDecimalOrLess($data['data'])); if(!$this->isTwoDecimalOrLess($data['data'])){ return $this->msg(10005); } } - $score_all_data = $this->calculation_score($user_data['gender'],$data,$card_data_sub_item_data['type']); + $score_all_data = $this->calculation_score($user_data['gender'],$data,$card_data_sub_item_data['type'],$card_data_sub_item_data['unit']); $save_data = [ 'acd_id' => $card_data_sub_item_data['acd_id'], 'acdsi_id' => $card_data_sub_item_data['id'], @@ -235,7 +596,7 @@ class Cardpublic extends Base{ 'detailed_msg' => json_encode($score_all_data), ]; - $result = Db::table('app_card_data_sub_item_data')->insert($save_data); + $result = Db::table($this->cardpublic_use_db_name['3'])->insert($save_data); // $result = true; if($result){ if($save_data['unit'] == '分/秒'){ @@ -253,36 +614,181 @@ class Cardpublic extends Base{ ##################################################get_label_list################################################## public function get_label_list_action($data){ // 查找用户是存在 - $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find(); if(!$user_data){ return $this->msg(10004); } - $label_data = Db::table('app_card_data_sub_item')->where("acd_id = ".$data['acd_id']." and suit_gender LIKE '%".$user_data['gender']."%'")->field('name,unit,type')->select(); + $label_data = Db::table($this->cardpublic_use_db_name['2'])->where("is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,acd_id,name,unit,type')->select(); if(count($label_data)<=0){ return $this->msg(10004); } + $return_data = []; + $temporary_arr = []; foreach ($label_data as $key => $value) { - if($value['type'] == 1){ - $label_data[$key]['default_value'] = '0'; - }else if($value['type'] == 2){ - $label_data[$key]['default_value'] = '0.0'; - }else if($value['type'] == 4){ - $label_data[$key]['default_value'] = '0:00'; + if(!array_key_exists($value['acd_id'], $temporary_arr)){ + $temporary_arr[$value['acd_id']] = [$value['name']]; + }else{ + array_push($temporary_arr[$value['acd_id']],$value['name']); } - unset($label_data[$key]['ROW_NUMBER']); } - return $this->msg($label_data); + foreach ($temporary_arr as $key => $value) { + array_push($return_data,[ + 'acd_id'=>$key, + 'list'=>$value, + ]); + } + return $this->msg($return_data); } - + ##################################################card_motion_curve################################################## + public function card_motion_curve_action($data){ + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find(); + if(!$user_data){ + return $this->msg(10004); + } + $card_sub_item_data = Db::table($this->cardpublic_use_db_name['3'])->where(['acd_id'=>$data['acd_id'],'aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc')->field('id,acdsi_id,score,LEFT(record_time,10) as r_t,record_time')->select(); + $card_sub_item_type = Db::table($this->cardpublic_use_db_name['2'])->where("acd_id = ".$data['acd_id']." and is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,name,unit')->select(); + $temporary_arr = []; + $return_data = []; + // 处理一个临时数据 + foreach ($card_sub_item_type as $key => $value) { + $temporary_arr[$value['id']] = ['name'=>$value['name'],'unit'=>$value['unit'],'time'=>[],'data'=>[]]; + } + // 往临时数组内填入数据 + foreach ($card_sub_item_data as $key => $value) { + array_push($temporary_arr[$value['acdsi_id']]['time'],$value['r_t']); + array_push($temporary_arr[$value['acdsi_id']]['data'],$this->convertStringToNumber($value['score'])); + } + $num = 0; + foreach ($temporary_arr as $key => $value) { + if(($num+1) > count($this->curve_color)){ + $num = 0; + } + array_push($return_data,[ + 'title'=>$value['name'], + 'key'=>$value['name'], + 'line'=>[ + 'categories'=>$value['time'], + 'series'=>[ + [ + 'color'=>$this->curve_color[$num], + 'name'=>$value['name'], + 'data'=>$value['data'], + ] + ], + ], + ]); + $num = $num+1; + } + return $this->msg($return_data); + } + ##################################################data_contrast_obtain_data################################################## + public function data_contrast_obtain_data_action($data){ + // $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $card_data = Db::table($this->cardpublic_use_db_name['2'])->where(['acd_id'=>$data['acd_id'],'name'=>$data['name'],'is_del'=>0])->find(); + + $result_data = Db::table($this->cardpublic_use_db_name['3']) + ->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$card_data['id'],'is_del'=>0]) + ->whereTime('record_time', 'between', [$data['s_time'], $data['e_time']]) + ->field('id,achievement,score,unit,record_time') + ->order('record_time desc') + ->select(); + $return_data = []; + foreach ($result_data as $key => $value) { + if($value['unit'] == '分/秒'){ + $temporary_arr_e1 = explode(':', $value['achievement']); + $temporary_arr_e2 = explode('/', $value['unit']); + } + $temporary_arr = [ + "id"=> $value['id'], + // "v1"=> $value['achievement'].$value['unit'], + "v1"=> $value['unit'] == '分/秒'?$temporary_arr_e1[0].$temporary_arr_e2[0].$temporary_arr_e1[1].$temporary_arr_e2[1]:$value['achievement'].$value['unit'], + "v2"=> $this->convertStringToNumber($value['score']).'分', + "v1_name"=> "成绩", + "v2_name"=> "得分", + "r_t"=> substr($value['record_time'], 0, 10) + ]; + array_push($return_data,$temporary_arr); + } + return $this->msg($return_data); + } + ##################################################data_contrast_contrast_data################################################## + public function data_contrast_contrast_data_action($data){ + + $tj = "id IN (".$data['before_id'].",".$data['after_id'].")"; + + $card_data = Db::table($this->cardpublic_use_db_name['3'])->where($tj)->select(); + if(count($card_data)<2){ + return $this->msg(10004); + } + if($card_data[0]['acdsi_id'] != $card_data[1]['acdsi_id']){ + return $this->msg(10003); + } + + } + ##################################################obtain_history_record################################################## + public function obtain_history_record_action($data){ + $card_data = Db::table($this->cardpublic_use_db_name['2'])->where(['acd_id'=>$data['acd_id'],'name'=>$data['name'],'is_del'=>0])->find(); + $result_count = Db::table($this->cardpublic_use_db_name['3']) + ->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$card_data['id'],'is_del'=>0]) + ->count(); + $result_data = Db::table($this->cardpublic_use_db_name['3']) + ->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$card_data['id'],'is_del'=>0]) + ->field('id,achievement,score,unit,record_time') + ->order('record_time desc') + ->page($data['page'].",10") + ->select(); + + $return_data = [ + 'totalrows'=>$result_count, + 'rows'=>[], + 'pagenow'=>$data['page'], + 'pagesize'=>10, + 'totalpage'=>ceil($result_count/10), + ]; + foreach ($result_data as $key => $value) { + $temporary_arr = []; + if($value['unit'] == '分/秒'){ + $temporary_arr_e1 = explode(':', $value['achievement']); + $temporary_arr_e2 = explode('/', $value['unit']); + } + $temporary_arr = [ + "id"=> $value['id'], + // "v1"=> $value['achievement'].$value['unit'], + "v1"=> $value['unit'] == '分/秒'?$temporary_arr_e1[0].$temporary_arr_e2[0].$temporary_arr_e1[1].$temporary_arr_e2[1]:$value['achievement'].$value['unit'], + "v2"=> $this->convertStringToNumber($value['score']).'分', + "v1_name"=> "成绩", + "v2_name"=> "得分", + "record_time"=> $value['record_time'] + ]; + array_push($return_data['rows'],$temporary_arr); + } + + return $this->msg($return_data); + } + ##################################################history_record_del################################################## + public function history_record_del_action($data){ + $result_count = Db::table($this->cardpublic_use_db_name['3']) + ->where(['id'=>$data['id']]) + ->update(['is_del'=>1]); + if($result_count){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + + + + + ################################################################tool################################################################ ################################################################tool################################################################ // 计算得分成绩以及线性进度 - public function calculation_score($gender,$data,$type){ - // $card_name['card_name'] = ; + public function calculation_score($gender,$data,$type,$unit_msg){ $card_name['project_name'] = $data['name']; $card_name['score'] = 0; $card_name['offset'] = 0; @@ -291,7 +797,7 @@ class Cardpublic extends Base{ // 计算得分 // 获取评分细则 - $estimate = Db::table('admin_estimate')->where(['type'=>3])->find(); + $estimate = Db::table($this->cardpublic_use_db_name['4'])->where(['type'=>3])->find(); $estimate = json_decode($estimate['content'],true); // 根据男女循环出项目细则 @@ -307,7 +813,7 @@ class Cardpublic extends Base{ } } foreach ($card_name['rule']['content'] as $key => $value) { - if($type == '分/秒'){ + if($type == '4'){ $rule_result = $this->convertMinutesSecondsToStringSeconds($value[0]); $data_result = $this->convertMinutesSecondsToStringSeconds($data['data']); }else{ @@ -337,33 +843,42 @@ class Cardpublic extends Base{ // 如果比较符号不是上述任何一个,可以抛出一个异常或错误 throw new Exception("Unsupported comparison operator: " . $value[1]); } + if($result == true){ $card_name['score'] = $value[2]; - if($value[2] < 100){ - $card_name['offset'] = $value[2]; - }else{ - $card_name['offset'] = 100; - } - // $card_name['offset'] = bcdiv($value[2],$card_name['diagram'][count($card_name['diagram'])-1]['max_val'],0); break; } } + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) foreach ($describe_list as $key => $value) { if($card_name['score'] >= $value['min_val'] && $card_name['score'] <= $value['max_val']){ $card_name['standard'] = $value['text']; $card_name['color'] = $value['color']; + if($card_name['score'] < 100){ + // 计算当前区间内的比值() + $card_name['offset'] = bcmul(bcdiv(bcsub($card_name['score'],$value['min_val'],20),bcsub($value['max_val'],$value['min_val'],20),4),25,2); + // 计算全线性下比值 + $card_name['offset'] = bcadd($card_name['offset'],bcmul(($key),25,0),0); + }else{ + $card_name['offset'] = '100'; + } break; } } $card_name['max_score'] = $card_name['rule']['content'][0][2]; $card_name['describe'] = $card_name['rule']['describe']; - $card_name['unit_data'] = $card_name['rule']['unit_data']; + $card_name['unit_data'] = $unit_msg; // $card_name['default_data_format'] = $card_name['rule']['value']; // $card_name['default_data_type'] = $card_name['rule']['type']; // $card_name['list'] = $describe_list; + unset($card_name['rule']); + return $card_name; } diff --git a/application/app/controller/Device.php b/application/app/controller/Device.php index cfc35be..5f0b606 100644 --- a/application/app/controller/Device.php +++ b/application/app/controller/Device.php @@ -9,6 +9,11 @@ use think\Log; class Device extends Base{ protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6']; + protected $device_use_db_name = [ + '1'=>'app_device_data', + '2'=>'app_account_number', + '3'=>'app_device_code_data', + ]; ################################################################接口################################################################ @@ -17,79 +22,178 @@ class Device extends Base{ // 获取系统设备列表 public function device_data_list($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->device_data_list_action($data); + + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + $return_data = $this->device_data_list_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 绑定系统设备 public function device_binding($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','device_id'=>'3','device_mac'=>'54654654']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data) || !array_key_exists('device_id', $data) || !array_key_exists('device_mac', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->device_binding_action($data); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('device_id', $data) || !array_key_exists('device_mac', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['device_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['device_mac'],'str')){ + return $this->msg(10005); + } + $return_data = $this->device_binding_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } } // 获取用户设备列表 public function device_user_data_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->device_user_data_list_action($data); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->device_user_data_list_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 解绑系统设备 public function device_unbinding($data = ['token'=>'e0966788d02cc93290d9d674921d9715','id'=>'8']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->device_unbinding_action($data); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->device_unbinding_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取设备详情 public function device_mac_get_content($data = ['mac'=>'76:FE:B3:2F:E7:D8','acd_id'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('mac', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - return $this->device_mac_get_content_action($data); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('mac', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['mac'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->device_mac_get_content_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } ################################################################业务接口################################################################ @@ -97,7 +201,7 @@ class Device extends Base{ ################################################device_data_list public function device_data_list_action($data){ - $result = Db::table('app_device_data')->where(['is_del'=>0])->field('id,name,pic,content,page_measure,bluetooth_type,device_model')->select(); + $result = Db::table($this->device_use_db_name['1'])->where(['is_del'=>0])->field('id,name,pic,content,page_measure,bluetooth_type,device_model')->select(); foreach ($result as $key => $value) { unset($result[$key]['ROW_NUMBER']); } @@ -110,11 +214,11 @@ class Device extends Base{ ################################################device_binding public function device_binding_action($data){ - $result_user = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find(); + $result_user = Db::table($this->device_use_db_name['2'])->where(['token'=>$data['token']])->field('id,token')->find(); if(!$result_user){ return $this->msg(10003); } - $device_code_data = Db::table('app_device_code_data')->where(['machine_code'=>$data['device_mac']])->find(); + $device_code_data = Db::table($this->device_use_db_name['3'])->where(['machine_code'=>$data['device_mac']])->find(); $device_code_data_user = explode(',',$device_code_data['bind_account_id']); if($device_code_data){ // 多用户可以绑定 @@ -122,7 +226,7 @@ class Device extends Base{ return $this->msg(10003,'设备已绑定'); }else{ array_push($device_code_data_user,$result_user['id']); - $device_binding = Db::table('app_device_code_data')->where(['machine_code'=>$data['device_mac']])->update([ + $device_binding = Db::table($this->device_use_db_name['3'])->where(['machine_code'=>$data['device_mac']])->update([ 'bind_account_id'=>implode(',',$device_code_data_user), ]); if($device_binding){ @@ -131,21 +235,8 @@ class Device extends Base{ return $this->msg(10002,'更新失败'); } } - // 仅单用户可以绑定 - // if($device_code_data['bind_account_id']){ - // return $this->msg(10003,'设备已被绑定'); - // }else{ - // $device_binding = Db::table('app_device_code_data')->where(['machine_code'=>$data['device_mac']])->update([ - // 'bind_account_id'=>$result_user['id'], - // ]); - // if($device_binding){ - // return $this->msg([]); - // }else{ - // return $this->msg(10002,'更新失败'); - // } - // } } - $device_binding = Db::table('app_device_code_data')->insert([ + $device_binding = Db::table($this->device_use_db_name['3'])->insert([ 'add_id'=>$data['device_id'], 'machine_code'=>$data['device_mac'], 'create_time'=>date('Y-m-d H:i:s'), @@ -160,14 +251,14 @@ class Device extends Base{ ################################################device_user_data_list public function device_user_data_list_action($data){ - $result_user = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find(); + $result_user = Db::table($this->device_use_db_name['2'])->where(['token'=>$data['token']])->field('id,token')->find(); if(!$result_user){ return $this->msg(10003); } $likePattern = '%' . $result_user['id'] . '%'; - $device_code_data = Db::table('app_device_code_data') + $device_code_data = Db::table($this->device_use_db_name['3']) ->alias('adcd') - ->join('app_device_data add','adcd.add_id = add.id','LEFT') + ->join(''.$this->device_use_db_name['1'].' add','adcd.add_id = add.id','LEFT') // ->where(['adcd.bind_account_id'=>$result_user['id']]) // ->where('adcd.bind_account_id LIKE "%'.$result_user['id'].'%"') ->where("adcd.bind_account_id LIKE ?", [$likePattern]) @@ -201,31 +292,25 @@ class Device extends Base{ ################################################device_unbinding public function device_unbinding_action($data){ - $result_user = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find(); + $result_user = Db::table($this->device_use_db_name['2'])->where(['token'=>$data['token']])->field('id,token')->find(); if(!$result_user){ return $this->msg(10003); } - $device_binding_user = Db::table('app_device_code_data') + $device_binding_user = Db::table($this->device_use_db_name['3']) ->alias('adcd') - ->join('app_device_data add2','add2.id = adcd.add_id','LEFT') + ->join(''.$this->device_use_db_name['1'].' add2','add2.id = adcd.add_id','LEFT') ->where(['adcd.id'=>$data['id']]) ->field('adcd.id,adcd.bind_account_id,add2.acd_id') ->find(); - // dump(time()); - // die; $device_binding_user = explode(',',$device_binding_user['bind_account_id']); - // dump($device_binding_user); $key = array_search($result_user['id'], $device_binding_user); if($key !== false){ unset($device_binding_user[$key]); }else{ return $this->msg([]); } - // dump($device_binding_user); - // dump(implode(',',$device_binding_user)); - // die; - $device_binding = Db::table('app_device_code_data')->where(['id'=>$data['id']])->update([ + $device_binding = Db::table($this->device_use_db_name['3'])->where(['id'=>$data['id']])->update([ 'bind_account_id'=>implode(',',$device_binding_user), ]); if($device_binding){ @@ -238,13 +323,11 @@ class Device extends Base{ ################################################device_mac_get_content public function device_mac_get_content_action($data){ - $user_id = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find(); - // dump($user_id); - // die; + $user_id = Db::table($this->device_use_db_name['2'])->where(['token'=>$data['token']])->field('id,token')->find(); $likePattern = '%' . $user_id['id'] . '%'; - $result_device = Db::table('app_device_code_data') + $result_device = Db::table($this->device_use_db_name['3']) ->alias('adcd') - ->join('app_device_data add','adcd.add_id = add.id','LEFT') + ->join(''.$this->device_use_db_name['1'].' add','adcd.add_id = add.id','LEFT') ->where([ 'adcd.machine_code'=>$data['mac'], 'add.acd_id'=>$data['acd_id'], diff --git a/application/app/controller/Index.php b/application/app/controller/Index.php index 4795133..d6c3a47 100644 --- a/application/app/controller/Index.php +++ b/application/app/controller/Index.php @@ -2,22 +2,31 @@ namespace app\app\controller; -use think\Controller; use think\Db; -use app\bj\controller\Common; -use think\Log; use \think\Validate; class Index extends Base{ - protected $moren_gufen_diqu = '上海,上海'; - protected $db_name = ['2'=>'app_card_body_data','6'=>'app_card_skip_data','8'=>'app_card_vitalcapacity_data']; + protected $moren_gufen_diqu = '北京,北京'; + protected $db_name = ['2'=>'app_card_body_data','6'=>'app_card_skip_data','8'=>'app_card_vitalcapacity_data','10'=>'app_card_data_sub_item_data']; + protected $index_use_db_name = [ + '1'=>'app_version_log', + '2'=>'app_user_data', + '3'=>'app_card_body_data', + '4'=>'app_device_code_data', + '5'=>'app_device_data', + '6'=>'app_card_data', + '7'=>'app_account_number', + '8'=>'app_card_data_sub_item', + '9'=>'app_card_data_sub_item_data', + '10'=>'admin_estimate' + ]; // protected $card_key = ['2'=>'body','6'=>'skip','8'=>'vitalcapacity']; protected $default_card = ['2','6','8']; protected $card_data = [ '2'=>['身体数据','body',['height'=>['身高','cm','-'],'weight'=>['体重','公斤','-'],'bmi'=>['BMI','无','-']]], // '6'=>['跳绳数据','skip',['jump_time'=>['用时','无','--:--:--'],'jump_num'=>['本次次数','次','-'],'average_num'=>['平均成绩','个','-'],'jump_kcal'=>['卡路里','kcal','-']]], '6'=>['跳绳数据','skip',['jump_time'=>['用时','无','--:--:--'],'jump_num'=>['本次次数','次','-'],'jump_kcal'=>['卡路里','kcal','-']]], - '8'=>['肺活量','vitalcapacity',['average'=>['本次数据','ml','-']]], + '8'=>['肺活量','vitalcapacity',['average'=>['平均成绩','ml','-']]], ]; protected $data_name_unit = [ @@ -26,7 +35,8 @@ class Index extends Base{ 'bmi'=>['BMI','','pc_bmistand2'], 'average'=>['肺活量','ml','pc_vitalcapacity_standard'] ]; - + protected $identity_list = ['P0'=>'陌生人','P1'=>'爸爸','P2'=>'妈妈','P3'=>'大宝','P4'=>'二宝','P5'=>'三宝','P6'=>'四宝','P7'=>'爷爷','P8'=>'奶奶']; + // protected $nickname_data2 = ['爸爸','妈妈','大宝','二宝','爷爷','奶奶','外公','外婆']; protected $grade_list = [ ['id'=>'nothing','name'=>'无'], ['id'=>'grade_s_1','name'=>'小学一年级'], @@ -50,423 +60,667 @@ class Index extends Base{ ################################################################个人资料卡################################################################ // 检测版本及判断是否登录失效 - public function login_invalid_version($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - // phpinfo(); - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - $result = Db::table('app_version_log')->order('is_del,id desc')->find(); - if($result){ - $version = $result['version_num_original']; - $url = $result['download_url']; - }else{ - $version = ''; - $url = ''; - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url]); - }else{ - return $this->msg(['version'=>$version,'url'=>$url]); - } + public function login_invalid_version($data = ['token'=>'']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + $result = Db::table($this->index_use_db_name['1'])->order('is_del,id desc')->find(); + if($result){ + $version = $result['version_num_original']; + $url = $result['download_url']; + }else{ + $version = ''; + $url = ''; + } + if($this->token_time_validate($data['token']) === false){ + $this->record_api_log($data, null, ['code'=>-1,'msg'=>'未登录',['version'=>$version,'url'=>$url]]); + return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url]); + }else{ + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',['version'=>$version,'url'=>$url]]); + return $this->msg(['version'=>$version,'url'=>$url]); + } + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } // 创建用户 - public function create_user_data($data = ['aan_id'=>66,'nickname'=>'王小二','birthday'=>'2019-01-01','gender'=>1,'grade'=>'二年级','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $verify_result = $this->verify_parameters($data,'register'); - if(!is_array($verify_result)){ - return $this->msg(10001,$verify_result); - } - $result = Db::table('app_user_data')->insertGetId($verify_result); - if($result){ - return $this->msg(['aud_id'=>$result]); - }else{ - return $this->msg(10002); - } + public function create_user_data($data = ['aan_id'=>1,'height'=>'152.3','weight'=>'35.4','nickname'=>'钮祜禄测试1','birthday'=>'2019-04-20','gender'=>1,'grade'=>'grade_s_3','identity_id'=>'P3','identity_name'=>'大宝','address'=>'河南,郑州','token'=>'57bd45e3a963b372ea2d873e4bd8d1f8']){ + + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('measure_model', $data)){ + return $this->msg(10001); + } + + if($data['measure_model'] != '1' && $data['measure_model'] != '2'){ + return $this->msg(10001); + } + + unset($data['token']); + $verify_result = $this->verify_parameters($data,'register'); + if(!is_array($verify_result)){ + return $this->msg(10001,$verify_result); + } + $result = Db::table($this->index_use_db_name['2'])->insertGetId($verify_result); + if($result){ + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',['aud_id'=>$result]]); + return $this->msg(['aud_id'=>$result]); + }else{ + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + + } catch (\Exception $e) { + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + + } // 修改用户 - public function update_user_data($data = ['id'=>66,'nickname'=>'王小二','birthday'=>'2019-01-01','gender'=>1,'grade'=>'二年级','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $verify_result = $this->verify_parameters2($data,'update'); - if(!is_array($verify_result)){ - return $this->msg(10001,$verify_result); - } - $id_val = $verify_result['id']; - unset($verify_result['id']); - $result = Db::table('app_user_data')->where(['id'=>$id_val])->update($verify_result); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } + public function update_user_data($data = ['id'=>66,'nickname'=>'王小二','birthday'=>'2019-01-01','gender'=>1,'grade'=>'二年级','identity_id'=>'P3','identity_name'=>'大宝','address'=>'河南,郑州','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + $verify_result = $this->verify_parameters2($data,'update'); + if(!is_array($verify_result)){ + return $this->msg(10001,$verify_result); + } + $id_val = $verify_result['id']; + unset($verify_result['id']); + $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$id_val])->update($verify_result); + if($result){ + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg([]); + }else{ + // 失败 + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + } catch (\Exception $e) { + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } // 删除用户 public function del_user_data($data = ['id'=>'26','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $result = Db::table('app_user_data')->where(['id'=>$data['id']])->update(['is_del'=>1]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['id']])->update(['is_del'=>1]); + if($result){ + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg([]); + }else{ + // 失败 + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取账号下用户列表 // $type 1获取列表,2获取详细信息 - public function get_user_card_list($data = ['aan_id'=>66,'type'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data) || !array_key_exists('aan_id', $data) || !array_key_exists('type', $data)){ - return $this->msg(10001); - } + public function get_user_card_list($data = ['aan_id'=>4,'type'=>2,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('aan_id', $data) || !array_key_exists('type', $data)){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aan_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $result = Db::table($this->index_use_db_name['2']) + ->where(['aan_id'=>$data['aan_id'],'is_del'=>0]) + ->field('id,aan_id,nickname,birthday,gender,card_order,target_weight,initial_weight,initial_date,grade,head_pic,weight,height,identity_name,address,identity_id,measure_model') + ->select(); + + $temporary_data = []; + if($data['type'] == 1){ + for ($i=0; $i < count($result); $i++) { + array_push($temporary_data,[ + 'id'=>$result[$i]['id'], + 'nickname'=>$result[$i]['nickname'], + 'identity_name'=>$result[$i]['identity_name'], + 'identity_id'=>$result[$i]['identity_id'], + ]); + } + }else{ + for ($i=0; $i < count($result); $i++) { + $result[$i]['age'] = $this->calculate_age($result[$i]['birthday']); + } + $temporary_data = $result; + } + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$temporary_data]); + return $this->msg($temporary_data); + + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $result = Db::table('app_user_data')->where(['aan_id'=>$data['aan_id'],'is_del'=>0])->select(); - // $result = Db::table('app_user_data')->where(['aan_id'=>$aan_id])->field('id,nickname')->select(); - $temporary_data = []; - if($data['type'] == 1){ - for ($i=0; $i < count($result); $i++) { - array_push($temporary_data,['id'=>$result[$i]['id'],'nickname'=>$result[$i]['nickname']]); - } - }else{ - for ($i=0; $i < count($result); $i++) { - $result[$i]['age'] = $this->calculate_age($result[$i]['birthday']); - // array_push($temporary_data,['id'=>$result[$i]['id'],'nickname'=>$result[$i]['nickname'],'age'=>$this->calculate_age($result[$i]['birthday'])]); - } - $temporary_data = $result; - } - return $this->msg($temporary_data); } // 获取指定用户详细信息 - public function get_user_data_information($data = ['aud_id'=>92,'token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - // dump(input('post.')); - // dump(input('get.')); - // // dump($data); - // die; - if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,head_pic,birthday,gender,card_order,target_weight,initial_weight,initial_date,weight')->find(); - $weight_data_pd = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('id,weight_val,record_time')->find(); - // dump($weight_data_pd); - // die; - if(!$result){ - return $this->msg(10003); - } - unset($result['ROW_NUMBER']); - $result['age'] = $this->calculate_age($result['birthday']); - if($result['card_order'] === ''){ - $result['card_order'] = []; - $result['card_data_list'] = []; - $result['target_current'] = $this->base_target_initial_cumulative_weight([]); + public function get_user_data_information($data = ['aud_id'=>79]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } - }else{ - $result['card_order'] = explode(',',$result['card_order']); - $calculation_results = $this->get_user_card_data_list($result,$result['id']); - $result['card_data_list'] = $calculation_results[0]; - $result['target_current'] = $calculation_results[1]; - } - - if($weight_data_pd){ - $result['weight'] = $weight_data_pd['weight_val']; - } - - - // $result['birthday'] = str_replace('-', '/', $result['birthday']); - // foreach ($result['card_data_list'] as $key => $value) { - // // dump($key); - // if($key == 'record_time' && $value != ''){ - // // dump(111); - // $result['card_data_list'][$key] = str_replace('-', '/', $result['card_data_list'][$key]); - // } - // } - unset($result['target_weight']); - unset($result['initial_weight']); - unset($result['initial_date']); - - // 获取设备信息进入卡片 start - $likePattern = '%' . $result['aan_id'] . '%'; - $result_device = Db::table('app_device_code_data') - ->alias('adcd') - ->join('app_device_data add','adcd.add_id = add.id','LEFT') - // ->where(['adcd.bind_account_id'=>$result['aan_id']]) - ->where("adcd.bind_account_id LIKE ?", [$likePattern]) - ->field('adcd.id,add.acd_id') - ->select(); - - $device_arr = []; - foreach ($result_device as $key => $value) { - if(!in_array($value['acd_id'],$device_arr)){ - array_push($device_arr,$value['acd_id']); + if(!array_key_exists('aud_id', $data)){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); } - } - // dump($device_arr); - // die; - foreach ($result['card_data_list'] as $key => $value) { - if(in_array($value['acd_id'],$device_arr)){ - $result['card_data_list'][$key]['device_determine'] = true; + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + // 获取用户信息 + $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,aan_id,nickname,head_pic,birthday,gender,card_order,target_weight,initial_weight,initial_date,height,weight,address,identity_id,measure_model')->find(); + if(!$result){ + return $this->msg(10004); + } + $result['age'] = $this->calculate_age($result['birthday']); + + // 从这里开始进入体脂还是体测的判断 + if($result['card_order'] != ""){ + $result['card_order'] = explode(',',$result['card_order']); }else{ - $result['card_data_list'][$key]['device_determine'] = false; + $result['card_order'] = []; } - } - $result['address'] = $this->moren_gufen_diqu; - // 插入肺活量的卡片标准 - $result['vitalcapacity_data'] = $this->get_vitalcapacity_data($result['id']); - // 获取设备信息进入卡片 end - return $this->msg($result); + if($result['measure_model'] == 1){// 这里是体测 + $calculation_results = $this->get_user_card_data_list($result,$result['id']); + $result['card_data_list'] = $calculation_results[0]; + $result['card_order'] = $calculation_results[1]; + + }else if($result['measure_model'] == 2){// 这里是体脂 + $result['card_data_list'] = []; + $result['card_order'] = []; + }else{ + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'measure_model数据不是1或者2',[]]); + return $this->msg(10004); + } + // // 获取设备信息进入卡片 start + // $likePattern = '%' . $result['aan_id'] . '%'; + // $result_device = Db::table($this->index_use_db_name['4']) + // ->alias('adcd') + // ->join(''.$this->index_use_db_name['5'].' add','adcd.add_id = add.id','LEFT') + // ->where("adcd.bind_account_id LIKE ?", [$likePattern]) + // ->field('adcd.id,add.acd_id') + // ->select(); + // $device_arr = []; + // foreach ($result_device as $key => $value) { + // if(!in_array($value['acd_id'],$device_arr)){ + // array_push($device_arr,$value['acd_id']); + // } + // } + // foreach ($result['card_data_list'] as $key => $value) { + // if(in_array($value['acd_id'],$device_arr)){ + // $result['card_data_list'][$key]['device_determine'] = true; + // }else{ + // $result['card_data_list'][$key]['device_determine'] = false; + // } + // } + // // 获取设备信息进入卡片 end + if($result['address'] == ''){ + $result['address'] = $this->moren_gufen_diqu; + } + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]); + return $this->msg($result); + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取所有卡片列表信息 - public function get_card_all_list($data = ['aud_id'=>83,'token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $user_card_list = Db::table('app_user_data')->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find(); - if(!$user_card_list){ - return $this->msg(10003); - } - unset($user_card_list['ROW_NUMBER']); - $user_card_list['card_order'] = explode(',',$user_card_list['card_order']); - $all_card_list = Db::table('app_card_data')->where(['is_del'=>0])->field('id,name,pic')->select(); - // dump($user_card_list); - // dump($all_card_list); - $result = ['user'=>[],'all'=>[]]; - foreach ($all_card_list as $key => $value) { - if(in_array($value['id'],$user_card_list['card_order'])){ - $result['user'][array_search($value['id'], $user_card_list['card_order'])] = ['id'=>$value['id'],'name'=>$value['name'],'pic'=>$value['pic']]; - }else{ - array_push($result['all'],['id'=>$value['id'],'name'=>$value['name'],'pic'=>$value['pic']]); + public function get_card_all_list($data = ['aud_id'=>11,'token'=>'57bd45e3a963b372ea2d873e4bd8d1f8']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); } - } - ksort($result['user']); - return $this->msg($result); + if(!array_key_exists('token', $data)){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $user_card_list = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find(); + + if(!$user_card_list){ + // 失败 + $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); + return $this->msg(10003); + } + unset($user_card_list['ROW_NUMBER']); + + $user_card_list['card_order'] = explode(',',$user_card_list['card_order']); + foreach ($user_card_list['card_order'] as $key => $value) { + if(in_array($value,$this->default_card)){ + unset($user_card_list['card_order'][$key]); + } + } + $user_card_list['card_order'] = array_values($user_card_list['card_order']); + $all_card_list = Db::table($this->index_use_db_name['6'])->where(['is_del'=>0])->field('id,name,pic')->select(); + // die; + $result = ['user'=>[],'all'=>[]]; + foreach ($all_card_list as $key => $value) { + if(in_array($value['id'],$user_card_list['card_order'])){ + $result['user'][array_search($value['id'], $user_card_list['card_order'])] = ['id'=>$value['id'],'name'=>$value['name'],'pic'=>$value['pic']]; + }else{ + array_push($result['all'],['id'=>$value['id'],'name'=>$value['name'],'pic'=>$value['pic']]); + } + } + ksort($result['user']); + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]); + return $this->msg($result); + + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 保存用户的卡片排序 - public function save_user_card_order($data=['aud_id'=>11,'card_order'=>'2,8','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('card_order', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if(!$this->is_num_array(explode(',',$data['card_order']))){ - return $this->msg(10001,'数据内参数格式或值错误'); - } - $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['card_order']]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } + public function save_user_card_order($data=['aud_id'=>11,'card_order'=>'2,6,10,12,13,8,14,16,15','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('card_order', $data) || !array_key_exists('token', $data)){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + if(!$this->is_num_array(explode(',',$data['card_order']))){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'数据内参数格式或值错误',[]]); + return $this->msg(10005,'数据内参数格式或值错误'); + } + $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['card_order']]); + if($result){ + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg([]); + }else{ + // 失败 + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取年级key列表 - public function get_grade_list(){ - $data = input('post.'); - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } + public function get_grade_list($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + if(count(input('post.')) > 0){ + $data = input('post.'); + } + // if(!array_key_exists('token', $data)){ + // $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + // return $this->msg(10001); + // } + $address_data = Db::table($this->base_use_db_name['5'])->where(['type' => '2'])->cache(3600)->field('id,content,city,area')->find(); + $return_data['area_list'] = json_decode($address_data['content'],true); + $return_data['identity_list'] = []; + foreach ($this->identity_list as $key => $value) { + array_push($return_data['identity_list'],['id'=>$key,'name'=>$value]); + } + $return_data['grade_list'] = $this->grade_list; + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg($return_data); + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } - return $this->msg($this->grade_list); - // $temporary_arr = Db::table('app_identity_data')->cache(true,60)->select(); - // $result = [['id'=>'nothing','name'=>'无']]; - // // dump(); - // // die; - // foreach ($temporary_arr as $key => $value) { - // array_push($result,['id'=>$value['id'],'name'=>$value['content']]); - // } - // return $this->msg(['grade_list'=>$this->grade_list,'identity_list'=>$result]); + // 修改用户所属区域 + public function update_user_address($data=['aud_id'=>'1','address_data'=>'上海,上海']){ + try { + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('address_data', $data)){ + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + $user_data = Db::table($this->base_use_db_name['2'])->where(['id' => $data['aud_id']])->count(); + if($user_data<=0){ + $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); + return $this->msg(10003); + } + $address_data = explode(',',$data['address_data']); + $address_result = Db::table($this->base_use_db_name['10'])->where(['province' => $address_data[0]])->cache(3600)->field('id,recommend_cards')->find(); + if(!$address_result){ + $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); + return $this->msg(10003); + } + $user_result = Db::table($this->base_use_db_name['2'])->where(['id' => $data['aud_id']])->update(['card_order'=>$address_result['recommend_cards']]); + + if($user_result){ + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg([]); + }else{ + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } } ################################获取账号下信息操作################################ // 获取账号下首页卡片的基础数据 public function get_user_card_data_list($data,$aud_id){ - - $result = []; - $db_arr = []; - foreach ($data['card_order'] as $key => $value) { - $db_arr[$value] = Db::table($this->db_name[$value])->where(['aud_id'=>$aud_id,'is_del'=>'0'])->order('record_time desc')->limit(1)->select(); - // dump($db_arr[$value]); - - if(count($db_arr[$value]) > 0){ - $db_arr[$value] = $db_arr[$value][0]; - }else{ - unset($db_arr[$value]); - } - } - - // 获取卡片路径及卡片数组处理start - $card_all_data = Db::table('app_card_data')->field('id,page_url_record,page_url_report,page_url_bluetooth')->select(); - $card_all_data_result = []; - foreach ($card_all_data as $key => $value) { - $card_all_data_result[$value['id']] = [ - 'page_url_record'=>$value['page_url_record'], - 'page_url_report'=>$value['page_url_report'], - 'page_url_bluetooth'=>$value['page_url_bluetooth'] - ]; - } - // 获取卡片路径及卡片数组处理end - - // dump($db_arr); - // die; - // 添加目标体重于当前体重差数据 - if(array_key_exists('2', $db_arr)){ - $target_current = $this->base_target_initial_cumulative_weight([ - 'weight'=>$db_arr['2']['weight']>0?$db_arr['2']['weight']:0, - 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, - 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, - 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, - ]); - }else{ - $target_current = $this->base_target_initial_cumulative_weight([ - 'weight'=>0, - 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, - 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, - 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, - ]); - } - if(count($db_arr) <= 0){ - // 没有数据,传递一个空的卡片 + // try { + // 你的业务逻辑 + $result = []; + $db_arr = []; foreach ($data['card_order'] as $key => $value) { - $temporary_arr = []; - $temporary_arr['id'] = ''; - $temporary_arr['acd_id'] = $value; - $temporary_arr['record_time'] = ''; - $temporary_arr['card_name'] = $this->card_data[$value][0]; - $temporary_arr['card_key'] = $this->card_data[$value][1]; - $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; - $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; - $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; - $temporary_arr['inside_data'] = []; - foreach ($this->card_data[$value][2] as $k => $v) { + if(in_array($value,$this->default_card)){ + // 过滤掉老版本的(268选项卡) + unset($data['card_order'][$key]); + continue; + }else{ + // 公共卡牌 + $db_arr[$value] = Db::table($this->index_use_db_name['9'])->where(['aud_id'=>$aud_id,'acd_id'=>$value,'is_del'=>'0'])->order('record_time desc')->limit(1)->select(); + if(count($db_arr[$value]) > 0){ + $temporary_data = Db::table($this->index_use_db_name['8'])->where(['id'=>$db_arr[$value][0]['acdsi_id']])->field('id,name')->find(); + $db_arr[$value][0]['acdsi_name'] = $temporary_data['name']; + } + if(count($db_arr[$value]) > 0){ + $db_arr[$value] = $db_arr[$value][0]; + }else{ + unset($db_arr[$value]); + } + } + } + $data['card_order'] = array_values($data['card_order']); + // 获取卡片背景图,及背景色信息及其他信息 + $card_all_data = Db::table($this->index_use_db_name['6'])->where(['is_del'=>0])->field('id,name,page_url_record,page_url_report,page_url_bluetooth,key_word,background_color,background_pic')->select(); + $card_all_data_result = []; + foreach ($card_all_data as $key => $value) { + $card_all_data_result[$value['id']] = $value; + } + // 获取卡片路径及卡片数组处理end + // // 添加目标体重于当前体重差数据 + // if(array_key_exists('2', $db_arr)){ + // $target_current = $this->base_target_initial_cumulative_weight([ + // 'weight'=>$db_arr['2']['weight']>0?$db_arr['2']['weight']:0, + // 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, + // 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, + // 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, + // ]); + // }else{ + // $target_current = $this->base_target_initial_cumulative_weight([ + // 'weight'=>0, + // 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, + // 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, + // 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, + // ]); + // } + if(count($db_arr) <= 0){ + // 没有数据,传递一个空的卡片 + foreach ($data['card_order'] as $key => $value) { + $temporary_arr = []; + $temporary_arr['id'] = ''; + $temporary_arr['acd_id'] = $value; + $temporary_arr['record_time'] = ''; + $temporary_arr['card_name'] = $card_all_data_result[$value]['name']; + $temporary_arr['card_key'] = $card_all_data_result[$value]['key_word']; + $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; + $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; + $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; + $temporary_arr['background_color'] = $card_all_data_result[$value]['background_color']; + $temporary_arr['background_pic'] = $card_all_data_result[$value]['background_pic']; + $temporary_arr['inside_data'] = []; array_push($temporary_arr['inside_data'],[ - 'key'=>$k, - 'name'=>$v[0], - 'value'=>$v[2], - 'unit'=>$v[1]!='无'?$v[1]:'', - 'standard'=>'', + 'key'=>'last_time', + 'name'=>'最近一次', + 'value'=>"--", + 'unit'=>'', + 'standard'=>'*分', 'color'=>'' ]); + array_push($result,$temporary_arr); } - array_push($result,$temporary_arr); - } - }else{ - // dump($db_arr); - // die; - foreach ($data['card_order'] as $key => $value) { - $temporary_arr = []; - $temporary_arr['acd_id'] = $value; - - $temporary_arr['card_name'] = $this->card_data[$value][0]; - $temporary_arr['card_key'] = $this->card_data[$value][1]; - $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; - $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; - $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; - $temporary_arr['inside_data'] = []; - if(array_key_exists($value,$db_arr)){ - $temporary_arr['id'] = $db_arr[$value]['id']; - $temporary_arr['record_time'] = $db_arr[$value]['record_time']; - foreach ($this->card_data[$value][2] as $k => $v) { - if($value == '2'){ - $tem_arr_2 = explode(',', $db_arr[$value][$k]); - }else if($value == '6' && $k == 'jump_time'){ - $time_conversion = $this->handle_hour_branch_second($db_arr[$value][$k]); - $tem_arr_2 = [$time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'],'','']; - }else{ - $tem_arr_2 = [$db_arr[$value][$k],'','']; - } - - // dump($tem_arr_2); + }else{ + foreach ($data['card_order'] as $key => $value) { + $temporary_arr = []; + $temporary_arr['acd_id'] = $value; + $temporary_arr['card_name'] = $card_all_data_result[$value]['name']; + $temporary_arr['card_key'] = $card_all_data_result[$value]['key_word']; + $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; + $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; + $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; + $temporary_arr['background_color'] = $card_all_data_result[$value]['background_color']; + $temporary_arr['background_pic'] = $card_all_data_result[$value]['background_pic']; + $temporary_arr['inside_data'] = []; + if(array_key_exists($value,$db_arr)){ + // 公共卡片内容 + $temporary_arr['id'] = $db_arr[$value]['id']; + $temporary_arr['record_time'] = $db_arr[$value]['record_time']; array_push($temporary_arr['inside_data'],[ - 'key'=>$k, - 'name'=>$v[0], - 'value'=>$tem_arr_2[0], - 'unit'=>$v[1]!='无'?$v[1]:'', - 'standard'=>$tem_arr_2[1]!='无'?$tem_arr_2[1]:'', - 'color'=>$tem_arr_2[2]!='无'?$tem_arr_2[2]:'' - ]); - } - }else{ - $temporary_arr['id'] = ''; - $temporary_arr['record_time'] = ''; - foreach ($this->card_data[$value][2] as $k => $v) { - array_push($temporary_arr['inside_data'],[ - 'key'=>$k, - 'name'=>$v[0], - 'value'=>$v[2], - 'unit'=>$v[1]!='无'?$v[1]:'', + 'key'=>'last_time', + // 'name'=>'最近一次', + 'name'=>"项目名称", + 'value'=>$db_arr[$value]['acdsi_name'], + 'unit'=>'', 'standard'=>'', 'color'=>'' ]); + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + // 'name'=>'最近一次', + 'name'=>"成绩", + 'value'=>$db_arr[$value]['achievement'], + 'unit'=>$db_arr[$value]['unit'], + 'standard'=>'', + 'color'=>'' + ]); + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + // 'name'=>'最近一次', + 'name'=>'得分', + // 'value'=>$db_arr[$value]['score'], + 'value'=>$this->convertStringToNumber($db_arr[$value]['score']), + 'unit'=>'分', + 'standard'=>"", + 'color'=>'' + ]); + }else{ + $temporary_arr['id'] = ''; + $temporary_arr['record_time'] = ''; + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + 'name'=>'最近一次', + 'value'=>"--", + 'unit'=>'', + 'standard'=>'*分', + 'color'=>'' + ]); } + array_push($result,$temporary_arr); } - array_push($result,$temporary_arr); - } - } - return [$result,$target_current]; + // 成功 + // $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[$result,$target_current]]); + return [$result,$data['card_order']]; + // } catch (\Exception $e) { + // // 捕获异常 + // $this->record_api_log($data, $e->getMessage(), null); + // } + } @@ -478,111 +732,290 @@ class Index extends Base{ public function verify_parameters($data,$type){ // 设置验证 - $rule = [ - 'aan_id' => 'require|number', - 'nickname' => 'require|chsAlphaNum', - 'birthday' => 'require|date', - 'gender' => 'require|number|in:0,1,2', - 'grade' => 'require', - 'height' => 'require|number', - 'weight' => 'require|number', - // 'identity' => 'require|number', - ]; - $msg = [ - 'aan_id.require' => '账号信息缺失', - 'nickname.require' => '昵称缺失', - 'birthday.require' => '生日缺失', - 'gender.require' => '性别缺失', - 'grade.require' => '年级缺失', - 'height.require' => '身高缺失', - 'weight.require' => '体重缺失', - // 'identity.require' => '身份缺失', + if($data['measure_model'] == 1){ + $rule = [ + 'aan_id' => 'require|number', + 'nickname' => 'require|chsAlphaNum', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + 'grade' => 'require', + 'height' => 'require|number', + 'weight' => 'require|number', + 'measure_model' => 'require|in:1,2', + 'identity_id' => 'require', + 'identity_name' => 'require', + 'address' => 'require', + ]; + $msg = [ + 'aan_id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + 'grade.require' => '年级缺失', + 'height.require' => '身高缺失', + 'weight.require' => '体重缺失', + 'measure_model.require' => '测量模式缺失', + 'identity_id.require' => '身份缺失', + 'identity_name.require' => '身份缺失', + 'address.require' => '区域缺失', + + 'aan_id.number' => '账号信息格式错误', + 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母和数字', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + 'measure_model.number' => '测量模式错误', + 'measure_model.in' => '测量模式信息错误', + 'height.number' => '身高必须为数字', + 'weight.number' => '体重必须为数字', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + $parameter['aan_id'] = $data['aan_id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + $parameter['card_order'] = ''; + $parameter['height'] = $data['height']; + $parameter['weight'] = $data['weight']; + $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $parameter['measure_model'] = $data['measure_model']; + $parameter['grade'] = $data['grade']; + $parameter['identity_id'] = $data['identity_id']; + $parameter['identity_name'] = $data['identity_name']; + $parameter['address'] = $data['address']; + + if(!array_key_exists($parameter['identity_id'],$this->identity_list)){ + return '身份信息错误'; + }else{ + if($parameter['identity_id'] != 'P0'){ + $parameter['identity_name'] = $this->identity_list[$data['identity_id']]; + $result = Db::table($this->index_use_db_name['2'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); + if($result>0){ + return '该身份已存在'; + } + } + } + $address_data = Db::table($this->index_use_db_name['10'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find(); + $parameter['card_order'] = $address_data['recommend_cards']; + }else{ + $rule = [ + 'aan_id' => 'require|number', + 'nickname' => 'require|chsAlphaNum', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + // 'grade' => 'require', + 'height' => 'require|number', + 'weight' => 'require|number', + 'measure_model' => 'require|in:1,2', + // 'identity_id' => 'require', + // 'identity_name' => 'require', + // 'address' => 'require', + ]; + $msg = [ + 'aan_id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + // 'grade.require' => '年级缺失', + 'height.require' => '身高缺失', + 'weight.require' => '体重缺失', + 'measure_model.require' => '测量模式缺失', + // 'identity_id.require' => '身份缺失', + // 'identity_name.require' => '身份缺失', + // 'address.require' => '区域缺失', + + 'aan_id.number' => '账号信息格式错误', + 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母和数字', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + 'measure_model.number' => '测量模式错误', + 'measure_model.in' => '测量模式信息错误', + 'height.number' => '身高必须为数字', + 'weight.number' => '体重必须为数字', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + $parameter['aan_id'] = $data['aan_id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + $parameter['card_order'] = '2'; + $parameter['height'] = $data['height']; + $parameter['weight'] = $data['weight']; + $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $parameter['measure_model'] = $data['measure_model']; - 'aan_id.number' => '账号信息格式错误', - 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母', - 'birthday.date' => '生日信息格式错误', - 'gender.number' => '性别格式错误', - 'gender.in' => '性别信息错误', - 'height.number' => '身高必须为数字', - 'weight.number' => '体重必须为数字', - // 'identity.number' => '身份信息格式错误', - ]; - $validate = new Validate($rule,$msg); - $result = $validate->check($data); - if(!$result){ - return $validate->getError(); + $parameter['grade'] = "nothing"; + $parameter['identity_id'] = "P0"; + $parameter['identity_name'] = "陌生人"; + $parameter['address'] = ''; + $parameter_pd = Db::table($this->index_use_db_name['7'])->where(['id'=>$parameter['aan_id']])->count(); + if($parameter_pd <= 0){ + return '该账户不存在'; + } + $result = Db::table($this->index_use_db_name['2'])->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); + if($result>0){ + return '该成员已存在'; + } } - - $parameter['aan_id'] = $data['aan_id']; - $parameter['nickname'] = $data['nickname']; - $parameter['birthday'] = $data['birthday']; - $parameter['gender'] = $data['gender']; - $parameter['grade'] = $data['grade']; - $parameter['card_order'] = '2,6,8'; - $parameter['height'] = $data['height']; - $parameter['weight'] = $data['weight']; - $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; - // $parameter['identity_data'] = $data['identity']; - $parameter['create_time'] = date('Y-m-d H:i:s'); - $parameter['last_update_time'] = date('Y-m-d H:i:s'); - $parameter_pd = Db::table('app_account_number')->where(['id'=>$parameter['aan_id']])->count(); - if($parameter_pd <= 0){ - return '该账户不存在'; - } - $result = Db::table('app_user_data')->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); - if($result>0){ - return '该成员已存在'; - } - return $parameter; } public function verify_parameters2($data,$type){ - // 设置验证 - $rule = [ - 'id' => 'require|number', - 'nickname' => 'require|chsAlphaNum', - 'birthday' => 'require|date', - 'gender' => 'require|number|in:0,1,2', - 'grade' => 'require', - 'height' => 'require|number', - 'weight' => 'require|number', - // 'identity' => 'require|number', - ]; - $msg = [ - 'id.require' => '用户信息缺失', - 'nickname.require' => '昵称缺失', - 'birthday.require' => '生日缺失', - 'gender.require' => '性别缺失', - 'grade.require' => '年级缺失', - 'height.require' => '身高缺失', - 'weight.require' => '体重缺失', - // 'identity.require' => '身份缺失', + if($data['measure_model'] == 1){ + $rule = [ + 'id' => 'require|number', + 'nickname' => 'require|chsAlphaNum', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + 'grade' => 'require', + 'height' => 'require|number', + 'weight' => 'require|number', + 'measure_model' => 'require|in:1,2', + 'identity_id' => 'require', + 'identity_name' => 'require', + 'address' => 'require', + ]; + $msg = [ + 'id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + 'grade.require' => '年级缺失', + 'height.require' => '身高缺失', + 'weight.require' => '体重缺失', + 'measure_model.require' => '测量模式缺失', + 'identity_id.require' => '身份缺失', + 'identity_name.require' => '身份缺失', + 'address.require' => '区域缺失', + + 'id.number' => '账号信息格式错误', + 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母和数字', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + 'measure_model.number' => '测量模式错误', + 'measure_model.in' => '测量模式信息错误', + 'height.number' => '身高必须为数字', + 'weight.number' => '体重必须为数字', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + $parameter['id'] = $data['id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + $parameter['card_order'] = '2'; + $parameter['height'] = $data['height']; + $parameter['weight'] = $data['weight']; + $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $parameter['measure_model'] = $data['measure_model']; + $parameter['grade'] = $data['grade']; + $parameter['identity_id'] = $data['identity_id']; + $parameter['identity_name'] = $data['identity_name']; + $parameter['address'] = $data['address']; + $aan_id = $data['aan_id']; + if(!array_key_exists($parameter['identity_id'],$this->identity_list)){ + return '身份信息错误'; + }else{ + if($parameter['identity_id'] != 'P0'){ + $parameter['identity_name'] = $this->identity_list[$data['identity_id']]; + $result = Db::table($this->index_use_db_name['2']) + // ->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$aan_id,'is_del'=>0]) + ->where("identity_id = '".$parameter['identity_id']."' and aan_id = '".$aan_id."' and is_del = 0 and id <> ".$parameter['id']."") + ->field('id,identity_id') + ->find(); + if($result && $parameter['id'] != $result['id']){ + return '该身份已存在'; + } + } + } + $address_data = Db::table($this->index_use_db_name['10'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find(); + $parameter['card_order'] = $address_data['recommend_cards']; + }else{ + $rule = [ + 'aan_id' => 'require|number', + 'nickname' => 'require|chsAlphaNum', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + // 'grade' => 'require', + 'height' => 'require|number', + 'weight' => 'require|number', + 'measure_model' => 'require|in:1,2', + // 'identity_id' => 'require', + // 'identity_name' => 'require', + // 'address' => 'require', + ]; + $msg = [ + 'aan_id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + // 'grade.require' => '年级缺失', + 'height.require' => '身高缺失', + 'weight.require' => '体重缺失', + 'measure_model.require' => '测量模式缺失', + // 'identity_id.require' => '身份缺失', + // 'identity_name.require' => '身份缺失', + // 'address.require' => '区域缺失', + + 'aan_id.number' => '账号信息格式错误', + 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母和数字', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + 'measure_model.number' => '测量模式错误', + 'measure_model.in' => '测量模式信息错误', + 'height.number' => '身高必须为数字', + 'weight.number' => '体重必须为数字', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + $parameter['id'] = $data['id']; + $parameter['aan_id'] = $data['aan_id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + // $parameter['card_order'] = '2'; + $parameter['height'] = $data['height']; + $parameter['weight'] = $data['weight']; + $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $parameter['measure_model'] = $data['measure_model']; - 'id.number' => '用户信息格式错误', - 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母、数字', - 'birthday.date' => '生日信息格式错误', - 'gender.number' => '性别格式错误', - 'gender.in' => '性别信息错误', - 'height.number' => '身高必须为数字', - 'weight.number' => '体重必须为数字', - // 'identity.number' => '身份信息格式错误', - ]; - $validate = new Validate($rule,$msg); - $result = $validate->check($data); - if(!$result){ - return $validate->getError(); + $parameter_pd = Db::table($this->index_use_db_name['7'])->where(['id'=>$parameter['aan_id']])->count(); + if($parameter_pd <= 0){ + return '该账户不存在'; + } + $result = Db::table($this->index_use_db_name['2']) + // ->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0]) + ->where("nickname = '".$parameter['nickname']."' and aan_id = '".$parameter['aan_id']."' and is_del = 0 and id <> ".$parameter['id']."") + ->count(); + if($result>0){ + return '该成员已存在'; + } + unset($parameter['aan_id']); } - - $parameter['id'] = $data['id']; - $parameter['nickname'] = $data['nickname']; - $parameter['birthday'] = $data['birthday']; - $parameter['height'] = $data['height']; - $parameter['weight'] = $data['weight']; - $parameter['gender'] = $data['gender']; - $parameter['grade'] = $data['grade']; - $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; - // $parameter['identity_data'] = $data['identity']; - $parameter['last_update_time'] = date('Y-m-d H:i:s'); return $parameter; } diff --git a/application/app/controller/Login.php b/application/app/controller/Login.php index 41d7fe8..7306654 100644 --- a/application/app/controller/Login.php +++ b/application/app/controller/Login.php @@ -2,17 +2,18 @@ namespace app\app\controller; -use think\Controller; + use think\Db; -use think\Cache; -use think\Log; -use \think\Validate; use PHPMailer\PHPMailer\PHPMailer; + class Login extends Base{ protected $code_time = 50; + // protected $token_time = 2592000;//30天的秒数 protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png'; - + protected $login_use_db_name = [ + '1'=>'app_account_number', + ]; ################################################################接口################################################################ ################################################################接口################################################################ @@ -20,186 +21,304 @@ class Login extends Base{ // 注册 public function register_action($data = ['data'=>18530934717,'password'=>'ceshi','code'=>'746119']){ - // 验证是否前段发送过来的数据 - if(count(input('post.')) > 0){ - $data = input('post.'); - } - // 验证数据项是否完整 - if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){ - return $this->msg(10001); - } - // 验证数据值是否合规 - if(!$data['data'] || !$data['password'] || !$data['code']){ - return $this->msg(10006); - } - // 验证是手机还是邮箱 - $montage_data = $this->is_tel_email($data['data']); - if($montage_data == false){ - return $this->msg(10005); - } - // 查询账号是否已经注册 - $inspect_repeat = Db::table('app_account_number')->where([$montage_data=>$data['data'],'is_del'=>0])->count(); - if($inspect_repeat >= 0){ - return $this->msg(10002,'注册失败,账号已存在'); - } - // 检查验证码 - $code_result = $this->check_code($data['data'],$data['code']); - if($code_result !== true){ - return $this->msg(10002,$code_result); - } - // 验证完之后 - $set_data = []; - if($montage_data == 'tel'){ - $set_data['tel'] = $data['data']; - }else{ - $set_data['email'] = $data['data']; - } - $set_data['password'] = $data['password']; - $set_data['head_pic'] = $this->default_head_pic; - $set_data['nickname'] = '用户'.time(); - $set_data['create_time'] = date('Y-m-d H:i:s'); - $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); - $result = Db::table('app_account_number')->insertGetId($set_data); - if($result){ - cache($set_data['token'], time()); - return $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + // 验证是否前段发送过来的数据 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + // 验证数据项是否完整 + if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){ + return $this->msg(10001); + } + // 验证数据值是否合规 + if(!$data['data'] || !$data['password'] || !$data['code']){ + return $this->msg(10006); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'num')){ + return $this->msg(10005); + } + // 验证是手机还是邮箱 + $montage_data = $this->is_tel_email($data['data']); + if($montage_data == false){ + return $this->msg(10005); + } + // 查询账号是否已经注册 + $inspect_repeat = Db::table($this->login_use_db_name['1'])->where([$montage_data=>$data['data'],'is_del'=>0])->count(); + if($inspect_repeat >= 0){ + return $this->msg(10002,'注册失败,账号已存在'); + } + // 检查验证码 + $code_result = $this->check_code($data['data'],$data['code']); + if($code_result !== true){ + return $this->msg(10002,$code_result); + } + // 验证完之后 + $set_data = []; + if($montage_data == 'tel'){ + $set_data['tel'] = $data['data']; + }else{ + $set_data['email'] = $data['data']; + } + $set_data['password'] = $data['password']; + $set_data['head_pic'] = $this->default_head_pic; + $set_data['nickname'] = '用户'.time(); + $set_data['create_time'] = date('Y-m-d H:i:s'); + $set_data['login_time'] = date('Y-m-d H:i:s'); + $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); + $result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data); + if($result){ + $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 重置密码 public function reset_password($data = ['data'=>'18530934717','password'=>'ceshi1','c_password'=>'ceshi1','code'=>'491661']){ - // 验证是否前段发送过来的数据 - if(count(input('post.')) > 0){ - $data = input('post.'); - } - // 验证数据项是否完整 - if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){ - return $this->msg(10001); - } - // 验证数据值是否合规 - if($data['password'] != $data['c_password']){ - return $this->msg(10003,'两次密码不一致'); - } - if($data['password'] == ''){ - return $this->msg(10003,'密码不能为空'); - } - // 检查验证码 - $code_result = $this->check_code($data['data'],$data['code']); - if($code_result !== true){ - return $this->msg(10003,$code_result); - } - $t_y = $this->is_tel_email($data['data']); - if($t_y === false){ - return $this->msg(10003,'账号格式错误'); - } - // 检查账号是否存在 - $find_data = Db::table('app_account_number')->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find(); - if(!$find_data){ - return $this->msg(10003); - } - $result = Db::table('app_account_number')->where([$t_y=>$data['data']])->update(['password'=>$data['password']]); - if($result){ - cache($find_data['token'], time()); - return $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + // 验证是否前段发送过来的数据 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + // 验证数据项是否完整 + if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){ + return $this->msg(10001); + } + // 验证数据值是否合规 + if($data['password'] != $data['c_password']){ + return $this->msg(10003,'两次密码不一致'); + } + if($data['password'] == ''){ + return $this->msg(10003,'密码不能为空'); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'num')){ + return $this->msg(10005); + } + // 检查验证码 + $code_result = $this->check_code($data['data'],$data['code']); + if($code_result !== true){ + return $this->msg(10003,$code_result); + } + $t_y = $this->is_tel_email($data['data']); + if($t_y === false){ + return $this->msg(10003,'账号格式错误'); + } + // 检查账号是否存在 + $find_data = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find(); + if(!$find_data){ + return $this->msg(10003); + } + $result = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data']])->update(['password'=>$data['password']]); + if($result){ + $return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 登录 - public function login_action($data = ['data'=>'18530934717','validate_data'=>'746119','type'=>'login','validate_type'=>'code']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){ - return $this->msg(10001); - } - // 检测是否为手机 - $montage_data = $this->is_tel_email($data['data']); - if($montage_data == false){ - return $this->msg(10005); - } - $verify_result[$montage_data] = $data['data']; - $verify_result['is_del'] = 0; - // 检测校验途径 - if($data['validate_type'] == 'code'){ - $code_name = $data['data']; - if($this->check_code($code_name,$data['validate_data']) === true){ - $result = Db::table('app_account_number')->where($verify_result)->field('id,token')->find(); - if($result){ - cache($result['token'], time()); - return $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]); - }else{ - $set_data['password'] = ''; - $set_data[$montage_data] = $data['data']; - $set_data['head_pic'] = $this->default_head_pic; - $set_data['nickname'] = '用户'.$data['data']; - $set_data['create_time'] = date('Y-m-d H:i:s'); - $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); - $result = Db::table('app_account_number')->insertGetId($set_data); + public function login_action($data = ['data'=>'18530934717','validate_data'=>'0932','type'=>'login','validate_type'=>'password']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){ + return $this->msg(10001); + } + // 检测是否为手机 + $montage_data = $this->is_tel_email($data['data']); + if($montage_data == false){ + return $this->msg(10005); + } + + $verify_result[$montage_data] = $data['data']; + $verify_result['is_del'] = 0; + // 检测校验途径 + if($data['validate_type'] == 'code'){ + $code_name = $data['data']; + if($this->check_code($code_name,$data['validate_data']) === true){ + $result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token')->find(); if($result){ - cache($set_data['token'], time()); - return $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功'); + Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); + $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]); }else{ - return $this->msg(10002); + $set_data['password'] = ''; + $set_data[$montage_data] = $data['data']; + $set_data['head_pic'] = $this->default_head_pic; + $set_data['nickname'] = '用户'.$data['data']; + $set_data['create_time'] = date('Y-m-d H:i:s'); + $set_data['login_time'] = date('Y-m-d H:i:s'); + $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); + $result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data); + if($result){ + $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功'); + }else{ + $return_data = $this->msg(10002); + } } - } - }else{ - return $this->msg(10003,'登录失败,验证码错误或失效'); - } - }else if($data['validate_type'] == 'password'){ - // $verify_result['password'] = $data['validate_data']; - $result = Db::table('app_account_number')->where($verify_result)->field('id,token,password')->find(); - if($result){ - if($result['password'] == ''){ - return $this->msg(10003,'该账户未设密码,请用验证码登录'); - } - if($data['validate_data'] != $result['password']){ - return $this->msg(10003,'账号密码错误'); }else{ - cache($result['token'], time()); - return $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功'); + $return_data = $this->msg(10003,'登录失败,验证码错误或失效'); + } + }else if($data['validate_type'] == 'password'){ + // $verify_result['password'] = $data['validate_data']; + $result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token,password')->find(); + if($result){ + if($result['password'] == ''){ + $return_data = $this->msg(10003,'该账户未设密码,请用验证码登录'); + } + if($data['validate_data'] != $result['password']){ + $return_data = $this->msg(10003,'账号密码错误'); + }else{ + + Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); + $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功'); + } + }else{ + $return_data = $this->msg(10003,'账号未注册,请先注册'); } }else{ - return $this->msg(10003,'账号未注册,请先注册'); + $return_data = $this->msg(10003,'校验参数错误'); } - }else{ - return $this->msg(10003,'校验参数错误'); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 退出登录操作 public function user_quit_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if($this->token_time_validate($data['token']) === false){ + $return_data = $this->msg(20001); + } + + $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']); + if($result){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - cache($data['token'], NULL); - return $this->msg([]); + } // 删除账号 public function delete_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - $result = Db::table('app_account_number')->where(['token'=>$data['token']])->update(['is_del'=>1]); - cache($data['token'], NULL); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-09-01 00:00:00']); + if($result){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } ################################################################接口################################################################ @@ -215,9 +334,7 @@ class Login extends Base{ * $road(是手机还是邮箱还是其他) 字符串 默认tel或email */ public function send_phone_email_code($data = ['data'=>'18530934717']){ - // dump(cache('linshi')); - // die; - // $data = input('post.'); + if(count(input('post.')) > 0){ $data = input('post.'); } @@ -235,15 +352,10 @@ class Login extends Base{ $road = 'tel'; }else{ $result = $this->send_email_code([$data['data']],['title'=>'体测APP验证码','from_user_name'=>'体测APP','content'=>$num]); - // dump($result); $road = 'email'; } - // dump($result); - // dump($road); - // die; if(is_array($result) && $result['code'] == 0){ cache($data['data'], $num, $this->code_time); - // dump($data['data']."_".$data['road']."_".$data['type']); // return $this->msg(['code'=>$num]); return $this->msg([]); // return true; @@ -291,8 +403,7 @@ class Login extends Base{ // 关闭cURL会话 curl_close($ch); // 处理响应 - // dump($response); - cache('linshi', $response); + if ($response) { return json_decode($response,true); } else { @@ -361,7 +472,7 @@ class Login extends Base{
     
    - QingCe! + Reedaw!
     
    @@ -373,7 +484,7 @@ class Login extends Base{
     
    - 感谢您选择青测产品! + 感谢您选择锐动产品!
     
    @@ -434,8 +545,6 @@ class Login extends Base{ '; $mail->Body = $neirong; //邮件主体内容 - // dump($address); - // die; //发送 if (!$mail->Send()) { @@ -451,10 +560,7 @@ class Login extends Base{ public function check_code($data = 18530934717 , $code = 123456){ // // 默认验证码正确 - // return true; - // dump($data); - // dump(cache($data)); - // die; + if(cache($data) == false){ return '验证码过期'; }else{ diff --git a/application/app/controller/Msginformation.php b/application/app/controller/Msginformation.php new file mode 100644 index 0000000..4fea149 --- /dev/null +++ b/application/app/controller/Msginformation.php @@ -0,0 +1,283 @@ +'admin_editor_text_content', + '2'=>'admin_editor_text_like_up_log', + ]; + protected $page_num = 10; + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + + // 获取板块,及板块下类型标签 + public function get_sector_label_msg(){ + try { + $return_data = $this->get_sector_label_msg_action(); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log([], $logContent, null); + return $this->msg(99999); + } + + } + // 获取板块下信息 + public function get_sector_content_msg($data = ['token'=>'6441bf7dabea7b3360a30240d3b19fc5','sector_id'=>1,'type'=>4,'page'=>1]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('sector_id', $data) || !array_key_exists('type', $data) || !array_key_exists('page', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['sector_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->get_sector_content_msg_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + + // 资讯点赞 + public function user_like_it($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','id'=>'44']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->user_like_it_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + + ################################################################业务################################################################ + ################################################################get_sector_label_msg + public function get_sector_label_msg_action(){ + $Template_arr = [ + 1=>[ + 'id'=>'1', + 'name'=>'推荐', + 'loop_data'=>[], + 'list'=>[ + ['id'=>0,'name'=>'全部'], + ['id'=>1,'name'=>'身高管理'], + ['id'=>2,'name'=>'体重管理'], + ['id'=>3,'name'=>'肺活训练'], + ['id'=>4,'name'=>'跳绳训练'], + ['id'=>5,'name'=>'中考体测'], + ] + ], + ]; + // 获取需要版块id start + $sector = Db::query(" + SELECT + sector + FROM ".$this->msginformation_use_db_name['1']." + group by sector + "); + $sector_all = []; + foreach ($sector as $key => $value) { + foreach (explode(',', $value['sector']) as $k => $v) { + if(!in_array($v, $sector_all)){ + array_push($sector_all, $v); + } + } + } + // 获取需要版块id end + // 填充进去版块的轮播start + $return_data = []; + foreach ($sector_all as $key => $value) { + + $loop_result = Db::query(" + SELECT + id, + title, + CONCAT('https://tc.pcxbc.com/', cover_image) AS cover_image + FROM ".$this->msginformation_use_db_name['1']." + WHERE + is_del = 0 AND loop_img > 0 AND sector LIKE '%".$value."%' + ORDER BY + loop_img desc + "); + $Template_arr[$value]['loop_data'] = $loop_result; + array_push($return_data, $Template_arr[$value]); + } + // 填充进去版块的轮播end + return $this->msg($return_data); + } + ################################################################get_sector_content_msg + public function get_sector_content_msg_action($data){ + $return_result = [ + 'page_now'=>$data['page'], + 'page_num'=>$this->page_num, + 'content_data'=>[] + ]; + if($data['type'] != 0){ + $type_str = " AND type LIKE '%".$data['type']."%'"; + }else{ + $type_str = ""; + } + $content_result = Db::query(" + SELECT + id, + title, + create_time, + i_like, + reading, + CONCAT('https://tc.pcxbc.com/', cover_image) AS cover_image, + top_up + FROM ".$this->msginformation_use_db_name['1']." + WHERE + is_del = 0 AND sector LIKE '%".$data['sector_id']."%'".$type_str." + ORDER BY + top_up desc,id + OFFSET + (".$data['page']." - 1) * ".$this->page_num." ROWS + FETCH NEXT + ".$this->page_num." ROWS ONLY + "); + $return_result['content_data'] = $content_result; + $user_like = Db::table($this->msginformation_use_db_name['2'])->where(['token'=>$data['token'],'is_del'=>0])->column('aetc_id'); + + foreach ($return_result['content_data'] as $key => $value) { + if(array_key_exists($value['id'], $user_like)){ + $return_result['content_data'][$key]['is_like'] = 1; + }else{ + $return_result['content_data'][$key]['is_like'] = 0; + } + } + return $this->msg($return_result); + } + ################################################################user_like_it + public function user_like_it_action($data){ + $user_like_data = Db::table($this->msginformation_use_db_name['2'])->where(['token'=>$data['token'],'aetc_id'=>$data['id']])->find(); + + if($user_like_data){ + // 如果找到有点赞记录 + if($user_like_data['is_del'] == 0){ + // 如果已经点了 + // 启动事务 + Db::startTrans(); + try{ + Db::table($this->msginformation_use_db_name['1'])->where(['id'=>$data['id']])->setDec('i_like'); + Db::table($this->msginformation_use_db_name['2'])->where(['aetc_id'=>$data['id'],'token'=>$data['token']])->update(['is_del'=>1,'update_time'=>date('Y-m-d H:i:s')]); + // 提交事务 + Db::commit(); + return $this->msg(['user_like'=>1]); + } catch (\Exception $e) { + // 回滚事务 + Db::rollback(); + return $this->msg(10002); + } + }else{ + // 如果之前点过又取消了 + // 启动事务 + Db::startTrans(); + try{ + Db::table($this->msginformation_use_db_name['1'])->where(['id'=>$data['id']])->setInc('i_like'); + Db::table($this->msginformation_use_db_name['2'])->where(['aetc_id'=>$data['id'],'token'=>$data['token']])->update(['is_del'=>0,'update_time'=>date('Y-m-d H:i:s')]); + // 提交事务 + Db::commit(); + return $this->msg(['user_like'=>0]); + } catch (\Exception $e) { + // 回滚事务 + Db::rollback(); + return $this->msg(10002); + } + } + }else{ + // 如果没有记录 + // 启动事务 + Db::startTrans(); + try{ + Db::table($this->msginformation_use_db_name['1'])->where(['id'=>$data['id']])->setInc('i_like'); + Db::table($this->msginformation_use_db_name['2'])->insert([ + 'aetc_id'=>$data['id'], + 'token'=>$data['token'], + 'create_time'=>date('Y-m-d H:i:s'), + 'update_time'=>date('Y-m-d H:i:s') + ]); + // 提交事务 + Db::commit(); + return $this->msg(['user_like'=>0]); + } catch (\Exception $e) { + // 回滚事务 + Db::rollback(); + return $this->msg(10002); + } + } + + } + + + +} \ No newline at end of file diff --git a/application/app/controller/Myinformation.php b/application/app/controller/Myinformation.php index b03cc1d..990de72 100644 --- a/application/app/controller/Myinformation.php +++ b/application/app/controller/Myinformation.php @@ -2,13 +2,15 @@ namespace app\app\controller; -use think\Controller; + use think\Db; use app\app\controller\Login; class Myinformation extends Base{ - + protected $myinformation_use_db_name = [ + '1'=>'app_account_number', + ]; // 加 bcadd(,,20) // 减 bcsub(,,20) // 乘 bcmul(,,20) @@ -19,69 +21,151 @@ class Myinformation extends Base{ // 获取账号下信息 public function get_my_account_msg($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->get_my_account_msg_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->get_my_account_msg_action($data); } // 修改昵称 public function update_my_nickname($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','nickname'=>'']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('nickname', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['nickname'],'str')){ + return $this->msg(10005); + } + $return_data = $this->update_my_nickname_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('nickname', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->update_my_nickname_action($data); } // 邮箱/手机绑定 public function update_my_account_msg($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','data'=>'tsf3920322@126.com','code'=>'123456']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('data', $data) || !array_key_exists('token', $data) || !array_key_exists('code', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'intnum')){ + return $this->msg(10005); + } + + $return_data = $this->update_my_account_msg_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('data', $data) || !array_key_exists('token', $data) || !array_key_exists('code', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->update_my_account_msg_action($data); } // 修改密码 public function update_my_password($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','password'=>'ceshi1','c_password'=>'ceshi1']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['c_password'],'str')){ + return $this->msg(10005); + } + $return_data = $this->update_my_password_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->update_my_password_action($data); + } ################################################################业务################################################################ ################################################################get_my_account_msg public function get_my_account_msg_action($data){ - $result = Db::table('app_account_number')->where(['token'=>$data['token'],'is_del'=>0])->find(); + $result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->find(); if($result){ return $this->msg([ 'my_tel'=>$result['tel'], @@ -98,7 +182,7 @@ class Myinformation extends Base{ } ################################################################update_my_nickname public function update_my_nickname_action($data){ - $result = Db::table('app_account_number')->where(['token'=>$data['token'],'is_del'=>0])->update([ + $result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([ 'nickname'=>$data['nickname'], 'update_time'=>date('Y-m-d H:i:s') ]); @@ -119,9 +203,7 @@ class Myinformation extends Base{ if($montage_data == false){ return $this->msg(10005); } - // dump($data); - // die; - $result = Db::table('app_account_number')->where(['token'=>$data['token'],'is_del'=>0])->update([ + $result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([ $montage_data=>$data['data'], 'update_time'=>date('Y-m-d H:i:s') ]); @@ -139,7 +221,7 @@ class Myinformation extends Base{ if($data['password'] == ''){ return $this->msg(10003,'密码不能为空'); } - $result = Db::table('app_account_number')->where(['token'=>$data['token'],'is_del'=>0])->update([ + $result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([ 'password'=>$data['password'], 'update_time'=>date('Y-m-d H:i:s') ]); diff --git a/application/app/controller/Pagingcontrast.php b/application/app/controller/Pagingcontrast.php index b829f76..0717b3e 100644 --- a/application/app/controller/Pagingcontrast.php +++ b/application/app/controller/Pagingcontrast.php @@ -2,113 +2,232 @@ namespace app\app\controller; -use think\Controller; use think\Db; -use \think\Validate; -use app\app\controller\Calculatebody; -use app\app\controller\Skip; class Pagingcontrast extends Base{ protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6']; protected $db_name = ['2'=>'app_card_body_data','6'=>'app_card_skip_data','8'=>'app_card_vitalcapacity_data']; + protected $pagingcontrast_use_db_name = [ + '1'=>'app_card_body_data', + '2'=>'app_card_skip_data', + '3'=>'app_card_vitalcapacity_data', + '4'=>'app_user_data', + ]; protected $request_result = [ '2'=>['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI',''],'fat_w'=>['脂肪量','kg'],'fat_r'=>['脂肪率','%'],'muscleval'=>['肌肉量','kg'],'muscle'=>['肌肉率','%'],'proteinval'=>['蛋白量','kg'],'protein'=>['蛋白率','%'],'water'=>['水分',''],'bone'=>['骨重','kg'],'visceral'=>['内脏指数',''],'sfr'=>['皮下脂肪','%'],'kcal'=>['基础代谢','kcal'],'un_fat_w_weight'=>['去脂体重','kg'],'body_age'=>['体龄',''],'body_level'=>['肥胖等级',''],'body_type'=>['体型','']], '6'=>['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']], '8'=>['one_val'=>['第一次','ml'],'two_val'=>['第二次','ml'],'three_val'=>['第三次','ml'],'average_val'=>['三次平均','ml'],'score'=>['最后成绩','分']] ]; - protected $pagesize = 10; - ################################################请求接口################################################ ################################################请求接口################################################ ################################################请求接口################################################ // 获取记录信息(分组)(包含身体、跳绳、肺活量) public function get_all_record_data_group($data = ['aud_id'=>'26','s_time'=>'2024-04-01','e_time'=>'2024-06-12','token'=>'0dafb98a10995c98b5a33b7d59d986ca','type'=>'6']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if(array_key_exists($data['type'],$this->db_name)){ - return $this->jump_transfer_interface_record($data,'group'); - }else{ - return $this->msg(10005); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + if(array_key_exists($data['type'],$this->db_name)){ + $return_data = $this->jump_transfer_interface_record($data,'group'); + }else{ + $return_data = $this->msg(10005); + } + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 获取记录信息(分页)(包含身体、跳绳、肺活量) - public function get_all_record_data_page($data = ['aud_id'=>'25','page'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca','type'=>'2']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('page', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if(array_key_exists($data['type'],$this->db_name)){ - return $this->jump_transfer_interface_record($data,'page'); - }else{ - return $this->msg(10005); + public function get_all_record_data_page($data = ['aud_id'=>'11','page'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca','type'=>'2']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('page', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + if(array_key_exists($data['type'],$this->db_name)){ + $return_data = $this->jump_transfer_interface_record($data,'page'); + }else{ + $return_data = $this->msg(10005); + } + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 获取详细历史数据信息(包含身体、跳绳、肺活量) - public function get_all_record_detailed_information($data = ['id'=>'39','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function get_all_record_detailed_information($data = ['id'=>'52','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->jump_transfer_interface_detailed($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->jump_transfer_interface_detailed($data); } // 数据对比(包含身体、跳绳、肺活量) - public function get_all_card_data_contrast($data = ['before_id'=>'837','after_id'=>'836','type'=>'6','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function get_all_card_data_contrast($data = ['before_id'=>'51','after_id'=>'52','type'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['before_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['after_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->jump_transfer_interface_data_contrast($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // $data = explode(',',$data['id_arr']); - // dump($data); - // die; - return $this->jump_transfer_interface_data_contrast($data); + } // 删除历史数据 public function del_all_record_data($data = ['id'=>'29','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $user_data = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->update(['is_del'=>1]); - if($user_data){ - return $this->msg([]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $user_data = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->update(['is_del'=>1]); + if($user_data){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } ################################################请求接口################################################ ################################################请求接口################################################ @@ -125,15 +244,6 @@ class Pagingcontrast extends Base{ } public function jump_transfer_interface_detailed($data){ return $this->get_all_detaile_data_msg($data); - - // if($data['type'] == '2'){ - // return $this->get_body_detaile_data_msg($data); - // }else if($data['type'] == '6'){ - // return $this->get_skip_detaile_data_msg($data); - // // return $this->msg(10005); - // }else if($data['type'] == '8'){ - // // return $this->get_body_record_data($data,$str); - // } } public function jump_transfer_interface_data_contrast($data){ if($data['type'] == '2'){ @@ -164,7 +274,7 @@ class Pagingcontrast extends Base{ height_val as v1, weight_val as v2, bmi_val as v3 - from app_card_body_data + from ".$this->pagingcontrast_use_db_name['1']." where aud_id='".$data['aud_id']."' and record_time between '".$data['s_time']."' and '".$data['e_time']."' and is_del = 0 @@ -183,8 +293,8 @@ class Pagingcontrast extends Base{ ]); } }else{ - $result = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,height_val,weight_val,bmi_val")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); - $return_result['totalrows'] = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->count(); + $result = Db::table($this->pagingcontrast_use_db_name['1'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,height_val,weight_val,bmi_val")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); + $return_result['totalrows'] = Db::table($this->pagingcontrast_use_db_name['1'])->where(['aud_id'=>$data['aud_id']])->count(); $return_result['rows'] = []; $return_result['pageno'] = $data['page']; $return_result['pagesize'] = $this->pagesize; @@ -220,7 +330,7 @@ class Pagingcontrast extends Base{ jump_num as v1, jump_time as v2, jump_kcal as v3 - from app_card_skip_data + from ".$this->pagingcontrast_use_db_name['2']." where aud_id='".$data['aud_id']."' and record_time between '".$data['s_time']."' and '".$data['e_time']."' and is_del = 0 @@ -240,8 +350,8 @@ class Pagingcontrast extends Base{ ]); } }else{ - $result = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,jump_num,jump_time,jump_kcal")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); - $return_result['totalrows'] = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->count(); + $result = Db::table($this->pagingcontrast_use_db_name['2'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,jump_num,jump_time,jump_kcal")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); + $return_result['totalrows'] = Db::table($this->pagingcontrast_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->count(); $return_result['rows'] = []; $return_result['pageno'] = $data['page']; $return_result['pagesize'] = $this->pagesize; @@ -280,7 +390,7 @@ class Pagingcontrast extends Base{ three_val as v3, average_val as v4, score as v5 - from app_card_vitalcapacity_data + from ".$this->pagingcontrast_use_db_name['3']." where aud_id='".$data['aud_id']."' and record_time between '".$data['s_time']."' and '".$data['e_time']."' and is_del = 0 @@ -289,10 +399,10 @@ class Pagingcontrast extends Base{ // $time_t = $this->handle_hour_branch_second($value['v2']); array_push($return_result, [ 'id'=>$value['id'], - 'v1'=>$value['v1'], - 'v2'=>$value['v2'], - 'v3'=>$value['v3'], - 'v4'=>$value['v4'], + 'v1'=>$value['v1'] == '.00'?'0':$value['v1'], + 'v2'=>$value['v2'] == '.00'?'0':$value['v2'], + 'v3'=>$value['v3'] == '.00'?'0':$value['v3'], + 'v4'=>$value['v4'] == '.00'?'0':$value['v4'], 'v5'=>explode(',',$value['v5'])[0], 'v1_name'=>'第一次', 'v2_name'=>'第二次', @@ -304,8 +414,8 @@ class Pagingcontrast extends Base{ ]); } }else{ - $result = Db::table('app_card_vitalcapacity_data')->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,one_val,two_val,three_val,average_val,score")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); - $return_result['totalrows'] = Db::table('app_card_vitalcapacity_data')->where(['aud_id'=>$data['aud_id']])->count(); + $result = Db::table($this->pagingcontrast_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,one_val,two_val,three_val,average_val,score")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); + $return_result['totalrows'] = Db::table($this->pagingcontrast_use_db_name['3'])->where(['aud_id'=>$data['aud_id']])->count(); $return_result['rows'] = []; $return_result['pageno'] = $data['page']; $return_result['pagesize'] = $this->pagesize; @@ -314,10 +424,10 @@ class Pagingcontrast extends Base{ // $time_t = $this->handle_hour_branch_second($value['jump_time']); array_push($return_result['rows'],[ 'id'=>$value['id'], - 'v1'=>$value['one_val'], - 'v2'=>$value['two_val'], - 'v3'=>$value['three_val'], - 'v4'=>$value['average_val'], + 'v1'=>$value['one_val'] == '.00'?'0':$value['one_val'], + 'v2'=>$value['two_val'] == '.00'?'0':$value['two_val'], + 'v3'=>$value['three_val'] == '.00'?'0':$value['three_val'], + 'v4'=>$value['average_val'] == '.00'?'0':$value['average_val'], 'v5'=>explode(',',$value['score'])[0], 'v1_name'=>'第一次', 'v2_name'=>'第二次', @@ -334,17 +444,38 @@ class Pagingcontrast extends Base{ // 获取详细历史数据信息 public function get_all_detaile_data_msg($data){ + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + // 设置排除在外的数据类型start + // $exclude_data_arr = ['height','weight','age','bmi','body_level','body_type']; + $exclude_data_arr = ['height','weight','age','bmi']; + // 设置排除在外的数据类型end $result = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->find(); + $for_data_arr = $this->request_result[$data['type']]; if($result){ + // if($data['type'] == 2 && $result['record_type'] != 'by_device_adc'){ + // $for_data_arr = ['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI','']]; + // } $result_data = []; - foreach ($this->request_result[$data['type']] as $key => $value) { + foreach ($for_data_arr as $key => $value) { $temporary_arr['key_name'] = $key; $temporary_arr['name'] = $value[0]; if($data['type'] == 2){ - if($key == 'un_fat_w_weight'){ - $temporary_arr['value'] = bcsub(explode(',',$result['weight'])[0],explode(',',$result['fat_w'])[0],2); + // 身体数据处理,如果没有阻抗,则只显示四项$exclude_data_arr + if($result['record_type'] != 'by_device_adc'){ + if(!in_array($key, $exclude_data_arr)){ + continue; + }else{ + $temporary_arr['value'] = explode(',',$result[$key])[0]; + } }else{ - $temporary_arr['value'] = explode(',',$result[$key])[0]; + if($key == 'un_fat_w_weight'){ + $temporary_arr['value'] = bcsub(explode(',',$result['weight'])[0],explode(',',$result['fat_w'])[0],2); + }else{ + $temporary_arr['value'] = explode(',',$result[$key])[0]; + } } }else{ $temporary_arr['value'] = explode(',',$result[$key])[0]; @@ -362,7 +493,6 @@ class Pagingcontrast extends Base{ // 数据对比 public function get_body_data_contrast($data){ - // dump($data); $data2 = [$data['before_id'],$data['after_id']]; $data3 = implode(',',$data2); $calculate_arr = []; @@ -384,18 +514,18 @@ class Pagingcontrast extends Base{ acbd.visceral, acbd.sfr, acbd.record_time, + acbd.record_type, REPLACE(CONVERT(varchar(10), acbd.record_time, 23), '-', '-') AS b_time, aud.nickname, aud.gender, aud.birthday, aud.head_pic - from app_card_body_data as acbd - left join app_user_data as aud on acbd.aud_id=aud.id + from ".$this->pagingcontrast_use_db_name['1']." as acbd + left join ".$this->pagingcontrast_use_db_name['4']." as aud on acbd.aud_id=aud.id where acbd.id in ($data3) and acbd.is_del = 0 "); - // dump($result); - // die; + if(!$result || count($result)<2){ return $this->msg(10004); } @@ -407,7 +537,7 @@ class Pagingcontrast extends Base{ $calculate_arr['after'] = $value; } } - $return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time']; + $return_data['time'] = $calculate_arr['before']['b_time'].'与'.$calculate_arr['after']['b_time']; $return_data['headimg'] = $calculate_arr['before']['head_pic']; $return_data['name'] = $calculate_arr['before']['nickname']; $return_data['gender'] = $calculate_arr['before']['gender']; @@ -415,13 +545,36 @@ class Pagingcontrast extends Base{ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); $return_data['list'] = []; - + // 处理如果没有阻抗的数据为0,显示异常start;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息 + if($calculate_arr['before']['record_type'] != 'by_device_adc' && $calculate_arr['after']['record_type'] != 'by_device_adc'){ + foreach ($calculate_arr['before'] as $key => $value) { + if(!in_array($key, ['height','weight','bmi'])){ + unset($calculate_arr['before'][$key]); + unset($calculate_arr['after'][$key]); + } + } + }else{ + foreach ($calculate_arr as $key => $value) { + if($value['record_type'] != 'by_device_adc'){ + $calculate_arr[$key]['fat_r'] = "0,异常"; + $calculate_arr[$key]['fat_w'] = "0,异常"; + $calculate_arr[$key]['muscle'] = "0,异常"; + $calculate_arr[$key]['muscleval'] = "0,异常"; + $calculate_arr[$key]['water'] = "0,异常"; + $calculate_arr[$key]['proteinval'] = "0,异常"; + $calculate_arr[$key]['bone'] = "0,异常"; + $calculate_arr[$key]['protein'] = "0,异常"; + $calculate_arr[$key]['kcal'] = "0,异常"; + $calculate_arr[$key]['visceral'] = "0,异常"; + $calculate_arr[$key]['sfr'] = "0,异常"; + } + } + } + // 处理如果没有阻抗的数据为0,显示异常end;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息 foreach ($calculate_arr['before'] as $key => $value) { if(in_array($key, ['height','weight','bmi','fat_r','fat_w','muscle','muscleval','water','proteinval','bone','protein','kcal','visceral','sfr'])){ $before_arr = explode(',', $value); $after_arr = explode(',', $calculate_arr['after'][$key]); - // $calculate_arr['before'][$key] = explode(',', $value); - array_push($return_data['list'], [ 'firstresult'=>[ 'color'=>'', @@ -447,7 +600,6 @@ class Pagingcontrast extends Base{ } // 数据对比 public function get_skip_data_contrast($data){ - // dump($data); $data2 = [$data['before_id'],$data['after_id']]; $data3 = implode(',',$data2); $calculate_arr = []; @@ -463,8 +615,8 @@ class Pagingcontrast extends Base{ aud.gender, aud.birthday, aud.head_pic - from app_card_skip_data as acsd - left join app_user_data as aud on acsd.aud_id=aud.id + from ".$this->pagingcontrast_use_db_name['2']." as acsd + left join ".$this->pagingcontrast_use_db_name['4']." as aud on acsd.aud_id=aud.id where acsd.id in ($data3) and acsd.is_del = 0 "); @@ -488,8 +640,6 @@ class Pagingcontrast extends Base{ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); $return_data['list'] = []; - // dump($calculate_arr); - // die; foreach ($calculate_arr['before'] as $key => $value) { if(in_array($key, ['jump_num','jump_time','jump_kcal'])){ $before_arr = $value; @@ -525,7 +675,6 @@ class Pagingcontrast extends Base{ } // 数据对比 public function get_vitalcapacity_data_contrast($data){ - // dump($data); $data2 = [$data['before_id'],$data['after_id']]; $data3 = implode(',',$data2); $calculate_arr = []; @@ -543,8 +692,8 @@ class Pagingcontrast extends Base{ aud.gender, aud.birthday, aud.head_pic - from app_card_vitalcapacity_data as acsd - left join app_user_data as aud on acsd.aud_id=aud.id + from ".$this->pagingcontrast_use_db_name['3']." as acsd + left join ".$this->pagingcontrast_use_db_name['4']." as aud on acsd.aud_id=aud.id where acsd.id in ($data3) and acsd.is_del = 0 "); @@ -568,8 +717,6 @@ class Pagingcontrast extends Base{ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); $return_data['list'] = []; - // dump($calculate_arr); - // die; foreach ($calculate_arr['before'] as $key => $value) { if(in_array($key, ['one_val','two_val','three_val','average_val','score_val'])){ $before_arr = $value; diff --git a/application/app/controller/Skip.php b/application/app/controller/Skip.php index 38bca8f..b5985b7 100644 --- a/application/app/controller/Skip.php +++ b/application/app/controller/Skip.php @@ -2,14 +2,17 @@ namespace app\app\controller; -use think\Controller; use think\Db; class Skip extends Base{ protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6']; - protected $curve_data_format = ['jump_num'=>['跳绳个数','个数/个','#009DFF'],'jump_time'=>['跳绳时长','时长/分','#009DFF'],'jump_kcal'=>['消耗卡路里','卡路里/kcal','#009DFF']]; - + protected $curve_data_format = ['jump_num'=>['跳绳个数','个','#009DFF'],'jump_time'=>['跳绳时长','分钟','#009DFF'],'jump_kcal'=>['消耗卡路里','kcal','#009DFF']]; + protected $skip_use_db_name = [ + '1'=>'app_card_skip_data', + '2'=>'app_user_data', + '3'=>'app_card_body_data', + ]; protected $result_end_data_mould = [ 'name'=>'', 'value'=>'', @@ -27,127 +30,230 @@ class Skip extends Base{ ################################################################接口################################################################ // 手动记录 public function skip_manual_recording($data = ['aud_id'=>'61','r_time'=>'2024-07-24','num'=>'369','time_m'=>'02','time_s'=>'42','type'=>'free','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('r_time', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['r_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'str')){ + return $this->msg(10005); + } + if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ + $return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); + } + if($data['num'] <= 0){ + $return_data = $this->msg(10005,'跳绳数不能小于等于0'); + } + if(abs($data['time_s']) >= 60){ + $return_data = $this->msg(10005,'秒钟值不能大于60'); + } + unset($data['token']); + if($this->validate_user_identity($data['aud_id']) === false){ + $return_data = $this->msg(10003); + } + $return_data = $this->skip_manual_recording_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - // dump(bcmul('1.23', '4.56', 2)); - // dump(bcround('18.777', 2)); - // // phpinfo(); - // // opcache_reset(); - // die; - - if(!array_key_exists('aud_id', $data) || !array_key_exists('r_time', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ - return $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); - } - if($data['num'] <= 0){ - return $this->msg(10005,'跳绳数不能小于等于0'); - } - if(abs($data['time_s']) >= 60){ - return $this->msg(10005,'秒钟值不能大于60'); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if($this->validate_user_identity($data['aud_id']) === false){ - return $this->msg(10003); - } - // die; - return $this->skip_manual_recording_action($data); + } // 设备记录记录 public function skip_manual_recording_device($data = ['aud_id'=>'58','num'=>'582','time_m'=>'10','time_s'=>'00','type'=>'free','kcal'=>'200','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('kcal', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['kcal'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'str')){ + return $this->msg(10005); + } + if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ + $return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); + } + if($data['num'] <= 0){ + $return_data = $this->msg(10005,'跳绳数不能小于等于0'); + } + if(abs($data['time_s']) >= 60){ + $return_data = $this->msg(10005,'秒钟值不能大于60'); + } + unset($data['token']); + if($this->validate_user_identity($data['aud_id']) === false){ + $return_data = $this->msg(10003); + } + $return_data = $this->skip_manual_recording_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('kcal', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ - return $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); - } - if($data['num'] <= 0){ - return $this->msg(10005,'跳绳数不能小于等于0'); - } - if(abs($data['time_s']) >= 60){ - return $this->msg(10005,'秒钟值不能大于60'); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if($this->validate_user_identity($data['aud_id']) === false){ - return $this->msg(10003); - } - return $this->skip_manual_recording_action($data); + } // 今日数据 public function skip_today_data($data = ['aud_id'=>'26','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->skip_today_data_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // dump($data); - // die; - return $this->skip_today_data_action($data); + } // 曲线 - public function skip_curve_chart($data = ['aud_id'=>'83','time'=>'2024-07-24','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function skip_curve_chart($data = ['aud_id'=>'9','time'=>'2024-10','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->skip_curve_chart_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->skip_curve_chart_action($data); + } // 删除历史数据 public function skip_del_record_data($data = ['id'=>'16','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $user_data = Db::table('app_card_skip_data')->where(['id'=>$data['id']])->update(['is_del'=>1]); - if($user_data){ - return $this->msg([]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $user_data = Db::table($this->skip_use_db_name['1'])->where(['id'=>$data['id']])->update(['is_del'=>1]); + if($user_data){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } ################################################################接口################################################################ ################################################################接口################################################################ ################################################################接口################################################################ ################################################################skip_manual_recording public function skip_manual_recording_action($data){ + // 分秒转换为秒 $data['time'] = abs($data['time_m'])*60+abs($data['time_s']); - $user_msg_content = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->count(); + $user_msg_content = Db::table($this->skip_use_db_name['2'])->where(['id'=>$data['aud_id']])->count(); if($user_msg_content<=0){ return $this->msg(10004); } if(!array_key_exists('kcal', $data)){ - $last_data_body = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc,id desc')->field('id,weight_val,record_time')->find(); + $last_data_body = Db::table($this->skip_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc,id desc')->field('id,weight_val,record_time')->find(); if(!$last_data_body){ - $last_data_body = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,weight as weight_val')->find(); + $last_data_body = Db::table($this->skip_use_db_name['2'])->where(['id'=>$data['aud_id']])->field('id,weight as weight_val')->find(); if(!$last_data_body){ return $this->msg(10004); } @@ -179,13 +285,13 @@ class Skip extends Base{ if(strlen($data_set['record_time']) <= 12){ $data_set['record_time'] = $this->addCurrentTimeToDateString($data_set['record_time']); } - $last_data_body = Db::table('app_card_skip_data')->insert($data_set); + $last_data_body = Db::table($this->skip_use_db_name['1'])->insert($data_set); $result = [ 'today_jump_num'=>0, 'today_jump_time'=>0, 'today_jump_kcal'=>0, ]; - $all_data = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); + $all_data = Db::table($this->skip_use_db_name['1'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); foreach ($all_data as $key => $value) { $result['today_jump_num'] = $result['today_jump_num']+$value['jump_num']; $result['today_jump_time'] = $result['today_jump_time']+$value['jump_time']; @@ -204,8 +310,8 @@ class Skip extends Base{ } ################################################################skip_today_data public function skip_today_data_action($data){ - $all_data = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); - $last_data = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->order('record_time desc,id desc')->field('id,jump_num,jump_time,jump_kcal,record_time')->find(); + $all_data = Db::table($this->skip_use_db_name['1'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); + $last_data = Db::table($this->skip_use_db_name['1'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc,id desc')->field('id,jump_num,jump_time,jump_kcal,record_time')->find(); $result = [ 'today_jump_num'=>0, 'today_jump_time'=>0, @@ -261,9 +367,7 @@ class Skip extends Base{ } // 使用查询构造器进行查询 - $result = Db::name('app_card_skip_data')->where($map)->field('jump_num,jump_time,jump_kcal,aud_id,record_time,jump_type,DATEPART(hour, record_time) AS hour,DATEPART(minute, record_time) AS minute,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); - // dump($result); - // die; + $result = Db::name($this->skip_use_db_name['1'])->where($map)->field('jump_num,jump_time,jump_kcal,aud_id,record_time,jump_type,DATEPART(hour, record_time) AS hour,DATEPART(minute, record_time) AS minute,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); $return_data = []; if(count($timeData) == 3){ $key_condition = 'hour'; @@ -272,7 +376,6 @@ class Skip extends Base{ }else if(count($timeData) == 1){ $key_condition = 'month'; } - // dump($key_condition); foreach ($this->curve_data_format as $key => $value) { $temporary_arr['title'] = $value[0].'('.$value[1].')'; $temporary_arr['key'] = $key; @@ -282,19 +385,9 @@ class Skip extends Base{ $temporary_arr['line']['series'][0]['data'] = []; foreach ($result as $k => $v) { if($key_condition == 'hour'){ - // 每一次的记录都添加进去 array_push($temporary_arr['line']['categories'],$result[$k]['hour'].':'.$result[$k]['minute']); array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]); - - // // 根据小时分组 - // if(in_array($result[$k][$key_condition].'时',$temporary_arr['line']['categories'])){ - // $num = array_search($result[$k][$key_condition].'时', $temporary_arr['line']['categories']); - // $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2); - // }else{ - // array_push($temporary_arr['line']['categories'],$result[$k][$key_condition].'时'); - // array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]); - // } }else if($key_condition == 'day'){ // 根据天分组 if(in_array($result[$k]['month'].'/'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){ @@ -316,11 +409,14 @@ class Skip extends Base{ } } } - // dump($temporary_arr); array_push($return_data,$temporary_arr); } foreach ($return_data[1]['line']['series'][0]['data'] as $key => $value) { + $return_data[1]['line']['series'][0]['data'][$key] = bcdiv($return_data[1]['line']['series'][0]['data'][$key],60,2); + // $jump_time_long = $this->handle_hour_branch_second($return_data[1]['line']['series'][0]['data'][$key]); + // $return_data[1]['line']['series'][0]['data'][$key] = $jump_time_long['h'].':'.$jump_time_long['m'].':'.$jump_time_long['s']; + } return $this->msg($return_data); } diff --git a/application/app/controller/Sportstesting.php b/application/app/controller/Sportstesting.php index 7c192b8..e859812 100644 --- a/application/app/controller/Sportstesting.php +++ b/application/app/controller/Sportstesting.php @@ -2,18 +2,19 @@ namespace app\app\controller; -use think\Controller; + use think\Db; -use app\bj\controller\Common; -use think\Log; -use \think\Validate; -use app\app\controller\Calculatebody; -use app\app\controller\Skip; + use Exception; class Sportstesting extends Base{ protected $color = ['#FF5656','#FF5656','#5AD06D','#6492F6','#3967D6']; + protected $sportstesting_use_db_name = [ + '1'=>'admin_estimate', + '2'=>'app_sportstesting_data', + '3'=>'app_user_data', + ]; protected $page_num = 10; protected $default_address = '上海'; protected $city_data_rule_name = [ @@ -35,561 +36,6 @@ class Sportstesting extends Base{ '4'=>'分钟秒钟(例1000米跑)', ]; - protected $city_data_rule2 = [ - '北京'=>[ - 'xc'=>[ - 'xc_1'=>[ - '1'=>[ - '1000米'=>[ - 'list'=>[ - '4:05'=>'8', - '4:11'=>'7.5', - '4:18'=>'7', - '4:26'=>'6.5', - '4:35'=>'6', - '4:45'=>'5.5', - '4:55'=>'5', - '5:01'=>'4.5', - '5:07'=>'4', - '5:13'=>'3.5', - '5:20'=>'3', - '5:27'=>'2.5', - '5:34'=>'2', - '5:42'=>'1.5', - '5:50'=>'1', - '5:59'=>'0.5', - '6:00'=>'0' - ], - 'unit'=>'分/秒', - 'value'=>'00:00', - 'proportion'=>'1', - 'type'=>'4', - ], - ], - '2'=>[ - '800米'=>[ - 'list'=>[ - '3:55'=>'8', - '4:01'=>'7.5', - '4:08'=>'7', - '4:16'=>'6.5', - '4:25'=>'6', - '4:35'=>'5.5', - '4:45'=>'5', - '4:49'=>'4.5', - '4:53'=>'4', - '4:57'=>'3.5', - '5:02'=>'3', - '5:07'=>'2.5', - '5:12'=>'2', - '5:19'=>'1.5', - '5:26'=>'1', - '5:35'=>'0.5', - '5:36'=>'0', - ], - 'unit'=>'分/秒', - 'value'=>'00:00', - 'proportion'=>'1', - 'type'=>'4', - ] - ], - ], - 'xc_2'=>[ - '1'=>[ - '引体向上'=>[ - 'list'=>[ - '11'=>'8', - '10'=>'7.5', - '9'=>'7', - '8'=>'6.5', - '7'=>'6', - '6'=>'5.5', - '5'=>'5', - '4'=>'4.5', - '3'=>'4', - '2'=>'3.5', - '1'=>'3' - ], - 'unit'=>'次', - 'value'=>'0', - 'proportion'=>'1', - 'type'=>'1', - ], - '双杠臂屈伸'=>[ - 'list'=>[ - '11'=>'8', - '10'=>'7.5', - '9'=>'7', - '8'=>'6.5', - '7'=>'6', - '6'=>'5.5', - '5'=>'5', - '4'=>'4.5', - '3'=>'4', - '2'=>'3.5', - '1'=>'3' - ], - 'unit'=>'次', - 'value'=>'0', - 'proportion'=>'1', - 'type'=>'1', - ], - ], - '2'=>[ - '斜身引体'=>[ - 'list'=>[ - '40'=>'8', - '36'=>'7.5', - '32'=>'7', - '28'=>'6.5', - '24'=>'6', - '20'=>'5.5', - '16'=>'5', - '12'=>'4.5', - '10'=>'4', - '9'=>'3.5', - '8'=>'3', - '7'=>'2.5', - '6'=>'2', - '5'=>'1.5', - '4'=>'1', - '3'=>'0.5', - '2'=>'0' - ], - 'unit'=>'次', - 'value'=>'0', - 'proportion'=>'1', - 'type'=>'1', - ], - '仰卧起坐'=>[ - 'list'=>[ - '42'=>'8', - '40'=>'7.5', - '37'=>'7', - '34'=>'6.5', - '30'=>'6', - '26'=>'5.5', - '22'=>'5', - '21'=>'4.5', - '20'=>'4', - '19'=>'3.5', - '18'=>'3', - '17'=>'2.5', - '16'=>'2', - '15'=>'1.5', - '14'=>'1', - '13'=>'0.5', - '12'=>'0' - ], - 'unit'=>'次', - 'value'=>'0', - 'proportion'=>'1', - 'type'=>'1', - ], - ], - ], - 'xc_3'=>[ - '1'=>[ - '足球运球/射门'=>['list'=>['19.5'=>'8','20.0'=>'7.5','20.5'=>'7','21.0'=>'6.5','21.5'=>'6','22.0'=>'5.5','22.5'=>'5','23.0'=>'4.5','23.8'=>'4','24.6'=>'3.5','25.4'=>'3','26.2'=>'2.5','27.0'=>'2','27.8'=>'1.5','28.6'=>'1','29.4'=>'0.5','29.5'=>'0'],'unit'=>'秒','value'=>'00.0','proportion'=>'1','type'=>'2',], - ], - '2'=>[ - '足球运球/射门'=>['list'=>['21.0'=>'8','21.5'=>'7.5','22.0'=>'7','22.5'=>'6.5','23.0'=>'6','23.5'=>'5.5','24.0'=>'5','24.5'=>'4.5','25.3'=>'4','26.1'=>'3.5','26.9'=>'3','27.7'=>'2.5','28.5'=>'2','29.3'=>'1.5','30.1'=>'1','30.9'=>'0.5','31.0'=>'0'],'unit'=>'秒','value'=>'00.0','proportion'=>'1','type'=>'2',], - ], - ], - 'xc_4'=>[ - '1'=>[ - '100米游泳'=>['list'=>['2:25'=>'6','2:35'=>'5.5','2:45'=>'5','2:55'=>'4.5','3:05'=>'4','3:15'=>'3.5','3:30'=>'3','3:40'=>'2.5','3:50'=>'2','4:00'=>'1.5','4:10'=>'1','4:20'=>'0.5','4:21'=>'0'],'unit'=>'分/秒','value'=>'00:00','proportion'=>'1','type'=>'4',], - ], - '2'=>[ - '100米游泳'=>['list'=>['2:40'=>'6','2:48'=>'5.5','2:56'=>'5','3:04'=>'4.5','3:12'=>'4','3:20'=>'3.5','3:30'=>'3','3:40'=>'2.5','3:50'=>'2','4:00'=>'1.5','4:10'=>'1','4:20'=>'0.5','4:21'=>'0'],'unit'=>'分/秒','value'=>'00:00','proportion'=>'1','type'=>'4',], - ], - ], - ], - 'gc'=>[ - 'gc_8_m'=>[ - '1'=>[ - 'BMI'=>['list'=>['15.6'=>'80','22.5'=>'100','25.2'=>'80','100'=>'60'],'unit'=>'','value'=>'0','proportion'=>'0.15','type'=>'2',], - '肺活量'=>['list'=>['3940'=>'100','3820'=>'95','3700'=>'90','3450'=>'85','3200'=>'80','3080'=>'78','2960'=>'76','2840'=>'74','2720'=>'72','2600'=>'70','2480'=>'68','2360'=>'66','2240'=>'64','2120'=>'62','2000'=>'60','1890'=>'50','1780'=>'40','1670'=>'30','1560'=>'20','1450'=>'10',],'unit'=>'ml','value'=>'0','proportion'=>'0.15','type'=>'1',], - '50米跑'=>[ - 'list'=>[ - '7.5'=>'100', - '7.6'=>'95', - '7.7'=>'90', - '7.8'=>'85', - '7.9'=>'80', - '8.1'=>'78', - '8.3'=>'76', - '8.5'=>'74', - '8.7'=>'72', - '8.9'=>'70', - '9.1'=>'68', - '9.3'=>'66', - '9.5'=>'64', - '9.7'=>'62', - '9.9'=>'60', - '10.1'=>'50', - '10.3'=>'40', - '10.5'=>'30', - '10.7'=>'20', - '10.9'=>'10', - ], - 'unit'=>'秒', - 'value'=>'00.0', - 'proportion'=>'0.2', - 'type'=>'2', - ], - '坐位体前屈'=>[ - 'list'=>[ - '19.6'=>'100', - '17.7'=>'95', - '15.8'=>'90', - '13.7'=>'85', - '11.6'=>'80', - '10.3'=>'78', - '9'=>'76', - '7.7'=>'74', - '6.4'=>'72', - '5.1'=>'70', - '3.8'=>'68', - '2.5'=>'66', - '1.2'=>'64', - '-0.1'=>'62', - '-1.4'=>'60', - '-2.6'=>'50', - '-3.8'=>'40', - '-5'=>'30', - '-6.2'=>'20', - '-7.4'=>'10', - ], - 'unit'=>'cm', - 'value'=>'00.0', - 'proportion'=>'0.1', - 'type'=>'3', - ], - '立定跳远'=>[ - 'list'=>[ - '240'=>'100', - '233'=>'95', - '226'=>'90', - '218'=>'85', - '210'=>'80', - '206'=>'78', - '202'=>'76', - '198'=>'74', - '194'=>'72', - '190'=>'70', - '186'=>'68', - '182'=>'66', - '178'=>'64', - '174'=>'62', - '170'=>'60', - '165'=>'50', - '160'=>'40', - '155'=>'30', - '150'=>'20', - '145'=>'10', - ], - 'unit'=>'cm', - 'value'=>'0', - 'proportion'=>'0.1', - 'type'=>'1', - ], - '引体向上'=>[ - 'list'=>[ - '14'=>'100', - '13'=>'95', - '12'=>'90', - '11'=>'85', - '10'=>'80', - '9'=>'76', - '8'=>'72', - '7'=>'68', - '6'=>'64', - '5'=>'60', - '4'=>'50', - '3'=>'40', - '2'=>'30', - '1'=>'20', - '0'=>'10', - ], - 'unit'=>'个', - 'value'=>'0', - 'proportion'=>'0.1', - 'type'=>'1', - 'add_point'=>[ - '10'=>'10', - '9'=>'9', - '8'=>'8', - '7'=>'7', - '6'=>'6', - '5'=>'5', - '4'=>'4', - '3'=>'3', - '2'=>'2', - '1'=>'1', - ] - ], - '男生1000米'=>[ - 'list'=>[ - '3:50'=>'100', - '3:55'=>'95', - '4:00'=>'90', - '4:07'=>'85', - '4:15'=>'80', - '4:20'=>'78', - '4:25'=>'76', - '4:30'=>'74', - '4:35'=>'72', - '4:40'=>'70', - '4:45'=>'68', - '4:50'=>'66', - '4:55'=>'64', - '5:00'=>'62', - '5:05'=>'60', - '5:25'=>'50', - '5:45'=>'40', - '6:05'=>'30', - '6:25'=>'20', - '6:45'=>'10', - ], - 'unit'=>'分/秒', - 'value'=>'00:00', - 'proportion'=>'0.2', - 'type'=>'4', - 'add_point'=>[ - '-35'=>'10', - '-32'=>'9', - '-29'=>'8', - '-26'=>'7', - '-23'=>'6', - '-20'=>'5', - '-16'=>'4', - '-12'=>'3', - '-8'=>'2', - '-4'=>'1', - ] - ], - ], - '2'=>[ - 'BMI'=>[ - 'list'=>[ - '15.2'=>'80', - '22.2'=>'100', - '24.8'=>'80', - '100'=>'60' - ], - 'unit'=>'', - 'value'=>'00.0', - 'proportion'=>'0.15', - 'type'=>'2', - ], - '肺活量'=>[ - 'list'=>[ - '2900'=>'100', - '2850'=>'95', - '2800'=>'90', - '2650'=>'85', - '2500'=>'80', - '2400'=>'78', - '2300'=>'76', - '2200'=>'74', - '2100'=>'72', - '2000'=>'70', - '1900'=>'68', - '1800'=>'66', - '1700'=>'64', - '1600'=>'62', - '1500'=>'60', - '1460'=>'50', - '1420'=>'40', - '1380'=>'30', - '1340'=>'20', - '1300'=>'10', - ], - 'unit'=>'ml', - 'value'=>'0', - 'proportion'=>'0.15', - 'type'=>'1', - ], - '50米跑'=>[ - 'list'=>[ - '8'=>'100', - '8.1'=>'95', - '8.2'=>'90', - '8.5'=>'85', - '8.8'=>'80', - '9'=>'78', - '9.2'=>'76', - '9.4'=>'74', - '9.6'=>'72', - '9.8'=>'70', - '10'=>'68', - '10.2'=>'66', - '10.4'=>'64', - '10.6'=>'62', - '10.8'=>'60', - '11'=>'50', - '11.2'=>'40', - '11.4'=>'30', - '11.6'=>'20', - '11.8'=>'10', - ], - 'unit'=>'秒', - 'value'=>'00.0', - 'proportion'=>'0.2', - 'type'=>'2', - ], - '坐位体前屈'=>[ - 'list'=>[ - '22.7'=>'100', - '21'=>'95', - '19.3'=>'90', - '17.6'=>'85', - '15.9'=>'80', - '14.6'=>'78', - '13.3'=>'76', - '12'=>'74', - '10.7'=>'72', - '9.4'=>'70', - '8.1'=>'68', - '6.8'=>'66', - '5.5'=>'64', - '4.2'=>'62', - '2.9'=>'60', - '2.1'=>'50', - '1.3'=>'40', - '0.5'=>'30', - '-0.3'=>'20', - '-1.1'=>'10', - ], - 'unit'=>'cm', - 'value'=>'00.0', - 'proportion'=>'0.1', - 'type'=>'3', - ], - '立定跳远'=>[ - 'list'=>[ - '240'=>'100', - '233'=>'95', - '226'=>'90', - '218'=>'85', - '210'=>'80', - '206'=>'78', - '202'=>'76', - '198'=>'74', - '194'=>'72', - '190'=>'70', - '186'=>'68', - '182'=>'66', - '178'=>'64', - '174'=>'62', - '170'=>'60', - '165'=>'50', - '160'=>'40', - '155'=>'30', - '150'=>'20', - '145'=>'10', - ], - 'unit'=>'cm', - 'value'=>'0', - 'proportion'=>'0.1', - 'type'=>'1', - ], - '一分钟仰卧起坐'=>[ - 'list'=>[ - '51'=>'100', - '49'=>'95', - '47'=>'90', - '44'=>'85', - '41'=>'80', - '39'=>'78', - '37'=>'76', - '35'=>'74', - '33'=>'72', - '31'=>'70', - '29'=>'68', - '27'=>'66', - '25'=>'64', - '23'=>'62', - '21'=>'60', - '19'=>'50', - '17'=>'40', - '15'=>'30', - '13'=>'20', - '11'=>'10', - ], - 'unit'=>'个', - 'value'=>'0', - 'proportion'=>'0.1', - 'type'=>'1', - 'add_point'=>[ - '13'=>'10', - '12'=>'9', - '11'=>'8', - '10'=>'7', - '9'=>'6', - '8'=>'5', - '7'=>'4', - '6'=>'3', - '4'=>'2', - '2'=>'1', - ] - ], - '女生800米'=>[ - 'list'=>[ - '3:30'=>'100', - '3:37'=>'95', - '3:44'=>'90', - '3:52'=>'85', - '4:00'=>'80', - '4:05'=>'78', - '4:10'=>'76', - '4:15'=>'74', - '4:20'=>'72', - '4:25'=>'70', - '4:30'=>'68', - '4:35'=>'66', - '4:40'=>'64', - '4:45'=>'62', - '4:50'=>'60', - '5:00'=>'50', - '5:10'=>'40', - '5:20'=>'30', - '5:30'=>'20', - '5:40'=>'10', - ], - 'unit'=>'分/秒', - 'value'=>'00:00', - 'proportion'=>'0.2', - 'type'=>'4', - 'add_point'=>[ - '-50'=>'10', - '-45'=>'9', - '-40'=>'8', - '-35'=>'7', - '-30'=>'6', - '-25'=>'5', - '-20'=>'4', - '-15'=>'3', - '-10'=>'2', - '-5'=>'1', - ] - ], - ], - ], - 'gc_8_r'=>[ - '1'=>[ - '机测'=>[ - 'list'=>[],'unit'=>'分','value'=>'0','proportion'=>'1','type'=>'1',], - ], - '2'=>[ - '机测'=>[ - 'list'=>[],'unit'=>'分','value'=>'0','proportion'=>'1','type'=>'1',], - ] - ] - ] - ], - ]; // 加 bcadd(,,20) // 减 bcsub(,,20) @@ -600,134 +46,278 @@ class Sportstesting extends Base{ ################################################################接口################################################################ // 获取单个类型列表 public function sportstesting_get_type_list($data = ['address'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('address', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['address'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_type_list_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('address', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->sportstesting_get_type_list_action($data); + } // 获取地区类型列表 - public function sportstesting_get_region_list($data = ['parameter_data'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function sportstesting_get_region_list($data = ['parameter_data'=>'河北,石家庄市','gender'=>'0']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('gender', $data) || !array_key_exists('parameter_data', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['parameter_data'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->sportstesting_get_region_list_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('gender', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->sportstesting_get_region_list_action($data); + } // 获取估分最后一次数据 public function sportstesting_get_last_data($data = ['aud_id'=>'83','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_last_data_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // cache('sportstesting_get_last_data',json_encode($data)); - return $this->sportstesting_get_last_data_action($data); + } // 计算并存储数据 public function sportstesting_set_once_data($data = ['aud_id'=>'83','parameter_data'=>'辽宁,沈阳市','result_data'=>'','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - // $data = json_decode(cache('sportstesting_set_once_data'),true); - // dump($data); - - // die; - // return $this->dayin_data('sportstesting_set_once_data'); - if(count(input('post.')) > 0){ - $data = input('post.'); - } - - if(!array_key_exists('aud_id', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('result_data', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if(is_array($data['result_data']) && !empty($data['result_data'])){ - // 是个数组且不为空数组 - foreach ($data['result_data'] as $key => $value) { - foreach ($value['list'] as $k => $v) { - if(count($v['list']) <= 0){ - return $this->msg(10010,$v['name'].'内并未选择内容'); - } - if($v['is_choice'] >= 0 && count($v['list']) < $v['is_choice']){ - return $this->msg(10010,$v['name'].'内并缺少选项,请选择'.$v['is_choice'].'个选项'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + + if(!array_key_exists('aud_id', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('result_data', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['parameter_data'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005); + } + if(is_array($data['result_data']) && !empty($data['result_data'])){ + // 是个数组且不为空数组 + foreach ($data['result_data'] as $key => $value) { + foreach ($value['list'] as $k => $v) { + if(count($v['list']) <= 0){ + return $this->msg(10010,$v['name'].'内并未选择内容'); + } + if($v['is_choice'] >= 0 && count($v['list']) < $v['is_choice']){ + return $this->msg(10010,$v['name'].'内并缺少选项,请选择'.$v['is_choice'].'个选项'); + } + foreach ($v['list'] as $c_k => $c_v) { + if(count($c_v) <= 0){ + return $this->msg(10010,$v['name'].'选项内内容异常'); + } + } } } + }else{ + return $this->msg(10006); } + unset($data['token']); + $return_data = $this->sportstesting_set_once_data_action2($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - cache('sportstesting_set_once_data',json_encode($data)); - // return $this->msg($data); - unset($data['token']); - // return $this->msg($data); - - return $this->sportstesting_set_once_data_action2($data); - // return $this->sportstesting_set_once_data_action($data); + } // 获取估分历史列表 public function sportstesting_get_all_list($data = ['aud_id'=>'25','page'=>'1','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data) || !array_key_exists('page', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_all_list_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data) || !array_key_exists('page', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // cache('sportstesting_get_all_list',json_encode($data)); - return $this->sportstesting_get_all_list_action($data); + } // 获取估分历史详情 public function sportstesting_get_one_details($data = ['id'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_one_details_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->sportstesting_get_one_details_action($data); + } // 获取估分已有的地区列表 public function sportstesting_get_city_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','type'=>'1']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('type', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_city_list_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('token', $data) || !array_key_exists('type', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->sportstesting_get_city_list_action($data); + } ################################################################业务################################################################ @@ -750,14 +340,9 @@ class Sportstesting extends Base{ // 全省地市一个规则start $db_condition = "province = '".$parameter_data[0]."'"; // 全省地市一个规则end - - $data = Db::table('admin_estimate')->where($db_condition)->find(); + $data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->find(); $data = json_decode($data['content'],true); - - // dump($data); - // die; $result = $this->handle_default_rule_list_content($data,$gender); - // die; return $this->msg($result); } ################################################sportstesting_get_region_list @@ -782,18 +367,18 @@ class Sportstesting extends Base{ $result['list'] = []; $result['total_score'] = 0; - $data = Db::table('admin_estimate')->where($db_condition)->select(); - // dump($data); - // die; + $data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->select(); + if(count($data) > 0){ if(count($data) > 1){ // 查到不止一条规则 return $this->msg(10004,'查询地址不够详细,请重新选择省市地区'); } - // dump(568); - // die; + $data = json_decode($data[0]['content'],true); $result = $this->handle_default_rule_list($data,$gender); + + // die; return $this->msg($result); }else{ return $this->msg(10004,'暂无该地区的估分规则,请选择其它地区'); @@ -802,7 +387,7 @@ class Sportstesting extends Base{ } ################################################sportstesting_get_last_data public function sportstesting_get_last_data_action($data){ - $user_data = Db::table('app_sportstesting_data')->where(['aud_id'=>$data['aud_id']])->order('id desc')->find(); + $user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->order('id desc')->find(); if($user_data){ $address = explode(',',$user_data['address']); @@ -816,20 +401,13 @@ class Sportstesting extends Base{ $result['area'] = count($address)>=3?$address[2]:''; return $this->msg($result); }else{ - $user_msg_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $user_msg_data = Db::table($this->sportstesting_use_db_name['3'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); if(!$user_msg_data){ return $this->msg(10004); } $address = $this->default_address; - // dump($address); - // die; - $address_data = $this->sportstesting_get_region_list_action(['parameter_data'=>$address,'gender'=>$user_msg_data['gender']]); - // dump(json_decode($address_data->getContent(),true)); - // dump(get_object_vars($address_data)); - // die; $address_data = json_decode($address_data->getContent(),true); - // return $this->msg($address_data); if($address_data['code'] == 10004){ return $this->msg(10004); } @@ -839,16 +417,13 @@ class Sportstesting extends Base{ $result['province'] = count($address)>=1?$address[0]:''; $result['city'] = count($address)>=2?$address[1]:''; $result['area'] = count($address)>=3?$address[2]:''; - return $this->msg($result); } } ################################################sportstesting_get_all_list public function sportstesting_get_all_list_action($data){ - $user_data_num = Db::table('app_sportstesting_data')->where(['aud_id'=>$data['aud_id']])->count(); - $user_data = Db::table('app_sportstesting_data')->where(['aud_id'=>$data['aud_id']])->page($data['page'],$this->page_num)->order('id desc')->select(); - // dump($user_data); - // die; + $user_data_num = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->count(); + $user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->page($data['page'],$this->page_num)->order('id desc')->field('id,create_time,score,max_score,address')->select(); if($user_data){ $result = []; $result['totalrows'] = $user_data_num; @@ -860,7 +435,7 @@ class Sportstesting extends Base{ array_push($result['rows'],[ 'id'=>$value['id'], 'create_time'=>$value['create_time'], - 'score'=>$value['score'], + 'score'=>$value['score'] == '.00'?"0":$value['score'], 'max_score'=>$value['max_score'], 'address'=>$value['address'], ]); @@ -872,7 +447,7 @@ class Sportstesting extends Base{ } ################################################sportstesting_get_one_details public function sportstesting_get_one_details_action($data){ - $user_data = Db::table('app_sportstesting_data')->where(['id'=>$data['id']])->find(); + $user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['id'=>$data['id']])->find(); if($user_data){ @@ -899,38 +474,32 @@ class Sportstesting extends Base{ } ################################################sportstesting_set_once_data public function sportstesting_set_once_data_action2($data){ - // $ceshi = [ - - // ]; + $return_result['total_score'] = 0; $return_result['max_score'] = 0; $parameter_data = explode(',',$data['parameter_data']); $gender = $data['gender']; if(count($parameter_data) == 1){ + // $db_condition = "province = '".$parameter_data[0]."'"; $db_condition = "province = '".$parameter_data[0]."'"; }else if(count($parameter_data) == 2){ - $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'"; + // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'"; + $db_condition = "province = '".$parameter_data[0]."'"; }else if(count($parameter_data) == 3){ - $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'"; + // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'"; + $db_condition = "province = '".$parameter_data[0]."'"; }else{ return $this->msg(10005); } - $find_data = Db::table('admin_estimate')->where($db_condition)->find(); + // 只根据省查找,全省一个标准 + $find_data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->find(); $find_data = json_decode($find_data['content'],true); $recognition_rule = $find_data[$gender]; - // dump($recognition_rule); - // // 测试用删掉s - // $data['result_data'] = $this->handle_default_rule_list2($find_data,$gender); - // // 测试用删掉e - // dump($data); - // return $this->msg(10010); foreach ($data['result_data'] as $key => $value) { // 遍历一级($value['key'] = 现场考试) - // dump($value); foreach ($value['list'] as $k2 => $v2) { // 遍历二级级($v2['key'] = 第一类项目 - // dump($v2); foreach ($v2['list'] as $k3 => $v3) { // 遍历二级级($v3['name'] = 1000米跑) $temporary_result = $this->obtaining_grades($recognition_rule[$value['key']][$v2['key']]['list'][$v3['name']]['content'],$v3); @@ -941,9 +510,8 @@ class Sportstesting extends Base{ } } } - // return $this->msg(999); $return_result['list'] = $data['result_data']; - $user_sportstesting_set = Db::table('app_sportstesting_data')->insert([ + $user_sportstesting_set = Db::table($this->sportstesting_use_db_name['2'])->insert([ 'aud_id'=>$data['aud_id'], 'content'=>json_encode($return_result['list']), 'score'=>$return_result['total_score'], @@ -973,7 +541,7 @@ class Sportstesting extends Base{ public function sportstesting_get_city_list_action($type){ if($type['type'] == '1'){ // 已有地区列表 - $data = Db::table('admin_estimate')->field('id,province,city,area')->select(); + $data = Db::table($this->sportstesting_use_db_name['1'])->field('id,province,city,area')->select(); $result = []; // 添加省份 foreach ($data as $key => $value) { @@ -1018,7 +586,7 @@ class Sportstesting extends Base{ } return $this->msg($result); }else if($type['type'] == '2'){ - $data = Db::table('admin_estimate')->where(['type' => '2'])->field('id,content,city,area')->find(); + $data = Db::table($this->sportstesting_use_db_name['1'])->where(['type' => '2'])->field('id,content,city,area')->find(); $result = json_decode($data['content'],true); return $this->msg($result); }else{ @@ -1042,9 +610,6 @@ class Sportstesting extends Base{ $secondsA = $sjA[1]; $minutesB = $sjB[0]; $secondsB = $sjB[1]; - // list($minutesA, $secondsA) = explode(':', $a); - // list($minutesB, $secondsB) = explode(':', $b); - // 转换为秒 $totalSecondsA = intval($minutesA) * 60 + intval($secondsA); $totalSecondsB = intval($minutesB) * 60 + intval($secondsB); @@ -1055,14 +620,19 @@ class Sportstesting extends Base{ }else{ return [false,$result]; } - // 比较两个时间(秒) - // return $totalSecondsB <= $totalSecondsA; } // 处理默认规则列表 public function handle_default_rule_list($data,$gender){ - $temporary_arr = $data[$gender]; + if($gender == 1){ + $temporary_arr = $data[$gender]; + }else{ + $temporary_arr = $data[2]; + } + + + // die; $result = []; foreach ($temporary_arr as $key => $value) { $num = array_push($result,['name'=>$key,'key'=>$key,'list'=>[]]); @@ -1091,8 +661,6 @@ class Sportstesting extends Base{ } } } - // dump($result); - // die; return $result; } // 获取所有选择项内容 @@ -1106,9 +674,7 @@ class Sportstesting extends Base{ $temporary_arr = []; $temporary_arr['key'] = $k2; $temporary_arr['list'] = []; - // dump($v2); foreach ($v2['list'] as $k3 => $v3) { - // dump($v3); array_push($temporary_arr['list'],[ 'name'=>$k3, 'proportion'=>$v3['proportion'], @@ -1120,7 +686,6 @@ class Sportstesting extends Base{ 'total_score'=>$v3['score'], ]); } - // dump($temporary_arr); array_push($result['list'],$temporary_arr); } } @@ -1135,10 +700,7 @@ class Sportstesting extends Base{ // 减 bcsub(,,20) // 乘 bcmul(,,20) // 除 bcdiv(,,20) - // dump($data); - // dump($rule); - // die; - if($data['value'] != ''){ + if($data['value'] != '' && $data['value'] != null && $data['value'] != '0' && $data['value'] != '0.0' && $data['value'] != '0.0' && $data['value'] != '0:00'){ if(count($rule) > 0){ foreach ($rule as $key => $value) { if($data['unit'] == '分/秒'){ @@ -1148,6 +710,7 @@ class Sportstesting extends Base{ $rule_result = $value[0]; $data_result = $data['value']; } + switch ($value[1]) { case "<=": $result = $data_result <= $rule_result; @@ -1171,9 +734,14 @@ class Sportstesting extends Base{ // 如果比较符号不是上述任何一个,可以抛出一个异常或错误 throw new Exception("Unsupported comparison operator: " . $value[1]); } - // dump($result); if($result == true){ - $data['score'] = $value[2]; + // 判断是不是0分 + if($data_result == 0){ + $data['score'] = 0; + }else{ + $data['score'] = $value[2]; + } + // 计算比例后分值 $proportional_post_score = bcmul($data['total_score'],$data['proportion'],2); $data['proportion_value'] = bcmul($data['score'],bcdiv($proportional_post_score,100,2),2); @@ -1185,7 +753,6 @@ class Sportstesting extends Base{ }else{ $data['score'] = $data['value'] <= $data['total_score']?bcmul(bcdiv($data['value'],$data['total_score'],20),100,2):100; // 计算比例后分值 - // $proportional_post_score = bcmul($data['total_score'],$data['proportion'],2); $data['proportion_value'] = $data['value'] <= $data['total_score']?$data['value']:$data['total_score']; } @@ -1203,8 +770,6 @@ class Sportstesting extends Base{ public function handle_default_rule_list2($data,$gender){ $temporary_arr = $data[$gender]; $result = []; - // dump($temporary_arr); - // die; foreach ($temporary_arr as $key => $value) { $num = array_push($result,['name'=>$key,'key'=>$key,'list'=>[]]); @@ -1227,9 +792,7 @@ class Sportstesting extends Base{ 'describe'=>$x_m_v['describe'], 'total_score'=>$x_m_v['score'], ]); - // dump($x_m_k); if($x_m_k == '1000米跑'){ - // dump('11'); $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '4:08'; }else if($x_m_k == '50米跑'){ $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '7.3'; @@ -1240,7 +803,6 @@ class Sportstesting extends Base{ }else if($x_m_k == '机考'){ $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '8.3'; }else if($x_m_k == '1000米'){ - // dump('22'); $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '4:08'; } // break; @@ -1260,7 +822,6 @@ class Sportstesting extends Base{ 'describe'=>$x_m_v['describe'], 'total_score'=>$x_m_v['score'], ]); - // dump($x_m_k); if($x_m_k == '1000米跑'){ $result[$num-1]['list'][$num2-1]['list'][0]['value'] = '4:07'; }else if($x_m_k == '50米跑'){ @@ -1285,9 +846,6 @@ class Sportstesting extends Base{ } } } - // dump($result); - // die; - // $result = json_encode($result); return $result; } diff --git a/application/app/controller/Vitalcapacity.php b/application/app/controller/Vitalcapacity.php index 524780b..03902ac 100644 --- a/application/app/controller/Vitalcapacity.php +++ b/application/app/controller/Vitalcapacity.php @@ -2,7 +2,6 @@ namespace app\app\controller; -use think\Controller; use think\Db; class Vitalcapacity extends Base{ @@ -17,7 +16,11 @@ class Vitalcapacity extends Base{ ['min_val'=>'10','max_val'=>'59','text'=>'不及格','color'=>'#FF5656'], ['min_val'=>'0','max_val'=>'9','text'=>'无效','color'=>'#FF5656'], ]; - + protected $vitalcapacity_use_db_name = [ + '1'=>'app_user_data', + '2'=>'app_card_vitalcapacity_data', + '3'=>'pc_vitalcapacity_standard', + ]; protected $result_end_data_mould = [ 'name'=>'', 'value'=>'', @@ -36,67 +39,134 @@ class Vitalcapacity extends Base{ ################################################################接口################################################################ // 手动数据记录 - public function vitalcapacity_save_record_data($data = ['aud_id'=>'83','one'=>'1523','two'=>'1825','three'=>'1896','time'=>'2024-07-23','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function vitalcapacity_save_record_data($data = ['aud_id'=>'11','one'=>'4900','two'=>'5100','three'=>'5300','time'=>'2024-11-14','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + unset($data['token']); + $data['one'] = $this->isPositiveNumber($data['one']) === false?0:$data['one']; + $data['two'] = $this->isPositiveNumber($data['one']) === false?0:$data['two']; + $data['three'] = $this->isPositiveNumber($data['one']) === false?0:$data['three']; + $return_data = $this->vitalcapacity_save_record_data_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $data['one'] = $this->isPositiveNumber($data['one']) === false?0:$data['one']; - $data['two'] = $this->isPositiveNumber($data['one']) === false?0:$data['two']; - $data['three'] = $this->isPositiveNumber($data['one']) === false?0:$data['three']; - return $this->vitalcapacity_save_record_data_action($data); + } // 设备数据记录 public function vitalcapacity_save_record_data_device($data = ['aud_id'=>'99','one'=>'1523','two'=>'1825','three'=>'1896','flow'=>'88.88','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('flow', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + unset($data['token']); + $data['one'] = $this->isPositiveNumber($data['one']) === false?0:$data['one']; + $data['two'] = $this->isPositiveNumber($data['one']) === false?0:$data['two']; + $data['three'] = $this->isPositiveNumber($data['one']) === false?0:$data['three']; + $return_data = $this->vitalcapacity_save_record_data_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('flow', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $data['one'] = $this->isPositiveNumber($data['one']) === false?0:$data['one']; - $data['two'] = $this->isPositiveNumber($data['one']) === false?0:$data['two']; - $data['three'] = $this->isPositiveNumber($data['one']) === false?0:$data['three']; - return $this->vitalcapacity_save_record_data_action($data); + } // 数据报告 public function vitalcapacity_data_report($data = ['aud_id'=>'83','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + unset($data['token']); + $return_data = $this->vitalcapacity_data_report_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->vitalcapacity_data_report_action($data); } // 曲线 public function vitalcapacity_curve_chart($data = ['aud_id'=>'83','time'=>'2024','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + unset($data['token']); + $return_data = $this->vitalcapacity_curve_chart_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->vitalcapacity_curve_chart_action($data); } ################################################################业务################################################################ @@ -115,41 +185,63 @@ class Vitalcapacity extends Base{ $temporary_arr['three_val'] = $data['three']; $temporary_arr['average_val'] = $temporary_arr['average']; $temporary_arr['flow_val'] = array_key_exists('flow', $data)?$data['flow']:'0.00'; + // die; // 处理记录时间 if(strlen($temporary_arr['record_time']) <= 12){ $temporary_arr['record_time'] = $this->addCurrentTimeToDateString($temporary_arr['record_time']); } - $user_msg = Db::name('app_user_data')->where(['id'=>$data['aud_id']])->field('grade,gender')->find(); + $user_msg = Db::name($this->vitalcapacity_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,grade,gender,birthday')->find(); + // die; if($user_msg){ // 根据性别&年级&年龄查规则 - if($user_msg['grade'] != 'nothing'){ - // 有年级项 - // 等级项(及格优秀良好等) - $achievement_judge_data = $this->vitalcapacity_achievement_judge(['average'=>$temporary_arr['average'],'grade'=>$user_msg['grade'],'gender'=>$user_msg['gender']]); - - $temporary_arr['score'] = $achievement_judge_data['score'].','.$achievement_judge_data['level'].','.$this->color[$achievement_judge_data['level']]; - $temporary_arr['score_val'] = $achievement_judge_data['score']; - // 获取肺活量标准 - - }else{ - $achievement_judge_data['level'] = "无"; - $temporary_arr['score'] = "0,无,无"; - $temporary_arr['score_val'] = "0"; + if($user_msg['grade'] == 'nothing'){ + // 计算年龄判断是属于哪个年级 + $user_age = $this->calculate_age($user_msg['birthday']); + if($user_age <= 7){ + $user_msg['grade'] = 'grade_s_1'; + }else if($user_age == 8){ + $user_msg['grade'] = 'grade_s_2'; + }else if($user_age == 9){ + $user_msg['grade'] = 'grade_s_3'; + }else if($user_age == 10){ + $user_msg['grade'] = 'grade_s_4'; + }else if($user_age == 11){ + $user_msg['grade'] = 'grade_s_5'; + }else if($user_age == 12){ + $user_msg['grade'] = 'grade_s_6'; + }else if($user_age == 13){ + $user_msg['grade'] = 'grade_m_1'; + }else if($user_age == 14){ + $user_msg['grade'] = 'grade_m_2'; + }else if($user_age == 15){ + $user_msg['grade'] = 'grade_m_3'; + }else if($user_age == 16){ + $user_msg['grade'] = 'grade_h_1'; + }else if($user_age == 17){ + $user_msg['grade'] = 'grade_h_2'; + }else if($user_age == 18){ + $user_msg['grade'] = 'grade_h_3'; + }else if($user_age == 19 || $user_age == 20){ + $user_msg['grade'] = 'grade_u_12'; + }else if($user_age >= 21){ + $user_msg['grade'] = 'grade_u_34'; + } } + $sql_str = "sex = ".$user_msg['gender']." and ".$user_msg['grade']." <= ".$temporary_arr['average_val']; + $user_achievement = Db::name($this->vitalcapacity_use_db_name['3'])->where($sql_str)->order($user_msg['grade'] .' desc')->field('level,score,'.$user_msg['grade'])->limit(1)->select(); + if(count($user_achievement)<=0){ + $user_achievement[0] = ['level'=>'无效','score'=>'0']; + } + $temporary_arr['score'] = $user_achievement[0]['score'].','.$user_achievement[0]['level'].','.$this->color[$user_achievement[0]['level']]; + $temporary_arr['score_val'] = $user_achievement[0]['score']; }else{ return $this->msg(10004); } - - $standard_data = $this->get_vitalcapacity_data($data['aud_id']); - // dump($standard_data); - // die; $temporary_arr['standard_data'] = json_encode($standard_data); - // dump($temporary_arr); - // die; - $result = Db::table('app_card_vitalcapacity_data')->insert($temporary_arr); + $result = Db::table($this->vitalcapacity_use_db_name['2'])->insert($temporary_arr); if($result){ $time = $result[0]['record_time']; @@ -157,7 +249,7 @@ class Vitalcapacity extends Base{ $time = date('Y年m月d日 H:i:s', $time); return $this->msg([ 'average'=>$temporary_arr['average'].'ml', - 'level'=>$achievement_judge_data['level'], + 'level'=>$user_achievement[0]['level'], 'time'=>$time, 'flow_val'=>$temporary_arr['flow_val'], 'list'=>$standard_data, @@ -170,7 +262,7 @@ class Vitalcapacity extends Base{ ################################################################vitalcapacity_data_report public function vitalcapacity_data_report_action($data){ - $result = Db::table('app_card_vitalcapacity_data')->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('record_time,score,average,flow_val,standard_data')->limit(1)->select(); + $result = Db::table($this->vitalcapacity_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('record_time,score,average,flow_val,standard_data')->limit(1)->select(); if(count($result) <= 0){ // return $this->msg(10004); @@ -191,8 +283,7 @@ class Vitalcapacity extends Base{ $o_l = explode(',',$result[0]['score']); // $standard_data = $this->get_vitalcapacity_data($data['aud_id']); $standard_data = json_decode($result[0]['standard_data'],true); - // dump($result); - // die; + return $this->msg([ 'average'=>$result[0]['average'].'ml', 'level'=>$o_l[1], @@ -225,14 +316,9 @@ class Vitalcapacity extends Base{ return $this->msg(10005); // 无效的时间数据格式 } - // dump($map); - // die; // 使用查询构造器进行查询 - $result = Db::name('app_card_vitalcapacity_data')->where($map)->field('id,one_val,two_val,three_val,average_val,score_val,aud_id,record_time,DATEPART(hour, record_time) AS hour,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); - // dump($map); - // dump($result); - // die; + $result = Db::name($this->vitalcapacity_use_db_name['2'])->where($map)->field('id,one_val,two_val,three_val,average_val,score_val,aud_id,record_time,DATEPART(hour, record_time) AS hour,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); $return_data = []; if(count($timeData) == 3){ $key_condition = 'hour'; @@ -241,9 +327,6 @@ class Vitalcapacity extends Base{ }else if(count($timeData) == 1){ $key_condition = 'month'; } - // dump($map); - // dump($key_condition); - // die; foreach ($this->curve_data_format as $key => $value) { $temporary_arr['title'] = $value[0].'('.$value[1].')'; $temporary_arr['key'] = $key; @@ -251,15 +334,8 @@ class Vitalcapacity extends Base{ $temporary_arr['line']['series'][0]['color'] = $value[2]; $temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')'; $temporary_arr['line']['series'][0]['data'] = []; - // dump($temporary_arr['title']); foreach ($result as $k => $v) { - // dump($k); - // if($result[$k][$key] == 26.43){ - // dump(123); - // } if($key_condition == 'hour'){ - // dump($result[$k][$key]); - // die; if(in_array($result[$k][$key_condition].'时',$temporary_arr['line']['categories'])){ $num = array_search($result[$k][$key_condition].'时', $temporary_arr['line']['categories']); @@ -270,7 +346,6 @@ class Vitalcapacity extends Base{ array_push($temporary_arr['line']['categories'],$result[$k][$key_condition].'时'); array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]); } - // dump($temporary_arr['line']['series'][0]['data']); }else if($key_condition == 'day'){ if(in_array($result[$k]['month'].'-'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){ $num = array_search($result[$k]['month'].'-'.$result[$k][$key_condition], $temporary_arr['line']['categories']); @@ -291,16 +366,8 @@ class Vitalcapacity extends Base{ } } } - // dump($temporary_arr); array_push($return_data,$temporary_arr); } - // dump($return_data); - // foreach ($return_data[1]['line']['series'][0]['data'] as $key => $value) { - // $return_data[1]['line']['series'][0]['data'][$key] = bcdiv($return_data[1]['line']['series'][0]['data'][$key],60,2); - // } - // // dump($temporary_arr); - // dump($return_data); - // die; return $this->msg($return_data); } @@ -313,24 +380,11 @@ class Vitalcapacity extends Base{ // 减 bcsub(,,20) // 乘 bcmul(,,20) // 除 bcdiv(,,20) - - // 肺活量成绩判断 - public function vitalcapacity_achievement_judge($data){ - $str = "sex = ".$data['gender']." and ".$data['grade']." <= ".$data['average']; - $user_achievement = Db::name('pc_vitalcapacity_standard')->where($str)->order($data['grade'] .' desc')->field('level,score,'.$data['grade'])->limit(1)->select(); - // dump($data); - // dump($user_achievement); - if(count($user_achievement)<=0){ - $user_achievement[0] = ['level'=>'无效','score'=>'0']; - } - // dump($user_achievement); - return $user_achievement[0]; - } // 肺活量判断区间 public function vitalcapacity_standard_interval($val,$data){ // 缓存一周 $result = ''; - if(count($data) <= 0){ + if(!$data || count($data) <= 0){ return $result; } $temporary_qj = $data; @@ -347,9 +401,15 @@ class Vitalcapacity extends Base{ } $num = count($temporary_qj)-1-$num; - $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2); - $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2); - + + if($max == 0){ + if($val >= $temporary_qj[0]['max_val']){ + $result = 100; + } + }else{ + $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2); + $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2); + } return $result; } // 肺活量判断区间(根据得分) @@ -371,22 +431,14 @@ class Vitalcapacity extends Base{ break; } } - // dump($data); - // dump($val); - // dump($max); - // dump($min); - // dump($num); - // 计算每份占比 $share_value = bcdiv($temporary_qj[0]['max_val'],count($temporary_qj),1); // 计算在这一段中占多少 $result = bcsub($val,$min,1); - // dump($result); $result = bcdiv($result,bcsub($max,$min,1),1); $num = count($temporary_qj)-1-$num; $num = bcmul($num,$share_value,1); $result = bcadd($num,$result,1); - // dump($share_value); // $num = count($temporary_qj)-1-$num; // $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2); // $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2); diff --git a/application/app/view/download/demo.html b/application/app/view/download/demo.html index 3b6977d..0fa6846 100644 --- a/application/app/view/download/demo.html +++ b/application/app/view/download/demo.html @@ -155,8 +155,9 @@ $('.ts').show() } else { console.log('当前不在微信环境中'); - if (isIOS()) { - console.log('当前是iOS设备'); + if (isIOS()) { + // alert('iOS设备不参与此次测试'); + // console.log('当前是iOS设备'); // 在这里执行iOS设备下的特定代码 window.location.href = "https://apps.apple.com/app/reedaw/id6654906497"; } else { diff --git a/application/app/view/download/demo2.html b/application/app/view/download/demo2.html index 2d9218f..2281ebf 100644 --- a/application/app/view/download/demo2.html +++ b/application/app/view/download/demo2.html @@ -44,31 +44,21 @@ font-size: 4vw; } .download{ - width: 40vw; - height: 10vw; - background-color: darkgray; - border-radius: 5vw; - text-align: center; - line-height: 10vw; - font-weight: bold; - text-decoration: none; - color: white; - margin-top: 10vw; + width: 60vw; + height: 12vw; + background: url('/download_img/download.png') no-repeat; + background-size: contain; } img{ - width: 25vw; - margin-bottom: 20vw; + width: 55vw; } .jump{ - width: 40vw; - height: 10vw; - color: white; - background-color: darkgray; - border-radius: 5vw; - text-align: center; - line-height: 10vw; - font-weight: bold; + width: 60vw; + height: 12vw; margin-bottom: 10vw; + margin-top: 12vw; + background: url('/download_img/open_wechat_app.png') no-repeat; + background-size: contain; } .ts{ width: 100vw; @@ -108,15 +98,53 @@ text-decoration: none; color: blue; } + .bouncing-button-container { + transform-origin: center bottom; /* 设置旋转的基点在底部中心 */ + animation: rotateAndRaise 2s ease-in-out forwards infinite; + } + @keyframes rotateAndRaise { + 0% { + transform: rotate(0deg) translateY(0); /* 初始状态,不旋转也不升高 */ + } + 10% { + transform: rotate(5deg); /* 初始状态,不旋转也不升高 */ + } + 20% { + transform: rotate(0deg) translateY(-50px); /* 50%时,旋转15°并升高50px */ + } + 30% { + transform: rotate(-5deg); /* 初始状态,不旋转也不升高 */ + } + 40% { + transform: rotate(0deg) translateY(0px); /* 结束状态,往右旋转30°并升高50px */ + } + 100% { + transform: rotate(0deg) translateY(0px); /* 结束状态,往右旋转30°并升高50px */ + } + } + .bottom_d{ + width: 100vw; + height: 65vw; + position: absolute; + bottom: 0; + left: 0; + background: url('/download_img/bottom.png') no-repeat; + background-position: bottom; + background-size: contain; + } + + +
    - -
    打开微信小程序
    -
    下载
    + +
    +
    +
    @@ -133,7 +161,7 @@ diff --git a/application/appbackups/controller/Base.php b/application/appbackups/controller/Base.php index a4fa4ca..1cb8e3c 100644 --- a/application/appbackups/controller/Base.php +++ b/application/appbackups/controller/Base.php @@ -6,12 +6,22 @@ use think\Controller; use think\Db; use think\Cache; use think\Log; +use PHPMailer\PHPMailer\PHPMailer; class Base extends Controller{ - protected $ceshiyong_token = ['caadd1be045a65f30b92aa805f1de54a','e0966788d02cc93290d9d674921d9715']; + protected $base_use_db_name = [ + '1'=>'app_data_log', + '2'=>'app_card_data', + '3'=>'app_user_data', + '4'=>'pc_vitalcapacity_standard', + '5'=>'admin_estimate', + '6'=>'app_account_number' + ]; + + protected $ceshiyong_token = ['57bd45e3a963b372ea2d873e4bd8d1f8','e0966788d02cc93290d9d674921d9715']; protected $base_call_method = ['内部']; - protected $token_time = 2592000;//30天的秒数 + protected $token_time = 30;//30天的秒数 protected $return_data_all = [ // '0' => ['success',[]], '10001'=>'关键参数缺失', @@ -20,11 +30,12 @@ class Base extends Controller{ '10004'=>'未找到有效数据', '10005'=>'参数格式错误', '10006'=>'参数不能为空', - '10007'=>'', + '10007'=>'参数错误', '10008'=>'', '10009'=>'', '10010'=>'自定义信息', '20001'=>'登录失效', + '99999'=>'网络异常,请稍后重试', ]; // 加 bcadd(,,20) // 减 bcsub(,,20) @@ -34,19 +45,25 @@ class Base extends Controller{ ################################################################接口################################################################ ################################################################接口################################################################ - // 操作记录留存 - // $data = ['aud_id'=>'xxxxxxxxxxxxxxx','order_list'=>[1,2,3,4,5]] - public function abnormal_data_log_action($dacall_methoda = 0,$content='未记录的内容',$use_database_name='未记录的数据库名'){ - $result = Db::table('app_data_log')->insert([ - 'create_time'=>date('Y-m-d H:i:s'), - 'call_method'=>$this->base_call_method[$dacall_methoda], - 'content'=>$content, - 'use_database_name'=>$use_database_name, - ]); + // 接口记录 + public function record_api_log($params, $error = null, $response = null){ + $logContent = "接口请求参数:" . json_encode($params, JSON_UNESCAPED_UNICODE) . PHP_EOL; + if ($error) { + $logContent .= "错误信息:" . $error['all_content'] . PHP_EOL; + if(!cache($error['flie']."_".$error['line'])){ + cache($error['flie']."_".$error['line'],"API错误",3600); + $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>$logContent]); + } + } + if ($response) { + $logContent .= "返回信息:" . json_encode($response, JSON_UNESCAPED_UNICODE) . PHP_EOL; + } + // 使用ThinkPHP的日志记录方法 + Log::record($logContent, 'api_log'); + } - // 检查变量是否是一个只有数字的一维数组 - public function is_num_array($array = [1,2,3],$type=1) { + public function is_num_array($array = [1,2,3]) { if (!is_array($array)) { return false; // 变量不是数组 } @@ -55,10 +72,8 @@ class Base extends Controller{ return false; // 数组中包含非数字元素 } } - if($type!=1){ - return true; - } - $result = Db::table('app_card_data')->where(['is_del'=>0])->cache(true,3600)->select();//查询结果缓存3600秒 + + $result = Db::table($this->base_use_db_name['2'])->where(['is_del'=>0])->cache(true,600)->select();//查询结果缓存3600秒 if(empty(array_diff($array, array_column($result, 'id')))){ return true;// 数组是一维的且只包含数字,且已经跟数据库比对过,每个数值都是有效 }else{ @@ -66,7 +81,7 @@ class Base extends Controller{ } } public function validate_user_identity($data) { - $validate_user = Db::table('app_user_data')->where(['id'=>$data])->count(); + $validate_user = Db::table($this->base_use_db_name['3'])->where(['id'=>$data])->count(); if($validate_user<=0){ return false; }else{ @@ -121,33 +136,58 @@ class Base extends Controller{ // 判断token是否过期 public function token_time_validate($token){ - // if(in_array($token,$this->ceshiyong_token)){ - // return true; - // } - // $time = cache($token); - // if($time === false){ - // Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token', 'log'); - // return false; - // } - // $diff_time = bcsub(time(),$time,0); - // if($diff_time > $this->token_time){ - // Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因当前时间戳减去记录时间戳后为'.$diff_time.'秒,大于规定秒数'.$this->token_time, 'log'); - // return false; - // } - // cache($token, time()); - // Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的秒数为'.time(), 'log'); - // return true; - - - if(cache($token) === false){ - Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token,或该token已经超过30天', 'log'); + // 591b70e0d80b5fa6d77e6e1384453ab9 + if(is_string($token)){ + + $length = strlen($token); + if ($length < 10 ) { + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,字符串长度小于10', 'token_log'); + return false; + } + }else{ + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,不是字符串', 'token_log'); return false; } - $time_now = date('Y-m-d H:i:s'); - cache($token,$time_now,$this->token_time); - Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.$time_now, 'log'); - return true; + $user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->field('id,login_time')->find(); + if(!$user_login){ + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,未找到用户token', 'token_log'); + return false; + } + + // 创建 DateTime 对象来表示指定的日期和时间 + $specifiedDateTime = new \DateTime($user_login['login_time']); + + // 获取当前时间的 DateTime 对象 + $currentDateTime = new \DateTime(); + + // 计算两个日期之间的差异(以秒为单位) + $interval = $currentDateTime->diff($specifiedDateTime); + + // 将差异转换为天数(注意:这里的天数可能不是整数,因为差异可能包括小时、分钟等) + $daysDifference = $interval->days; + + // 如果需要更精确的计算(包括小时、分钟等转换成的天数),可以使用以下方式: + // $totalSecondsDifference = $interval->format('%a') * 86400 + $interval->format('%h') * 3600 + $interval->format('%i') * 60 + $interval->format('%s'); + // $daysDifference = floor($totalSecondsDifference / 86400); // 将总秒数转换为天数并取整 + + // 判断差异是否超过指定的天数 + if ($daysDifference > $this->token_time) { + // echo "超过 {$specifiedDays} 天"; + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token,或该token已经超过30天', 'token_log'); + return false; + } else { + // echo "未超过 {$specifiedDays} 天"; + $user_login = Db::table($this->base_use_db_name['6'])->where(['token'=>$token])->update(['login_time'=>date('Y-m-d H:i:s')]); + if($user_login){ + Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.date('Y-m-d H:i:s'), 'token_log'); + return true; + }else{ + Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,数据库更新时间未成功', 'token_log'); + return true; + } + + } } // 计算天数 @@ -190,7 +230,10 @@ class Base extends Controller{ // 第一种:用户详情(所有数据都有) // 第二种:手动记录(只有最新体重) // 第三种:修改原始体重(只有原始体重) - // dump($data); + // $result_data['target_weight'] 目标体重 + // $result_data['initial_weight'] 最初体重 + // $result_data['weight'] 最近一次测量重量 + // $result_data['initial_date'] 初始体重日期 if(count($data) > 0){ $result_data['target_weight'] = $data['target_weight']; $result_data['initial_weight'] = $data['initial_weight']; @@ -202,7 +245,6 @@ class Base extends Controller{ $result_data['cumulative_weight'] = 0; $result_data['cumulative_day'] = 0; } - // dump($result_data); return $result_data; } @@ -240,7 +282,7 @@ class Base extends Controller{ ['min_val'=>'10','max_val'=>'59','text'=>'不及格','color'=>'#FF5656'], ['min_val'=>'0','max_val'=>'9','text'=>'无效','color'=>'#FF5656'], ]; - $grade = Db::table('app_user_data')->where(['id'=>$id])->field('id,grade,gender')->find(); + $grade = Db::table($this->base_use_db_name['3'])->where(['id'=>$id])->field('id,grade,gender')->find(); if(!$grade || $grade['grade'] == 'nothing'){ return []; } @@ -251,7 +293,7 @@ class Base extends Controller{ ".$grade['grade'].", ROW_NUMBER() OVER(PARTITION BY level ORDER BY ".$grade['grade']." ASC, id ASC) AS rn FROM - pc_vitalcapacity_standard + ".$this->base_use_db_name['4']." WHERE sex = ".$grade['gender']." ) @@ -263,10 +305,7 @@ class Base extends Controller{ RankedGrades WHERE rn = 1"; - // dump($sql_min); $result_min = Db::query($sql_min); - // dump($result_min); - // die; foreach ($result_min as $key => $value) { foreach ($standard_data as $sdk => $sdv) { if($value['level'] == $sdv['text']){ @@ -280,8 +319,6 @@ class Base extends Controller{ $standard_data[0]['max_val'] = '5140'; return $standard_data; } - - // 时间日期转换 public function addCurrentTimeToDateString($dateStr) { // 将日期字符串转换为DateTime对象 @@ -301,7 +338,7 @@ class Base extends Controller{ } // 处理分秒变秒 - function convertMinutesSecondsToStringSeconds($timeString) { + public function convertMinutesSecondsToStringSeconds($timeString) { // 分割字符串获取分钟和秒 list($minutes, $seconds) = explode(':', $timeString); // 将分钟和秒转换为秒 @@ -309,6 +346,35 @@ class Base extends Controller{ return $totalSeconds; } + // 转换数字"90.00", "88.11", "66.50", ".00"为正常数字 + public function convertStringToNumber($str) { + // 去除字符串两端的空格(如果有的话) + $str = trim($str); + + // 检查字符串是否为空或只包含小数点 + if ($str === '' || $str === '.') { + return 0; + } + + // 尝试将字符串转换为浮点数 + $number = (float)$str; + + // 格式化浮点数,去掉末尾多余的零 + $formattedNumber = rtrim(rtrim(sprintf('%.2f', $number), '0'), '.'); + + // 如果结果为空字符串(比如,原字符串是“.00”),则返回0 + if ($formattedNumber === '') { + return '0'; + } + // 返回结果,转换为整数如果小数点后没有数字 + if (strpos($formattedNumber, '.') === false) { + $formattedNumber = (int)$formattedNumber; + return "$formattedNumber"; + } + + return $formattedNumber; + } + // 时间加一或者减一 public function adjustDateTime($datetimeStr, $type) { // 将时间字符串转换为时间戳 @@ -350,6 +416,7 @@ class Base extends Controller{ } + // 发送一个PSOT请求 public function postRequest($url, $data = [], $headers = []) { $ch = curl_init(); // 初始化cURL会话 @@ -416,44 +483,135 @@ class Base extends Controller{ } + /* 接口说明(发邮件) + * $address(收件人的邮箱地址) 数组 格式: ['460834639@qq.com','460834639@qq.com'.......] + * $content(邮件的主题数据信息) 数组 格式:['title'=>'123','from_user_name'=>'123','content'=>'123'] + * $annex(附件路径信息) 字符串 + */ + public function send_email_api_error($address,$content,$annex=''){ + // $ad = '460834639@qq.com'; + $ad1 = '295155911@qq.com'; + $mail = new PHPMailer(); //实例化 + $mail->IsSMTP(); // 启用SMTP + $mail->Host = "smtp.126.com"; //SMTP服务器 163邮箱例子 + $mail->Port = 465; //邮件发送端口 + $mail->SMTPAuth = true; //启用SMTP认证 + $mail->SMTPSecure = 'ssl'; + $mail->CharSet = "UTF-8"; //字符集 + $mail->Encoding = "base64"; //编码方式 + $mail->Username = "tsf3920322@126.com"; //你的邮箱 + $mail->Password = "HLWXNRPUCTHJFIIX"; //你的密码(邮箱后台的授权密码) + $mail->From = "tsf3920322@126.com"; //发件人地址(也就是你的邮箱) + + // $mail->Subject = "微盟测试邮件"; //邮件标题 + $mail->Subject = $content['title']; //邮件标题 + + // $mail->FromName = "微盟体测中心"; //发件人姓名 + $mail->FromName = $content['from_user_name']; //发件人姓名 + + + for ($i=0; $i < count($address); $i++) { + $mail->AddAddress($address[$i], ""); //添加收件人(地址,昵称) + } + + if($annex != ''){ + // $url = ROOT_PATH. 'public' . DS . 'tsf' . DS .'demoooo.jpg'; + $mail->AddAttachment($annex,''); // 添加附件,并指定名称 + } + + $mail->IsHTML(true); //支持html格式内容 + + $neirong = $content['content']; + + $mail->Body = $neirong; //邮件主体内容 + //发送 + if (!$mail->Send()) { + + return ['code' => 10003,'msg'=>$mail->ErrorInfo]; + // return $mail->ErrorInfo; + } else { + return ['code' => 0]; + // return 'success'; + } + } + + + + // 验证是否字符串 + public function verify_data_is_ok($data = 2,$type){ + if($type == 'str'){ + if (is_string($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]); + return false; + } + }else if($type == 'num'){ + if (is_numeric($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]); + return false; + } + }else if($type == 'intnum'){ + $pattern = '/^\d+$/'; + if (preg_match($pattern, $data)) { + return true; // 匹配成功,返回 true + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]); + return false; // 匹配失败,返回 false + } + }else if($type == 'datetime'){ + $errors = \DateTime::getLastErrors(); // 获取上一次的解析错误 + $formats = ['Y-m-d','Y-m-d H:i:s']; + foreach ($formats as $format) { + $dateTime = \DateTime::createFromFormat($format, $data); + $newErrors = \DateTime::getLastErrors(); // 获取当前解析的错误 + // 检查是否有新的错误产生(即当前解析是否失败) + if ($dateTime && ($newErrors['warning_count'] == $errors['warning_count'] && $newErrors['error_count'] == $errors['error_count'])) { + // 如果没有新的错误,说明当前格式解析成功 + return true; + } + // 更新错误状态为当前解析的错误 + $errors = $newErrors; + } + // 如果所有格式都解析失败,则返回 false + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]); + return false; + }else if($type == 'other'){ + + } + + } + public function ceshiyong($aa = 4,$gd = 0.2){ - $token = 'caadd1be045a65f30b92aa805f1de54a'; - $jieguo = $this->token_time_validate($token); - // // // Log::record('用户尝试更新token时间,token:' . $token, 'log'); - // // // phpinfo(); - // // dump($jieguo); - // // // return $jieguo; - // // die; - // // cache($token, time()); - $time = cache($token); - dump($jieguo); - dump($time); - // // die; + $token = 'cd3f27cf4c4002170ea7bceeb723ac91'; + // dump(cache($token)); - - - - // $aa = 3; - // dump($aa/20); - $a = $aa; - for ($i=0; $i < 100; $i++) { - dump($a.'======='.$a/$aa*100); - $a = $a - $gd; - if($a < 0){ - break; + $data = Db::table('pc_bmistand2')->select(); + for ($i=0; $i < count($data); $i++) { + foreach ($data[$i] as $key => $value) { + $data[$i][$key] = str_replace(' ', '',$data[$i][$key]); + } + Db::table('pc_bmistand2')->where(['id'=>$data[$i]['id']])->update([ + 'month'=>$data[$i]['month'], + 'sex'=>$data[$i]['sex'], + // 'f3sd'=>$data[$i]['f3sd'], + // 'f2sd'=>$data[$i]['f2sd'], + 'f1sd'=>$data[$i]['f1sd'], + 'median'=>$data[$i]['median'], + 'z1sd'=>$data[$i]['z1sd'], + 'z2sd'=>$data[$i]['z2sd'], + // 'z3sd'=>$data[$i]['z3sd'], + ]); } - // $aa = 15; - // $a = 1; - // for ($i=0; $i < 100; $i++) { - // dump($aa.'======='.$aa/17.5*100); - // $aa = $aa - $a; - // if($aa < 1){ - // break; - // } - // } + dump('OK2'); + die; + // dump('ok'); + // $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>'123']); } diff --git a/application/appbackups/controller/Calculatebody.php b/application/appbackups/controller/Calculatebody.php index 14433fb..adc50bc 100644 --- a/application/appbackups/controller/Calculatebody.php +++ b/application/appbackups/controller/Calculatebody.php @@ -65,10 +65,7 @@ class Calculatebody extends Base{ 'adc'=>$data['adc'], 'gender'=>$data['gender'], ]; - // dump($temporary_parameter); - $request_result = $this->postRequest($url,$temporary_parameter); - // dump($request_result); $result['weight'] = $request_result['data']['weight']; $result['height'] = $request_result['data']['height']; $result['bmi'] = $request_result['data']['bmi']; @@ -89,8 +86,6 @@ class Calculatebody extends Base{ $result['bodyage'] = $request_result['data']['bodyage']; $result['lbm'] = $request_result['data']['lbm']; $result['body'] = $request_result['data']['body']; - // dump($result); - // die; // 使用接口调用之前的进行计算end $return_data['体重'] = $data['weight']; @@ -344,8 +339,6 @@ class Calculatebody extends Base{ $return_data['身体年龄'] = $result['bodyage']; - // dump($return_data); - // die; // $result_end['fat_r'] = $result['fat_r']; // $result_end['muscle'] = $result['muscle']; // $result_end['water'] = $result['water']; @@ -365,11 +358,7 @@ class Calculatebody extends Base{ // $result_end['lbm'] = $result['lbm']; // $result_end['weight'] = $result['weight']; // $result_end['height'] = $result['height']; - // dump($return_data); - // dump('========================================='); return $return_data; - // dump($result_end); - // die; } // 加 bcadd(,,20) @@ -387,10 +376,7 @@ class Calculatebody extends Base{ if (($weight <= 0) || ($weight > 220) || ($height <= 0) || ($height > 270) || ($age <= 0) || ($age > 120) || ($impedance <= 0) || ($impedance > 1000) || !in_array($gender, [1, 2])) { if ($weight != 0 && $height != 0) { // 计算BMI - // dump(bcmul($mheight, $mheight,20)); - // $bmi = bcmul(bcdiv($weight, bcmul($mheight, $mheight,20), 20), '10.0', 20); // 先算除法再算乘法 $bmi = bcdiv($weight, bcmul($mheight, $mheight,20), 2); - // $bmi = bcdiv($bmi, '10.0', 2); // 最后除以10,保留2位小数 $result_data['bmi'] = $bmi; $result_data['bone'] = 0; $result_data['muscle'] = 0; @@ -411,10 +397,6 @@ class Calculatebody extends Base{ return $result_data; } } - - // $num = bcmul(bcdiv($weight, bcmul($mheight, $mheight,20), 20), '10.0', 20); - // $num = bcdiv($num, '10.0', 2); // 确保最后结果也保留20位小数 - $num = intval(bcmul(bcdiv($weight,bcmul($mheight,$mheight,20),20),'10',20))/10; $num2 = 0.0; $num3 = 0.0; @@ -426,16 +408,9 @@ class Calculatebody extends Base{ $num9 = 0.0; $num10 = 0.0; $num11 = 0.0; - + // 根据男女计算脂肪率、脂肪量、肌肉率、肌肉量等等.... $standard_weight = 0.0; $standard_level = 0.0; - - - // dump($gender); - // 加 bcadd(,,20) - // 减 bcsub(,,20) - // 乘 bcmul(,,20) - // 除 bcdiv(,,20) if ($gender == 1){ // $num2 = 0.015 * $weight + (2.0 - 0.00055 * $impedance) * $height / 100 - 1.15; $num2 = bcsub(bcadd(bcmul('0.015',$weight,20),bcdiv(bcmul(bcsub('2.0',bcmul('0.00055',$impedance,20),20),$height,20),'100.0',20),20),'1.15',2); @@ -503,13 +478,11 @@ class Calculatebody extends Base{ $num3 = '75.0'; } // $result_data['muscle'] = ($num3 < 15.0) ? 15.0 : $num3; - // dump($num3); if(bccomp($num3, '15.0', 20) === -1){ $result_data['muscle'] = '15.00'; }else{ $result_data['muscle'] = $num3; } - // dump($num4); // $num4 = (($num4 > 70.0) ? 70.0 : $num4); if(bccomp($num4, '70.0', 20) === 1){ $num4 = '70.0'; @@ -530,7 +503,6 @@ class Calculatebody extends Base{ $result_data['fat_r'] = '5.00'; }else{ // $result_data['fat_r'] = $num5; - // dump($num5); $result_data['fat_r'] = substr($num5, 0, strpos($num5, ".") + 3); } // $result_data['sfr'] = $num6 <= 0 ? "0" : $num6; @@ -572,11 +544,9 @@ class Calculatebody extends Base{ $standard_level = bcdiv(bcsub($weight,$standard_weight,20),$standard_weight,2); // 加 bcadd(,,20) // 减 bcsub(,,20) - // dump($num11); if ($age < 18){ $num11 = $age; }else{ - // dump($num11); // $num11 = (($num11 > ($age + 10)) ? (($age + 10)) : $num11); if(bccomp($num11, $age + 10, 20) === 1){ $num11 = $age + 10; @@ -586,7 +556,6 @@ class Calculatebody extends Base{ $num11 = $age - 10; } } - // dump($age); $result_data['bodyage'] = $num11; $result_data['weight'] = $weight; @@ -595,13 +564,10 @@ class Calculatebody extends Base{ $result_data['adc'] = $impedance; $result_data['gender'] = $gender; $result_data['standard_level'] = $standard_level; - // dump($result_data); - // die; return $result_data; } // 计算脂肪率 function calculate_fat_r(){ - dump(123); } // 计算脂肪量 function calculate_zhifangliang(){ diff --git a/application/appbackups/controller/Card.php b/application/appbackups/controller/Card.php index c838a9d..01a620a 100644 --- a/application/appbackups/controller/Card.php +++ b/application/appbackups/controller/Card.php @@ -2,19 +2,25 @@ namespace app\app\controller; -use think\Controller; use think\Db; -use app\bj\controller\Common; -use think\Log; -use \think\Validate; use app\app\controller\Calculatebody; use app\app\controller\Cardparts; -use app\app\controller\Skip; class Card extends Base{ protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6']; - + protected $card_use_db_name = [ + '1'=>'app_card_body_data', + '2'=>'app_user_data', + '3'=>'pc_bmistand', + '4'=>'pc_heightstand', + '5'=>'pc_weightstand', + '6'=>'pc_childrenprescription', + '7'=>'pc_childprescriptionbyage', + '8'=>'pc_heightstand', + '9'=>'pc_weightstand', + '10'=>'pc_bmistand', + ]; protected $age_limit = 16; protected $unit_symbol = ['score'=>'分','height'=>'CM','weight'=>'公斤','bmi'=>'','fat_r'=>'%','fat_w'=>'kg','muscle'=>'%','muscleval'=>'kg','water'=>'kg','bone'=>'kg','protein'=>'%','proteinval'=>'kg','kcal'=>'kcal','visceral'=>'','sfr'=>'%',]; protected $unit_name = ['score'=>'身体得分','height'=>'身高','weight'=>'体重','bmi'=>'BMI','fat_r'=>'脂肪率','fat_w'=>'脂肪量','muscle'=>'肌肉率','muscleval'=>'肌肉量','water'=>'水分','bone'=>'骨重','protein'=>'蛋白率','proteinval'=>'蛋白量','kcal'=>'基础代谢','visceral'=>'内脏指数','sfr'=>'皮下脂肪','body_level'=>'肥胖等级','body_type'=>'身体类型']; @@ -71,9 +77,6 @@ class Card extends Base{ 'weight'=>['value'=>3,'list'=>['低'=>1,'偏低'=>1,'标准'=>2,'偏高'=>3,'高'=>3]], 'bmi'=>['value'=>2,'list'=>['消瘦'=>1,'正常'=>2,'偏重'=>3,'肥胖'=>4]], ]; - - - ################################################################接口################################################################ ################################################################接口################################################################ ################################################################接口################################################################ @@ -81,139 +84,224 @@ class Card extends Base{ // 详细卡片信息 // $data = ['id'=>'2'] - public function card_data_detailed($data=['aud_id'=>'87','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function card_data_detailed($data=['aud_id'=>'11','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->get_user_body_data($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->get_user_body_data($data); } // 曲线页面-曲线接口 - public function card_curve_chart($data = ['aud_id'=>'83','s_time'=>'2024-04-01','e_time'=>'2024-07-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function card_curve_chart($data = ['aud_id'=>'11','s_time'=>'2024-04-01','e_time'=>'2024-10-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + $return_data = $this->curve_chart_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // $data['s_time'] = $data['s_time'].' 00:00:00'; - // $data['e_time'] = $data['e_time'].' 23:59:59'; - return $this->curve_chart_action($data); + } // 手动记录 // $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1'] - public function card_manual_recording($data = ['aud_id'=>'83','time'=>'2024-07-24','height'=>'145.7','weight'=>'41.3','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - }else{ - $data['time'] = date('Y-m-d H:i:s'); + public function card_manual_recording($data = ['aud_id'=>'11','time'=>'2024-10-12','height'=>'155.7','weight'=>'46.7','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + }else{ + $data['time'] = date('Y-m-d H:i:s'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['height'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['weight'],'num')){ + return $this->msg(10005); + } + $data['acd_id'] = '2'; + $return_data = $this->set_user_body_data($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - // dump($data); - // die; - if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $data['acd_id'] = '2'; - return $this->set_user_body_data($data); + } // 设备记录 // $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1'] public function card_manual_recording_device($data = ['aud_id'=>'58','height'=>'175','weight'=>'68','adc'=>'550','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - }else{ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + }else{ + $data['time'] = date('Y-m-d H:i:s'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['height'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['weight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['adc'],'num')){ + return $this->msg(10005); + } + if($data['adc'] == 0){ + $data['adc'] = 550; + } $data['time'] = date('Y-m-d H:i:s'); + $data['acd_id'] = '2'; + $return_data = $this->set_user_body_data($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - // dump($data); - // die; - if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($data['adc'] == 0){ - $data['adc'] = 550; - } - $data['time'] = date('Y-m-d H:i:s'); - // if($this->token_time_validate($data['token']) === false){ - // return $this->msg(20001); - // } - // unset($data['token']); - $data['acd_id'] = '2'; - return $this->set_user_body_data($data); + } // 修改初始体重/目标体重 - public function card_modify_weight($data = ['aud_id'=>'25','weight'=>'25','type'=>1,'time'=>'','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function card_modify_weight($data = ['aud_id'=>'11','weight'=>'50','type'=>2,'time'=>'2024-10-01','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!is_array($data)){ + return $this->msg(10005); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('weight', $data) || !array_key_exists('type', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['weight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + if($data['type'] != 1){ + if(!$this->verify_data_is_ok($data['time'],'datetime')){ + return $this->msg(10005); + } + } + + $return_data = $this->modify_weight_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!is_array($data)){ - return $this->msg(10005); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('weight', $data) || !array_key_exists('type', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->modify_weight_action($data); } - // // 删除历史数据 - // public function card_del_record_data($data = ['id'=>'16','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - // if(count(input('post.')) > 0){ - // $data = input('post.'); - // } - // if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ - // return $this->msg(10001); - // } - // if($this->token_time_validate($data['token']) === false){ - // return $this->msg(20001); - // } - // unset($data['token']); - // $user_data = Db::table('app_card_body_data')->where(['id'=>$data['id']])->update(['is_del'=>1]); - // if($user_data){ - // return $this->msg([]); - // }else{ - // return $this->msg(10002); - // } - // } - - // // 数据对比 - // public function card_data_contrast($data = ['before_id'=>'24','after_id'=>'25','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - // if(count(input('post.')) > 0){ - // $data = input('post.'); - // } - // if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('token', $data)){ - // return $this->msg(10001); - // } - // if($this->token_time_validate($data['token']) === false){ - // return $this->msg(20001); - // } - // unset($data['token']); - // // $data = explode(',',$data['id_arr']); - // // dump($data); - // // die; - // return $this->body_data_contrast($data); - // } ################################################################业务接口################################################################ ################################################################业务接口################################################################ @@ -221,14 +309,6 @@ class Card extends Base{ ################################################card_data_detailed // 用户身体数据卡片获取 public function get_user_body_data($data){ - // $result = Db::table('app_card_body_data') - // ->alias('acbd') - // ->join('app_user_data aud','acbd.aud_id = aud.id','LEFT') - // ->where(['acbd.aud_id'=>$data['aud_id']]) - // ->order('acbd.record_time desc') - // ->field('acbd.*,aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date') - // ->find(); - // dump($data); $result = Db::query(" select Top 1 @@ -259,30 +339,22 @@ class Card extends Base{ acbd.bmi, acbd.body_age, aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date - from app_card_body_data as acbd - left join app_user_data as aud on acbd.aud_id=aud.id + from ".$this->card_use_db_name['1']." as acbd + left join ".$this->card_use_db_name['2']." as aud on acbd.aud_id=aud.id where acbd.aud_id='".$data['aud_id']."' order by acbd.record_time desc "); - // dump($result); - // die; if(!$result){ return $this->msg(10004); }else{ // $curve_bottom = $this->card_curve_target_action($result); $result_end = $this->processing_return_data_new($result[0]); - // dump($result_end); - // die; $cardparts = new Cardparts; - // dump($result_end); $result_end['gender'] = $result[0]['gender']; $result_end['record_time'] = $result[0]['record_time']; $result_end['score'] = $result_end['score']; $result_end['body_type'] = $result_end['body_type']; $result_end = $cardparts->conversion_interval($result_end); - // dump($result); - // dump($result_end); - // die; $result_end['cplist'] = $this->grow_up_recommendation([ 'birthday'=>$result[0]['birthday'], 'body'=>[ @@ -307,16 +379,11 @@ class Card extends Base{ } // 返回数据处理 public function processing_return_data_new($data){ - // dump($data); $result_end_data = []; $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']); $gender_val = $data['gender']; - // dump($data); - // dump($this->result_end_data_mould); - // die; foreach ($data as $key => $value) { if($key != 'aud_id' && $key != 'id' && $key != 'create_time' && $key != 'last_update_time' && $key != 'acd_id' && $key != 'ROW_NUMBER' && $key != 'record_time' && $key != 'gender' && $key != 'birthday'){ - // dump($key); // 设置单个数据格式 $result_end_data[$key] = $this->result_end_data_mould; if(array_key_exists($key, $this->unit_name)){ @@ -329,11 +396,7 @@ class Card extends Base{ if(strpos($value, ',')){ $result_end_data[$key]['standard'] = explode(',',$value)[1]; } - // dump($result_end_data[$key]); if(array_key_exists($key, $this->standard_color)){ - // dump($key); - // dump($result_end_data[$key]); - // dump($this->standard_color[$key]); if($result_end_data[$key]['standard'] != '异常'){ $result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']]; } @@ -343,9 +406,7 @@ class Card extends Base{ if(array_key_exists($key, $this->bhw_list)){ $result_end_data[$key]['list'] = $this->bhw_list[$key]; if($key == 'bmi'){ - // dump($month_num); - $bhw_date = Db::table('pc_bmistand')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); - // dump($bhw_date); + $bhw_date = Db::table($this->card_use_db_name['3'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f1sd']; $result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f1sd']; @@ -355,7 +416,7 @@ class Card extends Base{ $result_end_data[$key]['list'][3]['min_val'] = $bhw_date[0]['z2sd']; } }else if($key == 'height'){ - $bhw_date = Db::table('pc_heightstand')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + $bhw_date = Db::table($this->card_use_db_name['4'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd']; $result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd']; @@ -368,9 +429,7 @@ class Card extends Base{ $result_end_data[$key]['list'][4]['max_val'] = $bhw_date[0]['z3sd']; } }else if($key == 'weight'){ - $bhw_date = Db::table('pc_weightstand')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); - // dump($value); - // dump($bhw_date);/ + $bhw_date = Db::table($this->card_use_db_name['5'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $result_end_data[$key]['list'][0]['max_val'] = $bhw_date[0]['f2sd']; $result_end_data[$key]['list'][1]['min_val'] = $bhw_date[0]['f2sd']; @@ -387,10 +446,6 @@ class Card extends Base{ } } } - // $result_end_data['age'] = $data['age']; - // dump($data['age']); - // dump($result_end_data); - // die; return $result_end_data; } @@ -426,15 +481,14 @@ class Card extends Base{ $min_value = min($temporary_arr); $min_key = array_search($min_value,$temporary_arr); $type_num = $this->card_body_level[$min_key]['value']; - $temporary_arr2 = Db::table('pc_childrenprescription')->where(['Type'=>$type_num,'Level'=>$min_value,'IsDeleted'=>0])->field('Nutrition,Sport')->find(); - // dump($temporary_arr2); + $temporary_arr2 = Db::table($this->card_use_db_name['6'])->where(['Type'=>$type_num,'Level'=>$min_value,'IsDeleted'=>0])->field('Nutrition,Sport')->find(); array_push($result['nutritionlist'],$temporary_arr2['Nutrition']); array_push($result['sportlist'],$temporary_arr2['Sport']); // $result['nutritionlist'] = $temporary_arr2['Nutrition']; // $result['sportlist'] = $temporary_arr2['Sport']; $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']); - $temporary_arr2 = Db::table('pc_childprescriptionbyage')->where(['IsDeleted'=>0])->field('MinAge,MaxAge,Type,Content')->select(); + $temporary_arr2 = Db::table($this->card_use_db_name['7'])->where(['IsDeleted'=>0])->field('MinAge,MaxAge,Type,Content')->select(); $default_sleep = ''; $default_emotion = ''; foreach ($temporary_arr2 as $key => $value) { @@ -469,35 +523,17 @@ class Card extends Base{ // 曲线图动作函数 public function curve_chart_action($data){ $card_body_curve_arr = implode(',',$this->card_body_curve_arr); - // $user_data_list = Db::query(" - // select - // record_time, - // $card_body_curve_arr - // from app_card_body_data - // where aud_id='".$data['aud_id']."' - // and record_time between '".$data['s_time']."' - // and '".$data['e_time']."' - // order by record_time desc - // "); - // dump($card_body_curve_arr); - // dump($this->card_body_curve_arr); - // dump($data); - // $data['s_time'] = $this->adjustDateTime($data['s_time'],'subtract'); - // $data['e_time'] = $this->adjustDateTime($data['e_time'],'add'); - // dump($data); - // die; $data['s_time'] = $data['s_time'].' 00:00:00'; $data['e_time'] = $data['e_time'].' 23:59:59'; - $user_data_list = Db::table('app_card_body_data') + $user_data_list = Db::table($this->card_use_db_name['1']) ->where('aud_id', $data['aud_id']) ->whereTime('record_time', 'between', [$data['s_time'], $data['e_time']]) ->field("record_time,REPLACE(CONVERT(varchar(10), record_time, 23), '-', '-') AS b_time,$card_body_curve_arr") // ->field("record_time,REPLACE(CONVERT(varchar(10), record_time, 23), '-', '/') AS b_time,$card_body_curve_arr") ->order('record_time desc') ->select(); - // dump($user_data_list); // 下面业务逻辑是取每天的,最近后一次记录成绩 $data_arr = []; @@ -516,9 +552,6 @@ class Card extends Base{ array_push($record_arr2,$user_data_list[$key]); } } - // dump($record_arr1); - // dump($record_arr2); - // die; foreach ($this->card_body_curve_arr as $key => $value) { $temporary_arr = []; $temporary_arr['title'] = $this->card_body_curve_arr2[$key]; @@ -533,7 +566,6 @@ class Card extends Base{ array_push($data_arr,$temporary_arr); } } - // dump($data_arr); return $this->msg($data_arr); } @@ -542,12 +574,12 @@ class Card extends Base{ public function set_user_body_data($data){ $data['type'] = 1; - $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('birthday,gender,target_weight,initial_weight,initial_date')->find(); + $user_data = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->field('birthday,gender,target_weight,initial_weight,initial_date')->find(); if(!$user_data){ return $this->msg(10003); } if($user_data['initial_date'] == null){ - Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]); + Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update(['initial_weight'=>$data['weight'],'initial_date'=>$data['time']]); $target_current = $this->base_target_initial_cumulative_weight([ 'weight'=>$data['weight'], 'target_weight'=>$user_data['target_weight'], @@ -570,9 +602,9 @@ class Card extends Base{ $result_data['adc'] = $data['adc']; } $calculate_body_formula = new Calculatebody(); + // 计算身体数据 $get_body_value = $calculate_body_formula->calculate_body_data_result($result_data); - $get_body_value['gender'] = $user_data['gender']; $get_body_value['birthday'] = $user_data['birthday']; // 添加身高体重bmi的标尺标准 @@ -611,7 +643,7 @@ class Card extends Base{ $set_data['record_time'] = $this->addCurrentTimeToDateString($set_data['record_time']); } - $set_user_data = Db::table('app_card_body_data')->insert($set_data); + $set_user_data = Db::table($this->card_use_db_name['1'])->insert($set_data); if($set_user_data){ // 返回简要数据 if($data['type'] == 1){ @@ -631,16 +663,15 @@ class Card extends Base{ // 添加身高体重bmi的标准 public function hwb_standard($data){ - $linshi_data = []; $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']); - // dump($month_num); $gender_val = $data['gender']; if($data['age'] < $this->age_limit){ foreach ($data as $key => $value) { if($key =='身高'){ $linshi_data['身高'] = $this->bhw_list['height']; - $bhw_date = Db::table('pc_heightstand2')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + $bhw_date = Db::table($this->card_use_db_name['8'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + if($bhw_date){ $linshi_data['身高'][0]['max_val'] = $bhw_date[0]['f2sd']; $linshi_data['身高'][1]['min_val'] = $bhw_date[0]['f2sd']; @@ -652,9 +683,10 @@ class Card extends Base{ $linshi_data['身高'][4]['min_val'] = $bhw_date[0]['z2sd']; $linshi_data['身高'][4]['max_val'] = $bhw_date[0]['z3sd']; } + }else if($key =='体重'){ $linshi_data['体重'] = $this->bhw_list['weight']; - $bhw_date = Db::table('pc_weightstand2')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); + $bhw_date = Db::table($this->card_use_db_name['9'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $linshi_data['体重'][0]['max_val'] = $bhw_date[0]['f2sd']; $linshi_data['体重'][1]['min_val'] = $bhw_date[0]['f2sd']; @@ -668,8 +700,7 @@ class Card extends Base{ } }else if($key =='BMI'){ $linshi_data['BMI'] = $this->bhw_list['bmi']; - $bhw_date = Db::table('pc_bmistand2')->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); - // dump($bhw_date); + $bhw_date = Db::table($this->card_use_db_name['10'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); if($bhw_date){ $linshi_data['BMI'][0]['max_val'] = $bhw_date[0]['f1sd']; $linshi_data['BMI'][1]['min_val'] = $bhw_date[0]['f1sd']; @@ -680,10 +711,7 @@ class Card extends Base{ } } } - // dump($linshi_data); - // die; foreach ($linshi_data as $key => $value) { - // dump($value); foreach ($value as $k => $v) { if($data[$key] >= $v['min_val'] && $data[$key] < $v['max_val']){ // 如果落在区间内 @@ -704,10 +732,7 @@ class Card extends Base{ $data['体重2'] = $data['体重'].',无,无'; $data['BMI2'] = $data['BMI'].',无,无'; } - // dump($data); - // die; return $data; - // dump($data); } @@ -715,18 +740,16 @@ class Card extends Base{ public function modify_weight_action($data){ // $data['aud_id'] = 26; // $data['weight'] = 60; - // dump($data); - // die; $result = Db::query(" select TOP 1 - acbd.weight, + acbd.weight_val as weight, aud.target_weight, aud.initial_weight, aud.initial_date - from app_card_body_data as acbd - left join app_user_data as aud on acbd.aud_id = aud.id + from ".$this->card_use_db_name['1']." as acbd + left join ".$this->card_use_db_name['2']." as aud on acbd.aud_id = aud.id where acbd.aud_id = ".$data['aud_id']." order by acbd.record_time desc "); @@ -739,10 +762,7 @@ class Card extends Base{ }else{ return $this->msg(10005); } - $result_update = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update($bhw_date); - // dump($result_update); - // dump($result[0]['weight']); - // dump($result); + $result_update = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update($bhw_date); if($result_update){ $target_current = $this->base_target_initial_cumulative_weight([ @@ -751,8 +771,7 @@ class Card extends Base{ 'initial_weight'=>$data['type'] == 1?$result[0]['initial_weight']:$data['weight'], 'initial_date'=>$data['type'] == 1?$result[0]['initial_date']:$data['time'], ]); - // die; - // dump($target_current); + return $this->msg($target_current); }else{ return $this->msg(10002); diff --git a/application/appbackups/controller/Cardparts.php b/application/appbackups/controller/Cardparts.php index 048c153..b78d886 100644 --- a/application/appbackups/controller/Cardparts.php +++ b/application/appbackups/controller/Cardparts.php @@ -2,13 +2,6 @@ namespace app\app\controller; -use think\Controller; -use think\Db; -use app\bj\controller\Common; -use think\Log; -use \think\Validate; -use app\app\controller\Calculatebody; -use app\app\controller\Skip; class Cardparts extends Base{ @@ -181,8 +174,6 @@ class Cardparts extends Base{ // 除 bcdiv(,,20) // 计算部分内容的横线标准以及说明文字 public function conversion_interval($data){ - // dump($data); - // die; // $data['gender'] = $data['gender']==2?'woman':'man'; $gender = $data['gender']==2?'woman':'man'; $age = $data['age']['value']; @@ -203,9 +194,6 @@ class Cardparts extends Base{ // 使用 format 方法来指定新的日期和时间格式 $temporary_arr['record_time'] = $date_temporary->format('Y年m月d日 H:i:s'); - // dump($data); - // dump($temporary_arr); - // die; // 处理格式(顶部) foreach ($this->parameter_aggregate_top as $key => $value) { $data[$key]['key_name'] = $key; @@ -222,19 +210,14 @@ class Cardparts extends Base{ $data[$key]['desc'] = $value; array_push($temporary_arr['bottom_list'],$data[$key]); } - - // dump($temporary_arr); - // die; // 处理顶部list foreach ($temporary_arr['top_list'] as $key => $value) { if(count($temporary_arr['top_list'][$key]['list']) > 0){ $temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['top_list'][$key]['list'],$temporary_arr['top_list'][$key]['value'],$temporary_arr['top_list'][$key]['standard']); } } - // 处理底部list foreach ($temporary_arr['bottom_list'] as $key => $value) { - // dump($value['key_name']); // 脂肪率& if($value['key_name'] == 'fat_r'){ if($age < 30){ @@ -264,18 +247,15 @@ class Cardparts extends Base{ } // 肌肉率 else if($value['key_name'] == 'muscle'){ - // dump('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); $temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender]; // 处理异常 if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){ $temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]); } $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); - // dump($temporary_arr['bottom_list'][$key]); } // 肌肉量 else if($value['key_name'] == 'muscleval'){ - // dump('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); $temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender]; $temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']); // 处理异常 @@ -283,7 +263,6 @@ class Cardparts extends Base{ $temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]); } $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); - // dump($temporary_arr['bottom_list'][$key]); } // 水分 else if($value['key_name'] == 'water'){ @@ -323,7 +302,6 @@ class Cardparts extends Base{ $temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60']; } } - // dump($temporary_arr['bottom_list'][$key]); // 处理异常 if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){ $temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]); @@ -367,11 +345,6 @@ class Cardparts extends Base{ $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); } } - // dump($data['gender']); - // dump($data['age']['value']); - // // dump($temporary_arr['top_list']); - // dump($temporary_arr['bottom_list']); - // die; return $temporary_arr; } @@ -459,10 +432,6 @@ class Cardparts extends Base{ $temporary_arr = $data; } return $temporary_arr; - - // dump($data); - // dump($w); - // dump($k); } diff --git a/application/appbackups/controller/Cardpublic.php b/application/appbackups/controller/Cardpublic.php index f2b0753..672ef4e 100644 --- a/application/appbackups/controller/Cardpublic.php +++ b/application/appbackups/controller/Cardpublic.php @@ -2,18 +2,20 @@ namespace app\app\controller; -use think\Controller; use think\Db; -use app\bj\controller\Common; -use think\Log; -use \think\Validate; -use app\app\controller\Calculatebody; -use app\app\controller\Cardparts; -use app\app\controller\Skip; use Exception; class Cardpublic extends Base{ + protected $cardpublic_use_db_name = [ + '1'=>'app_user_data', + '2'=>'app_card_data_sub_item', + '3'=>'app_card_data_sub_item_data', + '4'=>'admin_estimate', + '5'=>'app_card_data' + ]; + + protected $curve_color = ['#f7b03e','#fb7b92','#ff9f40','#3fcba7',]; protected $level_data = [ ['min_val'=>'0','max_val'=>'59','text'=>'不及格','color'=>'#FB5755'], ['min_val'=>'60','max_val'=>'79','text'=>'及格','color'=>'#FCAE00'], @@ -21,63 +23,515 @@ class Cardpublic extends Base{ ['min_val'=>'90','max_val'=>'150','text'=>'优秀','color'=>'#6691EF'], ]; - // 示意接口 - public function card_curve_chart($data = ['aud_id'=>'83','s_time'=>'2024-04-01','e_time'=>'2024-07-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - } + // 获取卡片数据 - public function get_card_content($data = ['aud_id'=>'83','acd_id'=>'10','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // dump(111); - // die; - return $this->get_card_content_action($data); + public function get_card_content($data = ['aud_id'=>'11','acd_id'=>'16','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + // try { + // // 你的业务逻辑 + // $return_data = + // // 成功 + // $this->record_api_log($data, null, $return_data); + // return $return_data; + // } catch (\Exception $e) { + // // 捕获异常 + // $logContent["flie"] = $e->getFile(); + // $logContent["line"] = $e->getLine(); + // $logContent['all_content'] = "异常信息:\n"; + // $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + // $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + // $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + // $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + // $this->record_api_log($data, $logContent, null); + // return $this->msg(99999); + // } + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->get_card_content_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } + // {"acd_id":"11","name":"200米","record_time":"2024-09-27","data":"02:00","aud_id":"1","token":"57bd45e3a963b372ea2d873e4bd8d1f8","aan_id":"1"} // 存储信息 - public function data_save($data = ['aud_id'=>'83','acd_id'=>'10','name'=>'50米','data'=>'10.3','record_time'=>'2024-09-06','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('data', $data) || !array_key_exists('record_time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - - return $this->data_save_action($data); + public function data_save($data = ['aud_id'=>'11','acd_id'=>'16','name'=>'排球','data'=>'33','record_time'=>'2024-10-18']){ + // {"acd_id":"10","name":"1000米","record_time":"2024-10-18","data":"05:00","aud_id":"24","token":"6441bf7dabea7b3360a30240d3b19fc5","aan_id":"4"} + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('data', $data) || !array_key_exists('record_time', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['name'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['record_time'],'datetime')){ + return $this->msg(10005); + } + $return_data = $this->data_save_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取标签项目信息 - public function get_label_list($data = ['aud_id'=>'83','acd_id'=>'10','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + public function get_label_list($data = ['aud_id'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->get_label_list_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + + // 卡片运动曲线 + public function card_motion_curve($data = ['aud_id'=>'1','acd_id'=>'10','s_time'=>'2024-04-01','e_time'=>'2024-11-25','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->card_motion_curve_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + + // 数据对比-获取数据 + public function data_contrast_obtain_data($data = ['aud_id'=>'1','acd_id'=>'10','name'=>'1000米','s_time'=>'2024-04-01','e_time'=>'2024-10-03']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['name'],'str')){ + return $this->msg(10005); + } + $return_data = $this->data_contrast_obtain_data_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + // 数据对比-对比数据(暂时荒废) + public function data_contrast_contrast_data($data = ['before_id'=>'1','after_id'=>'3']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data)){ + return $this->msg(10001); + } + $return_data = $this->data_contrast_contrast_data_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + // 历史记录 + public function obtain_history_record($data = ['aud_id'=>'1','acd_id'=>'10','name'=>'1000米','page'=>'1']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['name'],'str')){ + return $this->msg(10005); + } + $return_data = $this->obtain_history_record_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + // 历史记录 + public function history_record_del($data = ['id'=>'10']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->history_record_del_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + // 获取手动记录内容 + public function obtain_manual_record_content($data = ['aud_id'=>11]){ if(count(input('post.')) > 0){ $data = input('post.'); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ + if(!array_key_exists('aud_id', $data)){ return $this->msg(10001); } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); } - return $this->get_label_list_action($data); + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + if(!$user_data){ + return $this->msg(10004); + } + + $card_data_c = Db::table($this->cardpublic_use_db_name['2']) + ->where(['is_del'=>0]) + ->field('id,name,type,unit,unit2,suit_gender,acd_id') + ->select(); + + $card_data_c2 = []; + foreach ($card_data_c as $key => $value) { + $temporary_arr = []; + $temporary_arr['id'] = $value['acd_id']; + $temporary_arr['height'] = false; + $temporary_arr['weight'] = false; + $temporary_arr['number'] = false; + $temporary_arr['time'] = false; + $temporary_arr['list'] = []; + $card_data_c2[$value['acd_id']] = $temporary_arr; + } + foreach ($card_data_c as $key => $value) { + if(in_array($user_data['gender'], explode(",", $value['suit_gender']))){ + $temporary_arr = []; + $temporary_arr['id'] = $value['id']; + $temporary_arr['name'] = $value['name']; + $temporary_arr['number'] = $value['unit2'] == '时长'?false:true; + $temporary_arr['type'] = $value['type']; + $temporary_arr['time'] = $value['unit2'] == '时长'?true:false; + $temporary_arr['describe'] = $value['unit2']; + $temporary_arr['unit'] = $value['unit'] == "分/秒"?'': $value['unit']; + array_push($card_data_c2[$value['acd_id']]['list'],$temporary_arr); + }else{ + continue; + } + + } + $card_data = [ + ['id'=>'2','height'=>true,'weight'=>true,'number'=>false,'time'=>false,'list'=>[]], + ['id'=>'6','height'=>false,'weight'=>false,'number'=>true,'time'=>true,'list'=>[]], + ]; + foreach ($card_data_c2 as $key => $value) { + array_push($card_data,$value); + } + // $card_data = [ + // ['id'=>'2','height'=>true,'weight'=>true,'number'=>false,'time'=>false,'list'=>[]], + // ['id'=>'6','height'=>false,'weight'=>false,'number'=>true,'time'=>true,'list'=>[]], + // [ + // 'id'=>'10', + // 'height'=>false, + // 'weight'=>false, + // 'number'=>false, + // 'time'=>false, + // 'list'=>[ + // [ + // 'id'=>'1', + // 'name'=>'1000米', + // 'number'=>false, + // 'type'=>4, + // 'time'=>true, + // 'describe'=>'时长', + // 'unit'=>'', + // ], + // [ + // 'id'=>'2', + // 'name'=>'800米', + // 'number'=>false, + // 'type'=>4, + // 'time'=>true, + // 'describe'=>'时长', + // 'unit'=>'', + // ], + // [ + // 'id'=>'3', + // 'name'=>'50米', + // 'number'=>true, + // 'type'=>2, + // 'time'=>false, + // 'describe'=>'时长', + // 'unit'=>'秒', + // ], + // ] + // ], + // [ + // 'id'=>'12', + // 'height'=>false, + // 'weight'=>false, + // 'number'=>false, + // 'time'=>false, + // 'list'=>[ + // [ + // 'id'=>'7', + // 'name'=>'立定跳远', + // 'number'=>true, + // 'type'=>1, + // 'time'=>false, + // 'describe'=>'距离', + // 'unit'=>'CM', + // ], + // ] + // ], + // [ + // 'id'=>'13', + // 'height'=>false, + // 'weight'=>false, + // 'number'=>false, + // 'time'=>false, + // 'list'=>[ + // [ + // 'id'=>'8', + // 'name'=>'引体向上', + // 'number'=>true, + // 'type'=>1, + // 'time'=>false, + // 'describe'=>'个数', + // 'unit'=>'个', + // ], + // [ + // 'id'=>'9', + // 'name'=>'1分钟仰卧起坐', + // 'number'=>true, + // 'type'=>1, + // 'time'=>false, + // 'describe'=>'个数', + // 'unit'=>'个', + // ], + // ] + // ], + // [ + // 'id'=>'14', + // 'height'=>false, + // 'weight'=>false, + // 'number'=>false, + // 'time'=>false, + // 'list'=>[ + // [ + // 'id'=>'10', + // 'name'=>'坐位体前屈', + // 'number'=>true, + // 'type'=>1, + // 'time'=>false, + // 'describe'=>'距离', + // 'unit'=>'CM', + // ], + // ] + // ], + // ]; + // if($user_data['gender'] == 1){ + // unset($card_data[2]['list'][1]);//800米 + // unset($card_data[4]['list'][1]);//仰卧起坐 + // }else if($user_data['gender'] == 2){ + // unset($card_data[2]['list'][0]);//1000米 + // unset($card_data[4]['list'][0]);//引体向上 + // } + // foreach ($card_data as $key => $value) { + // $card_data[$key]['list'] = array_values($card_data[$key]['list']); + // } + return $this->msg($card_data); } + @@ -86,13 +540,16 @@ class Cardpublic extends Base{ ##################################################get_card_content################################################## public function get_card_content_action($data){ + // 查找用户是存在 - $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find(); if(!$user_data){ return $this->msg(10004); } + // 卡片是否存在,以及是否含有子项 - $card_data_sub_item = Db::table('app_card_data_sub_item')->where("acd_id = ".$data['acd_id']." and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit')->select(); + $card_data_sub_item = Db::table($this->cardpublic_use_db_name['2'])->where("acd_id = ".$data['acd_id']." and is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit')->select(); + if(!$card_data_sub_item){ return $this->msg(10004); } @@ -124,14 +581,14 @@ class Cardpublic extends Base{ 'color' => '', 'offset' => '', 'unit_data' => '', + 'record_time' => '', ]; // 添加标签 array_push($return_data['label_list'],$value['name']); // 添加线性轴描述 $return_data['line_list'] = $this->level_data; // 查询最后一次成绩 - $data_this_time = Db::table('app_card_data_sub_item_data')->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id']])->order('id desc')->field('id,detailed_msg,achievement')->find(); - // dump($data_this_time); + $data_this_time = Db::table($this->cardpublic_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id'],'is_del'=>0])->order('record_time desc')->field('id,detailed_msg,achievement,record_time')->find(); if($data_this_time){ $data_this_time['detailed_msg'] = json_decode($data_this_time['detailed_msg'],true); // 设置基础数据 @@ -142,8 +599,9 @@ class Cardpublic extends Base{ $temporary_arr_c['color'] = $data_this_time['detailed_msg']['color']; $temporary_arr_c['offset'] = $data_this_time['detailed_msg']['offset']; $temporary_arr_c['unit_data'] = $data_this_time['detailed_msg']['unit_data']; + $temporary_arr_c['record_time'] = $data_this_time['record_time']; // 获取到该项所有数据 - $all_time_title = Db::table('app_card_data_sub_item_data')->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id']])->order('id desc')->field('id,achievement,LEFT(record_time,10) AS r_t')->select(); + $all_time_title = Db::table($this->cardpublic_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id'],'is_del'=>0])->order('id desc')->field('id,achievement,LEFT(record_time,10) AS r_t')->select(); // 处理今日,以及总计数据 if($data_this_time['detailed_msg']['unit_data'] == '分/秒'){ // 如果是分秒形式的数据 @@ -153,7 +611,6 @@ class Cardpublic extends Base{ // 处理本次数据最终格式 list($minutes, $seconds) = explode(':', $data_this_time['achievement']); $temporary_arr_c['this_time_value'] = $minutes . '分' . sprintf('%02d', $seconds) . '秒'; - // 计算今日总计&所有平均 $temporary_arr_c['all_times'] = count($all_time_title); foreach ($all_time_title as $k1 => $v1) { @@ -195,14 +652,14 @@ class Cardpublic extends Base{ public function data_save_action($data){ // 查找用户是存在 - $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); if(!$user_data){ return $this->msg(10004); } // 查找项目是否存在,以及获取项目信息 - $card_data_sub_item_data = Db::table('app_card_data_sub_item')->where("name = '".$data['name']."' and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit,acd_id')->find(); + $card_data_sub_item_data = Db::table($this->cardpublic_use_db_name['2'])->where("name = '".$data['name']."' and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit,acd_id')->find(); if(!$card_data_sub_item_data){ - return $this->msg(10004); + return $this->msg(10004,'1'); } // 如果项目数据类型为分秒格式 if($card_data_sub_item_data['type'] == 1){ @@ -217,12 +674,11 @@ class Cardpublic extends Base{ } }else if($card_data_sub_item_data['type'] == 2){ // 判断一个字符串是否为两位以内小数 - // dump($this->isTwoDecimalOrLess($data['data'])); if(!$this->isTwoDecimalOrLess($data['data'])){ return $this->msg(10005); } } - $score_all_data = $this->calculation_score($user_data['gender'],$data,$card_data_sub_item_data['type']); + $score_all_data = $this->calculation_score($user_data['gender'],$data,$card_data_sub_item_data['type'],$card_data_sub_item_data['unit']); $save_data = [ 'acd_id' => $card_data_sub_item_data['acd_id'], 'acdsi_id' => $card_data_sub_item_data['id'], @@ -235,7 +691,7 @@ class Cardpublic extends Base{ 'detailed_msg' => json_encode($score_all_data), ]; - $result = Db::table('app_card_data_sub_item_data')->insert($save_data); + $result = Db::table($this->cardpublic_use_db_name['3'])->insert($save_data); // $result = true; if($result){ if($save_data['unit'] == '分/秒'){ @@ -253,36 +709,181 @@ class Cardpublic extends Base{ ##################################################get_label_list################################################## public function get_label_list_action($data){ // 查找用户是存在 - $user_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find(); if(!$user_data){ return $this->msg(10004); } - $label_data = Db::table('app_card_data_sub_item')->where("acd_id = ".$data['acd_id']." and suit_gender LIKE '%".$user_data['gender']."%'")->field('name,unit,type')->select(); + $label_data = Db::table($this->cardpublic_use_db_name['2'])->where("is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,acd_id,name,unit,type')->select(); if(count($label_data)<=0){ return $this->msg(10004); } + $return_data = []; + $temporary_arr = []; foreach ($label_data as $key => $value) { - if($value['type'] == 1){ - $label_data[$key]['default_value'] = '0'; - }else if($value['type'] == 2){ - $label_data[$key]['default_value'] = '0.0'; - }else if($value['type'] == 4){ - $label_data[$key]['default_value'] = '0:00'; + if(!array_key_exists($value['acd_id'], $temporary_arr)){ + $temporary_arr[$value['acd_id']] = [$value['name']]; + }else{ + array_push($temporary_arr[$value['acd_id']],$value['name']); } - unset($label_data[$key]['ROW_NUMBER']); } - return $this->msg($label_data); + foreach ($temporary_arr as $key => $value) { + array_push($return_data,[ + 'acd_id'=>$key, + 'list'=>$value, + ]); + } + return $this->msg($return_data); } - + ##################################################card_motion_curve################################################## + public function card_motion_curve_action($data){ + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find(); + if(!$user_data){ + return $this->msg(10004); + } + $card_sub_item_data = Db::table($this->cardpublic_use_db_name['3'])->where(['acd_id'=>$data['acd_id'],'aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc')->field('id,acdsi_id,score,LEFT(record_time,10) as r_t,record_time')->select(); + $card_sub_item_type = Db::table($this->cardpublic_use_db_name['2'])->where("acd_id = ".$data['acd_id']." and is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,name,unit')->select(); + $temporary_arr = []; + $return_data = []; + // 处理一个临时数据 + foreach ($card_sub_item_type as $key => $value) { + $temporary_arr[$value['id']] = ['name'=>$value['name'],'unit'=>$value['unit'],'time'=>[],'data'=>[]]; + } + // 往临时数组内填入数据 + foreach ($card_sub_item_data as $key => $value) { + array_push($temporary_arr[$value['acdsi_id']]['time'],$value['r_t']); + array_push($temporary_arr[$value['acdsi_id']]['data'],$this->convertStringToNumber($value['score'])); + } + $num = 0; + foreach ($temporary_arr as $key => $value) { + if(($num+1) > count($this->curve_color)){ + $num = 0; + } + array_push($return_data,[ + 'title'=>$value['name'], + 'key'=>$value['name'], + 'line'=>[ + 'categories'=>$value['time'], + 'series'=>[ + [ + 'color'=>$this->curve_color[$num], + 'name'=>$value['name'], + 'data'=>$value['data'], + ] + ], + ], + ]); + $num = $num+1; + } + return $this->msg($return_data); + } + ##################################################data_contrast_obtain_data################################################## + public function data_contrast_obtain_data_action($data){ + // $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $card_data = Db::table($this->cardpublic_use_db_name['2'])->where(['acd_id'=>$data['acd_id'],'name'=>$data['name'],'is_del'=>0])->find(); + + $result_data = Db::table($this->cardpublic_use_db_name['3']) + ->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$card_data['id'],'is_del'=>0]) + ->whereTime('record_time', 'between', [$data['s_time'], $data['e_time']]) + ->field('id,achievement,score,unit,record_time') + ->order('record_time desc') + ->select(); + $return_data = []; + foreach ($result_data as $key => $value) { + if($value['unit'] == '分/秒'){ + $temporary_arr_e1 = explode(':', $value['achievement']); + $temporary_arr_e2 = explode('/', $value['unit']); + } + $temporary_arr = [ + "id"=> $value['id'], + // "v1"=> $value['achievement'].$value['unit'], + "v1"=> $value['unit'] == '分/秒'?$temporary_arr_e1[0].$temporary_arr_e2[0].$temporary_arr_e1[1].$temporary_arr_e2[1]:$value['achievement'].$value['unit'], + "v2"=> $this->convertStringToNumber($value['score']).'分', + "v1_name"=> "成绩", + "v2_name"=> "得分", + "r_t"=> substr($value['record_time'], 0, 10) + ]; + array_push($return_data,$temporary_arr); + } + return $this->msg($return_data); + } + ##################################################data_contrast_contrast_data################################################## + public function data_contrast_contrast_data_action($data){ + + $tj = "id IN (".$data['before_id'].",".$data['after_id'].")"; + + $card_data = Db::table($this->cardpublic_use_db_name['3'])->where($tj)->select(); + if(count($card_data)<2){ + return $this->msg(10004); + } + if($card_data[0]['acdsi_id'] != $card_data[1]['acdsi_id']){ + return $this->msg(10003); + } + + } + ##################################################obtain_history_record################################################## + public function obtain_history_record_action($data){ + $card_data = Db::table($this->cardpublic_use_db_name['2'])->where(['acd_id'=>$data['acd_id'],'name'=>$data['name'],'is_del'=>0])->find(); + $result_count = Db::table($this->cardpublic_use_db_name['3']) + ->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$card_data['id'],'is_del'=>0]) + ->count(); + $result_data = Db::table($this->cardpublic_use_db_name['3']) + ->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$card_data['id'],'is_del'=>0]) + ->field('id,achievement,score,unit,record_time') + ->order('record_time desc') + ->page($data['page'].",10") + ->select(); + + $return_data = [ + 'totalrows'=>$result_count, + 'rows'=>[], + 'pagenow'=>$data['page'], + 'pagesize'=>10, + 'totalpage'=>ceil($result_count/10), + ]; + foreach ($result_data as $key => $value) { + $temporary_arr = []; + if($value['unit'] == '分/秒'){ + $temporary_arr_e1 = explode(':', $value['achievement']); + $temporary_arr_e2 = explode('/', $value['unit']); + } + $temporary_arr = [ + "id"=> $value['id'], + // "v1"=> $value['achievement'].$value['unit'], + "v1"=> $value['unit'] == '分/秒'?$temporary_arr_e1[0].$temporary_arr_e2[0].$temporary_arr_e1[1].$temporary_arr_e2[1]:$value['achievement'].$value['unit'], + "v2"=> $this->convertStringToNumber($value['score']).'分', + "v1_name"=> "成绩", + "v2_name"=> "得分", + "record_time"=> $value['record_time'] + ]; + array_push($return_data['rows'],$temporary_arr); + } + + return $this->msg($return_data); + } + ##################################################history_record_del################################################## + public function history_record_del_action($data){ + $result_count = Db::table($this->cardpublic_use_db_name['3']) + ->where(['id'=>$data['id']]) + ->update(['is_del'=>1]); + if($result_count){ + return $this->msg([]); + }else{ + return $this->msg(10002); + } + } + + + + + ################################################################tool################################################################ ################################################################tool################################################################ // 计算得分成绩以及线性进度 - public function calculation_score($gender,$data,$type){ - // $card_name['card_name'] = ; + public function calculation_score($gender,$data,$type,$unit_msg){ $card_name['project_name'] = $data['name']; $card_name['score'] = 0; $card_name['offset'] = 0; @@ -291,7 +892,7 @@ class Cardpublic extends Base{ // 计算得分 // 获取评分细则 - $estimate = Db::table('admin_estimate')->where(['type'=>3])->find(); + $estimate = Db::table($this->cardpublic_use_db_name['4'])->where(['type'=>3])->find(); $estimate = json_decode($estimate['content'],true); // 根据男女循环出项目细则 @@ -307,7 +908,7 @@ class Cardpublic extends Base{ } } foreach ($card_name['rule']['content'] as $key => $value) { - if($type == '分/秒'){ + if($type == '4'){ $rule_result = $this->convertMinutesSecondsToStringSeconds($value[0]); $data_result = $this->convertMinutesSecondsToStringSeconds($data['data']); }else{ @@ -337,33 +938,42 @@ class Cardpublic extends Base{ // 如果比较符号不是上述任何一个,可以抛出一个异常或错误 throw new Exception("Unsupported comparison operator: " . $value[1]); } + if($result == true){ $card_name['score'] = $value[2]; - if($value[2] < 100){ - $card_name['offset'] = $value[2]; - }else{ - $card_name['offset'] = 100; - } - // $card_name['offset'] = bcdiv($value[2],$card_name['diagram'][count($card_name['diagram'])-1]['max_val'],0); break; } } + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) foreach ($describe_list as $key => $value) { if($card_name['score'] >= $value['min_val'] && $card_name['score'] <= $value['max_val']){ $card_name['standard'] = $value['text']; $card_name['color'] = $value['color']; + if($card_name['score'] < 100){ + // 计算当前区间内的比值() + $card_name['offset'] = bcmul(bcdiv(bcsub($card_name['score'],$value['min_val'],20),bcsub($value['max_val'],$value['min_val'],20),4),25,2); + // 计算全线性下比值 + $card_name['offset'] = bcadd($card_name['offset'],bcmul(($key),25,0),0); + }else{ + $card_name['offset'] = '100'; + } break; } } $card_name['max_score'] = $card_name['rule']['content'][0][2]; $card_name['describe'] = $card_name['rule']['describe']; - $card_name['unit_data'] = $card_name['rule']['unit_data']; + $card_name['unit_data'] = $unit_msg; // $card_name['default_data_format'] = $card_name['rule']['value']; // $card_name['default_data_type'] = $card_name['rule']['type']; // $card_name['list'] = $describe_list; + unset($card_name['rule']); + return $card_name; } diff --git a/application/appbackups/controller/Device.php b/application/appbackups/controller/Device.php index cfc35be..635fb05 100644 --- a/application/appbackups/controller/Device.php +++ b/application/appbackups/controller/Device.php @@ -9,6 +9,11 @@ use think\Log; class Device extends Base{ protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6']; + protected $device_use_db_name = [ + '1'=>'app_device_data', + '2'=>'app_account_number', + '3'=>'app_device_code_data', + ]; ################################################################接口################################################################ @@ -17,79 +22,179 @@ class Device extends Base{ // 获取系统设备列表 public function device_data_list($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->device_data_list_action($data); + + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + $return_data = $this->device_data_list_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 绑定系统设备 public function device_binding($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','device_id'=>'3','device_mac'=>'54654654']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data) || !array_key_exists('device_id', $data) || !array_key_exists('device_mac', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->device_binding_action($data); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('device_id', $data) || !array_key_exists('device_mac', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['device_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['device_mac'],'str')){ + return $this->msg(10005); + } + $return_data = $this->device_binding_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取用户设备列表 public function device_user_data_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->device_user_data_list_action($data); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->device_user_data_list_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 解绑系统设备 public function device_unbinding($data = ['token'=>'e0966788d02cc93290d9d674921d9715','id'=>'8']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->device_unbinding_action($data); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->device_unbinding_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取设备详情 public function device_mac_get_content($data = ['mac'=>'76:FE:B3:2F:E7:D8','acd_id'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('mac', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - return $this->device_mac_get_content_action($data); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('mac', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['mac'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->device_mac_get_content_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } ################################################################业务接口################################################################ @@ -97,7 +202,7 @@ class Device extends Base{ ################################################device_data_list public function device_data_list_action($data){ - $result = Db::table('app_device_data')->where(['is_del'=>0])->field('id,name,pic,content,page_measure,bluetooth_type,device_model')->select(); + $result = Db::table($this->device_use_db_name['1'])->where(['is_del'=>0])->field('id,name,pic,content,page_measure,bluetooth_type,device_model')->select(); foreach ($result as $key => $value) { unset($result[$key]['ROW_NUMBER']); } @@ -110,11 +215,11 @@ class Device extends Base{ ################################################device_binding public function device_binding_action($data){ - $result_user = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find(); + $result_user = Db::table($this->device_use_db_name['2'])->where(['token'=>$data['token']])->field('id,token')->find(); if(!$result_user){ return $this->msg(10003); } - $device_code_data = Db::table('app_device_code_data')->where(['machine_code'=>$data['device_mac']])->find(); + $device_code_data = Db::table($this->device_use_db_name['3'])->where(['machine_code'=>$data['device_mac']])->find(); $device_code_data_user = explode(',',$device_code_data['bind_account_id']); if($device_code_data){ // 多用户可以绑定 @@ -122,7 +227,7 @@ class Device extends Base{ return $this->msg(10003,'设备已绑定'); }else{ array_push($device_code_data_user,$result_user['id']); - $device_binding = Db::table('app_device_code_data')->where(['machine_code'=>$data['device_mac']])->update([ + $device_binding = Db::table($this->device_use_db_name['3'])->where(['machine_code'=>$data['device_mac']])->update([ 'bind_account_id'=>implode(',',$device_code_data_user), ]); if($device_binding){ @@ -131,21 +236,8 @@ class Device extends Base{ return $this->msg(10002,'更新失败'); } } - // 仅单用户可以绑定 - // if($device_code_data['bind_account_id']){ - // return $this->msg(10003,'设备已被绑定'); - // }else{ - // $device_binding = Db::table('app_device_code_data')->where(['machine_code'=>$data['device_mac']])->update([ - // 'bind_account_id'=>$result_user['id'], - // ]); - // if($device_binding){ - // return $this->msg([]); - // }else{ - // return $this->msg(10002,'更新失败'); - // } - // } } - $device_binding = Db::table('app_device_code_data')->insert([ + $device_binding = Db::table($this->device_use_db_name['3'])->insert([ 'add_id'=>$data['device_id'], 'machine_code'=>$data['device_mac'], 'create_time'=>date('Y-m-d H:i:s'), @@ -160,14 +252,14 @@ class Device extends Base{ ################################################device_user_data_list public function device_user_data_list_action($data){ - $result_user = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find(); + $result_user = Db::table($this->device_use_db_name['2'])->where(['token'=>$data['token']])->field('id,token')->find(); if(!$result_user){ return $this->msg(10003); } $likePattern = '%' . $result_user['id'] . '%'; - $device_code_data = Db::table('app_device_code_data') + $device_code_data = Db::table($this->device_use_db_name['3']) ->alias('adcd') - ->join('app_device_data add','adcd.add_id = add.id','LEFT') + ->join(''.$this->device_use_db_name['1'].' add','adcd.add_id = add.id','LEFT') // ->where(['adcd.bind_account_id'=>$result_user['id']]) // ->where('adcd.bind_account_id LIKE "%'.$result_user['id'].'%"') ->where("adcd.bind_account_id LIKE ?", [$likePattern]) @@ -201,31 +293,25 @@ class Device extends Base{ ################################################device_unbinding public function device_unbinding_action($data){ - $result_user = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find(); + $result_user = Db::table($this->device_use_db_name['2'])->where(['token'=>$data['token']])->field('id,token')->find(); if(!$result_user){ return $this->msg(10003); } - $device_binding_user = Db::table('app_device_code_data') + $device_binding_user = Db::table($this->device_use_db_name['3']) ->alias('adcd') - ->join('app_device_data add2','add2.id = adcd.add_id','LEFT') + ->join(''.$this->device_use_db_name['1'].' add2','add2.id = adcd.add_id','LEFT') ->where(['adcd.id'=>$data['id']]) ->field('adcd.id,adcd.bind_account_id,add2.acd_id') ->find(); - // dump(time()); - // die; $device_binding_user = explode(',',$device_binding_user['bind_account_id']); - // dump($device_binding_user); $key = array_search($result_user['id'], $device_binding_user); if($key !== false){ unset($device_binding_user[$key]); }else{ return $this->msg([]); } - // dump($device_binding_user); - // dump(implode(',',$device_binding_user)); - // die; - $device_binding = Db::table('app_device_code_data')->where(['id'=>$data['id']])->update([ + $device_binding = Db::table($this->device_use_db_name['3'])->where(['id'=>$data['id']])->update([ 'bind_account_id'=>implode(',',$device_binding_user), ]); if($device_binding){ @@ -238,13 +324,11 @@ class Device extends Base{ ################################################device_mac_get_content public function device_mac_get_content_action($data){ - $user_id = Db::table('app_account_number')->where(['token'=>$data['token']])->field('id,token')->find(); - // dump($user_id); - // die; + $user_id = Db::table($this->device_use_db_name['2'])->where(['token'=>$data['token']])->field('id,token')->find(); $likePattern = '%' . $user_id['id'] . '%'; - $result_device = Db::table('app_device_code_data') + $result_device = Db::table($this->device_use_db_name['3']) ->alias('adcd') - ->join('app_device_data add','adcd.add_id = add.id','LEFT') + ->join(''.$this->device_use_db_name['1'].' add','adcd.add_id = add.id','LEFT') ->where([ 'adcd.machine_code'=>$data['mac'], 'add.acd_id'=>$data['acd_id'], diff --git a/application/appbackups/controller/Index.php b/application/appbackups/controller/Index.php index 4795133..d0acd64 100644 --- a/application/appbackups/controller/Index.php +++ b/application/appbackups/controller/Index.php @@ -2,22 +2,31 @@ namespace app\app\controller; -use think\Controller; use think\Db; -use app\bj\controller\Common; -use think\Log; use \think\Validate; class Index extends Base{ protected $moren_gufen_diqu = '上海,上海'; - protected $db_name = ['2'=>'app_card_body_data','6'=>'app_card_skip_data','8'=>'app_card_vitalcapacity_data']; + protected $db_name = ['2'=>'app_card_body_data','6'=>'app_card_skip_data','8'=>'app_card_vitalcapacity_data','10'=>'app_card_data_sub_item_data']; + protected $index_use_db_name = [ + '1'=>'app_version_log', + '2'=>'app_user_data', + '3'=>'app_card_body_data', + '4'=>'app_device_code_data', + '5'=>'app_device_data', + '6'=>'app_card_data', + '7'=>'app_account_number', + '8'=>'app_card_data_sub_item', + '9'=>'app_card_data_sub_item_data', + '10'=>'admin_estimate' + ]; // protected $card_key = ['2'=>'body','6'=>'skip','8'=>'vitalcapacity']; protected $default_card = ['2','6','8']; protected $card_data = [ '2'=>['身体数据','body',['height'=>['身高','cm','-'],'weight'=>['体重','公斤','-'],'bmi'=>['BMI','无','-']]], // '6'=>['跳绳数据','skip',['jump_time'=>['用时','无','--:--:--'],'jump_num'=>['本次次数','次','-'],'average_num'=>['平均成绩','个','-'],'jump_kcal'=>['卡路里','kcal','-']]], '6'=>['跳绳数据','skip',['jump_time'=>['用时','无','--:--:--'],'jump_num'=>['本次次数','次','-'],'jump_kcal'=>['卡路里','kcal','-']]], - '8'=>['肺活量','vitalcapacity',['average'=>['本次数据','ml','-']]], + '8'=>['肺活量','vitalcapacity',['average'=>['平均成绩','ml','-']]], ]; protected $data_name_unit = [ @@ -26,7 +35,8 @@ class Index extends Base{ 'bmi'=>['BMI','','pc_bmistand2'], 'average'=>['肺活量','ml','pc_vitalcapacity_standard'] ]; - + protected $identity_list = ['P0'=>'陌生人','P1'=>'爸爸','P2'=>'妈妈','P3'=>'大宝','P4'=>'二宝','P5'=>'三宝','P6'=>'四宝','P7'=>'爷爷','P8'=>'奶奶']; + // protected $nickname_data2 = ['爸爸','妈妈','大宝','二宝','爷爷','奶奶','外公','外婆']; protected $grade_list = [ ['id'=>'nothing','name'=>'无'], ['id'=>'grade_s_1','name'=>'小学一年级'], @@ -50,423 +60,721 @@ class Index extends Base{ ################################################################个人资料卡################################################################ // 检测版本及判断是否登录失效 - public function login_invalid_version($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - // phpinfo(); - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - $result = Db::table('app_version_log')->order('is_del,id desc')->find(); - if($result){ - $version = $result['version_num_original']; - $url = $result['download_url']; - }else{ - $version = ''; - $url = ''; - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url]); - }else{ - return $this->msg(['version'=>$version,'url'=>$url]); - } + public function login_invalid_version($data = ['token'=>NULL]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + $result = Db::table($this->index_use_db_name['1'])->order('is_del,id desc')->find(); + if($result){ + $version = $result['version_num_original']; + $url = $result['download_url']; + }else{ + $version = ''; + $url = ''; + } + if($this->token_time_validate($data['token']) === false){ + $this->record_api_log($data, null, ['code'=>-1,'msg'=>'未登录',['version'=>$version,'url'=>$url]]); + return $this->msg(-1,'未登录',['version'=>$version,'url'=>$url]); + }else{ + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',['version'=>$version,'url'=>$url]]); + return $this->msg(['version'=>$version,'url'=>$url]); + } + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } // 创建用户 - public function create_user_data($data = ['aan_id'=>66,'nickname'=>'王小二','birthday'=>'2019-01-01','gender'=>1,'grade'=>'二年级','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $verify_result = $this->verify_parameters($data,'register'); - if(!is_array($verify_result)){ - return $this->msg(10001,$verify_result); - } - $result = Db::table('app_user_data')->insertGetId($verify_result); - if($result){ - return $this->msg(['aud_id'=>$result]); - }else{ - return $this->msg(10002); - } + public function create_user_data($data = ['aan_id'=>1,'height'=>'152.3','weight'=>'35.4','nickname'=>'钮祜禄测试1','birthday'=>'2019-04-20','gender'=>1,'grade'=>'grade_s_3','identity_id'=>'P3','identity_name'=>'大宝','address'=>'河南,郑州','token'=>'57bd45e3a963b372ea2d873e4bd8d1f8']){ + + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + + unset($data['token']); + $verify_result = $this->verify_parameters($data,'register'); + if(!is_array($verify_result)){ + return $this->msg(10001,$verify_result); + } + $result = Db::table($this->index_use_db_name['2'])->insertGetId($verify_result); + if($result){ + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',['aud_id'=>$result]]); + return $this->msg(['aud_id'=>$result]); + }else{ + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + + } catch (\Exception $e) { + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + + } // 修改用户 - public function update_user_data($data = ['id'=>66,'nickname'=>'王小二','birthday'=>'2019-01-01','gender'=>1,'grade'=>'二年级','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $verify_result = $this->verify_parameters2($data,'update'); - if(!is_array($verify_result)){ - return $this->msg(10001,$verify_result); - } - $id_val = $verify_result['id']; - unset($verify_result['id']); - $result = Db::table('app_user_data')->where(['id'=>$id_val])->update($verify_result); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } + public function update_user_data($data = ['id'=>66,'nickname'=>'王小二','birthday'=>'2019-01-01','gender'=>1,'grade'=>'二年级','identity_id'=>'P3','identity_name'=>'大宝','address'=>'河南,郑州','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + unset($data['token']); + $verify_result = $this->verify_parameters2($data,'update'); + if(!is_array($verify_result)){ + return $this->msg(10001,$verify_result); + } + $id_val = $verify_result['id']; + unset($verify_result['id']); + $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$id_val])->update($verify_result); + if($result){ + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg([]); + }else{ + // 失败 + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + } catch (\Exception $e) { + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } // 删除用户 public function del_user_data($data = ['id'=>'26','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $result = Db::table('app_user_data')->where(['id'=>$data['id']])->update(['is_del'=>1]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['id']])->update(['is_del'=>1]); + if($result){ + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg([]); + }else{ + // 失败 + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取账号下用户列表 // $type 1获取列表,2获取详细信息 - public function get_user_card_list($data = ['aan_id'=>66,'type'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data) || !array_key_exists('aan_id', $data) || !array_key_exists('type', $data)){ - return $this->msg(10001); - } + public function get_user_card_list($data = ['aan_id'=>1,'type'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('aan_id', $data) || !array_key_exists('type', $data)){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aan_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $result = Db::table($this->index_use_db_name['2'])->where(['aan_id'=>$data['aan_id'],'is_del'=>0])->select(); + $temporary_data = []; + if($data['type'] == 1){ + for ($i=0; $i < count($result); $i++) { + array_push($temporary_data,['id'=>$result[$i]['id'],'nickname'=>$result[$i]['nickname'],'identity_name'=>$result[$i]['identity_name'],'identity_id'=>$result[$i]['identity_id']]); + } + }else{ + for ($i=0; $i < count($result); $i++) { + $result[$i]['age'] = $this->calculate_age($result[$i]['birthday']); + } + $temporary_data = $result; + } + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$temporary_data]); + return $this->msg($temporary_data); + + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $result = Db::table('app_user_data')->where(['aan_id'=>$data['aan_id'],'is_del'=>0])->select(); - // $result = Db::table('app_user_data')->where(['aan_id'=>$aan_id])->field('id,nickname')->select(); - $temporary_data = []; - if($data['type'] == 1){ - for ($i=0; $i < count($result); $i++) { - array_push($temporary_data,['id'=>$result[$i]['id'],'nickname'=>$result[$i]['nickname']]); - } - }else{ - for ($i=0; $i < count($result); $i++) { - $result[$i]['age'] = $this->calculate_age($result[$i]['birthday']); - // array_push($temporary_data,['id'=>$result[$i]['id'],'nickname'=>$result[$i]['nickname'],'age'=>$this->calculate_age($result[$i]['birthday'])]); - } - $temporary_data = $result; - } - return $this->msg($temporary_data); } // 获取指定用户详细信息 - public function get_user_data_information($data = ['aud_id'=>92,'token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - // dump(input('post.')); - // dump(input('get.')); - // // dump($data); - // die; - if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data)){ - return $this->msg(10001); - } - // cache($data['token'],time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,head_pic,birthday,gender,card_order,target_weight,initial_weight,initial_date,weight')->find(); - $weight_data_pd = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('id,weight_val,record_time')->find(); - // dump($weight_data_pd); - // die; - if(!$result){ - return $this->msg(10003); - } - unset($result['ROW_NUMBER']); - $result['age'] = $this->calculate_age($result['birthday']); - if($result['card_order'] === ''){ - $result['card_order'] = []; - $result['card_data_list'] = []; - $result['target_current'] = $this->base_target_initial_cumulative_weight([]); + public function get_user_data_information($data = ['aud_id'=>11]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } - }else{ - $result['card_order'] = explode(',',$result['card_order']); - $calculation_results = $this->get_user_card_data_list($result,$result['id']); - $result['card_data_list'] = $calculation_results[0]; - $result['target_current'] = $calculation_results[1]; - } - - if($weight_data_pd){ - $result['weight'] = $weight_data_pd['weight_val']; - } - - - // $result['birthday'] = str_replace('-', '/', $result['birthday']); - // foreach ($result['card_data_list'] as $key => $value) { - // // dump($key); - // if($key == 'record_time' && $value != ''){ - // // dump(111); - // $result['card_data_list'][$key] = str_replace('-', '/', $result['card_data_list'][$key]); - // } - // } - unset($result['target_weight']); - unset($result['initial_weight']); - unset($result['initial_date']); - - // 获取设备信息进入卡片 start - $likePattern = '%' . $result['aan_id'] . '%'; - $result_device = Db::table('app_device_code_data') - ->alias('adcd') - ->join('app_device_data add','adcd.add_id = add.id','LEFT') - // ->where(['adcd.bind_account_id'=>$result['aan_id']]) - ->where("adcd.bind_account_id LIKE ?", [$likePattern]) - ->field('adcd.id,add.acd_id') - ->select(); - - $device_arr = []; - foreach ($result_device as $key => $value) { - if(!in_array($value['acd_id'],$device_arr)){ - array_push($device_arr,$value['acd_id']); + if(!array_key_exists('aud_id', $data)){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); } - } - // dump($device_arr); - // die; - foreach ($result['card_data_list'] as $key => $value) { - if(in_array($value['acd_id'],$device_arr)){ - $result['card_data_list'][$key]['device_determine'] = true; + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + // 获取用户信息 + $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,aan_id,nickname,head_pic,birthday,gender,card_order,target_weight,initial_weight,initial_date,weight,address,identity_id')->find(); + if(!$result){ + return $this->msg(10004); + } + // 获取用户身体卡片信息 + $weight_data_pd = Db::table($this->index_use_db_name['3'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('id,weight_val,record_time')->find(); + + if(!$result){ + // 失败 + $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); + return $this->msg(10003); + } + unset($result['ROW_NUMBER']); + $result['age'] = $this->calculate_age($result['birthday']); + if($result['card_order'] === ''){ + $result['card_order'] = []; + $result['card_data_list'] = []; + $result['target_current'] = $this->base_target_initial_cumulative_weight([]); + }else{ - $result['card_data_list'][$key]['device_determine'] = false; + $result['card_order'] = explode(',',$result['card_order']); + $calculation_results = $this->get_user_card_data_list($result,$result['id']); + $result['card_data_list'] = $calculation_results[0]; + $result['target_current'] = $calculation_results[1]; } - } - $result['address'] = $this->moren_gufen_diqu; - // 插入肺活量的卡片标准 - $result['vitalcapacity_data'] = $this->get_vitalcapacity_data($result['id']); - // 获取设备信息进入卡片 end - return $this->msg($result); + + + if($weight_data_pd){ + $result['weight'] = $weight_data_pd['weight_val']; + } + + unset($result['target_weight']); + unset($result['initial_weight']); + unset($result['initial_date']); + + // 获取设备信息进入卡片 start + $likePattern = '%' . $result['aan_id'] . '%'; + $result_device = Db::table($this->index_use_db_name['4']) + ->alias('adcd') + ->join(''.$this->index_use_db_name['5'].' add','adcd.add_id = add.id','LEFT') + // ->where(['adcd.bind_account_id'=>$result['aan_id']]) + ->where("adcd.bind_account_id LIKE ?", [$likePattern]) + ->field('adcd.id,add.acd_id') + ->select(); + + $device_arr = []; + foreach ($result_device as $key => $value) { + if(!in_array($value['acd_id'],$device_arr)){ + array_push($device_arr,$value['acd_id']); + } + } + foreach ($result['card_data_list'] as $key => $value) { + if(in_array($value['acd_id'],$device_arr)){ + $result['card_data_list'][$key]['device_determine'] = true; + }else{ + $result['card_data_list'][$key]['device_determine'] = false; + } + // // 处理卡片的背景色背景图 + // foreach ($card_pic_color as $ck => $cv) { + // if($cv['id'] == $value['acd_id']){ + // $result['card_data_list'][$key]['background_color'] = $cv['background_color']; + // $result['card_data_list'][$key]['background_pic'] = $cv['background_pic']; + // } + // } + } + // 获取设备信息进入卡片 end + // 插入肺活量的卡片标准 + if($result['address'] == ''){ + $result['address'] = $this->moren_gufen_diqu; + } + $result['vitalcapacity_data'] = $this->get_vitalcapacity_data($result['id']); + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]); + return $this->msg($result); + + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取所有卡片列表信息 - public function get_card_all_list($data = ['aud_id'=>83,'token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $user_card_list = Db::table('app_user_data')->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find(); - if(!$user_card_list){ - return $this->msg(10003); - } - unset($user_card_list['ROW_NUMBER']); - $user_card_list['card_order'] = explode(',',$user_card_list['card_order']); - $all_card_list = Db::table('app_card_data')->where(['is_del'=>0])->field('id,name,pic')->select(); - // dump($user_card_list); - // dump($all_card_list); - $result = ['user'=>[],'all'=>[]]; - foreach ($all_card_list as $key => $value) { - if(in_array($value['id'],$user_card_list['card_order'])){ - $result['user'][array_search($value['id'], $user_card_list['card_order'])] = ['id'=>$value['id'],'name'=>$value['name'],'pic'=>$value['pic']]; - }else{ - array_push($result['all'],['id'=>$value['id'],'name'=>$value['name'],'pic'=>$value['pic']]); + public function get_card_all_list($data = ['aud_id'=>1,'token'=>'57bd45e3a963b372ea2d873e4bd8d1f8']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); } - } - ksort($result['user']); - return $this->msg($result); + if(!array_key_exists('token', $data)){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $user_card_list = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find(); + + if(!$user_card_list){ + // 失败 + $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); + return $this->msg(10003); + } + unset($user_card_list['ROW_NUMBER']); + $user_card_list['card_order'] = explode(',',$user_card_list['card_order']); + $all_card_list = Db::table($this->index_use_db_name['6'])->where(['is_del'=>0])->field('id,name,pic')->select(); + + $result = ['user'=>[],'all'=>[]]; + foreach ($all_card_list as $key => $value) { + if(in_array($value['id'],$user_card_list['card_order'])){ + $result['user'][array_search($value['id'], $user_card_list['card_order'])] = ['id'=>$value['id'],'name'=>$value['name'],'pic'=>$value['pic']]; + }else{ + array_push($result['all'],['id'=>$value['id'],'name'=>$value['name'],'pic'=>$value['pic']]); + } + } + ksort($result['user']); + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]); + return $this->msg($result); + + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 保存用户的卡片排序 - public function save_user_card_order($data=['aud_id'=>11,'card_order'=>'2,8','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('card_order', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if(!$this->is_num_array(explode(',',$data['card_order']))){ - return $this->msg(10001,'数据内参数格式或值错误'); - } - $result = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['card_order']]); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); - } + public function save_user_card_order($data=['aud_id'=>11,'card_order'=>'2,6,10,12,13,8,14,16,15','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('card_order', $data) || !array_key_exists('token', $data)){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + if(!$this->is_num_array(explode(',',$data['card_order']))){ + // 失败 + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'数据内参数格式或值错误',[]]); + return $this->msg(10005,'数据内参数格式或值错误'); + } + $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['card_order']]); + if($result){ + // 成功 + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg([]); + }else{ + // 失败 + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } // 获取年级key列表 - public function get_grade_list(){ - $data = input('post.'); - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } + public function get_grade_list($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + if(count(input('post.')) > 0){ + $data = input('post.'); + } + // if(!array_key_exists('token', $data)){ + // $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + // return $this->msg(10001); + // } + $address_data = Db::table($this->base_use_db_name['5'])->where(['type' => '2'])->cache(3600)->field('id,content,city,area')->find(); + $return_data['area_list'] = json_decode($address_data['content'],true); + $return_data['identity_list'] = []; + foreach ($this->identity_list as $key => $value) { + array_push($return_data['identity_list'],['id'=>$key,'name'=>$value]); + } + $return_data['grade_list'] = $this->grade_list; + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg($return_data); + + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } - return $this->msg($this->grade_list); - // $temporary_arr = Db::table('app_identity_data')->cache(true,60)->select(); - // $result = [['id'=>'nothing','name'=>'无']]; - // // dump(); - // // die; - // foreach ($temporary_arr as $key => $value) { - // array_push($result,['id'=>$value['id'],'name'=>$value['content']]); - // } - // return $this->msg(['grade_list'=>$this->grade_list,'identity_list'=>$result]); + // 修改用户所属区域 + public function update_user_address($data=['aud_id'=>'1','address_data'=>'上海,上海']){ + try { + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('address_data', $data)){ + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + $user_data = Db::table($this->base_use_db_name['2'])->where(['id' => $data['aud_id']])->count(); + if($user_data<=0){ + $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); + return $this->msg(10003); + } + $address_data = explode(',',$data['address_data']); + $address_result = Db::table($this->base_use_db_name['10'])->where(['province' => $address_data[0]])->cache(3600)->field('id,recommend_cards')->find(); + if(!$address_result){ + $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); + return $this->msg(10003); + } + $user_result = Db::table($this->base_use_db_name['2'])->where(['id' => $data['aud_id']])->update(['card_order'=>$address_result['recommend_cards']]); + + if($user_result){ + $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[]]); + return $this->msg([]); + }else{ + $this->record_api_log($data, null, ['code'=>10002,'msg'=>'',[]]); + return $this->msg(10002); + } + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } } ################################获取账号下信息操作################################ // 获取账号下首页卡片的基础数据 public function get_user_card_data_list($data,$aud_id){ - - $result = []; - $db_arr = []; - foreach ($data['card_order'] as $key => $value) { - $db_arr[$value] = Db::table($this->db_name[$value])->where(['aud_id'=>$aud_id,'is_del'=>'0'])->order('record_time desc')->limit(1)->select(); - // dump($db_arr[$value]); - - if(count($db_arr[$value]) > 0){ - $db_arr[$value] = $db_arr[$value][0]; - }else{ - unset($db_arr[$value]); - } - } - - // 获取卡片路径及卡片数组处理start - $card_all_data = Db::table('app_card_data')->field('id,page_url_record,page_url_report,page_url_bluetooth')->select(); - $card_all_data_result = []; - foreach ($card_all_data as $key => $value) { - $card_all_data_result[$value['id']] = [ - 'page_url_record'=>$value['page_url_record'], - 'page_url_report'=>$value['page_url_report'], - 'page_url_bluetooth'=>$value['page_url_bluetooth'] - ]; - } - // 获取卡片路径及卡片数组处理end - - // dump($db_arr); - // die; - // 添加目标体重于当前体重差数据 - if(array_key_exists('2', $db_arr)){ - $target_current = $this->base_target_initial_cumulative_weight([ - 'weight'=>$db_arr['2']['weight']>0?$db_arr['2']['weight']:0, - 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, - 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, - 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, - ]); - }else{ - $target_current = $this->base_target_initial_cumulative_weight([ - 'weight'=>0, - 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, - 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, - 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, - ]); - } - if(count($db_arr) <= 0){ - // 没有数据,传递一个空的卡片 + // try { + // 你的业务逻辑 + $result = []; + $db_arr = []; foreach ($data['card_order'] as $key => $value) { - $temporary_arr = []; - $temporary_arr['id'] = ''; - $temporary_arr['acd_id'] = $value; - $temporary_arr['record_time'] = ''; - $temporary_arr['card_name'] = $this->card_data[$value][0]; - $temporary_arr['card_key'] = $this->card_data[$value][1]; - $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; - $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; - $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; - $temporary_arr['inside_data'] = []; - foreach ($this->card_data[$value][2] as $k => $v) { - array_push($temporary_arr['inside_data'],[ - 'key'=>$k, - 'name'=>$v[0], - 'value'=>$v[2], - 'unit'=>$v[1]!='无'?$v[1]:'', - 'standard'=>'', - 'color'=>'' - ]); - } - array_push($result,$temporary_arr); - } - }else{ - // dump($db_arr); - // die; - foreach ($data['card_order'] as $key => $value) { - $temporary_arr = []; - $temporary_arr['acd_id'] = $value; - - $temporary_arr['card_name'] = $this->card_data[$value][0]; - $temporary_arr['card_key'] = $this->card_data[$value][1]; - $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; - $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; - $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; - $temporary_arr['inside_data'] = []; - if(array_key_exists($value,$db_arr)){ - $temporary_arr['id'] = $db_arr[$value]['id']; - $temporary_arr['record_time'] = $db_arr[$value]['record_time']; - foreach ($this->card_data[$value][2] as $k => $v) { - if($value == '2'){ - $tem_arr_2 = explode(',', $db_arr[$value][$k]); - }else if($value == '6' && $k == 'jump_time'){ - $time_conversion = $this->handle_hour_branch_second($db_arr[$value][$k]); - $tem_arr_2 = [$time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'],'','']; - }else{ - $tem_arr_2 = [$db_arr[$value][$k],'','']; - } - - // dump($tem_arr_2); - array_push($temporary_arr['inside_data'],[ - 'key'=>$k, - 'name'=>$v[0], - 'value'=>$tem_arr_2[0], - 'unit'=>$v[1]!='无'?$v[1]:'', - 'standard'=>$tem_arr_2[1]!='无'?$tem_arr_2[1]:'', - 'color'=>$tem_arr_2[2]!='无'?$tem_arr_2[2]:'' - ]); - } + if($value<10){ + $db_arr[$value] = Db::table($this->db_name[$value])->where(['aud_id'=>$aud_id,'is_del'=>'0'])->order('record_time desc')->limit(1)->select(); }else{ + // 公共卡牌 + $db_arr[$value] = Db::table($this->index_use_db_name['9'])->where(['aud_id'=>$aud_id,'acd_id'=>$value,'is_del'=>'0'])->order('record_time desc')->limit(1)->select(); + if(count($db_arr[$value]) > 0){ + $temporary_data = Db::table($this->index_use_db_name['8'])->where(['id'=>$db_arr[$value][0]['acdsi_id']])->field('id,name')->find(); + $db_arr[$value][0]['acdsi_name'] = $temporary_data['name']; + } + } + if(count($db_arr[$value]) > 0){ + $db_arr[$value] = $db_arr[$value][0]; + }else{ + unset($db_arr[$value]); + } + } + // 获取卡片背景图,及背景色信息及其他信息 + $card_all_data = Db::table($this->index_use_db_name['6'])->field('id,name,page_url_record,page_url_report,page_url_bluetooth,key_word,background_color,background_pic')->select(); + $card_all_data_result = []; + foreach ($card_all_data as $key => $value) { + $card_all_data_result[$value['id']] = $value; + } + // 获取卡片路径及卡片数组处理end + // 添加目标体重于当前体重差数据 + if(array_key_exists('2', $db_arr)){ + $target_current = $this->base_target_initial_cumulative_weight([ + 'weight'=>$db_arr['2']['weight']>0?$db_arr['2']['weight']:0, + 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, + 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, + 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, + ]); + }else{ + $target_current = $this->base_target_initial_cumulative_weight([ + 'weight'=>0, + 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, + 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, + 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, + ]); + } + if(count($db_arr) <= 0){ + // 没有数据,传递一个空的卡片 + foreach ($data['card_order'] as $key => $value) { + $temporary_arr = []; $temporary_arr['id'] = ''; + $temporary_arr['acd_id'] = $value; $temporary_arr['record_time'] = ''; - foreach ($this->card_data[$value][2] as $k => $v) { + $temporary_arr['card_name'] = $card_all_data_result[$value]['name']; + $temporary_arr['card_key'] = $card_all_data_result[$value]['key_word']; + $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; + $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; + $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; + $temporary_arr['background_color'] = $card_all_data_result[$value]['background_color']; + $temporary_arr['background_pic'] = $card_all_data_result[$value]['background_pic']; + $temporary_arr['inside_data'] = []; + if(array_key_exists($value, $this->card_data)){ + foreach ($this->card_data[$value][2] as $k => $v) { + array_push($temporary_arr['inside_data'],[ + 'key'=>$k, + 'name'=>$v[0], + 'value'=>$v[2], + 'unit'=>$v[1]!='无'?$v[1]:'', + 'standard'=>'', + 'color'=>'' + ]); + } + }else{ array_push($temporary_arr['inside_data'],[ - 'key'=>$k, - 'name'=>$v[0], - 'value'=>$v[2], - 'unit'=>$v[1]!='无'?$v[1]:'', - 'standard'=>'', + 'key'=>'last_time', + 'name'=>'最近一次', + 'value'=>"--", + 'unit'=>'', + 'standard'=>'*分', 'color'=>'' ]); } + array_push($result,$temporary_arr); + } + }else{ + foreach ($data['card_order'] as $key => $value) { + $temporary_arr = []; + $temporary_arr['acd_id'] = $value; + $temporary_arr['card_name'] = $card_all_data_result[$value]['name']; + $temporary_arr['card_key'] = $card_all_data_result[$value]['key_word']; + $temporary_arr['page_url_record'] = $card_all_data_result[$value]['page_url_record']; + $temporary_arr['page_url_report'] = $card_all_data_result[$value]['page_url_report']; + $temporary_arr['page_url_bluetooth'] = $card_all_data_result[$value]['page_url_bluetooth']; + $temporary_arr['background_color'] = $card_all_data_result[$value]['background_color']; + $temporary_arr['background_pic'] = $card_all_data_result[$value]['background_pic']; + $temporary_arr['inside_data'] = []; + if(array_key_exists($value, $this->card_data)){ + if(array_key_exists($value,$db_arr)){ + $temporary_arr['id'] = $db_arr[$value]['id']; + $temporary_arr['record_time'] = $db_arr[$value]['record_time']; + foreach ($this->card_data[$value][2] as $k => $v) { + if($value == '2'){ + $tem_arr_2 = explode(',', $db_arr[$value][$k]); + }else if($value == '6' && $k == 'jump_time'){ + $time_conversion = $this->handle_hour_branch_second($db_arr[$value][$k]); + $tem_arr_2 = [$time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'],'','']; + }else{ + $tem_arr_2 = [$db_arr[$value][$k],'','']; + } + array_push($temporary_arr['inside_data'],[ + 'key'=>$k, + 'name'=>$v[0], + 'value'=>$tem_arr_2[0], + 'unit'=>$v[1]!='无'?$v[1]:'', + 'standard'=>$tem_arr_2[1]!='无'?$tem_arr_2[1]:'', + 'color'=>$tem_arr_2[2]!='无'?$tem_arr_2[2]:'' + ]); + } + }else{ + $temporary_arr['id'] = ''; + $temporary_arr['record_time'] = ''; + foreach ($this->card_data[$value][2] as $k => $v) { + array_push($temporary_arr['inside_data'],[ + 'key'=>$k, + 'name'=>$v[0], + 'value'=>$v[2], + 'unit'=>$v[1]!='无'?$v[1]:'', + 'standard'=>'', + 'color'=>'' + ]); + } + } + }else{ + if(array_key_exists($value,$db_arr)){ + // 公共卡片内容 + $temporary_arr['id'] = $db_arr[$value]['id']; + $temporary_arr['record_time'] = $db_arr[$value]['record_time']; + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + // 'name'=>'最近一次', + 'name'=>"项目名称", + 'value'=>$db_arr[$value]['acdsi_name'], + 'unit'=>'', + 'standard'=>'', + 'color'=>'' + ]); + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + // 'name'=>'最近一次', + 'name'=>"成绩", + 'value'=>$db_arr[$value]['achievement'], + 'unit'=>$db_arr[$value]['unit'], + 'standard'=>'', + 'color'=>'' + ]); + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + // 'name'=>'最近一次', + 'name'=>'得分', + // 'value'=>$db_arr[$value]['score'], + 'value'=>$this->convertStringToNumber($db_arr[$value]['score']), + 'unit'=>'分', + 'standard'=>"", + 'color'=>'' + ]); + }else{ + $temporary_arr['id'] = ''; + $temporary_arr['record_time'] = ''; + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + 'name'=>'最近一次', + 'value'=>"--", + 'unit'=>'', + 'standard'=>'*分', + 'color'=>'' + ]); + } + + } + array_push($result,$temporary_arr); } - array_push($result,$temporary_arr); - } - } - return [$result,$target_current]; + // 成功 + // $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[$result,$target_current]]); + return [$result,$target_current]; + // } catch (\Exception $e) { + // // 捕获异常 + // $this->record_api_log($data, $e->getMessage(), null); + // } + } @@ -486,7 +794,9 @@ class Index extends Base{ 'grade' => 'require', 'height' => 'require|number', 'weight' => 'require|number', - // 'identity' => 'require|number', + 'identity_id' => 'require', + 'identity_name' => 'require', + 'address' => 'require', ]; $msg = [ 'aan_id.require' => '账号信息缺失', @@ -496,7 +806,9 @@ class Index extends Base{ 'grade.require' => '年级缺失', 'height.require' => '身高缺失', 'weight.require' => '体重缺失', - // 'identity.require' => '身份缺失', + 'identity_id.require' => '身份缺失', + 'identity_name.require' => '身份缺失', + 'address.require' => '区域缺失', 'aan_id.number' => '账号信息格式错误', 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母', @@ -522,18 +834,33 @@ class Index extends Base{ $parameter['height'] = $data['height']; $parameter['weight'] = $data['weight']; $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; - // $parameter['identity_data'] = $data['identity']; + $parameter['identity_id'] = $data['identity_id']; + $parameter['identity_name'] = $data['identity_name']; + $parameter['address'] = $data['address']; $parameter['create_time'] = date('Y-m-d H:i:s'); $parameter['last_update_time'] = date('Y-m-d H:i:s'); - $parameter_pd = Db::table('app_account_number')->where(['id'=>$parameter['aan_id']])->count(); + + $parameter_pd = Db::table($this->index_use_db_name['7'])->where(['id'=>$parameter['aan_id']])->count(); if($parameter_pd <= 0){ return '该账户不存在'; } - $result = Db::table('app_user_data')->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); + $result = Db::table($this->index_use_db_name['2'])->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); if($result>0){ return '该成员已存在'; } - + if(!array_key_exists($parameter['identity_id'],$this->identity_list)){ + return '身份信息错误'; + }else{ + if($parameter['identity_id'] != 'P0'){ + $parameter['identity_name'] = $this->identity_list[$data['identity_id']]; + $result = Db::table($this->index_use_db_name['2'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); + if($result>0){ + return '该身份已存在'; + } + } + } + $address_data = Db::table($this->index_use_db_name['10'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find(); + $parameter['card_order'] = $address_data['recommend_cards']; return $parameter; } public function verify_parameters2($data,$type){ @@ -546,7 +873,9 @@ class Index extends Base{ 'grade' => 'require', 'height' => 'require|number', 'weight' => 'require|number', - // 'identity' => 'require|number', + 'identity_id' => 'require', + 'identity_name' => 'require', + 'address' => 'require', ]; $msg = [ 'id.require' => '用户信息缺失', @@ -556,7 +885,9 @@ class Index extends Base{ 'grade.require' => '年级缺失', 'height.require' => '身高缺失', 'weight.require' => '体重缺失', - // 'identity.require' => '身份缺失', + 'identity_id.require' => '身份缺失', + 'identity_name.require' => '身份缺失', + 'address.require' => '区域缺失', 'id.number' => '用户信息格式错误', 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母、数字', @@ -581,8 +912,33 @@ class Index extends Base{ $parameter['gender'] = $data['gender']; $parameter['grade'] = $data['grade']; $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; + $parameter['identity_id'] = $data['identity_id']; + $parameter['identity_name'] = $data['identity_name']; + $parameter['address'] = $data['address']; // $parameter['identity_data'] = $data['identity']; $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $aan_id = $data['aan_id']; + + + if(!array_key_exists($parameter['identity_id'],$this->identity_list)){ + return '身份信息错误'; + }else{ + if($parameter['identity_id'] != 'P0'){ + $parameter['identity_name'] = $this->identity_list[$data['identity_id']]; + $result = Db::table($this->index_use_db_name['2'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$aan_id,'is_del'=>0])->field('id,identity_id')->find(); + if($result && $parameter['id'] != $result['id']){ + return '该身份已存在'; + } + } + } + if($data['address'] != ''){ + $address_data = explode(',', $data['address']); + $card_result = Db::table($this->index_use_db_name['10'])->where(['province'=>$address_data[0],'is_del'=>0])->field('id,recommend_cards')->find(); + $parameter['card_order'] = $card_result['recommend_cards']; + }else{ + $parameter['card_order'] = '2'; + } + return $parameter; } diff --git a/application/appbackups/controller/Login.php b/application/appbackups/controller/Login.php index 41d7fe8..7306654 100644 --- a/application/appbackups/controller/Login.php +++ b/application/appbackups/controller/Login.php @@ -2,17 +2,18 @@ namespace app\app\controller; -use think\Controller; + use think\Db; -use think\Cache; -use think\Log; -use \think\Validate; use PHPMailer\PHPMailer\PHPMailer; + class Login extends Base{ protected $code_time = 50; + // protected $token_time = 2592000;//30天的秒数 protected $default_head_pic = 'http://tc.pcxbc.com/tsf/head_pic.png'; - + protected $login_use_db_name = [ + '1'=>'app_account_number', + ]; ################################################################接口################################################################ ################################################################接口################################################################ @@ -20,186 +21,304 @@ class Login extends Base{ // 注册 public function register_action($data = ['data'=>18530934717,'password'=>'ceshi','code'=>'746119']){ - // 验证是否前段发送过来的数据 - if(count(input('post.')) > 0){ - $data = input('post.'); - } - // 验证数据项是否完整 - if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){ - return $this->msg(10001); - } - // 验证数据值是否合规 - if(!$data['data'] || !$data['password'] || !$data['code']){ - return $this->msg(10006); - } - // 验证是手机还是邮箱 - $montage_data = $this->is_tel_email($data['data']); - if($montage_data == false){ - return $this->msg(10005); - } - // 查询账号是否已经注册 - $inspect_repeat = Db::table('app_account_number')->where([$montage_data=>$data['data'],'is_del'=>0])->count(); - if($inspect_repeat >= 0){ - return $this->msg(10002,'注册失败,账号已存在'); - } - // 检查验证码 - $code_result = $this->check_code($data['data'],$data['code']); - if($code_result !== true){ - return $this->msg(10002,$code_result); - } - // 验证完之后 - $set_data = []; - if($montage_data == 'tel'){ - $set_data['tel'] = $data['data']; - }else{ - $set_data['email'] = $data['data']; - } - $set_data['password'] = $data['password']; - $set_data['head_pic'] = $this->default_head_pic; - $set_data['nickname'] = '用户'.time(); - $set_data['create_time'] = date('Y-m-d H:i:s'); - $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); - $result = Db::table('app_account_number')->insertGetId($set_data); - if($result){ - cache($set_data['token'], time()); - return $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + // 验证是否前段发送过来的数据 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + // 验证数据项是否完整 + if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){ + return $this->msg(10001); + } + // 验证数据值是否合规 + if(!$data['data'] || !$data['password'] || !$data['code']){ + return $this->msg(10006); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'num')){ + return $this->msg(10005); + } + // 验证是手机还是邮箱 + $montage_data = $this->is_tel_email($data['data']); + if($montage_data == false){ + return $this->msg(10005); + } + // 查询账号是否已经注册 + $inspect_repeat = Db::table($this->login_use_db_name['1'])->where([$montage_data=>$data['data'],'is_del'=>0])->count(); + if($inspect_repeat >= 0){ + return $this->msg(10002,'注册失败,账号已存在'); + } + // 检查验证码 + $code_result = $this->check_code($data['data'],$data['code']); + if($code_result !== true){ + return $this->msg(10002,$code_result); + } + // 验证完之后 + $set_data = []; + if($montage_data == 'tel'){ + $set_data['tel'] = $data['data']; + }else{ + $set_data['email'] = $data['data']; + } + $set_data['password'] = $data['password']; + $set_data['head_pic'] = $this->default_head_pic; + $set_data['nickname'] = '用户'.time(); + $set_data['create_time'] = date('Y-m-d H:i:s'); + $set_data['login_time'] = date('Y-m-d H:i:s'); + $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); + $result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data); + if($result){ + $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 重置密码 public function reset_password($data = ['data'=>'18530934717','password'=>'ceshi1','c_password'=>'ceshi1','code'=>'491661']){ - // 验证是否前段发送过来的数据 - if(count(input('post.')) > 0){ - $data = input('post.'); - } - // 验证数据项是否完整 - if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){ - return $this->msg(10001); - } - // 验证数据值是否合规 - if($data['password'] != $data['c_password']){ - return $this->msg(10003,'两次密码不一致'); - } - if($data['password'] == ''){ - return $this->msg(10003,'密码不能为空'); - } - // 检查验证码 - $code_result = $this->check_code($data['data'],$data['code']); - if($code_result !== true){ - return $this->msg(10003,$code_result); - } - $t_y = $this->is_tel_email($data['data']); - if($t_y === false){ - return $this->msg(10003,'账号格式错误'); - } - // 检查账号是否存在 - $find_data = Db::table('app_account_number')->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find(); - if(!$find_data){ - return $this->msg(10003); - } - $result = Db::table('app_account_number')->where([$t_y=>$data['data']])->update(['password'=>$data['password']]); - if($result){ - cache($find_data['token'], time()); - return $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + // 验证是否前段发送过来的数据 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + // 验证数据项是否完整 + if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){ + return $this->msg(10001); + } + // 验证数据值是否合规 + if($data['password'] != $data['c_password']){ + return $this->msg(10003,'两次密码不一致'); + } + if($data['password'] == ''){ + return $this->msg(10003,'密码不能为空'); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'num')){ + return $this->msg(10005); + } + // 检查验证码 + $code_result = $this->check_code($data['data'],$data['code']); + if($code_result !== true){ + return $this->msg(10003,$code_result); + } + $t_y = $this->is_tel_email($data['data']); + if($t_y === false){ + return $this->msg(10003,'账号格式错误'); + } + // 检查账号是否存在 + $find_data = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find(); + if(!$find_data){ + return $this->msg(10003); + } + $result = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data']])->update(['password'=>$data['password']]); + if($result){ + $return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 登录 - public function login_action($data = ['data'=>'18530934717','validate_data'=>'746119','type'=>'login','validate_type'=>'code']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){ - return $this->msg(10001); - } - // 检测是否为手机 - $montage_data = $this->is_tel_email($data['data']); - if($montage_data == false){ - return $this->msg(10005); - } - $verify_result[$montage_data] = $data['data']; - $verify_result['is_del'] = 0; - // 检测校验途径 - if($data['validate_type'] == 'code'){ - $code_name = $data['data']; - if($this->check_code($code_name,$data['validate_data']) === true){ - $result = Db::table('app_account_number')->where($verify_result)->field('id,token')->find(); - if($result){ - cache($result['token'], time()); - return $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]); - }else{ - $set_data['password'] = ''; - $set_data[$montage_data] = $data['data']; - $set_data['head_pic'] = $this->default_head_pic; - $set_data['nickname'] = '用户'.$data['data']; - $set_data['create_time'] = date('Y-m-d H:i:s'); - $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); - $result = Db::table('app_account_number')->insertGetId($set_data); + public function login_action($data = ['data'=>'18530934717','validate_data'=>'0932','type'=>'login','validate_type'=>'password']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){ + return $this->msg(10001); + } + // 检测是否为手机 + $montage_data = $this->is_tel_email($data['data']); + if($montage_data == false){ + return $this->msg(10005); + } + + $verify_result[$montage_data] = $data['data']; + $verify_result['is_del'] = 0; + // 检测校验途径 + if($data['validate_type'] == 'code'){ + $code_name = $data['data']; + if($this->check_code($code_name,$data['validate_data']) === true){ + $result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token')->find(); if($result){ - cache($set_data['token'], time()); - return $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功'); + Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); + $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]); }else{ - return $this->msg(10002); + $set_data['password'] = ''; + $set_data[$montage_data] = $data['data']; + $set_data['head_pic'] = $this->default_head_pic; + $set_data['nickname'] = '用户'.$data['data']; + $set_data['create_time'] = date('Y-m-d H:i:s'); + $set_data['login_time'] = date('Y-m-d H:i:s'); + $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); + $result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data); + if($result){ + $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功'); + }else{ + $return_data = $this->msg(10002); + } } - } - }else{ - return $this->msg(10003,'登录失败,验证码错误或失效'); - } - }else if($data['validate_type'] == 'password'){ - // $verify_result['password'] = $data['validate_data']; - $result = Db::table('app_account_number')->where($verify_result)->field('id,token,password')->find(); - if($result){ - if($result['password'] == ''){ - return $this->msg(10003,'该账户未设密码,请用验证码登录'); - } - if($data['validate_data'] != $result['password']){ - return $this->msg(10003,'账号密码错误'); }else{ - cache($result['token'], time()); - return $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功'); + $return_data = $this->msg(10003,'登录失败,验证码错误或失效'); + } + }else if($data['validate_type'] == 'password'){ + // $verify_result['password'] = $data['validate_data']; + $result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token,password')->find(); + if($result){ + if($result['password'] == ''){ + $return_data = $this->msg(10003,'该账户未设密码,请用验证码登录'); + } + if($data['validate_data'] != $result['password']){ + $return_data = $this->msg(10003,'账号密码错误'); + }else{ + + Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); + $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功'); + } + }else{ + $return_data = $this->msg(10003,'账号未注册,请先注册'); } }else{ - return $this->msg(10003,'账号未注册,请先注册'); + $return_data = $this->msg(10003,'校验参数错误'); } - }else{ - return $this->msg(10003,'校验参数错误'); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 退出登录操作 public function user_quit_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if($this->token_time_validate($data['token']) === false){ + $return_data = $this->msg(20001); + } + + $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']); + if($result){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - cache($data['token'], NULL); - return $this->msg([]); + } // 删除账号 public function delete_account($data=['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - $result = Db::table('app_account_number')->where(['token'=>$data['token']])->update(['is_del'=>1]); - cache($data['token'], NULL); - if($result){ - return $this->msg([]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-09-01 00:00:00']); + if($result){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } ################################################################接口################################################################ @@ -215,9 +334,7 @@ class Login extends Base{ * $road(是手机还是邮箱还是其他) 字符串 默认tel或email */ public function send_phone_email_code($data = ['data'=>'18530934717']){ - // dump(cache('linshi')); - // die; - // $data = input('post.'); + if(count(input('post.')) > 0){ $data = input('post.'); } @@ -235,15 +352,10 @@ class Login extends Base{ $road = 'tel'; }else{ $result = $this->send_email_code([$data['data']],['title'=>'体测APP验证码','from_user_name'=>'体测APP','content'=>$num]); - // dump($result); $road = 'email'; } - // dump($result); - // dump($road); - // die; if(is_array($result) && $result['code'] == 0){ cache($data['data'], $num, $this->code_time); - // dump($data['data']."_".$data['road']."_".$data['type']); // return $this->msg(['code'=>$num]); return $this->msg([]); // return true; @@ -291,8 +403,7 @@ class Login extends Base{ // 关闭cURL会话 curl_close($ch); // 处理响应 - // dump($response); - cache('linshi', $response); + if ($response) { return json_decode($response,true); } else { @@ -361,7 +472,7 @@ class Login extends Base{
     
    - QingCe! + Reedaw!
     
    @@ -373,7 +484,7 @@ class Login extends Base{
     
    - 感谢您选择青测产品! + 感谢您选择锐动产品!
     
    @@ -434,8 +545,6 @@ class Login extends Base{ '; $mail->Body = $neirong; //邮件主体内容 - // dump($address); - // die; //发送 if (!$mail->Send()) { @@ -451,10 +560,7 @@ class Login extends Base{ public function check_code($data = 18530934717 , $code = 123456){ // // 默认验证码正确 - // return true; - // dump($data); - // dump(cache($data)); - // die; + if(cache($data) == false){ return '验证码过期'; }else{ diff --git a/application/appbackups/controller/Myinformation.php b/application/appbackups/controller/Myinformation.php index b03cc1d..cce171d 100644 --- a/application/appbackups/controller/Myinformation.php +++ b/application/appbackups/controller/Myinformation.php @@ -2,13 +2,15 @@ namespace app\app\controller; -use think\Controller; + use think\Db; -use app\app\controller\Login; +use app\testapp\controller\Login; class Myinformation extends Base{ - + protected $myinformation_use_db_name = [ + '1'=>'app_account_number', + ]; // 加 bcadd(,,20) // 减 bcsub(,,20) // 乘 bcmul(,,20) @@ -19,69 +21,151 @@ class Myinformation extends Base{ // 获取账号下信息 public function get_my_account_msg($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + $return_data = $this->get_my_account_msg_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->get_my_account_msg_action($data); } // 修改昵称 public function update_my_nickname($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','nickname'=>'']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('nickname', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['nickname'],'str')){ + return $this->msg(10005); + } + $return_data = $this->update_my_nickname_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('nickname', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->update_my_nickname_action($data); } // 邮箱/手机绑定 public function update_my_account_msg($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','data'=>'tsf3920322@126.com','code'=>'123456']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('data', $data) || !array_key_exists('token', $data) || !array_key_exists('code', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'intnum')){ + return $this->msg(10005); + } + + $return_data = $this->update_my_account_msg_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('data', $data) || !array_key_exists('token', $data) || !array_key_exists('code', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->update_my_account_msg_action($data); } // 修改密码 public function update_my_password($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','password'=>'ceshi1','c_password'=>'ceshi1']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['c_password'],'str')){ + return $this->msg(10005); + } + $return_data = $this->update_my_password_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - // unset($data['token']); - return $this->update_my_password_action($data); + } ################################################################业务################################################################ ################################################################get_my_account_msg public function get_my_account_msg_action($data){ - $result = Db::table('app_account_number')->where(['token'=>$data['token'],'is_del'=>0])->find(); + $result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->find(); if($result){ return $this->msg([ 'my_tel'=>$result['tel'], @@ -98,7 +182,7 @@ class Myinformation extends Base{ } ################################################################update_my_nickname public function update_my_nickname_action($data){ - $result = Db::table('app_account_number')->where(['token'=>$data['token'],'is_del'=>0])->update([ + $result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([ 'nickname'=>$data['nickname'], 'update_time'=>date('Y-m-d H:i:s') ]); @@ -119,9 +203,7 @@ class Myinformation extends Base{ if($montage_data == false){ return $this->msg(10005); } - // dump($data); - // die; - $result = Db::table('app_account_number')->where(['token'=>$data['token'],'is_del'=>0])->update([ + $result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([ $montage_data=>$data['data'], 'update_time'=>date('Y-m-d H:i:s') ]); @@ -139,7 +221,7 @@ class Myinformation extends Base{ if($data['password'] == ''){ return $this->msg(10003,'密码不能为空'); } - $result = Db::table('app_account_number')->where(['token'=>$data['token'],'is_del'=>0])->update([ + $result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([ 'password'=>$data['password'], 'update_time'=>date('Y-m-d H:i:s') ]); diff --git a/application/appbackups/controller/Pagingcontrast.php b/application/appbackups/controller/Pagingcontrast.php index b829f76..ef1a78c 100644 --- a/application/appbackups/controller/Pagingcontrast.php +++ b/application/appbackups/controller/Pagingcontrast.php @@ -2,113 +2,232 @@ namespace app\app\controller; -use think\Controller; use think\Db; -use \think\Validate; -use app\app\controller\Calculatebody; -use app\app\controller\Skip; class Pagingcontrast extends Base{ protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6']; protected $db_name = ['2'=>'app_card_body_data','6'=>'app_card_skip_data','8'=>'app_card_vitalcapacity_data']; + protected $pagingcontrast_use_db_name = [ + '1'=>'app_card_body_data', + '2'=>'app_card_skip_data', + '3'=>'app_card_vitalcapacity_data', + '4'=>'app_user_data', + ]; protected $request_result = [ '2'=>['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI',''],'fat_w'=>['脂肪量','kg'],'fat_r'=>['脂肪率','%'],'muscleval'=>['肌肉量','kg'],'muscle'=>['肌肉率','%'],'proteinval'=>['蛋白量','kg'],'protein'=>['蛋白率','%'],'water'=>['水分',''],'bone'=>['骨重','kg'],'visceral'=>['内脏指数',''],'sfr'=>['皮下脂肪','%'],'kcal'=>['基础代谢','kcal'],'un_fat_w_weight'=>['去脂体重','kg'],'body_age'=>['体龄',''],'body_level'=>['肥胖等级',''],'body_type'=>['体型','']], '6'=>['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']], '8'=>['one_val'=>['第一次','ml'],'two_val'=>['第二次','ml'],'three_val'=>['第三次','ml'],'average_val'=>['三次平均','ml'],'score'=>['最后成绩','分']] ]; - protected $pagesize = 10; - ################################################请求接口################################################ ################################################请求接口################################################ ################################################请求接口################################################ // 获取记录信息(分组)(包含身体、跳绳、肺活量) public function get_all_record_data_group($data = ['aud_id'=>'26','s_time'=>'2024-04-01','e_time'=>'2024-06-12','token'=>'0dafb98a10995c98b5a33b7d59d986ca','type'=>'6']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if(array_key_exists($data['type'],$this->db_name)){ - return $this->jump_transfer_interface_record($data,'group'); - }else{ - return $this->msg(10005); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + if(array_key_exists($data['type'],$this->db_name)){ + $return_data = $this->jump_transfer_interface_record($data,'group'); + }else{ + $return_data = $this->msg(10005); + } + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 获取记录信息(分页)(包含身体、跳绳、肺活量) public function get_all_record_data_page($data = ['aud_id'=>'25','page'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca','type'=>'2']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('page', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if(array_key_exists($data['type'],$this->db_name)){ - return $this->jump_transfer_interface_record($data,'page'); - }else{ - return $this->msg(10005); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('page', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + if(array_key_exists($data['type'],$this->db_name)){ + $return_data = $this->jump_transfer_interface_record($data,'page'); + }else{ + $return_data = $this->msg(10005); + } + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } // 获取详细历史数据信息(包含身体、跳绳、肺活量) public function get_all_record_detailed_information($data = ['id'=>'39','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->jump_transfer_interface_detailed($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->jump_transfer_interface_detailed($data); } // 数据对比(包含身体、跳绳、肺活量) public function get_all_card_data_contrast($data = ['before_id'=>'837','after_id'=>'836','type'=>'6','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['before_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['after_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->jump_transfer_interface_data_contrast($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // $data = explode(',',$data['id_arr']); - // dump($data); - // die; - return $this->jump_transfer_interface_data_contrast($data); + } // 删除历史数据 public function del_all_record_data($data = ['id'=>'29','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $user_data = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->update(['is_del'=>1]); - if($user_data){ - return $this->msg([]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $user_data = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->update(['is_del'=>1]); + if($user_data){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } ################################################请求接口################################################ ################################################请求接口################################################ @@ -125,15 +244,6 @@ class Pagingcontrast extends Base{ } public function jump_transfer_interface_detailed($data){ return $this->get_all_detaile_data_msg($data); - - // if($data['type'] == '2'){ - // return $this->get_body_detaile_data_msg($data); - // }else if($data['type'] == '6'){ - // return $this->get_skip_detaile_data_msg($data); - // // return $this->msg(10005); - // }else if($data['type'] == '8'){ - // // return $this->get_body_record_data($data,$str); - // } } public function jump_transfer_interface_data_contrast($data){ if($data['type'] == '2'){ @@ -164,7 +274,7 @@ class Pagingcontrast extends Base{ height_val as v1, weight_val as v2, bmi_val as v3 - from app_card_body_data + from ".$this->pagingcontrast_use_db_name['1']." where aud_id='".$data['aud_id']."' and record_time between '".$data['s_time']."' and '".$data['e_time']."' and is_del = 0 @@ -183,8 +293,8 @@ class Pagingcontrast extends Base{ ]); } }else{ - $result = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,height_val,weight_val,bmi_val")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); - $return_result['totalrows'] = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id']])->count(); + $result = Db::table($this->pagingcontrast_use_db_name['1'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,height_val,weight_val,bmi_val")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); + $return_result['totalrows'] = Db::table($this->pagingcontrast_use_db_name['1'])->where(['aud_id'=>$data['aud_id']])->count(); $return_result['rows'] = []; $return_result['pageno'] = $data['page']; $return_result['pagesize'] = $this->pagesize; @@ -220,7 +330,7 @@ class Pagingcontrast extends Base{ jump_num as v1, jump_time as v2, jump_kcal as v3 - from app_card_skip_data + from ".$this->pagingcontrast_use_db_name['2']." where aud_id='".$data['aud_id']."' and record_time between '".$data['s_time']."' and '".$data['e_time']."' and is_del = 0 @@ -240,8 +350,8 @@ class Pagingcontrast extends Base{ ]); } }else{ - $result = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,jump_num,jump_time,jump_kcal")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); - $return_result['totalrows'] = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->count(); + $result = Db::table($this->pagingcontrast_use_db_name['2'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,jump_num,jump_time,jump_kcal")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); + $return_result['totalrows'] = Db::table($this->pagingcontrast_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->count(); $return_result['rows'] = []; $return_result['pageno'] = $data['page']; $return_result['pagesize'] = $this->pagesize; @@ -280,7 +390,7 @@ class Pagingcontrast extends Base{ three_val as v3, average_val as v4, score as v5 - from app_card_vitalcapacity_data + from ".$this->pagingcontrast_use_db_name['3']." where aud_id='".$data['aud_id']."' and record_time between '".$data['s_time']."' and '".$data['e_time']."' and is_del = 0 @@ -304,8 +414,8 @@ class Pagingcontrast extends Base{ ]); } }else{ - $result = Db::table('app_card_vitalcapacity_data')->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,one_val,two_val,three_val,average_val,score")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); - $return_result['totalrows'] = Db::table('app_card_vitalcapacity_data')->where(['aud_id'=>$data['aud_id']])->count(); + $result = Db::table($this->pagingcontrast_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->field("id,record_time,REPLACE(record_time, '-', '-') AS b_time,one_val,two_val,three_val,average_val,score")->order('record_time desc')->page($data['page'],$this->pagesize)->select(); + $return_result['totalrows'] = Db::table($this->pagingcontrast_use_db_name['3'])->where(['aud_id'=>$data['aud_id']])->count(); $return_result['rows'] = []; $return_result['pageno'] = $data['page']; $return_result['pagesize'] = $this->pagesize; @@ -362,7 +472,6 @@ class Pagingcontrast extends Base{ // 数据对比 public function get_body_data_contrast($data){ - // dump($data); $data2 = [$data['before_id'],$data['after_id']]; $data3 = implode(',',$data2); $calculate_arr = []; @@ -389,13 +498,11 @@ class Pagingcontrast extends Base{ aud.gender, aud.birthday, aud.head_pic - from app_card_body_data as acbd - left join app_user_data as aud on acbd.aud_id=aud.id + from ".$this->pagingcontrast_use_db_name['1']." as acbd + left join ".$this->pagingcontrast_use_db_name['4']." as aud on acbd.aud_id=aud.id where acbd.id in ($data3) and acbd.is_del = 0 "); - // dump($result); - // die; if(!$result || count($result)<2){ return $this->msg(10004); } @@ -447,7 +554,6 @@ class Pagingcontrast extends Base{ } // 数据对比 public function get_skip_data_contrast($data){ - // dump($data); $data2 = [$data['before_id'],$data['after_id']]; $data3 = implode(',',$data2); $calculate_arr = []; @@ -463,8 +569,8 @@ class Pagingcontrast extends Base{ aud.gender, aud.birthday, aud.head_pic - from app_card_skip_data as acsd - left join app_user_data as aud on acsd.aud_id=aud.id + from ".$this->pagingcontrast_use_db_name['2']." as acsd + left join ".$this->pagingcontrast_use_db_name['4']." as aud on acsd.aud_id=aud.id where acsd.id in ($data3) and acsd.is_del = 0 "); @@ -488,8 +594,6 @@ class Pagingcontrast extends Base{ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); $return_data['list'] = []; - // dump($calculate_arr); - // die; foreach ($calculate_arr['before'] as $key => $value) { if(in_array($key, ['jump_num','jump_time','jump_kcal'])){ $before_arr = $value; @@ -525,7 +629,6 @@ class Pagingcontrast extends Base{ } // 数据对比 public function get_vitalcapacity_data_contrast($data){ - // dump($data); $data2 = [$data['before_id'],$data['after_id']]; $data3 = implode(',',$data2); $calculate_arr = []; @@ -543,8 +646,8 @@ class Pagingcontrast extends Base{ aud.gender, aud.birthday, aud.head_pic - from app_card_vitalcapacity_data as acsd - left join app_user_data as aud on acsd.aud_id=aud.id + from ".$this->pagingcontrast_use_db_name['3']." as acsd + left join ".$this->pagingcontrast_use_db_name['4']." as aud on acsd.aud_id=aud.id where acsd.id in ($data3) and acsd.is_del = 0 "); @@ -568,8 +671,6 @@ class Pagingcontrast extends Base{ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); $return_data['list'] = []; - // dump($calculate_arr); - // die; foreach ($calculate_arr['before'] as $key => $value) { if(in_array($key, ['one_val','two_val','three_val','average_val','score_val'])){ $before_arr = $value; diff --git a/application/appbackups/controller/Skip.php b/application/appbackups/controller/Skip.php index 38bca8f..b5985b7 100644 --- a/application/appbackups/controller/Skip.php +++ b/application/appbackups/controller/Skip.php @@ -2,14 +2,17 @@ namespace app\app\controller; -use think\Controller; use think\Db; class Skip extends Base{ protected $color = ['#FF5656','#FFAB00','#5AD06D','#6492F6','#3967D6']; - protected $curve_data_format = ['jump_num'=>['跳绳个数','个数/个','#009DFF'],'jump_time'=>['跳绳时长','时长/分','#009DFF'],'jump_kcal'=>['消耗卡路里','卡路里/kcal','#009DFF']]; - + protected $curve_data_format = ['jump_num'=>['跳绳个数','个','#009DFF'],'jump_time'=>['跳绳时长','分钟','#009DFF'],'jump_kcal'=>['消耗卡路里','kcal','#009DFF']]; + protected $skip_use_db_name = [ + '1'=>'app_card_skip_data', + '2'=>'app_user_data', + '3'=>'app_card_body_data', + ]; protected $result_end_data_mould = [ 'name'=>'', 'value'=>'', @@ -27,127 +30,230 @@ class Skip extends Base{ ################################################################接口################################################################ // 手动记录 public function skip_manual_recording($data = ['aud_id'=>'61','r_time'=>'2024-07-24','num'=>'369','time_m'=>'02','time_s'=>'42','type'=>'free','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('r_time', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['r_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'str')){ + return $this->msg(10005); + } + if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ + $return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); + } + if($data['num'] <= 0){ + $return_data = $this->msg(10005,'跳绳数不能小于等于0'); + } + if(abs($data['time_s']) >= 60){ + $return_data = $this->msg(10005,'秒钟值不能大于60'); + } + unset($data['token']); + if($this->validate_user_identity($data['aud_id']) === false){ + $return_data = $this->msg(10003); + } + $return_data = $this->skip_manual_recording_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - // dump(bcmul('1.23', '4.56', 2)); - // dump(bcround('18.777', 2)); - // // phpinfo(); - // // opcache_reset(); - // die; - - if(!array_key_exists('aud_id', $data) || !array_key_exists('r_time', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ - return $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); - } - if($data['num'] <= 0){ - return $this->msg(10005,'跳绳数不能小于等于0'); - } - if(abs($data['time_s']) >= 60){ - return $this->msg(10005,'秒钟值不能大于60'); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if($this->validate_user_identity($data['aud_id']) === false){ - return $this->msg(10003); - } - // die; - return $this->skip_manual_recording_action($data); + } // 设备记录记录 public function skip_manual_recording_device($data = ['aud_id'=>'58','num'=>'582','time_m'=>'10','time_s'=>'00','type'=>'free','kcal'=>'200','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('kcal', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['kcal'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'str')){ + return $this->msg(10005); + } + if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ + $return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); + } + if($data['num'] <= 0){ + $return_data = $this->msg(10005,'跳绳数不能小于等于0'); + } + if(abs($data['time_s']) >= 60){ + $return_data = $this->msg(10005,'秒钟值不能大于60'); + } + unset($data['token']); + if($this->validate_user_identity($data['aud_id']) === false){ + $return_data = $this->msg(10003); + } + $return_data = $this->skip_manual_recording_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('kcal', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ - return $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); - } - if($data['num'] <= 0){ - return $this->msg(10005,'跳绳数不能小于等于0'); - } - if(abs($data['time_s']) >= 60){ - return $this->msg(10005,'秒钟值不能大于60'); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - if($this->validate_user_identity($data['aud_id']) === false){ - return $this->msg(10003); - } - return $this->skip_manual_recording_action($data); + } // 今日数据 public function skip_today_data($data = ['aud_id'=>'26','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->skip_today_data_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // dump($data); - // die; - return $this->skip_today_data_action($data); + } // 曲线 - public function skip_curve_chart($data = ['aud_id'=>'83','time'=>'2024-07-24','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function skip_curve_chart($data = ['aud_id'=>'9','time'=>'2024-10','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->skip_curve_chart_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->skip_curve_chart_action($data); + } // 删除历史数据 public function skip_del_record_data($data = ['id'=>'16','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $user_data = Db::table('app_card_skip_data')->where(['id'=>$data['id']])->update(['is_del'=>1]); - if($user_data){ - return $this->msg([]); - }else{ - return $this->msg(10002); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $user_data = Db::table($this->skip_use_db_name['1'])->where(['id'=>$data['id']])->update(['is_del'=>1]); + if($user_data){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } + } ################################################################接口################################################################ ################################################################接口################################################################ ################################################################接口################################################################ ################################################################skip_manual_recording public function skip_manual_recording_action($data){ + // 分秒转换为秒 $data['time'] = abs($data['time_m'])*60+abs($data['time_s']); - $user_msg_content = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->count(); + $user_msg_content = Db::table($this->skip_use_db_name['2'])->where(['id'=>$data['aud_id']])->count(); if($user_msg_content<=0){ return $this->msg(10004); } if(!array_key_exists('kcal', $data)){ - $last_data_body = Db::table('app_card_body_data')->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc,id desc')->field('id,weight_val,record_time')->find(); + $last_data_body = Db::table($this->skip_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc,id desc')->field('id,weight_val,record_time')->find(); if(!$last_data_body){ - $last_data_body = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,weight as weight_val')->find(); + $last_data_body = Db::table($this->skip_use_db_name['2'])->where(['id'=>$data['aud_id']])->field('id,weight as weight_val')->find(); if(!$last_data_body){ return $this->msg(10004); } @@ -179,13 +285,13 @@ class Skip extends Base{ if(strlen($data_set['record_time']) <= 12){ $data_set['record_time'] = $this->addCurrentTimeToDateString($data_set['record_time']); } - $last_data_body = Db::table('app_card_skip_data')->insert($data_set); + $last_data_body = Db::table($this->skip_use_db_name['1'])->insert($data_set); $result = [ 'today_jump_num'=>0, 'today_jump_time'=>0, 'today_jump_kcal'=>0, ]; - $all_data = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); + $all_data = Db::table($this->skip_use_db_name['1'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); foreach ($all_data as $key => $value) { $result['today_jump_num'] = $result['today_jump_num']+$value['jump_num']; $result['today_jump_time'] = $result['today_jump_time']+$value['jump_time']; @@ -204,8 +310,8 @@ class Skip extends Base{ } ################################################################skip_today_data public function skip_today_data_action($data){ - $all_data = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); - $last_data = Db::table('app_card_skip_data')->where(['aud_id'=>$data['aud_id']])->order('record_time desc,id desc')->field('id,jump_num,jump_time,jump_kcal,record_time')->find(); + $all_data = Db::table($this->skip_use_db_name['1'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select(); + $last_data = Db::table($this->skip_use_db_name['1'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc,id desc')->field('id,jump_num,jump_time,jump_kcal,record_time')->find(); $result = [ 'today_jump_num'=>0, 'today_jump_time'=>0, @@ -261,9 +367,7 @@ class Skip extends Base{ } // 使用查询构造器进行查询 - $result = Db::name('app_card_skip_data')->where($map)->field('jump_num,jump_time,jump_kcal,aud_id,record_time,jump_type,DATEPART(hour, record_time) AS hour,DATEPART(minute, record_time) AS minute,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); - // dump($result); - // die; + $result = Db::name($this->skip_use_db_name['1'])->where($map)->field('jump_num,jump_time,jump_kcal,aud_id,record_time,jump_type,DATEPART(hour, record_time) AS hour,DATEPART(minute, record_time) AS minute,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); $return_data = []; if(count($timeData) == 3){ $key_condition = 'hour'; @@ -272,7 +376,6 @@ class Skip extends Base{ }else if(count($timeData) == 1){ $key_condition = 'month'; } - // dump($key_condition); foreach ($this->curve_data_format as $key => $value) { $temporary_arr['title'] = $value[0].'('.$value[1].')'; $temporary_arr['key'] = $key; @@ -282,19 +385,9 @@ class Skip extends Base{ $temporary_arr['line']['series'][0]['data'] = []; foreach ($result as $k => $v) { if($key_condition == 'hour'){ - // 每一次的记录都添加进去 array_push($temporary_arr['line']['categories'],$result[$k]['hour'].':'.$result[$k]['minute']); array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]); - - // // 根据小时分组 - // if(in_array($result[$k][$key_condition].'时',$temporary_arr['line']['categories'])){ - // $num = array_search($result[$k][$key_condition].'时', $temporary_arr['line']['categories']); - // $temporary_arr['line']['series'][0]['data'][$num] = bcadd($temporary_arr['line']['series'][0]['data'][$num],$result[$k][$key],2); - // }else{ - // array_push($temporary_arr['line']['categories'],$result[$k][$key_condition].'时'); - // array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]); - // } }else if($key_condition == 'day'){ // 根据天分组 if(in_array($result[$k]['month'].'/'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){ @@ -316,11 +409,14 @@ class Skip extends Base{ } } } - // dump($temporary_arr); array_push($return_data,$temporary_arr); } foreach ($return_data[1]['line']['series'][0]['data'] as $key => $value) { + $return_data[1]['line']['series'][0]['data'][$key] = bcdiv($return_data[1]['line']['series'][0]['data'][$key],60,2); + // $jump_time_long = $this->handle_hour_branch_second($return_data[1]['line']['series'][0]['data'][$key]); + // $return_data[1]['line']['series'][0]['data'][$key] = $jump_time_long['h'].':'.$jump_time_long['m'].':'.$jump_time_long['s']; + } return $this->msg($return_data); } diff --git a/application/appbackups/controller/Sportstesting.php b/application/appbackups/controller/Sportstesting.php index 7c192b8..e859812 100644 --- a/application/appbackups/controller/Sportstesting.php +++ b/application/appbackups/controller/Sportstesting.php @@ -2,18 +2,19 @@ namespace app\app\controller; -use think\Controller; + use think\Db; -use app\bj\controller\Common; -use think\Log; -use \think\Validate; -use app\app\controller\Calculatebody; -use app\app\controller\Skip; + use Exception; class Sportstesting extends Base{ protected $color = ['#FF5656','#FF5656','#5AD06D','#6492F6','#3967D6']; + protected $sportstesting_use_db_name = [ + '1'=>'admin_estimate', + '2'=>'app_sportstesting_data', + '3'=>'app_user_data', + ]; protected $page_num = 10; protected $default_address = '上海'; protected $city_data_rule_name = [ @@ -35,561 +36,6 @@ class Sportstesting extends Base{ '4'=>'分钟秒钟(例1000米跑)', ]; - protected $city_data_rule2 = [ - '北京'=>[ - 'xc'=>[ - 'xc_1'=>[ - '1'=>[ - '1000米'=>[ - 'list'=>[ - '4:05'=>'8', - '4:11'=>'7.5', - '4:18'=>'7', - '4:26'=>'6.5', - '4:35'=>'6', - '4:45'=>'5.5', - '4:55'=>'5', - '5:01'=>'4.5', - '5:07'=>'4', - '5:13'=>'3.5', - '5:20'=>'3', - '5:27'=>'2.5', - '5:34'=>'2', - '5:42'=>'1.5', - '5:50'=>'1', - '5:59'=>'0.5', - '6:00'=>'0' - ], - 'unit'=>'分/秒', - 'value'=>'00:00', - 'proportion'=>'1', - 'type'=>'4', - ], - ], - '2'=>[ - '800米'=>[ - 'list'=>[ - '3:55'=>'8', - '4:01'=>'7.5', - '4:08'=>'7', - '4:16'=>'6.5', - '4:25'=>'6', - '4:35'=>'5.5', - '4:45'=>'5', - '4:49'=>'4.5', - '4:53'=>'4', - '4:57'=>'3.5', - '5:02'=>'3', - '5:07'=>'2.5', - '5:12'=>'2', - '5:19'=>'1.5', - '5:26'=>'1', - '5:35'=>'0.5', - '5:36'=>'0', - ], - 'unit'=>'分/秒', - 'value'=>'00:00', - 'proportion'=>'1', - 'type'=>'4', - ] - ], - ], - 'xc_2'=>[ - '1'=>[ - '引体向上'=>[ - 'list'=>[ - '11'=>'8', - '10'=>'7.5', - '9'=>'7', - '8'=>'6.5', - '7'=>'6', - '6'=>'5.5', - '5'=>'5', - '4'=>'4.5', - '3'=>'4', - '2'=>'3.5', - '1'=>'3' - ], - 'unit'=>'次', - 'value'=>'0', - 'proportion'=>'1', - 'type'=>'1', - ], - '双杠臂屈伸'=>[ - 'list'=>[ - '11'=>'8', - '10'=>'7.5', - '9'=>'7', - '8'=>'6.5', - '7'=>'6', - '6'=>'5.5', - '5'=>'5', - '4'=>'4.5', - '3'=>'4', - '2'=>'3.5', - '1'=>'3' - ], - 'unit'=>'次', - 'value'=>'0', - 'proportion'=>'1', - 'type'=>'1', - ], - ], - '2'=>[ - '斜身引体'=>[ - 'list'=>[ - '40'=>'8', - '36'=>'7.5', - '32'=>'7', - '28'=>'6.5', - '24'=>'6', - '20'=>'5.5', - '16'=>'5', - '12'=>'4.5', - '10'=>'4', - '9'=>'3.5', - '8'=>'3', - '7'=>'2.5', - '6'=>'2', - '5'=>'1.5', - '4'=>'1', - '3'=>'0.5', - '2'=>'0' - ], - 'unit'=>'次', - 'value'=>'0', - 'proportion'=>'1', - 'type'=>'1', - ], - '仰卧起坐'=>[ - 'list'=>[ - '42'=>'8', - '40'=>'7.5', - '37'=>'7', - '34'=>'6.5', - '30'=>'6', - '26'=>'5.5', - '22'=>'5', - '21'=>'4.5', - '20'=>'4', - '19'=>'3.5', - '18'=>'3', - '17'=>'2.5', - '16'=>'2', - '15'=>'1.5', - '14'=>'1', - '13'=>'0.5', - '12'=>'0' - ], - 'unit'=>'次', - 'value'=>'0', - 'proportion'=>'1', - 'type'=>'1', - ], - ], - ], - 'xc_3'=>[ - '1'=>[ - '足球运球/射门'=>['list'=>['19.5'=>'8','20.0'=>'7.5','20.5'=>'7','21.0'=>'6.5','21.5'=>'6','22.0'=>'5.5','22.5'=>'5','23.0'=>'4.5','23.8'=>'4','24.6'=>'3.5','25.4'=>'3','26.2'=>'2.5','27.0'=>'2','27.8'=>'1.5','28.6'=>'1','29.4'=>'0.5','29.5'=>'0'],'unit'=>'秒','value'=>'00.0','proportion'=>'1','type'=>'2',], - ], - '2'=>[ - '足球运球/射门'=>['list'=>['21.0'=>'8','21.5'=>'7.5','22.0'=>'7','22.5'=>'6.5','23.0'=>'6','23.5'=>'5.5','24.0'=>'5','24.5'=>'4.5','25.3'=>'4','26.1'=>'3.5','26.9'=>'3','27.7'=>'2.5','28.5'=>'2','29.3'=>'1.5','30.1'=>'1','30.9'=>'0.5','31.0'=>'0'],'unit'=>'秒','value'=>'00.0','proportion'=>'1','type'=>'2',], - ], - ], - 'xc_4'=>[ - '1'=>[ - '100米游泳'=>['list'=>['2:25'=>'6','2:35'=>'5.5','2:45'=>'5','2:55'=>'4.5','3:05'=>'4','3:15'=>'3.5','3:30'=>'3','3:40'=>'2.5','3:50'=>'2','4:00'=>'1.5','4:10'=>'1','4:20'=>'0.5','4:21'=>'0'],'unit'=>'分/秒','value'=>'00:00','proportion'=>'1','type'=>'4',], - ], - '2'=>[ - '100米游泳'=>['list'=>['2:40'=>'6','2:48'=>'5.5','2:56'=>'5','3:04'=>'4.5','3:12'=>'4','3:20'=>'3.5','3:30'=>'3','3:40'=>'2.5','3:50'=>'2','4:00'=>'1.5','4:10'=>'1','4:20'=>'0.5','4:21'=>'0'],'unit'=>'分/秒','value'=>'00:00','proportion'=>'1','type'=>'4',], - ], - ], - ], - 'gc'=>[ - 'gc_8_m'=>[ - '1'=>[ - 'BMI'=>['list'=>['15.6'=>'80','22.5'=>'100','25.2'=>'80','100'=>'60'],'unit'=>'','value'=>'0','proportion'=>'0.15','type'=>'2',], - '肺活量'=>['list'=>['3940'=>'100','3820'=>'95','3700'=>'90','3450'=>'85','3200'=>'80','3080'=>'78','2960'=>'76','2840'=>'74','2720'=>'72','2600'=>'70','2480'=>'68','2360'=>'66','2240'=>'64','2120'=>'62','2000'=>'60','1890'=>'50','1780'=>'40','1670'=>'30','1560'=>'20','1450'=>'10',],'unit'=>'ml','value'=>'0','proportion'=>'0.15','type'=>'1',], - '50米跑'=>[ - 'list'=>[ - '7.5'=>'100', - '7.6'=>'95', - '7.7'=>'90', - '7.8'=>'85', - '7.9'=>'80', - '8.1'=>'78', - '8.3'=>'76', - '8.5'=>'74', - '8.7'=>'72', - '8.9'=>'70', - '9.1'=>'68', - '9.3'=>'66', - '9.5'=>'64', - '9.7'=>'62', - '9.9'=>'60', - '10.1'=>'50', - '10.3'=>'40', - '10.5'=>'30', - '10.7'=>'20', - '10.9'=>'10', - ], - 'unit'=>'秒', - 'value'=>'00.0', - 'proportion'=>'0.2', - 'type'=>'2', - ], - '坐位体前屈'=>[ - 'list'=>[ - '19.6'=>'100', - '17.7'=>'95', - '15.8'=>'90', - '13.7'=>'85', - '11.6'=>'80', - '10.3'=>'78', - '9'=>'76', - '7.7'=>'74', - '6.4'=>'72', - '5.1'=>'70', - '3.8'=>'68', - '2.5'=>'66', - '1.2'=>'64', - '-0.1'=>'62', - '-1.4'=>'60', - '-2.6'=>'50', - '-3.8'=>'40', - '-5'=>'30', - '-6.2'=>'20', - '-7.4'=>'10', - ], - 'unit'=>'cm', - 'value'=>'00.0', - 'proportion'=>'0.1', - 'type'=>'3', - ], - '立定跳远'=>[ - 'list'=>[ - '240'=>'100', - '233'=>'95', - '226'=>'90', - '218'=>'85', - '210'=>'80', - '206'=>'78', - '202'=>'76', - '198'=>'74', - '194'=>'72', - '190'=>'70', - '186'=>'68', - '182'=>'66', - '178'=>'64', - '174'=>'62', - '170'=>'60', - '165'=>'50', - '160'=>'40', - '155'=>'30', - '150'=>'20', - '145'=>'10', - ], - 'unit'=>'cm', - 'value'=>'0', - 'proportion'=>'0.1', - 'type'=>'1', - ], - '引体向上'=>[ - 'list'=>[ - '14'=>'100', - '13'=>'95', - '12'=>'90', - '11'=>'85', - '10'=>'80', - '9'=>'76', - '8'=>'72', - '7'=>'68', - '6'=>'64', - '5'=>'60', - '4'=>'50', - '3'=>'40', - '2'=>'30', - '1'=>'20', - '0'=>'10', - ], - 'unit'=>'个', - 'value'=>'0', - 'proportion'=>'0.1', - 'type'=>'1', - 'add_point'=>[ - '10'=>'10', - '9'=>'9', - '8'=>'8', - '7'=>'7', - '6'=>'6', - '5'=>'5', - '4'=>'4', - '3'=>'3', - '2'=>'2', - '1'=>'1', - ] - ], - '男生1000米'=>[ - 'list'=>[ - '3:50'=>'100', - '3:55'=>'95', - '4:00'=>'90', - '4:07'=>'85', - '4:15'=>'80', - '4:20'=>'78', - '4:25'=>'76', - '4:30'=>'74', - '4:35'=>'72', - '4:40'=>'70', - '4:45'=>'68', - '4:50'=>'66', - '4:55'=>'64', - '5:00'=>'62', - '5:05'=>'60', - '5:25'=>'50', - '5:45'=>'40', - '6:05'=>'30', - '6:25'=>'20', - '6:45'=>'10', - ], - 'unit'=>'分/秒', - 'value'=>'00:00', - 'proportion'=>'0.2', - 'type'=>'4', - 'add_point'=>[ - '-35'=>'10', - '-32'=>'9', - '-29'=>'8', - '-26'=>'7', - '-23'=>'6', - '-20'=>'5', - '-16'=>'4', - '-12'=>'3', - '-8'=>'2', - '-4'=>'1', - ] - ], - ], - '2'=>[ - 'BMI'=>[ - 'list'=>[ - '15.2'=>'80', - '22.2'=>'100', - '24.8'=>'80', - '100'=>'60' - ], - 'unit'=>'', - 'value'=>'00.0', - 'proportion'=>'0.15', - 'type'=>'2', - ], - '肺活量'=>[ - 'list'=>[ - '2900'=>'100', - '2850'=>'95', - '2800'=>'90', - '2650'=>'85', - '2500'=>'80', - '2400'=>'78', - '2300'=>'76', - '2200'=>'74', - '2100'=>'72', - '2000'=>'70', - '1900'=>'68', - '1800'=>'66', - '1700'=>'64', - '1600'=>'62', - '1500'=>'60', - '1460'=>'50', - '1420'=>'40', - '1380'=>'30', - '1340'=>'20', - '1300'=>'10', - ], - 'unit'=>'ml', - 'value'=>'0', - 'proportion'=>'0.15', - 'type'=>'1', - ], - '50米跑'=>[ - 'list'=>[ - '8'=>'100', - '8.1'=>'95', - '8.2'=>'90', - '8.5'=>'85', - '8.8'=>'80', - '9'=>'78', - '9.2'=>'76', - '9.4'=>'74', - '9.6'=>'72', - '9.8'=>'70', - '10'=>'68', - '10.2'=>'66', - '10.4'=>'64', - '10.6'=>'62', - '10.8'=>'60', - '11'=>'50', - '11.2'=>'40', - '11.4'=>'30', - '11.6'=>'20', - '11.8'=>'10', - ], - 'unit'=>'秒', - 'value'=>'00.0', - 'proportion'=>'0.2', - 'type'=>'2', - ], - '坐位体前屈'=>[ - 'list'=>[ - '22.7'=>'100', - '21'=>'95', - '19.3'=>'90', - '17.6'=>'85', - '15.9'=>'80', - '14.6'=>'78', - '13.3'=>'76', - '12'=>'74', - '10.7'=>'72', - '9.4'=>'70', - '8.1'=>'68', - '6.8'=>'66', - '5.5'=>'64', - '4.2'=>'62', - '2.9'=>'60', - '2.1'=>'50', - '1.3'=>'40', - '0.5'=>'30', - '-0.3'=>'20', - '-1.1'=>'10', - ], - 'unit'=>'cm', - 'value'=>'00.0', - 'proportion'=>'0.1', - 'type'=>'3', - ], - '立定跳远'=>[ - 'list'=>[ - '240'=>'100', - '233'=>'95', - '226'=>'90', - '218'=>'85', - '210'=>'80', - '206'=>'78', - '202'=>'76', - '198'=>'74', - '194'=>'72', - '190'=>'70', - '186'=>'68', - '182'=>'66', - '178'=>'64', - '174'=>'62', - '170'=>'60', - '165'=>'50', - '160'=>'40', - '155'=>'30', - '150'=>'20', - '145'=>'10', - ], - 'unit'=>'cm', - 'value'=>'0', - 'proportion'=>'0.1', - 'type'=>'1', - ], - '一分钟仰卧起坐'=>[ - 'list'=>[ - '51'=>'100', - '49'=>'95', - '47'=>'90', - '44'=>'85', - '41'=>'80', - '39'=>'78', - '37'=>'76', - '35'=>'74', - '33'=>'72', - '31'=>'70', - '29'=>'68', - '27'=>'66', - '25'=>'64', - '23'=>'62', - '21'=>'60', - '19'=>'50', - '17'=>'40', - '15'=>'30', - '13'=>'20', - '11'=>'10', - ], - 'unit'=>'个', - 'value'=>'0', - 'proportion'=>'0.1', - 'type'=>'1', - 'add_point'=>[ - '13'=>'10', - '12'=>'9', - '11'=>'8', - '10'=>'7', - '9'=>'6', - '8'=>'5', - '7'=>'4', - '6'=>'3', - '4'=>'2', - '2'=>'1', - ] - ], - '女生800米'=>[ - 'list'=>[ - '3:30'=>'100', - '3:37'=>'95', - '3:44'=>'90', - '3:52'=>'85', - '4:00'=>'80', - '4:05'=>'78', - '4:10'=>'76', - '4:15'=>'74', - '4:20'=>'72', - '4:25'=>'70', - '4:30'=>'68', - '4:35'=>'66', - '4:40'=>'64', - '4:45'=>'62', - '4:50'=>'60', - '5:00'=>'50', - '5:10'=>'40', - '5:20'=>'30', - '5:30'=>'20', - '5:40'=>'10', - ], - 'unit'=>'分/秒', - 'value'=>'00:00', - 'proportion'=>'0.2', - 'type'=>'4', - 'add_point'=>[ - '-50'=>'10', - '-45'=>'9', - '-40'=>'8', - '-35'=>'7', - '-30'=>'6', - '-25'=>'5', - '-20'=>'4', - '-15'=>'3', - '-10'=>'2', - '-5'=>'1', - ] - ], - ], - ], - 'gc_8_r'=>[ - '1'=>[ - '机测'=>[ - 'list'=>[],'unit'=>'分','value'=>'0','proportion'=>'1','type'=>'1',], - ], - '2'=>[ - '机测'=>[ - 'list'=>[],'unit'=>'分','value'=>'0','proportion'=>'1','type'=>'1',], - ] - ] - ] - ], - ]; // 加 bcadd(,,20) // 减 bcsub(,,20) @@ -600,134 +46,278 @@ class Sportstesting extends Base{ ################################################################接口################################################################ // 获取单个类型列表 public function sportstesting_get_type_list($data = ['address'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('address', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['address'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_type_list_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('address', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->sportstesting_get_type_list_action($data); + } // 获取地区类型列表 - public function sportstesting_get_region_list($data = ['parameter_data'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + public function sportstesting_get_region_list($data = ['parameter_data'=>'河北,石家庄市','gender'=>'0']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('gender', $data) || !array_key_exists('parameter_data', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['parameter_data'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->sportstesting_get_region_list_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('gender', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->sportstesting_get_region_list_action($data); + } // 获取估分最后一次数据 public function sportstesting_get_last_data($data = ['aud_id'=>'83','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_last_data_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // cache('sportstesting_get_last_data',json_encode($data)); - return $this->sportstesting_get_last_data_action($data); + } // 计算并存储数据 public function sportstesting_set_once_data($data = ['aud_id'=>'83','parameter_data'=>'辽宁,沈阳市','result_data'=>'','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - // $data = json_decode(cache('sportstesting_set_once_data'),true); - // dump($data); - - // die; - // return $this->dayin_data('sportstesting_set_once_data'); - if(count(input('post.')) > 0){ - $data = input('post.'); - } - - if(!array_key_exists('aud_id', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('result_data', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if(is_array($data['result_data']) && !empty($data['result_data'])){ - // 是个数组且不为空数组 - foreach ($data['result_data'] as $key => $value) { - foreach ($value['list'] as $k => $v) { - if(count($v['list']) <= 0){ - return $this->msg(10010,$v['name'].'内并未选择内容'); - } - if($v['is_choice'] >= 0 && count($v['list']) < $v['is_choice']){ - return $this->msg(10010,$v['name'].'内并缺少选项,请选择'.$v['is_choice'].'个选项'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + + if(!array_key_exists('aud_id', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('result_data', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['parameter_data'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005); + } + if(is_array($data['result_data']) && !empty($data['result_data'])){ + // 是个数组且不为空数组 + foreach ($data['result_data'] as $key => $value) { + foreach ($value['list'] as $k => $v) { + if(count($v['list']) <= 0){ + return $this->msg(10010,$v['name'].'内并未选择内容'); + } + if($v['is_choice'] >= 0 && count($v['list']) < $v['is_choice']){ + return $this->msg(10010,$v['name'].'内并缺少选项,请选择'.$v['is_choice'].'个选项'); + } + foreach ($v['list'] as $c_k => $c_v) { + if(count($c_v) <= 0){ + return $this->msg(10010,$v['name'].'选项内内容异常'); + } + } } } + }else{ + return $this->msg(10006); } + unset($data['token']); + $return_data = $this->sportstesting_set_once_data_action2($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - cache('sportstesting_set_once_data',json_encode($data)); - // return $this->msg($data); - unset($data['token']); - // return $this->msg($data); - - return $this->sportstesting_set_once_data_action2($data); - // return $this->sportstesting_set_once_data_action($data); + } // 获取估分历史列表 public function sportstesting_get_all_list($data = ['aud_id'=>'25','page'=>'1','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data) || !array_key_exists('page', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_all_list_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data) || !array_key_exists('page', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - // cache('sportstesting_get_all_list',json_encode($data)); - return $this->sportstesting_get_all_list_action($data); + } // 获取估分历史详情 public function sportstesting_get_one_details($data = ['id'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_one_details_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->sportstesting_get_one_details_action($data); + } // 获取估分已有的地区列表 public function sportstesting_get_city_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a','type'=>'1']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('type', $data)){ + $return_data = $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + unset($data['token']); + $return_data = $this->sportstesting_get_city_list_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('token', $data) || !array_key_exists('type', $data)){ - return $this->msg(10001); - } - // cache($data['token'], time()); - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->sportstesting_get_city_list_action($data); + } ################################################################业务################################################################ @@ -750,14 +340,9 @@ class Sportstesting extends Base{ // 全省地市一个规则start $db_condition = "province = '".$parameter_data[0]."'"; // 全省地市一个规则end - - $data = Db::table('admin_estimate')->where($db_condition)->find(); + $data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->find(); $data = json_decode($data['content'],true); - - // dump($data); - // die; $result = $this->handle_default_rule_list_content($data,$gender); - // die; return $this->msg($result); } ################################################sportstesting_get_region_list @@ -782,18 +367,18 @@ class Sportstesting extends Base{ $result['list'] = []; $result['total_score'] = 0; - $data = Db::table('admin_estimate')->where($db_condition)->select(); - // dump($data); - // die; + $data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->select(); + if(count($data) > 0){ if(count($data) > 1){ // 查到不止一条规则 return $this->msg(10004,'查询地址不够详细,请重新选择省市地区'); } - // dump(568); - // die; + $data = json_decode($data[0]['content'],true); $result = $this->handle_default_rule_list($data,$gender); + + // die; return $this->msg($result); }else{ return $this->msg(10004,'暂无该地区的估分规则,请选择其它地区'); @@ -802,7 +387,7 @@ class Sportstesting extends Base{ } ################################################sportstesting_get_last_data public function sportstesting_get_last_data_action($data){ - $user_data = Db::table('app_sportstesting_data')->where(['aud_id'=>$data['aud_id']])->order('id desc')->find(); + $user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->order('id desc')->find(); if($user_data){ $address = explode(',',$user_data['address']); @@ -816,20 +401,13 @@ class Sportstesting extends Base{ $result['area'] = count($address)>=3?$address[2]:''; return $this->msg($result); }else{ - $user_msg_data = Db::table('app_user_data')->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + $user_msg_data = Db::table($this->sportstesting_use_db_name['3'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); if(!$user_msg_data){ return $this->msg(10004); } $address = $this->default_address; - // dump($address); - // die; - $address_data = $this->sportstesting_get_region_list_action(['parameter_data'=>$address,'gender'=>$user_msg_data['gender']]); - // dump(json_decode($address_data->getContent(),true)); - // dump(get_object_vars($address_data)); - // die; $address_data = json_decode($address_data->getContent(),true); - // return $this->msg($address_data); if($address_data['code'] == 10004){ return $this->msg(10004); } @@ -839,16 +417,13 @@ class Sportstesting extends Base{ $result['province'] = count($address)>=1?$address[0]:''; $result['city'] = count($address)>=2?$address[1]:''; $result['area'] = count($address)>=3?$address[2]:''; - return $this->msg($result); } } ################################################sportstesting_get_all_list public function sportstesting_get_all_list_action($data){ - $user_data_num = Db::table('app_sportstesting_data')->where(['aud_id'=>$data['aud_id']])->count(); - $user_data = Db::table('app_sportstesting_data')->where(['aud_id'=>$data['aud_id']])->page($data['page'],$this->page_num)->order('id desc')->select(); - // dump($user_data); - // die; + $user_data_num = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->count(); + $user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->page($data['page'],$this->page_num)->order('id desc')->field('id,create_time,score,max_score,address')->select(); if($user_data){ $result = []; $result['totalrows'] = $user_data_num; @@ -860,7 +435,7 @@ class Sportstesting extends Base{ array_push($result['rows'],[ 'id'=>$value['id'], 'create_time'=>$value['create_time'], - 'score'=>$value['score'], + 'score'=>$value['score'] == '.00'?"0":$value['score'], 'max_score'=>$value['max_score'], 'address'=>$value['address'], ]); @@ -872,7 +447,7 @@ class Sportstesting extends Base{ } ################################################sportstesting_get_one_details public function sportstesting_get_one_details_action($data){ - $user_data = Db::table('app_sportstesting_data')->where(['id'=>$data['id']])->find(); + $user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['id'=>$data['id']])->find(); if($user_data){ @@ -899,38 +474,32 @@ class Sportstesting extends Base{ } ################################################sportstesting_set_once_data public function sportstesting_set_once_data_action2($data){ - // $ceshi = [ - - // ]; + $return_result['total_score'] = 0; $return_result['max_score'] = 0; $parameter_data = explode(',',$data['parameter_data']); $gender = $data['gender']; if(count($parameter_data) == 1){ + // $db_condition = "province = '".$parameter_data[0]."'"; $db_condition = "province = '".$parameter_data[0]."'"; }else if(count($parameter_data) == 2){ - $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'"; + // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'"; + $db_condition = "province = '".$parameter_data[0]."'"; }else if(count($parameter_data) == 3){ - $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'"; + // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'"; + $db_condition = "province = '".$parameter_data[0]."'"; }else{ return $this->msg(10005); } - $find_data = Db::table('admin_estimate')->where($db_condition)->find(); + // 只根据省查找,全省一个标准 + $find_data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->find(); $find_data = json_decode($find_data['content'],true); $recognition_rule = $find_data[$gender]; - // dump($recognition_rule); - // // 测试用删掉s - // $data['result_data'] = $this->handle_default_rule_list2($find_data,$gender); - // // 测试用删掉e - // dump($data); - // return $this->msg(10010); foreach ($data['result_data'] as $key => $value) { // 遍历一级($value['key'] = 现场考试) - // dump($value); foreach ($value['list'] as $k2 => $v2) { // 遍历二级级($v2['key'] = 第一类项目 - // dump($v2); foreach ($v2['list'] as $k3 => $v3) { // 遍历二级级($v3['name'] = 1000米跑) $temporary_result = $this->obtaining_grades($recognition_rule[$value['key']][$v2['key']]['list'][$v3['name']]['content'],$v3); @@ -941,9 +510,8 @@ class Sportstesting extends Base{ } } } - // return $this->msg(999); $return_result['list'] = $data['result_data']; - $user_sportstesting_set = Db::table('app_sportstesting_data')->insert([ + $user_sportstesting_set = Db::table($this->sportstesting_use_db_name['2'])->insert([ 'aud_id'=>$data['aud_id'], 'content'=>json_encode($return_result['list']), 'score'=>$return_result['total_score'], @@ -973,7 +541,7 @@ class Sportstesting extends Base{ public function sportstesting_get_city_list_action($type){ if($type['type'] == '1'){ // 已有地区列表 - $data = Db::table('admin_estimate')->field('id,province,city,area')->select(); + $data = Db::table($this->sportstesting_use_db_name['1'])->field('id,province,city,area')->select(); $result = []; // 添加省份 foreach ($data as $key => $value) { @@ -1018,7 +586,7 @@ class Sportstesting extends Base{ } return $this->msg($result); }else if($type['type'] == '2'){ - $data = Db::table('admin_estimate')->where(['type' => '2'])->field('id,content,city,area')->find(); + $data = Db::table($this->sportstesting_use_db_name['1'])->where(['type' => '2'])->field('id,content,city,area')->find(); $result = json_decode($data['content'],true); return $this->msg($result); }else{ @@ -1042,9 +610,6 @@ class Sportstesting extends Base{ $secondsA = $sjA[1]; $minutesB = $sjB[0]; $secondsB = $sjB[1]; - // list($minutesA, $secondsA) = explode(':', $a); - // list($minutesB, $secondsB) = explode(':', $b); - // 转换为秒 $totalSecondsA = intval($minutesA) * 60 + intval($secondsA); $totalSecondsB = intval($minutesB) * 60 + intval($secondsB); @@ -1055,14 +620,19 @@ class Sportstesting extends Base{ }else{ return [false,$result]; } - // 比较两个时间(秒) - // return $totalSecondsB <= $totalSecondsA; } // 处理默认规则列表 public function handle_default_rule_list($data,$gender){ - $temporary_arr = $data[$gender]; + if($gender == 1){ + $temporary_arr = $data[$gender]; + }else{ + $temporary_arr = $data[2]; + } + + + // die; $result = []; foreach ($temporary_arr as $key => $value) { $num = array_push($result,['name'=>$key,'key'=>$key,'list'=>[]]); @@ -1091,8 +661,6 @@ class Sportstesting extends Base{ } } } - // dump($result); - // die; return $result; } // 获取所有选择项内容 @@ -1106,9 +674,7 @@ class Sportstesting extends Base{ $temporary_arr = []; $temporary_arr['key'] = $k2; $temporary_arr['list'] = []; - // dump($v2); foreach ($v2['list'] as $k3 => $v3) { - // dump($v3); array_push($temporary_arr['list'],[ 'name'=>$k3, 'proportion'=>$v3['proportion'], @@ -1120,7 +686,6 @@ class Sportstesting extends Base{ 'total_score'=>$v3['score'], ]); } - // dump($temporary_arr); array_push($result['list'],$temporary_arr); } } @@ -1135,10 +700,7 @@ class Sportstesting extends Base{ // 减 bcsub(,,20) // 乘 bcmul(,,20) // 除 bcdiv(,,20) - // dump($data); - // dump($rule); - // die; - if($data['value'] != ''){ + if($data['value'] != '' && $data['value'] != null && $data['value'] != '0' && $data['value'] != '0.0' && $data['value'] != '0.0' && $data['value'] != '0:00'){ if(count($rule) > 0){ foreach ($rule as $key => $value) { if($data['unit'] == '分/秒'){ @@ -1148,6 +710,7 @@ class Sportstesting extends Base{ $rule_result = $value[0]; $data_result = $data['value']; } + switch ($value[1]) { case "<=": $result = $data_result <= $rule_result; @@ -1171,9 +734,14 @@ class Sportstesting extends Base{ // 如果比较符号不是上述任何一个,可以抛出一个异常或错误 throw new Exception("Unsupported comparison operator: " . $value[1]); } - // dump($result); if($result == true){ - $data['score'] = $value[2]; + // 判断是不是0分 + if($data_result == 0){ + $data['score'] = 0; + }else{ + $data['score'] = $value[2]; + } + // 计算比例后分值 $proportional_post_score = bcmul($data['total_score'],$data['proportion'],2); $data['proportion_value'] = bcmul($data['score'],bcdiv($proportional_post_score,100,2),2); @@ -1185,7 +753,6 @@ class Sportstesting extends Base{ }else{ $data['score'] = $data['value'] <= $data['total_score']?bcmul(bcdiv($data['value'],$data['total_score'],20),100,2):100; // 计算比例后分值 - // $proportional_post_score = bcmul($data['total_score'],$data['proportion'],2); $data['proportion_value'] = $data['value'] <= $data['total_score']?$data['value']:$data['total_score']; } @@ -1203,8 +770,6 @@ class Sportstesting extends Base{ public function handle_default_rule_list2($data,$gender){ $temporary_arr = $data[$gender]; $result = []; - // dump($temporary_arr); - // die; foreach ($temporary_arr as $key => $value) { $num = array_push($result,['name'=>$key,'key'=>$key,'list'=>[]]); @@ -1227,9 +792,7 @@ class Sportstesting extends Base{ 'describe'=>$x_m_v['describe'], 'total_score'=>$x_m_v['score'], ]); - // dump($x_m_k); if($x_m_k == '1000米跑'){ - // dump('11'); $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '4:08'; }else if($x_m_k == '50米跑'){ $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '7.3'; @@ -1240,7 +803,6 @@ class Sportstesting extends Base{ }else if($x_m_k == '机考'){ $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '8.3'; }else if($x_m_k == '1000米'){ - // dump('22'); $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '4:08'; } // break; @@ -1260,7 +822,6 @@ class Sportstesting extends Base{ 'describe'=>$x_m_v['describe'], 'total_score'=>$x_m_v['score'], ]); - // dump($x_m_k); if($x_m_k == '1000米跑'){ $result[$num-1]['list'][$num2-1]['list'][0]['value'] = '4:07'; }else if($x_m_k == '50米跑'){ @@ -1285,9 +846,6 @@ class Sportstesting extends Base{ } } } - // dump($result); - // die; - // $result = json_encode($result); return $result; } diff --git a/application/appbackups/controller/Vitalcapacity.php b/application/appbackups/controller/Vitalcapacity.php index 524780b..1a724d0 100644 --- a/application/appbackups/controller/Vitalcapacity.php +++ b/application/appbackups/controller/Vitalcapacity.php @@ -2,7 +2,6 @@ namespace app\app\controller; -use think\Controller; use think\Db; class Vitalcapacity extends Base{ @@ -17,7 +16,11 @@ class Vitalcapacity extends Base{ ['min_val'=>'10','max_val'=>'59','text'=>'不及格','color'=>'#FF5656'], ['min_val'=>'0','max_val'=>'9','text'=>'无效','color'=>'#FF5656'], ]; - + protected $vitalcapacity_use_db_name = [ + '1'=>'app_user_data', + '2'=>'app_card_vitalcapacity_data', + '3'=>'pc_vitalcapacity_standard', + ]; protected $result_end_data_mould = [ 'name'=>'', 'value'=>'', @@ -37,66 +40,133 @@ class Vitalcapacity extends Base{ // 手动数据记录 public function vitalcapacity_save_record_data($data = ['aud_id'=>'83','one'=>'1523','two'=>'1825','three'=>'1896','time'=>'2024-07-23','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + unset($data['token']); + $data['one'] = $this->isPositiveNumber($data['one']) === false?0:$data['one']; + $data['two'] = $this->isPositiveNumber($data['one']) === false?0:$data['two']; + $data['three'] = $this->isPositiveNumber($data['one']) === false?0:$data['three']; + $return_data = $this->vitalcapacity_save_record_data_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $data['one'] = $this->isPositiveNumber($data['one']) === false?0:$data['one']; - $data['two'] = $this->isPositiveNumber($data['one']) === false?0:$data['two']; - $data['three'] = $this->isPositiveNumber($data['one']) === false?0:$data['three']; - return $this->vitalcapacity_save_record_data_action($data); + } // 设备数据记录 public function vitalcapacity_save_record_data_device($data = ['aud_id'=>'99','one'=>'1523','two'=>'1825','three'=>'1896','flow'=>'88.88','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('flow', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + unset($data['token']); + $data['one'] = $this->isPositiveNumber($data['one']) === false?0:$data['one']; + $data['two'] = $this->isPositiveNumber($data['one']) === false?0:$data['two']; + $data['three'] = $this->isPositiveNumber($data['one']) === false?0:$data['three']; + $return_data = $this->vitalcapacity_save_record_data_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('flow', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - $data['one'] = $this->isPositiveNumber($data['one']) === false?0:$data['one']; - $data['two'] = $this->isPositiveNumber($data['one']) === false?0:$data['two']; - $data['three'] = $this->isPositiveNumber($data['one']) === false?0:$data['three']; - return $this->vitalcapacity_save_record_data_action($data); + } // 数据报告 - public function vitalcapacity_data_report($data = ['aud_id'=>'83','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + public function vitalcapacity_data_report($data = ['aud_id'=>'61','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + unset($data['token']); + $return_data = $this->vitalcapacity_data_report_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->vitalcapacity_data_report_action($data); } // 曲线 public function vitalcapacity_curve_chart($data = ['aud_id'=>'83','time'=>'2024','token'=>'caadd1be045a65f30b92aa805f1de54a']){ - if(count(input('post.')) > 0){ - $data = input('post.'); + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ + $return_data = $this->msg(10001); + } + unset($data['token']); + $return_data = $this->vitalcapacity_curve_chart_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); } - if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ - return $this->msg(10001); - } - if($this->token_time_validate($data['token']) === false){ - return $this->msg(20001); - } - unset($data['token']); - return $this->vitalcapacity_curve_chart_action($data); } ################################################################业务################################################################ @@ -120,7 +190,7 @@ class Vitalcapacity extends Base{ $temporary_arr['record_time'] = $this->addCurrentTimeToDateString($temporary_arr['record_time']); } - $user_msg = Db::name('app_user_data')->where(['id'=>$data['aud_id']])->field('grade,gender')->find(); + $user_msg = Db::name($this->vitalcapacity_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('grade,gender')->find(); if($user_msg){ // 根据性别&年级&年龄查规则 if($user_msg['grade'] != 'nothing'){ @@ -144,12 +214,8 @@ class Vitalcapacity extends Base{ $standard_data = $this->get_vitalcapacity_data($data['aud_id']); - // dump($standard_data); - // die; $temporary_arr['standard_data'] = json_encode($standard_data); - // dump($temporary_arr); - // die; - $result = Db::table('app_card_vitalcapacity_data')->insert($temporary_arr); + $result = Db::table($this->vitalcapacity_use_db_name['2'])->insert($temporary_arr); if($result){ $time = $result[0]['record_time']; @@ -170,7 +236,7 @@ class Vitalcapacity extends Base{ ################################################################vitalcapacity_data_report public function vitalcapacity_data_report_action($data){ - $result = Db::table('app_card_vitalcapacity_data')->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('record_time,score,average,flow_val,standard_data')->limit(1)->select(); + $result = Db::table($this->vitalcapacity_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('record_time,score,average,flow_val,standard_data')->limit(1)->select(); if(count($result) <= 0){ // return $this->msg(10004); @@ -191,8 +257,7 @@ class Vitalcapacity extends Base{ $o_l = explode(',',$result[0]['score']); // $standard_data = $this->get_vitalcapacity_data($data['aud_id']); $standard_data = json_decode($result[0]['standard_data'],true); - // dump($result); - // die; + return $this->msg([ 'average'=>$result[0]['average'].'ml', 'level'=>$o_l[1], @@ -225,14 +290,9 @@ class Vitalcapacity extends Base{ return $this->msg(10005); // 无效的时间数据格式 } - // dump($map); - // die; // 使用查询构造器进行查询 - $result = Db::name('app_card_vitalcapacity_data')->where($map)->field('id,one_val,two_val,three_val,average_val,score_val,aud_id,record_time,DATEPART(hour, record_time) AS hour,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); - // dump($map); - // dump($result); - // die; + $result = Db::name($this->vitalcapacity_use_db_name['2'])->where($map)->field('id,one_val,two_val,three_val,average_val,score_val,aud_id,record_time,DATEPART(hour, record_time) AS hour,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); $return_data = []; if(count($timeData) == 3){ $key_condition = 'hour'; @@ -241,9 +301,6 @@ class Vitalcapacity extends Base{ }else if(count($timeData) == 1){ $key_condition = 'month'; } - // dump($map); - // dump($key_condition); - // die; foreach ($this->curve_data_format as $key => $value) { $temporary_arr['title'] = $value[0].'('.$value[1].')'; $temporary_arr['key'] = $key; @@ -251,15 +308,8 @@ class Vitalcapacity extends Base{ $temporary_arr['line']['series'][0]['color'] = $value[2]; $temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')'; $temporary_arr['line']['series'][0]['data'] = []; - // dump($temporary_arr['title']); foreach ($result as $k => $v) { - // dump($k); - // if($result[$k][$key] == 26.43){ - // dump(123); - // } if($key_condition == 'hour'){ - // dump($result[$k][$key]); - // die; if(in_array($result[$k][$key_condition].'时',$temporary_arr['line']['categories'])){ $num = array_search($result[$k][$key_condition].'时', $temporary_arr['line']['categories']); @@ -270,7 +320,6 @@ class Vitalcapacity extends Base{ array_push($temporary_arr['line']['categories'],$result[$k][$key_condition].'时'); array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]); } - // dump($temporary_arr['line']['series'][0]['data']); }else if($key_condition == 'day'){ if(in_array($result[$k]['month'].'-'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){ $num = array_search($result[$k]['month'].'-'.$result[$k][$key_condition], $temporary_arr['line']['categories']); @@ -291,16 +340,8 @@ class Vitalcapacity extends Base{ } } } - // dump($temporary_arr); array_push($return_data,$temporary_arr); } - // dump($return_data); - // foreach ($return_data[1]['line']['series'][0]['data'] as $key => $value) { - // $return_data[1]['line']['series'][0]['data'][$key] = bcdiv($return_data[1]['line']['series'][0]['data'][$key],60,2); - // } - // // dump($temporary_arr); - // dump($return_data); - // die; return $this->msg($return_data); } @@ -317,20 +358,17 @@ class Vitalcapacity extends Base{ // 肺活量成绩判断 public function vitalcapacity_achievement_judge($data){ $str = "sex = ".$data['gender']." and ".$data['grade']." <= ".$data['average']; - $user_achievement = Db::name('pc_vitalcapacity_standard')->where($str)->order($data['grade'] .' desc')->field('level,score,'.$data['grade'])->limit(1)->select(); - // dump($data); - // dump($user_achievement); + $user_achievement = Db::name($this->vitalcapacity_use_db_name['3'])->where($str)->order($data['grade'] .' desc')->field('level,score,'.$data['grade'])->limit(1)->select(); if(count($user_achievement)<=0){ $user_achievement[0] = ['level'=>'无效','score'=>'0']; } - // dump($user_achievement); return $user_achievement[0]; } // 肺活量判断区间 public function vitalcapacity_standard_interval($val,$data){ // 缓存一周 $result = ''; - if(count($data) <= 0){ + if(!$data || count($data) <= 0){ return $result; } $temporary_qj = $data; @@ -371,22 +409,14 @@ class Vitalcapacity extends Base{ break; } } - // dump($data); - // dump($val); - // dump($max); - // dump($min); - // dump($num); - // 计算每份占比 $share_value = bcdiv($temporary_qj[0]['max_val'],count($temporary_qj),1); // 计算在这一段中占多少 $result = bcsub($val,$min,1); - // dump($result); $result = bcdiv($result,bcsub($max,$min,1),1); $num = count($temporary_qj)-1-$num; $num = bcmul($num,$share_value,1); $result = bcadd($num,$result,1); - // dump($share_value); // $num = count($temporary_qj)-1-$num; // $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2); // $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2); diff --git a/application/appbackups/view/download/demo.html b/application/appbackups/view/download/demo.html index 3b6977d..0fa6846 100644 --- a/application/appbackups/view/download/demo.html +++ b/application/appbackups/view/download/demo.html @@ -155,8 +155,9 @@ $('.ts').show() } else { console.log('当前不在微信环境中'); - if (isIOS()) { - console.log('当前是iOS设备'); + if (isIOS()) { + // alert('iOS设备不参与此次测试'); + // console.log('当前是iOS设备'); // 在这里执行iOS设备下的特定代码 window.location.href = "https://apps.apple.com/app/reedaw/id6654906497"; } else { diff --git a/application/appbackups/view/download/demo2.html b/application/appbackups/view/download/demo2.html index 2d9218f..7099137 100644 --- a/application/appbackups/view/download/demo2.html +++ b/application/appbackups/view/download/demo2.html @@ -44,12 +44,12 @@ font-size: 4vw; } .download{ - width: 40vw; - height: 10vw; - background-color: darkgray; - border-radius: 5vw; + width: 55vw; + height: 11vw; + background-color: #FFA940; + border-radius: 5.5vw; text-align: center; - line-height: 10vw; + line-height: 11vw; font-weight: bold; text-decoration: none; color: white; @@ -57,16 +57,15 @@ } img{ width: 25vw; - margin-bottom: 20vw; } .jump{ - width: 40vw; - height: 10vw; + width: 55vw; + height: 11vw; color: white; - background-color: darkgray; - border-radius: 5vw; + background-color: #389E0D; + border-radius: 5.5vw; text-align: center; - line-height: 10vw; + line-height: 11vw; font-weight: bold; margin-bottom: 10vw; } @@ -115,8 +114,11 @@
    +
    reedaw
    打开微信小程序
    -
    下载
    +
    下载APP
    diff --git a/application/route.php b/application/route.php index ca7327a..b1a374e 100644 --- a/application/route.php +++ b/application/route.php @@ -15,8 +15,9 @@ use think\Route; // // ################################################################下载################################################################ //下载页1 -Route::any('/download', 'app/download/demo'); -Route::any('/download2', 'app/download/demo2'); +Route::any('/download', 'app/download/demo2'); +Route::any('/download2', 'app/download/demo'); +Route::any('/testedition/download', 'testapp/download/demo'); Route::any('/ceshi', 'app/download/ceshi'); Route::any('/get_class', 'admin/demo/get_class_xuesheng'); @@ -71,6 +72,20 @@ Route::any('/appversion/app_edit', 'admin/appversion/app_edit'); Route::any('/appversion/app_del', 'admin/appversion/app_del'); Route::any('/appversion/app_add_action', 'admin/appversion/app_add_action'); Route::any('/appversion/app_edit_action', 'admin/appversion/app_edit_action'); +// 资讯管理 +Route::any('/editortext/index', 'admin/editortext/index'); +Route::any('/editortext/add_content', 'admin/editortext/add_content'); +Route::any('/editortext/add_content_action', 'admin/editortext/add_content_action'); +Route::any('/editortext/edit_content', 'admin/editortext/edit_content'); +Route::any('/editortext/edit_content_action', 'admin/editortext/edit_content_action'); +Route::any('/editortext/edit_order_action', 'admin/editortext/edit_order_action'); +Route::any('/editortext/model_content', 'admin/editortext/model_content'); +Route::any('/editortext/upload_pic_action', 'admin/editortext/upload_pic_action'); +Route::any('/editortext/upload_video_action', 'admin/editortext/upload_video_action'); +Route::any('/editortext/stop_action', 'admin/editortext/stop_action'); + + + // 联系我们H5 Route::any('/technology/index', 'admin/technology/index'); @@ -180,6 +195,15 @@ Route::any('/testedition/card_curve_chart', 'testapp/card/card_curve_chart'); // 曲线页面底部目标 Route::any('/card_curve_target', 'app/card/card_curve_target'); Route::any('/testedition/card_curve_target', 'testapp/card/card_curve_target'); +// 身高预测接口 +Route::any('/card_height_prediction', 'app/card/card_height_prediction'); +Route::any('/testedition/card_height_prediction', 'testapp/card/card_height_prediction'); +// 身高预测接口 +Route::any('/card_bmi_evaluation', 'app/card/card_bmi_evaluation'); +Route::any('/testedition/card_bmi_evaluation', 'testapp/card/card_bmi_evaluation'); + + + // ################################跳绳接口################################ // 手动记录 Route::any('/skip_manual_recording', 'app/skip/skip_manual_recording'); @@ -270,33 +294,44 @@ Route::any('/testedition/update_my_password', 'testapp/myinformation/update_my_p // ################################通用卡片接口################################ // 报告页详情 -// Route::any('/get_card_content', 'app/cardpublic/get_card_content'); +Route::any('/get_card_content', 'app/cardpublic/get_card_content'); Route::any('/testedition/get_card_content', 'testapp/cardpublic/get_card_content'); // 存储数据 -// Route::any('/public_data_save', 'app/cardpublic/data_save'); +Route::any('/public_data_save', 'app/cardpublic/data_save'); Route::any('/testedition/public_data_save', 'testapp/cardpublic/data_save'); // 获取标签项目信息 -// Route::any('/get_label_list', 'app/cardpublic/get_label_list'); +Route::any('/get_label_list', 'app/cardpublic/get_label_list'); Route::any('/testedition/get_label_list', 'testapp/cardpublic/get_label_list'); // 卡片运动曲线 -// Route::any('/card_motion_curve', 'app/cardpublic/card_motion_curve'); +Route::any('/card_motion_curve', 'app/cardpublic/card_motion_curve'); Route::any('/testedition/card_motion_curve', 'testapp/cardpublic/card_motion_curve'); // 获取手动记录内容 -// Route::any('/obtain_manual_record_content', 'app/cardpublic/obtain_manual_record_content'); +Route::any('/obtain_manual_record_content', 'app/cardpublic/obtain_manual_record_content'); Route::any('/testedition/obtain_manual_record_content', 'testapp/cardpublic/obtain_manual_record_content'); // 数据对比-获取数据 -// Route::any('/data_contrast_obtain_data', 'app/cardpublic/data_contrast_obtain_data'); +Route::any('/data_contrast_obtain_data', 'app/cardpublic/data_contrast_obtain_data'); Route::any('/testedition/data_contrast_obtain_data', 'testapp/cardpublic/data_contrast_obtain_data'); // 数据对比-对比数据 -// Route::any('/data_contrast_contrast_data', 'app/cardpublic/data_contrast_contrast_data'); +Route::any('/data_contrast_contrast_data', 'app/cardpublic/data_contrast_contrast_data'); Route::any('/testedition/data_contrast_contrast_data', 'testapp/cardpublic/data_contrast_contrast_data'); // 获取历史数据 -// Route::any('/obtain_history_record', 'app/cardpublic/obtain_history_record'); +Route::any('/obtain_history_record', 'app/cardpublic/obtain_history_record'); Route::any('/testedition/obtain_history_record', 'testapp/cardpublic/obtain_history_record'); // 删除历史数据 -// Route::any('/history_record_del', 'app/cardpublic/history_record_del'); +Route::any('/history_record_del', 'app/cardpublic/history_record_del'); Route::any('/testedition/history_record_del', 'testapp/cardpublic/history_record_del'); +// ################################资讯接口################################ +// 获取板块信息及板块下标签类别信息 +Route::any('/get_sector_label_msg', 'app/Msginformation/get_sector_label_msg'); +Route::any('/testedition/get_sector_label_msg', 'testapp/Msginformation/get_sector_label_msg'); +// 板块默认内容 +Route::any('/get_sector_content_msg', 'app/Msginformation/get_sector_content_msg'); +Route::any('/testedition/get_sector_content_msg', 'testapp/Msginformation/get_sector_content_msg'); +// 点赞 +Route::any('/user_like_it', 'app/Msginformation/user_like_it'); +Route::any('/testedition/user_like_it', 'testapp/Msginformation/user_like_it'); + diff --git a/application/testapp/controller/Base.php b/application/testapp/controller/Base.php index 3f42fa4..5ff0f03 100644 --- a/application/testapp/controller/Base.php +++ b/application/testapp/controller/Base.php @@ -35,7 +35,7 @@ class Base extends Controller{ '10009'=>'', '10010'=>'自定义信息', '20001'=>'登录失效', - '99999'=>'接口错误', + '99999'=>'网络异常,请稍后重试', ]; // 加 bcadd(,,20) // 减 bcsub(,,20) @@ -62,22 +62,8 @@ class Base extends Controller{ Log::record($logContent, 'api_log'); } - - - - // $data = ['aud_id'=>'xxxxxxxxxxxxxxx','order_list'=>[1,2,3,4,5]] - public function abnormal_data_log_action($dacall_methoda = 0,$content='未记录的内容',$use_database_name='未记录的数据库名'){ - $result = Db::table($this->base_use_db_name['1'])->insert([ - 'create_time'=>date('Y-m-d H:i:s'), - 'call_method'=>$this->base_call_method[$dacall_methoda], - 'content'=>$content, - 'use_database_name'=>$use_database_name, - ]); - } - - // 检查变量是否是一个只有数字的一维数组 - public function is_num_array($array = [1,2,3],$type=1) { + public function is_num_array($array = [1,2,3]) { if (!is_array($array)) { return false; // 变量不是数组 } @@ -86,10 +72,8 @@ class Base extends Controller{ return false; // 数组中包含非数字元素 } } - if($type!=1){ - return true; - } - $result = Db::table($this->base_use_db_name['2'])->where(['is_del'=>0])->cache(true,3600)->select();//查询结果缓存3600秒 + + $result = Db::table($this->base_use_db_name['2'])->where(['is_del'=>0])->cache(true,600)->select();//查询结果缓存3600秒 if(empty(array_diff($array, array_column($result, 'id')))){ return true;// 数组是一维的且只包含数字,且已经跟数据库比对过,每个数值都是有效 }else{ @@ -203,15 +187,6 @@ class Base extends Controller{ } } - - // if(cache($token) === false){ - // Log::record('用户尝试更新token时间,token:' . $token.',但是更新token失败,原因没有找到该token,或该token已经超过30天', 'token_log'); - // return false; - // } - // $time_now = date('Y-m-d H:i:s'); - // cache($token,$time_now,$this->token_time); - // Log::record('用户尝试更新token时间,token:' . $token.',记录成功,最新的时间为'.$time_now, 'token_log'); - // return true; } // 计算天数 @@ -254,7 +229,10 @@ class Base extends Controller{ // 第一种:用户详情(所有数据都有) // 第二种:手动记录(只有最新体重) // 第三种:修改原始体重(只有原始体重) - // dump($data); + // $result_data['target_weight'] 目标体重 + // $result_data['initial_weight'] 最初体重 + // $result_data['weight'] 最近一次测量重量 + // $result_data['initial_date'] 初始体重日期 if(count($data) > 0){ $result_data['target_weight'] = $data['target_weight']; $result_data['initial_weight'] = $data['initial_weight']; @@ -266,7 +244,6 @@ class Base extends Controller{ $result_data['cumulative_weight'] = 0; $result_data['cumulative_day'] = 0; } - // dump($result_data); return $result_data; } @@ -304,10 +281,43 @@ class Base extends Controller{ ['min_val'=>'10','max_val'=>'59','text'=>'不及格','color'=>'#FF5656'], ['min_val'=>'0','max_val'=>'9','text'=>'无效','color'=>'#FF5656'], ]; - $grade = Db::table($this->base_use_db_name['3'])->where(['id'=>$id])->field('id,grade,gender')->find(); - if(!$grade || $grade['grade'] == 'nothing'){ + $grade = Db::table($this->base_use_db_name['3'])->where(['id'=>$id])->field('id,grade,gender,birthday')->find(); + if(!$grade){ return []; } + if($grade['grade'] == 'nothing'){ + // 计算年龄判断是属于哪个年级 + $user_age = $this->calculate_age($grade['birthday']); + if($user_age <= 7){ + $grade['grade'] = 'grade_s_1'; + }else if($user_age == 8){ + $grade['grade'] = 'grade_s_2'; + }else if($user_age == 9){ + $grade['grade'] = 'grade_s_3'; + }else if($user_age == 10){ + $grade['grade'] = 'grade_s_4'; + }else if($user_age == 11){ + $grade['grade'] = 'grade_s_5'; + }else if($user_age == 12){ + $grade['grade'] = 'grade_s_6'; + }else if($user_age == 13){ + $grade['grade'] = 'grade_m_1'; + }else if($user_age == 14){ + $grade['grade'] = 'grade_m_2'; + }else if($user_age == 15){ + $grade['grade'] = 'grade_m_3'; + }else if($user_age == 16){ + $grade['grade'] = 'grade_h_1'; + }else if($user_age == 17){ + $grade['grade'] = 'grade_h_2'; + }else if($user_age == 18){ + $grade['grade'] = 'grade_h_3'; + }else if($user_age == 19 || $user_age == 20){ + $grade['grade'] = 'grade_u_12'; + }else if($user_age >= 21){ + $grade['grade'] = 'grade_u_34'; + } + } $sql_min = "WITH RankedGrades AS ( SELECT id, @@ -327,10 +337,7 @@ class Base extends Controller{ RankedGrades WHERE rn = 1"; - // dump($sql_min); $result_min = Db::query($sql_min); - // dump($result_min); - // die; foreach ($result_min as $key => $value) { foreach ($standard_data as $sdk => $sdv) { if($value['level'] == $sdv['text']){ @@ -344,8 +351,6 @@ class Base extends Controller{ $standard_data[0]['max_val'] = '5140'; return $standard_data; } - - // 时间日期转换 public function addCurrentTimeToDateString($dateStr) { // 将日期字符串转换为DateTime对象 @@ -365,7 +370,7 @@ class Base extends Controller{ } // 处理分秒变秒 - function convertMinutesSecondsToStringSeconds($timeString) { + public function convertMinutesSecondsToStringSeconds($timeString) { // 分割字符串获取分钟和秒 list($minutes, $seconds) = explode(':', $timeString); // 将分钟和秒转换为秒 @@ -373,6 +378,35 @@ class Base extends Controller{ return $totalSeconds; } + // 转换数字"90.00", "88.11", "66.50", ".00"为正常数字 + public function convertStringToNumber($str) { + // 去除字符串两端的空格(如果有的话) + $str = trim($str); + + // 检查字符串是否为空或只包含小数点 + if ($str === '' || $str === '.') { + return 0; + } + + // 尝试将字符串转换为浮点数 + $number = (float)$str; + + // 格式化浮点数,去掉末尾多余的零 + $formattedNumber = rtrim(rtrim(sprintf('%.2f', $number), '0'), '.'); + + // 如果结果为空字符串(比如,原字符串是“.00”),则返回0 + if ($formattedNumber === '') { + return '0'; + } + // 返回结果,转换为整数如果小数点后没有数字 + if (strpos($formattedNumber, '.') === false) { + $formattedNumber = (int)$formattedNumber; + return "$formattedNumber"; + } + + return $formattedNumber; + } + // 时间加一或者减一 public function adjustDateTime($datetimeStr, $type) { // 将时间字符串转换为时间戳 @@ -414,6 +448,7 @@ class Base extends Controller{ } + // 发送一个PSOT请求 public function postRequest($url, $data = [], $headers = []) { $ch = curl_init(); // 初始化cURL会话 @@ -431,6 +466,7 @@ class Base extends Controller{ curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data)); // POST数据 // 设置请求头 if (!empty($headers)) { + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); }else{ // 如果需要发送JSON数据,可以使用以下设置: @@ -521,8 +557,6 @@ class Base extends Controller{ $neirong = $content['content']; $mail->Body = $neirong; //邮件主体内容 - // dump($address); - // die; //发送 if (!$mail->Send()) { @@ -535,12 +569,73 @@ class Base extends Controller{ } + + // 验证是否字符串 + public function verify_data_is_ok($data = 2,$type){ + if($type == 'str'){ + if (is_string($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为字符串',[]]); + return false; + } + }else if($type == 'num'){ + if (is_numeric($data)) { + return true; + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为数字',[]]); + return false; + } + }else if($type == 'intnum'){ + $pattern = '/^\d+$/'; + if (preg_match($pattern, $data)) { + return true; // 匹配成功,返回 true + } else { + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为整数数字',[]]); + return false; // 匹配失败,返回 false + } + }else if($type == 'datetime'){ + $formats = ['Y-m-d','Y-m-d H:i:s']; + foreach ($formats as $format) { + $dateTime = \DateTime::createFromFormat($format, $data); + // 检查时间字符串是否成功解析,并且解析后的日期时间与原始字符串表示的时间一致 + if ($dateTime && $dateTime->format($format) === $data) { + return true; + } + } + // 如果所有格式都解析失败,则返回 false + $this->record_api_log($data, null, ['code'=>10005,'msg'=>'校验参数不为日期格式',[]]); + return false; + }else if($type == 'other'){ + + } + + } + public function ceshiyong($aa = 4,$gd = 0.2){ $token = 'cd3f27cf4c4002170ea7bceeb723ac91'; - dump(cache($token)); - // dump('ok'); + + $data = Db::table('pc_bmistand2')->select(); + for ($i=0; $i < count($data); $i++) { + foreach ($data[$i] as $key => $value) { + $data[$i][$key] = str_replace(' ', '',$data[$i][$key]); + + } + Db::table('pc_bmistand2')->where(['id'=>$data[$i]['id']])->update([ + 'month'=>$data[$i]['month'], + 'sex'=>$data[$i]['sex'], + // 'f3sd'=>$data[$i]['f3sd'], + // 'f2sd'=>$data[$i]['f2sd'], + 'f1sd'=>$data[$i]['f1sd'], + 'median'=>$data[$i]['median'], + 'z1sd'=>$data[$i]['z1sd'], + 'z2sd'=>$data[$i]['z2sd'], + // 'z3sd'=>$data[$i]['z3sd'], + ]); + } + die; // $this->send_email_api_error(["tsf3920322@126.com"],['title'=>'接口报错','from_user_name'=>'青测API','content'=>'123']); } diff --git a/application/testapp/controller/Calculatebody.php b/application/testapp/controller/Calculatebody.php index 7066b5e..02af512 100644 --- a/application/testapp/controller/Calculatebody.php +++ b/application/testapp/controller/Calculatebody.php @@ -61,11 +61,15 @@ class Calculatebody extends Base{ $temporary_parameter = [ 'weight'=>$data['weight'], 'height'=>$data['height'], - 'age'=>$data['age'], - 'adc'=>$data['adc'], + 'age'=>round($data['age']),//四舍五入取整 + 'adc'=>round($data['adc']),//四舍五入取整 'gender'=>$data['gender'], ]; $request_result = $this->postRequest($url,$temporary_parameter); + if($request_result['code'] != 0){ + return false; + } + $result['weight'] = $request_result['data']['weight']; $result['height'] = $request_result['data']['height']; $result['bmi'] = $request_result['data']['bmi']; @@ -86,8 +90,6 @@ class Calculatebody extends Base{ $result['bodyage'] = $request_result['data']['bodyage']; $result['lbm'] = $request_result['data']['lbm']; $result['body'] = $request_result['data']['body']; - // dump($result); - // die; // 使用接口调用之前的进行计算end $return_data['体重'] = $data['weight']; @@ -341,8 +343,6 @@ class Calculatebody extends Base{ $return_data['身体年龄'] = $result['bodyage']; - // dump($return_data); - // die; // $result_end['fat_r'] = $result['fat_r']; // $result_end['muscle'] = $result['muscle']; // $result_end['water'] = $result['water']; @@ -362,11 +362,7 @@ class Calculatebody extends Base{ // $result_end['lbm'] = $result['lbm']; // $result_end['weight'] = $result['weight']; // $result_end['height'] = $result['height']; - // dump($return_data); - // dump('========================================='); return $return_data; - // dump($result_end); - // die; } // 加 bcadd(,,20) @@ -486,13 +482,11 @@ class Calculatebody extends Base{ $num3 = '75.0'; } // $result_data['muscle'] = ($num3 < 15.0) ? 15.0 : $num3; - // dump($num3); if(bccomp($num3, '15.0', 20) === -1){ $result_data['muscle'] = '15.00'; }else{ $result_data['muscle'] = $num3; } - // dump($num4); // $num4 = (($num4 > 70.0) ? 70.0 : $num4); if(bccomp($num4, '70.0', 20) === 1){ $num4 = '70.0'; @@ -513,7 +507,6 @@ class Calculatebody extends Base{ $result_data['fat_r'] = '5.00'; }else{ // $result_data['fat_r'] = $num5; - // dump($num5); $result_data['fat_r'] = substr($num5, 0, strpos($num5, ".") + 3); } // $result_data['sfr'] = $num6 <= 0 ? "0" : $num6; @@ -555,11 +548,9 @@ class Calculatebody extends Base{ $standard_level = bcdiv(bcsub($weight,$standard_weight,20),$standard_weight,2); // 加 bcadd(,,20) // 减 bcsub(,,20) - // dump($num11); if ($age < 18){ $num11 = $age; }else{ - // dump($num11); // $num11 = (($num11 > ($age + 10)) ? (($age + 10)) : $num11); if(bccomp($num11, $age + 10, 20) === 1){ $num11 = $age + 10; @@ -569,7 +560,6 @@ class Calculatebody extends Base{ $num11 = $age - 10; } } - // dump($age); $result_data['bodyage'] = $num11; $result_data['weight'] = $weight; @@ -578,13 +568,10 @@ class Calculatebody extends Base{ $result_data['adc'] = $impedance; $result_data['gender'] = $gender; $result_data['standard_level'] = $standard_level; - // dump($result_data); - // die; return $result_data; } // 计算脂肪率 function calculate_fat_r(){ - dump(123); } // 计算脂肪量 function calculate_zhifangliang(){ diff --git a/application/testapp/controller/Card.php b/application/testapp/controller/Card.php index a38a1f7..267f763 100644 --- a/application/testapp/controller/Card.php +++ b/application/testapp/controller/Card.php @@ -55,7 +55,7 @@ class Card extends Base{ 'proteinval'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], 'bone'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], 'protein'=>['不足'=>'#FED966','标准'=>'#58CF6B','优'=>'#3A68D7'], - 'kcal'=>['偏低'=>'#FF5656','优'=>'#5ad06d'], + 'kcal'=>['偏低'=>'#FF5656','优'=>'#3A68D4'], 'visceral'=>['标准'=>'#55CF6C','警惕'=>'#FEAC00','危险'=>'#FB5A52'], 'sfr'=>['不足'=>'#FCDB68','标准'=>'#59D16F','偏高'=>'#FEAB03'], ]; @@ -77,6 +77,10 @@ class Card extends Base{ 'weight'=>['value'=>3,'list'=>['低'=>1,'偏低'=>1,'标准'=>2,'偏高'=>3,'高'=>3]], 'bmi'=>['value'=>2,'list'=>['消瘦'=>1,'正常'=>2,'偏重'=>3,'肥胖'=>4]], ]; + protected $unit_data = [ + 'height'=>['cm','inch','ft-in'], + 'weight'=>['kg','斤','st:lb','lb'], + ]; ################################################################接口################################################################ ################################################################接口################################################################ ################################################################接口################################################################ @@ -84,17 +88,18 @@ class Card extends Base{ // 详细卡片信息 // $data = ['id'=>'2'] - public function card_data_detailed($data=['aud_id'=>'11','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + public function card_data_detailed($data=['aud_id'=>'37']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ $data = input('post.'); } - - if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ + if(!array_key_exists('aud_id', $data)){ return $this->msg(10001); } - unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } $return_data = $this->get_user_body_data($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -110,7 +115,7 @@ class Card extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -126,6 +131,15 @@ class Card extends Base{ return $this->msg(10001); } unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } $return_data = $this->curve_chart_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -141,14 +155,15 @@ class Card extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 手动记录 // $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1'] - public function card_manual_recording($data = ['aud_id'=>'11','time'=>'2024-10-12','height'=>'155.7','weight'=>'46.7','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + // public function card_manual_recording($data = ['aud_id'=>'37','time'=>'2024-10-12','height'=>'144.7,cm','weight'=>'36.8,kg','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + public function card_manual_recording($data = ['aud_id'=>'37','time'=>'2024-10-12','height'=>'144.7','weight'=>'36.8','token'=>'caadd1be045a65f30b92aa805f1de54a']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -160,8 +175,40 @@ class Card extends Base{ return $this->msg(10001); } unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['height'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['weight'],'num')){ + return $this->msg(10005); + } + // $data['height'] = explode(',',$data['height']); + // if(count($data['height']) < 2){ + // return $this->msg(10005); + // } + // if(!$this->verify_data_is_ok($data['height'][0],'num')){ + // return $this->msg(10005); + // } + // if(!in_array($data['height'][1],$this->unit_data['height'])){ + // return $this->msg(10005); + // } + // $data['weight'] = explode(',',$data['weight']); + // if(count($data['height']) < 2){ + // return $this->msg(10005); + // } + // if(!$this->verify_data_is_ok($data['weight'][0],'num')){ + // return $this->msg(10005); + // } + // if(!in_array($data['weight'][1],$this->unit_data['weight'])){ + // return $this->msg(10005); + // } $data['acd_id'] = '2'; - $return_data = $this->set_user_body_data($data); + $return_data = $this->set_user_body_data($data,'by_hand_means'); // 成功 $this->record_api_log($data, null, $return_data); return $return_data; @@ -176,13 +223,14 @@ class Card extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 设备记录 // $data = ['id'=>'2','time'=>'1991-04-20 10:10:10','height'=>'15.1','weight'=>'75.1'] - public function card_manual_recording_device($data = ['aud_id'=>'58','height'=>'175','weight'=>'68','adc'=>'550','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + // public function card_manual_recording_device($data = ['aud_id'=>'37','height'=>'169.60,inch','weight'=>'52.45,lb','adc'=>'520.3','token'=>'591b70e0d80b5fa6d77e6e1384453ab9']){ + public function card_manual_recording_device($data = ['aud_id'=>'37','height'=>'169.60','weight'=>'52.45','adc'=>'520.3','token'=>'591b70e0d80b5fa6d77e6e1384453ab9']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -193,12 +241,41 @@ class Card extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('height', $data) || !array_key_exists('weight', $data) || !array_key_exists('adc', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } - if($data['adc'] == 0){ - $data['adc'] = 550; + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['height'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['weight'],'num')){ + return $this->msg(10005); + } + // $data['height'] = explode(',',$data['height']); + // if(count($data['height']) < 2){ + // return $this->msg(10005); + // } + // if(!$this->verify_data_is_ok($data['height'][0],'num')){ + // return $this->msg(10005); + // } + // if(!in_array($data['height'][1],$this->unit_data['height'])){ + // return $this->msg(10005); + // } + // $data['weight'] = explode(',',$data['weight']); + // if(count($data['height']) < 2){ + // return $this->msg(10005); + // } + // if(!$this->verify_data_is_ok($data['weight'][0],'num')){ + // return $this->msg(10005); + // } + // if(!in_array($data['weight'][1],$this->unit_data['weight'])){ + // return $this->msg(10005); + // } + if(!$this->verify_data_is_ok($data['adc'],'num')){ + return $this->msg(10005); } $data['time'] = date('Y-m-d H:i:s'); $data['acd_id'] = '2'; - $return_data = $this->set_user_body_data($data); + $return_data = $this->set_user_body_data($data,'by_device'); // 成功 $this->record_api_log($data, null, $return_data); return $return_data; @@ -213,13 +290,13 @@ class Card extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 修改初始体重/目标体重 - public function card_modify_weight($data = ['aud_id'=>'25','weight'=>'25','type'=>1,'time'=>'','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function card_modify_weight($data = ['aud_id'=>'11','weight'=>'50','type'=>2,'time'=>'2024-10-01','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -232,6 +309,21 @@ class Card extends Base{ return $this->msg(10001); } unset($data['token']); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['weight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + if($data['type'] != 1){ + if(!$this->verify_data_is_ok($data['time'],'datetime')){ + return $this->msg(10005); + } + } + $return_data = $this->modify_weight_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -247,10 +339,121 @@ class Card extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } + + // 身高预测 + public function card_height_prediction($data = ['dadHeight'=>'199','momHeight'=>'160','birthday'=>'2014-07-24','sex'=>'1',]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!is_array($data)){ + return $this->msg(10005); + } + if(!array_key_exists('dadHeight', $data) || !array_key_exists('momHeight', $data) || !array_key_exists('birthday', $data) || !array_key_exists('sex', $data)){ + return $this->msg(10001); + } + unset($data['token']); + if(!$this->verify_data_is_ok($data['birthday'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['dadHeight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['momHeight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['sex'],'intnum')){ + return $this->msg(10005); + } + + // 直接开始业务,请求外部接口start + $url = 'https://ybapi.pcxbc.com/api/child/predictheight'; + $temporary_parameter = [ + 'dadHeight'=>$data['dadHeight'], + 'momHeight'=>$data['momHeight'], + 'birthday'=>$data['birthday'], + 'sex'=>$data['sex'], + ]; + $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com')); + // 直接开始业务,请求外部接口end + $this->record_api_log($data, null, $request_result); + return json($request_result); + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + } + + // BMI测评 + public function card_bmi_evaluation($cbe_data = ['height'=>'177','weight'=>'177','birthday'=>'2024-10-03','sex'=>'1'],$type = false){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0 && $type == false){ + $cbe_data = input('post.'); + } + if(!is_array($cbe_data)){ + return $this->msg(10005); + } + if(!array_key_exists('height', $cbe_data) || !array_key_exists('weight', $cbe_data) || !array_key_exists('birthday', $cbe_data) || !array_key_exists('sex', $cbe_data)){ + return $this->msg(10001); + } + unset($cbe_data['token']); + if(!$this->verify_data_is_ok($cbe_data['birthday'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($cbe_data['height'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($cbe_data['weight'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($cbe_data['sex'],'intnum')){ + return $this->msg(10005); + } + + // 直接开始业务,请求外部接口start + $url = 'http://ybdevice.pcxbc.com/api/result/calcbmi'; + $temporary_parameter = [ + 'height'=>$cbe_data['height'], + 'weight'=>$cbe_data['weight'], + 'birthday'=>$cbe_data['birthday'], + 'sex'=>$cbe_data['sex'], + ]; + $request_result = $this->postRequest($url,$temporary_parameter,array('Content-Type:application/json','Origin:http://ybdevice.pcxbc.com')); + // 直接开始业务,请求外部接口end + + // 处理进度点 + $request_result =$this->bmi_evaluation_action($request_result); + $this->record_api_log($cbe_data, null, $request_result); + return $request_result; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($cbe_data, $logContent, null); + return $this->msg(99999); + } + } ################################################################业务接口################################################################ ################################################################业务接口################################################################ @@ -263,6 +466,7 @@ class Card extends Base{ Top 1 acbd.id, acbd.acd_id, + acbd.record_type, acbd.create_time, acbd.last_update_time, acbd.score, @@ -284,19 +488,80 @@ class Card extends Base{ acbd.age, acbd.is_del, acbd.height, + acbd.height_val, acbd.weight, + acbd.weight_val, acbd.bmi, acbd.body_age, aud.birthday,aud.gender,aud.target_weight,aud.initial_weight,aud.initial_date from ".$this->card_use_db_name['1']." as acbd left join ".$this->card_use_db_name['2']." as aud on acbd.aud_id=aud.id - where acbd.aud_id='".$data['aud_id']."' + where acbd.is_del=0 and acbd.aud_id='".$data['aud_id']."' order by acbd.record_time desc "); - if(!$result){ - return $this->msg(10004); + + if(count($result) <= 0){ + $result_return = [ + "score_name"=>"", + "score_value"=>"", + "score_unit"=>"", + "body_type_name"=>"", + "body_type_value"=>"", + "body_type_unit"=>"", + "record_time"=>"", + 'top_list'=>[ + [ + "name"=>"体重", + "value"=>"0", + "unit"=>"公斤", + "standard"=>"", + "color"=>"", + "list"=>[], + "key_name"=>"weight", + "desc"=>"反映和衡量一个人健康状况的重要标志之一", + "offset"=>"0" + ], + [ + "name"=>"身高", + "value"=>"0", + "unit"=>"CM", + "standard"=>"", + "color"=>"", + "list"=>[], + "key_name"=>"height", + "desc"=>"人体纵向部分的长度,源于人体的纵向生长,受遗传因素的影响较大", + "offset"=>"0" + ], + [ + "name"=>"BMI", + "value"=>"0", + "unit"=>"公斤", + "standard"=>"", + "color"=>"", + "list"=>[], + "key_name"=>"bmi", + "desc"=>"BMI是身体质量指数,是目前国际上常用的衡量人体胖瘦程度以及是否健康的一个标准。", + "offset"=>"0" + ], + ], + 'bottom_list' => [], + 'cplist'=>[ + 'nutritionlist'=>[], + 'sportlist'=>[], + 'sleeplist'=>[], + 'moodlist'=>[], + ], + 'literature'=>[], + 'target_current'=>[ + 'target_weight'=>'0', + 'initial_weight'=>'0', + 'cumulative_weight'=>'0', + 'cumulative_day'=>'0' + ], + ]; + return $this->msg($result_return); }else{ - // $curve_bottom = $this->card_curve_target_action($result); + $result_end = $this->processing_return_data_new($result[0]); $cardparts = new Cardparts; $result_end['gender'] = $result[0]['gender']; @@ -304,6 +569,7 @@ class Card extends Base{ $result_end['score'] = $result_end['score']; $result_end['body_type'] = $result_end['body_type']; $result_end = $cardparts->conversion_interval($result_end); + $result_end['cplist'] = $this->grow_up_recommendation([ 'birthday'=>$result[0]['birthday'], 'body'=>[ @@ -312,17 +578,51 @@ class Card extends Base{ 'bmi'=>$result[0]['bmi'] ], ]); - if(count($result_end['cplist']['nutritionlist']) <= 0){ - // $result_end['cplist'] = []; - $result_end['literature'] = []; + // 只有含有阻抗的记录才有数据参考 + if($result[0]['record_type'] == 'by_device_adc'){ + if(count($result_end['cplist']['nutritionlist']) <= 0){ + $result_end['literature'] = []; + }else{ + $result_end['literature'] = [ + '《中华人民共和国卫生行业标准WS 423-2013》', + '《中华人民共和国卫生行业标准WS/T 612-2018》', + '《中华人民共和国卫生行业标准WS/T1586-2018》', + '《WHO 5~19岁身高/体重判定标准》', + ]; + } }else{ - $result_end['literature'] = [ - '《中华人民共和国卫生行业标准WS 423-2013》', - '《中华人民共和国卫生行业标准WS/T 612-2018》', - '《中华人民共和国卫生行业标准WS/T1586-2018》', - '《WHO 5~19岁身高/体重判定标准》', - ]; + $result_end['literature'] = []; } + + // 加入曲线板块底部的减肥计划数据start + $result_end['target_current'] = $this->base_target_initial_cumulative_weight([ + 'weight'=>$result[0]['weight']>0?$result[0]['weight']:0, + 'target_weight'=>$result[0]['target_weight']>0?$result[0]['target_weight']:0, + 'initial_weight'=>$result[0]['initial_weight']>0?$result[0]['initial_weight']:0, + 'initial_date'=>$result[0]['initial_date']!=null?$result[0]['initial_date']:0, + ]); + + if(count($result_end['top_list'][2]['list']) <= 0){ + // 这是16岁以上人群 + $data = [ + 'height'=>$result[0]['height_val'], + 'weight'=>$result[0]['weight_val'], + 'birthday'=>$result[0]['birthday'], + 'sex'=>$result[0]['gender'] + ]; + + $temporary_arr_bmi_list = $this->card_bmi_evaluation($data,true); + $temporary_arr_bmi_list = $temporary_arr_bmi_list->getData(); + + if($temporary_arr_bmi_list['code'] == 0){ + $result_end['top_list'][2]['standard'] = $temporary_arr_bmi_list['data']['bmilevel']; + $result_end['top_list'][2]['color'] = $temporary_arr_bmi_list['data']['bmilevelcolor']; + $result_end['top_list'][2]['list'] = $temporary_arr_bmi_list['data']['bmilevellist']; + $result_end['top_list'][2]['offset'] = $temporary_arr_bmi_list['data']['offset']; + } + } + + // 加入曲线板块底部的减肥计划数据end return $this->msg($result_end); } } @@ -335,18 +635,22 @@ class Card extends Base{ if($key != 'aud_id' && $key != 'id' && $key != 'create_time' && $key != 'last_update_time' && $key != 'acd_id' && $key != 'ROW_NUMBER' && $key != 'record_time' && $key != 'gender' && $key != 'birthday'){ // 设置单个数据格式 $result_end_data[$key] = $this->result_end_data_mould; + // 该项名 if(array_key_exists($key, $this->unit_name)){ $result_end_data[$key]['name'] = $this->unit_name[$key]; } + // 该项单位 if(array_key_exists($key, $this->unit_symbol)){ $result_end_data[$key]['unit'] = $this->unit_symbol[$key]; } + $result_end_data[$key]['value'] = explode(',',$value)[0]; + if(strpos($value, ',')){ $result_end_data[$key]['standard'] = explode(',',$value)[1]; } if(array_key_exists($key, $this->standard_color)){ - if($result_end_data[$key]['standard'] != '异常'){ + if($result_end_data[$key]['standard'] != '异常' && $result_end_data[$key]['standard'] != ''){ $result_end_data[$key]['color'] = $this->standard_color[$key][$result_end_data[$key]['standard']]; } } @@ -520,8 +824,24 @@ class Card extends Base{ ################################################card_manual_recording // 用户身体数据卡片记录 - public function set_user_body_data($data){ - + public function set_user_body_data($data,$type){ + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + // // 这里开始转换不同单位的身高体重为cm跟kg(start) + // if($data['height'][1] == 'kg'){ + // $data['height'] = $data['height'][0]; + // }else if($data['height'][1] == '斤'){ + // // 斤数除以2就是公斤 + // $data['height'] = bcdiv($data['height'][0],2,2); + // }else if($data['height'][1] == 'st:lb'){ + // $data['height'] = $data['height'][0]; + // }else if($data['height'][1] == 'lb'){ + // $data['height'] = $data['height'][0]; + // } + // // 这里开始转换不同单位的身高体重为cm跟kg(end) + // $adc_type = $type; $data['type'] = 1; $user_data = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->field('birthday,gender,target_weight,initial_weight,initial_date')->find(); if(!$user_data){ @@ -548,20 +868,25 @@ class Card extends Base{ $result_data['age'] = $this->calculate_age($user_data['birthday']); $result_data['gender'] = $user_data['gender']; if(array_key_exists('adc', $data)){ - $result_data['adc'] = $data['adc']; + if($data['adc'] > 0){ + $result_data['adc'] = $data['adc']; + $type = "by_device_adc"; + }else{ + $result_data['adc'] = 550; + $type = "by_device"; + } } $calculate_body_formula = new Calculatebody(); // 计算身体数据 $get_body_value = $calculate_body_formula->calculate_body_data_result($result_data); - // dump($get_body_value); - // die; + if($get_body_value === false){ + return $this->msg(10005); + } $get_body_value['gender'] = $user_data['gender']; $get_body_value['birthday'] = $user_data['birthday']; // 添加身高体重bmi的标尺标准 $get_body_value = $this->hwb_standard($get_body_value); - // dump($get_body_value); - // die; $set_data = [ 'acd_id'=>$data['acd_id'], 'aud_id'=>$data['aud_id'], @@ -589,38 +914,42 @@ class Card extends Base{ 'sfr'=>implode(',',$get_body_value['皮下脂肪']), 'body_level'=>$get_body_value['肥胖等级'], 'body_type'=>$get_body_value['身体类型'], - 'body_age'=>$get_body_value['身体年龄'] + 'body_age'=>$get_body_value['身体年龄'], + 'record_type' => $type ]; if(strlen($set_data['record_time']) <= 12){ // 时间日期转换,把'Y-m-d'转换成'Y-m-d H:i:s'格式 $set_data['record_time'] = $this->addCurrentTimeToDateString($set_data['record_time']); } - - $set_user_data = Db::table($this->card_use_db_name['1'])->insert($set_data); - if($set_user_data){ - // 返回简要数据 - if($data['type'] == 1){ - return $this->msg([ - 'acd_id'=>2, - 'height'=>$get_body_value['身高'].',CM', - 'weight'=>$get_body_value['体重'].',公斤', - 'bmi'=>$get_body_value['BMI'], - 'target_current'=>$target_current, - ]); - } + // 启动事务 + Db::startTrans(); + try{ + $set_user_data = Db::table($this->card_use_db_name['1'])->insert($set_data); + $update_user_data = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update(['height'=>$get_body_value['身高'],'weight'=>$get_body_value['体重']]); - }else{ + // 提交事务 + Db::commit(); + return $this->msg([ + 'acd_id'=>2, + 'height'=>$get_body_value['身高'].',CM', + 'weight'=>$get_body_value['体重'].',公斤', + 'bmi'=>$get_body_value['BMI'], + // 'user_set_height'=>$get_body_value['身高'], + // 'user_set_weight'=>$get_body_value['体重'], + 'target_current'=>$target_current, + ]); + } catch (\Exception $e) { + // 回滚事务 + Db::rollback(); return $this->msg(10002); } + } // 添加身高体重bmi的标准 public function hwb_standard($data){ - // dump($data); - // die; $linshi_data = []; $month_num = $this->calculateAgeInMonthsWithPrecision($data['birthday']); - // dump($month_num); $gender_val = $data['gender']; if($data['age'] < $this->age_limit){ foreach ($data as $key => $value) { @@ -643,8 +972,6 @@ class Card extends Base{ }else if($key =='体重'){ $linshi_data['体重'] = $this->bhw_list['weight']; $bhw_date = Db::table($this->card_use_db_name['9'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); - // dump($data['体重']); - // dump($bhw_date); if($bhw_date){ $linshi_data['体重'][0]['max_val'] = $bhw_date[0]['f2sd']; $linshi_data['体重'][1]['min_val'] = $bhw_date[0]['f2sd']; @@ -659,7 +986,6 @@ class Card extends Base{ }else if($key =='BMI'){ $linshi_data['BMI'] = $this->bhw_list['bmi']; $bhw_date = Db::table($this->card_use_db_name['10'])->where("Month <= $month_num and Sex = '$gender_val'")->order('Month desc')->limit(1)->select(); - // dump($bhw_date); if($bhw_date){ $linshi_data['BMI'][0]['max_val'] = $bhw_date[0]['f1sd']; $linshi_data['BMI'][1]['min_val'] = $bhw_date[0]['f1sd']; @@ -670,10 +996,7 @@ class Card extends Base{ } } } - // dump($linshi_data); - // die; foreach ($linshi_data as $key => $value) { - // dump($value); foreach ($value as $k => $v) { if($data[$key] >= $v['min_val'] && $data[$key] < $v['max_val']){ // 如果落在区间内 @@ -694,10 +1017,7 @@ class Card extends Base{ $data['体重2'] = $data['体重'].',无,无'; $data['BMI2'] = $data['BMI'].',无,无'; } - // dump($data); - // die; return $data; - // dump($data); } @@ -705,13 +1025,11 @@ class Card extends Base{ public function modify_weight_action($data){ // $data['aud_id'] = 26; // $data['weight'] = 60; - // dump($data); - // die; $result = Db::query(" select TOP 1 - acbd.weight, + acbd.weight_val as weight, aud.target_weight, aud.initial_weight, aud.initial_date @@ -730,9 +1048,6 @@ class Card extends Base{ return $this->msg(10005); } $result_update = Db::table($this->card_use_db_name['2'])->where(['id'=>$data['aud_id']])->update($bhw_date); - // dump($result_update); - // dump($result[0]['weight']); - // dump($result); if($result_update){ $target_current = $this->base_target_initial_cumulative_weight([ @@ -741,8 +1056,7 @@ class Card extends Base{ 'initial_weight'=>$data['type'] == 1?$result[0]['initial_weight']:$data['weight'], 'initial_date'=>$data['type'] == 1?$result[0]['initial_date']:$data['time'], ]); - // die; - // dump($target_current); + return $this->msg($target_current); }else{ return $this->msg(10002); @@ -750,7 +1064,69 @@ class Card extends Base{ } - ################################################card_record_detailed_information + ################################################card_bmi_evaluation + public function bmi_evaluation_action($data){ + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + if(!array_key_exists('code',$data) || !array_key_exists('data',$data)){ + return $this->msg(99999,'网络异常,请稍后重试1'); + } + if($data['code'] != 0){ + return $this->msg(99999,'网络异常,请稍后重试2'); + } + if(!is_array($data['data'])){ + return $this->msg(99999,'网络异常,请稍后重试3'); + } + if(!array_key_exists('bmi',$data['data']) || !array_key_exists('bmilevel',$data['data']) || !array_key_exists('bmilevelcolor',$data['data']) || !array_key_exists('bmilevellist',$data['data'])){ + return $this->msg(99999,'网络异常,请稍后重试4'); + } + if(!is_array($data['data']['bmilevellist'])){ + return $this->msg(99999,'网络异常,请稍后重试5'); + } + $num = 0; + $subsection_val = 0; + $temporary_subsection_val = null; + foreach ($data['data']['bmilevellist'] as $key => $value) { + if(!array_key_exists('maxvalue',$value) || !array_key_exists('minvalue',$value)){ + return $this->msg(99999,'网络异常,请稍后重试6'); + } + // 判断是否可以进行比较,规则是否正确 + if(is_numeric($value['maxvalue']) && is_numeric($value['minvalue'])){ + if($data['data']['bmi'] >= $value['minvalue'] && $data['data']['bmi'] < $value['maxvalue']){ + // 在落点内 + $subsection_val = bcsub($value['maxvalue'],$value['minvalue'],1);//获取最大最小值差 + $temporary_subsection_val = bcsub($data['data']['bmi'],$value['minvalue'],1);//获取当前值与最小值差 + $temporary_subsection_val = bcdiv($temporary_subsection_val,$subsection_val,1);//获取当前值与最小值差与最大最小值差之比 + $subsection_val = bcdiv(100,count($data['data']['bmilevellist']),1);//每段应该的百分比 + $temporary_subsection_val = bcmul($subsection_val,$temporary_subsection_val,1);//获取当前值与最小值差与最大最小值差之比与总段数之比 + $temporary_subsection_val = bcadd($temporary_subsection_val,bcmul($subsection_val,$num,1),1); + }else{ + $num = $num + 1; + } + } + } + + if($temporary_subsection_val === null){ + if($data['data']['bmi'] >= $data['data']['bmilevellist'][count($data['data']['bmilevellist'])-1]['maxvalue']){ + $temporary_subsection_val = 100; + }else{ + return $this->msg(99999,'网络异常,请稍后重试7'); + } + } + $data['data']['offset'] = $temporary_subsection_val; + $data = $data['data']; + // 处理key名称一致start + foreach ($data['bmilevellist'] as $key => $value) { + $data['bmilevellist'][$key]['max_val'] = $value['maxvalue']; + $data['bmilevellist'][$key]['min_val'] = $value['minvalue']; + unset($data['bmilevellist'][$key]['minvalue']); + unset($data['bmilevellist'][$key]['maxvalue']); + } + // 处理key名称一致end + return $this->msg($data); + } ################################################################其他接口################################################################ diff --git a/application/testapp/controller/Cardparts.php b/application/testapp/controller/Cardparts.php index 30ca62a..b173ba8 100644 --- a/application/testapp/controller/Cardparts.php +++ b/application/testapp/controller/Cardparts.php @@ -179,17 +179,18 @@ class Cardparts extends Base{ $age = $data['age']['value']; $weight = 0; $temporary_arr = [ - 'score_name' =>$data['score']['name'], - 'score_value' =>$data['score']['value'], - 'score_unit' =>$data['score']['unit'], - 'body_type_name' =>$data['body_type']['name'], - 'body_type_value' =>$data['body_type']['value'], - 'body_type_unit' =>$data['body_type']['unit'], + 'score_name' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['name']:'', + 'score_value' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['value']:'', + 'score_unit' =>$data['record_type']['value'] == 'by_device_adc'?$data['score']['unit']:'', + 'body_type_name' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['name']:'', + 'body_type_value' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['value']:'', + 'body_type_unit' =>$data['record_type']['value'] == 'by_device_adc'?$data['body_type']['unit']:'', // 'record_time' =>str_replace('-', '/', $data['record_time']), 'record_time' =>$data['record_time'], 'top_list'=>[], 'bottom_list'=>[], ]; + // die; $date_temporary = new \DateTime($temporary_arr['record_time']); // 使用 format 方法来指定新的日期和时间格式 @@ -216,9 +217,14 @@ class Cardparts extends Base{ $temporary_arr['top_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['top_list'][$key]['list'],$temporary_arr['top_list'][$key]['value'],$temporary_arr['top_list'][$key]['standard']); } } + + // 如果是没有阻抗的测试,那么就不要底部的其他数据了 + if($data['record_type']['value'] != 'by_device_adc'){ + $temporary_arr['bottom_list'] = []; + return $temporary_arr; + } // 处理底部list foreach ($temporary_arr['bottom_list'] as $key => $value) { - // dump($value['key_name']); // 脂肪率& if($value['key_name'] == 'fat_r'){ if($age < 30){ @@ -248,18 +254,15 @@ class Cardparts extends Base{ } // 肌肉率 else if($value['key_name'] == 'muscle'){ - // dump('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); $temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender]; // 处理异常 if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){ $temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]); } $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); - // dump($temporary_arr['bottom_list'][$key]); } // 肌肉量 else if($value['key_name'] == 'muscleval'){ - // dump('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%'); $temporary_arr['bottom_list'][$key]['list'] = $this->muscle_muscleval[$gender]; $temporary_arr['bottom_list'][$key]['list'] = $this->calculate_new_standard($temporary_arr['bottom_list'][$key]['list'],$weight,$value['key_name']); // 处理异常 @@ -267,7 +270,6 @@ class Cardparts extends Base{ $temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]); } $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); - // dump($temporary_arr['bottom_list'][$key]); } // 水分 else if($value['key_name'] == 'water'){ @@ -307,7 +309,6 @@ class Cardparts extends Base{ $temporary_arr['bottom_list'][$key]['list'] = $this->bone[$gender]['60']; } } - // dump($temporary_arr['bottom_list'][$key]); // 处理异常 if($temporary_arr['bottom_list'][$key]['standard'] == '异常'){ $temporary_arr['bottom_list'][$key] = $this->handling_exceptions($temporary_arr['bottom_list'][$key]); @@ -351,11 +352,6 @@ class Cardparts extends Base{ $temporary_arr['bottom_list'][$key]['offset'] = $this->calculate_landing_point($temporary_arr['bottom_list'][$key]['list'],$temporary_arr['bottom_list'][$key]['value'],$temporary_arr['bottom_list'][$key]['standard']); } } - // dump($data['gender']); - // dump($data['age']['value']); - // // dump($temporary_arr['top_list']); - // dump($temporary_arr['bottom_list']); - // die; return $temporary_arr; } diff --git a/application/testapp/controller/Cardpublic.php b/application/testapp/controller/Cardpublic.php index 7c9f35d..da0f2f6 100644 --- a/application/testapp/controller/Cardpublic.php +++ b/application/testapp/controller/Cardpublic.php @@ -12,6 +12,7 @@ class Cardpublic extends Base{ '2'=>'test_app_card_data_sub_item', '3'=>'test_app_card_data_sub_item_data', '4'=>'test_admin_estimate', + '5'=>'test_app_card_data' ]; protected $curve_color = ['#f7b03e','#fb7b92','#ff9f40','#3fcba7',]; @@ -24,7 +25,7 @@ class Cardpublic extends Base{ // 获取卡片数据 - public function get_card_content($data = ['aud_id'=>'83','acd_id'=>'10','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + public function get_card_content($data = ['aud_id'=>'11','acd_id'=>'13','token'=>'caadd1be045a65f30b92aa805f1de54a']){ // try { // // 你的业务逻辑 // $return_data = @@ -42,7 +43,7 @@ class Cardpublic extends Base{ // $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; // $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; // $this->record_api_log($data, $logContent, null); - // return $this->msg(99999,'接口错误'); + // return $this->msg(99999); // } try { // 你的业务逻辑 @@ -52,6 +53,15 @@ class Cardpublic extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } $return_data = $this->get_card_content_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -68,14 +78,15 @@ class Cardpublic extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // {"acd_id":"11","name":"200米","record_time":"2024-09-27","data":"02:00","aud_id":"1","token":"57bd45e3a963b372ea2d873e4bd8d1f8","aan_id":"1"} // 存储信息 - public function data_save($data = ['aud_id'=>'1','acd_id'=>'10','name'=>'50米','data'=>'9.5','record_time'=>'2024-10-11']){ + public function data_save($data = ['aud_id'=>'11','acd_id'=>'16','name'=>'排球','data'=>'33','record_time'=>'2024-10-18']){ + // {"acd_id":"10","name":"1000米","record_time":"2024-10-18","data":"05:00","aud_id":"24","token":"6441bf7dabea7b3360a30240d3b19fc5","aan_id":"4"} try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -84,6 +95,18 @@ class Cardpublic extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('data', $data) || !array_key_exists('record_time', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['name'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['record_time'],'datetime')){ + return $this->msg(10005); + } $return_data = $this->data_save_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -100,7 +123,7 @@ class Cardpublic extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -115,6 +138,12 @@ class Cardpublic extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } $return_data = $this->get_label_list_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -131,7 +160,7 @@ class Cardpublic extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -146,6 +175,21 @@ class Cardpublic extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } $return_data = $this->card_motion_curve_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -162,7 +206,7 @@ class Cardpublic extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -177,6 +221,21 @@ class Cardpublic extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['name'],'str')){ + return $this->msg(10005); + } $return_data = $this->data_contrast_obtain_data_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -193,11 +252,11 @@ class Cardpublic extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } - // 数据对比-对比数据 + // 数据对比-对比数据(暂时荒废) public function data_contrast_contrast_data($data = ['before_id'=>'1','after_id'=>'3']){ try { // 你的业务逻辑 @@ -223,7 +282,7 @@ class Cardpublic extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -237,6 +296,18 @@ class Cardpublic extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('name', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['name'],'str')){ + return $this->msg(10005); + } $return_data = $this->obtain_history_record_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -253,7 +324,7 @@ class Cardpublic extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -267,6 +338,9 @@ class Cardpublic extends Base{ if(!array_key_exists('id', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } $return_data = $this->history_record_del_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -283,154 +357,98 @@ class Cardpublic extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 获取手动记录内容 - public function obtain_manual_record_content($data = ['aud_id'=>1]){ - if(count(input('post.')) > 0){ - $data = input('post.'); - } - if(!array_key_exists('aud_id', $data)){ - return $this->msg(10001); - } - $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); - if(!$user_data){ - return $this->msg(10004); - } - $card_data = [ - ['id'=>'2','height'=>true,'weight'=>true,'number'=>false,'time'=>false,'list'=>[]], - ['id'=>'6','height'=>false,'weight'=>false,'number'=>true,'time'=>true,'list'=>[]], - [ - 'id'=>'10', - 'height'=>false, - 'weight'=>false, - 'number'=>false, - 'time'=>false, - 'list'=>[ - [ - 'id'=>'1', - 'name'=>'1000米', - 'number'=>false, - 'type'=>4, - 'time'=>true, - 'describe'=>'时长', - 'unit'=>'', - ], - [ - 'id'=>'2', - 'name'=>'800米', - 'number'=>false, - 'type'=>4, - 'time'=>true, - 'describe'=>'时长', - 'unit'=>'', - ], - [ - 'id'=>'3', - 'name'=>'50米', - 'number'=>true, - 'type'=>2, - 'time'=>false, - 'describe'=>'时长', - 'unit'=>'秒', - ], - ] - ], - [ - 'id'=>'12', - 'height'=>false, - 'weight'=>false, - 'number'=>false, - 'time'=>false, - 'list'=>[ - [ - 'id'=>'7', - 'name'=>'立定跳远', - 'number'=>true, - 'type'=>1, - 'time'=>false, - 'describe'=>'距离', - 'unit'=>'CM', - ], - ] - ], - [ - 'id'=>'13', - 'height'=>false, - 'weight'=>false, - 'number'=>false, - 'time'=>false, - 'list'=>[ - [ - 'id'=>'8', - 'name'=>'引体向上', - 'number'=>true, - 'type'=>1, - 'time'=>false, - 'describe'=>'个数', - 'unit'=>'个', - ], - [ - 'id'=>'9', - 'name'=>'1分钟仰卧起坐', - 'number'=>true, - 'type'=>1, - 'time'=>false, - 'describe'=>'个数', - 'unit'=>'个', - ], - ] - ], - [ - 'id'=>'14', - 'height'=>false, - 'weight'=>false, - 'number'=>false, - 'time'=>false, - 'list'=>[ - [ - 'id'=>'10', - 'name'=>'坐位体前屈', - 'number'=>true, - 'type'=>1, - 'time'=>false, - 'describe'=>'距离', - 'unit'=>'CM', - ], - ] - ], - ]; - if($user_data['gender'] == 1){ - unset($card_data[2]['list'][1]);//800米 - unset($card_data[4]['list'][1]);//仰卧起坐 - }else if($user_data['gender'] == 2){ - unset($card_data[2]['list'][0]);//1000米 - unset($card_data[4]['list'][0]);//引体向上 - } - foreach ($card_data as $key => $value) { - $card_data[$key]['list'] = array_values($card_data[$key]['list']); - } - - return $this->msg($card_data); + public function obtain_manual_record_content($data = ['aud_id'=>11]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('aud_id', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); + if(!$user_data){ + return $this->msg(10004); + } + $card_data_c = Db::table($this->cardpublic_use_db_name['2']) + ->where(['is_del'=>0]) + ->field('id,name,type,unit,unit2,suit_gender,acd_id') + ->select(); + $card_data_c2 = []; + foreach ($card_data_c as $key => $value) { + $temporary_arr = []; + $temporary_arr['id'] = $value['acd_id']; + $temporary_arr['height'] = false; + $temporary_arr['weight'] = false; + $temporary_arr['number'] = false; + $temporary_arr['time'] = false; + $temporary_arr['list'] = []; + $card_data_c2[$value['acd_id']] = $temporary_arr; + } + foreach ($card_data_c as $key => $value) { + if(in_array($user_data['gender'], explode(",", $value['suit_gender']))){ + $temporary_arr = []; + $temporary_arr['id'] = $value['id']; + $temporary_arr['name'] = $value['name']; + $temporary_arr['number'] = $value['unit2'] == '时长'?false:true; + $temporary_arr['type'] = $value['type']; + $temporary_arr['time'] = $value['unit2'] == '时长'?true:false; + $temporary_arr['describe'] = $value['unit2']; + $temporary_arr['unit'] = $value['unit'] == "分/秒"?'': $value['unit']; + array_push($card_data_c2[$value['acd_id']]['list'],$temporary_arr); + }else{ + continue; + } + + } + $card_data = [ + ['id'=>'2','height'=>true,'weight'=>true,'number'=>false,'time'=>false,'list'=>[]], + ['id'=>'6','height'=>false,'weight'=>false,'number'=>true,'time'=>true,'list'=>[]], + ]; + foreach ($card_data_c2 as $key => $value) { + array_push($card_data,$value); + } + // 成功 + $this->record_api_log($data, null, $card_data); + return $this->msg($card_data); + // return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } } - - - - ################################################################action################################################################ ################################################################action################################################################ ##################################################get_card_content################################################## public function get_card_content_action($data){ + // 查找用户是存在 $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,gender')->find(); if(!$user_data){ return $this->msg(10004); } + // 卡片是否存在,以及是否含有子项 $card_data_sub_item = Db::table($this->cardpublic_use_db_name['2'])->where("acd_id = ".$data['acd_id']." and is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit')->select(); + if(!$card_data_sub_item){ return $this->msg(10004); } @@ -470,7 +488,7 @@ class Cardpublic extends Base{ $return_data['line_list'] = $this->level_data; // 查询最后一次成绩 $data_this_time = Db::table($this->cardpublic_use_db_name['3'])->where(['aud_id'=>$data['aud_id'],'acdsi_id'=>$value['id'],'is_del'=>0])->order('record_time desc')->field('id,detailed_msg,achievement,record_time')->find(); - // dump($data_this_time); + if($data_this_time){ $data_this_time['detailed_msg'] = json_decode($data_this_time['detailed_msg'],true); // 设置基础数据 @@ -525,6 +543,11 @@ class Cardpublic extends Base{ $temporary_arr_c['today_times'] = $temporary_arr_c['today_times'].'次'; $temporary_arr_c['all_times'] = $temporary_arr_c['all_times'].'次'; + }else{ + $project_describe = Db::table($this->cardpublic_use_db_name['2'])->where(['id'=>$value['id'],'is_del'=>0])->field('id,project_describe')->find(); + if($project_describe){ + $temporary_arr_c['describe'] = $project_describe['project_describe']; + } } array_push($return_data['label_data'],$temporary_arr_c); } @@ -541,7 +564,7 @@ class Cardpublic extends Base{ // 查找项目是否存在,以及获取项目信息 $card_data_sub_item_data = Db::table($this->cardpublic_use_db_name['2'])->where("name = '".$data['name']."' and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,type,name,unit,acd_id')->find(); if(!$card_data_sub_item_data){ - return $this->msg(10004); + return $this->msg(10004,'1'); } // 如果项目数据类型为分秒格式 if($card_data_sub_item_data['type'] == 1){ @@ -556,15 +579,11 @@ class Cardpublic extends Base{ } }else if($card_data_sub_item_data['type'] == 2){ // 判断一个字符串是否为两位以内小数 - // dump($this->isTwoDecimalOrLess($data['data'])); if(!$this->isTwoDecimalOrLess($data['data'])){ return $this->msg(10005); } } - - $score_all_data = $this->calculation_score($user_data['gender'],$data,$card_data_sub_item_data['type']); - // dump($score_all_data); - // die; + $score_all_data = $this->calculation_score($user_data['gender'],$data,$card_data_sub_item_data['type'],$card_data_sub_item_data['unit']); $save_data = [ 'acd_id' => $card_data_sub_item_data['acd_id'], 'acdsi_id' => $card_data_sub_item_data['id'], @@ -629,7 +648,6 @@ class Cardpublic extends Base{ return $this->msg(10004); } $card_sub_item_data = Db::table($this->cardpublic_use_db_name['3'])->where(['acd_id'=>$data['acd_id'],'aud_id'=>$data['aud_id'],'is_del'=>0])->order('record_time desc')->field('id,acdsi_id,score,LEFT(record_time,10) as r_t,record_time')->select(); - // dump($card_sub_item_data); $card_sub_item_type = Db::table($this->cardpublic_use_db_name['2'])->where("acd_id = ".$data['acd_id']." and is_del = 0 and suit_gender LIKE '%".$user_data['gender']."%'")->field('id,name,unit')->select(); $temporary_arr = []; $return_data = []; @@ -639,9 +657,8 @@ class Cardpublic extends Base{ } // 往临时数组内填入数据 foreach ($card_sub_item_data as $key => $value) { - // dump($value); array_push($temporary_arr[$value['acdsi_id']]['time'],$value['r_t']); - array_push($temporary_arr[$value['acdsi_id']]['data'],$value['score']); + array_push($temporary_arr[$value['acdsi_id']]['data'],$this->convertStringToNumber($value['score'])); } $num = 0; foreach ($temporary_arr as $key => $value) { @@ -668,7 +685,6 @@ class Cardpublic extends Base{ } ##################################################data_contrast_obtain_data################################################## public function data_contrast_obtain_data_action($data){ - // dump($data); // $user_data = Db::table($this->cardpublic_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,gender')->find(); $card_data = Db::table($this->cardpublic_use_db_name['2'])->where(['acd_id'=>$data['acd_id'],'name'=>$data['name'],'is_del'=>0])->find(); @@ -678,8 +694,6 @@ class Cardpublic extends Base{ ->field('id,achievement,score,unit,record_time') ->order('record_time desc') ->select(); - - // dump($result_data); $return_data = []; foreach ($result_data as $key => $value) { if($value['unit'] == '分/秒'){ @@ -690,17 +704,13 @@ class Cardpublic extends Base{ "id"=> $value['id'], // "v1"=> $value['achievement'].$value['unit'], "v1"=> $value['unit'] == '分/秒'?$temporary_arr_e1[0].$temporary_arr_e2[0].$temporary_arr_e1[1].$temporary_arr_e2[1]:$value['achievement'].$value['unit'], - "v2"=> $value['score'].'分', + "v2"=> $this->convertStringToNumber($value['score']).'分', "v1_name"=> "成绩", "v2_name"=> "得分", "r_t"=> substr($value['record_time'], 0, 10) ]; array_push($return_data,$temporary_arr); } - // dump($user_data); - // dump($card_data); - // dump($result_data); - // dump($return_data); return $this->msg($return_data); } ##################################################data_contrast_contrast_data################################################## @@ -716,7 +726,6 @@ class Cardpublic extends Base{ return $this->msg(10003); } - dump($card_data); } ##################################################obtain_history_record################################################## public function obtain_history_record_action($data){ @@ -748,7 +757,7 @@ class Cardpublic extends Base{ "id"=> $value['id'], // "v1"=> $value['achievement'].$value['unit'], "v1"=> $value['unit'] == '分/秒'?$temporary_arr_e1[0].$temporary_arr_e2[0].$temporary_arr_e1[1].$temporary_arr_e2[1]:$value['achievement'].$value['unit'], - "v2"=> $value['score'].'分', + "v2"=> $this->convertStringToNumber($value['score']).'分', "v1_name"=> "成绩", "v2_name"=> "得分", "record_time"=> $value['record_time'] @@ -779,10 +788,7 @@ class Cardpublic extends Base{ ################################################################tool################################################################ // 计算得分成绩以及线性进度 - public function calculation_score($gender,$data,$type){ - // dump($gender); - // dump($data); - // dump($type); + public function calculation_score($gender,$data,$type,$unit_msg){ $card_name['project_name'] = $data['name']; $card_name['score'] = 0; $card_name['offset'] = 0; @@ -806,10 +812,7 @@ class Cardpublic extends Base{ } } } - // dump($type); foreach ($card_name['rule']['content'] as $key => $value) { - // dump($key); - // dump($value); if($type == '4'){ $rule_result = $this->convertMinutesSecondsToStringSeconds($value[0]); $data_result = $this->convertMinutesSecondsToStringSeconds($data['data']); @@ -842,7 +845,6 @@ class Cardpublic extends Base{ } if($result == true){ - // dump($value[2]); $card_name['score'] = $value[2]; break; @@ -854,17 +856,11 @@ class Cardpublic extends Base{ // 乘 bcmul(,,20) // 除 bcdiv(,,20) foreach ($describe_list as $key => $value) { - // dump($key); if($card_name['score'] >= $value['min_val'] && $card_name['score'] <= $value['max_val']){ $card_name['standard'] = $value['text']; $card_name['color'] = $value['color']; - // dump($card_name); if($card_name['score'] < 100){ // 计算当前区间内的比值() - // dump($card_name['score']); - // dump($value); - // dump(bcsub($card_name['offset'],$value['min_val'],20)); - // dump(bcsub($value['max_val'],$value['min_val'],20)); $card_name['offset'] = bcmul(bcdiv(bcsub($card_name['score'],$value['min_val'],20),bcsub($value['max_val'],$value['min_val'],20),4),25,2); // 计算全线性下比值 $card_name['offset'] = bcadd($card_name['offset'],bcmul(($key),25,0),0); @@ -876,15 +872,13 @@ class Cardpublic extends Base{ } $card_name['max_score'] = $card_name['rule']['content'][0][2]; $card_name['describe'] = $card_name['rule']['describe']; - $card_name['unit_data'] = $card_name['rule']['unit_data']; + $card_name['unit_data'] = $unit_msg; // $card_name['default_data_format'] = $card_name['rule']['value']; // $card_name['default_data_type'] = $card_name['rule']['type']; // $card_name['list'] = $describe_list; unset($card_name['rule']); - // dump($card_name); - // die; return $card_name; } diff --git a/application/testapp/controller/Device.php b/application/testapp/controller/Device.php index b40d35d..1aebc25 100644 --- a/application/testapp/controller/Device.php +++ b/application/testapp/controller/Device.php @@ -47,7 +47,7 @@ class Device extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -62,7 +62,15 @@ class Device extends Base{ if(!array_key_exists('token', $data) || !array_key_exists('device_id', $data) || !array_key_exists('device_mac', $data)){ return $this->msg(10001); } - + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['device_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['device_mac'],'str')){ + return $this->msg(10005); + } $return_data = $this->device_binding_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -78,9 +86,8 @@ class Device extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } - } // 获取用户设备列表 public function device_user_data_list($data = ['token'=>'caadd1be045a65f30b92aa805f1de54a']){ @@ -92,6 +99,9 @@ class Device extends Base{ if(!array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } $return_data = $this->device_user_data_list_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -107,7 +117,7 @@ class Device extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -121,6 +131,12 @@ class Device extends Base{ if(!array_key_exists('token', $data) || !array_key_exists('id', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } $return_data = $this->device_unbinding_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -136,7 +152,7 @@ class Device extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -151,6 +167,15 @@ class Device extends Base{ if(!array_key_exists('mac', $data) || !array_key_exists('acd_id', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['mac'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['acd_id'],'intnum')){ + return $this->msg(10005); + } $return_data = $this->device_mac_get_content_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -166,7 +191,7 @@ class Device extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -278,19 +303,13 @@ class Device extends Base{ ->where(['adcd.id'=>$data['id']]) ->field('adcd.id,adcd.bind_account_id,add2.acd_id') ->find(); - // dump(time()); - // die; $device_binding_user = explode(',',$device_binding_user['bind_account_id']); - // dump($device_binding_user); $key = array_search($result_user['id'], $device_binding_user); if($key !== false){ unset($device_binding_user[$key]); }else{ return $this->msg([]); } - // dump($device_binding_user); - // dump(implode(',',$device_binding_user)); - // die; $device_binding = Db::table($this->device_use_db_name['3'])->where(['id'=>$data['id']])->update([ 'bind_account_id'=>implode(',',$device_binding_user), ]); @@ -305,8 +324,6 @@ class Device extends Base{ public function device_mac_get_content_action($data){ $user_id = Db::table($this->device_use_db_name['2'])->where(['token'=>$data['token']])->field('id,token')->find(); - // dump($user_id); - // die; $likePattern = '%' . $user_id['id'] . '%'; $result_device = Db::table($this->device_use_db_name['3']) ->alias('adcd') diff --git a/application/testapp/controller/Download.php b/application/testapp/controller/Download.php index c5b68c7..ab6723a 100644 --- a/application/testapp/controller/Download.php +++ b/application/testapp/controller/Download.php @@ -1,6 +1,6 @@ order('id desc')->find(); // echo '你好,这里仅仅是个下载展示页面-1'; // echo '
    点击下载'; - $url = Db::table('test_app_version_log')->order('id desc')->find(); + $url = Db::table('app_version_log')->order('id desc')->find(); $this->assign([ 'url' => $url['download_url'], @@ -21,7 +21,7 @@ class Download extends Base{ public function demo2(){ - $url = Db::table('test_app_version_log')->order('id desc')->find(); + $url = Db::table('app_version_log')->order('id desc')->find(); $this->assign([ diff --git a/application/testapp/controller/Index.php b/application/testapp/controller/Index.php index 8910094..173165f 100644 --- a/application/testapp/controller/Index.php +++ b/application/testapp/controller/Index.php @@ -6,7 +6,7 @@ use think\Db; use \think\Validate; class Index extends Base{ - protected $moren_gufen_diqu = '上海,上海'; + protected $moren_gufen_diqu = '北京,北京'; protected $db_name = ['2'=>'test_app_card_body_data','6'=>'test_app_card_skip_data','8'=>'test_app_card_vitalcapacity_data','10'=>'test_app_card_data_sub_item_data']; protected $index_use_db_name = [ '1'=>'test_app_version_log', @@ -60,7 +60,7 @@ class Index extends Base{ ################################################################个人资料卡################################################################ // 检测版本及判断是否登录失效 - public function login_invalid_version($data = ['token'=>NULL]){ + public function login_invalid_version($data = ['token'=>'']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -96,7 +96,7 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } @@ -111,9 +111,14 @@ class Index extends Base{ if(count(input('post.')) > 0){ $data = input('post.'); } - if(!array_key_exists('token', $data)){ + if(!array_key_exists('token', $data) || !array_key_exists('measure_model', $data)){ return $this->msg(10001); } + + if($data['measure_model'] != '1' && $data['measure_model'] != '2'){ + return $this->msg(10001); + } + unset($data['token']); $verify_result = $this->verify_parameters($data,'register'); if(!is_array($verify_result)){ @@ -138,7 +143,7 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } @@ -182,7 +187,7 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } @@ -198,6 +203,9 @@ class Index extends Base{ if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['id']])->update(['is_del'=>1]); if($result){ @@ -222,7 +230,7 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -230,7 +238,7 @@ class Index extends Base{ // 获取账号下用户列表 // $type 1获取列表,2获取详细信息 - public function get_user_card_list($data = ['aan_id'=>1,'type'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function get_user_card_list($data = ['aan_id'=>4,'type'=>2,'token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -241,12 +249,27 @@ class Index extends Base{ $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aan_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); - $result = Db::table($this->index_use_db_name['2'])->where(['aan_id'=>$data['aan_id'],'is_del'=>0])->select(); + $result = Db::table($this->index_use_db_name['2']) + ->where(['aan_id'=>$data['aan_id'],'is_del'=>0]) + ->field('id,aan_id,nickname,birthday,gender,card_order,target_weight,initial_weight,initial_date,grade,head_pic,weight,height,identity_name,address,identity_id,measure_model') + ->select(); + $temporary_data = []; if($data['type'] == 1){ for ($i=0; $i < count($result); $i++) { - array_push($temporary_data,['id'=>$result[$i]['id'],'nickname'=>$result[$i]['nickname'],'identity_name'=>$result[$i]['identity_name'],'identity_id'=>$result[$i]['identity_id']]); + array_push($temporary_data,[ + 'id'=>$result[$i]['id'], + 'nickname'=>$result[$i]['nickname'], + 'identity_name'=>$result[$i]['identity_name'], + 'identity_id'=>$result[$i]['identity_id'], + ]); } }else{ for ($i=0; $i < count($result); $i++) { @@ -270,13 +293,13 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 获取指定用户详细信息 - public function get_user_data_information($data = ['aud_id'=>1]){ + public function get_user_data_information($data = ['aud_id'=>11]){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -288,85 +311,57 @@ class Index extends Base{ $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); return $this->msg(10001); } - - // 获取用户信息 - $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id']])->field('id,aan_id,nickname,head_pic,birthday,gender,card_order,target_weight,initial_weight,initial_date,weight,address,identity_id')->find(); - // 获取用户身体卡片信息 - $weight_data_pd = Db::table($this->index_use_db_name['3'])->where(['aud_id'=>$data['aud_id']])->order('record_time desc')->field('id,weight_val,record_time')->find(); - - // dump($card_pic_color); - // die; - if(!$result){ - // 失败 - $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); - return $this->msg(10003); + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + // 获取用户信息 + $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,aan_id,nickname,head_pic,birthday,gender,card_order,target_weight,initial_weight,initial_date,height,weight,address,identity_id,measure_model')->find(); + if(!$result){ + return $this->msg(10004); } - unset($result['ROW_NUMBER']); $result['age'] = $this->calculate_age($result['birthday']); - if($result['card_order'] === ''){ - $result['card_order'] = []; - $result['card_data_list'] = []; - $result['target_current'] = $this->base_target_initial_cumulative_weight([]); - - }else{ - $result['card_order'] = explode(',',$result['card_order']); + + // 从这里开始进入体脂还是体测的判断 + $result['card_order'] = explode(',',$result['card_order']); + if($result['measure_model'] == 1){// 这里是体测 $calculation_results = $this->get_user_card_data_list($result,$result['id']); $result['card_data_list'] = $calculation_results[0]; - $result['target_current'] = $calculation_results[1]; + $result['card_order'] = $calculation_results[1]; + + }else if($result['measure_model'] == 2){// 这里是体脂 + $result['card_data_list'] = []; + $result['card_order'] = []; + }else{ + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'measure_model数据不是1或者2',[]]); + return $this->msg(10004); } - - - if($weight_data_pd){ - $result['weight'] = $weight_data_pd['weight_val']; - } - - unset($result['target_weight']); - unset($result['initial_weight']); - unset($result['initial_date']); - - // 获取设备信息进入卡片 start - $likePattern = '%' . $result['aan_id'] . '%'; - $result_device = Db::table($this->index_use_db_name['4']) - ->alias('adcd') - ->join(''.$this->index_use_db_name['5'].' add','adcd.add_id = add.id','LEFT') - // ->where(['adcd.bind_account_id'=>$result['aan_id']]) - ->where("adcd.bind_account_id LIKE ?", [$likePattern]) - ->field('adcd.id,add.acd_id') - ->select(); - - $device_arr = []; - foreach ($result_device as $key => $value) { - if(!in_array($value['acd_id'],$device_arr)){ - array_push($device_arr,$value['acd_id']); - } - } - // dump($device_arr); - // die; - foreach ($result['card_data_list'] as $key => $value) { - if(in_array($value['acd_id'],$device_arr)){ - $result['card_data_list'][$key]['device_determine'] = true; - }else{ - $result['card_data_list'][$key]['device_determine'] = false; - } - // // 处理卡片的背景色背景图 - // foreach ($card_pic_color as $ck => $cv) { - // if($cv['id'] == $value['acd_id']){ - // $result['card_data_list'][$key]['background_color'] = $cv['background_color']; - // $result['card_data_list'][$key]['background_pic'] = $cv['background_pic']; - // } - // } - } - // 获取设备信息进入卡片 end - // 插入肺活量的卡片标准 + // // 获取设备信息进入卡片 start + // $likePattern = '%' . $result['aan_id'] . '%'; + // $result_device = Db::table($this->index_use_db_name['4']) + // ->alias('adcd') + // ->join(''.$this->index_use_db_name['5'].' add','adcd.add_id = add.id','LEFT') + // ->where("adcd.bind_account_id LIKE ?", [$likePattern]) + // ->field('adcd.id,add.acd_id') + // ->select(); + // $device_arr = []; + // foreach ($result_device as $key => $value) { + // if(!in_array($value['acd_id'],$device_arr)){ + // array_push($device_arr,$value['acd_id']); + // } + // } + // foreach ($result['card_data_list'] as $key => $value) { + // if(in_array($value['acd_id'],$device_arr)){ + // $result['card_data_list'][$key]['device_determine'] = true; + // }else{ + // $result['card_data_list'][$key]['device_determine'] = false; + // } + // } + // // 获取设备信息进入卡片 end if($result['address'] == ''){ $result['address'] = $this->moren_gufen_diqu; } - $result['vitalcapacity_data'] = $this->get_vitalcapacity_data($result['id']); - // 成功 $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',$result]); return $this->msg($result); - - } catch (\Exception $e) { // 捕获异常 $logContent["flie"] = $e->getFile(); @@ -378,13 +373,13 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 获取所有卡片列表信息 - public function get_card_all_list($data = ['aud_id'=>1,'token'=>'57bd45e3a963b372ea2d873e4bd8d1f8']){ + public function get_card_all_list($data = ['aud_id'=>11,'token'=>'57bd45e3a963b372ea2d873e4bd8d1f8']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -392,22 +387,31 @@ class Index extends Base{ } if(!array_key_exists('token', $data)){ // 失败 - $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); return $this->msg(10001); } - + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $user_card_list = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id'],'is_del'=>0])->field('id,card_order')->find(); if(!$user_card_list){ // 失败 - $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); + $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); return $this->msg(10003); } unset($user_card_list['ROW_NUMBER']); - $user_card_list['card_order'] = explode(',',$user_card_list['card_order']); - $all_card_list = Db::table($this->index_use_db_name['6'])->where(['is_del'=>0])->field('id,name,pic')->select(); + $user_card_list['card_order'] = explode(',',$user_card_list['card_order']); + foreach ($user_card_list['card_order'] as $key => $value) { + if(in_array($value,$this->default_card)){ + unset($user_card_list['card_order'][$key]); + } + } + $user_card_list['card_order'] = array_values($user_card_list['card_order']); + $all_card_list = Db::table($this->index_use_db_name['6'])->where(['is_del'=>0])->field('id,name,pic')->select(); + // die; $result = ['user'=>[],'all'=>[]]; foreach ($all_card_list as $key => $value) { if(in_array($value['id'],$user_card_list['card_order'])){ @@ -433,13 +437,13 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 保存用户的卡片排序 - public function save_user_card_order($data=['aud_id'=>11,'card_order'=>'2,8','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function save_user_card_order($data=['aud_id'=>11,'card_order'=>'2,6,10,12,13,8,14,16,15','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -447,15 +451,17 @@ class Index extends Base{ } if(!array_key_exists('aud_id', $data) || !array_key_exists('card_order', $data) || !array_key_exists('token', $data)){ // 失败 - $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); return $this->msg(10001); } - + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); if(!$this->is_num_array(explode(',',$data['card_order']))){ // 失败 - $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); - return $this->msg(10001,'数据内参数格式或值错误'); + $this->record_api_log($data, null, ['code'=>10001,'msg'=>'数据内参数格式或值错误',[]]); + return $this->msg(10005,'数据内参数格式或值错误'); } $result = Db::table($this->index_use_db_name['2'])->where(['id'=>$data['aud_id']])->update(['card_order'=>$data['card_order']]); if($result){ @@ -480,7 +486,7 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } @@ -517,7 +523,7 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -531,6 +537,9 @@ class Index extends Base{ $this->record_api_log($data, null, ['code'=>10001,'msg'=>'',[]]); return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } $user_data = Db::table($this->base_use_db_name['2'])->where(['id' => $data['aud_id']])->count(); if($user_data<=0){ $this->record_api_log($data, null, ['code'=>10003,'msg'=>'',[]]); @@ -562,7 +571,7 @@ class Index extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } ################################获取账号下信息操作################################ @@ -574,8 +583,10 @@ class Index extends Base{ $result = []; $db_arr = []; foreach ($data['card_order'] as $key => $value) { - if($value<10){ - $db_arr[$value] = Db::table($this->db_name[$value])->where(['aud_id'=>$aud_id,'is_del'=>'0'])->order('record_time desc')->limit(1)->select(); + if(in_array($value,$this->default_card)){ + // 过滤掉老版本的(268选项卡) + unset($data['card_order'][$key]); + continue; }else{ // 公共卡牌 $db_arr[$value] = Db::table($this->index_use_db_name['9'])->where(['aud_id'=>$aud_id,'acd_id'=>$value,'is_del'=>'0'])->order('record_time desc')->limit(1)->select(); @@ -583,36 +594,38 @@ class Index extends Base{ $temporary_data = Db::table($this->index_use_db_name['8'])->where(['id'=>$db_arr[$value][0]['acdsi_id']])->field('id,name')->find(); $db_arr[$value][0]['acdsi_name'] = $temporary_data['name']; } - } - if(count($db_arr[$value]) > 0){ - $db_arr[$value] = $db_arr[$value][0]; - }else{ - unset($db_arr[$value]); + if(count($db_arr[$value]) > 0){ + $db_arr[$value] = $db_arr[$value][0]; + }else{ + unset($db_arr[$value]); + } } } + $data['card_order'] = array_values($data['card_order']); // 获取卡片背景图,及背景色信息及其他信息 - $card_all_data = Db::table($this->index_use_db_name['6'])->field('id,name,page_url_record,page_url_report,page_url_bluetooth,key_word,background_color,background_pic')->select(); + $card_all_data = Db::table($this->index_use_db_name['6'])->where(['is_del'=>0])->field('id,name,page_url_record,page_url_report,page_url_bluetooth,key_word,background_color,background_pic')->select(); $card_all_data_result = []; foreach ($card_all_data as $key => $value) { $card_all_data_result[$value['id']] = $value; } // 获取卡片路径及卡片数组处理end - // 添加目标体重于当前体重差数据 - if(array_key_exists('2', $db_arr)){ - $target_current = $this->base_target_initial_cumulative_weight([ - 'weight'=>$db_arr['2']['weight']>0?$db_arr['2']['weight']:0, - 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, - 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, - 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, - ]); - }else{ - $target_current = $this->base_target_initial_cumulative_weight([ - 'weight'=>0, - 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, - 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, - 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, - ]); - } + // // 添加目标体重于当前体重差数据 + // if(array_key_exists('2', $db_arr)){ + // $target_current = $this->base_target_initial_cumulative_weight([ + // 'weight'=>$db_arr['2']['weight']>0?$db_arr['2']['weight']:0, + // 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, + // 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, + // 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, + // ]); + // }else{ + // $target_current = $this->base_target_initial_cumulative_weight([ + // 'weight'=>0, + // 'target_weight'=>$data['target_weight']>0?$data['target_weight']:0, + // 'initial_weight'=>$data['initial_weight']>0?$data['initial_weight']:0, + // 'initial_date'=>$data['initial_date']!=null?$data['initial_date']:0, + // ]); + // } + if(count($db_arr) <= 0){ // 没有数据,传递一个空的卡片 foreach ($data['card_order'] as $key => $value) { @@ -628,27 +641,14 @@ class Index extends Base{ $temporary_arr['background_color'] = $card_all_data_result[$value]['background_color']; $temporary_arr['background_pic'] = $card_all_data_result[$value]['background_pic']; $temporary_arr['inside_data'] = []; - if(array_key_exists($value, $this->card_data)){ - foreach ($this->card_data[$value][2] as $k => $v) { - array_push($temporary_arr['inside_data'],[ - 'key'=>$k, - 'name'=>$v[0], - 'value'=>$v[2], - 'unit'=>$v[1]!='无'?$v[1]:'', - 'standard'=>'', - 'color'=>'' - ]); - } - }else{ - array_push($temporary_arr['inside_data'],[ - 'key'=>'last_time', - 'name'=>'最近一次', - 'value'=>"--", - 'unit'=>'', - 'standard'=>'*分', - 'color'=>'' - ]); - } + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + 'name'=>'最近一次', + 'value'=>"--", + 'unit'=>'', + 'standard'=>'*分', + 'color'=>'' + ]); array_push($result,$temporary_arr); } }else{ @@ -663,94 +663,56 @@ class Index extends Base{ $temporary_arr['background_color'] = $card_all_data_result[$value]['background_color']; $temporary_arr['background_pic'] = $card_all_data_result[$value]['background_pic']; $temporary_arr['inside_data'] = []; - if(array_key_exists($value, $this->card_data)){ - if(array_key_exists($value,$db_arr)){ - $temporary_arr['id'] = $db_arr[$value]['id']; - $temporary_arr['record_time'] = $db_arr[$value]['record_time']; - foreach ($this->card_data[$value][2] as $k => $v) { - if($value == '2'){ - $tem_arr_2 = explode(',', $db_arr[$value][$k]); - }else if($value == '6' && $k == 'jump_time'){ - $time_conversion = $this->handle_hour_branch_second($db_arr[$value][$k]); - $tem_arr_2 = [$time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'],'','']; - }else{ - $tem_arr_2 = [$db_arr[$value][$k],'','']; - } - array_push($temporary_arr['inside_data'],[ - 'key'=>$k, - 'name'=>$v[0], - 'value'=>$tem_arr_2[0], - 'unit'=>$v[1]!='无'?$v[1]:'', - 'standard'=>$tem_arr_2[1]!='无'?$tem_arr_2[1]:'', - 'color'=>$tem_arr_2[2]!='无'?$tem_arr_2[2]:'' - ]); - } - }else{ - $temporary_arr['id'] = ''; - $temporary_arr['record_time'] = ''; - foreach ($this->card_data[$value][2] as $k => $v) { - array_push($temporary_arr['inside_data'],[ - 'key'=>$k, - 'name'=>$v[0], - 'value'=>$v[2], - 'unit'=>$v[1]!='无'?$v[1]:'', - 'standard'=>'', - 'color'=>'' - ]); - } - } + if(array_key_exists($value,$db_arr)){ + // 公共卡片内容 + $temporary_arr['id'] = $db_arr[$value]['id']; + $temporary_arr['record_time'] = $db_arr[$value]['record_time']; + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + // 'name'=>'最近一次', + 'name'=>"项目名称", + 'value'=>$db_arr[$value]['acdsi_name'], + 'unit'=>'', + 'standard'=>'', + 'color'=>'' + ]); + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + // 'name'=>'最近一次', + 'name'=>"成绩", + 'value'=>$db_arr[$value]['achievement'], + 'unit'=>$db_arr[$value]['unit'], + 'standard'=>'', + 'color'=>'' + ]); + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + // 'name'=>'最近一次', + 'name'=>'得分', + // 'value'=>$db_arr[$value]['score'], + 'value'=>$this->convertStringToNumber($db_arr[$value]['score']), + 'unit'=>'分', + 'standard'=>"", + 'color'=>'' + ]); }else{ - if(array_key_exists($value,$db_arr)){ - // 公共卡片内容 - $temporary_arr['id'] = $db_arr[$value]['id']; - $temporary_arr['record_time'] = $db_arr[$value]['record_time']; - array_push($temporary_arr['inside_data'],[ - 'key'=>'last_time', - // 'name'=>'最近一次', - 'name'=>"项目名称", - 'value'=>$db_arr[$value]['acdsi_name'], - 'unit'=>'', - 'standard'=>'', - 'color'=>'' - ]); - array_push($temporary_arr['inside_data'],[ - 'key'=>'last_time', - // 'name'=>'最近一次', - 'name'=>"成绩", - 'value'=>$db_arr[$value]['achievement'], - 'unit'=>$db_arr[$value]['unit'], - 'standard'=>'', - 'color'=>'' - ]); - array_push($temporary_arr['inside_data'],[ - 'key'=>'last_time', - // 'name'=>'最近一次', - 'name'=>'得分', - 'value'=>$db_arr[$value]['score'], - 'unit'=>'分', - 'standard'=>"", - 'color'=>'' - ]); - }else{ - $temporary_arr['id'] = ''; - $temporary_arr['record_time'] = ''; - array_push($temporary_arr['inside_data'],[ - 'key'=>'last_time', - 'name'=>'最近一次', - 'value'=>"--", - 'unit'=>'', - 'standard'=>'*分', - 'color'=>'' - ]); - } - + $temporary_arr['id'] = ''; + $temporary_arr['record_time'] = ''; + array_push($temporary_arr['inside_data'],[ + 'key'=>'last_time', + 'name'=>'最近一次', + 'value'=>"--", + 'unit'=>'', + 'standard'=>'*分', + 'color'=>'' + ]); } array_push($result,$temporary_arr); } } // 成功 // $this->record_api_log($data, null, ['code'=>0,'msg'=>'success',[$result,$target_current]]); - return [$result,$target_current]; + return [$result,$data['card_order']]; // } catch (\Exception $e) { // // 捕获异常 // $this->record_api_log($data, $e->getMessage(), null); @@ -767,159 +729,290 @@ class Index extends Base{ public function verify_parameters($data,$type){ // 设置验证 - $rule = [ - 'aan_id' => 'require|number', - 'nickname' => 'require|chsAlphaNum', - 'birthday' => 'require|date', - 'gender' => 'require|number|in:0,1,2', - 'grade' => 'require', - 'height' => 'require|number', - 'weight' => 'require|number', - 'identity_id' => 'require', - 'identity_name' => 'require', - 'address' => 'require', - ]; - $msg = [ - 'aan_id.require' => '账号信息缺失', - 'nickname.require' => '昵称缺失', - 'birthday.require' => '生日缺失', - 'gender.require' => '性别缺失', - 'grade.require' => '年级缺失', - 'height.require' => '身高缺失', - 'weight.require' => '体重缺失', - 'identity_id.require' => '身份缺失', - 'identity_name.require' => '身份缺失', - 'address.require' => '区域缺失', - - 'aan_id.number' => '账号信息格式错误', - 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母', - 'birthday.date' => '生日信息格式错误', - 'gender.number' => '性别格式错误', - 'gender.in' => '性别信息错误', - 'height.number' => '身高必须为数字', - 'weight.number' => '体重必须为数字', - // 'identity.number' => '身份信息格式错误', - ]; - $validate = new Validate($rule,$msg); - $result = $validate->check($data); - if(!$result){ - return $validate->getError(); - } - - $parameter['aan_id'] = $data['aan_id']; - $parameter['nickname'] = $data['nickname']; - $parameter['birthday'] = $data['birthday']; - $parameter['gender'] = $data['gender']; - $parameter['grade'] = $data['grade']; - $parameter['card_order'] = '2,6,8'; - $parameter['height'] = $data['height']; - $parameter['weight'] = $data['weight']; - $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; - $parameter['identity_id'] = $data['identity_id']; - $parameter['identity_name'] = $data['identity_name']; - $parameter['address'] = $data['address']; - $parameter['create_time'] = date('Y-m-d H:i:s'); - $parameter['last_update_time'] = date('Y-m-d H:i:s'); - - $parameter_pd = Db::table($this->index_use_db_name['7'])->where(['id'=>$parameter['aan_id']])->count(); - if($parameter_pd <= 0){ - return '该账户不存在'; - } - $result = Db::table($this->index_use_db_name['2'])->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); - if($result>0){ - return '该成员已存在'; - } - if(!array_key_exists($parameter['identity_id'],$this->identity_list)){ - return '身份信息错误'; - }else{ - if($parameter['identity_id'] != 'P0'){ - $parameter['identity_name'] = $this->identity_list[$data['identity_id']]; - $result = Db::table($this->index_use_db_name['2'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); - if($result>0){ - return '该身份已存在'; + if($data['measure_model'] == 1){ + $rule = [ + 'aan_id' => 'require|number', + 'nickname' => 'require|chsAlphaNum', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + 'grade' => 'require', + 'height' => 'require|number', + 'weight' => 'require|number', + 'measure_model' => 'require|in:1,2', + 'identity_id' => 'require', + 'identity_name' => 'require', + 'address' => 'require', + ]; + $msg = [ + 'aan_id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + 'grade.require' => '年级缺失', + 'height.require' => '身高缺失', + 'weight.require' => '体重缺失', + 'measure_model.require' => '测量模式缺失', + 'identity_id.require' => '身份缺失', + 'identity_name.require' => '身份缺失', + 'address.require' => '区域缺失', + + 'aan_id.number' => '账号信息格式错误', + 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母和数字', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + 'measure_model.number' => '测量模式错误', + 'measure_model.in' => '测量模式信息错误', + 'height.number' => '身高必须为数字', + 'weight.number' => '体重必须为数字', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + $parameter['aan_id'] = $data['aan_id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + $parameter['card_order'] = ''; + $parameter['height'] = $data['height']; + $parameter['weight'] = $data['weight']; + $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $parameter['measure_model'] = $data['measure_model']; + $parameter['grade'] = $data['grade']; + $parameter['identity_id'] = $data['identity_id']; + $parameter['identity_name'] = $data['identity_name']; + $parameter['address'] = $data['address']; + + if(!array_key_exists($parameter['identity_id'],$this->identity_list)){ + return '身份信息错误'; + }else{ + if($parameter['identity_id'] != 'P0'){ + $parameter['identity_name'] = $this->identity_list[$data['identity_id']]; + $result = Db::table($this->index_use_db_name['2'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); + if($result>0){ + return '该身份已存在'; + } } } + $address_data = Db::table($this->index_use_db_name['10'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find(); + $parameter['card_order'] = $address_data['recommend_cards']; + }else{ + $rule = [ + 'aan_id' => 'require|number', + 'nickname' => 'require|chsAlphaNum', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + // 'grade' => 'require', + 'height' => 'require|number', + 'weight' => 'require|number', + 'measure_model' => 'require|in:1,2', + // 'identity_id' => 'require', + // 'identity_name' => 'require', + // 'address' => 'require', + ]; + $msg = [ + 'aan_id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + // 'grade.require' => '年级缺失', + 'height.require' => '身高缺失', + 'weight.require' => '体重缺失', + 'measure_model.require' => '测量模式缺失', + // 'identity_id.require' => '身份缺失', + // 'identity_name.require' => '身份缺失', + // 'address.require' => '区域缺失', + + 'aan_id.number' => '账号信息格式错误', + 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母和数字', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + 'measure_model.number' => '测量模式错误', + 'measure_model.in' => '测量模式信息错误', + 'height.number' => '身高必须为数字', + 'weight.number' => '体重必须为数字', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + $parameter['aan_id'] = $data['aan_id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + $parameter['card_order'] = '2'; + $parameter['height'] = $data['height']; + $parameter['weight'] = $data['weight']; + $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $parameter['measure_model'] = $data['measure_model']; + + $parameter['grade'] = "nothing"; + $parameter['identity_id'] = "P0"; + $parameter['identity_name'] = "陌生人"; + $parameter['address'] = ''; + $parameter_pd = Db::table($this->index_use_db_name['7'])->where(['id'=>$parameter['aan_id']])->count(); + if($parameter_pd <= 0){ + return '该账户不存在'; + } + $result = Db::table($this->index_use_db_name['2'])->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0])->count(); + if($result>0){ + return '该成员已存在'; + } } - $address_data = Db::table($this->index_use_db_name['10'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find(); - $parameter['card_order'] = $address_data['recommend_cards']; return $parameter; } public function verify_parameters2($data,$type){ - // 设置验证 - $rule = [ - 'id' => 'require|number', - 'nickname' => 'require|chsAlphaNum', - 'birthday' => 'require|date', - 'gender' => 'require|number|in:0,1,2', - 'grade' => 'require', - 'height' => 'require|number', - 'weight' => 'require|number', - 'identity_id' => 'require', - 'identity_name' => 'require', - 'address' => 'require', - ]; - $msg = [ - 'id.require' => '用户信息缺失', - 'nickname.require' => '昵称缺失', - 'birthday.require' => '生日缺失', - 'gender.require' => '性别缺失', - 'grade.require' => '年级缺失', - 'height.require' => '身高缺失', - 'weight.require' => '体重缺失', - 'identity_id.require' => '身份缺失', - 'identity_name.require' => '身份缺失', - 'address.require' => '区域缺失', - - 'id.number' => '用户信息格式错误', - 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母、数字', - 'birthday.date' => '生日信息格式错误', - 'gender.number' => '性别格式错误', - 'gender.in' => '性别信息错误', - 'height.number' => '身高必须为数字', - 'weight.number' => '体重必须为数字', - // 'identity.number' => '身份信息格式错误', - ]; - $validate = new Validate($rule,$msg); - $result = $validate->check($data); - if(!$result){ - return $validate->getError(); - } - - $parameter['id'] = $data['id']; - $parameter['nickname'] = $data['nickname']; - $parameter['birthday'] = $data['birthday']; - $parameter['height'] = $data['height']; - $parameter['weight'] = $data['weight']; - $parameter['gender'] = $data['gender']; - $parameter['grade'] = $data['grade']; - $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; - $parameter['identity_id'] = $data['identity_id']; - $parameter['identity_name'] = $data['identity_name']; - $parameter['address'] = $data['address']; - // $parameter['identity_data'] = $data['identity']; - $parameter['last_update_time'] = date('Y-m-d H:i:s'); - $aan_id = $data['aan_id']; - - - if(!array_key_exists($parameter['identity_id'],$this->identity_list)){ - return '身份信息错误'; - }else{ - if($parameter['identity_id'] != 'P0'){ - $parameter['identity_name'] = $this->identity_list[$data['identity_id']]; - $result = Db::table($this->index_use_db_name['2'])->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$aan_id,'is_del'=>0])->field('id,identity_id')->find(); - if($result && $parameter['id'] != $result['id']){ - return '该身份已存在'; + if($data['measure_model'] == 1){ + $rule = [ + 'id' => 'require|number', + 'nickname' => 'require|chsAlphaNum', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + 'grade' => 'require', + 'height' => 'require|number', + 'weight' => 'require|number', + 'measure_model' => 'require|in:1,2', + 'identity_id' => 'require', + 'identity_name' => 'require', + 'address' => 'require', + ]; + $msg = [ + 'id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + 'grade.require' => '年级缺失', + 'height.require' => '身高缺失', + 'weight.require' => '体重缺失', + 'measure_model.require' => '测量模式缺失', + 'identity_id.require' => '身份缺失', + 'identity_name.require' => '身份缺失', + 'address.require' => '区域缺失', + + 'id.number' => '账号信息格式错误', + 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母和数字', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + 'measure_model.number' => '测量模式错误', + 'measure_model.in' => '测量模式信息错误', + 'height.number' => '身高必须为数字', + 'weight.number' => '体重必须为数字', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + $parameter['id'] = $data['id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + $parameter['card_order'] = '2'; + $parameter['height'] = $data['height']; + $parameter['weight'] = $data['weight']; + $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $parameter['measure_model'] = $data['measure_model']; + $parameter['grade'] = $data['grade']; + $parameter['identity_id'] = $data['identity_id']; + $parameter['identity_name'] = $data['identity_name']; + $parameter['address'] = $data['address']; + $aan_id = $data['aan_id']; + if(!array_key_exists($parameter['identity_id'],$this->identity_list)){ + return '身份信息错误'; + }else{ + if($parameter['identity_id'] != 'P0'){ + $parameter['identity_name'] = $this->identity_list[$data['identity_id']]; + $result = Db::table($this->index_use_db_name['2']) + // ->where(['identity_id'=>$parameter['identity_id'],'aan_id'=>$aan_id,'is_del'=>0]) + ->where("identity_id = '".$parameter['identity_id']."' and aan_id = '".$aan_id."' and is_del = 0 and id <> ".$parameter['id']."") + ->field('id,identity_id') + ->find(); + if($result && $parameter['id'] != $result['id']){ + return '该身份已存在'; + } } } - } - if($data['address'] != ''){ - $address_data = explode(',', $data['address']); - $card_result = Db::table($this->index_use_db_name['10'])->where(['province'=>$address_data[0],'is_del'=>0])->field('id,recommend_cards')->find(); - $parameter['card_order'] = $card_result['recommend_cards']; + $address_data = Db::table($this->index_use_db_name['10'])->where(['province'=>explode(',',$parameter['address'])[0],'is_del'=>0])->field('id,recommend_cards')->find(); + $parameter['card_order'] = $address_data['recommend_cards']; }else{ - $parameter['card_order'] = '2'; + $rule = [ + 'aan_id' => 'require|number', + 'nickname' => 'require|chsAlphaNum', + 'birthday' => 'require|date', + 'gender' => 'require|number|in:0,1,2', + // 'grade' => 'require', + 'height' => 'require|number', + 'weight' => 'require|number', + 'measure_model' => 'require|in:1,2', + // 'identity_id' => 'require', + // 'identity_name' => 'require', + // 'address' => 'require', + ]; + $msg = [ + 'aan_id.require' => '账号信息缺失', + 'nickname.require' => '昵称缺失', + 'birthday.require' => '生日缺失', + 'gender.require' => '性别缺失', + // 'grade.require' => '年级缺失', + 'height.require' => '身高缺失', + 'weight.require' => '体重缺失', + 'measure_model.require' => '测量模式缺失', + // 'identity_id.require' => '身份缺失', + // 'identity_name.require' => '身份缺失', + // 'address.require' => '区域缺失', + + 'aan_id.number' => '账号信息格式错误', + 'nickname.chsAlphaNum' => '昵称只能是只能是汉字、字母和数字', + 'birthday.date' => '生日信息格式错误', + 'gender.number' => '性别格式错误', + 'gender.in' => '性别信息错误', + 'measure_model.number' => '测量模式错误', + 'measure_model.in' => '测量模式信息错误', + 'height.number' => '身高必须为数字', + 'weight.number' => '体重必须为数字', + ]; + $validate = new Validate($rule,$msg); + $result = $validate->check($data); + if(!$result){ + return $validate->getError(); + } + $parameter['id'] = $data['id']; + $parameter['aan_id'] = $data['aan_id']; + $parameter['nickname'] = $data['nickname']; + $parameter['birthday'] = $data['birthday']; + $parameter['gender'] = $data['gender']; + // $parameter['card_order'] = '2'; + $parameter['height'] = $data['height']; + $parameter['weight'] = $data['weight']; + $parameter['head_pic'] = $data['gender'] == 2?'http://tc.pcxbc.com/tsf/2.png':'http://tc.pcxbc.com/tsf/1.png'; + $parameter['create_time'] = date('Y-m-d H:i:s'); + $parameter['last_update_time'] = date('Y-m-d H:i:s'); + $parameter['measure_model'] = $data['measure_model']; + + $parameter_pd = Db::table($this->index_use_db_name['7'])->where(['id'=>$parameter['aan_id']])->count(); + if($parameter_pd <= 0){ + return '该账户不存在'; + } + $result = Db::table($this->index_use_db_name['2']) + // ->where(['nickname'=>$parameter['nickname'],'aan_id'=>$parameter['aan_id'],'is_del'=>0]) + ->where("nickname = '".$parameter['nickname']."' and aan_id = '".$parameter['aan_id']."' and is_del = 0 and id <> ".$parameter['id']."") + ->count(); + if($result>0){ + return '该成员已存在'; + } + unset($parameter['aan_id']); } - return $parameter; } diff --git a/application/testapp/controller/Login.php b/application/testapp/controller/Login.php index 896a345..a80b58b 100644 --- a/application/testapp/controller/Login.php +++ b/application/testapp/controller/Login.php @@ -29,26 +29,32 @@ class Login extends Base{ } // 验证数据项是否完整 if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('code', $data)){ - $return_data = $this->msg(10001); + return $this->msg(10001); } // 验证数据值是否合规 if(!$data['data'] || !$data['password'] || !$data['code']){ - $return_data = $this->msg(10006); + return $this->msg(10006); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'num')){ + return $this->msg(10005); } // 验证是手机还是邮箱 $montage_data = $this->is_tel_email($data['data']); if($montage_data == false){ - $return_data = $this->msg(10005); + return $this->msg(10005); } // 查询账号是否已经注册 $inspect_repeat = Db::table($this->login_use_db_name['1'])->where([$montage_data=>$data['data'],'is_del'=>0])->count(); if($inspect_repeat >= 0){ - $return_data = $this->msg(10002,'注册失败,账号已存在'); + return $this->msg(10002,'注册失败,账号已存在'); } // 检查验证码 $code_result = $this->check_code($data['data'],$data['code']); if($code_result !== true){ - $return_data = $this->msg(10002,$code_result); + return $this->msg(10002,$code_result); } // 验证完之后 $set_data = []; @@ -61,10 +67,10 @@ class Login extends Base{ $set_data['head_pic'] = $this->default_head_pic; $set_data['nickname'] = '用户'.time(); $set_data['create_time'] = date('Y-m-d H:i:s'); + $set_data['login_time'] = date('Y-m-d H:i:s'); $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); $result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data); if($result){ - cache($set_data['token'],date('Y-m-d H:i:s'),$this->token_time); $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result]); }else{ $return_data = $this->msg(10002); @@ -84,7 +90,7 @@ class Login extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -98,36 +104,40 @@ class Login extends Base{ } // 验证数据项是否完整 if(!array_key_exists('data', $data) || !array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('code', $data)){ - $return_data = $this->msg(10001); + return $this->msg(10001); } // 验证数据值是否合规 if($data['password'] != $data['c_password']){ - $return_data = $this->msg(10003,'两次密码不一致'); + return $this->msg(10003,'两次密码不一致'); } if($data['password'] == ''){ - $return_data = $this->msg(10003,'密码不能为空'); + return $this->msg(10003,'密码不能为空'); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'num')){ + return $this->msg(10005); } // 检查验证码 $code_result = $this->check_code($data['data'],$data['code']); if($code_result !== true){ - $return_data = $this->msg(10003,$code_result); + return $this->msg(10003,$code_result); } $t_y = $this->is_tel_email($data['data']); if($t_y === false){ - $return_data = $this->msg(10003,'账号格式错误'); + return $this->msg(10003,'账号格式错误'); } // 检查账号是否存在 $find_data = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data'],'is_del'=>0])->field('id,token')->find(); if(!$find_data){ - $return_data = $this->msg(10003); + return $this->msg(10003); } $result = Db::table($this->login_use_db_name['1'])->where([$t_y=>$data['data']])->update(['password'=>$data['password']]); if($result){ - - cache($find_data['token'],date('Y-m-d H:i:s'),$this->token_time); - $return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]); + $return_data = $this->msg(['token'=>$find_data['token'],'aan_id'=>$find_data['id']]); }else{ - $return_data = $this->msg(10002); + $return_data = $this->msg(10002); } // 成功 @@ -144,7 +154,7 @@ class Login extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -157,40 +167,37 @@ class Login extends Base{ $data = input('post.'); } if(!array_key_exists('data', $data) || !array_key_exists('validate_data', $data) || !array_key_exists('validate_type', $data)){ - $return_data = $this->msg(10001); + return $this->msg(10001); } // 检测是否为手机 $montage_data = $this->is_tel_email($data['data']); if($montage_data == false){ - $return_data = $this->msg(10005); + return $this->msg(10005); } + $verify_result[$montage_data] = $data['data']; $verify_result['is_del'] = 0; - // dump($data); - // die; // 检测校验途径 if($data['validate_type'] == 'code'){ $code_name = $data['data']; if($this->check_code($code_name,$data['validate_data']) === true){ $result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token')->find(); if($result){ - - cache($result['token'],date('Y-m-d H:i:s'),$this->token_time); - $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]); + Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); + $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']]); }else{ $set_data['password'] = ''; $set_data[$montage_data] = $data['data']; $set_data['head_pic'] = $this->default_head_pic; $set_data['nickname'] = '用户'.$data['data']; $set_data['create_time'] = date('Y-m-d H:i:s'); + $set_data['login_time'] = date('Y-m-d H:i:s'); $set_data['token'] = md5($data['data'].$this->create_random_string(12).time()); $result = Db::table($this->login_use_db_name['1'])->insertGetId($set_data); if($result){ - - cache($set_data['token'],date('Y-m-d H:i:s'),$this->token_time); - $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功'); + $return_data = $this->msg(['token'=>$set_data['token'],'aan_id'=>$result],'登录成功'); }else{ - $return_data = $this->msg(10002); + $return_data = $this->msg(10002); } } }else{ @@ -201,19 +208,20 @@ class Login extends Base{ $result = Db::table($this->login_use_db_name['1'])->where($verify_result)->field('id,token,password')->find(); if($result){ if($result['password'] == ''){ - $return_data = $this->msg(10003,'该账户未设密码,请用验证码登录'); + $return_data = $this->msg(10003,'该账户未设密码,请用验证码登录'); } if($data['validate_data'] != $result['password']){ - $return_data = $this->msg(10003,'账号密码错误'); + $return_data = $this->msg(10003,'账号密码错误'); }else{ - cache($result['token'],date('Y-m-d H:i:s'),$this->token_time); - $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功'); + + Db::table($this->login_use_db_name['1'])->where($verify_result)->update(['login_time'=>date('Y-m-d H:i:s')]); + $return_data = $this->msg(['token'=>$result['token'],'aan_id'=>$result['id']],'登录成功'); } }else{ - $return_data = $this->msg(10003,'账号未注册,请先注册'); + $return_data = $this->msg(10003,'账号未注册,请先注册'); } }else{ - $return_data = $this->msg(10003,'校验参数错误'); + $return_data = $this->msg(10003,'校验参数错误'); } // 成功 @@ -230,7 +238,7 @@ class Login extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } @@ -248,8 +256,14 @@ class Login extends Base{ if($this->token_time_validate($data['token']) === false){ $return_data = $this->msg(20001); } - cache($data['token'],NULL); - $return_data = $this->msg([]); + + $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['login_time'=>'2024-09-01 00:00:00']); + if($result){ + $return_data = $this->msg([]); + }else{ + $return_data = $this->msg(10002); + } + // 成功 $this->record_api_log($data, null, $return_data); @@ -265,7 +279,7 @@ class Login extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -281,9 +295,8 @@ class Login extends Base{ if(!array_key_exists('token', $data)){ $return_data = $this->msg(10001); } - $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['is_del'=>1]); + $result = Db::table($this->login_use_db_name['1'])->where(['token'=>$data['token']])->update(['is_del'=>1,'login_time'=>'2024-09-01 00:00:00']); if($result){ - cache($data['token'], NULL); $return_data = $this->msg([]); }else{ $return_data = $this->msg(10002); @@ -303,7 +316,7 @@ class Login extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -339,15 +352,10 @@ class Login extends Base{ $road = 'tel'; }else{ $result = $this->send_email_code([$data['data']],['title'=>'体测APP验证码','from_user_name'=>'体测APP','content'=>$num]); - // dump($result); $road = 'email'; } - // dump($result); - // dump($road); - // die; if(is_array($result) && $result['code'] == 0){ cache($data['data'], $num, $this->code_time); - // dump($data['data']."_".$data['road']."_".$data['type']); // return $this->msg(['code'=>$num]); return $this->msg([]); // return true; @@ -537,8 +545,6 @@ class Login extends Base{ '; $mail->Body = $neirong; //邮件主体内容 - // dump($address); - // die; //发送 if (!$mail->Send()) { diff --git a/application/testapp/controller/Msginformation.php b/application/testapp/controller/Msginformation.php new file mode 100644 index 0000000..89e18f9 --- /dev/null +++ b/application/testapp/controller/Msginformation.php @@ -0,0 +1,283 @@ +'admin_editor_text_content', + '2'=>'admin_editor_text_like_up_log', + ]; + protected $page_num = 10; + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + ################################################################接口################################################################ + ################################################################接口################################################################ + ################################################################接口################################################################ + + // 获取板块,及板块下类型标签 + public function get_sector_label_msg(){ + try { + $return_data = $this->get_sector_label_msg_action(); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log([], $logContent, null); + return $this->msg(99999); + } + + } + // 获取板块下信息 + public function get_sector_content_msg($data = ['token'=>'6441bf7dabea7b3360a30240d3b19fc5','sector_id'=>1,'type'=>4,'page'=>1]){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('token', $data) || !array_key_exists('sector_id', $data) || !array_key_exists('type', $data) || !array_key_exists('page', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['sector_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->get_sector_content_msg_action($data); + + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + + // 资讯点赞 + public function user_like_it($data = ['token'=>'0dafb98a10995c98b5a33b7d59d986ca','id'=>'44']){ + try { + // 你的业务逻辑 + if(count(input('post.')) > 0){ + $data = input('post.'); + } + if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ + return $this->msg(10001); + } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->user_like_it_action($data); + // 成功 + $this->record_api_log($data, null, $return_data); + return $return_data; + } catch (\Exception $e) { + // 捕获异常 + $logContent["flie"] = $e->getFile(); + $logContent["line"] = $e->getLine(); + $logContent['all_content'] = "异常信息:\n"; + $logContent['all_content'] .= "消息: " . $e->getMessage() . "\n"; + $logContent['all_content'] .= "代码: " . $e->getCode() . "\n"; + $logContent['all_content'] .= "文件: " . $e->getFile() . "\n"; + $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; + $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; + $this->record_api_log($data, $logContent, null); + return $this->msg(99999); + } + + } + + ################################################################业务################################################################ + ################################################################get_sector_label_msg + public function get_sector_label_msg_action(){ + $Template_arr = [ + 1=>[ + 'id'=>'1', + 'name'=>'推荐', + 'loop_data'=>[], + 'list'=>[ + ['id'=>0,'name'=>'全部'], + ['id'=>1,'name'=>'身高管理'], + ['id'=>2,'name'=>'体重管理'], + ['id'=>3,'name'=>'肺活训练'], + ['id'=>4,'name'=>'跳绳训练'], + ['id'=>5,'name'=>'中考体测'], + ] + ], + ]; + // 获取需要版块id start + $sector = Db::query(" + SELECT + sector + FROM ".$this->msginformation_use_db_name['1']." + group by sector + "); + $sector_all = []; + foreach ($sector as $key => $value) { + foreach (explode(',', $value['sector']) as $k => $v) { + if(!in_array($v, $sector_all)){ + array_push($sector_all, $v); + } + } + } + // 获取需要版块id end + // 填充进去版块的轮播start + $return_data = []; + foreach ($sector_all as $key => $value) { + + $loop_result = Db::query(" + SELECT + id, + title, + CONCAT('https://tc.pcxbc.com/', cover_image) AS cover_image + FROM ".$this->msginformation_use_db_name['1']." + WHERE + is_del = 0 AND loop_img > 0 AND sector LIKE '%".$value."%' + ORDER BY + loop_img desc + "); + $Template_arr[$value]['loop_data'] = $loop_result; + array_push($return_data, $Template_arr[$value]); + } + // 填充进去版块的轮播end + return $this->msg($return_data); + } + ################################################################get_sector_content_msg + public function get_sector_content_msg_action($data){ + $return_result = [ + 'page_now'=>$data['page'], + 'page_num'=>$this->page_num, + 'content_data'=>[] + ]; + if($data['type'] != 0){ + $type_str = " AND type LIKE '%".$data['type']."%'"; + }else{ + $type_str = ""; + } + $content_result = Db::query(" + SELECT + id, + title, + create_time, + i_like, + reading, + CONCAT('https://tc.pcxbc.com/', cover_image) AS cover_image, + top_up + FROM ".$this->msginformation_use_db_name['1']." + WHERE + is_del = 0 AND sector LIKE '%".$data['sector_id']."%'".$type_str." + ORDER BY + top_up desc,id + OFFSET + (".$data['page']." - 1) * ".$this->page_num." ROWS + FETCH NEXT + ".$this->page_num." ROWS ONLY + "); + $return_result['content_data'] = $content_result; + $user_like = Db::table($this->msginformation_use_db_name['2'])->where(['token'=>$data['token'],'is_del'=>0])->column('aetc_id'); + + foreach ($return_result['content_data'] as $key => $value) { + if(array_key_exists($value['id'], $user_like)){ + $return_result['content_data'][$key]['is_like'] = 1; + }else{ + $return_result['content_data'][$key]['is_like'] = 0; + } + } + return $this->msg($return_result); + } + ################################################################user_like_it + public function user_like_it_action($data){ + $user_like_data = Db::table($this->msginformation_use_db_name['2'])->where(['token'=>$data['token'],'aetc_id'=>$data['id']])->find(); + + if($user_like_data){ + // 如果找到有点赞记录 + if($user_like_data['is_del'] == 0){ + // 如果已经点了 + // 启动事务 + Db::startTrans(); + try{ + Db::table($this->msginformation_use_db_name['1'])->where(['id'=>$data['id']])->setDec('i_like'); + Db::table($this->msginformation_use_db_name['2'])->where(['aetc_id'=>$data['id'],'token'=>$data['token']])->update(['is_del'=>1,'update_time'=>date('Y-m-d H:i:s')]); + // 提交事务 + Db::commit(); + return $this->msg(['user_like'=>1]); + } catch (\Exception $e) { + // 回滚事务 + Db::rollback(); + return $this->msg(10002); + } + }else{ + // 如果之前点过又取消了 + // 启动事务 + Db::startTrans(); + try{ + Db::table($this->msginformation_use_db_name['1'])->where(['id'=>$data['id']])->setInc('i_like'); + Db::table($this->msginformation_use_db_name['2'])->where(['aetc_id'=>$data['id'],'token'=>$data['token']])->update(['is_del'=>0,'update_time'=>date('Y-m-d H:i:s')]); + // 提交事务 + Db::commit(); + return $this->msg(['user_like'=>0]); + } catch (\Exception $e) { + // 回滚事务 + Db::rollback(); + return $this->msg(10002); + } + } + }else{ + // 如果没有记录 + // 启动事务 + Db::startTrans(); + try{ + Db::table($this->msginformation_use_db_name['1'])->where(['id'=>$data['id']])->setInc('i_like'); + Db::table($this->msginformation_use_db_name['2'])->insert([ + 'aetc_id'=>$data['id'], + 'token'=>$data['token'], + 'create_time'=>date('Y-m-d H:i:s'), + 'update_time'=>date('Y-m-d H:i:s') + ]); + // 提交事务 + Db::commit(); + return $this->msg(['user_like'=>0]); + } catch (\Exception $e) { + // 回滚事务 + Db::rollback(); + return $this->msg(10002); + } + } + + } + + + +} \ No newline at end of file diff --git a/application/testapp/controller/Myinformation.php b/application/testapp/controller/Myinformation.php index 6770f88..d4e08bd 100644 --- a/application/testapp/controller/Myinformation.php +++ b/application/testapp/controller/Myinformation.php @@ -29,6 +29,9 @@ class Myinformation extends Base{ if(!array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } $return_data = $this->get_my_account_msg_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -44,7 +47,7 @@ class Myinformation extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -58,6 +61,12 @@ class Myinformation extends Base{ if(!array_key_exists('nickname', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['nickname'],'str')){ + return $this->msg(10005); + } $return_data = $this->update_my_nickname_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -73,7 +82,7 @@ class Myinformation extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -87,6 +96,13 @@ class Myinformation extends Base{ if(!array_key_exists('data', $data) || !array_key_exists('token', $data) || !array_key_exists('code', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['code'],'intnum')){ + return $this->msg(10005); + } + $return_data = $this->update_my_account_msg_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -102,7 +118,7 @@ class Myinformation extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -117,6 +133,15 @@ class Myinformation extends Base{ if(!array_key_exists('password', $data) || !array_key_exists('c_password', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['token'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['password'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['c_password'],'str')){ + return $this->msg(10005); + } $return_data = $this->update_my_password_action($data); // 成功 $this->record_api_log($data, null, $return_data); @@ -132,7 +157,7 @@ class Myinformation extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -178,8 +203,6 @@ class Myinformation extends Base{ if($montage_data == false){ return $this->msg(10005); } - // dump($data); - // die; $result = Db::table($this->myinformation_use_db_name['1'])->where(['token'=>$data['token'],'is_del'=>0])->update([ $montage_data=>$data['data'], 'update_time'=>date('Y-m-d H:i:s') diff --git a/application/testapp/controller/Pagingcontrast.php b/application/testapp/controller/Pagingcontrast.php index 626164c..321da82 100644 --- a/application/testapp/controller/Pagingcontrast.php +++ b/application/testapp/controller/Pagingcontrast.php @@ -33,6 +33,18 @@ class Pagingcontrast extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['s_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['e_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); if(array_key_exists($data['type'],$this->db_name)){ $return_data = $this->jump_transfer_interface_record($data,'group'); @@ -53,12 +65,12 @@ class Pagingcontrast extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 获取记录信息(分页)(包含身体、跳绳、肺活量) - public function get_all_record_data_page($data = ['aud_id'=>'25','page'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca','type'=>'2']){ + public function get_all_record_data_page($data = ['aud_id'=>'11','page'=>1,'token'=>'0dafb98a10995c98b5a33b7d59d986ca','type'=>'2']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -67,6 +79,15 @@ class Pagingcontrast extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('page', $data) || !array_key_exists('token', $data) || !array_key_exists('type', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); if(array_key_exists($data['type'],$this->db_name)){ $return_data = $this->jump_transfer_interface_record($data,'page'); @@ -87,12 +108,12 @@ class Pagingcontrast extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 获取详细历史数据信息(包含身体、跳绳、肺活量) - public function get_all_record_detailed_information($data = ['id'=>'39','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function get_all_record_detailed_information($data = ['id'=>'52','type'=>'2','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -101,6 +122,12 @@ class Pagingcontrast extends Base{ if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $return_data = $this->jump_transfer_interface_detailed($data); // 成功 @@ -117,12 +144,12 @@ class Pagingcontrast extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 数据对比(包含身体、跳绳、肺活量) - public function get_all_card_data_contrast($data = ['before_id'=>'837','after_id'=>'836','type'=>'6','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + public function get_all_card_data_contrast($data = ['before_id'=>'51','after_id'=>'52','type'=>'2','token'=>'caadd1be045a65f30b92aa805f1de54a']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -131,6 +158,15 @@ class Pagingcontrast extends Base{ if(!array_key_exists('before_id', $data) || !array_key_exists('after_id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['before_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['after_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $return_data = $this->jump_transfer_interface_data_contrast($data); // 成功 @@ -147,7 +183,7 @@ class Pagingcontrast extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -161,6 +197,12 @@ class Pagingcontrast extends Base{ if(!array_key_exists('id', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ return $this->msg(10001); } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $user_data = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->update(['is_del'=>1]); if($user_data){ @@ -183,7 +225,7 @@ class Pagingcontrast extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -357,10 +399,10 @@ class Pagingcontrast extends Base{ // $time_t = $this->handle_hour_branch_second($value['v2']); array_push($return_result, [ 'id'=>$value['id'], - 'v1'=>$value['v1'], - 'v2'=>$value['v2'], - 'v3'=>$value['v3'], - 'v4'=>$value['v4'], + 'v1'=>$value['v1'] == '.00'?'0':$value['v1'], + 'v2'=>$value['v2'] == '.00'?'0':$value['v2'], + 'v3'=>$value['v3'] == '.00'?'0':$value['v3'], + 'v4'=>$value['v4'] == '.00'?'0':$value['v4'], 'v5'=>explode(',',$value['v5'])[0], 'v1_name'=>'第一次', 'v2_name'=>'第二次', @@ -382,10 +424,10 @@ class Pagingcontrast extends Base{ // $time_t = $this->handle_hour_branch_second($value['jump_time']); array_push($return_result['rows'],[ 'id'=>$value['id'], - 'v1'=>$value['one_val'], - 'v2'=>$value['two_val'], - 'v3'=>$value['three_val'], - 'v4'=>$value['average_val'], + 'v1'=>$value['one_val'] == '.00'?'0':$value['one_val'], + 'v2'=>$value['two_val'] == '.00'?'0':$value['two_val'], + 'v3'=>$value['three_val'] == '.00'?'0':$value['three_val'], + 'v4'=>$value['average_val'] == '.00'?'0':$value['average_val'], 'v5'=>explode(',',$value['score'])[0], 'v1_name'=>'第一次', 'v2_name'=>'第二次', @@ -402,17 +444,38 @@ class Pagingcontrast extends Base{ // 获取详细历史数据信息 public function get_all_detaile_data_msg($data){ + // 加 bcadd(,,20) + // 减 bcsub(,,20) + // 乘 bcmul(,,20) + // 除 bcdiv(,,20) + // 设置排除在外的数据类型start + // $exclude_data_arr = ['height','weight','age','bmi','body_level','body_type']; + $exclude_data_arr = ['height','weight','age','bmi']; + // 设置排除在外的数据类型end $result = Db::table($this->db_name[$data['type']])->where(['id'=>$data['id']])->find(); + $for_data_arr = $this->request_result[$data['type']]; if($result){ + // if($data['type'] == 2 && $result['record_type'] != 'by_device_adc'){ + // $for_data_arr = ['height'=>['身高','cm'],'weight'=>['体重','kg'],'age'=>['年龄','岁'],'bmi'=>['BMI','']]; + // } $result_data = []; - foreach ($this->request_result[$data['type']] as $key => $value) { + foreach ($for_data_arr as $key => $value) { $temporary_arr['key_name'] = $key; $temporary_arr['name'] = $value[0]; if($data['type'] == 2){ - if($key == 'un_fat_w_weight'){ - $temporary_arr['value'] = bcsub(explode(',',$result['weight'])[0],explode(',',$result['fat_w'])[0],2); + // 身体数据处理,如果没有阻抗,则只显示四项$exclude_data_arr + if($result['record_type'] != 'by_device_adc'){ + if(!in_array($key, $exclude_data_arr)){ + continue; + }else{ + $temporary_arr['value'] = explode(',',$result[$key])[0]; + } }else{ - $temporary_arr['value'] = explode(',',$result[$key])[0]; + if($key == 'un_fat_w_weight'){ + $temporary_arr['value'] = bcsub(explode(',',$result['weight'])[0],explode(',',$result['fat_w'])[0],2); + }else{ + $temporary_arr['value'] = explode(',',$result[$key])[0]; + } } }else{ $temporary_arr['value'] = explode(',',$result[$key])[0]; @@ -430,7 +493,6 @@ class Pagingcontrast extends Base{ // 数据对比 public function get_body_data_contrast($data){ - // dump($data); $data2 = [$data['before_id'],$data['after_id']]; $data3 = implode(',',$data2); $calculate_arr = []; @@ -452,6 +514,7 @@ class Pagingcontrast extends Base{ acbd.visceral, acbd.sfr, acbd.record_time, + acbd.record_type, REPLACE(CONVERT(varchar(10), acbd.record_time, 23), '-', '-') AS b_time, aud.nickname, aud.gender, @@ -462,8 +525,7 @@ class Pagingcontrast extends Base{ where acbd.id in ($data3) and acbd.is_del = 0 "); - // dump($result); - // die; + if(!$result || count($result)<2){ return $this->msg(10004); } @@ -475,7 +537,7 @@ class Pagingcontrast extends Base{ $calculate_arr['after'] = $value; } } - $return_data['time'] = $calculate_arr['before']['b_time'].'-'.$calculate_arr['after']['b_time']; + $return_data['time'] = $calculate_arr['before']['b_time'].'与'.$calculate_arr['after']['b_time']; $return_data['headimg'] = $calculate_arr['before']['head_pic']; $return_data['name'] = $calculate_arr['before']['nickname']; $return_data['gender'] = $calculate_arr['before']['gender']; @@ -483,13 +545,36 @@ class Pagingcontrast extends Base{ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); $return_data['list'] = []; - + // 处理如果没有阻抗的数据为0,显示异常start;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息 + if($calculate_arr['before']['record_type'] != 'by_device_adc' && $calculate_arr['after']['record_type'] != 'by_device_adc'){ + foreach ($calculate_arr['before'] as $key => $value) { + if(!in_array($key, ['height','weight','bmi'])){ + unset($calculate_arr['before'][$key]); + unset($calculate_arr['after'][$key]); + } + } + }else{ + foreach ($calculate_arr as $key => $value) { + if($value['record_type'] != 'by_device_adc'){ + $calculate_arr[$key]['fat_r'] = "0,异常"; + $calculate_arr[$key]['fat_w'] = "0,异常"; + $calculate_arr[$key]['muscle'] = "0,异常"; + $calculate_arr[$key]['muscleval'] = "0,异常"; + $calculate_arr[$key]['water'] = "0,异常"; + $calculate_arr[$key]['proteinval'] = "0,异常"; + $calculate_arr[$key]['bone'] = "0,异常"; + $calculate_arr[$key]['protein'] = "0,异常"; + $calculate_arr[$key]['kcal'] = "0,异常"; + $calculate_arr[$key]['visceral'] = "0,异常"; + $calculate_arr[$key]['sfr'] = "0,异常"; + } + } + } + // 处理如果没有阻抗的数据为0,显示异常end;同步处理,如果两个对比数据,都没有阻抗数据,则只显示基础信息 foreach ($calculate_arr['before'] as $key => $value) { if(in_array($key, ['height','weight','bmi','fat_r','fat_w','muscle','muscleval','water','proteinval','bone','protein','kcal','visceral','sfr'])){ $before_arr = explode(',', $value); $after_arr = explode(',', $calculate_arr['after'][$key]); - // $calculate_arr['before'][$key] = explode(',', $value); - array_push($return_data['list'], [ 'firstresult'=>[ 'color'=>'', @@ -515,7 +600,6 @@ class Pagingcontrast extends Base{ } // 数据对比 public function get_skip_data_contrast($data){ - // dump($data); $data2 = [$data['before_id'],$data['after_id']]; $data3 = implode(',',$data2); $calculate_arr = []; @@ -556,8 +640,6 @@ class Pagingcontrast extends Base{ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); $return_data['list'] = []; - // dump($calculate_arr); - // die; foreach ($calculate_arr['before'] as $key => $value) { if(in_array($key, ['jump_num','jump_time','jump_kcal'])){ $before_arr = $value; @@ -593,7 +675,6 @@ class Pagingcontrast extends Base{ } // 数据对比 public function get_vitalcapacity_data_contrast($data){ - // dump($data); $data2 = [$data['before_id'],$data['after_id']]; $data3 = implode(',',$data2); $calculate_arr = []; @@ -636,8 +717,6 @@ class Pagingcontrast extends Base{ $return_data['day'] = abs($this->daysSince($calculate_arr['before']['record_time'],$calculate_arr['after']['record_time'])); $return_data['list'] = []; - // dump($calculate_arr); - // die; foreach ($calculate_arr['before'] as $key => $value) { if(in_array($key, ['one_val','two_val','three_val','average_val','score_val'])){ $before_arr = $value; diff --git a/application/testapp/controller/Skip.php b/application/testapp/controller/Skip.php index e059997..35daa09 100644 --- a/application/testapp/controller/Skip.php +++ b/application/testapp/controller/Skip.php @@ -38,6 +38,15 @@ class Skip extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('r_time', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['r_time'],'datetime')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'str')){ + return $this->msg(10005); + } if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ $return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); } @@ -67,7 +76,7 @@ class Skip extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -81,6 +90,15 @@ class Skip extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('kcal', $data) || !array_key_exists('num', $data) || !array_key_exists('time_m', $data) || !array_key_exists('time_s', $data) || !array_key_exists('type', $data) || !array_key_exists('token', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['kcal'],'num')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['type'],'str')){ + return $this->msg(10005); + } if(!$this->isValidInteger($data['num']+0) || !$this->isValidInteger($data['time_m']+0) || !$this->isValidInteger($data['time_s']+0)){ $return_data = $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数'); } @@ -110,7 +128,7 @@ class Skip extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -124,6 +142,9 @@ class Skip extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $return_data = $this->skip_today_data_action($data); @@ -141,7 +162,7 @@ class Skip extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -155,6 +176,9 @@ class Skip extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('time', $data) || !array_key_exists('token', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $return_data = $this->skip_curve_chart_action($data); @@ -172,7 +196,7 @@ class Skip extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -186,6 +210,9 @@ class Skip extends Base{ if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $user_data = Db::table($this->skip_use_db_name['1'])->where(['id'=>$data['id']])->update(['is_del'=>1]); if($user_data){ @@ -207,7 +234,7 @@ class Skip extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -341,8 +368,6 @@ class Skip extends Base{ // 使用查询构造器进行查询 $result = Db::name($this->skip_use_db_name['1'])->where($map)->field('jump_num,jump_time,jump_kcal,aud_id,record_time,jump_type,DATEPART(hour, record_time) AS hour,DATEPART(minute, record_time) AS minute,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); - // dump($result); - // die; $return_data = []; if(count($timeData) == 3){ $key_condition = 'hour'; @@ -351,7 +376,6 @@ class Skip extends Base{ }else if(count($timeData) == 1){ $key_condition = 'month'; } - // dump($key_condition); foreach ($this->curve_data_format as $key => $value) { $temporary_arr['title'] = $value[0].'('.$value[1].')'; $temporary_arr['key'] = $key; @@ -385,11 +409,8 @@ class Skip extends Base{ } } } - // dump($temporary_arr); array_push($return_data,$temporary_arr); } - // dump($return_data); - // dump($return_data[1]['line']['series'][0]['data']); foreach ($return_data[1]['line']['series'][0]['data'] as $key => $value) { $return_data[1]['line']['series'][0]['data'][$key] = bcdiv($return_data[1]['line']['series'][0]['data'][$key],60,2); diff --git a/application/testapp/controller/Sportstesting.php b/application/testapp/controller/Sportstesting.php index d048f5b..5515aa1 100644 --- a/application/testapp/controller/Sportstesting.php +++ b/application/testapp/controller/Sportstesting.php @@ -54,6 +54,12 @@ class Sportstesting extends Base{ if(!array_key_exists('address', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['address'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $return_data = $this->sportstesting_get_type_list_action($data); @@ -71,21 +77,26 @@ class Sportstesting extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } // 获取地区类型列表 - public function sportstesting_get_region_list($data = ['parameter_data'=>'上海','gender'=>'1','token'=>'caadd1be045a65f30b92aa805f1de54a']){ + public function sportstesting_get_region_list($data = ['parameter_data'=>'河北,石家庄市','gender'=>'0']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ $data = input('post.'); } - if(!array_key_exists('gender', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('token', $data)){ + if(!array_key_exists('gender', $data) || !array_key_exists('parameter_data', $data)){ $return_data = $this->msg(10001); } - unset($data['token']); + if(!$this->verify_data_is_ok($data['parameter_data'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005); + } $return_data = $this->sportstesting_get_region_list_action($data); // 成功 @@ -102,7 +113,7 @@ class Sportstesting extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -116,6 +127,9 @@ class Sportstesting extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $return_data = $this->sportstesting_get_last_data_action($data); @@ -133,7 +147,7 @@ class Sportstesting extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -148,18 +162,34 @@ class Sportstesting extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('parameter_data', $data) || !array_key_exists('result_data', $data) || !array_key_exists('gender', $data) || !array_key_exists('token', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['parameter_data'],'str')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['gender'],'intnum')){ + return $this->msg(10005); + } if(is_array($data['result_data']) && !empty($data['result_data'])){ // 是个数组且不为空数组 foreach ($data['result_data'] as $key => $value) { foreach ($value['list'] as $k => $v) { if(count($v['list']) <= 0){ - $return_data = $this->msg(10010,$v['name'].'内并未选择内容'); + return $this->msg(10010,$v['name'].'内并未选择内容'); } if($v['is_choice'] >= 0 && count($v['list']) < $v['is_choice']){ - $return_data = $this->msg(10010,$v['name'].'内并缺少选项,请选择'.$v['is_choice'].'个选项'); + return $this->msg(10010,$v['name'].'内并缺少选项,请选择'.$v['is_choice'].'个选项'); + } + foreach ($v['list'] as $c_k => $c_v) { + if(count($c_v) <= 0){ + return $this->msg(10010,$v['name'].'选项内内容异常'); + } } } } + }else{ + return $this->msg(10006); } unset($data['token']); $return_data = $this->sportstesting_set_once_data_action2($data); @@ -178,7 +208,7 @@ class Sportstesting extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } @@ -193,6 +223,12 @@ class Sportstesting extends Base{ if(!array_key_exists('aud_id', $data) || !array_key_exists('token', $data) || !array_key_exists('page', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){ + return $this->msg(10005); + } + if(!$this->verify_data_is_ok($data['page'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $return_data = $this->sportstesting_get_all_list_action($data); @@ -210,7 +246,7 @@ class Sportstesting extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -224,6 +260,9 @@ class Sportstesting extends Base{ if(!array_key_exists('id', $data) || !array_key_exists('token', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['id'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $return_data = $this->sportstesting_get_one_details_action($data); @@ -241,7 +280,7 @@ class Sportstesting extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -256,6 +295,9 @@ class Sportstesting extends Base{ if(!array_key_exists('token', $data) || !array_key_exists('type', $data)){ $return_data = $this->msg(10001); } + if(!$this->verify_data_is_ok($data['type'],'intnum')){ + return $this->msg(10005); + } unset($data['token']); $return_data = $this->sportstesting_get_city_list_action($data); @@ -273,7 +315,7 @@ class Sportstesting extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -298,7 +340,6 @@ class Sportstesting extends Base{ // 全省地市一个规则start $db_condition = "province = '".$parameter_data[0]."'"; // 全省地市一个规则end - $data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->find(); $data = json_decode($data['content'],true); $result = $this->handle_default_rule_list_content($data,$gender); @@ -327,13 +368,17 @@ class Sportstesting extends Base{ $result['list'] = []; $result['total_score'] = 0; $data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->select(); + if(count($data) > 0){ if(count($data) > 1){ // 查到不止一条规则 return $this->msg(10004,'查询地址不够详细,请重新选择省市地区'); } + $data = json_decode($data[0]['content'],true); $result = $this->handle_default_rule_list($data,$gender); + + // die; return $this->msg($result); }else{ return $this->msg(10004,'暂无该地区的估分规则,请选择其它地区'); @@ -378,7 +423,7 @@ class Sportstesting extends Base{ ################################################sportstesting_get_all_list public function sportstesting_get_all_list_action($data){ $user_data_num = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->count(); - $user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->page($data['page'],$this->page_num)->order('id desc')->select(); + $user_data = Db::table($this->sportstesting_use_db_name['2'])->where(['aud_id'=>$data['aud_id']])->page($data['page'],$this->page_num)->order('id desc')->field('id,create_time,score,max_score,address')->select(); if($user_data){ $result = []; $result['totalrows'] = $user_data_num; @@ -390,7 +435,7 @@ class Sportstesting extends Base{ array_push($result['rows'],[ 'id'=>$value['id'], 'create_time'=>$value['create_time'], - 'score'=>$value['score'], + 'score'=>$value['score'] == '.00'?"0":$value['score'], 'max_score'=>$value['max_score'], 'address'=>$value['address'], ]); @@ -429,29 +474,32 @@ class Sportstesting extends Base{ } ################################################sportstesting_set_once_data public function sportstesting_set_once_data_action2($data){ + $return_result['total_score'] = 0; $return_result['max_score'] = 0; $parameter_data = explode(',',$data['parameter_data']); $gender = $data['gender']; if(count($parameter_data) == 1){ + // $db_condition = "province = '".$parameter_data[0]."'"; $db_condition = "province = '".$parameter_data[0]."'"; }else if(count($parameter_data) == 2){ - $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'"; + // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."'"; + $db_condition = "province = '".$parameter_data[0]."'"; }else if(count($parameter_data) == 3){ - $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'"; + // $db_condition = "province = '".$parameter_data[0]."' and city = '".$parameter_data[1]."' and area = '".$parameter_data[2]."'"; + $db_condition = "province = '".$parameter_data[0]."'"; }else{ return $this->msg(10005); } + // 只根据省查找,全省一个标准 $find_data = Db::table($this->sportstesting_use_db_name['1'])->where($db_condition)->find(); $find_data = json_decode($find_data['content'],true); $recognition_rule = $find_data[$gender]; foreach ($data['result_data'] as $key => $value) { // 遍历一级($value['key'] = 现场考试) - // dump($value); foreach ($value['list'] as $k2 => $v2) { // 遍历二级级($v2['key'] = 第一类项目 - // dump($v2); foreach ($v2['list'] as $k3 => $v3) { // 遍历二级级($v3['name'] = 1000米跑) $temporary_result = $this->obtaining_grades($recognition_rule[$value['key']][$v2['key']]['list'][$v3['name']]['content'],$v3); @@ -577,7 +625,14 @@ class Sportstesting extends Base{ // 处理默认规则列表 public function handle_default_rule_list($data,$gender){ - $temporary_arr = $data[$gender]; + if($gender == 1){ + $temporary_arr = $data[$gender]; + }else{ + $temporary_arr = $data[2]; + } + + + // die; $result = []; foreach ($temporary_arr as $key => $value) { $num = array_push($result,['name'=>$key,'key'=>$key,'list'=>[]]); @@ -619,9 +674,7 @@ class Sportstesting extends Base{ $temporary_arr = []; $temporary_arr['key'] = $k2; $temporary_arr['list'] = []; - // dump($v2); foreach ($v2['list'] as $k3 => $v3) { - // dump($v3); array_push($temporary_arr['list'],[ 'name'=>$k3, 'proportion'=>$v3['proportion'], @@ -633,7 +686,6 @@ class Sportstesting extends Base{ 'total_score'=>$v3['score'], ]); } - // dump($temporary_arr); array_push($result['list'],$temporary_arr); } } @@ -648,7 +700,7 @@ class Sportstesting extends Base{ // 减 bcsub(,,20) // 乘 bcmul(,,20) // 除 bcdiv(,,20) - if($data['value'] != ''){ + if($data['value'] != '' && $data['value'] != null && $data['value'] != '0' && $data['value'] != '0.0' && $data['value'] != '0.0' && $data['value'] != '0:00'){ if(count($rule) > 0){ foreach ($rule as $key => $value) { if($data['unit'] == '分/秒'){ @@ -658,6 +710,7 @@ class Sportstesting extends Base{ $rule_result = $value[0]; $data_result = $data['value']; } + switch ($value[1]) { case "<=": $result = $data_result <= $rule_result; @@ -681,9 +734,14 @@ class Sportstesting extends Base{ // 如果比较符号不是上述任何一个,可以抛出一个异常或错误 throw new Exception("Unsupported comparison operator: " . $value[1]); } - // dump($result); if($result == true){ - $data['score'] = $value[2]; + // 判断是不是0分 + if($data_result == 0){ + $data['score'] = 0; + }else{ + $data['score'] = $value[2]; + } + // 计算比例后分值 $proportional_post_score = bcmul($data['total_score'],$data['proportion'],2); $data['proportion_value'] = bcmul($data['score'],bcdiv($proportional_post_score,100,2),2); @@ -734,9 +792,7 @@ class Sportstesting extends Base{ 'describe'=>$x_m_v['describe'], 'total_score'=>$x_m_v['score'], ]); - // dump($x_m_k); if($x_m_k == '1000米跑'){ - // dump('11'); $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '4:08'; }else if($x_m_k == '50米跑'){ $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '7.3'; @@ -747,7 +803,6 @@ class Sportstesting extends Base{ }else if($x_m_k == '机考'){ $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '8.3'; }else if($x_m_k == '1000米'){ - // dump('22'); $result[$num-1]['list'][$num2-1]['list'][$num3-1]['value'] = '4:08'; } // break; @@ -767,7 +822,6 @@ class Sportstesting extends Base{ 'describe'=>$x_m_v['describe'], 'total_score'=>$x_m_v['score'], ]); - // dump($x_m_k); if($x_m_k == '1000米跑'){ $result[$num-1]['list'][$num2-1]['list'][0]['value'] = '4:07'; }else if($x_m_k == '50米跑'){ diff --git a/application/testapp/controller/Vitalcapacity.php b/application/testapp/controller/Vitalcapacity.php index e4cb640..5c1f0e0 100644 --- a/application/testapp/controller/Vitalcapacity.php +++ b/application/testapp/controller/Vitalcapacity.php @@ -39,7 +39,7 @@ class Vitalcapacity extends Base{ ################################################################接口################################################################ // 手动数据记录 - public function vitalcapacity_save_record_data($data = ['aud_id'=>'83','one'=>'1523','two'=>'1825','three'=>'1896','time'=>'2024-07-23','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ + public function vitalcapacity_save_record_data($data = ['aud_id'=>'11','one'=>'4900','two'=>'5100','three'=>'5300','time'=>'2024-11-14','token'=>'0dafb98a10995c98b5a33b7d59d986ca']){ try { // 你的业务逻辑 if(count(input('post.')) > 0){ @@ -68,7 +68,7 @@ class Vitalcapacity extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -102,7 +102,7 @@ class Vitalcapacity extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } } @@ -133,7 +133,7 @@ class Vitalcapacity extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } @@ -165,9 +165,8 @@ class Vitalcapacity extends Base{ $logContent['all_content'] .= "行号: " . $e->getLine() . "\n"; $logContent['all_content'] .= "跟踪信息:\n" . $e->getTraceAsString() . "\n"; $this->record_api_log($data, $logContent, null); - return $this->msg(99999,'接口错误'); + return $this->msg(99999); } - } ################################################################业务################################################################ @@ -186,40 +185,62 @@ class Vitalcapacity extends Base{ $temporary_arr['three_val'] = $data['three']; $temporary_arr['average_val'] = $temporary_arr['average']; $temporary_arr['flow_val'] = array_key_exists('flow', $data)?$data['flow']:'0.00'; + // die; // 处理记录时间 if(strlen($temporary_arr['record_time']) <= 12){ $temporary_arr['record_time'] = $this->addCurrentTimeToDateString($temporary_arr['record_time']); } - $user_msg = Db::name($this->vitalcapacity_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('grade,gender')->find(); + $user_msg = Db::name($this->vitalcapacity_use_db_name['1'])->where(['id'=>$data['aud_id']])->field('id,grade,gender,birthday')->find(); + // die; if($user_msg){ // 根据性别&年级&年龄查规则 - if($user_msg['grade'] != 'nothing'){ - // 有年级项 - // 等级项(及格优秀良好等) - $achievement_judge_data = $this->vitalcapacity_achievement_judge(['average'=>$temporary_arr['average'],'grade'=>$user_msg['grade'],'gender'=>$user_msg['gender']]); - - $temporary_arr['score'] = $achievement_judge_data['score'].','.$achievement_judge_data['level'].','.$this->color[$achievement_judge_data['level']]; - $temporary_arr['score_val'] = $achievement_judge_data['score']; - // 获取肺活量标准 - - }else{ - $achievement_judge_data['level'] = "无"; - $temporary_arr['score'] = "0,无,无"; - $temporary_arr['score_val'] = "0"; + if($user_msg['grade'] == 'nothing'){ + // 计算年龄判断是属于哪个年级 + $user_age = $this->calculate_age($user_msg['birthday']); + if($user_age <= 7){ + $user_msg['grade'] = 'grade_s_1'; + }else if($user_age == 8){ + $user_msg['grade'] = 'grade_s_2'; + }else if($user_age == 9){ + $user_msg['grade'] = 'grade_s_3'; + }else if($user_age == 10){ + $user_msg['grade'] = 'grade_s_4'; + }else if($user_age == 11){ + $user_msg['grade'] = 'grade_s_5'; + }else if($user_age == 12){ + $user_msg['grade'] = 'grade_s_6'; + }else if($user_age == 13){ + $user_msg['grade'] = 'grade_m_1'; + }else if($user_age == 14){ + $user_msg['grade'] = 'grade_m_2'; + }else if($user_age == 15){ + $user_msg['grade'] = 'grade_m_3'; + }else if($user_age == 16){ + $user_msg['grade'] = 'grade_h_1'; + }else if($user_age == 17){ + $user_msg['grade'] = 'grade_h_2'; + }else if($user_age == 18){ + $user_msg['grade'] = 'grade_h_3'; + }else if($user_age == 19 || $user_age == 20){ + $user_msg['grade'] = 'grade_u_12'; + }else if($user_age >= 21){ + $user_msg['grade'] = 'grade_u_34'; + } } + $sql_str = "sex = ".$user_msg['gender']." and ".$user_msg['grade']." <= ".$temporary_arr['average_val']; + $user_achievement = Db::name($this->vitalcapacity_use_db_name['3'])->where($sql_str)->order($user_msg['grade'] .' desc')->field('level,score,'.$user_msg['grade'])->limit(1)->select(); + if(count($user_achievement)<=0){ + $user_achievement[0] = ['level'=>'无效','score'=>'0']; + } + $temporary_arr['score'] = $user_achievement[0]['score'].','.$user_achievement[0]['level'].','.$this->color[$user_achievement[0]['level']]; + $temporary_arr['score_val'] = $user_achievement[0]['score']; }else{ return $this->msg(10004); } - - $standard_data = $this->get_vitalcapacity_data($data['aud_id']); - // dump($standard_data); - // die; $temporary_arr['standard_data'] = json_encode($standard_data); - // dump($temporary_arr); - // die; $result = Db::table($this->vitalcapacity_use_db_name['2'])->insert($temporary_arr); if($result){ @@ -228,7 +249,7 @@ class Vitalcapacity extends Base{ $time = date('Y年m月d日 H:i:s', $time); return $this->msg([ 'average'=>$temporary_arr['average'].'ml', - 'level'=>$achievement_judge_data['level'], + 'level'=>$user_achievement[0]['level'], 'time'=>$time, 'flow_val'=>$temporary_arr['flow_val'], 'list'=>$standard_data, @@ -262,8 +283,7 @@ class Vitalcapacity extends Base{ $o_l = explode(',',$result[0]['score']); // $standard_data = $this->get_vitalcapacity_data($data['aud_id']); $standard_data = json_decode($result[0]['standard_data'],true); - // dump($result); - // die; + return $this->msg([ 'average'=>$result[0]['average'].'ml', 'level'=>$o_l[1], @@ -296,14 +316,9 @@ class Vitalcapacity extends Base{ return $this->msg(10005); // 无效的时间数据格式 } - // dump($map); - // die; // 使用查询构造器进行查询 $result = Db::name($this->vitalcapacity_use_db_name['2'])->where($map)->field('id,one_val,two_val,three_val,average_val,score_val,aud_id,record_time,DATEPART(hour, record_time) AS hour,DATEPART(day, record_time) AS day,DATEPART(month, record_time) AS month')->order('record_time')->select(); - // dump($map); - // dump($result); - // die; $return_data = []; if(count($timeData) == 3){ $key_condition = 'hour'; @@ -312,9 +327,6 @@ class Vitalcapacity extends Base{ }else if(count($timeData) == 1){ $key_condition = 'month'; } - // dump($map); - // dump($key_condition); - // die; foreach ($this->curve_data_format as $key => $value) { $temporary_arr['title'] = $value[0].'('.$value[1].')'; $temporary_arr['key'] = $key; @@ -322,15 +334,8 @@ class Vitalcapacity extends Base{ $temporary_arr['line']['series'][0]['color'] = $value[2]; $temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')'; $temporary_arr['line']['series'][0]['data'] = []; - // dump($temporary_arr['title']); foreach ($result as $k => $v) { - // dump($k); - // if($result[$k][$key] == 26.43){ - // dump(123); - // } if($key_condition == 'hour'){ - // dump($result[$k][$key]); - // die; if(in_array($result[$k][$key_condition].'时',$temporary_arr['line']['categories'])){ $num = array_search($result[$k][$key_condition].'时', $temporary_arr['line']['categories']); @@ -341,7 +346,6 @@ class Vitalcapacity extends Base{ array_push($temporary_arr['line']['categories'],$result[$k][$key_condition].'时'); array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]); } - // dump($temporary_arr['line']['series'][0]['data']); }else if($key_condition == 'day'){ if(in_array($result[$k]['month'].'-'.$result[$k][$key_condition],$temporary_arr['line']['categories'])){ $num = array_search($result[$k]['month'].'-'.$result[$k][$key_condition], $temporary_arr['line']['categories']); @@ -362,16 +366,8 @@ class Vitalcapacity extends Base{ } } } - // dump($temporary_arr); array_push($return_data,$temporary_arr); } - // dump($return_data); - // foreach ($return_data[1]['line']['series'][0]['data'] as $key => $value) { - // $return_data[1]['line']['series'][0]['data'][$key] = bcdiv($return_data[1]['line']['series'][0]['data'][$key],60,2); - // } - // // dump($temporary_arr); - // dump($return_data); - // die; return $this->msg($return_data); } @@ -384,24 +380,11 @@ class Vitalcapacity extends Base{ // 减 bcsub(,,20) // 乘 bcmul(,,20) // 除 bcdiv(,,20) - - // 肺活量成绩判断 - public function vitalcapacity_achievement_judge($data){ - $str = "sex = ".$data['gender']." and ".$data['grade']." <= ".$data['average']; - $user_achievement = Db::name($this->vitalcapacity_use_db_name['3'])->where($str)->order($data['grade'] .' desc')->field('level,score,'.$data['grade'])->limit(1)->select(); - // dump($data); - // dump($user_achievement); - if(count($user_achievement)<=0){ - $user_achievement[0] = ['level'=>'无效','score'=>'0']; - } - // dump($user_achievement); - return $user_achievement[0]; - } // 肺活量判断区间 public function vitalcapacity_standard_interval($val,$data){ // 缓存一周 $result = ''; - if(count($data) <= 0){ + if(!$data || count($data) <= 0){ return $result; } $temporary_qj = $data; @@ -418,9 +401,15 @@ class Vitalcapacity extends Base{ } $num = count($temporary_qj)-1-$num; - $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2); - $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2); - + + if($max == 0){ + if($val >= $temporary_qj[0]['max_val']){ + $result = 100; + } + }else{ + $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2); + $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2); + } return $result; } // 肺活量判断区间(根据得分) @@ -442,22 +431,14 @@ class Vitalcapacity extends Base{ break; } } - // dump($data); - // dump($val); - // dump($max); - // dump($min); - // dump($num); - // 计算每份占比 $share_value = bcdiv($temporary_qj[0]['max_val'],count($temporary_qj),1); // 计算在这一段中占多少 $result = bcsub($val,$min,1); - // dump($result); $result = bcdiv($result,bcsub($max,$min,1),1); $num = count($temporary_qj)-1-$num; $num = bcmul($num,$share_value,1); $result = bcadd($num,$result,1); - // dump($share_value); // $num = count($temporary_qj)-1-$num; // $temporary_num = bcmul(bcdiv(bcsub($val,$min,20),bcsub($max,$min,20),2),bcdiv(100,count($temporary_qj),2),2); // $result = bcadd(bcmul(bcdiv(100,count($temporary_qj),2),$num,2),$temporary_num,2); diff --git a/application/testapp/view/download/demo.html b/application/testapp/view/download/demo.html index 3b6977d..0fa6846 100644 --- a/application/testapp/view/download/demo.html +++ b/application/testapp/view/download/demo.html @@ -155,8 +155,9 @@ $('.ts').show() } else { console.log('当前不在微信环境中'); - if (isIOS()) { - console.log('当前是iOS设备'); + if (isIOS()) { + // alert('iOS设备不参与此次测试'); + // console.log('当前是iOS设备'); // 在这里执行iOS设备下的特定代码 window.location.href = "https://apps.apple.com/app/reedaw/id6654906497"; } else { diff --git a/application/testapp/view/download/demo2.html b/application/testapp/view/download/demo2.html index 2d9218f..7099137 100644 --- a/application/testapp/view/download/demo2.html +++ b/application/testapp/view/download/demo2.html @@ -44,12 +44,12 @@ font-size: 4vw; } .download{ - width: 40vw; - height: 10vw; - background-color: darkgray; - border-radius: 5vw; + width: 55vw; + height: 11vw; + background-color: #FFA940; + border-radius: 5.5vw; text-align: center; - line-height: 10vw; + line-height: 11vw; font-weight: bold; text-decoration: none; color: white; @@ -57,16 +57,15 @@ } img{ width: 25vw; - margin-bottom: 20vw; } .jump{ - width: 40vw; - height: 10vw; + width: 55vw; + height: 11vw; color: white; - background-color: darkgray; - border-radius: 5vw; + background-color: #389E0D; + border-radius: 5.5vw; text-align: center; - line-height: 10vw; + line-height: 11vw; font-weight: bold; margin-bottom: 10vw; } @@ -115,8 +114,11 @@
    +
    reedaw
    打开微信小程序
    -
    下载
    +
    下载APP
    diff --git a/public/Q1medp48CV.txt b/public/Q1medp48CV.txt new file mode 100644 index 0000000..9865bd9 --- /dev/null +++ b/public/Q1medp48CV.txt @@ -0,0 +1 @@ +d0a3e497101588de6c22a6cbe8748cbe \ No newline at end of file