SchoolPhysicalExamination/application/NewReedaw/controller/app/Skip.php

620 lines
30 KiB
PHP

<?php
namespace app\NewReedaw\controller\app;
use think\Db;
use think\Cache;
class Skip extends Base{
protected $skip_db_name = [
'zhanghao'=>'app_account_number',
'juese'=>'app_user_data',
'body'=>'app_card_body_data',
'skip'=>'app_card_skip_data',
];
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 $pagesize = 15;
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 测试token=>'caadd1be045a65f30b92aa805f1de54a'
################################################################接口################################################################
################################################################接口################################################################
################################################################接口################################################################
// 手动记录
public function manual_record(){
$data = input('post.');
try {
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->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type error');
}
if(!$this->verify_data_is_ok($data['r_time'],'datetime')){
return $this->msg(10005,'r_time type error');
}
if(!$this->verify_data_is_ok($data['type'],'str')){
return $this->msg(10005,'type type error');
}
if(!$this->verify_data_is_ok($data['num'],'intnum') || !$this->verify_data_is_ok($data['time_m'],'intnum') || !$this->verify_data_is_ok($data['time_s'],'intnum')){
return $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
}
if($data['num'] <= 0){
return $this->msg(10005,'跳绳数不能小于等于0');
}
if(abs($data['time_s']) >= 60){
return $this->msg(10005,'秒钟值不能大于60');
}
unset($data['token']);
if($this->validate_user_identity($data['aud_id']) === false){
return $this->msg(10003);
}
return $this->manual_record_action($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_record(){
$data = input('post.');
try {
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->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 $this->msg(10005,'跳绳数量或者分钟、秒钟值必须为整数');
}
if($data['num'] <= 0){
return $this->msg(10005,'跳绳数不能小于等于0');
}
if(abs($data['time_s']) >= 60){
return $this->msg(10005,'秒钟值不能大于60');
}
unset($data['token']);
if($this->validate_user_identity($data['aud_id']) === false){
return $this->msg(10003);
}
return $this->manual_record_action($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_report(){
$data = input('post.');
try {
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);
}
unset($data['token']);
return $this->data_report_action($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 curve_chart(){
$data = input('post.');
try {
if(!array_key_exists('aud_id', $data) || !array_key_exists('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);
}
unset($data['token']);
return $this->curve_chart_action($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 record_list_page(){
$data = input('post.');
try {
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('page', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type error');
}
if(!$this->verify_data_is_ok($data['page'],'intnum')){
return $this->msg(10005,'page type error');
}
return $this->record_list_page_or_group_action($data,'page');
} 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 record_list_group(){
$data = input('post.');
try {
if(!array_key_exists('token', $data) || !array_key_exists('aud_id', $data) || !array_key_exists('s_time', $data) || !array_key_exists('e_time', $data)){
return $this->msg(10001);
}
if(!$this->verify_data_is_ok($data['token'],'str')){
return $this->msg(10005,'token type error');
}
if(!$this->verify_data_is_ok($data['aud_id'],'intnum')){
return $this->msg(10005,'aud_id type error');
}
if(!$this->verify_data_is_ok($data['s_time'],'datetime')){
return $this->msg(10005,'page type error');
}
if(!$this->verify_data_is_ok($data['e_time'],'datetime')){
return $this->msg(10005,'page type error');
}
return $this->record_list_page_or_group_action($data,'group');
} 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 detailed_record(){
$data = input('post.');
try {
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,'token type error');
}
if(!$this->verify_data_is_ok($data['id'],'intnum')){
return $this->msg(10005,'id type error');
}
return $this->get_all_detaile_data_action($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 del_record(){
$data = input('post.');
try {
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']);
// 核实账号
$zh_data = Db::table($this->skip_db_name['zhanghao'])->where(['token'=>$data['token'],'is_del'=>0])->field('id,token')->find();
if(!$zh_data){
return $this->msg(10003);
}
// dump($zh_data);
// 核实角色
$js_data = Db::table($this->skip_db_name['juese'])->where(['aan_id'=>$zh_data['id'],'is_del'=>0])->field('id')->select();
if(!$js_data){
return $this->msg(10003);
}
// dump($js_data);
$skip_data = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id']])->field('id,aud_id')->find();
if(!$skip_data){
return $this->msg(10004);
}
// dump($skip_data);
$pd = false;
foreach ($js_data as $key => $value) {
if($value['id'] == $skip_data['aud_id']){
$pd = true;
}
}
if($pd == true){
$user_data = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id']])->update(['is_del'=>1]);
if($user_data){
return $this->msg([]);
}else{
return $this->msg(10002);
}
}else{
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);
}
}
################################################################action################################################################
################################################################action################################################################
public function manual_record_action($data){
// 分秒转换为秒
$data['time'] = abs($data['time_m'])*60+abs($data['time_s']);
$user_msg_content = Db::table($this->skip_db_name['juese'])->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($this->skip_db_name['body'])->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($this->skip_db_name['juese'])->where(['id'=>$data['aud_id']])->field('id,weight as weight_val')->find();
if(!$last_data_body){
return $this->msg(10004);
}
}
$kcal_data = $this->skip_kcal_calculate($data['num'],$data['time'],$last_data_body['weight_val']);
}else{
// 将时间从秒转换为分钟
$minutes = bcdiv($data['time'],60,20);
// 计算每分钟的跳绳次数
$jumpsPerMinute = bcdiv($data['num'],$minutes,2);
$kcal_data['totalCalories'] = $data['kcal'];
$kcal_data['averageAchievement'] = $jumpsPerMinute;
$kcal_data['caloriesPerMinute'] = bcdiv($kcal_data['totalCalories'],$minutes,2);
}
$data_set = [
'create_time'=>date('Y-m-d H:i:s'),
'last_update_time'=>date('Y-m-d H:i:s'),
'jump_num'=>$data['num'],
'jump_time'=>$data['time'],
'jump_kcal'=>$kcal_data['totalCalories'],
'average_num'=>$kcal_data['averageAchievement'],
'average_kcal'=>$kcal_data['caloriesPerMinute'],
'aud_id'=>$data['aud_id'],
'record_time'=>array_key_exists('r_time', $data)?$data['r_time']:date('Y-m-d H:i:s'),
'jump_type'=>$data['type']
];
if(strlen($data_set['record_time']) <= 12){
$data_set['record_time'] = $this->addCurrentTimeToDateString($data_set['record_time']);
}
$last_data_body = Db::table($this->skip_db_name['skip'])->insert($data_set);
$result = [
'today_jump_num'=>0,
'today_jump_time'=>0,
'today_jump_kcal'=>0,
];
$all_data = Db::table($this->skip_db_name['skip'])->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'];
$result['today_jump_kcal'] = bcadd($result['today_jump_kcal'],$value['jump_kcal'],2);
}
$result['last_jump_num'] = $data['num'];
$result['last_jump_time'] = $data['time'];
$result['last_jump_kcal'] = $data_set['jump_kcal'];
// $result['last_record_time'] = str_replace('-', '/', $data_set['record_time']);
$result['last_record_time'] = $data_set['record_time'];
$time_conversion = $this->handle_hour_branch_second($result['today_jump_time']);
$result['today_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
$time_conversion = $this->handle_hour_branch_second($result['last_jump_time']);
$result['last_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
return $this->msg($result);
}
public function data_report_action($data){
$all_data = Db::table($this->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->whereTime('record_time','today')->field('jump_num,jump_time,jump_kcal')->select();
$last_data = Db::table($this->skip_db_name['skip'])->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,
'today_jump_kcal'=>0,
];
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'];
$result['today_jump_kcal'] = bcadd($result['today_jump_kcal'],$value['jump_kcal'],2);
}
if($last_data){
$result['last_jump_num'] = $last_data['jump_num'];
$result['last_jump_time'] = $last_data['jump_time'];
$result['last_jump_kcal'] = $last_data['jump_kcal'];
$result['last_record_time'] = $last_data['record_time'];
}else{
$result['last_jump_num'] = 0;
$result['last_jump_time'] = 0;
$result['last_jump_kcal'] = 0;
$result['last_record_time'] = '';
}
$time_conversion = $this->handle_hour_branch_second($result['today_jump_time']);
$result['today_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
$time_conversion = $this->handle_hour_branch_second($result['last_jump_time']);
$result['last_jump_time'] = $time_conversion['h'].':'.$time_conversion['m'].':'.$time_conversion['s'];
return $this->msg($result);
}
public function curve_chart_action($data){
$audid = $data['aud_id'];
$timeData = explode('-', $data['time']);
// 根据$timeData的长度构建不同的查询条件
$map = ['aud_id' => $audid,'is_del'=>0];
switch (count($timeData)) {
case 3: // 年月日
$map['record_time'] = ['between', [date('Y-m-d 00:00:00', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2])), date('Y-m-d 23:59:59', strtotime($timeData[0] . '-' . $timeData[1] . '-' . $timeData[2]))]];
break;
case 2: // 年月
$map['record_time'] = ['between', [date('Y-m-01 00:00:00', strtotime($timeData[0] . '-' . $timeData[1])), date('Y-m-t 23:59:59', strtotime($timeData[0] . '-' . $timeData[1]))]];
break;
case 1: // 年
$map['record_time'] = ['between', [date('Y-01-01 00:00:00', strtotime($timeData[0])), date('Y-12-31 23:59:59', strtotime($timeData[0]))]];
break;
default:
return $this->msg(10005); // 无效的时间数据格式
}
// 使用查询构造器进行查询
$result = Db::name($this->skip_db_name['skip'])->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';
}else if(count($timeData) == 2){
$key_condition = 'day';
}else if(count($timeData) == 1){
$key_condition = 'month';
}
foreach ($this->curve_data_format as $key => $value) {
$temporary_arr['title'] = $value[0].'('.$value[1].')';
$temporary_arr['key'] = $key;
$temporary_arr['line']['categories'] = [];
$temporary_arr['line']['series'][0]['color'] = $value[2];
$temporary_arr['line']['series'][0]['name'] = $value[0].'('.$value[1].')';
$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]);
}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']);
$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]['month'].'/'.$result[$k][$key_condition]);
array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
}
}else{
// 根据年分组
if(in_array($result[$k]['month'].'月',$temporary_arr['line']['categories'])){
$num = array_search($result[$k]['month'].'月', $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]['month'].'月');
array_push($temporary_arr['line']['series'][0]['data'],$result[$k][$key]);
}
}
}
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);
}
return $this->msg($return_data);
}
public function record_list_page_or_group_action($data,$type){
$return_result = [];
if($type == 'group'){
$data['s_time'] = $data['s_time'].' 00:00:00';
$data['e_time'] = $data['e_time'].' 23:59:59';
$result = Db::query("
select
id,
CONVERT(varchar(10), record_time, 120) AS r_t,
CONVERT(varchar(19), record_time, 120) AS record_time,
jump_num as v1,
jump_time as v2,
jump_kcal as v3
from ".$this->skip_db_name['skip']."
where aud_id='".$data['aud_id']."'
and record_time between '".$data['s_time']."' and '".$data['e_time']."'
and is_del = 0
order by record_time desc");
foreach ($result as $key => $value) {
$time_t = $this->handle_hour_branch_second($value['v2']);
array_push($return_result, [
'id'=>$value['id'],
'v1'=>$value['v1'],
'v2'=>$time_t['h'].':'.$time_t['m'].':'.$time_t['s'],
'v3'=>$value['v3'],
'v1_name'=>'个数',
'v2_name'=>'时长',
'v3_name'=>'卡路里',
// 'r_t'=>str_replace('-', '/', $value['r_t'])
'r_t'=>$value['r_t']
]);
}
}else{
$result = Db::table($this->skip_db_name['skip'])->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->skip_db_name['skip'])->where(['aud_id'=>$data['aud_id']])->count();
$return_result['rows'] = [];
$return_result['pageno'] = $data['page'];
$return_result['pagesize'] = $this->pagesize;
$return_result['totalpage'] = ceil($return_result['totalrows']/$this->pagesize);
foreach ($result as $key => $value) {
$time_t = $this->handle_hour_branch_second($value['jump_time']);
array_push($return_result['rows'],[
'id'=>$value['id'],
'v1'=>$value['jump_num'],
'v2'=>$time_t['h'].':'.$time_t['m'].':'.$time_t['s'],
'v3'=>$value['jump_kcal'],
'v1_name'=>'个数',
'v2_name'=>'时长',
'v3_name'=>'卡路里',
'record_time'=>$value['b_time'],
]);
}
}
return $this->msg($return_result);
}
public function get_all_detaile_data_action($data){
$result = $result = Db::table($this->skip_db_name['skip'])->where(['id'=>$data['id'],'is_del'=>0])->find();
$for_data_arr = ['jump_num'=>['个数',''],'jump_time'=>['时长',''],'jump_kcal'=>['卡路里','kcal']];
if($result){
$result_data = [];
foreach ($for_data_arr as $key => $value) {
$temporary_arr['key_name'] = $key;
$temporary_arr['name'] = $value[0];
$temporary_arr['value'] = explode(',',$result[$key])[0];
$temporary_arr['unit'] = $value[1];
array_push($result_data,$temporary_arr);
}
return $this->msg($result_data);
}else{
return $this->msg(10002);
}
}
################################################################内部调用################################################################
################################################################内部调用################################################################
// 跳绳卡路里计算
public function skip_kcal_calculate($num=143, $time=222, $weight=70) {
// 加 bcadd(,,20)
// 减 bcsub(,,20)
// 乘 bcmul(,,20)
// 除 bcdiv(,,20)
// 将时间从秒转换为分钟
$minutes = bcdiv($time,60,20);
// 计算每分钟的跳绳次数
$jumpsPerMinute = bcdiv($num,$minutes,2);
// 根据跳绳次数确定MET值
// $met = 11.8;
if ($jumpsPerMinute < 100) {
$met = 8.8;
} else if ($jumpsPerMinute >= 100 && $jumpsPerMinute < 120) {
$met = 11.8;
} else {
$met = 12.3;
}
// 计算每分钟燃烧的卡路里
$caloriesPerMinute = bcdiv(bcmul(bcmul($met,$weight,20),3.5,20),200,2);
// 计算总卡路里消耗
$totalCalories = bcmul($caloriesPerMinute,$minutes,2);
// 返回结果
return [
'averageAchievement' => $jumpsPerMinute,
'caloriesPerMinute' => $caloriesPerMinute,
'totalCalories' => $totalCalories
];
}
}