197 lines
8.9 KiB
PHP
197 lines
8.9 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 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);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
################################################################action################################################################
|
|
################################################################action################################################################
|
|
|
|
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 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
|
|
];
|
|
}
|
|
|
|
|
|
} |