452 lines
20 KiB
PHP
452 lines
20 KiB
PHP
|
|
<?php
|
|||
|
|
|
|||
|
|
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 $level_data = [
|
|||
|
|
['min_val'=>'0','max_val'=>'59','text'=>'不及格','color'=>'#FB5755'],
|
|||
|
|
['min_val'=>'60','max_val'=>'79','text'=>'及格','color'=>'#FCAE00'],
|
|||
|
|
['min_val'=>'80','max_val'=>'89','text'=>'良好','color'=>'#58CF67'],
|
|||
|
|
['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 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 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);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
################################################################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();
|
|||
|
|
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();
|
|||
|
|
if(!$card_data_sub_item){
|
|||
|
|
return $this->msg(10004);
|
|||
|
|
}
|
|||
|
|
$return_data = [
|
|||
|
|
'icon' => '',
|
|||
|
|
'label_list' => [],
|
|||
|
|
'line_list' => [],
|
|||
|
|
'label_data' => [],
|
|||
|
|
|
|||
|
|
];
|
|||
|
|
$data_this_time = [];
|
|||
|
|
$today_time = date('Y-m-d');
|
|||
|
|
foreach ($card_data_sub_item as $key => $value) {
|
|||
|
|
// 设置单项数据模板
|
|||
|
|
$temporary_arr_c = [
|
|||
|
|
'project_name' => $value['name'],
|
|||
|
|
'score' => '',
|
|||
|
|
'max_score' => '',
|
|||
|
|
'standard' => '',
|
|||
|
|
'this_time_title' => '本次成绩',
|
|||
|
|
'this_time_value' => '',
|
|||
|
|
'today_time_title' => '今日总计',
|
|||
|
|
'today_times' => 0,
|
|||
|
|
'today_time_value' => 0,
|
|||
|
|
'all_time_title' => '总计平均',
|
|||
|
|
'all_times' => 0,
|
|||
|
|
'all_time_value' => 0,
|
|||
|
|
'describe' => '',
|
|||
|
|
'color' => '',
|
|||
|
|
'offset' => '',
|
|||
|
|
'unit_data' => '',
|
|||
|
|
];
|
|||
|
|
// 添加标签
|
|||
|
|
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);
|
|||
|
|
if($data_this_time){
|
|||
|
|
$data_this_time['detailed_msg'] = json_decode($data_this_time['detailed_msg'],true);
|
|||
|
|
// 设置基础数据
|
|||
|
|
$temporary_arr_c['score'] = $data_this_time['detailed_msg']['score'].'分';
|
|||
|
|
$temporary_arr_c['max_score'] = $data_this_time['detailed_msg']['max_score'];
|
|||
|
|
$temporary_arr_c['standard'] = $data_this_time['detailed_msg']['standard'];
|
|||
|
|
$temporary_arr_c['describe'] = $data_this_time['detailed_msg']['describe'];
|
|||
|
|
$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'];
|
|||
|
|
// 获取到该项所有数据
|
|||
|
|
$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();
|
|||
|
|
// 处理今日,以及总计数据
|
|||
|
|
if($data_this_time['detailed_msg']['unit_data'] == '分/秒'){
|
|||
|
|
// 如果是分秒形式的数据
|
|||
|
|
// 设置今日数据跟总计数据的格式
|
|||
|
|
$temporary_arr_c['today_time_value'] = "0:00";
|
|||
|
|
$temporary_arr_c['all_time_value'] = "0:00";
|
|||
|
|
// 处理本次数据最终格式
|
|||
|
|
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) {
|
|||
|
|
$temporary_arr_c['all_time_value'] = $this->sumTimes($temporary_arr_c['all_time_value'],$v1['achievement']);
|
|||
|
|
if($v1['r_t'] == $today_time){
|
|||
|
|
$temporary_arr_c['today_times'] = $temporary_arr_c['today_times']+1;
|
|||
|
|
$temporary_arr_c['today_time_value'] = $this->sumTimes($temporary_arr_c['today_time_value'],$v1['achievement']);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$temporary_arr_c['all_time_value'] = $this->averageTime($temporary_arr_c['all_time_value'],$temporary_arr_c['all_times']);
|
|||
|
|
list($minutes, $seconds) = explode(':', $temporary_arr_c['today_time_value']);
|
|||
|
|
$temporary_arr_c['today_time_value'] = $minutes . '分' . sprintf('%02d', $seconds) . '秒';
|
|||
|
|
|
|||
|
|
}else{
|
|||
|
|
|
|||
|
|
$temporary_arr_c['this_time_value'] = $data_this_time['achievement'].$data_this_time['detailed_msg']['unit_data'];
|
|||
|
|
|
|||
|
|
$temporary_arr_c['all_times'] = count($all_time_title);
|
|||
|
|
foreach ($all_time_title as $k1 => $v1) {
|
|||
|
|
$temporary_arr_c['all_time_value'] = $temporary_arr_c['all_time_value']+$v1['achievement'];
|
|||
|
|
if($v1['r_t'] == $today_time){
|
|||
|
|
$temporary_arr_c['today_times'] = $temporary_arr_c['today_times']+1;
|
|||
|
|
$temporary_arr_c['today_time_value'] = $temporary_arr_c['today_time_value']+$v1['achievement'];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
$temporary_arr_c['today_time_value'] = $temporary_arr_c['today_time_value'].$data_this_time['detailed_msg']['unit_data'];
|
|||
|
|
|
|||
|
|
$temporary_arr_c['all_time_value'] = bcdiv($temporary_arr_c['all_time_value'],$temporary_arr_c['all_times'],1).$data_this_time['detailed_msg']['unit_data'];
|
|||
|
|
}
|
|||
|
|
$temporary_arr_c['today_times'] = $temporary_arr_c['today_times'].'次';
|
|||
|
|
$temporary_arr_c['all_times'] = $temporary_arr_c['all_times'].'次';
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
array_push($return_data['label_data'],$temporary_arr_c);
|
|||
|
|
}
|
|||
|
|
return $this->msg($return_data);
|
|||
|
|
}
|
|||
|
|
##################################################data_save##################################################
|
|||
|
|
public function data_save_action($data){
|
|||
|
|
|
|||
|
|
// 查找用户是存在
|
|||
|
|
$user_data = Db::table('app_user_data')->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();
|
|||
|
|
if(!$card_data_sub_item_data){
|
|||
|
|
return $this->msg(10004);
|
|||
|
|
}
|
|||
|
|
// 如果项目数据类型为分秒格式
|
|||
|
|
if($card_data_sub_item_data['type'] == 1){
|
|||
|
|
// 判断是否为整型,或者字符串类型的整型数字
|
|||
|
|
if(!$this->isValidInteger($data['data'])){
|
|||
|
|
return $this->msg(10005);
|
|||
|
|
}
|
|||
|
|
}else if($card_data_sub_item_data['type'] == 4){
|
|||
|
|
// 检查字符串格式是否为“数字”+“:”+“数字”的格式,且冒号后的数字小于等于59
|
|||
|
|
if(!$this->isValidFormatWithLimit($data['data'])){
|
|||
|
|
return $this->msg(10005);
|
|||
|
|
}
|
|||
|
|
}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']);
|
|||
|
|
$save_data = [
|
|||
|
|
'acd_id' => $card_data_sub_item_data['acd_id'],
|
|||
|
|
'acdsi_id' => $card_data_sub_item_data['id'],
|
|||
|
|
'aud_id' => $data['aud_id'],
|
|||
|
|
'achievement' => $data['data'],
|
|||
|
|
'record_time' => $data['record_time'].date(' H:i:s'),
|
|||
|
|
'create_time' => date('Y-m-d H:i:s'),
|
|||
|
|
'unit' => $card_data_sub_item_data['unit'],
|
|||
|
|
'score' => $score_all_data['score'],
|
|||
|
|
'detailed_msg' => json_encode($score_all_data),
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
$result = Db::table('app_card_data_sub_item_data')->insert($save_data);
|
|||
|
|
// $result = true;
|
|||
|
|
if($result){
|
|||
|
|
if($save_data['unit'] == '分/秒'){
|
|||
|
|
list($minutes, $seconds) = explode(':', $data['data']);
|
|||
|
|
$score_all_data['this_time_value'] = $minutes . '分' . sprintf('%02d', $seconds) . '秒';
|
|||
|
|
}else{
|
|||
|
|
$score_all_data['this_time_value'] = $data['data'].$save_data['unit'];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return $this->msg($score_all_data);
|
|||
|
|
}else{
|
|||
|
|
return $this->msg(10002);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
##################################################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();
|
|||
|
|
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();
|
|||
|
|
if(count($label_data)<=0){
|
|||
|
|
return $this->msg(10004);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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';
|
|||
|
|
}
|
|||
|
|
unset($label_data[$key]['ROW_NUMBER']);
|
|||
|
|
}
|
|||
|
|
return $this->msg($label_data);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
################################################################tool################################################################
|
|||
|
|
################################################################tool################################################################
|
|||
|
|
|
|||
|
|
// 计算得分成绩以及线性进度
|
|||
|
|
public function calculation_score($gender,$data,$type){
|
|||
|
|
// $card_name['card_name'] = ;
|
|||
|
|
$card_name['project_name'] = $data['name'];
|
|||
|
|
$card_name['score'] = 0;
|
|||
|
|
$card_name['offset'] = 0;
|
|||
|
|
$describe_list = $this->level_data;
|
|||
|
|
$card_name['rule'] = [];
|
|||
|
|
|
|||
|
|
// 计算得分
|
|||
|
|
// 获取评分细则
|
|||
|
|
$estimate = Db::table('admin_estimate')->where(['type'=>3])->find();
|
|||
|
|
$estimate = json_decode($estimate['content'],true);
|
|||
|
|
|
|||
|
|
// 根据男女循环出项目细则
|
|||
|
|
foreach ($estimate[$gender]['公共考核标准'] as $key => $value) {
|
|||
|
|
if(count($card_name['rule']) > 0){
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
foreach ($value['list'] as $k => $v) {
|
|||
|
|
if($k == $data['name']){
|
|||
|
|
$card_name['rule'] = $v;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
foreach ($card_name['rule']['content'] as $key => $value) {
|
|||
|
|
if($type == '分/秒'){
|
|||
|
|
$rule_result = $this->convertMinutesSecondsToStringSeconds($value[0]);
|
|||
|
|
$data_result = $this->convertMinutesSecondsToStringSeconds($data['data']);
|
|||
|
|
}else{
|
|||
|
|
$rule_result = $value[0];
|
|||
|
|
$data_result = $data['data'];
|
|||
|
|
}
|
|||
|
|
switch ($value[1]) {
|
|||
|
|
case "<=":
|
|||
|
|
$result = $data_result <= $rule_result;
|
|||
|
|
break;
|
|||
|
|
case ">=":
|
|||
|
|
$result = $data_result >= $rule_result;
|
|||
|
|
break;
|
|||
|
|
case "<":
|
|||
|
|
$result = $data_result < $rule_result;
|
|||
|
|
break;
|
|||
|
|
case ">":
|
|||
|
|
$result = $data_result > $rule_result;
|
|||
|
|
break;
|
|||
|
|
case "==":
|
|||
|
|
$result = $data_result == $rule_result;
|
|||
|
|
break;
|
|||
|
|
case "!=":
|
|||
|
|
$result = $data_result != $rule_result;
|
|||
|
|
break;
|
|||
|
|
default:
|
|||
|
|
// 如果比较符号不是上述任何一个,可以抛出一个异常或错误
|
|||
|
|
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;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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'];
|
|||
|
|
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['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;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 获取标签列表,以及标签列表下数据
|
|||
|
|
public function get_other_data(){
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
################################################################其他################################################################
|
|||
|
|
################################################################其他################################################################
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 检查字符串格式是否为“数字”+“:”+“数字”的格式,且冒号后的数字小于等于59
|
|||
|
|
public function isValidFormatWithLimit($str){
|
|||
|
|
// 使用正则表达式匹配“数字:数字”的格式
|
|||
|
|
if (preg_match('/^(\d+):(\d+)$/', $str, $matches)) {
|
|||
|
|
// 提取冒号前后的数字
|
|||
|
|
$firstNumber = $matches[1];
|
|||
|
|
$secondNumber = $matches[2];
|
|||
|
|
|
|||
|
|
// 检查冒号后的数字是否小于等于60
|
|||
|
|
if ($secondNumber <= 59) {
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 两个时间相加4:20、5:15
|
|||
|
|
function sumTimes($time1, $time2) {
|
|||
|
|
// 将时间字符串拆分为分钟和秒
|
|||
|
|
list($min1, $sec1) = explode(':', $time1);
|
|||
|
|
list($min2, $sec2) = explode(':', $time2);
|
|||
|
|
|
|||
|
|
// 将分钟和秒转换为整数
|
|||
|
|
$totalMin = (int)$min1 + (int)$min2;
|
|||
|
|
$totalSec = (int)$sec1 + (int)$sec2;
|
|||
|
|
|
|||
|
|
// 如果秒数超过或等于60,则进位到分钟
|
|||
|
|
if ($totalSec >= 60) {
|
|||
|
|
$totalMin += floor($totalSec / 60);
|
|||
|
|
$totalSec = $totalSec % 60;
|
|||
|
|
}
|
|||
|
|
// 格式化总时间为"分:秒"
|
|||
|
|
// $totalTime = sprintf('%d分%02d秒', $totalMin, $totalSec);
|
|||
|
|
$totalTime = $totalMin.":".$totalSec;
|
|||
|
|
// 返回结果
|
|||
|
|
return $totalTime;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
// 处理平均时间
|
|||
|
|
function averageTime($timeStr, $divisor) {
|
|||
|
|
// 步骤1: 拆分时间字符串
|
|||
|
|
list($minutes, $seconds) = explode(':', $timeStr);
|
|||
|
|
|
|||
|
|
// 步骤2: 转换为总秒数
|
|||
|
|
$totalSeconds = ($minutes * 60) + $seconds;
|
|||
|
|
|
|||
|
|
// 步骤3: 除以参数
|
|||
|
|
$averageSeconds = $totalSeconds / $divisor;
|
|||
|
|
|
|||
|
|
// 步骤4: 转换回分钟和秒
|
|||
|
|
$averageMinutes = floor($averageSeconds / 60);
|
|||
|
|
$remainingSeconds = round($averageSeconds % 60); // 使用round来处理小数秒,如果需要更精确的四舍五入
|
|||
|
|
|
|||
|
|
// 步骤5: 格式化结果为“分:秒”
|
|||
|
|
$formattedTime = sprintf('%d分%02d秒', $averageMinutes, $remainingSeconds);
|
|||
|
|
|
|||
|
|
return $formattedTime;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|